Bug 601029 - Add a context menu with a "copy" command to error console rows [r=mfinkle]
--- 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="©.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);