From b8321f13ea89b8cdb35668625501cc4bc6ee367c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 2 Jan 2007 10:50:38 +0000 Subject: [PATCH] Fix ZoteroPane.selectItem() to rely on itemsView.selectItem() to find the item in the current view if it's there, regardless of mode -- this simplifies ZP.selectItem() and fixes problems adding items while viewing a saved search. If the new item(/attachment/note) matches the saved search, it'll now appear and become selected. Otherwise, Z will switch to the Library and the new item will be selected in there. There might be some regressions from this, but it seems to work fine. Also: - Fixed JS strict warnings in popup note window - Use Zotero.Notes.add() when using toolbar button instead of a two-stage save with ZP.newItem('note') --- chrome/content/zotero/bindings/noteeditor.xml | 6 +- chrome/content/zotero/overlay.js | 62 +++++++------------ chrome/content/zotero/xpcom/data_access.js | 2 +- chrome/content/zotero/xpcom/itemTreeView.js | 2 + 4 files changed, 30 insertions(+), 42 deletions(-) diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml index 6abded6fe..ab729ffe1 100644 --- a/chrome/content/zotero/bindings/noteeditor.xml +++ b/chrome/content/zotero/bindings/noteeditor.xml @@ -25,7 +25,7 @@ xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> - + null - + null - + null diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 0bda4b57d..a838710e7 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -262,12 +262,16 @@ var ZoteroPane = new function() } item.save(); - if(itemsView && itemsView._itemGroup.isCollection()) + + if (itemsView && itemsView._itemGroup.isCollection()) { itemsView._itemGroup.ref.addItem(item.getID()); - + } + //set to Info tab document.getElementById('zotero-view-item').selectedIndex = 0; + selectItem(item.getID()); + return item; } @@ -681,31 +685,17 @@ var ZoteroPane = new function() if (!itemID) { return; } - if(itemsView) - { - if(!itemsView._itemGroup.isLibrary()) - { - if (inLibrary) { - collectionsView.selection.select(0); - } - // Select the Library if the item is not in the current collection - // TODO: does not work in saved searches - else { - var item = Zotero.Items.get(itemID); - var collectionID = itemsView._itemGroup.ref.getID(); - if (!item.isRegularItem()) { - // If this isn't a regular item, check if the parent is - // in the collection instead - if (!Zotero.Items.get(item.getSource()).inCollection(collectionID)) { - collectionsView.selection.select(0); - } - } - else if (!item.inCollection(collectionID)) { - collectionsView.selection.select(0); - } - } + + if (itemsView) { + if (!itemsView._itemGroup.isLibrary() && inLibrary) { + collectionsView.selection.select(0); + } + + var selected = itemsView.selectItem(itemID); + if (!selected) { + collectionsView.selection.select(0); + itemsView.selectItem(itemID); } - itemsView.selectItem(itemID); } } @@ -1114,25 +1104,21 @@ var ZoteroPane = new function() { if (!popup) { - var item = newItem(Zotero.ItemTypes.getID('note')); - var note = document.getElementById('zotero-note-editor'); try { // trim text = text.replace(/^[\xA0\r\n\s]*(.*)[\xA0\r\n\s]*$/m, "$1"); } catch (e){} - if (text) - { - note.value = text; - } - note.save(); - note.focus(); - if (parent) - { - item.setSource(parent); - selectItem(item.getID()); + var itemID = Zotero.Notes.add(text, parent); + + if (itemsView && itemsView._itemGroup.isCollection()) { + itemsView._itemGroup.ref.addItem(itemID); } + + selectItem(itemID); + + document.getElementById('zotero-note-editor').focus(); } else { diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index cc3c23944..4aaecada5 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -2343,7 +2343,7 @@ Zotero.Notes = new function(){ var bindParams = [ note.getID(), (sourceItemID ? {int:sourceItemID} : null), - {string:text}, + {string: text ? text : ''}, isAbstract ? 1 : null, ]; Zotero.DB.query(sql, bindParams); diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 0ede38842..e5656b9c5 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -617,6 +617,8 @@ Zotero.ItemTreeView.prototype.selectItem = function(id) this.selection.select(row); this._treebox.ensureRowIsVisible(row); + + return true; } /*