Bug 472487. Use the default filename in modeOpen in the Mac filepicker (e.g. so that file inputs prefill the currently-selected file in the filepicker). r=josh, sr=roc
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 12 Jan 2009 10:43:27 -0500
changeset 23545 5e45ba40a88ae5d71a449db11fcafa994a523313
parent 23544 8837f5204f30d0de933ad56f85b34a366bc25717
child 23546 3b9d2ef2e4a8b474c1998e917da206ff8bac829d
push id4593
push userbzbarsky@mozilla.com
push dateMon, 12 Jan 2009 15:59:48 +0000
treeherdermozilla-central@5e45ba40a88a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh, roc
bugs472487
milestone1.9.2a1pre
Bug 472487. Use the default filename in modeOpen in the Mac filepicker (e.g. so that file inputs prefill the currently-selected file in the filepicker). r=josh, sr=roc
widget/src/cocoa/nsFilePicker.h
widget/src/cocoa/nsFilePicker.mm
--- a/widget/src/cocoa/nsFilePicker.h
+++ b/widget/src/cocoa/nsFilePicker.h
@@ -82,17 +82,17 @@ protected:
 
   virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle,
                           PRInt16 aMode);
 
     // actual implementations of get/put dialogs using NSOpenPanel & NSSavePanel
     // aFile is an existing but unspecified file. These functions must specify it.
     //
     // will return |returnCancel| or |returnOK| as result.
-  PRInt16 GetLocalFiles(const nsString& inTitle, PRBool inAllowMultiple, nsCOMArray<nsILocalFile>& outFiles);
+  PRInt16 GetLocalFiles(const nsString& inTitle, const nsString& inDefaultName, PRBool inAllowMultiple, nsCOMArray<nsILocalFile>& outFiles);
   PRInt16 GetLocalFolder(const nsString& inTitle, nsILocalFile** outFile);
   PRInt16 PutLocalFile(const nsString& inTitle, const nsString& inDefaultName, nsILocalFile** outFile);
 
   NSArray  *GenerateFilterList();
   void     SetDialogTitle(const nsString& inTitle, id aDialog);
   NSString *PanelDefaultDirectory();
   NSView* GetAccessoryView();
                                                 
--- a/widget/src/cocoa/nsFilePicker.mm
+++ b/widget/src/cocoa/nsFilePicker.mm
@@ -193,21 +193,21 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16
 // make this look as much like Carbon nsFilePicker as possible.  
 
   mFiles.Clear();
   nsCOMPtr<nsILocalFile> theFile;
 
   switch (mMode)
   {
     case modeOpen:
-      userClicksOK = GetLocalFiles(mTitle, PR_FALSE, mFiles);
+      userClicksOK = GetLocalFiles(mTitle, mDefault, PR_FALSE, mFiles);
       break;
     
     case modeOpenMultiple:
-      userClicksOK = GetLocalFiles(mTitle, PR_TRUE, mFiles);
+      userClicksOK = GetLocalFiles(mTitle, mDefault, PR_TRUE, mFiles);
       break;
       
     case modeSave:
       userClicksOK = PutLocalFile(mTitle, mDefault, getter_AddRefs(theFile));
       break;
       
     case modeGetFolder:
       userClicksOK = GetLocalFolder(mTitle, getter_AddRefs(theFile));
@@ -223,17 +223,17 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16
   
   *retval = userClicksOK;
   return NS_OK;
 }
 
 
 // Use OpenPanel to do a GetFile. Returns |returnOK| if the user presses OK in the dialog. 
 PRInt16
-nsFilePicker::GetLocalFiles(const nsString& inTitle, PRBool inAllowMultiple, nsCOMArray<nsILocalFile>& outFiles)
+nsFilePicker::GetLocalFiles(const nsString& inTitle, const nsString& inDefaultName, PRBool inAllowMultiple, nsCOMArray<nsILocalFile>& outFiles)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   PRInt16 retVal = (PRInt16)returnCancel;
   NSOpenPanel *thePanel = [NSOpenPanel openPanel];
 
   // Get filters
   // filters may be null, if we should allow all file types.
@@ -246,28 +246,32 @@ nsFilePicker::GetLocalFiles(const nsStri
   [thePanel setCanChooseDirectories:NO];
   [thePanel setCanChooseFiles:YES];
   [thePanel setResolvesAliases:YES];        //this is default - probably doesn't need to be set
   
   // if we show all file types, also "expose" bundles' contents.
   if (!filters)
     [thePanel setTreatsFilePackagesAsDirectories:NO];       
 
+  // set up default file name
+  NSString* defaultFilename = [NSString stringWithCharacters:(const unichar*)inDefaultName.get() length:inDefaultName.Length()];
+
   // 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/";
   }
 
   nsCocoaUtils::PrepareForNativeAppModalDialog();
-  int result = [thePanel runModalForDirectory:theDir file:nil types:filters];  
+  int result = [thePanel runModalForDirectory:theDir file:defaultFilename
+                types:filters];
   nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
   
   if (result == NSFileHandlingPanelCancelButton)
     return retVal;
   
   // append each chosen file to our list
   for (unsigned int i = 0; i < [[thePanel URLs] count]; i++) {
     NSURL *theURL = [[thePanel URLs] objectAtIndex:i];