Bug 366479 - [mac] Copy command is broken in the JS console. r=gavin,neil. sr=neil.
authormozilla.mano@sent.com
Thu, 22 Mar 2007 16:28:22 -0700
changeset 10 01acfb40a3e7a0c9b3704b44ff66e7984eecddc8
parent 9 2a109d05f223b3eb06487e0e600c5cbc333ef47a
child 11 68b7f903ae7fb59647e9af5ab64c6688d183aedc
push idunknown
push userunknown
push dateunknown
reviewersgavin, neil, neil
bugs366479
milestone1.9a3pre
Bug 366479 - [mac] Copy command is broken in the JS console. r=gavin,neil. sr=neil.
toolkit/components/console/content/console.js
toolkit/components/console/content/console.xul
toolkit/components/console/content/consoleBindings.xml
--- a/toolkit/components/console/content/console.js
+++ b/toolkit/components/console/content/console.js
@@ -92,31 +92,16 @@ function updateSortCommand(aOrder)
 }
 
 function updateModeCommand(aMode)
 {
   var bc = document.getElementById("Console:mode" + aMode);
   bc.setAttribute("checked", true);
 }
 
-function copyItemToClipboard()
-{
-  gConsole.copySelectedItem();
-}
-
-function isItemSelected()
-{
-  return gConsole.selectedItem != null;
-}
-
-function updateCopyMenu()
-{
-  goSetCommandEnabled("cmd_copy", isItemSelected())
-}
-
 function onEvalKeyPress(aEvent)
 {
   if (aEvent.keyCode == 13)
     evaluateTypein();
 }
 
 function evaluateTypein()
 {
--- a/toolkit/components/console/content/console.xul
+++ b/toolkit/components/console/content/console.xul
@@ -36,16 +36,17 @@
 # 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 *****
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> 
 <?xml-stylesheet href="chrome://global/skin/console/console.css" type="text/css"?> 
 <?xml-stylesheet href="chrome://global/content/console.css" type="text/css"?> 
+<?xul-overlay href="chrome://global/content/editMenuOverlay.xul"?>
 
 <!DOCTYPE window [
   <!ENTITY % console SYSTEM "chrome://global/locale/console.dtd"> %console;
 ]>
 
 <window id="JSConsoleWindow"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         title="&errorConsole.title;"
@@ -55,21 +56,19 @@
         persist="screenX screenY width height sizemode"
         onclose="return closeWindow(false);"> 
 
   <script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
   <script type="application/x-javascript" src="chrome://global/content/console.js"/>
 
   <stringbundle id="ConsoleBundle" src="chrome://global/locale/console.properties"/>
 
-  <commandset id="consoleCommands"
-              commandupdater="true"
-              events="select"
-              oncommandupdate="updateCopyMenu()">
-    <command id="cmd_copy" oncommand="copyItemToClipboard()"/>
+  <commandset id="editMenuCommands"/>
+
+  <commandset id="consoleCommands">
     <command id="cmd_close" oncommand="closeWindow(true)"/>
   </commandset>
 
   <broadcaster id="Console:clear" label="&clear.label;" 
                accesskey="&clear.accesskey;"
                oncommand="clearConsole();"/>
   <broadcaster id="Console:sortAscend" label="&sortFirst.label;" 
                accesskey="&sortFirst.accesskey;"
@@ -89,33 +88,31 @@
                  label="&warnings.label;" accesskey="&warnings.accesskey;"
                  oncommand="changeMode('Warnings');"/>
     <broadcaster id="Console:modeMessages"
                  label="&messages.label;" accesskey="&messages.accesskey;"
                  oncommand="changeMode('Messages');"/>
   </broadcasterset>
 
   <keyset id="consoleKeys">
-    <key id="key_copy"  key="&copyCmd.commandkey;"  modifiers="accel"
-         command="cmd_copy"/>
     <key id="key_close" key="&closeCmd.commandkey;" modifiers="accel"
          command="cmd_close"/>
     <key keycode="VK_ESCAPE" command="cmd_close"/>
     <key id="key_focus1" key="&focus1.commandkey;" modifiers="accel"
          oncommand="gTextBoxEval.focus()"/>
     <key id="key_focus2" key="&focus2.commandkey;" modifiers="alt"
          oncommand="gTextBoxEval.focus()"/>
   </keyset>
 
   <popupset id="ContextMenus">
     <popup id="ConsoleContext">
       <menuitem type="radio" observes="Console:sortAscend"/>
       <menuitem type="radio" observes="Console:sortDescend"/>
       <menuseparator/>
-      <menuitem id="menu_copy_cm" observes="cmd_copy" label="&copyCmd.label;" key="key_copy" accesskey="&copyCmd.accesskey;"/>
+      <menuitem id="menu_copy_cm" command="cmd_copy" label="&copyCmd.label;" accesskey="&copyCmd.accesskey;"/>
     </popup>
   </popupset>
   
   <toolbox id="console-toolbox">
     <toolbar class="chromeclass-toolbar" id="ToolbarMode">
       <toolbarbutton type="radio" group="mode" observes="Console:modeAll"/>
       <toolbarbutton type="radio" group="mode" observes="Console:modeErrors"/>
       <toolbarbutton type="radio" group="mode" observes="Console:modeWarnings"/>
@@ -130,10 +127,8 @@
     </toolbar>
   </toolbox>
   
   <vbox id="ConsoleBox" class="console-box" flex="1" context="ConsoleContext" persist="sortOrder"/>
 
   <iframe name="Evaluator" id="Evaluator" collapsed="true" src="chrome://global/content/blank.html"/>
 
 </window>
-
-
--- a/toolkit/components/console/content/consoleBindings.xml
+++ b/toolkit/components/console/content/consoleBindings.xml
@@ -58,16 +58,19 @@
       <property name="selectedItem">
         <getter>return this.mSelectedItem</getter>
         <setter><![CDATA[
           if (this.mSelectedItem)
             this.mSelectedItem.removeAttribute("selected");
           
           this.mSelectedItem = val;
           val.setAttribute("selected", "true");
+
+          // Update edit commands
+          window.updateCommands("focus");
         ]]></setter>
       </property>
     
       <method name="init">
         <body><![CDATA[
           this.mCount = 0;
           
           this.mConsoleListener = {
@@ -87,25 +90,26 @@
               "Unable to display errors - couldn't get Console Service component. " +
               "(Missing @mozilla.org/consoleservice;1)");
             return;
           }          
                     
           this.mMode = this.getAttribute("mode") || "All";
 
           this.appendInitialItems();
+          window.controllers.insertControllerAt(0, this._controller);
         ]]></body>
       </method>
-    
+
       <method name="destroy">
         <body><![CDATA[
           this.mCService.unregisterListener(this.mConsoleListener);
         ]]></body>
       </method>
-    
+
       <method name="appendInitialItems">
         <body><![CDATA[
           var out = {}; // Throwaway references to support 'out' parameters.
           this.mCService.getMessageArray(out, {});
           var messages = out.value;
       
           // In case getMessageArray returns 0-length array as null
           if (!messages)
@@ -273,16 +277,43 @@
             aChar += aChar;
 
           return aChar + aChar.slice(0, aCol - aChar.length);
         ]]></body>
       </method>
           
       <constructor> this.init(); </constructor>
       <destructor> this.destroy(); </destructor>
+
+      <!-- Command controller for the copy command -->
+      <field name="_controller"><![CDATA[({
+        _outer: this,
+
+        QueryInterface: function(aIID) {
+          if (aIID.equals(Components.interfaces.nsIController) ||
+              aIID.equals(Components.interfaces.nsISupports))
+            return this;
+          throw Components.results.NS_NOINTERFACE;
+        },
+
+        supportsCommand: function(aCommand) {
+          return aCommand == "cmd_copy";
+        },
+
+        isCommandEnabled: function(aCommand) {
+          return aCommand == "cmd_copy" && this._outer.selectedItem;
+        },
+
+        doCommand: function(aCommand) {
+          if (aCommand == "cmd_copy")
+            this._outer.copySelectedItem();
+        },
+
+        onEvent: function() { }
+      });]]></field>
     </implementation>
     
     <handlers>
       <handler event="mousedown"><![CDATA[
         if (event.button == 0 || event.button == 2) {
           var target = event.originalTarget;
   
           while (target && !("_IsConsoleRow" in target))
@@ -346,19 +377,18 @@
           }
           
           if (this.hasAttribute("code"))
             msg += "\n" + strBundle.getString("errCode") + "\n" + this.getAttribute("code");
           
           return msg;
         ]]></body>
       </method>
-      
     </implementation>
-    
+
   </binding>
   
   <binding id="message" extends="xul:box">
     <content>
       <xul:box class="console-internal-box" flex="1">
         <xul:box class="console-row-icon" align="center">
           <xul:image class="console-icon" xbl:inherits="src,type"/>
         </xul:box>