Mercurial > snowl
changeset 319:a6cafdade667
don't initialize list view until the user opens it
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Fri, 10 Oct 2008 18:12:16 -0700 |
parents | 0856399a6a9e |
children | b09b7f436e1a |
files | content/list-sidebar.js content/list-sidebar.xul content/list.js |
diffstat | 3 files changed, 51 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/content/list-sidebar.js Thu Oct 09 17:30:24 2008 -0700 +++ b/content/list-sidebar.js Fri Oct 10 18:12:16 2008 -0700 @@ -52,3 +52,13 @@ rootTreeItem. QueryInterface(Ci.nsIInterfaceRequestor). getInterface(Ci.nsIDOMWindow); + +let ListSidebar = { + onLoad: function() { + gBrowserWindow.SnowlMessageView.show(); + }, + + onUnload: function() { + gBrowserWindow.SnowlMessageView.hide(); + } +}
--- a/content/list-sidebar.xul Thu Oct 09 17:30:24 2008 -0700 +++ b/content/list-sidebar.xul Fri Oct 10 18:12:16 2008 -0700 @@ -43,8 +43,8 @@ <page id="snowlSidebar" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="&page.title;" - onload="gBrowserWindow.SnowlMessageView.show()" - onunload="gBrowserWindow.SnowlMessageView.hide()"> + onload="ListSidebar.onLoad()" + onunload="ListSidebar.onUnload()"> <script type="application/x-javascript" src="chrome://snowl/content/list-sidebar.js"/>
--- a/content/list.js Thu Oct 09 17:30:24 2008 -0700 +++ b/content/list.js Fri Oct 10 18:12:16 2008 -0700 @@ -45,24 +45,25 @@ Cu.import("resource://snowl/modules/utils.js"); let SnowlMessageView = { - _log: null, + // Logger + get _log() { + delete this._log; + return this._log = Log4Moz.Service.getLogger("Snowl.ListView"); + }, // Observer Service + // FIXME: switch to using the Observers module. get _obsSvc() { - let obsSvc = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); delete this._obsSvc; - this._obsSvc = obsSvc; - return this._obsSvc; + return this._obsSvc = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); }, // Atom Service get _atomSvc() { - let atomSvc = Cc["@mozilla.org/atom-service;1"]. - getService(Ci.nsIAtomService); delete this._atomSvc; - this._atomSvc = atomSvc; - return this._atomSvc; + return this._atomSvc = Cc["@mozilla.org/atom-service;1"]. + getService(Ci.nsIAtomService); }, // The ID of the source to display. The sidebar can set this to the source @@ -153,20 +154,28 @@ //**************************************************************************// // Initialization and Destruction - init: function() { - this._log = Log4Moz.Service.getLogger("Snowl.View"); + show: function() { this._obsSvc.addObserver(this, "messages:changed", true); - let container = document.getElementById("snowlViewContainer"); - if (container.getAttribute("placement") == "side") - this.placeOnSide(); - this._collection = new SnowlCollection(); this._sort(); - this._tree.view = this; + + // We don't have to initialize the view, as placing it does so for us. + //this._tree.view = this; + + this.place(); + + document.getElementById("snowlViewContainer").hidden = false; + document.getElementById("snowlViewSplitter").hidden = false; }, - destroy: function() { + hide: function() { + document.getElementById("snowlViewSplitter").hidden = true; + document.getElementById("snowlViewContainer").hidden = true; + + // XXX Should we somehow destroy the view here (f.e. by setting + // this._tree.view to null)? + this._obsSvc.removeObserver(this, "messages:changed"); }, @@ -274,6 +283,19 @@ this.placeOnTop(); }, + place: function() { + let container = document.getElementById("snowlViewContainer"); + switch (container.getAttribute("placement")) { + case "side": + this.placeOnSide(); + break; + case "top": + default: + this.placeOnTop(); + break; + } + }, + placeOnSide: function() { let browser = document.getElementById("browser"); let container = document.getElementById("snowlViewContainer"); @@ -425,20 +447,6 @@ this._tree.boxObject.invalidate(); }, - show: function() { - let container = document.getElementById("snowlViewContainer"); - let splitter = document.getElementById("snowlViewSplitter"); - container.hidden = false; - splitter.hidden = false; - }, - - hide: function() { - let container = document.getElementById("snowlViewContainer"); - let splitter = document.getElementById("snowlViewSplitter"); - container.hidden = true; - splitter.hidden = true; - }, - onClickColumnHeader: function(aEvent) { let column = aEvent.target; let property = this._columnProperties[column.id]; @@ -481,5 +489,3 @@ this._collection.sort(); } }; - -window.addEventListener("load", function() { SnowlMessageView.init() }, false);