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')
This commit is contained in:
Dan Stillman 2007-01-02 10:50:38 +00:00
parent 26c62fba4b
commit b8321f13ea
4 changed files with 30 additions and 42 deletions

View File

@ -25,7 +25,7 @@
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="note-editor"> <binding id="note-editor">
<implementation> <implementation>
<field name="itemRef"/> <field name="itemRef">null</field>
<property name="item" onget="return this.itemRef;"> <property name="item" onget="return this.itemRef;">
<setter> <setter>
<![CDATA[ <![CDATA[
@ -42,7 +42,7 @@
]]> ]]>
</setter> </setter>
</property> </property>
<field name="noteRef"/> <field name="noteRef">null</field>
<property name="note" onget="return this.noteRef;"> <property name="note" onget="return this.noteRef;">
<setter> <setter>
<![CDATA[ <![CDATA[
@ -60,7 +60,7 @@
]]> ]]>
</setter> </setter>
</property> </property>
<field name="collectionRef"/> <field name="collectionRef">null</field>
<property name="collection" onget="return this.collectionRef;" onset="this.collectionRef = val;"/> <property name="collection" onget="return this.collectionRef;" onset="this.collectionRef = val;"/>
<property name="value" onget="return this.id('noteField').value;" onset="this.id('noteField').value = val;"/> <property name="value" onget="return this.id('noteField').value;" onset="this.id('noteField').value = val;"/>
<method name="save"> <method name="save">

View File

@ -262,12 +262,16 @@ var ZoteroPane = new function()
} }
item.save(); item.save();
if(itemsView && itemsView._itemGroup.isCollection())
if (itemsView && itemsView._itemGroup.isCollection()) {
itemsView._itemGroup.ref.addItem(item.getID()); itemsView._itemGroup.ref.addItem(item.getID());
}
//set to Info tab //set to Info tab
document.getElementById('zotero-view-item').selectedIndex = 0; document.getElementById('zotero-view-item').selectedIndex = 0;
selectItem(item.getID());
return item; return item;
} }
@ -681,31 +685,17 @@ var ZoteroPane = new function()
if (!itemID) { if (!itemID) {
return; return;
} }
if(itemsView)
{ if (itemsView) {
if(!itemsView._itemGroup.isLibrary()) if (!itemsView._itemGroup.isLibrary() && inLibrary) {
{ collectionsView.selection.select(0);
if (inLibrary) { }
collectionsView.selection.select(0);
} var selected = itemsView.selectItem(itemID);
// Select the Library if the item is not in the current collection if (!selected) {
// TODO: does not work in saved searches collectionsView.selection.select(0);
else { itemsView.selectItem(itemID);
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);
}
}
} }
itemsView.selectItem(itemID);
} }
} }
@ -1114,25 +1104,21 @@ var ZoteroPane = new function()
{ {
if (!popup) if (!popup)
{ {
var item = newItem(Zotero.ItemTypes.getID('note'));
var note = document.getElementById('zotero-note-editor');
try { try {
// trim // trim
text = text.replace(/^[\xA0\r\n\s]*(.*)[\xA0\r\n\s]*$/m, "$1"); text = text.replace(/^[\xA0\r\n\s]*(.*)[\xA0\r\n\s]*$/m, "$1");
} }
catch (e){} catch (e){}
if (text)
{
note.value = text;
}
note.save();
note.focus();
if (parent) var itemID = Zotero.Notes.add(text, parent);
{
item.setSource(parent); if (itemsView && itemsView._itemGroup.isCollection()) {
selectItem(item.getID()); itemsView._itemGroup.ref.addItem(itemID);
} }
selectItem(itemID);
document.getElementById('zotero-note-editor').focus();
} }
else else
{ {

View File

@ -2343,7 +2343,7 @@ Zotero.Notes = new function(){
var bindParams = [ var bindParams = [
note.getID(), note.getID(),
(sourceItemID ? {int:sourceItemID} : null), (sourceItemID ? {int:sourceItemID} : null),
{string:text}, {string: text ? text : ''},
isAbstract ? 1 : null, isAbstract ? 1 : null,
]; ];
Zotero.DB.query(sql, bindParams); Zotero.DB.query(sql, bindParams);

View File

@ -617,6 +617,8 @@ Zotero.ItemTreeView.prototype.selectItem = function(id)
this.selection.select(row); this.selection.select(row);
this._treebox.ensureRowIsVisible(row); this._treebox.ensureRowIsVisible(row);
return true;
} }
/* /*