diff options
author | Kris Maglione <jg@suckless.org> | 2009-10-11 02:38:33 -0400 |
---|---|---|
committer | Kris Maglione <jg@suckless.org> | 2009-10-11 02:38:33 -0400 |
commit | 755079877ed98d06589af510a1b8986ae0c2c6f6 (patch) | |
tree | ddd18df6846dd66468f5d45a76e880ee2a34ec55 | |
parent | cf08acaf69151d9eea02c4aa142ef3924a4743fb (diff) | |
download | pentadactyl-755079877ed98d06589af510a1b8986ae0c2c6f6.tar.gz |
Fix occasional lag in updating tab count widget (thanks elitemx). Minor cleanup.
-rw-r--r-- | common/content/events.js | 10 | ||||
-rw-r--r-- | common/content/ui.js | 52 |
2 files changed, 28 insertions, 34 deletions
diff --git a/common/content/events.js b/common/content/events.js index dd3d06fe..0ea683f2 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -350,19 +350,19 @@ function Events() //{{{ let tabContainer = tabs.getBrowser().mTabContainer; tabContainer.addEventListener("TabMove", function (event) { - statusline.updateTabCount(); + statusline.updateTabCount(true); }, false); tabContainer.addEventListener("TabOpen", function (event) { - statusline.updateTabCount(); + statusline.updateTabCount(true); }, false); tabContainer.addEventListener("TabClose", function (event) { - statusline.updateTabCount(); + statusline.updateTabCount(true); }, false); tabContainer.addEventListener("TabSelect", function (event) { // TODO: is all of that necessary? + // I vote no. --Kris modes.reset(); - // XXX: apparently the tab container hasn't updated mTabs yet - setTimeout(function () { statusline.updateTabCount(); }, 0); + statusline.updateTabCount(true); tabs.updateSelectionHistory(); if (options["focuscontent"]) diff --git a/common/content/ui.js b/common/content/ui.js index f100848a..4694dc62 100644 --- a/common/content/ui.js +++ b/common/content/ui.js @@ -34,23 +34,25 @@ function CommandLine() //{{{ storage.newObject("sanitize", function () { ({ CLEAR: "browser:purge-session-history", + QUIT: "quit-application", init: function () { services.get("observer").addObserver(this, this.CLEAR, false); - services.get("observer").addObserver(this, "quit-application", false); + services.get("observer").addObserver(this, this.QUIT, false); }, observe: function (subject, topic, data) { - if (topic == this.CLEAR) + switch (topic) { - ["search", "command"].forEach(function (mode) { - History(null, mode).sanitize(); - }); - } - else if (topic == "quit-application") - { - services.get("observer").removeObserver(this, this.CLEAR); - services.get("observer").removeObserver(this, "quit-application"); + case this.CLEAR: + ["search", "command"].forEach(function (mode) { + History(null, mode).sanitize(); + }); + break; + case this.QUIT: + services.get("observer").removeObserver(this, this.CLEAR); + services.get("observer").removeObserver(this, this.QUIT); + break; } } }).init(); @@ -2253,32 +2255,24 @@ function StatusLine() //{{{ /** * Display the correct tabcount (e.g., [1/5]) on the status bar. * - * @param {number} currentIndex The 1-based index of the - * currently selected tab. @optional - * @param {number} totalTabs The total number of tabs. @optional + * @param {bool} delayed When true, update count after a + * brief timeout. Useful in the many cases when an + * event that triggers an update is broadcast before + * the tab state is fully updated. */ - updateTabCount: function updateTabCount(currentIndex, totalTabs) + updateTabCount: function updateTabCount(delayed) { - if (!liberator.has("tabs")) + if (liberator.has("tabs")) { - tabCountWidget = ""; - return; - } + if (delayed) + return void setTimeout(function () statusline.updateTabCount(false), 0); - // update the ordinal which is used for numbered tabs only when the user has - // tab numbers set - if (options.get("guioptions").has("n", "N")) - { + // update the ordinal which is used for numbered tabs for (let [i, tab] in util.Array.iteritems(getBrowser().mTabs)) tab.setAttribute("ordinal", i + 1); - } - if (!currentIndex || typeof currentIndex != "number") - currentIndex = tabs.index() + 1; - if (!totalTabs || typeof currentIndex != "number") - totalTabs = tabs.count; - - tabCountWidget.value = "[" + currentIndex + "/" + totalTabs + "]"; + tabCountWidget.value = "[" + (tabs.index() + 1) + "/" + tabs.count + "]"; + } }, /** |