Mercurial > snowl
comparison content/collections.js @ 358:c00b3db58dcf
add 'snowl' to all observer topics to avoid conflicts with other extensions/core code; use the Observers component everywhere
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Tue, 04 Nov 2008 12:11:07 -0800 |
parents | e9d7087abad1 |
children |
comparison
equal
deleted
inserted
replaced
357:1db123f46ed7 | 358:c00b3db58dcf |
---|---|
32 * the provisions above, a recipient may use your version of this file under | 32 * the provisions above, a recipient may use your version of this file under |
33 * the terms of any one of the MPL, the GPL or the LGPL. | 33 * the terms of any one of the MPL, the GPL or the LGPL. |
34 * | 34 * |
35 * ***** END LICENSE BLOCK ***** */ | 35 * ***** END LICENSE BLOCK ***** */ |
36 | 36 |
37 // modules that come with Firefox | |
38 | |
39 // modules that are generic | |
40 Cu.import("resource://snowl/modules/log4moz.js"); | |
41 Cu.import("resource://snowl/modules/Observers.js"); | |
42 Cu.import("resource://snowl/modules/URI.js"); | |
43 | |
44 // modules that are Snowl-specific | |
37 Cu.import("resource://snowl/modules/service.js"); | 45 Cu.import("resource://snowl/modules/service.js"); |
38 Cu.import("resource://snowl/modules/datastore.js"); | 46 Cu.import("resource://snowl/modules/datastore.js"); |
39 Cu.import("resource://snowl/modules/log4moz.js"); | |
40 Cu.import("resource://snowl/modules/source.js"); | 47 Cu.import("resource://snowl/modules/source.js"); |
41 Cu.import("resource://snowl/modules/feed.js"); | 48 Cu.import("resource://snowl/modules/feed.js"); |
42 Cu.import("resource://snowl/modules/URI.js"); | |
43 Cu.import("resource://snowl/modules/identity.js"); | 49 Cu.import("resource://snowl/modules/identity.js"); |
44 Cu.import("resource://snowl/modules/collection.js"); | 50 Cu.import("resource://snowl/modules/collection.js"); |
45 Cu.import("resource://snowl/modules/opml.js"); | 51 Cu.import("resource://snowl/modules/opml.js"); |
46 | 52 |
47 let gBrowserWindow = window.QueryInterface(Ci.nsIInterfaceRequestor). | 53 let gBrowserWindow = window.QueryInterface(Ci.nsIInterfaceRequestor). |
52 getInterface(Ci.nsIDOMWindow); | 58 getInterface(Ci.nsIDOMWindow); |
53 | 59 |
54 let CollectionsView = { | 60 let CollectionsView = { |
55 _log: null, | 61 _log: null, |
56 | 62 |
57 // Observer Service | |
58 get _obsSvc() { | |
59 let obsSvc = Cc["@mozilla.org/observer-service;1"]. | |
60 getService(Ci.nsIObserverService); | |
61 delete this._obsSvc; | |
62 this._obsSvc = obsSvc; | |
63 return this._obsSvc; | |
64 }, | |
65 | |
66 get _tree() { | 63 get _tree() { |
67 delete this._tree; | 64 delete this._tree; |
68 return this._tree = document.getElementById("sourcesView"); | 65 return this._tree = document.getElementById("sourcesView"); |
69 }, | 66 }, |
70 | 67 |
78 //**************************************************************************// | 75 //**************************************************************************// |
79 // Initialization & Destruction | 76 // Initialization & Destruction |
80 | 77 |
81 init: function() { | 78 init: function() { |
82 this._log = Log4Moz.Service.getLogger("Snowl.Sidebar"); | 79 this._log = Log4Moz.Service.getLogger("Snowl.Sidebar"); |
83 this._obsSvc.addObserver(this, "sources:changed", true); | 80 Observers.add(this, "snowl:sources:changed"); |
84 this._getCollections(); | 81 this._getCollections(); |
85 this._buildCollectionTree(); | 82 this._buildCollectionTree(); |
86 | 83 |
87 // Ensure collection selection maintained, if in List sidebar | 84 // Ensure collection selection maintained, if in List sidebar |
88 if (document.getElementById("snowlSidebar")) | 85 if (document.getElementById("snowlSidebar")) |
227 } | 224 } |
228 }, | 225 }, |
229 | 226 |
230 | 227 |
231 //**************************************************************************// | 228 //**************************************************************************// |
232 // Misc XPCOM Interface Implementations | 229 // Misc XPCOM Interfaces |
233 | |
234 // nsISupports | |
235 QueryInterface: function(aIID) { | |
236 if (aIID.equals(Ci.nsIObserver) || | |
237 aIID.equals(Ci.nsISupportsWeakReference) || | |
238 aIID.equals(Ci.nsISupports)) | |
239 return this; | |
240 | |
241 throw Cr.NS_ERROR_NO_INTERFACE; | |
242 }, | |
243 | 230 |
244 // nsIObserver | 231 // nsIObserver |
245 observe: function(subject, topic, data) { | 232 observe: function(subject, topic, data) { |
246 switch (topic) { | 233 switch (topic) { |
247 case "sources:changed": | 234 case "snowl:sources:changed": |
248 this._getCollections(); | 235 this._getCollections(); |
249 // Rebuild the view to reflect the new collection of messages. | 236 // Rebuild the view to reflect the new collection of messages. |
250 // Since the number of rows might have changed, we do this by reinitializing | 237 // Since the number of rows might have changed, we do this by reinitializing |
251 // the view instead of merely invalidating the box object (which doesn't | 238 // the view instead of merely invalidating the box object (which doesn't |
252 // expect changes to the number of rows). | 239 // expect changes to the number of rows). |
343 catch(ex) { | 330 catch(ex) { |
344 SnowlDatastore.dbConnection.rollbackTransaction(); | 331 SnowlDatastore.dbConnection.rollbackTransaction(); |
345 throw ex; | 332 throw ex; |
346 } | 333 } |
347 | 334 |
348 this._obsSvc.notifyObservers(null, "sources:changed", null); | 335 Observers.notify(null, "snowl:sources:changed", null); |
349 this._obsSvc.notifyObservers(null, "messages:changed", null); | 336 Observers.notify(null, "snowl:messages:changed", null); |
350 } | 337 } |
351 | 338 |
352 }; | 339 }; |
353 | 340 |
354 window.addEventListener("load", function() { CollectionsView.init() }, true); | 341 window.addEventListener("load", function() { CollectionsView.init() }, true); |