Basic viewer: Open separate windows per URI (#3081)

This commit is contained in:
Abe Jellinek 2023-04-12 16:53:28 -04:00 committed by GitHub
parent 8e6f33f045
commit b33d3ec799
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 33 deletions

View file

@ -124,22 +124,6 @@ var Zotero_Preferences = {
} }
}, },
/**
* Opens a URI in the basic viewer
*/
openInViewer: function (uri) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("zotero:basicViewer");
if (win) {
win.loadURI(uri);
}
else {
window.openDialog("chrome://zotero/content/standalone/basicViewer.xhtml",
"basicViewer", "chrome,resizable,centerscreen,menubar,scrollbars", uri);
}
},
_onNavigationSelect() { _onNavigationSelect() {
for (let child of this.content.children) { for (let child of this.content.children) {
if (child !== this.helpContainer) { if (child !== this.helpContainer) {

View file

@ -253,10 +253,10 @@
<hbox id="zotero-prefpane-advanced-open-buttons" align="center"> <hbox id="zotero-prefpane-advanced-open-buttons" align="center">
<button id="config-editor" <button id="config-editor"
label="&zotero.preferences.configEditor;" label="&zotero.preferences.configEditor;"
oncommand="Zotero_Preferences.openInViewer('about:config')"/> oncommand="Zotero.openInViewer('about:config')"/>
<button id="memory-info" <button id="memory-info"
label="Memory Info" label="Memory Info"
oncommand="Zotero_Preferences.openInViewer('about:memory')" oncommand="Zotero.openInViewer('about:memory')"
hidden="true"/> hidden="true"/>
</hbox> </hbox>
</vbox> </vbox>

View file

@ -61,10 +61,10 @@
<hbox> <hbox>
<button id="openCSLEdit" <button id="openCSLEdit"
label="&zotero.preferences.styleEditor;" label="&zotero.preferences.styleEditor;"
oncommand="Zotero_Preferences.openInViewer('chrome://zotero/content/tools/csledit.xhtml', true)"/> oncommand="Zotero.openInViewer('chrome://zotero/content/tools/csledit.xhtml', true)"/>
<button id="openCSLPreview" <button id="openCSLPreview"
label="&zotero.preferences.stylePreview;" label="&zotero.preferences.stylePreview;"
oncommand="Zotero_Preferences.openInViewer('chrome://zotero/content/tools/cslpreview.xhtml', true)"/> oncommand="Zotero.openInViewer('chrome://zotero/content/tools/cslpreview.xhtml', true)"/>
</hbox> </hbox>
</groupbox> </groupbox>
</vbox> </vbox>

View file

@ -52,6 +52,7 @@ window.addEventListener("load", /*async */function () {
//browser.docShellIsActive = false; //browser.docShellIsActive = false;
// Load URI passed in as nsISupports .data via openWindow() // Load URI passed in as nsISupports .data via openWindow()
window.viewerOriginalURI = window.arguments[0];
loadURI(window.arguments[0]); loadURI(window.arguments[0]);
}, false); }, false);

View file

@ -1090,21 +1090,22 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
* @param {Function} [onLoad] - Function to run once URI is loaded; passed the loaded document * @param {Function} [onLoad] - Function to run once URI is loaded; passed the loaded document
*/ */
this.openInViewer = function (uri, onLoad) { this.openInViewer = function (uri, onLoad) {
var wm = Services.wm; var viewerWins = Services.wm.getEnumerator("zotero:basicViewer");
var win = wm.getMostRecentWindow("zotero:basicViewer"); for (let existingWin of viewerWins) {
if (win) { if (existingWin.viewerOriginalURI === uri) {
win.loadURI(uri); existingWin.focus();
} else { return;
let ww = Components.classes['@mozilla.org/embedcomp/window-watcher;1'] }
.getService(Components.interfaces.nsIWindowWatcher);
let arg = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
arg.data = uri;
win = ww.openWindow(null, "chrome://zotero/content/standalone/basicViewer.xhtml",
"basicViewer", "chrome,dialog=yes,resizable,centerscreen,menubar,scrollbars", arg);
} }
let ww = Components.classes['@mozilla.org/embedcomp/window-watcher;1']
.getService(Components.interfaces.nsIWindowWatcher);
let arg = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
arg.data = uri;
let win = ww.openWindow(null, "chrome://zotero/content/standalone/basicViewer.xhtml",
null, "chrome,dialog=yes,resizable,centerscreen,menubar,scrollbars", arg);
if (onLoad) { if (onLoad) {
let browser let browser;
let func = function () { let func = function () {
win.removeEventListener("load", func); win.removeEventListener("load", func);
// <browser> is created in basicViewer.js in a window load event, so we have to // <browser> is created in basicViewer.js in a window load event, so we have to