Bug 718480: Unable to save new message as file when subject is empty. r=neil
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Mon, 12 Mar 2012 21:34:34 +0200
changeset 11064 ba06afbb5121723325afa002abecb722e97065ca
parent 11063 d5c44c6980e4f211f6c465a929d2e93e892a50af
child 11065 4c05177d7f2a1e3ecb9f2c20c7bad555515f0f8c
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs718480
Bug 718480: Unable to save new message as file when subject is empty. r=neil
editor/ui/composer/content/ComposerCommands.js
editor/ui/composer/content/editor.js
editor/ui/locales/en-US/chrome/composer/editor.properties
--- a/editor/ui/composer/content/ComposerCommands.js
+++ b/editor/ui/composer/content/ComposerCommands.js
@@ -788,35 +788,35 @@ function GetExtensionBasedOnMimeType(aMI
 
 function GetSuggestedFileName(aDocumentURLString, aMIMEType)
 {
   var extension = GetExtensionBasedOnMimeType(aMIMEType);
   if (extension)
     extension = "." + extension;
 
   // check for existing file name we can use
-  if (aDocumentURLString.length >= 0 && !IsUrlAboutBlank(aDocumentURLString))
+  if (aDocumentURLString && !IsUrlAboutBlank(aDocumentURLString))
   {
-    var docURI = null;
     try {
-
       var ioService = GetIOService();
-      docURI = ioService.newURI(aDocumentURLString, GetCurrentEditor().documentCharacterSet, null);
+      var docURI = ioService.newURI(aDocumentURLString,
+        GetCurrentEditor().documentCharacterSet, null);
       docURI = docURI.QueryInterface(Components.interfaces.nsIURL);
 
       // grab the file name
       var url = validateFileName(decodeURIComponent(docURI.fileBaseName));
       if (url)
         return url+extension;
     } catch(e) {}
   } 
 
-  // check if there is a title we can use to generate a valid filename,
-  // if we can't, just go with gUntitledString
-  var title = validateFileName(GetDocumentTitle()) || gUntitledString;
+  // Check if there is a title we can use to generate a valid filename,
+  // if we can't, use the default filename.
+  var title = validateFileName(GetDocumentTitle()) ||
+              GetString("untitledDefaultFilename");
   return title + extension;
 }
 
 // returns file picker result
 function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, aDocumentURLString)
 {
   var dialogResult = {};
   dialogResult.filepickerClick = nsIFilePicker.returnCancel;
@@ -894,25 +894,28 @@ function PromptForSaveLocation(aDoSaveAs
     SaveFilePickerDirectory(fp, aEditorType);
   }
   else if ("gFilePickerDirectory" in window && gFilePickerDirectory)
     fp.displayDirectory = gFilePickerDirectory; 
 
   return dialogResult;
 }
 
-// returns a boolean (whether to continue (true) or not (false) because user canceled)
+/**
+ * If needed, prompt for document title and set the document title to the
+ * preferred value.
+ * @return true if the title was set up successfully;
+ *         false if the user cancelled the title prompt
+ */
 function PromptAndSetTitleIfNone()
 {
   if (GetDocumentTitle()) // we have a title; no need to prompt!
     return true;
 
   var promptService = GetPromptService();
-  if (!promptService) return false;
-
   var result = {value:null};
   var captionStr = GetString("DocumentTitle");
   var msgStr = GetString("NeedDocTitle") + '\n' + GetString("DocTitleHelp");
   var confirmed = promptService.prompt(window, captionStr, msgStr, result, null, {value:0});
   if (confirmed)
     SetDocumentTitle(TrimString(result.value));
 
   return confirmed;
@@ -1707,17 +1710,20 @@ function SaveDocument(aSaveAs, aSaveCopy
 
 	    replacing = (dialogResult.filepickerClick == nsIFilePicker.returnReplace);
 	    urlstring = dialogResult.resultingURIString;
 	    tempLocalFile = dialogResult.resultingLocalFile;
  
       // update the new URL for the webshell unless we are saving a copy
       if (!aSaveCopy)
         doUpdateURI = true;
-   } catch (e) {  return false; }
+    } catch (e) {
+       Components.utils.reportError(e);
+       return false; 
+    }
   } // mustShowFileDialog
 
   var success = true;
   var ioService;
   try {
     // if somehow we didn't get a local file but we did get a uri, 
     // attempt to create the localfile if it's a "file" url
     var docURI;
@@ -2097,19 +2103,16 @@ var nsRevertCommand =
   doCommand: function(aCommand)
   {
     // Confirm with the user to abandon current changes
     var promptService = GetPromptService();
     if (promptService)
     {
       // Put the page title in the message string
       var title = GetDocumentTitle();
-      if (!title)
-        title = gUntitledString;
-
       var msg = GetString("AbandonChanges").replace(/%title%/,title);
 
       var result = promptService.confirmEx(window, GetString("RevertCaption"), msg,
   						      (promptService.BUTTON_TITLE_REVERT * promptService.BUTTON_POS_0) +
   						      (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
   						      null, null, null, null, {value:0});
 
       // Reload page if first button (Revert) was pressed
--- a/editor/ui/composer/content/editor.js
+++ b/editor/ui/composer/content/editor.js
@@ -691,27 +691,23 @@ function CheckAndSaveDocument(command, a
       break;
     case "cmd_validate":
       strID = "BeforeValidate";
       break;
   }
     
   var reasonToSave = strID ? GetString(strID) : "";
 
-  var title = document.title;
-  if (!title)
-    title = gUntitledString;
+  var title = document.title || GetString("untitledDefaultFilename");
 
   var dialogTitle = GetString(doPublish ? "PublishPage" : "SaveDocument");
   var dialogMsg = GetString(doPublish ? "PublishPrompt" : "SaveFilePrompt");
   dialogMsg = (dialogMsg.replace(/%title%/,title)).replace(/%reason%/,reasonToSave);
 
   var promptService = GetPromptService();
-  if (!promptService)
-    return false;
 
   var result = {value:0};
   var promptFlags = promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1;
   var button1Title = null;
   var button3Title = null;
 
   if (doPublish)
   {
--- a/editor/ui/locales/en-US/chrome/composer/editor.properties
+++ b/editor/ui/locales/en-US/chrome/composer/editor.properties
@@ -107,16 +107,17 @@ Style_A=A, B, C…
 Style_a=a, b, c…
 Pixels=pixels
 Percent=percent
 PercentOfCell=% of cell
 PercentOfWindow=% of window
 PercentOfTable=% of table
 #LOCALIZATION NOTE (untitledTitle): %S is the window #.  No plural handling needed.
 untitledTitle=untitled-%S
+untitledDefaultFilename=untitled
 ShowToolbar=Show Toolbar
 HideToolbar=Hide Toolbar
 ImapError=Unable to load image 
 ImapCheck=\nPlease select a new location (URL) and try again.
 SaveToUseRelativeUrl=Relative URLs can only be used on pages which have been saved
 NoNamedAnchorsOrHeadings=(No named anchors or headings in this page)
 TextColor=Text Color
 HighlightColor=Highlight Color