Closes #299, Method for viewing a child item that shows up in a search in its hierarchical context

Right-click option "Show in Library" for items in collections and saved searches

Other changes:

- Fixed error when focusing a collection with no items
- selectItem() now takes an inLibrary option to always use the Library even if the item is in the current collection
- Reworked buildCollectionContextMenu() to be much easier to change (will do the same for buildItemContextMenu() eventually) -- this required moving some DTD strings to properties, which I only did for en-US now, but I'll do it for the other locales we have as well
This commit is contained in:
Dan Stillman 2006-12-09 22:33:45 +00:00
parent 5ad86d2f50
commit 77b631f04e
4 changed files with 123 additions and 63 deletions

View File

@ -555,25 +555,42 @@ var ZoteroPane = new function()
return itemsView; return itemsView;
} }
function selectItem(id)
/*
* Select item in current collection or, if not there, in Library
*
* If _inLibrary_, force switch to Library
*/
function selectItem(itemID, inLibrary)
{ {
if (!itemID) {
return false;
}
if(itemsView) if(itemsView)
{ {
if(!itemsView._itemGroup.isLibrary()) if(!itemsView._itemGroup.isLibrary())
{ {
//select the Library if the item is not in the current collection if (inLibrary) {
var item = Zotero.Items.get(id);
var collectionID = itemsView._itemGroup.ref.getID();
if(!item.isRegularItem())
{
if(!Zotero.Items.get(item.getSource()).inCollection(collectionID))
collectionsView.selection.select(0);
}
else if(!item.inCollection(collectionID))
collectionsView.selection.select(0); 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);
}
}
} }
itemsView.selectItem(id); itemsView.selectItem(itemID);
} }
} }
@ -662,45 +679,71 @@ var ZoteroPane = new function()
{ {
var menu = document.getElementById('zotero-collectionmenu'); var menu = document.getElementById('zotero-collectionmenu');
var m = {
newCollection: 0,
newSavedSearch: 1,
newSubcollection: 2,
sep1: 3,
editSelectedCollection: 4,
removeCollection: 5,
sep2: 6,
exportCollection: 7,
createBibCollection: 8,
exportFile: 9,
loadReport: 10
};
// Collection // Collection
if (collectionsView.selection.count == 1 && if (collectionsView.selection.count == 1 &&
collectionsView._getItemAtRow(collectionsView.selection.currentIndex).isCollection()) collectionsView._getItemAtRow(collectionsView.selection.currentIndex).isCollection())
{ {
var hide = [0,1,5,7,10,12,13]; var hide = [m.newCollection, m.newSavedSearch, m.exportFile];
var show = [2,3,4,6,8,9,11,14]; var show = [m.newSubcollection, m.sep1, m.editSelectedCollection, m.removeCollection,
m.sep2, m.exportCollection, m.createBibCollection, m.loadReport];
if (itemsView.rowCount>0) if (itemsView.rowCount>0)
{ {
var enable = [9,11,14]; var enable = [m.exportCollection, m.createBibCollection, m.loadReport];
} }
else else
{ {
var disable = [9,11,14]; var disable = [m.exportCollection, m.createBibCollection, m.loadReport];
} }
menu.childNodes[14].setAttribute('label', Zotero.getString('pane.collections.menu.generateReport.collection')); menu.childNodes[m.editSelectedCollection].setAttribute('label', Zotero.getString('pane.collections.menu.rename.collection'));
menu.childNodes[m.removeCollection].setAttribute('label', Zotero.getString('pane.collections.menu.remove.collection'));
menu.childNodes[m.exportCollection].setAttribute('label', Zotero.getString('pane.collections.menu.export.collection'));
menu.childNodes[m.createBibCollection].setAttribute('label', Zotero.getString('pane.collections.menu.createBib.collection'));
menu.childNodes[m.loadReport].setAttribute('label', Zotero.getString('pane.collections.menu.generateReport.collection'));
} }
// Saved Search // Saved Search
else if (collectionsView.selection.count == 1 && else if (collectionsView.selection.count == 1 &&
collectionsView._getItemAtRow(collectionsView.selection.currentIndex).isSearch()) collectionsView._getItemAtRow(collectionsView.selection.currentIndex).isSearch())
{ {
var hide = [0,1,2,3,4,6,9,11,13]; var hide = [m.newCollection, m.newSavedSearch, m.newSubcollection, m.sep1, m.exportFile]
var show = [5,7,8,10,12,14]; var show = [m.editSelectedCollection, m.removeCollection, m.sep2, m.exportCollection,
m.createBibCollection, m.loadReport];
if (itemsView.rowCount>0) if (itemsView.rowCount>0)
{ {
var enable = [10,12,14]; var enable = [m.exportCollection, m.createBibCollection, m.loadReport];
} }
else else
{ {
var disable = [10,12,14]; var disable = [m.exportCollection, m.createBibCollection, m.loadReport];
} }
menu.childNodes[14].setAttribute('label', Zotero.getString('pane.collections.menu.generateReport.savedSearch')); menu.childNodes[m.editSelectedCollection].setAttribute('label', Zotero.getString('pane.collections.menu.edit.savedSearch'));
menu.childNodes[m.removeCollection].setAttribute('label', Zotero.getString('pane.collections.menu.remove.savedSearch'));
menu.childNodes[m.exportCollection].setAttribute('label', Zotero.getString('pane.collections.menu.export.savedSearch'));
menu.childNodes[m.createBibCollection].setAttribute('label', Zotero.getString('pane.collections.menu.createBib.savedSearch'));
menu.childNodes[m.loadReport].setAttribute('label', Zotero.getString('pane.collections.menu.generateReport.savedSearch'));
} }
// Library // Library
else else
{ {
var hide = [2,4,5,6,7,8,9,10,11,12,14]; var hide = [m.newSubcollection, m.editSelectedCollection, m.removeCollection, m.sep2,
var show = [0,1,3,13]; m.exportCollection, m.createBibCollection, m.loadReport];
var show = [m.newCollection, m.newSavedSearch, m.sep1, m.exportFile];
} }
for (var i in disable) for (var i in disable)
@ -732,69 +775,85 @@ var ZoteroPane = new function()
if(itemsView && itemsView.selection.count > 0) if(itemsView && itemsView.selection.count > 0)
{ {
enable.push(0,1,2,4,5,7,8,9,10); enable.push(0,2,3,4,6,7,8,10,11,12);
// Multiple items selected // Multiple items selected
if (itemsView.selection.count > 1) if (itemsView.selection.count > 1)
{ {
var multiple = '.multiple'; var multiple = '.multiple';
hide.push(0,1,2,3,4); hide.push(0,1,2,3,4,5,6);
} }
// Single item selected // Single item selected
else else
{ {
var item = itemsView._getItemAtRow(itemsView.selection.currentIndex).ref; var item = itemsView._getItemAtRow(itemsView.selection.currentIndex).ref;
var itemID = item.getID();
menu.setAttribute('itemID', itemID);
// Show in Library
if (!itemsView._itemGroup.isLibrary()) {
show.push(0,1);
}
else {
hide.push(0,1);
}
if (item.isRegularItem()) if (item.isRegularItem())
{ {
var itemID = item.getID(); show.push(2,3,4,6);
menu.setAttribute('itemID', itemID); hide.push(5); // abstract
show.push(0,1,2,4);
hide.push(3); // abstract
} }
else else
{ {
hide.push(0,1,2); hide.push(2,3,4);
// Abstract // Abstract
if (item.isNote() && item.getSource()) { if (item.isNote() && item.getSource()) {
show.push(3,4); show.push(5,6);
if (item.isAbstract()) { if (item.isAbstract()) {
menu.childNodes[3].setAttribute('label', Zotero.getString('pane.items.menu.abstract.unset')); menu.childNodes[5].setAttribute('label', Zotero.getString('pane.items.menu.abstract.unset'));
} }
else { else {
menu.childNodes[3].setAttribute('label', Zotero.getString('pane.items.menu.abstract.set')); menu.childNodes[5].setAttribute('label', Zotero.getString('pane.items.menu.abstract.set'));
} }
} }
else { else {
hide.push(3,4); hide.push(5,6);
} }
} }
} }
} }
else else
{ {
disable.push(0,1,2,5,6,8,9,10); // Show in Library
hide.push(3); // abstract if (!itemsView._itemGroup.isLibrary()) {
show.push(4); // separator show.push(0,1);
}
else {
hide.push(0,1);
}
disable.push(0,2,3,4,7,8,10,11,12);
hide.push(5); // abstract
show.push(6); // separator
} }
// Remove from collection // Remove from collection
if (itemsView._itemGroup.isCollection()) if (itemsView._itemGroup.isCollection())
{ {
menu.childNodes[5].setAttribute('label', Zotero.getString('pane.items.menu.remove' + multiple)); menu.childNodes[7].setAttribute('label', Zotero.getString('pane.items.menu.remove' + multiple));
show.push(5); show.push(7);
} }
else else
{ {
hide.push(5); hide.push(7);
} }
// Plural if necessary // Plural if necessary
menu.childNodes[6].setAttribute('label', Zotero.getString('pane.items.menu.erase' + multiple)); menu.childNodes[8].setAttribute('label', Zotero.getString('pane.items.menu.erase' + multiple));
menu.childNodes[8].setAttribute('label', Zotero.getString('pane.items.menu.export' + multiple)); menu.childNodes[10].setAttribute('label', Zotero.getString('pane.items.menu.export' + multiple));
menu.childNodes[9].setAttribute('label', Zotero.getString('pane.items.menu.createBib' + multiple)); menu.childNodes[11].setAttribute('label', Zotero.getString('pane.items.menu.createBib' + multiple));
menu.childNodes[10].setAttribute('label', Zotero.getString('pane.items.menu.generateReport' + multiple)); menu.childNodes[12].setAttribute('label', Zotero.getString('pane.items.menu.generateReport' + multiple));
for (var i in disable) for (var i in disable)
{ {

View File

@ -70,19 +70,17 @@
<menuitem label="&zotero.toolbar.newSavedSearch.label;" oncommand="ZoteroPane.newSearch()"/> <menuitem label="&zotero.toolbar.newSavedSearch.label;" oncommand="ZoteroPane.newSearch()"/>
<menuitem label="&zotero.toolbar.newSubcollection.label;" oncommand="ZoteroPane.newCollection(ZoteroPane.getSelectedCollection().getID())"/> <menuitem label="&zotero.toolbar.newSubcollection.label;" oncommand="ZoteroPane.newCollection(ZoteroPane.getSelectedCollection().getID())"/>
<menuseparator/> <menuseparator/>
<menuitem label="&zotero.toolbar.renameCollection.label;" oncommand="ZoteroPane.editSelectedCollection();"/> <menuitem oncommand="ZoteroPane.editSelectedCollection();"/>
<menuitem label="&zotero.toolbar.renameSavedSearch.label;" oncommand="ZoteroPane.editSelectedCollection()"/> <menuitem oncommand="ZoteroPane.deleteSelectedCollection();"/>
<menuitem label="&zotero.toolbar.removeCollection.label;" oncommand="ZoteroPane.deleteSelectedCollection();"/>
<menuitem label="&zotero.toolbar.removeSavedSearch.label;" oncommand="ZoteroPane.deleteSelectedCollection()"/>
<menuseparator/> <menuseparator/>
<menuitem label="&zotero.toolbar.exportCollection.label;" oncommand="Zotero_File_Interface.exportCollection();"/> <menuitem oncommand="Zotero_File_Interface.exportCollection();"/>
<menuitem label="&zotero.toolbar.exportSavedSearch.label;" oncommand="Zotero_File_Interface.exportCollection()"/> <menuitem oncommand="Zotero_File_Interface.bibliographyFromCollection();"/>
<menuitem label="&zotero.toolbar.createBibCollection.label;" oncommand="Zotero_File_Interface.bibliographyFromCollection();"/>
<menuitem label="&zotero.toolbar.createBibSavedSearch.label;" oncommand="Zotero_File_Interface.bibliographyFromCollection()"/>
<menuitem label="&zotero.toolbar.export.label;" oncommand="Zotero_File_Interface.exportFile()"/> <menuitem label="&zotero.toolbar.export.label;" oncommand="Zotero_File_Interface.exportFile()"/>
<menuitem oncommand="Zotero_Report_Interface.loadCollectionReport()"/> <menuitem oncommand="Zotero_Report_Interface.loadCollectionReport()"/>
</popup> </popup>
<popup id="zotero-itemmenu" onpopupshowing="ZoteroPane.buildItemContextMenu();"> <popup id="zotero-itemmenu" onpopupshowing="ZoteroPane.buildItemContextMenu();">
<menuitem label="&zotero.items.menu.showInLibrary;" oncommand="ZoteroPane.selectItem(this.parentNode.getAttribute('itemID'), true)"/>
<menuseparator/>
<menuitem label="&zotero.items.menu.attach.note;" oncommand="ZoteroPane.newNote(false, this.parentNode.getAttribute('itemID'))"/> <menuitem label="&zotero.items.menu.attach.note;" oncommand="ZoteroPane.newNote(false, this.parentNode.getAttribute('itemID'))"/>
<menuitem label="&zotero.items.menu.attach.snapshot;" oncommand="ZoteroPane.addAttachmentFromPage(false, this.parentNode.getAttribute('itemID'));"/> <menuitem label="&zotero.items.menu.attach.snapshot;" oncommand="ZoteroPane.addAttachmentFromPage(false, this.parentNode.getAttribute('itemID'));"/>
<menuitem label="&zotero.items.menu.attach.link;" oncommand="ZoteroPane.addAttachmentFromPage(true, this.parentNode.getAttribute('itemID'));"/> <menuitem label="&zotero.items.menu.attach.link;" oncommand="ZoteroPane.addAttachmentFromPage(true, this.parentNode.getAttribute('itemID'));"/>
@ -162,7 +160,7 @@
id="zotero-items-tree" context="zotero-itemmenu" id="zotero-items-tree" context="zotero-itemmenu"
ondblclick="ZoteroPane.onDoubleClick(event, this);" ondblclick="ZoteroPane.onDoubleClick(event, this);"
enableColumnDrag="true" enableColumnDrag="true"
onfocus="if (!ZoteroPane.getItemsView().selection.count) { ZoteroPane.getItemsView().selection.select(0); }" onfocus="if (ZoteroPane.getItemsView().rowCount &amp;&amp; !ZoteroPane.getItemsView().selection.count) { ZoteroPane.getItemsView().selection.select(0); }"
onkeypress="if (event.keyCode == event.DOM_VK_BACK_SPACE || event.keyCode == event.DOM_VK_DELETE){ ZoteroPane.deleteSelectedItem(); event.preventDefault(); }" onkeypress="if (event.keyCode == event.DOM_VK_BACK_SPACE || event.keyCode == event.DOM_VK_DELETE){ ZoteroPane.deleteSelectedItem(); event.preventDefault(); }"
onselect="ZoteroPane.itemSelected();" onselect="ZoteroPane.itemSelected();"
ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event,ZoteroPane.getItemsView());" ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event,ZoteroPane.getItemsView());"

View File

@ -19,6 +19,7 @@
<!ENTITY zotero.items.dateAdded_column "Date Added"> <!ENTITY zotero.items.dateAdded_column "Date Added">
<!ENTITY zotero.items.dateModified_column "Date Modified"> <!ENTITY zotero.items.dateModified_column "Date Modified">
<!ENTITY zotero.items.menu.showInLibrary "Show in Library">
<!ENTITY zotero.items.menu.attach.note "Add Note"> <!ENTITY zotero.items.menu.attach.note "Add Note">
<!ENTITY zotero.items.menu.attach.snapshot "Attach Snapshot of Current Page"> <!ENTITY zotero.items.menu.attach.snapshot "Attach Snapshot of Current Page">
<!ENTITY zotero.items.menu.attach.link "Attach Link to Current Page"> <!ENTITY zotero.items.menu.attach.link "Attach Link to Current Page">
@ -33,19 +34,11 @@
<!ENTITY zotero.toolbar.newSubcollection.label "New Subcollection..."> <!ENTITY zotero.toolbar.newSubcollection.label "New Subcollection...">
<!ENTITY zotero.toolbar.newSavedSearch.label "New Saved Search..."> <!ENTITY zotero.toolbar.newSavedSearch.label "New Saved Search...">
<!ENTITY zotero.toolbar.tagSelector.label "Show/Hide Tag Selector"> <!ENTITY zotero.toolbar.tagSelector.label "Show/Hide Tag Selector">
<!ENTITY zotero.toolbar.renameCollection.label "Rename Collection...">
<!ENTITY zotero.toolbar.removeCollection.label "Remove Collection...">
<!ENTITY zotero.toolbar.exportCollection.label "Export Collection...">
<!ENTITY zotero.toolbar.renameSavedSearch.label "Edit Saved Search...">
<!ENTITY zotero.toolbar.removeSavedSearch.label "Remove Saved Search...">
<!ENTITY zotero.toolbar.exportSavedSearch.label "Export Saved Search...">
<!ENTITY zotero.toolbar.actions.label "Actions"> <!ENTITY zotero.toolbar.actions.label "Actions">
<!ENTITY zotero.toolbar.import.label "Import..."> <!ENTITY zotero.toolbar.import.label "Import...">
<!ENTITY zotero.toolbar.export.label "Export Library..."> <!ENTITY zotero.toolbar.export.label "Export Library...">
<!ENTITY zotero.toolbar.preferences.label "Preferences..."> <!ENTITY zotero.toolbar.preferences.label "Preferences...">
<!ENTITY zotero.toolbar.about.label "About Zotero..."> <!ENTITY zotero.toolbar.about.label "About Zotero...">
<!ENTITY zotero.toolbar.createBibCollection.label "Create Bibliography From Collection...">
<!ENTITY zotero.toolbar.createBibSavedSearch.label "Create Bibliography From Saved Search...">
<!ENTITY zotero.toolbar.search.label "Search:"> <!ENTITY zotero.toolbar.search.label "Search:">
<!ENTITY zotero.toolbar.fullscreen.tooltip "Toggle Fullscreen Mode"> <!ENTITY zotero.toolbar.fullscreen.tooltip "Toggle Fullscreen Mode">
<!ENTITY zotero.toolbar.goToURL.label "View"> <!ENTITY zotero.toolbar.goToURL.label "View">

View File

@ -4,6 +4,16 @@ pane.collections.name = Collection name:
pane.collections.rename = Rename collection: pane.collections.rename = Rename collection:
pane.collections.library = My Library pane.collections.library = My Library
pane.collections.untitled = Untitled pane.collections.untitled = Untitled
pane.collections.menu.rename.collection = Rename Collection...
pane.collections.menu.edit.savedSearch = Edit Saved Search
pane.collections.menu.remove.collection = Remove Collection...
pane.collections.menu.remove.savedSearch = Remove Saved Search...
pane.collections.menu.export.collection = Export Collection...
pane.collections.menu.export.savedSearch = Export Saved Search...
pane.collections.menu.createBib.collection = Create Bibliography From Collection...
pane.collections.menu.createBib.savedSearch = Create Bibliography From Saved Search...
pane.collections.menu.generateReport.collection = Generate Report from Collection... pane.collections.menu.generateReport.collection = Generate Report from Collection...
pane.collections.menu.generateReport.savedSearch = Generate Report from Saved Search... pane.collections.menu.generateReport.savedSearch = Generate Report from Saved Search...