From 14861326269eb87406f9eed792b483e044b5d59a Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Wed, 9 Feb 2011 03:22:06 +0000 Subject: [PATCH] Add flexible locate menu, based on a (very heavily modified) copy of the pubget patch. Documentation is forthcoming. --- chrome/content/zotero/bindings/itembox.xml | 191 +----- chrome/content/zotero/locateManager.xul | 277 +++++++++ chrome/content/zotero/locateMenu.js | 317 ++++++++++ chrome/content/zotero/xpcom/locateManager.js | 578 ++++++++++++++++++ chrome/content/zotero/xpcom/openurl.js | 170 +++--- chrome/content/zotero/xpcom/zotero.js | 3 + chrome/content/zotero/zoteroPane.js | 88 +-- chrome/content/zotero/zoteroPane.xul | 72 ++- chrome/locale/en-US/zotero/preferences.dtd | 8 + chrome/locale/en-US/zotero/zotero.properties | 16 +- .../skin/default/zotero/bindings/itembox.css | 18 - chrome/skin/default/zotero/overlay.css | 5 + chrome/skin/default/zotero/preferences.css | 13 +- components/zotero-service.js | 1 + engines.json | 43 ++ 15 files changed, 1430 insertions(+), 370 deletions(-) create mode 100644 chrome/content/zotero/locateManager.xul create mode 100644 chrome/content/zotero/locateMenu.js create mode 100644 chrome/content/zotero/xpcom/locateManager.js create mode 100644 engines.json diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml index 5643f323ce..35fcce1b47 100644 --- a/chrome/content/zotero/bindings/itembox.xml +++ b/chrome/content/zotero/bindings/itembox.xml @@ -44,7 +44,6 @@ false false false - false false false false @@ -61,7 +60,6 @@ this.clickable = false; this.editable = false; this.saveOnEdit = false; - this.displayGoButtons = false; this.showTypeMenu = false; this.hideEmptyFields = false; this.clickByRow = false; @@ -75,7 +73,6 @@ this.clickable = true; this.editable = true; this.saveOnEdit = true - this.displayGoButtons = true; this.showTypeMenu = true; this.clickHandler = this.showEditor; this.blurHandler = this.hideEditor; @@ -90,7 +87,6 @@ this.clickable = true; this.editable = true; this.saveOnEdit = false; - this.displayGoButtons = false; this.showTypeMenu = true; this.clickHandler = this.showEditor; this.blurHandler = this.hideEditor; @@ -230,111 +226,6 @@ 'document.getBindingParent(this).clickHandler(this)'); } - if (this.displayGoButtons) { - // Enable/disable "View =>" button - testView: try { - var viewButton = document.getElementById('view-button'); - - viewButton.removeAttribute('viewSnapshot'); - viewButton.removeAttribute('viewURL'); - viewButton.setAttribute('label', - Zotero.getString('pane.item.goToURL.online.label')); - viewButton.setAttribute('tooltiptext', - Zotero.getString('pane.item.goToURL.online.tooltip')); - - var spec = false, validURI = false; - - var uri = Components.classes["@mozilla.org/network/standard-url;1"]. - createInstance(Components.interfaces.nsIURI); - - // First try to find a snapshot matching the item's URL field - var snapID = this.item.getBestAttachment(); - if (snapID) { - spec = Zotero.Items.get(snapID).getLocalFileURL(); - uri.spec = spec; - if (!uri.scheme || uri.scheme != 'file') { - snapID = false; - spec = false; - } - } - - // If that fails, try the URL field itself - if (!spec) { - spec = this.item.getField('url'); - uri.spec = spec; - if (!(uri.scheme && (uri.host || uri.scheme == 'file'))) { - spec = false; - } - } - - // If that fails, try the DOI field - if (!spec) { - var doi = this.item.getField('DOI'); - if (doi && typeof val == 'String') { - // Pull out DOI, in case there's a prefix - doi = Zotero.Utilities.cleanDOI(doi);; - if (doi) { - spec = "http://dx.doi.org/" + encodeURIComponent(doi); - } - } - } - - if (!spec) { - break testView; - } - - validURI = true; - - if (snapID) { - viewButton.setAttribute('label', - Zotero.getString('pane.item.goToURL.snapshot.label')); - viewButton.setAttribute('tooltiptext', - Zotero.getString('pane.item.goToURL.snapshot.tooltip')); - viewButton.setAttribute('viewSnapshot', snapID); - } - else { - viewButton.setAttribute('viewURL', spec); - } - } - catch (e) { - Zotero.debug(e); - } - viewButton.setAttribute('disabled', !validURI); - - // Enable/disable "Locate =>" button - switch (this.item.itemTypeID) { - // DEBUG: handle descendents of these types as well? - case Zotero.ItemTypes.getID('book'): - case Zotero.ItemTypes.getID('bookSection'): - case Zotero.ItemTypes.getID('journalArticle'): - case Zotero.ItemTypes.getID('thesis'): - var openURL = true; - break; - - default: - var openURL = false; - } - - var locateButton = document.getElementById('locate-button'); - - // TODO: move Locate service logic to separate interface - var wayback = this._itemHasURL(); - if (wayback) { - locateButton.setAttribute('type', 'menu'); - locateButton.setAttribute('disabled', false); - document.getElementById('locate-service-openurl').disabled = !openURL; - } - else { - locateButton.removeAttribute('type'); - locateButton.disabled = !openURL; - } - - this._id('go-buttons').hidden = false; - } - else { - this._id('go-buttons').hidden = true; - } - // Item type menu if (this.showTypeMenu) { // Build item type menu if it hasn't been built yet @@ -452,7 +343,7 @@ label.setAttribute("isButton", true); // TODO: make getFieldValue non-private and use below instead label.setAttribute("onclick", "ZoteroPane.loadURI(this.nextSibling.firstChild ? this.nextSibling.firstChild.nodeValue : this.nextSibling.value, event)"); - label.setAttribute("tooltiptext", Zotero.getString('pane.item.goToURL.online.tooltip')); + label.setAttribute("tooltiptext", Zotero.getString('locate.online.tooltip')); } else if (fieldName == 'DOI' && val && typeof val == 'string') { // Pull out DOI, in case there's a prefix @@ -461,7 +352,7 @@ doi = "http://dx.doi.org/" + encodeURIComponent(doi); label.setAttribute("isButton", true); label.setAttribute("onclick", "ZoteroPane.loadURI('" + doi + "', event)"); - label.setAttribute("tooltiptext", Zotero.getString('pane.item.goToURL.online.tooltip')); + label.setAttribute("tooltiptext", Zotero.getString('locate.online.tooltip')); } } else if (fieldName == 'abstractNote') { @@ -567,16 +458,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -2395,29 +2226,13 @@ - - - +