www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 0828d4d5e971e0b1425ad52e9587f535f5e2a0b1
parent 5bcce8ba826008e4e7a831c8cb467afd54b1de58
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue,  6 Sep 2016 19:10:51 -0400

openPreferences() updates

- Move openPreferences() to Zotero.Utilities.Internal
- Add support for opening windows when there's no active browser window
- Allow selecting prefpane tab by id via 'tab' property
- openPreferences() now takes an object as its second argument with a
  'tab', 'tabIndex', or 'action' property

Diffstat:
Mchrome/content/zotero/preferences/preferences.js | 22++++++++++++++++++++--
Mchrome/content/zotero/xpcom/utilities_internal.js | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mchrome/content/zotero/zoteroPane.js | 33++++-----------------------------
3 files changed, 80 insertions(+), 31 deletions(-)

diff --git a/chrome/content/zotero/preferences/preferences.js b/chrome/content/zotero/preferences/preferences.js @@ -41,11 +41,29 @@ var Zotero_Preferences = { var io = window.arguments[0]; if(io.pane) { + let tabID = io.tab; let tabIndex = io.tabIndex; var pane = document.getElementById(io.pane); document.getElementById('zotero-prefs').showPane(pane); - // Select tab within pane - if (tabIndex !== undefined) { + // Select tab within pane by tab id + if (tabID !== undefined) { + if (pane.loaded) { + let tab = document.querySelector('tab#' + tabID); + if (tab) { + document.getElementsByTagName('tabbox')[0].selectedTab = tab; + } + } + else { + pane.addEventListener('paneload', function () { + let tab = document.querySelector('tab#' + tabID); + if (tab) { + document.getElementsByTagName('tabbox')[0].selectedTab = tab; + } + }) + } + } + // Select tab within pane by index + else if (tabIndex !== undefined) { if (pane.loaded) { document.getElementsByTagName('tabbox')[0].selectedIndex = tabIndex; } diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js @@ -1117,6 +1117,62 @@ Zotero.Utilities.Internal = { }, + openPreferences: function (paneID, options = {}) { + if (typeof options == 'string') { + Zotero.debug("ZoteroPane.openPreferences() now takes an 'options' object -- update your code", 2); + options = { + action: options + }; + } + + var io = { + pane: paneID, + tab: options.tab, + tabIndex: options.tabIndex, + action: options.action + }; + + var win = null; + // If window is already open and no special action, just focus it + if (!options.action) { + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + var enumerator = wm.getEnumerator("zotero:pref"); + if (enumerator.hasMoreElements()) { + var win = enumerator.getNext(); + win.focus(); + if (paneID) { + var pane = win.document.getElementsByAttribute('id', paneID)[0]; + pane.parentElement.showPane(pane); + + // TODO: tab/action + } + } + } + if (!win) { + let args = [ + 'chrome://zotero/content/preferences/preferences.xul', + 'zotero-prefs', + 'chrome,titlebar,toolbar,centerscreen,' + + Zotero.Prefs.get('browser.preferences.instantApply', true) ? 'dialog=no' : 'modal', + io + ]; + + let win = Services.wm.getMostRecentWindow("navigator:browser"); + if (win) { + win.openDialog(...args); + } + else { + // nsIWindowWatcher needs a wrappedJSObject + args[args.length - 1].wrappedJSObject = args[args.length - 1]; + Services.ww.openWindow(null, ...args); + } + } + + return win; + }, + + /** * Quits Zotero, optionally restarting. * @param {Boolean} [restart=false] diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js @@ -1660,7 +1660,7 @@ var ZoteroPane = new function() null, null, null, {} ); if (index == 0) { - ZoteroPane_Local.openPreferences('zotero-prefpane-search', 'pdftools-install'); + ZoteroPane_Local.openPreferences('zotero-prefpane-search', { action: 'pdftools-install' }); } return false; } @@ -3164,34 +3164,9 @@ var ZoteroPane = new function() this.openPreferences = function (paneID, action) { - var io = { - pane: paneID, - action: action - }; - - var win = null; - // If window is already open, just focus it - if (!action) { - var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator); - var enumerator = wm.getEnumerator("zotero:pref"); - if (enumerator.hasMoreElements()) { - var win = enumerator.getNext(); - win.focus(); - if (paneID) { - var pane = win.document.getElementsByAttribute('id', paneID)[0]; - pane.parentElement.showPane(pane); - } - } - } - if (!win) { - window.openDialog('chrome://zotero/content/preferences/preferences.xul', - 'zotero-prefs', - 'chrome,titlebar,toolbar,centerscreen,' - + Zotero.Prefs.get('browser.preferences.instantApply', true) ? 'dialog=no' : 'modal', - io - ); - } + Zotero.warn("ZoteroPane.openPreferences() is deprecated" + + " -- use Zotero.Utilities.Internal.openPreferences() instead"); + Zotero.Utilities.Internal.openPreferences(paneID, { action }); }