OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/shell_dialogs.h" | 5 #include "chrome/browser/shell_dialogs.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> |
(...skipping 11 matching lines...) Expand all Loading... |
22 class SelectFileDialogImpl; | 22 class SelectFileDialogImpl; |
23 | 23 |
24 // A bridge class to act as the modal delegate to the save/open sheet and send | 24 // A bridge class to act as the modal delegate to the save/open sheet and send |
25 // the results to the C++ class. | 25 // the results to the C++ class. |
26 @interface SelectFileDialogBridge : NSObject<NSOpenSavePanelDelegate> { | 26 @interface SelectFileDialogBridge : NSObject<NSOpenSavePanelDelegate> { |
27 @private | 27 @private |
28 SelectFileDialogImpl* selectFileDialogImpl_; // WEAK; owns us | 28 SelectFileDialogImpl* selectFileDialogImpl_; // WEAK; owns us |
29 } | 29 } |
30 | 30 |
31 - (id)initWithSelectFileDialogImpl:(SelectFileDialogImpl*)s; | 31 - (id)initWithSelectFileDialogImpl:(SelectFileDialogImpl*)s; |
32 - (void)endedPanel:(NSSavePanel *)panel | 32 - (void)endedPanel:(NSSavePanel*)panel |
33 withReturn:(int)returnCode | 33 withReturn:(int)returnCode |
34 context:(void *)context; | 34 context:(void *)context; |
35 | 35 |
36 // NSSavePanel delegate method | 36 // NSSavePanel delegate method |
37 - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename; | 37 - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename; |
38 | 38 |
39 @end | 39 @end |
40 | 40 |
41 // Implementation of SelectFileDialog that shows Cocoa dialogs for choosing a | 41 // Implementation of SelectFileDialog that shows Cocoa dialogs for choosing a |
42 // file or folder. | 42 // file or folder. |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 @implementation SelectFileDialogBridge | 318 @implementation SelectFileDialogBridge |
319 | 319 |
320 - (id)initWithSelectFileDialogImpl:(SelectFileDialogImpl*)s { | 320 - (id)initWithSelectFileDialogImpl:(SelectFileDialogImpl*)s { |
321 self = [super init]; | 321 self = [super init]; |
322 if (self != nil) { | 322 if (self != nil) { |
323 selectFileDialogImpl_ = s; | 323 selectFileDialogImpl_ = s; |
324 } | 324 } |
325 return self; | 325 return self; |
326 } | 326 } |
327 | 327 |
328 - (void)endedPanel:(id)panel | 328 - (void)endedPanel:(NSSavePanel*)panel |
329 withReturn:(int)returnCode | 329 withReturn:(int)returnCode |
330 context:(void *)context { | 330 context:(void *)context { |
331 int index = 0; | 331 int index = 0; |
332 SelectFileDialogImpl::SheetContext* context_struct = | 332 SelectFileDialogImpl::SheetContext* context_struct = |
333 (SelectFileDialogImpl::SheetContext*)context; | 333 (SelectFileDialogImpl::SheetContext*)context; |
334 | 334 |
335 SelectFileDialog::Type type = context_struct->type; | 335 SelectFileDialog::Type type = context_struct->type; |
336 NSWindow* parentWindow = context_struct->owning_window; | 336 NSWindow* parentWindow = context_struct->owning_window; |
337 delete context_struct; | 337 delete context_struct; |
338 | 338 |
339 bool isMulti = type == SelectFileDialog::SELECT_OPEN_MULTI_FILE; | 339 bool isMulti = type == SelectFileDialog::SELECT_OPEN_MULTI_FILE; |
340 | 340 |
341 std::vector<FilePath> paths; | 341 std::vector<FilePath> paths; |
342 bool did_cancel = returnCode == NSCancelButton; | 342 bool did_cancel = returnCode == NSCancelButton; |
343 if (!did_cancel) { | 343 if (!did_cancel) { |
344 if (type == SelectFileDialog::SELECT_SAVEAS_FILE) { | 344 if (type == SelectFileDialog::SELECT_SAVEAS_FILE) { |
345 paths.push_back(FilePath(base::SysNSStringToUTF8([panel filename]))); | 345 paths.push_back(FilePath(base::SysNSStringToUTF8([panel filename]))); |
346 | 346 |
347 NSView* accessoryView = [panel accessoryView]; | 347 NSView* accessoryView = [panel accessoryView]; |
348 if (accessoryView) { | 348 if (accessoryView) { |
349 NSPopUpButton* popup = [accessoryView viewWithTag:kFileTypePopupTag]; | 349 NSPopUpButton* popup = [accessoryView viewWithTag:kFileTypePopupTag]; |
350 if (popup) { | 350 if (popup) { |
351 // File type indexes are 1-based. | 351 // File type indexes are 1-based. |
352 index = [popup indexOfSelectedItem] + 1; | 352 index = [popup indexOfSelectedItem] + 1; |
353 } | 353 } |
354 } else { | 354 } else { |
355 index = 1; | 355 index = 1; |
356 } | 356 } |
357 } else { | 357 } else { |
358 NSArray* filenames = [panel filenames]; | 358 CHECK([panel isKindOfClass:[NSOpenPanel class]]); |
| 359 NSArray* filenames = [static_cast<NSOpenPanel*>(panel) filenames]; |
359 for (NSString* filename in filenames) | 360 for (NSString* filename in filenames) |
360 paths.push_back(FilePath(base::SysNSStringToUTF8(filename))); | 361 paths.push_back(FilePath(base::SysNSStringToUTF8(filename))); |
361 } | 362 } |
362 } | 363 } |
363 | 364 |
364 selectFileDialogImpl_->FileWasSelected(panel, | 365 selectFileDialogImpl_->FileWasSelected(panel, |
365 parentWindow, | 366 parentWindow, |
366 did_cancel, | 367 did_cancel, |
367 isMulti, | 368 isMulti, |
368 paths, | 369 paths, |
369 index); | 370 index); |
370 [panel release]; | 371 [panel release]; |
371 } | 372 } |
372 | 373 |
373 - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename { | 374 - (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename { |
374 return selectFileDialogImpl_->ShouldEnableFilename(sender, filename); | 375 return selectFileDialogImpl_->ShouldEnableFilename(sender, filename); |
375 } | 376 } |
376 | 377 |
377 @end | 378 @end |
OLD | NEW |