From 3dc0ad3745284e249f17e50cf1304048aec5b091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 25 Mar 2016 05:49:14 +0100 Subject: [PATCH] Add feed menu buttons. Close adomasven/zotero#9. --- .../content/zotero-platform/unix/itemPane.css | 12 ++ chrome/content/zotero/itemPane.js | 103 ++++++++++++++++++ chrome/content/zotero/itemPane.xul | 13 ++- .../preferences/preferences_advanced.xul | 9 +- chrome/content/zotero/xpcom/itemTreeView.js | 18 +-- .../zotero/xpcom/utilities_internal.js | 75 +++++++++++++ chrome/content/zotero/zoteroPane.js | 52 ++++++--- chrome/locale/en-US/zotero/preferences.dtd | 2 +- chrome/locale/en-US/zotero/zotero.properties | 1 + chrome/skin/default/zotero/itemPane.css | 24 +++- defaults/preferences/zotero.js | 2 + test/tests/itemPaneTest.js | 16 +++ 12 files changed, 295 insertions(+), 32 deletions(-) create mode 100644 chrome/content/zotero-platform/unix/itemPane.css diff --git a/chrome/content/zotero-platform/unix/itemPane.css b/chrome/content/zotero-platform/unix/itemPane.css new file mode 100644 index 0000000000..c3b5a82b98 --- /dev/null +++ b/chrome/content/zotero-platform/unix/itemPane.css @@ -0,0 +1,12 @@ +/* Some distros have icons disabled by default at the OS level and + * mozilla is a respectful gent. + */ +#zotero-feed-item-addTo-button .button-icon { + display: block; + margin-right: 5px +} + +/* Set to hidden in user-agent css for some reason. */ +#zotero-feed-item-addTo-button .menu-iconic-left { + visibility: visible; +} \ No newline at end of file diff --git a/chrome/content/zotero/itemPane.js b/chrome/content/zotero/itemPane.js index e42a3aa572..e03951bfe1 100644 --- a/chrome/content/zotero/itemPane.js +++ b/chrome/content/zotero/itemPane.js @@ -25,6 +25,7 @@ var ZoteroItemPane = new function() { var _lastItem, _itemBox, _notesLabel, _notesButton, _notesList, _tagsBox, _relatedBox; + var _translationTarget; this.onLoad = function () { if (!Zotero) { @@ -47,6 +48,22 @@ var ZoteroItemPane = new function() { } + this.init = function() { + Zotero.debug("Initializing ZoteroItemPane"); + let lastTranslationTarget = Zotero.Prefs.get('feeds.lastTranslationTarget'); + if (lastTranslationTarget) { + if (lastTranslationTarget[0] == "C") { + _translationTarget = Zotero.Collections.get(parseInt(lastTranslationTarget.substr(1))); + } else if (lastTranslationTarget[0] == "L") { + _translationTarget = Zotero.Libraries.get(parseInt(lastTranslationTarget.substr(1))); + } + } + if (!_translationTarget) { + _translationTarget = Zotero.Libraries.userLibrary; + } + this.setTranslateButton(); + } + /* * Load a top-level item */ @@ -185,6 +202,92 @@ var ZoteroItemPane = new function() { } + this.translateSelectedItems = Zotero.Promise.coroutine(function* () { + var collectionID = _translationTarget.objectType == 'collection' ? _translationTarget.id : undefined; + var items = ZoteroPane_Local.itemsView.getSelectedItems(); + for (let item of items) { + yield item.translate(_translationTarget.libraryID, collectionID); + } + }); + + + this.buildTranslateSelectContextMenu = function (event) { + var menu = document.getElementById('zotero-item-addTo-menu'); + // Don't trigger rebuilding on nested popupmenu open/close + if (event.target != menu) { + return; + } + // Clear previous items + while (menu.firstChild) { + menu.removeChild(menu.firstChild); + } + + var libraries = Zotero.Libraries.getAll(); + for (let library of libraries) { + if (!library.editable || library.libraryType == 'publications') { + continue; + } + Zotero.Utilities.Internal.createMenuForTarget(library, menu, function(event, libraryOrCollection) { + ZoteroItemPane.setTranslationTarget(libraryOrCollection); + event.stopPropagation(); + }); + } + }; + + + this.setTranslateButton = function() { + var label = Zotero.getString('general.addTo', _translationTarget.name); + var elem = document.getElementById('zotero-feed-item-addTo-button'); + elem.setAttribute('label', label); + + var key = Zotero.Keys.getKeyForCommand('saveToZotero'); + + var tooltip = label + + (Zotero.rtl ? ' \u202B' : ' ') + '(' + + (Zotero.isMac ? '⇧⌘' : Zotero.getString('general.keys.ctrlShift')) + + key + ')'; + elem.setAttribute('tooltiptext', tooltip); + + var objectType = _translationTarget._objectType; + var imageSrc = Zotero.Utilities.Internal.getCollectionImageSrc(objectType); + elem.setAttribute('image', imageSrc); + }; + + + this.setTranslationTarget = function(translationTarget) { + _translationTarget = translationTarget; + if (translationTarget.objectType == 'collection') { + Zotero.Prefs.set('feeds.translationTarget', "C" + translationTarget.id); + } else { + Zotero.Prefs.set('feeds.translationTarget', "L" + translationTarget.libraryID); + } + ZoteroItemPane.setTranslateButton(); + }; + + + this.setToggleReadLabel = function() { + var markRead = false; + var items = ZoteroPane_Local.itemsView.getSelectedItems(); + for (let item of items) { + if (!item.isRead) { + markRead = true; + break; + } + } + var elem = document.getElementById('zotero-feed-item-toggleRead-button'); + if (markRead) { + var label = Zotero.getString('pane.item.markAsRead'); + } else { + label = Zotero.getString('pane.item.markAsUnread'); + } + elem.setAttribute('label', label); + + var key = Zotero.Keys.getKeyForCommand('toggleRead'); + var tooltip = label + (Zotero.rtl ? ' \u202B' : ' ') + '(' + key + ')' + elem.setAttribute('tooltiptext', tooltip); + }; + + function _updateNoteCount() { var c = _notesList.childNodes.length; diff --git a/chrome/content/zotero/itemPane.xul b/chrome/content/zotero/itemPane.xul index 70f89167e9..b4ac760afa 100644 --- a/chrome/content/zotero/itemPane.xul +++ b/chrome/content/zotero/itemPane.xul @@ -24,6 +24,7 @@ ***** END LICENSE BLOCK ***** --> + @@ -33,13 +34,23 @@ -