From 4ef7c943744d23714278e95209a022f63876dda8 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 10 Feb 2012 01:20:00 -0500 Subject: [PATCH] Switch to regular add-on bar button Can be moved/removed via Customize as well as via Zotero prefs. The icon can be in the toolbar or in the add-on bar, but not both, because it's now the same button with different styling depending on where it is. If the icon does not exist in the UI and the pref is set to show (as it is by default), the icon is added to the add-on bar and the add-on bar is persisted open. This has the effect of showing the icon/bar on first run. If the icon is removed or the bar is hidden, they remain that way. --- chrome/content/zotero/overlay.js | 91 ++++++++++++------ .../content/zotero/preferences/preferences.js | 16 ++- chrome/content/zotero/statusBarOverlay.xul | 9 -- chrome/content/zotero/xpcom/zotero.js | 73 +++++++++++++- chrome/skin/default/zotero/overlay.css | 26 ----- .../default/zotero/zotero-z-16px-hover.png | Bin 1011 -> 0 bytes .../default/zotero/zotero-z-24px-hover.png | Bin 1823 -> 0 bytes chrome/skin/default/zotero/zotero.css | 38 ++++---- 8 files changed, 161 insertions(+), 92 deletions(-) delete mode 100644 chrome/content/zotero/statusBarOverlay.xul delete mode 100644 chrome/skin/default/zotero/zotero-z-16px-hover.png delete mode 100644 chrome/skin/default/zotero/zotero-z-24px-hover.png 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 777d4682438a51111941dc84d90e82ab4611731b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1011 zcmVn`gc-ciox^2@_6I5-i z*g3hm8Q_j%WMKI9;|IgTv*-UDnlXF%$9wmSIM~?VZ~_eg2q4B{paDPs{uW^6=ilmI zTWuw*AkXma!$*ey|Nfykm63^&frE#K;oHYg44ax;FMfRR$X(>e$Cm&B#PSy?`SaKB zsmAW^R?KXy48Oj8V^Fp-2U!XSe}Df08~EY*3x;=QkgNJ~68G#zUGANoDF}M{MFnoFYmf_gq zr9k=}P>PY^|KEQM|Ns2W1PCA&pe0tnfwsK7b(?`tT%6(WpFfa5`}&PRLQR#yF*}pt zA5d&vO+CZ&>oeUGR8%t@1v;IJkB{LuFo1soF(_Psnn7Xo3m|}4fVN)-rbbgxH2wMg zo8i~@?+nQc<}xT-S}<&=Z(>;6*~S1glHteakH7@S#K6kQ1=S4F&v+9cfLIuqndUM4 z`)3N`|N8Nb!M&h>!6G_>;p_YN3_pR1C!n-~fr*&~tp4@A`wSP>Z)9L*Wr3z+<|P0D z#KOtMyx<$--y~pInEnU)g-1vb7!%KcX_Jw`yBeq&WE(I>fevK2wqqB=+0|srXPJ+=?XJ5lk1Pa|K|Ss`NIg9F;KG{Bu#+{R%YhwH~;@hHDX{p z{tp;?00G1VlV|(SaDnsRe|t6-ri%Ye%r}{sng25|Gc$lN6ASZypx8ZDR;I@7KR;XV h`~CeW%zXd>1^@%1SH2+Nr1Ag&002ovPDHLkV1l5Q*e?J8 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 9d542654eb29e77417f329ab2b5cd62427a29fe0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1823 zcmV+)2jKXLP)NmlfBmQ^#LN@&M_SxdRzX3VO-N9ffr*jv z@5j&YpFDbao%zx8U2lGVSR>BGd!6wgGsA@6pBakzgu&)@zk3O$0Ro5xMEC{E-W^U1T9 z!knBJfo@=Uar*`XuaF1>KmalG?m5VClHm`71sfN`$M4^g)s&Q%1vJ(3i6|*De0~3( z;pdmH41a$71RDAa6$35%_3azOkI!EiIQjS()NO4z|37^e@c7Q%pB(ILM;MqG81C&n zzyJ_HEUfJ84F7+9V)*>~mk$Rg=WLtw6h;;f4u%iUo`K_p;XeaGz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j8vM&xD-+yY>^&dkcl@b<@dqyH=%VO)%iPC!*EzZw4X zgW?Ssv7dkueE-M)|A+qn`LSAvgY(FLVEM=ltOa2fG(Wiyu0{a@3;?5A*5M^Rwsrsj N002ovPDHLkV1kyuOm+YO 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); }