From 6ccfed24886370d2cb6312f542cf5dc07ababd6d Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 31 Oct 2015 03:46:47 -0400 Subject: [PATCH] Don't show item context menu until it's ready With async generation, an incorrect menu was showing first before the correct version appeared. --- chrome/content/zotero/locateMenu.js | 7 ++++--- chrome/content/zotero/zoteroPane.js | 21 +++++++++++++++++---- chrome/content/zotero/zoteroPane.xul | 4 ++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/locateMenu.js b/chrome/content/zotero/locateMenu.js index c4ee9dea7..836d101df 100644 --- a/chrome/content/zotero/locateMenu.js +++ b/chrome/content/zotero/locateMenu.js @@ -94,8 +94,9 @@ var Zotero_LocateMenu = new function() { * Clear the bottom part of the context menu and add locate options * @param {menupopup} menu The menu to add context menu items to * @param {Boolean} showIcons Whether menu items should have associated icons + * @return {Promise} */ - this.buildContextMenu = function(menu, showIcons) { + this.buildContextMenu = Zotero.Promise.coroutine(function* (menu, showIcons) { // get selected items var selectedItems = _getSelectedItems(); @@ -103,7 +104,7 @@ var Zotero_LocateMenu = new function() { if(!selectedItems.length || selectedItems.length > 20) return; // add view options - _addViewOptions(menu, selectedItems, showIcons); + yield _addViewOptions(menu, selectedItems, showIcons); /*// look for locate engines var availableEngines = _getAvailableLocateEngines(selectedItems); @@ -119,7 +120,7 @@ var Zotero_LocateMenu = new function() { submenu.appendChild(submenuPopup); menu.appendChild(submenu); }*/ - } + }); function _addViewOption(selectedItems, optionName, optionObject, showIcons) { var menuitem = _createMenuItem(Zotero.getString("locate."+optionName+".label"), diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 64617cc43..15b7bbe3c 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -2591,7 +2591,7 @@ var ZoteroPane = new function() } // add locate menu options - Zotero_LocateMenu.buildContextMenu(menu, true); + yield Zotero_LocateMenu.buildContextMenu(menu, true); }); @@ -2625,12 +2625,25 @@ var ZoteroPane = new function() } } } - - // Automatically select all equivalent items when clicking on an item - // in duplicates view else if (tree.id == 'zotero-items-tree') { + // Show context menu once it's ready + if (event.button == 2) { + // Allow item to be selected first + setTimeout(function () { + ZoteroPane_Local.buildItemContextMenu() + .then(function () { + document.getElementById('zotero-itemmenu').openPopup( + null, null, event.clientX, event.clientY, true, false, event + ); + }) + }); + return; + } + let collectionTreeRow = ZoteroPane_Local.getCollectionTreeRow(); + // Automatically select all equivalent items when clicking on an item + // in duplicates view if (collectionTreeRow.isDuplicates()) { // Trigger only on primary-button single clicks without modifiers // (so that items can still be selected and deselected manually) diff --git a/chrome/content/zotero/zoteroPane.xul b/chrome/content/zotero/zoteroPane.xul index 003a2da04..0758c49ea 100644 --- a/chrome/content/zotero/zoteroPane.xul +++ b/chrome/content/zotero/zoteroPane.xul @@ -258,7 +258,7 @@ - + @@ -340,7 +340,7 @@