Bug 102275 - Number untitled pages. r=Neil, sr=Standard8
authorEdmund Wong <ewong@pw-wspx.org>
Thu, 08 Dec 2011 09:40:49 +0800
changeset 9955 a5059b3c07fb56373520e045f4b3a10e575c0dc2
parent 9954 778c81627f48a7370d1ba5a2cec42e43229ecff3
child 9956 64a900fced079949eeea35135fca687b9300b178
push id336
push userbugzilla@standard8.plus.com
push dateTue, 31 Jan 2012 22:15:45 +0000
treeherdercomm-beta@54945f5d278d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil, Standard8
bugs102275
Bug 102275 - Number untitled pages. r=Neil, sr=Standard8
editor/ui/Makefile.in
editor/ui/composer/content/ComposerCommands.js
editor/ui/composer/content/editor.js
editor/ui/composer/content/editorUtilities.js
editor/ui/dialogs/content/EditorPublishProgress.js
editor/ui/editorUtilities.jsm
editor/ui/locales/en-US/chrome/composer/editor.properties
--- a/editor/ui/Makefile.in
+++ b/editor/ui/Makefile.in
@@ -48,9 +48,13 @@ DIRS           = \
 
 ifndef MOZ_STANDALONE_COMPOSER
 PREF_JS_EXPORTS = $(srcdir)/composer.js
 ifdef MOZ_SUITE
 EXTRA_COMPONENTS = nsComposerCmdLineHandler.manifest nsComposerCmdLineHandler.js
 endif
 endif
 
+EXTRA_JS_MODULES += \
+  editorUtilities.jsm \
+  $(NULL)
+
 include $(topsrcdir)/config/rules.mk
--- a/editor/ui/composer/content/ComposerCommands.js
+++ b/editor/ui/composer/content/ComposerCommands.js
@@ -805,18 +805,18 @@ function GetSuggestedFileName(aDocumentU
       // 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 "untitled"
-  var title = validateFileName(GetDocumentTitle()) || GetString("untitled");
+  // if we can't, just go with gUntitledString
+  var title = validateFileName(GetDocumentTitle()) || gUntitledString;
   return title + extension;
 }
 
 // returns file picker result
 function PromptForSaveLocation(aDoSaveAsText, aEditorType, aMIMEType, aDocumentURLString)
 {
   var dialogResult = {};
   dialogResult.filepickerClick = nsIFilePicker.returnCancel;
@@ -2098,17 +2098,17 @@ var nsRevertCommand =
   {
     // 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 = GetString("untitled");
+        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});
 
--- a/editor/ui/composer/content/editor.js
+++ b/editor/ui/composer/content/editor.js
@@ -35,16 +35,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+Components.utils.import("resource:///modules/editorUtilities.jsm");
+
 /* Main Composer window UI control */
 
 var gComposerWindowControllerID = 0;
 var prefAuthorString = "";
 
 const kDisplayModeNormal = 0;
 const kDisplayModeAllTags = 1;
 const kDisplayModeSource = 2;
@@ -219,16 +221,18 @@ function EditorOnLoad()
         var arrayArgComponents = window.arguments[1].split("=");
         if (arrayArgComponents) {
           // Put argument where EditorStartup expects it.
           document.getElementById( "args" ).setAttribute("charset", arrayArgComponents[1]);
         }
       }
     }
 
+    gUntitledString = GetFormattedString("untitledTitle", GetNextUntitledValue());
+
     // Continue with normal startup.
     EditorStartup();
 
     // Initialize our source text <editor>
     try {
       gSourceContentWindow = document.getElementById("content-source");
       gSourceContentWindow.makeEditable("text", false);
       gSourceTextEditor = gSourceContentWindow.getEditor(gSourceContentWindow.contentWindow);
@@ -828,17 +832,17 @@ function CheckAndSaveDocument(command, a
       strID = "BeforeValidate";
       break;
   }
     
   var reasonToSave = strID ? GetString(strID) : "";
 
   var title = document.title;
   if (!title)
-    title = GetString("untitled");
+    title = gUntitledString;
 
   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;
@@ -2075,17 +2079,18 @@ function UpdateWindowTitle()
 
       var fileType = IsHTMLEditor() ? "html" : "text";
       // Save changed title in the recent pages data in prefs
       SaveRecentFilesPrefs(title, fileType);
     }
 
     // Set window title with " - Composer" or " - Text Editor" appended.
     var xulWin = document.documentElement;
-    document.title = (title || filename || GetString("untitled")) +
+
+    document.title = (title || filename || gUntitledString) +
                      windowTitle +
                      xulWin.getAttribute("titlemenuseparator") + 
                      xulWin.getAttribute("titlemodifier");
   } catch (e) { dump(e); }
 }
 
 function SaveRecentFilesPrefs(aTitle, aFileType)
 {
--- a/editor/ui/composer/content/editorUtilities.js
+++ b/editor/ui/composer/content/editorUtilities.js
@@ -130,16 +130,37 @@ function GetString(name)
   {
     try {
       return gStringBundle.GetStringFromName(name);
     } catch (e) {}
   }
   return null;
 }
 
+function GetFormattedString(aName, aVal)
+{
+  if (!gStringBundle)
+  {
+    try {
+      var gStringBundle =
+          Components.classes["@mozilla.org/intl/stringbundle;1"]
+                    .getService(Components.interfaces.nsIStringBundleService)
+                    .createBundle("chrome://editor/locale/editor.properties"); 
+
+    } catch (ex) {}
+  }
+  if (gStringBundle)
+  {
+    try {
+      return gStringBundle.formatStringFromName(aName, [aVal], 1);
+    } catch (e) {}
+  }
+  return null;
+}
+
 function TrimStringLeft(string)
 {
   if(!string) return "";
   return string.trimLeft();
 }
 
 function TrimStringRight(string)
 {
--- a/editor/ui/dialogs/content/EditorPublishProgress.js
+++ b/editor/ui/dialogs/content/EditorPublishProgress.js
@@ -105,17 +105,17 @@ function Startup()
   gDialog.FinalStatusMessage = document.getElementById("FinalStatusMessage");
   gDialog.StatusMessage      = document.getElementById("StatusMessage");
   gDialog.KeepOpen           = document.getElementById("KeepOpen");
   gDialog.Close              = document.documentElement.getButton("cancel");
 
   SetWindowLocation();
   var title = GetDocumentTitle();
   if (!title)
-    title = "("+GetString("untitled")+")";
+    title = "(" + opener.gUntitledString + ")";
   document.title = GetString("PublishProgressCaption").replace(/%title%/, title);
 
   document.getElementById("PublishToSite").value = 
     GetString("PublishToSite").replace(/%title%/, TruncateStringAtWordEnd(gPublishData.siteName, 25)); 
 
   // Show publishing destination URL
   document.getElementById("PublishUrl").value = gPublishData.publishUrl;
   
new file mode 100644
--- /dev/null
+++ b/editor/ui/editorUtilities.jsm
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is editor utility code.
+ *
+ * The Initial Developer of the Original Code is
+ * the SeaMonkey Project.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Edmund Wong <ewong@pw-wspx.org>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var EXPORTED_SYMBOLS = ["GetNextUntitledValue"];
+
+var sUntitledCount = 1;
+
+function GetNextUntitledValue()
+{
+  return sUntitledCount++;
+}
--- a/editor/ui/locales/en-US/chrome/composer/editor.properties
+++ b/editor/ui/locales/en-US/chrome/composer/editor.properties
@@ -105,17 +105,18 @@ Style_I=I, II, III…
 Style_i=i, ii, iii…
 Style_A=A, B, C…
 Style_a=a, b, c…
 Pixels=pixels
 Percent=percent
 PercentOfCell=% of cell
 PercentOfWindow=% of window
 PercentOfTable=% of table
-untitled=untitled
+#LOCALIZATION NOTE (untitledTitle): %S is the window #.  No plural handling needed.
+untitledTitle=untitled-%S
 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