Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: chrome/browser/ui/cocoa/select_file_dialog_mac.mm

Issue 9982014: Make common utility to load views from nibs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: retain autorelease Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/shell/shell_login_dialog_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/select_file_dialog.h" 5 #include "chrome/browser/ui/select_file_dialog.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <CoreServices/CoreServices.h> 8 #include <CoreServices/CoreServices.h>
9 9
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/mac/bundle_locations.h" 16 #include "base/mac/bundle_locations.h"
17 #import "base/mac/cocoa_protocols.h" 17 #import "base/mac/cocoa_protocols.h"
18 #include "base/mac/mac_util.h" 18 #include "base/mac/mac_util.h"
19 #include "base/mac/scoped_cftyperef.h" 19 #include "base/mac/scoped_cftyperef.h"
20 #import "base/memory/scoped_nsobject.h" 20 #import "base/memory/scoped_nsobject.h"
21 #include "base/sys_string_conversions.h" 21 #include "base/sys_string_conversions.h"
22 #include "base/threading/thread_restrictions.h" 22 #include "base/threading/thread_restrictions.h"
23 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
24 #import "ui/base/cocoa/nib_loading.h"
24 #include "ui/base/l10n/l10n_util_mac.h" 25 #include "ui/base/l10n/l10n_util_mac.h"
25 26
26 static const int kFileTypePopupTag = 1234; 27 namespace {
28
29 const int kFileTypePopupTag = 1234;
30
31 } // namespace
27 32
28 class SelectFileDialogImpl; 33 class SelectFileDialogImpl;
29 34
30 // A bridge class to act as the modal delegate to the save/open sheet and send 35 // A bridge class to act as the modal delegate to the save/open sheet and send
31 // the results to the C++ class. 36 // the results to the C++ class.
32 @interface SelectFileDialogBridge : NSObject<NSOpenSavePanelDelegate> { 37 @interface SelectFileDialogBridge : NSObject<NSOpenSavePanelDelegate> {
33 @private 38 @private
34 SelectFileDialogImpl* selectFileDialogImpl_; // WEAK; owns us 39 SelectFileDialogImpl* selectFileDialogImpl_; // WEAK; owns us
35 } 40 }
36 41
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 listener_->MultiFilesSelected(files, params); 292 listener_->MultiFilesSelected(files, params);
288 } else { 293 } else {
289 listener_->FileSelected(files[0], index, params); 294 listener_->FileSelected(files[0], index, params);
290 } 295 }
291 } 296 }
292 } 297 }
293 298
294 NSView* SelectFileDialogImpl::GetAccessoryView(const FileTypeInfo* file_types, 299 NSView* SelectFileDialogImpl::GetAccessoryView(const FileTypeInfo* file_types,
295 int file_type_index) { 300 int file_type_index) {
296 DCHECK(file_types); 301 DCHECK(file_types);
297 scoped_nsobject<NSNib> nib ( 302 NSView* accessory_view = ui::GetViewFromNib(@"SaveAccessoryView");
298 [[NSNib alloc] initWithNibNamed:@"SaveAccessoryView" 303 if (!accessory_view)
299 bundle:base::mac::FrameworkBundle()]);
300 if (!nib)
301 return nil; 304 return nil;
302 305
303 NSArray* objects;
304 BOOL success = [nib instantiateNibWithOwner:nil
305 topLevelObjects:&objects];
306 if (!success)
307 return nil;
308 [objects makeObjectsPerformSelector:@selector(release)];
309
310 // This is a one-object nib, but IB insists on creating a second object, the
311 // NSApplication. I don't know why.
312 size_t view_index = 0;
313 while (view_index < [objects count] &&
314 ![[objects objectAtIndex:view_index] isKindOfClass:[NSView class]])
315 ++view_index;
316 DCHECK(view_index < [objects count]);
317 NSView* accessory_view = [objects objectAtIndex:view_index];
318
319 NSPopUpButton* popup = [accessory_view viewWithTag:kFileTypePopupTag]; 306 NSPopUpButton* popup = [accessory_view viewWithTag:kFileTypePopupTag];
320 DCHECK(popup); 307 DCHECK(popup);
321 308
322 size_t type_count = file_types->extensions.size(); 309 size_t type_count = file_types->extensions.size();
323 for (size_t type = 0; type<type_count; ++type) { 310 for (size_t type = 0; type<type_count; ++type) {
324 NSString* type_description; 311 NSString* type_description;
325 if (type < file_types->extension_description_overrides.size()) { 312 if (type < file_types->extension_description_overrides.size()) {
326 type_description = base::SysUTF16ToNSString( 313 type_description = base::SysUTF16ToNSString(
327 file_types->extension_description_overrides[type]); 314 file_types->extension_description_overrides[type]);
328 } else { 315 } else {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 paths, 406 paths,
420 index); 407 index);
421 [panel release]; 408 [panel release];
422 } 409 }
423 410
424 - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename { 411 - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename {
425 return selectFileDialogImpl_->ShouldEnableFilename(sender, filename); 412 return selectFileDialogImpl_->ShouldEnableFilename(sender, filename);
426 } 413 }
427 414
428 @end 415 @end
OLDNEW
« no previous file with comments | « no previous file | content/shell/shell_login_dialog_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698