diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index c022192e89..cdea1c2c9c 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -429,15 +429,24 @@ var Zotero_Browser = new function() { function updateStatus() { var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser); - var captureIcon = tab.getCaptureIcon(); - if(captureIcon) { - Zotero_Browser.statusImage.src = captureIcon; + var state = tab.getCaptureState(); + if (state != tab.CAPTURE_STATE_DISABLED) { + Zotero_Browser.statusImage.src = tab.getCaptureIcon(); Zotero_Browser.statusImage.tooltipText = tab.getCaptureTooltip(); + if (state == tab.CAPTURE_STATE_TRANSLATABLE) { + Zotero_Browser.statusImage.classList.add('translate'); + } + else { + Zotero_Browser.statusImage.classList.remove('translate'); + } Zotero_Browser.statusImage.hidden = false; - Zotero_Browser.statusImage.addEventListener("load", function() { - document.getElementById("zotero-status-image-guidance").show(); - }, false); + if (state == tab.CAPTURE_STATE_TRANSLATABLE) { + Zotero_Browser.statusImage.addEventListener("load", function() { + document.getElementById("zotero-status-image-guidance").show(); + }, false); + } + // TODO: Different guidance for web pages? } else { Zotero_Browser.statusImage.hidden = true; } @@ -723,6 +732,10 @@ Zotero_Browser.Tab = function(browser) { this.page = new Object(); } +Zotero_Browser.Tab.prototype.CAPTURE_STATE_DISABLED = 0; +Zotero_Browser.Tab.prototype.CAPTURE_STATE_GENERIC = 1; +Zotero_Browser.Tab.prototype.CAPTURE_STATE_TRANSLATABLE = 2; + /* * clears page-specific information */ @@ -735,8 +748,6 @@ Zotero_Browser.Tab.prototype.clear = function() { * detects translators for this browser object */ Zotero_Browser.Tab.prototype.detectTranslators = function(rootDoc, doc) { - this.page.saveEnabled = true; - if (doc instanceof HTMLDocument) { if (doc.documentURI.startsWith("about:")) { this.page.saveEnabled = false; @@ -808,55 +819,69 @@ Zotero_Browser.Tab.prototype._attemptLocalFileImport = function(doc) { } } + +Zotero_Browser.Tab.prototype.getCaptureState = function () { + if (!this.page.saveEnabled) { + return this.CAPTURE_STATE_DISABLED; + } + if (this.page.translators && this.page.translators.length) { + return this.CAPTURE_STATE_TRANSLATABLE; + } + return this.CAPTURE_STATE_GENERIC; +} + /* * returns the URL of the image representing the translator to be called on the * current page, or false if the page cannot be scraped */ Zotero_Browser.Tab.prototype.getCaptureIcon = function() { - if (!this.page.saveEnabled) { - return false; - } + var suffix = Zotero.hiRes ? "@2x" : ""; - if(this.page.translators && this.page.translators.length) { + switch (this.getCaptureState()) { + case this.CAPTURE_STATE_DISABLED: + return false; + + case this.CAPTURE_STATE_TRANSLATABLE: var itemType = this.page.translators[0].itemType; return (itemType === "multiple" ? "chrome://zotero/skin/treesource-collection.png" : Zotero.ItemTypes.getImageSrc(itemType)); - } // TODO: Show icons for images, PDFs, etc.? - return "chrome://zotero/skin/treeitem-webpage.png"; + default: + return "chrome://zotero/skin/treeitem-webpage" + suffix + ".png"; + } } Zotero_Browser.Tab.prototype.getCaptureTooltip = function() { - if (!this.page.saveEnabled) { + switch (this.getCaptureState()) { + case this.CAPTURE_STATE_DISABLED: return ''; - } - if (this.page.translators && this.page.translators.length) { + case this.CAPTURE_STATE_TRANSLATABLE: var arr = [Zotero.getString('ingester.saveToZotero')]; if (this.page.translators[0].itemType == 'multiple') { arr.push('...'); } arr.push (' ' , '(' + this.page.translators[0].label + ')'); return Zotero.localeJoin(arr, ''); - } // TODO: Different captions for images, PDFs, etc.? - return Zotero.getString('ingester.saveToZotero') - + " (" + Zotero.getString('itemTypes.webpage') + ")"; + default: + return Zotero.getString('ingester.saveToZotero') + + " (" + Zotero.getString('itemTypes.webpage') + ")"; + } } Zotero_Browser.Tab.prototype.getCaptureCommand = function () { - if (!this.page.saveEnabled) { + switch (this.getCaptureState()) { + case this.CAPTURE_STATE_DISABLED: return ''; - } - - if (this.page.translators && this.page.translators.length) { + case this.CAPTURE_STATE_TRANSLATABLE: return ''; + default: + return 'cmd_zotero_newItemFromCurrentPage'; } - - return 'cmd_zotero_newItemFromCurrentPage'; } @@ -882,6 +907,8 @@ Zotero_Browser.Tab.prototype._selectItems = function(obj, itemList, callback) { * called when translators are available */ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, translators) { + this.page.saveEnabled = true; + if(translators && translators.length) { //see if we should keep the previous set of translators if(//we already have a translator for part of this page @@ -906,6 +933,7 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla return; //keep what we had } else { this.clear(); //clear URL bar icon + this.page.saveEnabled = true; } Zotero.debug("Translate: found translators for page\n" @@ -914,7 +942,6 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla this.page.translate = translate; this.page.translators = translators; this.page.document = translate.document; - this.page.saveEnabled = true; this.page.translate.clearHandlers("select"); this.page.translate.setHandler("select", this._selectItems); diff --git a/chrome/content/zotero/icon.js b/chrome/content/zotero/icon.js new file mode 100644 index 0000000000..ddb32e5044 --- /dev/null +++ b/chrome/content/zotero/icon.js @@ -0,0 +1,90 @@ +/* + ***** BEGIN LICENSE BLOCK ***** + + Copyright © 2015 Center for History and New Media + George Mason University, Fairfax, Virginia, USA + http://zotero.org + + This file is part of Zotero. + + Zotero is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Zotero is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with Zotero. If not, see . + + ***** END LICENSE BLOCK ***** +*/ + +"use strict"; + +Components.utils.import("resource:///modules/CustomizableUI.jsm"); + +var buttonID = 'zotero-toolbar-button'; +CustomizableUI.createWidget({ + id: buttonID, + label: "Zotero", + tooltiptext: "Zotero", + defaultArea: CustomizableUI.AREA_NAVBAR, + onCommand: function () { + ZoteroOverlay.toggleDisplay(); + }, + onCreated: function (node) { + if (Zotero && Zotero.initialized) { + // TODO: move to strings + let str = 'Zotero'; + let key = Zotero.Keys.getKeyForCommand('openZotero'); + if (key) { + str += ' (' + + (Zotero.isMac ? '⇧⌘' : Zotero.getString('general.keys.ctrlShift')) + + key + + ')'; + } + node.setAttribute('tooltiptext', str); + + var placement = CustomizableUI.getPlacementOfWidget(buttonID); + // If icon is in toolbar, show guidance panel if necessary + if (placement && placement.area == 'nav-bar') { + window.setTimeout(function() { + var isUpgrade = false; + try { + isUpgrade = Zotero.Prefs.get("firstRunGuidanceShown.saveIcon"); + } catch(e) {} + var property = "firstRunGuidance.toolbarButton."+(isUpgrade ? "upgrade" : "new"); + var shortcut = Zotero.getString(Zotero.isMac ? "general.keys.cmdShift" : "general.keys.ctrlShift")+ + Zotero.Prefs.get("keys.openZotero"); + document.getElementById("zotero-toolbar-button-guidance").show(null, Zotero.getString(property, shortcut)); + }); + } + } + else { + if (Zotero) { + var errMsg = Zotero.startupError; + } + + // Use defaults if necessary + if (!errMsg) { + // Get the stringbundle manually + var src = 'chrome://zotero/locale/zotero.properties'; + var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1']. + getService(Components.interfaces.nsILocaleService); + var appLocale = localeService.getApplicationLocale(); + var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] + .getService(Components.interfaces.nsIStringBundleService); + var stringBundle = stringBundleService.createBundle(src, appLocale); + + var errMsg = stringBundle.GetStringFromName('startupError'); + } + + node.setAttribute('tooltiptext', errMsg); + node.setAttribute('error', 'true'); + } + } +}); diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 5c71b68a8c..95c168cef8 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -70,89 +70,21 @@ var ZoteroOverlay = new function() observerService.addObserver(zoteroObserver, "browser-delayed-startup-finished", false); - // Make Zotero icon visible, if requested + // Set a flag for hi-res displays + Zotero.hiRes = window.devicePixelRatio > 1; + + // Clear old Zotero icon pref var prefBranch = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService) .getBranch('extensions.zotero.'); + prefBranch.clearUserPref('statusBarIcon'); - var navBar = document.getElementById('nav-bar'); - - var iconPref = prefBranch.getIntPref('statusBarIcon'); - - // Add icon to toolbar if not in the window already and not hidden by the pref - if (!document.getElementById("zotero-toolbar-button") && iconPref != 0) { - navBar.insertItem("zotero-toolbar-button"); - navBar.setAttribute("currentset", navBar.currentSet); - document.persist(navBar.id, "currentset"); - navBar.setAttribute("collapsed", false); - document.persist(navBar.id, "collapsed"); - } - - var icon = document.getElementById('zotero-toolbar-button'); - - // Add a listener for toolbar change events - window.addEventListener("customizationchange", onToolbarChange, false); + // Add toolbar icon + Services.scriptloader.loadSubScript("chrome://zotero/content/icon.js", {}, "UTF-8"); if (Zotero && Zotero.initialized){ + // TODO: Add only when progress window is open document.getElementById('appcontent').addEventListener('mousemove', Zotero.ProgressWindowSet.updateTimers, false); - if (icon) { - // TODO: move to strings - let str = 'Zotero'; - let key = Zotero.Keys.getKeyForCommand('openZotero'); - if (key) { - str += ' (' - + (Zotero.isMac ? '⇧⌘' : Zotero.getString('general.keys.ctrlShift')) - + key - + ')'; - } - icon.setAttribute('tooltiptext', str); - - // If hidden in prefs, remove from add-on bar - if (iconPref == 0) { - var toolbar = icon.parentNode; - if (toolbar.id == 'nav-bar') { - var palette = document.getElementById("navigator-toolbox").palette; - palette.appendChild(icon); - toolbar.setAttribute("currentset", toolbar.currentSet); - document.persist(toolbar.id, "currentset"); - } - } - - if (icon.getAttribute("cui-areatype") == "toolbar") { - window.setTimeout(function() { - var isUpgrade = false; - try { - isUpgrade = Zotero.Prefs.get("firstRunGuidanceShown.saveIcon"); - } catch(e) {} - var property = "firstRunGuidance.toolbarButton."+(isUpgrade ? "upgrade" : "new"); - var shortcut = Zotero.getString(Zotero.isMac ? "general.keys.cmdShift" : "general.keys.ctrlShift")+ - Zotero.Prefs.get("keys.openZotero"); - document.getElementById("zotero-toolbar-button-guidance").show(null, Zotero.getString(property, shortcut)); - }, 0); - } - } - } - else { - if (Zotero) { - var errMsg = Zotero.startupError; - } - - // Use defaults if necessary - if (!errMsg) { - // Get the stringbundle manually - var src = 'chrome://zotero/locale/zotero.properties'; - var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1']. - getService(Components.interfaces.nsILocaleService); - var appLocale = localeService.getApplicationLocale(); - var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] - .getService(Components.interfaces.nsIStringBundleService); - var stringBundle = stringBundleService.createBundle(src, appLocale); - - var errMsg = stringBundle.GetStringFromName('startupError'); - } - - icon.setAttribute('tooltiptext', errMsg); - icon.setAttribute('error', 'true'); } // Used for loading pages from upgrade wizard @@ -191,28 +123,7 @@ var ZoteroOverlay = new function() } - function onToolbarChange(e) { - // e.target seems to be navigator-toolbox in all cases, - // so check the nav-bar directly - var navBar = document.getElementById("nav-bar"); - var icon = document.getElementById("zotero-toolbar-button"); - if (icon) { - // If dragged to nav bar - if (navBar.getElementsByAttribute("id", "zotero-toolbar-button").length) { - var statusBarPref = Zotero.Prefs.get("statusBarIcon"); - // If pref set to hide, force to full - if (statusBarPref == 0) { - Zotero.Prefs.set("statusBarIcon", 1) - } - return; - } - } - Zotero.Prefs.set("statusBarIcon", 0); - } - - this.onUnload = function() { - window.removeEventListener("customizationchange", onToolbarChange, false); ZoteroPane.destroy(); } diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul index 8d758db2b7..87c163fda2 100644 --- a/chrome/content/zotero/overlay.xul +++ b/chrome/content/zotero/overlay.xul @@ -43,12 +43,6 @@ - - - - diff --git a/chrome/skin/default/zotero/overlay.css b/chrome/skin/default/zotero/overlay.css index 0a4a66c5c4..c9c32337b9 100644 --- a/chrome/skin/default/zotero/overlay.css +++ b/chrome/skin/default/zotero/overlay.css @@ -1,7 +1,11 @@ -#zotero-status-image -{ +#zotero-status-image { width: 16px; height: 16px; + margin-right: 3px; +} + +#zotero-status-image:not(.translate):not(:hover) { + filter: grayscale(100%); } #zotero-pane diff --git a/chrome/skin/default/zotero/treeitem-webpage@2x.png b/chrome/skin/default/zotero/treeitem-webpage@2x.png new file mode 100644 index 0000000000..ba7bc2ef7e Binary files /dev/null and b/chrome/skin/default/zotero/treeitem-webpage@2x.png differ diff --git a/chrome/skin/default/zotero/zotero.css b/chrome/skin/default/zotero/zotero.css index b166e3c3dd..c7d8074db5 100644 --- a/chrome/skin/default/zotero/zotero.css +++ b/chrome/skin/default/zotero/zotero.css @@ -22,40 +22,17 @@ } /* - Add-on bar and toolbar icon + Toolbar icons */ - -/* Old styling */ #zotero-toolbar-button { - list-style-image: url(chrome://zotero/skin/zotero-z-24px.png); + list-style-image: url("chrome://zotero/skin/zotero-z-16px-australis.svg"); } -#zotero-toolbar-button:active { - list-style-image: url(chrome://zotero/skin/zotero-z-24px-active.png); -} - -toolbar[iconsize="small"] #zotero-toolbar-button { - list-style-image: url(chrome://zotero/skin/zotero-z-16px.png); -} - -toolbar[iconsize="small"] #zotero-toolbar-button:active { - list-style-image: url(chrome://zotero/skin/zotero-z-16px-active.png); -} - -/* Australis styling */ #zotero-toolbar-button[cui-areatype="menu-panel"], -toolbarpaletteitem[place="palette"] > #zotero-toolbar-button, -#zotero-toolbar-button:active[cui-areatype="menu-panel"], -toolbarpaletteitem[place="palette"] > #zotero-toolbar-button:active { - list-style-image: url("chrome://zotero/skin/zotero-z-32px-australis.svg"); +toolbarpaletteitem[place="palette"] > #zotero-toolbar-button { + list-style-image: url("chrome://zotero/skin/zotero-z-32px-australis.svg"); } -#zotero-toolbar-button[cui-areatype="toolbar"], -#zotero-toolbar-button:active[cui-areatype="toolbar"] { - list-style-image: url("chrome://zotero/skin/zotero-z-16px-australis.svg") !important; -} - - /* Bindings */ textbox[multiline="true"][type="timed"] { diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js index 279904094a..6bfacd496c 100644 --- a/defaults/preferences/zotero.js +++ b/defaults/preferences/zotero.js @@ -26,7 +26,6 @@ pref("extensions.zotero.triggerProxyAuthentication", true); pref("extensions.zotero.proxyAuthenticationURLs", 'http://www.acm.org,http://www.ebscohost.com,http://www.elsevier.com,http://www.ieee.org,http://www.jstor.org,http://www.ovid.com,http://www.springer.com,http://www.tandfonline.com'); pref("extensions.zotero.cacheTranslatorData",true); pref("extensions.zotero.showIn", 1); -pref("extensions.zotero.statusBarIcon", 1); pref("extensions.zotero.browserContentContextMenu", true); pref("extensions.zotero.openURL.resolver","http://worldcatlibraries.org/registry/gateway"); pref("extensions.zotero.openURL.version","1.0");