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
This commit is contained in:
parent
5bcce8ba82
commit
0828d4d5e9
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user