From 96345a3aa82e18b7b17169f3d88fc9393c952a67 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 8 Aug 2009 07:38:34 +0000 Subject: [PATCH] Don't hang UI when importing files - File import now uses a translucent overlay over Zotero pane with a progress meter that doesn't hang - New method Zotero.wait(timeout) to allow synchronous code to wait for events on main thread to be processed until timeout is reached - Wait status can be tested with Zotero.waiting property - Zotero.showZoteroPaneProgressBar(msg, determinate) locks Zotero and creates overlay with progress meter - Code that might trigger via timers or external UI should check Zotero.lock Lock checks so far: - Translator save icon and RIS/Refer import display error if triggered while locked - Browser content context menu options are now in a Zotero submenu and are disabled when Zotero is locked - Sync, repository, and DB backup timers check for lock and bail - If a new window is opened, Zotero pane can't be opened and display an error message until lock is released Probably need to check lock in word processor integration code and advanced search window Also: - New method Zotero.sleep(ms) (currently unused) to allow synchronous code to sleep and allow events on main thread to be processed --- chrome/content/zotero/browser.js | 11 ++ chrome/content/zotero/fileInterface.js | 60 ++--------- chrome/content/zotero/fileProgress.xul | 15 --- chrome/content/zotero/overlay.js | 51 ++++++--- chrome/content/zotero/overlay.xul | 63 ++++++++--- chrome/content/zotero/xpcom/db.js | 15 +++ chrome/content/zotero/xpcom/ingester.js | 16 ++- chrome/content/zotero/xpcom/schema.js | 6 ++ chrome/content/zotero/xpcom/sync.js | 5 + chrome/content/zotero/xpcom/translate.js | 3 + chrome/content/zotero/xpcom/zotero.js | 129 +++++++++++++++++++++++ chrome/skin/default/zotero/overlay.css | 8 +- 12 files changed, 282 insertions(+), 100 deletions(-) delete mode 100644 chrome/content/zotero/fileProgress.xul diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index cbd073644d..fce82cda86 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -120,6 +120,17 @@ var Zotero_Browser = new function() { * @return void */ function scrapeThisPage(libraryID, collectionID) { + if (Zotero.locked) { + Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError")); + // TODO: localize + var desc = "A Zotero operation is currently in progress. Please wait until it finishes and try again."; + Zotero_Browser.progress.addDescription(desc); + Zotero_Browser.progress.show(); + Zotero_Browser.progress.startCloseTimer(8000); + return; + return; + } + if (!Zotero.stateCheck()) { Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError")); var desc = Zotero.getString("ingester.scrapeError.transactionInProgress.previousError") diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index 7fce01c010..402d571b89 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -80,10 +80,9 @@ Zotero_File_Exporter.prototype.save = function() { translation.setHandler("done", this._exportDone); Zotero.UnresponsiveScriptIndicator.disable(); Zotero_File_Interface.Progress.show( - Zotero.getString("fileInterface.itemsExported"), - function() { - translation.translate(); - }); + Zotero.getString("fileInterface.itemsExported") + ); + translation.translate() } return false; } @@ -269,13 +268,10 @@ var Zotero_File_Interface = new function() { // show progress indicator Zotero_File_Interface.Progress.show( - Zotero.getString("fileInterface.itemsImported"), - function() { - Zotero.DB.beginTransaction(); - - // translate - translation.translate(); - }); + Zotero.getString("fileInterface.itemsImported") + ); + Zotero.DB.beginTransaction(); + translation.translate(); } else { var prompt = Components.classes["@mozilla.org/network/default-prompt;1"] .getService(Components.interfaces.nsIPrompt); @@ -569,50 +565,14 @@ var Zotero_File_Interface = new function() { // Handles the display of a progress indicator Zotero_File_Interface.Progress = new function() { - var _windowLoaded = false; - var _windowLoading = false; - var _progressWindow; - // keep track of all of these things in case they're called before we're - // done loading the progress window - var _loadHeadline, _loadNumber, _outOf, _callback; - this.show = show; this.close = close; - function show(headline, callback) { - if(_windowLoading || _windowLoaded) { // already loading or loaded - _progressWindow.focus(); - return false; - } - _windowLoading = true; - - _loadHeadline = headline; - _loadNumber = 0; - _outOf = 0; - _callback = callback; - - _progressWindow = window.openDialog("chrome://zotero/content/fileProgress.xul", "", "chrome,resizable=no,close=no,dependent,dialog,centerscreen"); - _progressWindow.addEventListener("pageshow", _onWindowLoaded, false); - - return true; + function show(headline) { + Zotero.showZoteroPaneProgressBar(headline) } function close() { - _windowLoaded = false; - try { - _progressWindow.close(); - } catch(ex) {} - } - - function _onWindowLoaded() { - _windowLoading = false; - _windowLoaded = true; - - // do things we delayed because the winodw was loading - _progressWindow.document.getElementById("progress-label").value = _loadHeadline; - - if(_callback) { - window.setTimeout(_callback, 1500); - } + Zotero.hideZoteroPaneOverlay(); } } \ No newline at end of file diff --git a/chrome/content/zotero/fileProgress.xul b/chrome/content/zotero/fileProgress.xul deleted file mode 100644 index ed2e0160a8..0000000000 --- a/chrome/content/zotero/fileProgress.xul +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index ee891ee31d..6b7caea20e 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -27,6 +27,7 @@ var ZoteroPane = new function() { this.collectionsView = false; this.itemsView = false; + this.__defineGetter__('loaded', function () _loaded); //Privileged methods this.onLoad = onLoad; @@ -85,6 +86,7 @@ var ZoteroPane = new function() const COLLECTIONS_HEIGHT = 32; // minimum height of the collections pane and toolbar var self = this; + var _loaded = false; var titlebarcolorState, toolbarCollapseState, titleState; // Also needs to be changed in collectionTreeView.js @@ -99,6 +101,11 @@ var ZoteroPane = new function() return; } + if (Zotero.locked) { + return; + } + _loaded = true; + if(Zotero.Prefs.get("zoteroPaneOnTop")) { var oldPane = document.getElementById('zotero-pane'); @@ -245,7 +252,7 @@ var ZoteroPane = new function() */ function onUnload() { - if (!Zotero || !Zotero.initialized) { + if (!Zotero || !Zotero.initialized || !_loaded) { return; } @@ -262,7 +269,19 @@ var ZoteroPane = new function() */ function toggleDisplay() { - var zoteroPane = document.getElementById('zotero-pane'); + if (!ZoteroPane.loaded) { + if (Zotero.locked) { + var pr = Components.classes["@mozilla.org/network/default-prompt;1"] + .getService(Components.interfaces.nsIPrompt); + // TODO: localize + var msg = "Another Zotero operation is currently in progress.\n\nPlease wait until it has finished."; + pr.alert("", msg); + return; + } + ZoteroPane.onLoad(); + } + + var zoteroPane = document.getElementById('zotero-pane-stack'); var zoteroSplitter = document.getElementById('zotero-splitter') if (zoteroPane.getAttribute('hidden') == 'true') { @@ -383,7 +402,7 @@ var ZoteroPane = new function() function isShowing() { - var zoteroPane = document.getElementById('zotero-pane'); + var zoteroPane = document.getElementById('zotero-pane-stack'); return zoteroPane.getAttribute('hidden') != 'true' && zoteroPane.getAttribute('collapsed') != 'true'; } @@ -391,21 +410,21 @@ var ZoteroPane = new function() function fullScreen(set) { - var zPane = document.getElementById('zotero-pane'); + var zoteroPane = document.getElementById('zotero-pane-stack'); if (set != undefined) { var makeFullScreen = !!set; } else { - var makeFullScreen = zPane.getAttribute('fullscreenmode') != 'true'; + var makeFullScreen = zoteroPane.getAttribute('fullscreenmode') != 'true'; } // Turn Z-pane flex on to stretch to window in full-screen, but off otherwise so persist works - zPane.setAttribute('flex', makeFullScreen ? "1" : "0"); + zoteroPane.setAttribute('flex', makeFullScreen ? "1" : "0"); document.getElementById('content').setAttribute('collapsed', makeFullScreen); document.getElementById('zotero-splitter').setAttribute('hidden', makeFullScreen); - zPane.setAttribute('fullscreenmode', makeFullScreen); + zoteroPane.setAttribute('fullscreenmode', makeFullScreen); _setFullWindowMode(makeFullScreen); } @@ -468,6 +487,11 @@ var ZoteroPane = new function() Zotero.debug(e); } + if (Zotero.locked) { + event.preventDefault(); + return; + } + if (from == 'zotero-pane') { // Highlight collections containing selected items // @@ -497,7 +521,7 @@ var ZoteroPane = new function() } // Ignore keystrokes if Zotero pane is closed - var zoteroPane = document.getElementById('zotero-pane'); + var zoteroPane = document.getElementById('zotero-pane-stack'); if (zoteroPane.getAttribute('hidden') == 'true' || zoteroPane.getAttribute('collapsed') == 'true') { return; @@ -783,7 +807,6 @@ var ZoteroPane = new function() function toggleTagSelector(){ - var zoteroPane = document.getElementById('zotero-pane'); var tagSelector = document.getElementById('zotero-tag-selector'); var showing = tagSelector.getAttribute('collapsed') == 'true'; @@ -805,7 +828,7 @@ var ZoteroPane = new function() function updateTagSelectorSize() { //Zotero.debug('Updating tag selector size'); - var zoteroPane = document.getElementById('zotero-pane'); + var zoteroPane = document.getElementById('zotero-pane-stack'); var splitter = document.getElementById('zotero-tags-splitter'); var tagSelector = document.getElementById('zotero-tag-selector'); @@ -966,7 +989,6 @@ var ZoteroPane = new function() } - this.showDuplicates = function () { if (this.collectionsView.selection.count == 1 && this.collectionsView.selection.currentIndex != -1) { var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex); @@ -2225,8 +2247,11 @@ var ZoteroPane = new function() } } - var separator = document.getElementById("zotero-context-separator"); - separator.hidden = !showing; + // If Zotero is locked, disable menu items + var menu = document.getElementById('zotero-content-area-context-menu'); + for each(var menuitem in menu.firstChild.childNodes) { + menuitem.disabled = Zotero.locked; + } } diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul index 2bbbdd88a8..7a7ce39ea0 100644 --- a/chrome/content/zotero/overlay.xul +++ b/chrome/content/zotero/overlay.xul @@ -53,20 +53,23 @@ - @@ -74,7 +77,15 @@ + + + + + + +