From f247d9d01b401474540b2ecf1a62245597180c8d Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 19 Sep 2011 15:39:21 -0400 Subject: [PATCH] Add third argument to dactyl.clipboardWrite. --- common/content/dactyl.js | 30 +++++++++++++++++++++--------- common/modules/commands.jsm | 2 +- common/modules/services.jsm | 3 +++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 26029ea8..53305344 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -349,9 +349,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { */ clipboardRead: function clipboardRead(getClipboard) { try { - const clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard); - const transferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable); + const { clipboard } = services; + let transferable = services.Transferable(); transferable.addDataFlavor("text/unicode"); let source = clipboard[getClipboard || !clipboard.supportsSelectionClipboard() ? @@ -373,12 +373,21 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * Copies a string to the system clipboard. If *verbose* is specified the * copied string is also echoed to the command line. * - * @param {string} str - * @param {boolean} verbose + * @param {string} str The string to write. + * @param {boolean} verbose If true, the user is notified of the copied data. + * @param {string} which Which clipboard to write to. Either + * "global" or "selection". If not provided, both clipboards are + * updated. + * @optional */ - clipboardWrite: function clipboardWrite(str, verbose) { - const clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper); - clipboardHelper.copyString(str); + clipboardWrite: function clipboardWrite(str, verbose, which) { + if (!which) + services.clipboardHelper.copyString(str); + else if (which == "selection" && !services.clipboard.supportsSelectionClipboard()) + return; + else + services.clipboardHelper.copyStringToClipboard(str, + services.clipboard["k" + util.capitalize(which) + "Clipboard"]); if (verbose) { let message = { message: _("dactyl.yank", str) }; @@ -416,8 +425,10 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { echoerr: function echoerr(str, flags) { flags |= commandline.APPEND_TO_MESSAGES; - if (isinstance(str, ["DOMException", "Error", "Exception"]) || isinstance(str, ["XPCWrappedNative_NoHelper"]) && /^\[Exception/.test(str)) + if (isinstance(str, ["DOMException", "Error", "Exception"]) + || isinstance(str, ["XPCWrappedNative_NoHelper"]) && /^\[Exception/.test(str)) dactyl.reportError(str); + if (isObject(str) && "echoerr" in str) str = str.echoerr; else if (isinstance(str, ["Error", FailedAssertion]) && str.fileName) @@ -1207,7 +1218,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { if (error instanceof FailedAssertion && error.noTrace || error.message === "Interrupted") { let context = contexts.context; let prefix = context ? context.file + ":" + context.line + ": " : ""; - if (error.message && error.message.indexOf(prefix) !== 0) + if (error.message && error.message.indexOf(prefix) !== 0 && + prefix != "[Command Line]:1: ") error.message = prefix + error.message; if (error.message) diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 45b4d0d6..0fb9a065 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -1182,7 +1182,7 @@ var Commands = Module("commands", { (?P [:\s]*) (?P (?:\d+ | %)? ) (?P - (?: (?P ) : )? + (?: (?P ) : )? (?P (?:-? [()] | | !)? )) (?P !?) (?P \s*) diff --git a/common/modules/services.jsm b/common/modules/services.jsm index 8d9273bb..b69522c0 100644 --- a/common/modules/services.jsm +++ b/common/modules/services.jsm @@ -29,6 +29,8 @@ var Services = Module("Services", { this.add("cache", "@mozilla.org/network/cache-service;1", "nsICacheService"); this.add("charset", "@mozilla.org/charset-converter-manager;1", "nsICharsetConverterManager"); this.add("chromeRegistry", "@mozilla.org/chrome/chrome-registry;1", "nsIXULChromeRegistry"); + this.add("clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard"); + this.add("clipboardHelper", "@mozilla.org/widget/clipboardhelper;1", "nsIClipboardHelper"); this.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=dactyl"); this.add("console", "@mozilla.org/consoleservice;1", "nsIConsoleService"); this.add("dactyl:", "@mozilla.org/network/protocol;1?name=dactyl"); @@ -93,6 +95,7 @@ var Services = Module("Services", { this.addClass("String", "@mozilla.org/supports-string;1", "nsISupportsString", "data"); this.addClass("StringStream", "@mozilla.org/io/string-input-stream;1", "nsIStringInputStream", "data"); this.addClass("Transfer", "@mozilla.org/transfer;1", "nsITransfer", "init"); + this.addClass("Transferable", "@mozilla.org/widget/transferable;1", "nsITransferable"); this.addClass("Timer", "@mozilla.org/timer;1", "nsITimer", "initWithCallback"); this.addClass("URL", "@mozilla.org/network/standard-url;1", ["nsIStandardURL", "nsIURL"], "init"); this.addClass("Xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest", "open");