Permalink
Browse files

allocation memory

  • Loading branch information...
1 parent a5bbbc9 commit 164395699a809c9a5464c7312ffa3fd963248426 @bakulf committed Dec 31, 2011
Showing with 93 additions and 65 deletions.
  1. +78 −23 content/modules/switchy-manager.jsm
  2. +8 −39 content/switchy-manager.js
  3. +7 −3 content/switchy.js
@@ -9,17 +9,21 @@ var EXPORTED_SYMBOLS = ["SwitchyManagerData"];
// Objects -------------------------------------------------------------------
// Object for the 'add URL' view:
-var SwitchyManagerAddUrl = {
+function SwitchyManagerAddUrl(window, document) {
+ this.initialize(window, document);
+}
+
+SwitchyManagerAddUrl.prototype = {
_data: null,
_browser: null,
_timer: null,
_document: null,
_window: null,
- initialize: function(document, window) {
- this._document = document;
+ initialize: function(window, document) {
this._window = window;
+ this._document = document;
this._browser = this._document.getElementById('add-browser');
this._browser.addProgressListener(this, Components.interfaces.nsIWebProgress.NOTIFY_ALL |
@@ -105,15 +109,8 @@ var SwitchyManagerAddUrl = {
let me = this;
switchy.addURL(null, url, type, listProfiles, onStartup, exclusive, function(state) {
// Change Page:
- if (state == true) {
- for (var i = 0; i < SwitchyManagerData.pages.length; ++i) {
- if ('pageProfiles' == SwitchyManagerData.pages[i].funcName) {
- SwitchyManagerData.pages[i].obj.setData(['alert-url-added']);
- SwitchyManagerData.node.selectItem(SwitchyManagerData.document.getElementById(SwitchyManagerData.pages[i].id));
- break;
- }
- }
- }
+ if (state == true && me._window.switchyManagerData)
+ me._window.switchyManagerData.pageProfiles('alert-url-added');
else
me.showAlert('alert-error');
});
@@ -217,7 +214,11 @@ var SwitchyManagerAddUrl = {
};
// Object for the 'profiles list' view:
-var SwitchyManagerProfiles = {
+function SwitchyManagerProfiles(window, document) {
+ this.initialize(window, document);
+}
+
+SwitchyManagerProfiles.prototype = {
_browser: null,
_alert: null,
_timer: null,
@@ -226,9 +227,9 @@ var SwitchyManagerProfiles = {
_document: null,
_window: null,
- initialize: function(document, window) {
- this._document = document;
+ initialize: function(window, document) {
this._window = window;
+ this._document = document;
this._browser = this._document.getElementById('profiles-browser');
this._browser.addProgressListener(this, Components.interfaces.nsIWebProgress.NOTIFY_ALL |
@@ -602,15 +603,19 @@ var SwitchyManagerProfiles = {
};
// Object for the 'about' view:
-var SwitchyManagerAbout = {
+function SwitchyManagerAbout(window, document) {
+ this.initialize(window, document);
+}
+
+SwitchyManagerAbout.prototype = {
_browser: null,
_document: null,
_window: null,
- initialize: function(document, window) {
- this._document = document;
+ initialize: function(window, document) {
this._window = window;
+ this._document = document;
this._browser = this._document.getElementById('about-browser');
},
@@ -632,13 +637,63 @@ var SwitchyManagerAbout = {
}
};
-var SwitchyManagerData = {
+// Object data
+function SwitchyManagerData(window, document) {
+ this.initialize(window, document);
+}
+
+SwitchyManagerData.prototype = {
document : null,
node : null,
+ pages : null,
+
+ initialize : function(window, document) {
+ this.document = document;
+
+ this.node = document.getElementById("categories");
+ this.pages = [
+ { funcName: 'addURL', id: 'category-add', page_id: 'add-view', obj: new SwitchyManagerAddUrl(window, document) },
+ { funcName: 'pageProfiles', id: 'category-profiles', page_id: 'profiles-view', obj: new SwitchyManagerProfiles(window, document) },
+ { funcName: 'pageAbout', id: 'category-about', page_id: 'about-view', obj: new SwitchyManagerAbout(window, document) }
+ ];
+
+ // Event listener:
+ var me = this;
+ this.node.addEventListener("select", function() { me._pageSelected(); }, false);
+
+ // Select a view:
+ this.node.selectItem(document.getElementById(this.pages[0].id));
+ this._pageSelected();
+ },
+
+ shutdown : function() {
+ // Shutdown any object:
+ for (var i = 0; i < this.pages.length; ++i) {
+ this.pages[i].obj.shutdown();
+ }
+
+ this.document = null;
+ },
- pages : [
- { funcName: 'addURL', id: 'category-add', page_id: 'add-view', obj: SwitchyManagerAddUrl },
- { funcName: 'pageProfiles', id: 'category-profiles', page_id: 'profiles-view', obj: SwitchyManagerProfiles },
- { funcName: 'pageAbout', id: 'category-about', page_id: 'about-view', obj: SwitchyManagerAbout } ]
+ _pageSelected : function() {
+ for (var i = 0; i < this.pages.length; ++i) {
+ if (this.pages[i].id == this.node.selectedItem.id) {
+ this.document.getElementById(this.pages[i].page_id).hidden = false;
+ this.pages[i].obj.show();
+ } else {
+ this.document.getElementById(this.pages[i].page_id).hidden = true;
+ }
+ }
+ },
+
+ __noSuchMethod__ : function(id, args) {
+ for (var i = 0; i < this.pages.length; ++i) {
+ if (id == this.pages[i].funcName) {
+ this.pages[i].obj.setData(args);
+ this.node.selectItem(this.document.getElementById(this.pages[i].id));
+ break;
+ }
+ }
+ }
};
View
@@ -10,55 +10,24 @@ SwitchyManager.initialize = function() {
Services.obs.addObserver(SwitchyManager._sendPong, "Switchy-manager-ping", false);
SwitchyOverlay.managerLoad();
- SwitchyManagerData.node = document.getElementById("categories");
- SwitchyManagerData.document = document;
-
- // Initialization of any object:
- for (var i = 0; i < SwitchyManagerData.pages.length; ++i)
- SwitchyManagerData.pages[i].obj.initialize(document, window);
-
- // Event listener:
- SwitchyManagerData.node.addEventListener("select", function() { SwitchyManager._pageSelected(); }, false);
-
- // Select a view:
- SwitchyManagerData.node.selectItem(document.getElementById(SwitchyManagerData.pages[0].id));
- SwitchyManager._pageSelected();
+ window.switchyManagerData = new SwitchyManagerData(window, document);
// Send a message about the loading completed
- Services.obs.notifyObservers(null, "Switchy-manager-loaded", "");
+ Services.obs.notifyObservers(window, "Switchy-manager-loaded", "");
}
// Shutdown
SwitchyManager.shutdown = function() {
Services.obs.removeObserver(SwitchyManager._sendPong, "Switchy-manager-ping");
- // Shutdown any object:
- for (var i = 0; i < SwitchyManagerData.pages.length; ++i)
- SwitchyManagerData.pages[i].obj.shutdown();
+ if (!window.switchyManagerData)
+ return;
+
+ window.switchyManagerData.shutdown();
+ window.switchyManagerData = null;
}
// Send a ping to inform when the UI is ready:
SwitchyManager._sendPong = function(aSubject, aTopic, aData) {
- Services.obs.notifyObservers(null, "Switchy-manager-pong", "");
-}
-
-SwitchyManager._pageSelected = function() {
- for (var i = 0; i < SwitchyManagerData.pages.length; ++i) {
- if (SwitchyManagerData.pages[i].id == SwitchyManagerData.node.selectedItem.id) {
- document.getElementById(SwitchyManagerData.pages[i].page_id).hidden = false;
- SwitchyManagerData.pages[i].obj.show();
- } else {
- document.getElementById(SwitchyManagerData.pages[i].page_id).hidden = true;
- }
- }
-}
-
-SwitchyManager.__noSuchMethod__ = function(id, args) {
- for (var i = 0; i < SwitchyManagerData.pages.length; ++i) {
- if (id == SwitchyManagerData.pages[i].funcName) {
- SwitchyManagerData.pages[i].obj.setData(args);
- SwitchyManagerData.node.selectItem(SwitchyManagerData.document.getElementById(SwitchyManagerData.pages[i].id));
- break;
- }
- }
+ Services.obs.notifyObservers(window, "Switchy-manager-pong", "");
}
View
@@ -2,6 +2,7 @@
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("chrome://switchy/content/modules/switchy.jsm");
+Components.utils.import("chrome://switchy/content/modules/switchy-manager.jsm");
// Generic load for any window:
window.addEventListener("load", function() {
@@ -147,14 +148,17 @@ SwitchyOverlay._panelManagerPageNoWin = function(page, newUrlObj) {
}
SwitchyOverlay._panelManagerPage = function(win, page, newUrlObj) {
+ if (!win.switchyManagerData)
+ return;
+
if (page == SwitchyOverlay.SWITCHY_ADD)
- SwitchyManager.addURL(newUrlObj);
+ win.switchyManagerData.addURL(newUrlObj);
if (page == SwitchyOverlay.SWITCHY_ABOUT)
- SwitchyManager.pageAbout();
+ win.switchyManagerData.pageAbout();
if (page == SwitchyOverlay.SWITCHY_PROFILES)
- SwitchyManager.pageProfiles();
+ win.switchyManagerData.pageProfiles();
}
// This will switch to the tab in aWindow having aURI, if present.

0 comments on commit 1643956

Please sign in to comment.