Fix collection-menu selection via right-click->drag->release or keyboard

This commit is contained in:
Dan Stillman 2017-07-12 15:43:20 -04:00
parent aad12db2ff
commit 02774ac6fe
2 changed files with 131 additions and 124 deletions

View File

@ -2345,19 +2345,16 @@ var ZoteroPane = new function()
} }
this.buildCollectionContextMenu = function (noRepeat) {
var libraryID = this.getSelectedLibraryID();
// menuitem configuration // menuitem configuration
// //
// This has to be kept in sync with zotero-collectionmenu in zoteroPane.xul. We could do this // This has to be kept in sync with zotero-collectionmenu in zoteroPane.xul. We could do this
// entirely in JS, but various localized strings are only in zotero.dtd, and they're used in // entirely in JS, but various localized strings are only in zotero.dtd, and they're used in
// standalone.xul as well, so for now they have to remain as XML entities. // standalone.xul as well, so for now they have to remain as XML entities.
var options = [ var _collectionContextMenuOptions = [
{ {
id: "sync", id: "sync",
label: Zotero.getString('sync.sync'), label: Zotero.getString('sync.sync'),
onclick: () => { oncommand: () => {
Zotero.Sync.Runner.sync({ Zotero.Sync.Runner.sync({
libraries: [libraryID], libraries: [libraryID],
}); });
@ -2376,76 +2373,76 @@ var ZoteroPane = new function()
}, },
{ {
id: "newSubcollection", id: "newSubcollection",
onclick: () => { oncommand: () => {
this.newCollection(this.getSelectedCollection().key); this.newCollection(this.getSelectedCollection().key);
} }
}, },
{ {
id: "refreshFeed", id: "refreshFeed",
onclick: () => this.refreshFeed() oncommand: () => this.refreshFeed()
}, },
{ {
id: "sep2", id: "sep2",
}, },
{ {
id: "showDuplicates", id: "showDuplicates",
onclick: () => { oncommand: () => {
this.setVirtual(libraryID, 'duplicates', true); this.setVirtual(libraryID, 'duplicates', true);
} }
}, },
{ {
id: "showUnfiled", id: "showUnfiled",
onclick: () => { oncommand: () => {
this.setVirtual(libraryID, 'unfiled', true); this.setVirtual(libraryID, 'unfiled', true);
} }
}, },
{ {
id: "editSelectedCollection", id: "editSelectedCollection",
onclick: () => this.editSelectedCollection() oncommand: () => this.editSelectedCollection()
}, },
{ {
id: "markReadFeed", id: "markReadFeed",
onclick: () => this.markFeedRead() oncommand: () => this.markFeedRead()
}, },
{ {
id: "editSelectedFeed", id: "editSelectedFeed",
onclick: () => this.editSelectedFeed() oncommand: () => this.editSelectedFeed()
}, },
{ {
id: "deleteCollection", id: "deleteCollection",
onclick: () => this.deleteSelectedCollection() oncommand: () => this.deleteSelectedCollection()
}, },
{ {
id: "deleteCollectionAndItems", id: "deleteCollectionAndItems",
onclick: () => this.deleteSelectedCollection(true) oncommand: () => this.deleteSelectedCollection(true)
}, },
{ {
id: "sep3", id: "sep3",
}, },
{ {
id: "exportCollection", id: "exportCollection",
onclick: () => Zotero_File_Interface.exportCollection() oncommand: () => Zotero_File_Interface.exportCollection()
}, },
{ {
id: "createBibCollection", id: "createBibCollection",
onclick: () => Zotero_File_Interface.bibliographyFromCollection() oncommand: () => Zotero_File_Interface.bibliographyFromCollection()
}, },
{ {
id: "exportFile", id: "exportFile",
onclick: () => Zotero_File_Interface.exportFile() oncommand: () => Zotero_File_Interface.exportFile()
}, },
{ {
id: "loadReport", id: "loadReport",
onclick: event => Zotero_Report_Interface.loadCollectionReport(event) oncommand: event => Zotero_Report_Interface.loadCollectionReport(event)
}, },
{ {
id: "emptyTrash", id: "emptyTrash",
onclick: () => this.emptyTrash() oncommand: () => this.emptyTrash()
}, },
{ {
id: "removeLibrary", id: "removeLibrary",
label: Zotero.getString('pane.collections.menu.remove.library'), label: Zotero.getString('pane.collections.menu.remove.library'),
onclick: () => { oncommand: () => {
let library = Zotero.Libraries.get(libraryID); let library = Zotero.Libraries.get(libraryID);
let ps = Services.prompt; let ps = Services.prompt;
let buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING) let buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
@ -2466,6 +2463,9 @@ var ZoteroPane = new function()
}, },
]; ];
this.buildCollectionContextMenu = function (noRepeat) {
var libraryID = this.getSelectedLibraryID();
var options = _collectionContextMenuOptions;
var collectionTreeRow = this.collectionsView.selectedTreeRow; var collectionTreeRow = this.collectionsView.selectedTreeRow;
// This can happen if selection is changing during delayed second call below // This can happen if selection is changing during delayed second call below
@ -2499,9 +2499,6 @@ var ZoteroPane = new function()
if (option.command) { if (option.command) {
menuitem.setAttribute('command', option.command); menuitem.setAttribute('command', option.command);
} }
else if (option.onclick) {
menuitem.onclick = option.onclick;
}
} }
// By default things are hidden and visible, so we only need to record // By default things are hidden and visible, so we only need to record
@ -2659,7 +2656,15 @@ var ZoteroPane = new function()
for (let id of disable) { for (let id of disable) {
m[id].setAttribute('disabled', true); m[id].setAttribute('disabled', true);
} }
};
this.onCollectionContextMenuSelect = function (event) {
event.stopPropagation();
var o = _collectionContextMenuOptions.find(o => o.id == event.target.id)
if (o.oncommand) {
o.oncommand();
} }
};
this.buildItemContextMenu = Zotero.Promise.coroutine(function* () { this.buildItemContextMenu = Zotero.Promise.coroutine(function* () {
var options = [ var options = [

View File

@ -257,7 +257,9 @@
</toolbar> </toolbar>
<popupset> <popupset>
<menupopup id="zotero-collectionmenu" onpopupshowing="ZoteroPane_Local.buildCollectionContextMenu();"> <menupopup id="zotero-collectionmenu"
onpopupshowing="ZoteroPane_Local.buildCollectionContextMenu();"
oncommand="ZoteroPane.onCollectionContextMenuSelect(event)">
<!-- Keep order in sync with buildCollectionContextMenu, which adds additional attributes --> <!-- Keep order in sync with buildCollectionContextMenu, which adds additional attributes -->
<menuitem class="zotero-menuitem-sync"/> <menuitem class="zotero-menuitem-sync"/>
<menuseparator/> <menuseparator/>