diff --git a/common/locale/en-US/gui.xml b/common/locale/en-US/gui.xml index 02afea01..94a34def 100644 --- a/common/locale/en-US/gui.xml +++ b/common/locale/en-US/gui.xml @@ -208,6 +208,20 @@

+ + :sidebar! name + +

+ Toggle the sidebar window. When name is provided, the + semantics are as follows: If the named is currently open, it is + closed. Otherwise the sidebar is closed. When name is + not provided, the semantics are as follows: If the sidebar is + currently open, it is closed. Otherwise the previously open sidebar + panel is re-opened. +

+
+
+

Status line

diff --git a/common/modules/util.jsm b/common/modules/util.jsm index c67b8f37..52debe7a 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -743,15 +743,14 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @param {function(XMLHttpRequest)} callback * @returns {XMLHttpRequest} */ - httpGet: function httpGet(url, callback) { + httpGet: function httpGet(url, callback, self) { try { let xmlhttp = services.Xmlhttp(); xmlhttp.mozBackgroundRequest = true; - if (callback) - xmlhttp.onreadystatechange = function () { - if (xmlhttp.readyState == 4) - callback(xmlhttp); - }; + if (callback) { + xmlhttp.onload = function handler(event) { util.trapErrors(callback, self, xmlhttp, event) }; + xmlhttp.onerror = xmlhttp.onload; + } xmlhttp.open("GET", url, !!callback); xmlhttp.send(null); return xmlhttp; diff --git a/pentadactyl/NEWS b/pentadactyl/NEWS index c1d125e3..578f3d62 100644 --- a/pentadactyl/NEWS +++ b/pentadactyl/NEWS @@ -80,6 +80,8 @@ - :saveas now provides completions for default file names, and automatically chooses a filename when the save target is a directory. + - :sidebar now accepts a ! flag to toggle the sidebar rather + than open it unconditionally. - Added :write !cmd and :write >>file. - Added :yank command. - :delmarks, :marks and :qmarks now also accept ranges, same as diff --git a/pentadactyl/content/config.js b/pentadactyl/content/config.js index 4df9288c..bed5b294 100644 --- a/pentadactyl/content/config.js +++ b/pentadactyl/content/config.js @@ -167,7 +167,7 @@ var Config = Module("config", ConfigBase, { }, { }, { commands: function (dactyl, modules, window) { - const { commands, completion } = modules; + const { commands, completion, config } = modules; const { document } = window; commands.add(["winon[ly]"], @@ -205,10 +205,20 @@ var Config = Module("config", ConfigBase, { "Open the sidebar window", function (args) { function compare(a, b) util.compareIgnoreCase(a, b) == 0 + let title = document.getElementById("sidebar-title"); + + dactyl.assert(args.length || title.value || args.bang && config.lastSidebar, + "Argument required"); + + if (!args.length) + return window.toggleSidebar(title.value ? null : config.lastSidebar); // focus if the requested sidebar is already open - if (compare(document.getElementById("sidebar-title").value, args[0])) + if (compare(title.value, args[0])) { + if (args.bang) + return window.toggleSidebar(); return dactyl.focus(document.getElementById("sidebar-box")); + } let menu = document.getElementById("viewSidebarMenu"); @@ -223,7 +233,8 @@ var Config = Module("config", ConfigBase, { return dactyl.echoerr("No sidebar " + args[0] + " found"); }, { - argCount: "1", + argCount: "?", + bang: true, completer: function (context) { context.ignoreCase = true; return completion.sidebar(context); @@ -322,6 +333,12 @@ var Config = Module("config", ConfigBase, { "Firefox location bar entries (bookmarks and history sorted in an intelligent way)", completion.location); }, + events: function (dactyl, modules, window) { + modules.events.addSessionListener(window, "SidebarFocused", function (event) { + modules.config.lastSidebar = window.document.getElementById("sidebar-box") + .getAttribute("sidebarcommand"); + }, false); + }, modes: function (dactyl, modules, window) { const { config, modes } = modules; config.ignoreKeys = {