From 237db5ed586f705d508c96d978fcb6e97d8a3b27 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 21 Sep 2006 07:54:18 +0000 Subject: [PATCH] Copied out scraping progress window for general use -- I'll use this for fulltext indexing notification, and ideally the scraper will use this instead now (Simon, let me know if there's any problem with that) Example usage: var windowWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]. getService(Components.interfaces.nsIWindowWatcher); var progress = new Scholar.ProgressWindow(windowWatcher.activeWindow); progress.changeHeadline('Indexing item...'); progress.addLines(['All About Foo'], ['chrome://scholar/skin/treeitem-book.png']); progress.addDescription('Bar bar bar bar bar'); progress.show(); progress.fade(); --- .../content/scholar/progressWindow.xul | 17 +++ .../content/scholar/xpcom/progressWindow.js | 135 ++++++++++++++++++ .../skin/default/scholar/scholar.css | 6 +- components/chnmIZoteroService.js | 4 + 4 files changed, 159 insertions(+), 3 deletions(-) create mode 100755 chrome/chromeFiles/content/scholar/progressWindow.xul create mode 100644 chrome/chromeFiles/content/scholar/xpcom/progressWindow.js diff --git a/chrome/chromeFiles/content/scholar/progressWindow.xul b/chrome/chromeFiles/content/scholar/progressWindow.xul new file mode 100755 index 0000000000..a96bfa69c2 --- /dev/null +++ b/chrome/chromeFiles/content/scholar/progressWindow.xul @@ -0,0 +1,17 @@ + + + + + + + + + + + + + diff --git a/chrome/chromeFiles/content/scholar/xpcom/progressWindow.js b/chrome/chromeFiles/content/scholar/xpcom/progressWindow.js new file mode 100644 index 0000000000..2eaadfff44 --- /dev/null +++ b/chrome/chromeFiles/content/scholar/xpcom/progressWindow.js @@ -0,0 +1,135 @@ +/* + * Handles the display of a div showing progress in scraping, indexing, etc. + * + * Pass the active window into the constructor + */ +Scholar.ProgressWindow = function(_window){ + var _progressWindow = null; + var _windowLoaded = false; + var _windowLoading = false; + // keep track of all of these things in case they're called before we're + // done loading the progress window + var _loadDescription = null; + var _loadLines = new Array(); + var _loadIcons = new Array(); + var _loadHeadline = ''; + + this.show = show; + this.changeHeadline = changeHeadline; + this.addLines = addLines; + this.addDescription = addDescription; + this.fade = fade; + this.kill = kill; + + function show() { + if(_windowLoading || _windowLoaded) { // already loading or loaded + return false; + } + _progressWindow = _window.openDialog("chrome://scholar/chrome/progressWindow.xul", + "", "chrome,dialog=no,titlebar=no,popup=yes"); + _progressWindow.addEventListener("load", _onWindowLoaded, false); + _windowLoading = true; + + return true; + } + + function changeHeadline(headline) { + if(_windowLoaded) { + _progressWindow.document.getElementById("zotero-progress-text-headline").value = headline; + } else { + _loadHeadline = headline; + } + } + + function addLines(label, icon) { + if(_windowLoaded) { + for(i in label) { + var newLabel = _progressWindow.document.createElement("label"); + newLabel.setAttribute("class", "zotero-progress-item-label"); + newLabel.setAttribute("crop", "end"); + newLabel.setAttribute("value", label[i]); + + var newImage = _progressWindow.document.createElement("image"); + newImage.setAttribute("class", "zotero-progress-item-icon"); + newImage.setAttribute("src", icon[i]); + + var newHB = _progressWindow.document.createElement("hbox"); + newHB.setAttribute("class", "zotero-progress-item-hbox"); + newHB.setAttribute("valign", "center"); + newHB.appendChild(newImage); + newHB.appendChild(newLabel); + + _progressWindow.document.getElementById("zotero-progress-text-box").appendChild(newHB); + } + + _move(); + } else { + _loadLines = _loadLines.concat(label); + _loadIcons = _loadIcons.concat(icon); + } + } + + function addDescription(text) { + if(_windowLoaded) { + var newHB = _progressWindow.document.createElement("hbox"); + newHB.setAttribute("class", "zotero-progress-item-hbox"); + var newDescription = _progressWindow.document.createElement("description"); + newDescription.setAttribute("class", "zotero-progress-description"); + var newText = _progressWindow.document.createTextNode(text); + + newDescription.appendChild(newText); + newHB.appendChild(newDescription); + _progressWindow.document.getElementById("zotero-progress-text-box").appendChild(newHB); + + _move(); + } else { + _loadDescription = text; + } + } + + function fade() { + if(_windowLoaded || _windowLoading) { + _window.setTimeout(_timeout, 2500); + } + } + + function kill() { + _windowLoaded = false; + _windowLoading = false; + try { + _progressWindow.close(); + } catch(ex) {} + } + + function _onWindowLoaded() { + _windowLoading = false; + _windowLoaded = true; + + _move(); + // do things we delayed because the window was loading + changeHeadline(_loadHeadline); + addLines(_loadLines, _loadIcons); + if(_loadDescription) { + addDescription(_loadDescription); + } + + // reset parameters + _loadDescription = null; + _loadLines = new Array(); + _loadIcons = new Array(); + _loadHeadline = ''; + } + + function _move() { + _progressWindow.sizeToContent(); + _progressWindow.moveTo( + _window.screenX + _window.innerWidth - _progressWindow.outerWidth - 30, + _window.screenY + _window.innerHeight - _progressWindow.outerHeight - 10 + ); + } + + function _timeout() { + kill(); // could check to see if we're really supposed to fade yet + // (in case multiple scrapers are operating at once) + } +} diff --git a/chrome/chromeFiles/skin/default/scholar/scholar.css b/chrome/chromeFiles/skin/default/scholar/scholar.css index b5564da00b..bdddad8c93 100644 --- a/chrome/chromeFiles/skin/default/scholar/scholar.css +++ b/chrome/chromeFiles/skin/default/scholar/scholar.css @@ -147,7 +147,7 @@ zoterosearchtextbox .toolbarbutton-menu-dropmarker background: #666666; } -#scholar-progress-box +#zotero-progress-box, #scholar-progress-box { border: 2px solid #7a0000; margin: 0; @@ -156,13 +156,13 @@ zoterosearchtextbox .toolbarbutton-menu-dropmarker padding-bottom: 3px; } -.scholar-progress-item-icon +.zotero-progress-item-icon, .scholar-progress-item-icon { width: 16px; height: 16px; } -.scholar-progress-item-hbox +.zotero-progress-item-hbox, .scholar-progress-item-hbox { padding-left: 5px; margin-top: 3px; diff --git a/components/chnmIZoteroService.js b/components/chnmIZoteroService.js index 38cc684ae5..e6a58ecf98 100644 --- a/components/chnmIZoteroService.js +++ b/components/chnmIZoteroService.js @@ -82,6 +82,10 @@ Cc["@mozilla.org/moz/jssubscript-loader;1"] .getService(Ci.mozIJSSubScriptLoader) .loadSubScript("chrome://scholar/content/xpcom/collectionTreeView.js"); +Cc["@mozilla.org/moz/jssubscript-loader;1"] + .getService(Ci.mozIJSSubScriptLoader) + .loadSubScript("chrome://scholar/content/xpcom/progressWindow.js"); + Cc["@mozilla.org/moz/jssubscript-loader;1"] .getService(Ci.mozIJSSubScriptLoader) .loadSubScript("chrome://global/content/nsTransferable.js");