Bug 802776 - Update deprecated calls in NSOpenPanel and NSSavePanel and transform default directory paths strings to URIs so they work as expected. r=josh
authorAndre Reinald <areinald@mozilla.com>
Thu, 18 Apr 2013 12:39:09 -0400
changeset 129221 43987922a6b34b8ba4ab3c361a2a5f2bdd2c5e2f
parent 129220 5b25aba83eebfb933364249f0fcafdddd72f45a4
child 129222 9dd64ef21eff04910856d1d287b74700d8363369
push id24562
push userryanvm@gmail.com
push dateFri, 19 Apr 2013 01:24:04 +0000
treeherdermozilla-central@f8d27fe5d7c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh
bugs802776
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 802776 - Update deprecated calls in NSOpenPanel and NSSavePanel and transform default directory paths strings to URIs so they work as expected. r=josh
widget/cocoa/nsFilePicker.mm
--- a/widget/cocoa/nsFilePicker.mm
+++ b/widget/cocoa/nsFilePicker.mm
@@ -296,66 +296,68 @@ nsFilePicker::GetLocalFiles(const nsStri
   SetShowHiddenFileState(thePanel);
 
   // Set the options for how the get file dialog will appear
   SetDialogTitle(inTitle, thePanel);
   [thePanel setAllowsMultipleSelection:inAllowMultiple];
   [thePanel setCanSelectHiddenExtension:YES];
   [thePanel setCanChooseDirectories:NO];
   [thePanel setCanChooseFiles:YES];
-  [thePanel setResolvesAliases:YES];        //this is default - probably doesn't need to be set
+  [thePanel setResolvesAliases:YES]; //this is default - probably doesn't need to be set
   
   // Get filters
   // filters may be null, if we should allow all file types.
   NSArray *filters = GetFilterList();
 
   // set up default directory
   NSString *theDir = PanelDefaultDirectory();
   
   // if this is the "Choose application..." dialog, and no other start
   // dir has been set, then use the Applications folder.
-  if (!theDir && filters && [filters count] == 1 && 
-      [(NSString *)[filters objectAtIndex:0] isEqualToString:@"app"]) {
-    theDir = @"/Applications/";
+  if (!theDir) {
+    if (filters && [filters count] == 1 &&
+        [(NSString *)[filters objectAtIndex:0] isEqualToString:@"app"])
+      theDir = @"/Applications/";
+    else
+      theDir = @"";
   }
 
+  [thePanel setDirectoryURL:[[NSURL alloc] initFileURLWithPath:theDir isDirectory:YES]];
+
   int result;
   nsCocoaUtils::PrepareForNativeAppModalDialog();
   if (mFilters.Length() > 1) {
     // [NSURL initWithString:] (below) throws an exception if URLString is nil.
-    if (!theDir) {
-      theDir = @"";
-    }
 
     NSPopUpButtonObserver* observer = [[NSPopUpButtonObserver alloc] init];
 
     NSView* accessoryView = GetAccessoryView();
     [thePanel setAccessoryView:accessoryView];
 
     [observer setPopUpButton:[accessoryView viewWithTag:kSaveTypeControlTag]];
     [observer setOpenPanel:thePanel];
     [observer setFilePicker:this];
 
     [[NSNotificationCenter defaultCenter]
       addObserver:observer
       selector:@selector(menuChangedItem:)
       name:NSMenuWillSendActionNotification object:nil];
 
-    [thePanel setDirectoryURL:[[NSURL alloc] initWithString:theDir]];
     UpdatePanelFileTypes(thePanel, filters);
     result = [thePanel runModal];
 
     [[NSNotificationCenter defaultCenter] removeObserver:observer];
     [observer release];
   } else {
     // If we show all file types, also "expose" bundles' contents.
     if (!filters) {
       [thePanel setTreatsFilePackagesAsDirectories:YES];
     }
-    result = [thePanel runModalForDirectory:theDir file:nil types:filters];
+    [thePanel setAllowedFileTypes:filters];
+    result = [thePanel runModal];
   }
   nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
   
   if (result == NSFileHandlingPanelCancelButton)
     return retVal;
 
   // Converts data from a NSArray of NSURL to the returned format.
   // We should be careful to not call [thePanel URLs] more than once given that
@@ -404,18 +406,19 @@ nsFilePicker::GetLocalFolder(const nsStr
   [thePanel setResolvesAliases:YES];          //this is default - probably doesn't need to be set
   [thePanel setCanCreateDirectories:YES];
   
   // packages != folders
   [thePanel setTreatsFilePackagesAsDirectories:NO];
 
   // set up default directory
   NSString *theDir = PanelDefaultDirectory();
+  [thePanel setDirectoryURL:[[NSURL alloc] initFileURLWithPath:theDir isDirectory:YES]];
   nsCocoaUtils::PrepareForNativeAppModalDialog();
-  int result = [thePanel runModalForDirectory:theDir file:nil types:nil];  
+  int result = [thePanel runModal];
   nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
 
   if (result == NSFileHandlingPanelCancelButton)
     return retVal;
 
   // get the path for the folder (we allow just 1, so that's all we get)
   NSURL *theURL = [[thePanel URLs] objectAtIndex:0];
   if (theURL) {
@@ -452,20 +455,22 @@ nsFilePicker::PutLocalFile(const nsStrin
   NSView* accessoryView = GetAccessoryView();
   [thePanel setAccessoryView:accessoryView];
 
   // set up default file name
   NSString* defaultFilename = [NSString stringWithCharacters:(const unichar*)inDefaultName.get() length:inDefaultName.Length()];
 
   // set up default directory
   NSString *theDir = PanelDefaultDirectory();
+  [thePanel setDirectoryURL:[[NSURL alloc] initFileURLWithPath:theDir isDirectory:YES]];
 
   // load the panel
   nsCocoaUtils::PrepareForNativeAppModalDialog();
-  int result = [thePanel runModalForDirectory:theDir file:defaultFilename];
+  [thePanel setNameFieldStringValue:defaultFilename];
+  int result = [thePanel runModal];
   nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
   if (result == NSFileHandlingPanelCancelButton)
     return retVal;
 
   // get the save type
   NSPopUpButton* popupButton = [accessoryView viewWithTag:kSaveTypeControlTag];
   if (popupButton) {
     mSelectedTypeIndex = [popupButton indexOfSelectedItem];