Bug 445807 - Port |Bug 400248 Remove strres.js use in nsContextMenu.js| to SeaMonkey (Av1d) "Remove strres.js" part, r=IanN, sr=Neil
authorSerge Gautherie <sgautherie.bz@free.fr>
Mon, 18 Aug 2008 18:16:46 +0200
changeset 169 edb1732a88c3767a2c20a6652022acccc09abc19
parent 168 076411b96f5c9bf94d473b4b17cf3c5a3889397c
child 170 2854814076ae30ef0f997943f8e3a3e0c942cec8
push idunknown
push userunknown
push dateunknown
reviewersIanN, Neil
bugs445807, 400248
Bug 445807 - Port |Bug 400248 Remove strres.js use in nsContextMenu.js| to SeaMonkey (Av1d) "Remove strres.js" part, r=IanN, sr=Neil
suite/common/contentAreaContextOverlay.xul
suite/common/nsContextMenu.js
--- a/suite/common/contentAreaContextOverlay.xul
+++ b/suite/common/contentAreaContextOverlay.xul
@@ -36,18 +36,16 @@
    - the terms of any one of the MPL, the GPL or the LGPL.
    -
    - ***** END LICENSE BLOCK ***** -->
 <!DOCTYPE overlay SYSTEM "chrome://communicator/locale/contentAreaCommands.dtd" >
 <overlay id="contentAreaContextOverlay"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
   <!-- Context menu -->
-  <!-- XXX: Replace strres.js when nsContextMenu.js is converted -->
-  <script type="application/x-javascript" src="chrome://global/content/strres.js"/>
   <script type="application/x-javascript">
     // Global variable that holds the nsContextMenu instance.
     var gContextMenu = null;
     
     // Global variable that caches the default search engine info
     var gDefaultEngine = null;
   </script>
   <script type="application/x-javascript" src="chrome://global/content/inlineSpellCheckUI.js"/>
--- a/suite/common/nsContextMenu.js
+++ b/suite/common/nsContextMenu.js
@@ -692,21 +692,22 @@ nsContextMenu.prototype = {
     // Change current window to the URL of the background image.
     viewBGImage : function () {
         urlSecurityCheck( this.bgImageURL, this.target.nodePrincipal,
                           Components.interfaces.nsIScriptSecurityManager.ALLOW_CHROME );
         openTopWin( this.bgImageURL, this.target.ownerDocument.defaultView );
     },
     setWallpaper: function() {
       // Confirm since it's annoying if you hit this accidentally.
-      var promptService       = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
-      var gNavigatorBundle    = document.getElementById("bundle_navigator");
-      var promptTitle         = gNavigatorBundle.getString("wallpaperConfirmTitle");
-      var promptMsg           = gNavigatorBundle.getString("wallpaperConfirmMsg");
-      var promptConfirmButton = gNavigatorBundle.getString("wallpaperConfirmButton");
+      var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+                                    .getService(Components.interfaces.nsIPromptService);
+      var navigatorBundle = document.getElementById("bundle_navigator");
+      var promptTitle = navigatorBundle.getString("wallpaperConfirmTitle");
+      var promptMsg = navigatorBundle.getString("wallpaperConfirmMsg");
+      var promptConfirmButton = navigatorBundle.getString("wallpaperConfirmButton");
 
       var buttonPressed = promptService.confirmEx(window, promptTitle, promptMsg,
                                                    (promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0) +
                                                    (promptService.BUTTON_TITLE_CANCEL    * promptService.BUTTON_POS_1),
                                                    promptConfirmButton, null, null, null, {value:0});
  
       if (buttonPressed != 0)
         return;
@@ -876,39 +877,40 @@ nsContextMenu.prototype = {
               }
             }
           }
         }
 
         return text;
     },
 
-    //Get selected object and convert it to a string to get
-    //selected text.   Only use the first 15 chars.
-    isTextSelection : function() {
-        var result = false;
-        var selection = this.searchSelected(16);
-
-        var bundle = srGetStrBundle("chrome://communicator/locale/contentAreaCommands.properties");
+    /**
+     * Determines whether the focused window has selected text, and if so
+     * formats the first 15 characters for the label of the context-searchselect
+     * element according to the searchText string.
+     * @return true if there is selected text, false if not
+     */
+    isTextSelection : function isTextSelection() {
+      var searchSelectText = this.searchSelected(16);
+      if (!searchSelectText)
+        return false;
 
-        var searchSelectText;
-        if (selection != "") {
-            searchSelectText = selection.toString();
-            if (searchSelectText.length > 15)
-                searchSelectText = searchSelectText.substr(0,15) + "...";
-            result = true;
+      if (searchSelectText.length > 15)
+        searchSelectText = searchSelectText.substr(0, 15) + "...";
 
-          // format "Search for <selection>" string to show in menu
-          searchSelectText = bundle.formatStringFromName("searchText",
-                                                         [searchSelectText], 1);
-          this.setItemAttr("context-searchselect", "label", searchSelectText);
-          this.setItemAttr("context-searchselect", "accesskey", 
-                            bundle.GetStringFromName("searchText.accesskey"));
-        } 
-        return result;
+      // Format "Search for <selection>" string to show in menu.
+      // Use |getStringBundle()| from <contentAreaUtils.js>.
+      var bundle = getStringBundle();
+      searchSelectText = bundle.formatStringFromName("searchText",
+                                                     [searchSelectText], 1);
+      this.setItemAttr("context-searchselect", "label", searchSelectText);
+      this.setItemAttr("context-searchselect", "accesskey",
+                       bundle.GetStringFromName("searchText.accesskey"));
+
+      return true;
     },
     
     searchSelected : function( charlen ) {
         var focusedWindow = document.commandDispatcher.focusedWindow;
         var searchStr = focusedWindow.getSelection();
         searchStr = searchStr.toString();
         // searching for more than 150 chars makes no sense
         if (!charlen)