diff --git a/chrome/content/zotero/note.js b/chrome/content/zotero/note.js index 5807ea4dce..1ca100615c 100644 --- a/chrome/content/zotero/note.js +++ b/chrome/content/zotero/note.js @@ -60,7 +60,7 @@ function onLoad() noteEditor.collection = Zotero.Collections.get(collectionID); } - notifierUnregisterID = Zotero.Notifier.registerItemObserver(NotifyCallback); + notifierUnregisterID = Zotero.Notifier.registerObserver(NotifyCallback, 'item'); } function onUnload() @@ -68,11 +68,12 @@ function onUnload() if(noteEditor && noteEditor.value) noteEditor.save(); - Zotero.Notifier.unregisterItemObserver(notifierUnregisterID); + Zotero.Notifier.unregisterObserver(notifierUnregisterID); } var NotifyCallback = { - notify: function(){ + notify: function(action, type, ids){ + // DEBUG: why does this reset without checking the modified ids? if (noteEditor.note){ noteEditor.note = noteEditor.note; } diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 31724d62b0..d16eaaebe9 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -36,7 +36,7 @@ Zotero.CollectionTreeView = function() this._treebox = null; this.refresh(); - this._unregisterID = Zotero.Notifier.registerCollectionObserver(this); + this._unregisterID = Zotero.Notifier.registerObserver(this, ['collection', 'search']); } /* @@ -208,7 +208,7 @@ Zotero.CollectionTreeView.prototype.notify = function(action, type, ids) */ Zotero.CollectionTreeView.prototype.unregister = function() { - Zotero.Notifier.unregisterCollectionObserver(this._unregisterID); + Zotero.Notifier.unregisterObserver(this._unregisterID); } Zotero.CollectionTreeView.prototype.isLibrary = function(row) diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 5165348929..a12b6a63e9 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -39,7 +39,7 @@ Zotero.ItemTreeView = function(itemGroup, sourcesOnly) this._treebox = null; this.refresh(); - this._unregisterID = Zotero.Notifier.registerItemObserver(this); + this._unregisterID = Zotero.Notifier.registerObserver(this, 'item'); } /* @@ -91,6 +91,10 @@ Zotero.ItemTreeView.prototype.refresh = function() */ Zotero.ItemTreeView.prototype.notify = function(action, type, ids) { + if (type != 'item'){ + return; + } + var madeChanges = false; this.selection.selectEventsSuppressed = true; var savedSelection = this.saveSelection(); @@ -278,7 +282,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids) */ Zotero.ItemTreeView.prototype.unregister = function() { - Zotero.Notifier.unregisterItemObserver(this._unregisterID); + Zotero.Notifier.unregisterObserver(this._unregisterID); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/content/zotero/xpcom/notifier.js b/chrome/content/zotero/xpcom/notifier.js index cc808a4a88..af271c32a2 100644 --- a/chrome/content/zotero/xpcom/notifier.js +++ b/chrome/content/zotero/xpcom/notifier.js @@ -21,11 +21,12 @@ */ Zotero.Notifier = new function(){ - var _observers = new Array(); + var _observers = new Zotero.Hash(); var _disabled = false; - _observers['collectionObserver'] = new Zotero.Hash(); - _observers['itemObserver'] = new Zotero.Hash(); + var _types = ['collection', 'search', 'item']; + this.registerObserver = registerObserver; + this.unregisterObserver = unregisterObserver; this.registerCollectionObserver = registerCollectionObserver; this.registerItemObserver = registerItemObserver; this.unregisterCollectionObserver = unregisterCollectionObserver; @@ -35,20 +36,65 @@ Zotero.Notifier = new function(){ this.enable = enable; this.isEnabled = isEnabled; + function registerObserver(ref, types){ + if (types){ + types = Zotero.flattenArguments(types); + + for (var i=0; i