www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 0e3071576b0b0accc7eb9254e4661603bfd91ebf
parent 460a423df3886dbe26ce0ffd525676c456b23adf
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sat, 14 Apr 2018 11:32:23 -0400

Show "Export Collection…" if there are items in subcollections

And generate collection context menu asynchronously

Closes #1482

Diffstat:
Mchrome/content/zotero/zoteroPane.js | 75++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Mchrome/content/zotero/zoteroPane.xul | 11++++++-----
2 files changed, 54 insertions(+), 32 deletions(-)

diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js @@ -2380,6 +2380,37 @@ var ZoteroPane = new function() } + /** + * Show context menu once it's ready + */ + this.onCollectionsContextMenuOpen = async function (event) { + await ZoteroPane.buildCollectionContextMenu(); + document.getElementById('zotero-collectionmenu').openPopup( + null, null, event.clientX + 1, event.clientY + 1, true, false, event + ); + }; + + + /** + * Show context menu once it's ready + */ + this.onItemsContextMenuOpen = async function (event) { + await ZoteroPane.buildItemContextMenu() + document.getElementById('zotero-itemmenu').openPopup( + null, null, event.clientX + 1, event.clientY + 1, true, false, event + ); + }; + + + this.onCollectionContextMenuSelect = function (event) { + event.stopPropagation(); + var o = _collectionContextMenuOptions.find(o => o.id == event.target.id) + if (o.oncommand) { + o.oncommand(); + } + }; + + // menuitem configuration // // This has to be kept in sync with zotero-collectionmenu in zoteroPane.xul. We could do this @@ -2498,7 +2529,7 @@ var ZoteroPane = new function() }, ]; - this.buildCollectionContextMenu = function (noRepeat) { + this.buildCollectionContextMenu = async function () { var libraryID = this.getSelectedLibraryID(); var options = _collectionContextMenuOptions; @@ -2508,12 +2539,16 @@ var ZoteroPane = new function() return; } - // If the items view isn't initialized, this was a right-click on a different collection and - // the new collection's items are still loading, so update the menu after loading. This causes - // some menu items (e.g., export/createBib/loadReport) to appear gray in the menu at first and - // then turn black once there are items. Pass a flag to prevent an accidental infinite loop. - if (!collectionTreeRow.isHeader() && !this.itemsView.initialized && !noRepeat) { - this.itemsView.onLoad.addListener(() => this.buildCollectionContextMenu(true)); + // If the items view isn't initialized, this was a right-click on a different collection + // and the new collection's items are still loading, so continue menu after loading is + // done. This causes some menu items (e.g., export/createBib/loadReport) to appear gray + // in the menu at first and then turn black once there are items + if (!collectionTreeRow.isHeader() && !this.itemsView.initialized) { + await new Promise((resolve) => { + this.itemsView.onLoad.addListener(() => { + resolve(); + }); + }); } // Set attributes on the menu from the configuration object @@ -2554,7 +2589,12 @@ var ZoteroPane = new function() ]; if (!this.itemsView.rowCount) { - disable = ['exportCollection', 'createBibCollection', 'loadReport']; + disable = ['createBibCollection', 'loadReport']; + + // If no items in subcollections either, disable export + if (!(await collectionTreeRow.ref.getDescendents(false, 'item', false).length)) { + disable.push('exportCollection'); + } } // Adjust labels @@ -2693,25 +2733,6 @@ var ZoteroPane = new function() } }; - this.onCollectionContextMenuSelect = function (event) { - event.stopPropagation(); - var o = _collectionContextMenuOptions.find(o => o.id == event.target.id) - if (o.oncommand) { - o.oncommand(); - } - }; - - /** - * Show context menu once it's ready - */ - this.onItemsContextMenuOpen = function (event) { - ZoteroPane.buildItemContextMenu() - .then(function () { - document.getElementById('zotero-itemmenu').openPopup( - null, null, event.clientX + 1, event.clientY + 1, true, false, event - ); - }) - }; this.buildItemContextMenu = Zotero.Promise.coroutine(function* () { var options = [ diff --git a/chrome/content/zotero/zoteroPane.xul b/chrome/content/zotero/zoteroPane.xul @@ -273,7 +273,6 @@ <popupset> <menupopup id="zotero-collectionmenu" - onpopupshowing="ZoteroPane_Local.buildCollectionContextMenu();" oncommand="ZoteroPane.onCollectionContextMenuSelect(event)"> <!-- Keep order in sync with buildCollectionContextMenu, which adds additional attributes --> <menuitem class="zotero-menuitem-sync"/> @@ -344,10 +343,12 @@ <box id="zotero-collections-tree-shim"/> <!-- This extra vbox prevents the toolbar from getting compressed when resizing the tag selector to max height --> - <tree id="zotero-collections-tree" hidecolumnpicker="true" context="zotero-collectionmenu" - onmouseover="ZoteroPane_Local.collectionsView.setHighlightedRows();" - onselect="ZoteroPane_Local.onCollectionSelected();" - seltype="cell" flex="1" editable="true"> + <tree id="zotero-collections-tree" + hidecolumnpicker="true" + oncontextmenu="ZoteroPane.onCollectionsContextMenuOpen(event)" + onmouseover="ZoteroPane_Local.collectionsView.setHighlightedRows();" + onselect="ZoteroPane_Local.onCollectionSelected();" + seltype="cell" flex="1" editable="true"> <treecols> <treecol id="zotero-collections-name-column"