Bug 601029 - Add a context menu with a "copy" command to error console rows [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 01 Oct 2010 08:27:12 -0700
changeset 66769 1ab14c62101bcebae79cba4ac69d317ebd08ccac
parent 66768 1f38ed5cc8d5407fc2ba64f6e97139cd9e2a940d
child 66770 f8a065a7f869307e584589a0bcdd99d9976342b0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs601029
Bug 601029 - Add a context menu with a "copy" command to error console rows [r=mfinkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.xul
mobile/chrome/content/console.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -2432,17 +2432,17 @@ var ContextHelper = {
       return false;
     }
 
     // Allow the first and last *non-hidden* elements to be selected in CSS.
     first.setAttribute("selector", "first-child");
     last.setAttribute("selector", "last-child");
 
     let label = document.getElementById("context-hint");
-    label.value = this.popupState.label;
+    label.value = this.popupState.label || "";
 
     this._panel.hidden = false;
     window.addEventListener("resize", this, true);
 
     this.sizeToContent();
     BrowserUI.pushPopup(this, [this._popup]);
     return true;
   },
@@ -2460,16 +2460,21 @@ var ContextHelper = {
   },
 
   handleEvent: function handleEvent(aEvent) {
     this.sizeToContent();
   }
 };
 
 var ContextCommands = {
+  copy: function cc_copy() {
+    let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
+    clipboard.copyString(ContextHelper.popupState.string);
+  },
+
   openInNewTab: function cc_openInNewTab() {
     Browser.addTab(ContextHelper.popupState.linkURL, false, Browser.selectedTab);
   },
 
   saveLink: function cc_saveLink() {
     let browser = ContextHelper.popupState.target;
     saveURL(ContextHelper.popupState.linkURL, null, "SaveLinkTitle", false, true, browser.documentURI);
   },
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -483,17 +483,17 @@
                   <radio id="console-filter-messages" label="&consoleMessages.label;" value="message"/>
                   <radio id="console-filter-warnings" label="&consoleWarnings.label;" value="warning"/>
                   <radio id="console-filter-errors" label="&consoleErrors.label;" value="error"/>
                 </radiogroup>
                 <button id="console-clear" class="button-dark show-text" oncommand="ConsoleView.clearConsole();" label="&consoleClear.label;"/>
               </hbox>
             </vbox>
 
-            <richlistbox id="console-box" class="console-box" flex="1" onkeypress="ConsoleView.onConsoleBoxKeyPress(event)"/>
+            <richlistbox id="console-box" class="console-box" flex="1" onkeypress="ConsoleView.onConsoleBoxKeyPress(event)" oncontextmenu="ConsoleView.onContextMenu(event);"/>
           </vbox>
         </deck>
       </vbox>
     </vbox>
 
     <vbox id="awesome-panels" hidden="true">
       <!-- Awesome header row -->
       <hbox id="awesome-header">
@@ -536,16 +536,19 @@
     </hbox>
 
     <hbox id="context-container" class="window-width window-height context-block" top="0" left="0" hidden="true">
       <vbox id="context-popup" class="dialog-dark">
         <hbox id="context-header">
           <label id="context-hint" crop="center" flex="1"/>
         </hbox>
         <richlistbox id="context-commands" onclick="ContextHelper.hide();" flex="1">
+          <richlistitem class="context-command" id="context-copy" type="copy" onclick="ContextCommands.copy();">
+            <label value="&copy.label;"/>
+          </richlistitem>
           <richlistitem class="context-command" id="context-openinnewtab" type="link-saveable" onclick="ContextCommands.openInNewTab();">
             <label value="&contextOpenInNewTab.label;"/>
           </richlistitem>
           <richlistitem class="context-command" id="context-savelink" type="link-saveable" onclick="ContextCommands.saveLink();">
             <label value="&contextSaveLink.label;"/>
           </richlistitem>
           <richlistitem class="context-command" id="context-saveimage" type="image-loaded" onclick="ContextCommands.saveImage();">
             <label value="&contextSaveImage.label;"/>
--- a/mobile/chrome/content/console.js
+++ b/mobile/chrome/content/console.js
@@ -52,16 +52,17 @@ let ConsoleView = {
     this._evalTextbox = document.getElementById("console-eval-textbox");
     this._bundle = Elements.browserBundle;
 
     this._count = 0;
     this.limit = 250;
 
     let self = this;
     let panels = document.getElementById("panel-items");
+
     panels.addEventListener("select",
                             function(aEvent) {
                               if (panels.selectedPanel.id == "console-container")
                                 self._delayedInit();
                             },
                             false);
   },
 
@@ -249,16 +250,30 @@ let ConsoleView = {
         else
           row.collapsed = true;
       }
       this._list.mode = mode;
       this._list.scrollToIndex(0);
     }
   },
 
+  onContextMenu: function cv_onContextMenu(aEvent) {
+    let row = aEvent.target;
+    let text = ["msg", "href", "line", "code", "col"].map(function(attr) row.getAttribute(attr))
+               .filter(function(x) x).join("\n");
+
+    ContextHelper.showPopup({
+      target: row,
+      json: {
+        types: ["copy"],
+        string: text
+      }
+    });
+  },
+
   onEvalKeyPress: function cv_onEvalKeyPress(aEvent) {
     if (aEvent.keyCode == 13)
       this.evaluateTypein();
   },
 
   onConsoleBoxKeyPress: function cv_onConsoleBoxKeyPress(aEvent) {
     if ((aEvent.charCode == 99 || aEvent.charCode == 67) && aEvent.ctrlKey && this._list && this._list.selectedItem) {
       let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);