fix some cases where multiple Zotero tabs could be open

This commit is contained in:
Simon Kornblith 2011-02-03 20:22:56 +00:00
parent e26b292324
commit 0578c01899
3 changed files with 27 additions and 6 deletions

View file

@ -28,7 +28,6 @@
*/
var ZoteroOverlay = new function()
{
const ZOTERO_TAB_URL = "chrome://zotero/content/tab.xul";
const DEFAULT_ZPANE_HEIGHT = 300;
var toolbarCollapseState, isFx36, showInPref;
@ -47,12 +46,9 @@ var ZoteroOverlay = new function()
if(!isFx36) {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var zoteroObserver = {"observe":function(subject, topic, data) {
var zoteroObserver = function(subject, topic, data) {
if(subject != window) return;
observerService.removeObserver(this, "browser-delayed-startup-finished");
Zotero.wait(1000); // there ought to be a better way to determine when the tab
// will have a reasonable URI instead of returning about:blank,
// but I'm not sure what it is
if(showInPref === 2) {
var tabbar = document.getElementById("TabsToolbar");
if(tabbar && window.getComputedStyle(tabbar).display !== "none") {
@ -64,7 +60,7 @@ var ZoteroOverlay = new function()
var zoteroTab = ZoteroOverlay.findZoteroTab();
if(zoteroTab) gBrowser.removeTab(zoteroTab);
}
}};
};
observerService.addObserver(zoteroObserver, "browser-delayed-startup-finished", false);
}

View file

@ -40,6 +40,17 @@ var ZoteroTab = new function()
}
if(browserIndex === -1) return;
// if we somehow ended up with other Zotero tabs in the window, close them
var numTabs = window.gBrowser.browsers.length;
for(var index = 0; index < numTabs; index++) {
if(index === browserIndex) continue;
var currentBrowser = window.gBrowser.browsers[index];
if(currentBrowser && ZOTERO_TAB_URL == currentBrowser.currentURI.spec) {
window.gBrowser.removeTab(window.gBrowser.tabs[index]);
}
}
// initialize ZoteroPane and swap out old window ZoteroPane object
if(window.ZoteroPane) {
window.ZoteroPane_Overlay = window.ZoteroPane;
@ -69,6 +80,19 @@ var ZoteroTab = new function()
}
window.gBrowser.tabContainer.addEventListener("TabSelect", listener, false);
}
if(Zotero && Zotero.isFx4) {
// on Fx 4, add an event listener so the pinned tab isn't restored on close
var pinnedTabCloser = function() {
try {
window.gBrowser.removeTab(tab);
} catch(e) {}
}
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(pinnedTabCloser, "quit-application-requested", false);
window.addEventListener("close", pinnedTabCloser, false);
}
}
this.onUnload = function() {

View file

@ -22,6 +22,7 @@
***** END LICENSE BLOCK *****
*/
const ZOTERO_TAB_URL = "chrome://zotero/content/tab.xul";
/*
* This object contains the various functions for the interface