diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 0db2d7c43..a20a12631 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -36,6 +36,8 @@ var ZoteroOverlay = new function() this.isTab = false; this.onLoad = function() { + try { + zoteroPane = document.getElementById('zotero-pane-stack'); zoteroSplitter = document.getElementById('zotero-splitter'); @@ -74,43 +76,45 @@ var ZoteroOverlay = new function() } // Make Zotero icon visible, if requested - var iconPref = Components.classes["@mozilla.org/preferences-service;1"] + var prefBranch = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService) - .getBranch('extensions.zotero.').getIntPref('statusBarIcon'); + .getBranch('extensions.zotero.'); - var fx36Icon = document.getElementById('zotero-status-bar-icon'); var addonBar = document.getElementById('addon-bar'); - // Status bar in Fx3.6 - if (isFx36) { - var icon = fx36Icon; - } - // In >=Fx4, add to add-on bar - else { - // add Zotero icon - var icon = document.createElement('toolbarbutton'); - icon.id = 'zotero-addon-bar-icon'; - icon.setAttribute('oncommand', 'ZoteroOverlay.toggleDisplay()'); - icon.setAttribute('hidden', true); - addonBar.appendChild(icon); - if (addonBar.collapsed) { - // If no Zotero or icon isn't set to hidden, show add-on bar - if (iconPref != 0) { - setToolbarVisibility(addonBar, true); - } - } + var iconPref = prefBranch.getIntPref('statusBarIcon'); + + // If this is the first run, add icon to add-on bar if not + // in the window already and not hidden by the Zotero prefs + if (!document.getElementById("zotero-toolbar-button") && iconPref != 0) { + addonBar.insertItem("zotero-toolbar-button"); + addonBar.setAttribute("currentset", addonBar.currentSet); + document.persist(addonBar.id, "currentset"); + addonBar.setAttribute("collapsed", false); + document.persist(addonBar.id, "collapsed"); } + var icon = document.getElementById('zotero-toolbar-button'); + + // Add a listener for toolbar change events + window.addEventListener("customizationchange", onToolbarChange, false); + if (Zotero && Zotero.initialized){ document.getElementById('appcontent').addEventListener('mousemove', Zotero.ProgressWindowSet.updateTimers, false); - switch (iconPref) { - case 2: - icon.setAttribute('hidden', false); - break; - case 1: - icon.setAttribute('hidden', false); + if (icon) { + if (iconPref == 1) { icon.setAttribute('compact', true); - break; + } + // If hidden in prefs, remove from add-on bar + else if (iconPref == 0) { + var toolbar = icon.parentNode; + if (toolbar.id == 'addon-bar') { + var palette = doc.getElementById("navigator-toolbox").palette; + palette.appendChild(icon); + toolbar.setAttribute("currentset", toolbar.currentSet); + document.persist(toolbar.id, "currentset"); + } + } } } else { @@ -134,7 +138,6 @@ var ZoteroOverlay = new function() icon.setAttribute('tooltiptext', errMsg); icon.setAttribute('error', 'true'); - icon.setAttribute('hidden', false); } // Used for loading pages from upgrade wizard @@ -162,9 +165,39 @@ var ZoteroOverlay = new function() ZoteroOverlay.toggleDisplay(_stateBeforeReload); } }); + + } + catch (e) { + Zotero.debug(e); + } } + + function onToolbarChange(e) { + // e.target seems to be navigator-toolbox in all cases, + // so check the addon-bar directly + var addonBar = document.getElementById("addon-bar"); + var icon = document.getElementById("zotero-toolbar-button"); + if (icon) { + // If dragged to add-on bar + if (addonBar.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", 2) + } + else if (statusBarPref == 1) { + icon.setAttribute("compact", true); + } + return; + } + } + Zotero.Prefs.set("statusBarIcon", 0); + } + + this.onUnload = function() { + window.removeEventListener("customizationchange", onToolbarChange, false); ZoteroPane.destroy(); } diff --git a/chrome/content/zotero/preferences/preferences.js b/chrome/content/zotero/preferences/preferences.js index 4217e7fec..6bd332728 100644 --- a/chrome/content/zotero/preferences/preferences.js +++ b/chrome/content/zotero/preferences/preferences.js @@ -1853,19 +1853,17 @@ function updateWordProcessorInstructions() { } /** - * Sets "Status bar icon" to "None" if Zotero is set to load in separate tab on Fx 4 + * Sets "Status bar icon" to "None" if Zotero is set to load in separate tab */ function handleShowInPreferenceChange() { var showInSeparateTab = document.getElementById("zotero-prefpane-general-showIn-separateTab"); var showInAppTab = document.getElementById("zotero-prefpane-general-showIn-appTab"); - if(Zotero.isFx4) { - if(showInAppTab.selected) { - document.getElementById('statusBarIcon').selectedItem = document.getElementById('statusBarIcon-none'); - Zotero.Prefs.set("statusBarIcon", 0); - } else if(Zotero.isFx4) { - document.getElementById('statusBarIcon').selectedItem = document.getElementById('statusBarIcon-full'); - Zotero.Prefs.set("statusBarIcon", 2); - } + if(showInAppTab.selected) { + document.getElementById('statusBarIcon').selectedItem = document.getElementById('statusBarIcon-none'); + Zotero.Prefs.set("statusBarIcon", 0); + } else { + document.getElementById('statusBarIcon').selectedItem = document.getElementById('statusBarIcon-full'); + Zotero.Prefs.set("statusBarIcon", 2); } } diff --git a/chrome/content/zotero/statusBarOverlay.xul b/chrome/content/zotero/statusBarOverlay.xul deleted file mode 100644 index 94e580f94..000000000 --- a/chrome/content/zotero/statusBarOverlay.xul +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 24eb8fb7d..405bf6913 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -2033,9 +2033,74 @@ Zotero.Prefs = new function(){ if(topic!="nsPref:changed"){ return; } + + try { + // subject is the nsIPrefBranch we're observing (after appropriate QI) // data is the name of the pref that's been changed (relative to subject) - switch (data){ + switch (data) { + case "statusBarIcon": + var doc = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator) + .getMostRecentWindow("navigator:browser").document; + + var addonBar = doc.getElementById("addon-bar"); + var icon = doc.getElementById("zotero-toolbar-button"); + // When the customize window is open, toolbar buttons seem to + // become wrapped in toolbarpaletteitems, which we need to remove + // manually if we change the pref to hidden or else the customize + // window doesn't close. + var wrapper = doc.getElementById("wrapper-zotero-toolbar-button"); + var palette = doc.getElementById("navigator-toolbox").palette; + var inAddonBar = false; + if (icon) { + // Because of the potential wrapper, don't just use .parentNode + var toolbar = Zotero.getAncestorByTagName(icon, "toolbar"); + inAddonBar = toolbar == addonBar; + } + var val = this.get("statusBarIcon"); + if (val == 0) { + // If showing in add-on bar, hide + if (!icon || !inAddonBar) { + return; + } + palette.appendChild(icon); + if (wrapper) { + addonBar.removeChild(wrapper); + } + addonBar.setAttribute("currentset", addonBar.currentSet); + doc.persist(addonBar.id, "currentset"); + } + else { + // If showing somewhere else, remove it from there + if (icon && !inAddonBar) { + palette.appendChild(icon); + if (wrapper) { + toolbar.removeChild(wrapper); + } + toolbar.setAttribute("currentset", toolbar.currentSet); + doc.persist(toolbar.id, "currentset"); + } + + // If not showing in add-on bar, add + if (!inAddonBar) { + var icon = addonBar.insertItem("zotero-toolbar-button"); + addonBar.setAttribute("currentset", addonBar.currentSet); + doc.persist(addonBar.id, "currentset"); + addonBar.setAttribute("collapsed", false); + doc.persist(addonBar.id, "collapsed"); + } + // And make small + if (val == 1) { + icon.setAttribute("compact", true); + } + // Or large + else if (val == 2) { + icon.removeAttribute("compact"); + } + } + break; + case "automaticScraperUpdates": if (this.get('automaticScraperUpdates')){ Zotero.Schema.updateFromRepository(); @@ -2081,6 +2146,12 @@ Zotero.Prefs = new function(){ } break; } + + } + catch (e) { + Zotero.debug(e); + throw (e); + } } } diff --git a/chrome/skin/default/zotero/overlay.css b/chrome/skin/default/zotero/overlay.css index dd7f2bc29..0c592af27 100644 --- a/chrome/skin/default/zotero/overlay.css +++ b/chrome/skin/default/zotero/overlay.css @@ -3,32 +3,6 @@ width: 16px; height: 16px; } -#zotero-status-bar-icon, #zotero-addon-bar-icon -{ - width: 55px; - list-style-image: url(chrome://zotero/skin/zotero_status_bar.png); -} -#zotero-status-bar-icon -{ - margin: 0 0 -1px; /* For Fitts's law (on OS X, at least) */ - padding: 0 0 1px; -} -#zotero-addon-bar-icon -{ - margin-left: 10px; - margin-right: 10px; - padding: 0 0 1px 0; - -moz-appearance: none; -} -#zotero-status-bar-icon[compact="true"], #zotero-addon-bar-icon[compact="true"] -{ - width: 20px; - list-style-image: url(chrome://zotero/skin/zotero_status_bar_compact.png); -} -#zotero-status-bar-icon[error="true"], #zotero-addon-bar-icon[error="true"] -{ - list-style-image: url(chrome://zotero/skin/zotero_status_bar_error.png); -} #zotero-pane { diff --git a/chrome/skin/default/zotero/zotero-z-16px-hover.png b/chrome/skin/default/zotero/zotero-z-16px-hover.png deleted file mode 100644 index 777d46824..000000000 Binary files a/chrome/skin/default/zotero/zotero-z-16px-hover.png and /dev/null differ diff --git a/chrome/skin/default/zotero/zotero-z-24px-hover.png b/chrome/skin/default/zotero/zotero-z-24px-hover.png deleted file mode 100644 index 9d542654e..000000000 Binary files a/chrome/skin/default/zotero/zotero-z-24px-hover.png and /dev/null differ diff --git a/chrome/skin/default/zotero/zotero.css b/chrome/skin/default/zotero/zotero.css index 891eb6386..337d47e04 100644 --- a/chrome/skin/default/zotero/zotero.css +++ b/chrome/skin/default/zotero/zotero.css @@ -21,34 +21,36 @@ padding:0; } -#zotero-toolbar-button -{ - list-style-image: url('chrome://zotero/skin/zotero-z-24px.png'); +/* + Add-on bar and toolbar icon +*/ +#zotero-toolbar-button { + list-style-image: url(chrome://zotero/skin/zotero-z-24px.png); } -#zotero-toolbar-button:hover -{ - list-style-image: url('chrome://zotero/skin/zotero-z-24px-hover.png'); +#zotero-toolbar-button:active { + list-style-image: url(chrome://zotero/skin/zotero-z-24px-active.png); } -#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 -{ - 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); } -toolbar[iconsize="small"] #zotero-toolbar-button:hover -{ - list-style-image: url('chrome://zotero/skin/zotero-z-16px-hover.png'); +#addon-bar #zotero-toolbar-button { + list-style-image: url(chrome://zotero/skin/zotero_status_bar.png); } -toolbar[iconsize="small"] #zotero-toolbar-button:active -{ - list-style-image: url('chrome://zotero/skin/zotero-z-16px-active.png'); +#addon-bar #zotero-toolbar-button[compact="true"] { + width: 20px; + list-style-image: url(chrome://zotero/skin/zotero_status_bar_compact.png); +} + +#addon-bar #zotero-toolbar-button[error="true"] { + list-style-image: url(chrome://zotero/skin/zotero_status_bar_error.png); }