Bug 862019 - Add Ctrl-C listener to Variables View for copying items, r=vporof

This commit is contained in:
Brian Mooney 2013-10-06 14:17:14 +03:00
parent f097865b72
commit 868038d725
2 changed files with 45 additions and 0 deletions

View File

@ -476,6 +476,28 @@ function performTest() {
is(gVariablesView.getFocusedItem().visible, false, is(gVariablesView.getFocusedItem().visible, false,
"The 'someProp7' variable should be hidden."); "The 'someProp7' variable should be hidden.");
// Part 11: Test that Ctrl-C copies the current item to the system clipboard
gVariablesView.focusFirstVisibleItem();
let copied = promise.defer();
let expectedValue = gVariablesView.getFocusedItem().name
+ gVariablesView.getFocusedItem().separatorStr
+ gVariablesView.getFocusedItem().value;
waitForClipboard(expectedValue, function setup() {
EventUtils.synthesizeKey("C", { metaKey: true }, gDebugger);
}, copied.resolve, copied.reject
);
try {
yield copied.promise;
ok(true,
"Ctrl-C copied the selected item to the clipboard.");
} catch (e) {
ok(false,
"Ctrl-C didn't copy the selected item to the clipboard.");
}
yield closeDebuggerAndFinish(gPanel); yield closeDebuggerAndFinish(gPanel);
}); });
} }

View File

@ -25,6 +25,10 @@ Cu.import("resource:///modules/devtools/shared/event-emitter.js");
XPCOMUtils.defineLazyModuleGetter(this, "devtools", XPCOMUtils.defineLazyModuleGetter(this, "devtools",
"resource://gre/modules/devtools/Loader.jsm"); "resource://gre/modules/devtools/Loader.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "clipboardHelper",
"@mozilla.org/widget/clipboardhelper;1",
"nsIClipboardHelper");
Object.defineProperty(this, "WebConsoleUtils", { Object.defineProperty(this, "WebConsoleUtils", {
get: function() { get: function() {
return devtools.require("devtools/toolkit/webconsole/utils").Utils; return devtools.require("devtools/toolkit/webconsole/utils").Utils;
@ -77,11 +81,13 @@ this.VariablesView = function VariablesView(aParentNode, aFlags = {}) {
this._onSearchboxInput = this._onSearchboxInput.bind(this); this._onSearchboxInput = this._onSearchboxInput.bind(this);
this._onSearchboxKeyPress = this._onSearchboxKeyPress.bind(this); this._onSearchboxKeyPress = this._onSearchboxKeyPress.bind(this);
this._onViewKeyPress = this._onViewKeyPress.bind(this); this._onViewKeyPress = this._onViewKeyPress.bind(this);
this._onViewKeyDown = this._onViewKeyDown.bind(this);
// Create an internal scrollbox container. // Create an internal scrollbox container.
this._list = this.document.createElement("scrollbox"); this._list = this.document.createElement("scrollbox");
this._list.setAttribute("orient", "vertical"); this._list.setAttribute("orient", "vertical");
this._list.addEventListener("keypress", this._onViewKeyPress, false); this._list.addEventListener("keypress", this._onViewKeyPress, false);
this._list.addEventListener("keydown", this._onViewKeyDown, false);
this._parent.appendChild(this._list); this._parent.appendChild(this._list);
this._boxObject = this._list.boxObject.QueryInterface(Ci.nsIScrollBoxObject); this._boxObject = this._list.boxObject.QueryInterface(Ci.nsIScrollBoxObject);
@ -180,7 +186,9 @@ VariablesView.prototype = {
this.window.setTimeout(() => { this.window.setTimeout(() => {
prevList.removeEventListener("keypress", this._onViewKeyPress, false); prevList.removeEventListener("keypress", this._onViewKeyPress, false);
prevList.removeEventListener("keydown", this._onViewKeyDown, false);
currList.addEventListener("keypress", this._onViewKeyPress, false); currList.addEventListener("keypress", this._onViewKeyPress, false);
currList.addEventListener("keydown", this._onViewKeyDown, false);
currList.setAttribute("orient", "vertical"); currList.setAttribute("orient", "vertical");
this._parent.removeChild(prevList); this._parent.removeChild(prevList);
@ -819,6 +827,21 @@ VariablesView.prototype = {
} }
}, },
/**
* Listener handling a key down event on the view.
*/
_onViewKeyDown: function(e) {
if (e.keyCode == e.DOM_VK_C) {
// Copy current selection to clipboard.
if (e.ctrlKey || e.metaKey) {
let item = this.getFocusedItem();
clipboardHelper.copyString(
item._nameString + item.separatorStr + item._valueString
);
}
}
},
/** /**
* The number of elements in this container to jump when Page Up or Page Down * The number of elements in this container to jump when Page Up or Page Down
* keys are pressed. If falsy, then the page size will be based on the * keys are pressed. If falsy, then the page size will be based on the