From 35aaa013ed1d8f1bc22bab1d2e916baef79443a3 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 2 Apr 2024 05:49:54 -0400 Subject: [PATCH] Move ZoteroPane.syncAlert() to Sync.Runner.alert() And use for sync setup in prefs so that it includes the dialog header from the sync error messages --- .../zotero/preferences/preferences_sync.jsx | 6 +-- .../content/zotero/xpcom/sync/syncRunner.js | 47 ++++++++++++++++++ chrome/content/zotero/zoteroPane.js | 49 +------------------ 3 files changed, 49 insertions(+), 53 deletions(-) diff --git a/chrome/content/zotero/preferences/preferences_sync.jsx b/chrome/content/zotero/preferences/preferences_sync.jsx index 2a63e453b1..cc643d53d3 100644 --- a/chrome/content/zotero/preferences/preferences_sync.jsx +++ b/chrome/content/zotero/preferences/preferences_sync.jsx @@ -145,11 +145,7 @@ Zotero_Preferences.Sync = { } catch (e) { setTimeout(function () { - Zotero.alert( - window, - Zotero.getString('general.error'), - e.message - ); + Zotero.Sync.Runner.alert(e); }); throw e; } diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 8425a03432..f5b3e0cebd 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -1593,6 +1593,53 @@ Zotero.Sync.Runner_Module = function (options = {}) { } + this.alert = function (e) { + e = Zotero.Sync.Runner.parseError(e); + var ps = Services.prompt; + var buttonText = e.dialogButtonText; + var buttonCallback = e.dialogButtonCallback; + + if (e.errorType == 'warning' || e.errorType == 'error') { + let title = Zotero.getString('general.' + e.errorType); + // TODO: Display header in bold + let msg = (e.dialogHeader ? e.dialogHeader + '\n\n' : '') + e.message; + + if (e.errorType == 'warning' || buttonText === null) { + ps.alert(null, title, e.message); + return; + } + + if (!buttonText) { + buttonText = Zotero.getString('errorReport.reportError'); + buttonCallback = function () { + ZoteroPane.reportErrors(); + }; + } + + let buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_OK + + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_IS_STRING; + let index = ps.confirmEx( + null, + title, + msg, + buttonFlags, + "", + buttonText, + "", null, {} + ); + + if (index == 1) { + setTimeout(buttonCallback, 1); + } + } + // Upgrade message + else if (e.errorType == 'upgrade') { + ps.alert(null, "", e.message); + return; + } + }; + + /** * Register labels in sync icon tooltip to receive updates * diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index bd5cb6cac4..36513fa796 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -4798,7 +4798,7 @@ var ZoteroPane = new function() catch (e) { // TODO: show error somewhere else Zotero.debug(e, 1); - ZoteroPane_Local.syncAlert(e); + Zotero.Sync.Runner.alert(e); return; } @@ -5142,53 +5142,6 @@ var ZoteroPane = new function() }; - this.syncAlert = function (e) { - e = Zotero.Sync.Runner.parseError(e); - var ps = Services.prompt; - var buttonText = e.dialogButtonText; - var buttonCallback = e.dialogButtonCallback; - - if (e.errorType == 'warning' || e.errorType == 'error') { - let title = Zotero.getString('general.' + e.errorType); - // TODO: Display header in bold - let msg = (e.dialogHeader ? e.dialogHeader + '\n\n' : '') + e.message; - - if (e.errorType == 'warning' || buttonText === null) { - ps.alert(null, title, e.message); - return; - } - - if (!buttonText) { - buttonText = Zotero.getString('errorReport.reportError'); - buttonCallback = function () { - ZoteroPane.reportErrors(); - }; - } - - let buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_OK - + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_IS_STRING; - let index = ps.confirmEx( - null, - title, - msg, - buttonFlags, - "", - buttonText, - "", null, {} - ); - - if (index == 1) { - setTimeout(buttonCallback, 1); - } - } - // Upgrade message - else if (e.errorType == 'upgrade') { - ps.alert(null, "", e.message); - return; - } - }; - - this.recognizeSelected = function() { Zotero.RecognizeDocument.recognizeItems(ZoteroPane.getSelectedItems()); Zotero.ProgressQueues.get('recognize').getDialog().open();