From 953ec31166e95aa33fb2d6932353cef615b7be0f Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 28 Aug 2011 20:12:08 +0000 Subject: [PATCH] Add context menu to translate icon, allowing the user to save to Zotero with alternative translators and to perform library lookup or use lookup engines without first saving the item --- chrome/content/zotero/browser.js | 109 +++++++++++++++---- chrome/content/zotero/locateMenu.js | 19 +++- chrome/content/zotero/overlay.xul | 7 +- chrome/content/zotero/xpcom/locateManager.js | 10 +- chrome/content/zotero/zoteroPane.xul | 2 +- chrome/locale/en-US/zotero/zotero.properties | 4 + 6 files changed, 118 insertions(+), 33 deletions(-) diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index b147c38b4..698615886 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -125,7 +125,7 @@ var Zotero_Browser = new function() { * Scrapes a page (called when the capture icon is clicked * @return void */ - function scrapeThisPage(/*libraryID, collectionID*/) { + function scrapeThisPage(translator) { if (Zotero.locked) { Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError")); var desc = Zotero.localeJoin([ @@ -159,7 +159,7 @@ var Zotero_Browser = new function() { } // translate into specified library and collection - _getTabObject(this.tabbrowser.selectedBrowser).translate(libraryID, collectionID); + _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser).translate(libraryID, collectionID, translator); } /* @@ -480,23 +480,85 @@ var Zotero_Browser = new function() { } } + /** + * Called when status bar icon is right-clicked + */ + this.onStatusPopupShowing = function(e) { + var popup = e.target; + while(popup.hasChildNodes()) popup.removeChild(popup.lastChild); + + var tab = _getTabObject(this.tabbrowser.selectedBrowser); + var translators = tab.page.translators; + for(var i=0, n=translators.length; i 7 && translate.document.documentURI.substr(0, 7) == "file://") { this._attemptLocalFileImport(translate.document); } + Zotero_Browser.updateStatus(); } diff --git a/chrome/content/zotero/locateMenu.js b/chrome/content/zotero/locateMenu.js index a0555b9ff..8b66cfeb4 100644 --- a/chrome/content/zotero/locateMenu.js +++ b/chrome/content/zotero/locateMenu.js @@ -50,7 +50,7 @@ var Zotero_LocateMenu = new function() { var availableEngines = _getAvailableLocateEngines(selectedItems); // add engines that are available for selected items if(availableEngines.length) { - _addLocateEngines(locateMenu, availableEngines, true); + Zotero_LocateMenu.addLocateEngines(locateMenu, availableEngines, null, true); } } else { // add "no items selected" @@ -207,16 +207,21 @@ var Zotero_LocateMenu = new function() { /** * Add locate engine options to a menu * @param {menupopup} menu The menu to add menu items to - * @param {Zotero.LocateManater.LocateEngine[]} engines The list of engines to add to the menu + * @param {Zotero.LocateManager.LocateEngine[]} engines The list of engines to add to the menu + * @param {Function|null} items Function to call to locate items * @param {Boolean} showIcons Whether menu items should have associated icons */ - function _addLocateEngines(menu, engines, showIcons) { + this.addLocateEngines = function(menu, engines, locateFn, showIcons) { + if(!locateFn) { + locateFn = this.locateItem; + } + for each(var engine in engines) { var menuitem = _createMenuItem(engine.name, null, engine.description); menuitem.setAttribute("class", "menuitem-iconic"); menuitem.setAttribute("image", engine.icon); menu.appendChild(menuitem); - menuitem.addEventListener("command", _locateItem, false); + menuitem.addEventListener("command", locateFn, false); } } @@ -270,8 +275,10 @@ var Zotero_LocateMenu = new function() { /** * Locate selected items */ - function _locateItem(event) { - var selectedItems = _getSelectedItems(); + this.locateItem = function(event, selectedItems) { + if(!selectedItems) { + selectedItems = _getSelectedItems(); + } // find selected engine var selectedEngine = Zotero.LocateManager.getEngineByName(event.target.label); diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul index de511608f..4ff5999dc 100644 --- a/chrome/content/zotero/overlay.xul +++ b/chrome/content/zotero/overlay.xul @@ -69,7 +69,12 @@ - + + + + diff --git a/chrome/content/zotero/xpcom/locateManager.js b/chrome/content/zotero/xpcom/locateManager.js index 93c343586..aa0a11d71 100644 --- a/chrome/content/zotero/xpcom/locateManager.js +++ b/chrome/content/zotero/xpcom/locateManager.js @@ -269,7 +269,7 @@ Zotero.LocateManager = new function() { var ns = engine._urlNamespaces[nsPrefix]; if(!ns) return false; } else { - if(param === "searchTerms") return [item.getField("title")]; + if(param === "searchTerms") return [item.title]; return false; } @@ -277,7 +277,7 @@ Zotero.LocateManager = new function() { // take a normal "title," even though we don't use it, because it is valid (but not // preferred) OpenURL if(param === "title") { - var title = item.getField("title"); + var title = item.title; return (title ? [encodeURIComponent(title)] : false); } @@ -298,7 +298,7 @@ Zotero.LocateManager = new function() { } else if(param === "year") { return (itemOpenURL["rft.date"] ? [itemOpenURL["rft.date"][0].substr(0, 4)] : false); } else { - var result = item.getField(param); + var result = item[param]; return (result ? [encodeURIComponent(result)] : false); } } else { @@ -412,6 +412,10 @@ Zotero.LocateManager = new function() { if(responseType && responseType !== "text/html") { throw "LocateManager supports only responseType text/html"; } + + if(item.toArray) { + item = item.toArray(); + } var itemAsOpenURL = Zotero.OpenURL.createContextObject(item, "1.0", true); diff --git a/chrome/content/zotero/zoteroPane.xul b/chrome/content/zotero/zoteroPane.xul index b3ba8a837..e2543c4bf 100644 --- a/chrome/content/zotero/zoteroPane.xul +++ b/chrome/content/zotero/zoteroPane.xul @@ -43,7 +43,7 @@