Don't show progress window for PDF recognition if only one file

This commit is contained in:
Dan Stillman 2018-10-08 02:46:13 -04:00
parent 7ecaab73a0
commit be8db4fc50
2 changed files with 22 additions and 5 deletions

View file

@ -69,6 +69,10 @@ Zotero.ProgressQueueDialog = function (progressQueue) {
_showMinimize = show; _showMinimize = show;
}; };
this.isOpen = function () {
return !!_progressWindow;
};
this.close = function () { this.close = function () {
// In case close() is called before open() // In case close() is called before open()
if (!_progressWindow) { if (!_progressWindow) {

View file

@ -105,7 +105,7 @@ Zotero.RecognizePDF = new function () {
* Adds items to the queue and triggers processing * Adds items to the queue and triggers processing
* @param {Zotero.Item[]} items * @param {Zotero.Item[]} items
*/ */
this.recognizeItems = function (items) { this.recognizeItems = async function (items) {
for (let item of items) { for (let item of items) {
if( if(
_processingItemID === item.id || _processingItemID === item.id ||
@ -117,7 +117,7 @@ Zotero.RecognizePDF = new function () {
_queue.unshift(item.id); _queue.unshift(item.id);
_progressQueue.addRow(item); _progressQueue.addRow(item);
} }
_processQueue(); await _processQueue();
}; };
@ -133,7 +133,7 @@ Zotero.RecognizePDF = new function () {
}; };
this.autoRecognizeItems = function (items) { this.autoRecognizeItems = async function (items) {
if (!Zotero.Prefs.get('autoRecognizeFiles')) return; if (!Zotero.Prefs.get('autoRecognizeFiles')) return;
var pdfs = items.filter((item) => { var pdfs = items.filter((item) => {
@ -144,8 +144,21 @@ Zotero.RecognizePDF = new function () {
if (!pdfs.length) { if (!pdfs.length) {
return; return;
} }
this.recognizeItems(pdfs); var queue = Zotero.ProgressQueues.get('recognize');
Zotero.ProgressQueues.get('recognize').getDialog().open(); var dialog = queue.getDialog();
var numInQueue = queue.getTotal();
var promise = this.recognizeItems(pdfs);
// If the queue wasn't empty or more than one file is being saved, show the dialog
if (numInQueue > 0 || pdfs.length > 1) {
dialog.open();
return promise;
}
await promise;
// If dialog wasn't opened automatically and wasn't opened manually, clear it after
// recognizing files
if (!dialog.isOpen()) {
queue.cancel();
}
}; };