1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-06 00:34:11 +01:00

Automatically track and remove long-lived event listeners.

This commit is contained in:
Kris Maglione
2009-11-13 16:12:50 -05:00
parent 569bef73bd
commit a4dced6911
5 changed files with 84 additions and 77 deletions

View File

@@ -26,34 +26,24 @@ const Tabs = Module("tabs", {
this._lastBufferSwitchArgs = "";
this._lastBufferSwitchSpecial = true;
let tabContainer = this.getBrowser().mTabContainer;
this._updateTabCount = function () { statusline.updateTabCount(true); };
["TabMove", "TabOpen", "TabClose"].forEach(function (event) {
tabContainer.addEventListener(event, this._updateTabCount, false);
}, this);
this._onTabSelect = function () {
// TODO: is all of that necessary?
// I vote no. --Kris
modes.reset();
statusline.updateTabCount(true);
this.updateSelectionHistory();
if (options["focuscontent"])
setTimeout(function () { liberator.focusContent(true); }, 10); // just make sure, that no widget has focus
};
tabContainer.addEventListener("TabSelect", this.closure._onTabSelect, false);
// hide tabs initially to prevent flickering when 'stal' would hide them
// on startup
if (config.hasTabbrowser)
this.getBrowser().mTabContainer.collapsed = true; // FIXME: see 'stal' comment
},
destroy: function () {
let tabContainer = this.getBrowser().mTabContainer;
["TabMove", "TabOpen", "TabClose"].forEach(function (event) {
tabContainer.removeEventListener(event, this._updateTabCount, false);
}, this);
tabContainer.removeEventListener("TabSelect", this.closure._onTabSelect, false);
_updateTabCount: function () {
statusline.updateTabCount(true);
},
_onTabSelect: function () {
// TODO: is all of that necessary?
// I vote no. --Kris
modes.reset();
statusline.updateTabCount(true);
this.updateSelectionHistory();
if (options["focuscontent"])
setTimeout(function () { liberator.focusContent(true); }, 10); // just make sure, that no widget has focus
},
/**
@@ -942,6 +932,13 @@ const Tabs = Module("tabs", {
"Open tabs",
completion.buffer);
},
events: function () {
let tabContainer = this.getBrowser().mTabContainer;
["TabMove", "TabOpen", "TabClose"].forEach(function (event) {
events.addSessionListener(tabContainer, event, this.closure._updateTabCount, false);
}, this);
events.addSessionListener(tabContainer, "TabSelect", this.closure._onTabSelect, false);
},
mappings: function () {
mappings.add([modes.NORMAL], ["g0", "g^"],
"Go to the first tab",