- closes #130, add progress bar for import/export
- eliminates "unresponsive script" message on import/export i tried to make a progress bar that actually provides useful information, but for some reason, XUL interface updates are done asynchronously, and thus don't actually happen as long as the import/export operation continues. the code is there, but disabled, if there's some solution to this issue, but i searched and couldn't find one.
This commit is contained in:
parent
6ad7acf4d8
commit
30af2c89df
5 changed files with 189 additions and 15 deletions
|
@ -1,4 +1,6 @@
|
|||
Scholar_File_Interface = new function() {
|
||||
var _unresponsiveScriptPreference;
|
||||
|
||||
this.exportFile = exportFile;
|
||||
this.importFile = importFile;
|
||||
this.bibliographyFromProject = bibliographyFromProject;
|
||||
|
@ -21,11 +23,42 @@ Scholar_File_Interface = new function() {
|
|||
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
||||
translation.setLocation(fp.file);
|
||||
translation.setTranslator(translators[fp.filterIndex]);
|
||||
//translation.setHandler("done", _exportDone);
|
||||
translation.translate();
|
||||
//translation.setHandler("itemCount", _exportItemCount);
|
||||
//translation.setHandler("itemDone", _exportItemDone);
|
||||
translation.setHandler("done", _exportDone);
|
||||
_disableUnresponsive();
|
||||
Scholar_File_Interface.Progress.show(
|
||||
Scholar.getString("fileInterface.itemsExported"),
|
||||
function() {
|
||||
translation.translate();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* set progress indicator length
|
||||
*/
|
||||
function _exportItemCount(obj, number) {
|
||||
Scholar.debug("count called with "+number);
|
||||
Scholar_File_Interface.Progress.setNumber(number);
|
||||
}
|
||||
|
||||
/*
|
||||
* Increment progress for each item exported
|
||||
*/
|
||||
function _exportItemDone(obj, item) {
|
||||
Scholar_File_Interface.Progress.increment();
|
||||
}
|
||||
|
||||
/*
|
||||
* closes items exported indicator
|
||||
*/
|
||||
function _exportDone(obj) {
|
||||
Scholar_File_Interface.Progress.close();
|
||||
_restoreUnresponsive();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Creates Scholar.Translate instance and shows file picker for file import
|
||||
*/
|
||||
|
@ -49,12 +82,56 @@ Scholar_File_Interface = new function() {
|
|||
if(translators.length) {
|
||||
// TODO: display a list of available translators
|
||||
translation.setTranslator(translators[0]);
|
||||
// show progress indicator
|
||||
translation.setHandler("itemDone", _importItemDone);
|
||||
translation.translate();
|
||||
translation.setHandler("done", _importDone);
|
||||
_disableUnresponsive();
|
||||
Scholar_File_Interface.Progress.show(
|
||||
Scholar.getString("fileInterface.itemsImported"),
|
||||
function() {
|
||||
translation.translate();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves items after they've been imported. We could have a nice little
|
||||
* "items imported" indicator, too.
|
||||
*/
|
||||
function _importItemDone(obj, item) {
|
||||
//Scholar_File_Interface.Progress.increment();
|
||||
item.save();
|
||||
}
|
||||
|
||||
/*
|
||||
* closes items imported indicator
|
||||
*/
|
||||
function _importDone(obj) {
|
||||
Scholar_File_Interface.Progress.close();
|
||||
_restoreUnresponsive();
|
||||
}
|
||||
|
||||
/*
|
||||
* disables the "unresponsive script" warning; necessary for import and
|
||||
* export, which can take quite a while to execute
|
||||
*/
|
||||
function _disableUnresponsive() {
|
||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
|
||||
getService(Components.interfaces.nsIPrefBranch);
|
||||
_unresponsiveScriptPreference = prefService.getIntPref("dom.max_script_run_time");
|
||||
prefService.setIntPref("dom.max_script_run_time", 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* restores the "unresponsive script" warning
|
||||
*/
|
||||
function _restoreUnresponsive() {
|
||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
|
||||
getService(Components.interfaces.nsIPrefBranch);
|
||||
prefService.setIntPref("dom.max_script_run_time", _unresponsiveScriptPreference);
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a bibliography
|
||||
*/
|
||||
|
@ -65,14 +142,6 @@ Scholar_File_Interface = new function() {
|
|||
_doBibliographyOptions(Scholar.getItems(collection.getID()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Saves items after they've been imported. We could have a nice little
|
||||
* "items imported" indicator, too.
|
||||
*/
|
||||
function _importItemDone(obj, item) {
|
||||
item.save();
|
||||
}
|
||||
|
||||
/*
|
||||
* Shows bibliography options and creates a bibliography
|
||||
*/
|
||||
|
@ -161,4 +230,79 @@ Scholar_File_Interface = new function() {
|
|||
clipboardService.setData(transferable, null, Components.interfaces.nsIClipboard.kGlobalClipboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handles the display of a progress indicator
|
||||
Scholar_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.setNumber = setNumber;
|
||||
//this.increment = increment;
|
||||
this.close = close;
|
||||
|
||||
function show(headline, callback) {
|
||||
if(_windowLoading || _windowLoaded) { // already loading or loaded
|
||||
return false;
|
||||
}
|
||||
_windowLoading = true;
|
||||
|
||||
_loadHeadline = headline;
|
||||
_loadNumber = 0;
|
||||
_outOf = 0;
|
||||
_callback = callback;
|
||||
|
||||
_progressWindow = window.openDialog("chrome://scholar/chrome/fileProgress.xul", "", "chrome,resizable=no,close=no,dependent,dialog,centerscreen");
|
||||
_progressWindow.addEventListener("pageshow", _onWindowLoaded, false);
|
||||
}
|
||||
|
||||
/*function setNumber(number) {
|
||||
_outOf = number;
|
||||
if(_windowLoaded) {
|
||||
var progressMeter = _progressWindow.document.getElementById("progress-indicator");
|
||||
progressMeter.mode = "normal";
|
||||
progressMeter.value = "0%";
|
||||
}
|
||||
}
|
||||
|
||||
function increment() {
|
||||
_loadNumber++;
|
||||
if(_windowLoaded) {
|
||||
_progressWindow.document.getElementById("progress-items").value = _loadNumber;
|
||||
if(_outOf) {
|
||||
_progressWindow.document.getElementById("progress-indicator").value = ((_loadNumber/_outOf)*100).toString()+"%";
|
||||
}
|
||||
_progressWindow.getSelection();
|
||||
}
|
||||
}*/
|
||||
|
||||
function close() {
|
||||
_windowLoaded = false;
|
||||
try {
|
||||
_progressWindow.close();
|
||||
} catch(ex) {}
|
||||
}
|
||||
|
||||
function _onWindowLoaded() {
|
||||
_windowLoading = false;
|
||||
_windowLoaded = true;
|
||||
|
||||
// do things we delayed because the winodw was loading
|
||||
/*if(_outOf) {
|
||||
var progressMeter = _progressWindow.document.getElementById("progress-indicator");
|
||||
progressMeter.mode = "normal";
|
||||
progressMeter.value = ((_loadNumber/_outOf)*100).toString()+"%";
|
||||
}
|
||||
_progressWindow.document.getElementById("progress-items").value = _loadNumber;*/
|
||||
_progressWindow.document.getElementById("progress-label").value = _loadHeadline;
|
||||
|
||||
if(_callback) {
|
||||
window.setTimeout(_callback, 1500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
15
chrome/chromeFiles/content/scholar/fileProgress.xul
Normal file
15
chrome/chromeFiles/content/scholar/fileProgress.xul
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" ?>
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<!DOCTYPE window SYSTEM "chrome://scholar/locale/scholar.dtd">
|
||||
|
||||
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&progress.title;" width="300" height="30"
|
||||
id="scholar-progress">
|
||||
<vbox style="padding:10px">
|
||||
<hbox align="stretch">
|
||||
<label id="progress-label" flex="1" />
|
||||
<label id="progress-items" style="text-align:right;width:20px" />
|
||||
</hbox>
|
||||
<progressmeter id="progress-indicator" mode="undetermined" />
|
||||
</vbox>
|
||||
</window>
|
|
@ -137,6 +137,12 @@ Scholar.Translate.prototype.setTranslator = function(translator) {
|
|||
* returns: a numerically indexed array of ids, as extracted from the passed
|
||||
* string
|
||||
*
|
||||
* itemCount
|
||||
* valid: export
|
||||
* called: when the export
|
||||
* passed: the number of items to be processed
|
||||
* returns: N/A
|
||||
*
|
||||
* itemDone
|
||||
* valid: web
|
||||
* called: when an item has been processed; may be called asynchronously
|
||||
|
@ -146,7 +152,7 @@ Scholar.Translate.prototype.setTranslator = function(translator) {
|
|||
* done
|
||||
* valid: all
|
||||
* called: when all processing is finished
|
||||
* passed: returns true if successful, false if an error occurred
|
||||
* passed: true if successful, false if an error occurred
|
||||
* returns: N/A
|
||||
*/
|
||||
Scholar.Translate.prototype.setHandler = function(type, handler) {
|
||||
|
@ -708,6 +714,8 @@ Scholar.Translate.prototype._export = function() {
|
|||
|
||||
// get items
|
||||
this._itemsLeft = Scholar.getItems();
|
||||
// run handler for items available
|
||||
this._runHandler("itemCount", this._itemsLeft.length);
|
||||
|
||||
// get collections, if requested
|
||||
if(this._configOptions.getCollections) {
|
||||
|
@ -760,8 +768,10 @@ Scholar.Translate.prototype._exportConfigureIO = function() {
|
|||
Scholar.Translate.prototype._exportGetItem = function() {
|
||||
if(this._itemsLeft.length != 0) {
|
||||
var returnItem = this._itemsLeft.shift();
|
||||
this._runHandler("itemDone", returnItem);
|
||||
return returnItem.toArray();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,4 +49,6 @@
|
|||
<!ENTITY bibliography.output.label "Output Format:">
|
||||
<!ENTITY bibliography.saveAsHTML.label "Save as HTML">
|
||||
<!ENTITY bibliography.copyToClipboard.label "Copy to Clipboard">
|
||||
<!ENTITY bibliography.print.label "Print">
|
||||
<!ENTITY bibliography.print.label "Print">
|
||||
|
||||
<!ENTITY progress.title "Progress">
|
|
@ -86,4 +86,7 @@ ingester.scrapeErrorDescription = An error occurred while saving this item. Plea
|
|||
|
||||
db.dbCorruptedNoBackup = The Scholar database appears to have become corrupted, and no automatic backup is available.\n\nA new database file has been created. The damaged file was saved in your Scholar directory.
|
||||
db.dbRestored = The Scholar database appears to have become corrupted.\n\nYour data was restored from the last automatic backup made on %1 at %2. The damaged file was saved in your Scholar directory.
|
||||
db.dbRestoreFailed = The Scholar database appears to have become corrupted, and an attempt to restore from the last automatic backup failed.\n\nA new database file has been created. The damaged file was saved in your Scholar directory.
|
||||
db.dbRestoreFailed = The Scholar database appears to have become corrupted, and an attempt to restore from the last automatic backup failed.\n\nA new database file has been created. The damaged file was saved in your Scholar directory.
|
||||
|
||||
fileInterface.itemsImported = Importing items...
|
||||
fileInterface.itemsExported = Exporting items...
|
Loading…
Add table
Reference in a new issue