From ce5fd11a7b582b0c560dbbe4c0f4f9cdf583886e Mon Sep 17 00:00:00 2001 From: Fiyinfolu Eludire <17176053+faeludire@users.noreply.github.com> Date: Tue, 29 Dec 2020 19:46:52 +0000 Subject: [PATCH 1/9] [WIP] Fix for application dialogs opening in wrong displays --- src/main/java/org/jabref/gui/JabRefFrame.java | 2 +- src/main/java/org/jabref/gui/help/AboutAction.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 74ba19fd5eb..dd1e9360ad1 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -892,7 +892,7 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.OPEN_DEV_VERSION_LINK, new OpenBrowserAction("https://builds.jabref.org/master/")), factory.createMenuItem(StandardActions.OPEN_CHANGELOG, new OpenBrowserAction("https://github.com/JabRef/jabref/blob/master/CHANGELOG.md")) ), - factory.createMenuItem(StandardActions.ABOUT, new AboutAction()) + factory.createMenuItem(StandardActions.ABOUT, new AboutAction(mainStage)) ); // @formatter:on diff --git a/src/main/java/org/jabref/gui/help/AboutAction.java b/src/main/java/org/jabref/gui/help/AboutAction.java index ec0e82077a5..1a9d57a8ed9 100644 --- a/src/main/java/org/jabref/gui/help/AboutAction.java +++ b/src/main/java/org/jabref/gui/help/AboutAction.java @@ -1,11 +1,21 @@ package org.jabref.gui.help; +import javafx.stage.Stage; + import org.jabref.gui.actions.SimpleCommand; public class AboutAction extends SimpleCommand { + private final Stage primaryStage; + + public AboutAction(Stage primaryState) { + this.primaryStage = primaryState; + } + @Override public void execute() { - new AboutDialogView().show(); + AboutDialogView aboutDialogView = new AboutDialogView(); + aboutDialogView.initOwner(primaryStage); + aboutDialogView.show(); } } From 7aacc88126308ad16cd61743a24938c1d5352770 Mon Sep 17 00:00:00 2001 From: Fiyinfolu Eludire <17176053+faeludire@users.noreply.github.com> Date: Wed, 30 Dec 2020 16:48:59 +0000 Subject: [PATCH 2/9] [WIP] Fix for application dialogs opening in wrong displays --- src/main/java/org/jabref/gui/DialogService.java | 3 +++ .../java/org/jabref/gui/JabRefDialogService.java | 7 +++++++ src/main/java/org/jabref/gui/JabRefFrame.java | 2 +- .../java/org/jabref/gui/help/AboutAction.java | 16 +++++----------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jabref/gui/DialogService.java b/src/main/java/org/jabref/gui/DialogService.java index 34fb8994247..addad97e913 100644 --- a/src/main/java/org/jabref/gui/DialogService.java +++ b/src/main/java/org/jabref/gui/DialogService.java @@ -15,6 +15,7 @@ import javafx.scene.control.DialogPane; import javafx.scene.control.TextInputDialog; +import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.DirectoryDialogConfiguration; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.l10n.Localization; @@ -272,4 +273,6 @@ Optional showCustomButtonDialogAndWait(Alert.AlertType type, String * @return the selected file or an empty {@link Optional} if no file has been selected */ Optional showFileOpenFromArchiveDialog(Path archivePath) throws IOException; + + void show(BaseDialog aboutDialogView); } diff --git a/src/main/java/org/jabref/gui/JabRefDialogService.java b/src/main/java/org/jabref/gui/JabRefDialogService.java index 53816e402e8..e48c86abe7b 100644 --- a/src/main/java/org/jabref/gui/JabRefDialogService.java +++ b/src/main/java/org/jabref/gui/JabRefDialogService.java @@ -36,6 +36,7 @@ import org.jabref.gui.icon.IconTheme; import org.jabref.gui.util.BackgroundTask; +import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.DirectoryDialogConfiguration; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.ZipFileChooser; @@ -385,4 +386,10 @@ public Optional showFileOpenFromArchiveDialog(Path archivePath) throws IOE throw new IOException("Could not instantiate ZIP-archive reader.", exc); } } + + @Override + public void show(BaseDialog aboutDialogView) { + aboutDialogView.initOwner(mainWindow); + aboutDialogView.show(); + } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index dd1e9360ad1..74ba19fd5eb 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -892,7 +892,7 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.OPEN_DEV_VERSION_LINK, new OpenBrowserAction("https://builds.jabref.org/master/")), factory.createMenuItem(StandardActions.OPEN_CHANGELOG, new OpenBrowserAction("https://github.com/JabRef/jabref/blob/master/CHANGELOG.md")) ), - factory.createMenuItem(StandardActions.ABOUT, new AboutAction(mainStage)) + factory.createMenuItem(StandardActions.ABOUT, new AboutAction()) ); // @formatter:on diff --git a/src/main/java/org/jabref/gui/help/AboutAction.java b/src/main/java/org/jabref/gui/help/AboutAction.java index 1a9d57a8ed9..9fae01d07ca 100644 --- a/src/main/java/org/jabref/gui/help/AboutAction.java +++ b/src/main/java/org/jabref/gui/help/AboutAction.java @@ -1,21 +1,15 @@ package org.jabref.gui.help; -import javafx.stage.Stage; - +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; -public class AboutAction extends SimpleCommand { - - private final Stage primaryStage; - - public AboutAction(Stage primaryState) { - this.primaryStage = primaryState; - } +import com.airhacks.afterburner.injection.Injector; +public class AboutAction extends SimpleCommand { @Override public void execute() { + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); AboutDialogView aboutDialogView = new AboutDialogView(); - aboutDialogView.initOwner(primaryStage); - aboutDialogView.show(); + dialogService.show(aboutDialogView); } } From e856ddaf00bccb562d42dc6b73e75ea351124831 Mon Sep 17 00:00:00 2001 From: Fiyinfolu Eludire <17176053+faeludire@users.noreply.github.com> Date: Wed, 30 Dec 2020 19:25:06 +0000 Subject: [PATCH 3/9] [WIP] Fix for application dialogs opening in wrong displays --- .../java/org/jabref/gui/DialogService.java | 4 ++-- .../org/jabref/gui/EntryTypeViewModel.java | 2 +- .../org/jabref/gui/JabRefDialogService.java | 23 +++++++++++++------ src/main/java/org/jabref/gui/JabRefFrame.java | 2 +- .../gui/auximport/NewSubLibraryAction.java | 7 ++++-- .../bibtexextractor/ExtractBibtexAction.java | 7 ++++-- .../CitationKeyPatternAction.java | 6 ++++- .../org/jabref/gui/cleanup/CleanupAction.java | 7 ++++-- .../jabref/gui/collab/DatabaseChangePane.java | 7 +++--- .../ManageContentSelectorAction.java | 6 ++++- .../jabref/gui/copyfiles/CopyFilesAction.java | 3 +-- .../CustomizeEntryAction.java | 7 ++++-- .../SetupGeneralFieldsAction.java | 6 ++++- .../ShowDocumentViewerAction.java | 6 ++++- .../duplicationFinder/DuplicateSearch.java | 3 ++- .../jabref/gui/edit/ManageKeywordsAction.java | 7 ++++-- .../jabref/gui/edit/MassSetFieldsAction.java | 3 +-- .../jabref/gui/edit/ReplaceStringAction.java | 7 ++++-- .../exporter/ManageCustomExportsAction.java | 6 ++++- .../FindUnlinkedFilesAction.java | 3 +-- .../CustomizeExternalFileTypesViewModel.java | 8 ++++--- .../EditExternalFileTypesAction.java | 7 ++++-- .../gui/fieldeditors/LinkedFileViewModel.java | 4 +--- .../java/org/jabref/gui/help/AboutAction.java | 3 +-- .../jabref/gui/help/ErrorConsoleAction.java | 7 ++++-- .../org/jabref/gui/help/VersionWorker.java | 2 +- .../org/jabref/gui/importer/ImportAction.java | 2 +- .../gui/importer/ImportEntriesViewModel.java | 6 +++-- .../importer/ManageCustomImportsAction.java | 6 ++++- .../jabref/gui/importer/NewEntryAction.java | 2 +- .../actions/CheckForNewEntryTypesAction.java | 8 ++++--- .../fetcher/WebSearchPaneViewModel.java | 2 +- .../gui/integrity/IntegrityCheckAction.java | 4 +--- .../gui/journals/ManageJournalsAction.java | 6 ++++- .../keyboard/CustomizeKeyBindingAction.java | 6 ++++- .../LibraryPropertiesAction.java | 7 ++++-- .../gui/linkedfile/AttachFileAction.java | 2 +- .../gui/mergeentries/FetchAndMergeEntry.java | 2 +- .../gui/mergeentries/MergeEntriesAction.java | 2 +- .../metadata/BibtexStringEditorAction.java | 6 ++++- .../org/jabref/gui/openoffice/OOBibBase.java | 2 +- .../gui/openoffice/OpenOfficePanel.java | 18 +++++---------- .../PreferencesDialogViewModel.java | 2 +- .../preferences/ShowPreferencesAction.java | 6 ++++- .../ManageProtectedTermsAction.java | 7 ++++-- .../ManageProtectedTermsViewModel.java | 3 +-- .../ConnectToSharedDatabaseCommand.java | 6 ++++- .../gui/shared/SharedDatabaseUIManager.java | 4 ++-- .../gui/texparser/ParseLatexAction.java | 7 ++++-- .../texparser/ParseLatexDialogViewModel.java | 3 ++- .../texparser/ParseLatexResultViewModel.java | 7 ++++-- 51 files changed, 181 insertions(+), 98 deletions(-) diff --git a/src/main/java/org/jabref/gui/DialogService.java b/src/main/java/org/jabref/gui/DialogService.java index addad97e913..8dc6b61248d 100644 --- a/src/main/java/org/jabref/gui/DialogService.java +++ b/src/main/java/org/jabref/gui/DialogService.java @@ -185,7 +185,7 @@ Optional showCustomButtonDialogAndWait(Alert.AlertType type, String * @param dialog dialog to show * @param type of result */ - Optional showCustomDialogAndWait(Dialog dialog); + Optional showCustomDialogAndWait(javafx.scene.control.Dialog dialog); /** * Constructs and shows a canceable {@link ProgressDialog}. Clicking cancel will cancel the underlying service and close the dialog @@ -274,5 +274,5 @@ Optional showCustomButtonDialogAndWait(Alert.AlertType type, String */ Optional showFileOpenFromArchiveDialog(Path archivePath) throws IOException; - void show(BaseDialog aboutDialogView); + void show(BaseDialog aboutDialogView); } diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 4ca06d9736a..d8221b328e6 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -155,7 +155,7 @@ public void runFetcherWorker() { Optional duplicate = new DuplicateCheck(Globals.entryTypesManager).containsDuplicate(libraryTab.getDatabase(), entry, libraryTab.getBibDatabaseContext().getMode()); if ((duplicate.isPresent())) { DuplicateResolverDialog dialog = new DuplicateResolverDialog(entry, duplicate.get(), DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, libraryTab.getBibDatabaseContext(), stateManager); - switch (dialog.showAndWait().orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) { + switch (dialogService.showCustomDialogAndWait(dialog).orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK)) { case KEEP_LEFT: libraryTab.getDatabase().removeEntry(duplicate.get()); libraryTab.getDatabase().insertEntry(entry); diff --git a/src/main/java/org/jabref/gui/JabRefDialogService.java b/src/main/java/org/jabref/gui/JabRefDialogService.java index e48c86abe7b..1a8af7cee36 100644 --- a/src/main/java/org/jabref/gui/JabRefDialogService.java +++ b/src/main/java/org/jabref/gui/JabRefDialogService.java @@ -70,11 +70,11 @@ public class JabRefDialogService implements DialogService { private static final Logger LOGGER = LoggerFactory.getLogger(JabRefDialogService.class); private static PreferencesService preferences; - private final Window mainWindow; + private static Window mainWindow; private final JFXSnackbar statusLine; public JabRefDialogService(Window mainWindow, Pane mainPane, PreferencesService preferences) { - this.mainWindow = mainWindow; + JabRefDialogService.mainWindow = mainWindow; this.statusLine = new JFXSnackbar(mainPane); JabRefDialogService.preferences = preferences; } @@ -85,6 +85,7 @@ private static FXDialog createDialog(AlertType type, String title, String conten alert.setHeaderText(null); alert.setContentText(content); alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE); + alert.initOwner(mainWindow); return alert; } @@ -118,6 +119,7 @@ protected Node createDetailsButton() { alert.setHeaderText(null); alert.setContentText(content); alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE); + alert.initOwner(mainWindow); return alert; } @@ -137,6 +139,7 @@ public Optional showChoiceDialogAndWait(String title, String content, Str choiceDialog.setHeaderText(title); choiceDialog.setTitle(title); choiceDialog.setContentText(content); + choiceDialog.initOwner(mainWindow); preferences.getTheme().installCss(choiceDialog.getDialogPane().getScene()); return choiceDialog.showAndWait(); } @@ -146,6 +149,7 @@ public Optional showInputDialogAndWait(String title, String content) { TextInputDialog inputDialog = new TextInputDialog(); inputDialog.setHeaderText(title); inputDialog.setContentText(content); + inputDialog.initOwner(mainWindow); preferences.getTheme().installCss(inputDialog.getDialogPane().getScene()); return inputDialog.showAndWait(); } @@ -155,6 +159,7 @@ public Optional showInputDialogWithDefaultAndWait(String title, String c TextInputDialog inputDialog = new TextInputDialog(defaultValue); inputDialog.setHeaderText(title); inputDialog.setContentText(content); + inputDialog.initOwner(mainWindow); preferences.getTheme().installCss(inputDialog.getDialogPane().getScene()); return inputDialog.showAndWait(); } @@ -182,6 +187,7 @@ public void showErrorDialogAndWait(String message, Throwable exception) { ExceptionDialog exceptionDialog = new ExceptionDialog(exception); exceptionDialog.getDialogPane().setMaxWidth(mainWindow.getWidth() / 2); exceptionDialog.setHeaderText(message); + exceptionDialog.initOwner(mainWindow); preferences.getTheme().installCss(exceptionDialog.getDialogPane().getScene()); exceptionDialog.showAndWait(); } @@ -191,6 +197,7 @@ public void showErrorDialogAndWait(String title, String content, Throwable excep ExceptionDialog exceptionDialog = new ExceptionDialog(exception); exceptionDialog.setHeaderText(title); exceptionDialog.setContentText(content); + exceptionDialog.initOwner(mainWindow); preferences.getTheme().installCss(exceptionDialog.getDialogPane().getScene()); exceptionDialog.showAndWait(); } @@ -260,12 +267,14 @@ public Optional showCustomDialogAndWait(String title, DialogPane con alert.getButtonTypes().setAll(buttonTypes); alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE); alert.setResizable(true); + alert.initOwner(mainWindow); preferences.getTheme().installCss(alert.getDialogPane().getScene()); return alert.showAndWait(); } @Override - public Optional showCustomDialogAndWait(Dialog dialog) { + public Optional showCustomDialogAndWait(javafx.scene.control.Dialog dialog) { + dialog.initOwner(mainWindow); return dialog.showAndWait(); } @@ -286,6 +295,7 @@ public void showProgressDialog(String title, String content, Task task) { progressDialog.close(); }); preferences.getTheme().installCss(progressDialog.getDialogPane().getScene()); + progressDialog.initOwner(mainWindow); progressDialog.show(); } @@ -308,6 +318,7 @@ public Optional showBackgroundProgressDialogAndWait(String title alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.CANCEL); alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE); alert.setResizable(true); + alert.initOwner(mainWindow); preferences.getTheme().installCss(alert.getDialogPane().getScene()); stateManager.getAnyTaskRunning().addListener((observable, oldValue, newValue) -> { @@ -317,9 +328,7 @@ public Optional showBackgroundProgressDialogAndWait(String title } }); - Dialog dialog = alert::showAndWait; - - return showCustomDialogAndWait(dialog); + return alert.showAndWait(); } @Override @@ -388,7 +397,7 @@ public Optional showFileOpenFromArchiveDialog(Path archivePath) throws IOE } @Override - public void show(BaseDialog aboutDialogView) { + public void show(BaseDialog aboutDialogView) { aboutDialogView.initOwner(mainWindow); aboutDialogView.show(); } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 74ba19fd5eb..27f5263ee17 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -1089,7 +1089,7 @@ private void addImportedEntries(final LibraryTab panel, final ParserResult parse cleanup.doPostCleanup(parserResult.getDatabase().getEntries()); ImportEntriesDialog dialog = new ImportEntriesDialog(panel.getBibDatabaseContext(), task); dialog.setTitle(Localization.lang("Import")); - dialog.showAndWait(); + dialogService.showCustomDialogAndWait(dialog); } public FileHistoryMenu getFileHistory() { diff --git a/src/main/java/org/jabref/gui/auximport/NewSubLibraryAction.java b/src/main/java/org/jabref/gui/auximport/NewSubLibraryAction.java index 85c766f10c3..36c426afb17 100644 --- a/src/main/java/org/jabref/gui/auximport/NewSubLibraryAction.java +++ b/src/main/java/org/jabref/gui/auximport/NewSubLibraryAction.java @@ -1,9 +1,12 @@ package org.jabref.gui.auximport; +import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + import static org.jabref.gui.actions.ActionHelper.needsDatabase; /** @@ -21,7 +24,7 @@ public NewSubLibraryAction(JabRefFrame jabRefFrame, StateManager stateManager) { @Override public void execute() { - FromAuxDialog dialog = new FromAuxDialog(jabRefFrame); - dialog.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new FromAuxDialog(jabRefFrame)); } } diff --git a/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexAction.java b/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexAction.java index 7610a6d7fa9..7f742093845 100644 --- a/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexAction.java +++ b/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexAction.java @@ -1,8 +1,11 @@ package org.jabref.gui.bibtexextractor; +import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + import static org.jabref.gui.actions.ActionHelper.needsDatabase; public class ExtractBibtexAction extends SimpleCommand { @@ -13,7 +16,7 @@ public ExtractBibtexAction(StateManager stateManager) { @Override public void execute() { - ExtractBibtexDialog dlg = new ExtractBibtexDialog(); - dlg.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new ExtractBibtexDialog()); } } diff --git a/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternAction.java b/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternAction.java index 983e9103e00..cb7676fbc08 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/CitationKeyPatternAction.java @@ -1,9 +1,12 @@ package org.jabref.gui.citationkeypattern; +import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + import static org.jabref.gui.actions.ActionHelper.needsDatabase; public class CitationKeyPatternAction extends SimpleCommand { @@ -18,6 +21,7 @@ public CitationKeyPatternAction(JabRefFrame frame, StateManager stateManager) { @Override public void execute() { - new CitationKeyPatternDialog(frame.getCurrentLibraryTab()).showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new CitationKeyPatternDialog(frame.getCurrentLibraryTab())); } } diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java index ad7dab14172..17fc4d39db0 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java @@ -56,10 +56,13 @@ public void execute() { isCanceled = false; modifiedEntriesCount = 0; - Optional chosenPreset = new CleanupDialog( + CleanupDialog cleanupDialog = new CleanupDialog( stateManager.getActiveDatabase().get(), preferences.getCleanupPreset(), - preferences.getFilePreferences()).showAndWait(); + preferences.getFilePreferences() + ); + + Optional chosenPreset = dialogService.showCustomDialogAndWait(cleanupDialog); chosenPreset.ifPresent(preset -> { if (preset.isRenamePDFActive() && preferences.getAutoLinkPreferences().shouldAskAutoNamingPdfs()) { diff --git a/src/main/java/org/jabref/gui/collab/DatabaseChangePane.java b/src/main/java/org/jabref/gui/collab/DatabaseChangePane.java index a879f81489a..569b07158d1 100644 --- a/src/main/java/org/jabref/gui/collab/DatabaseChangePane.java +++ b/src/main/java/org/jabref/gui/collab/DatabaseChangePane.java @@ -4,10 +4,12 @@ import javafx.scene.Node; +import org.jabref.gui.DialogService; import org.jabref.gui.icon.IconTheme; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; +import com.airhacks.afterburner.injection.Injector; import org.controlsfx.control.NotificationPane; import org.controlsfx.control.action.Action; @@ -33,9 +35,8 @@ private void onDatabaseChanged(List changes) { this.hide(); }), new Action(Localization.lang("Review changes"), event -> { - ChangeDisplayDialog changeDialog = new ChangeDisplayDialog(database, changes); - changeDialog.showAndWait(); - + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new ChangeDisplayDialog(database, changes)); this.hide(); })); this.show(); diff --git a/src/main/java/org/jabref/gui/contentselector/ManageContentSelectorAction.java b/src/main/java/org/jabref/gui/contentselector/ManageContentSelectorAction.java index e91c22b6e19..19a5b3cb254 100644 --- a/src/main/java/org/jabref/gui/contentselector/ManageContentSelectorAction.java +++ b/src/main/java/org/jabref/gui/contentselector/ManageContentSelectorAction.java @@ -1,10 +1,13 @@ package org.jabref.gui.contentselector; +import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + import static org.jabref.gui.actions.ActionHelper.needsDatabase; public class ManageContentSelectorAction extends SimpleCommand { @@ -19,7 +22,8 @@ public ManageContentSelectorAction(JabRefFrame jabRefFrame, StateManager stateMa @Override public void execute() { + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); LibraryTab libraryTab = jabRefFrame.getCurrentLibraryTab(); - new ContentSelectorDialogView(libraryTab).showAndWait(); + dialogService.showCustomDialogAndWait(new ContentSelectorDialogView(libraryTab)); } } diff --git a/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java b/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java index 07ee7470d6c..9574e128edb 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java @@ -35,8 +35,7 @@ private void showDialog(List data) { dialogService.showInformationDialogAndWait(Localization.lang("Copy linked files to folder..."), Localization.lang("No linked files found for export.")); return; } - CopyFilesDialogView dialog = new CopyFilesDialogView(new CopyFilesResultListDependency(data)); - dialog.showAndWait(); + dialogService.showCustomDialogAndWait(new CopyFilesDialogView(new CopyFilesResultListDependency(data))); } @Override diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryAction.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryAction.java index a320dcc0b45..f3a7f8be885 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryAction.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryAction.java @@ -1,10 +1,13 @@ package org.jabref.gui.customentrytypes; +import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntryTypesManager; +import com.airhacks.afterburner.injection.Injector; + import static org.jabref.gui.actions.ActionHelper.needsDatabase; public class CustomizeEntryAction extends SimpleCommand { @@ -21,7 +24,7 @@ public CustomizeEntryAction(StateManager stateManager, BibEntryTypesManager entr @Override public void execute() { BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); - CustomizeEntryTypeDialogView dialog = new CustomizeEntryTypeDialogView(database, entryTypesManager); - dialog.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new CustomizeEntryTypeDialogView(database, entryTypesManager)); } } diff --git a/src/main/java/org/jabref/gui/customizefields/SetupGeneralFieldsAction.java b/src/main/java/org/jabref/gui/customizefields/SetupGeneralFieldsAction.java index 35fe7eb61a7..e3c6cca6d40 100644 --- a/src/main/java/org/jabref/gui/customizefields/SetupGeneralFieldsAction.java +++ b/src/main/java/org/jabref/gui/customizefields/SetupGeneralFieldsAction.java @@ -1,11 +1,15 @@ package org.jabref.gui.customizefields; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + public class SetupGeneralFieldsAction extends SimpleCommand { @Override public void execute() { - new CustomizeGeneralFieldsDialogView().showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new CustomizeGeneralFieldsDialogView()); } } diff --git a/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java b/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java index a9a94d52b16..b059c2c5b7f 100644 --- a/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java +++ b/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java @@ -1,10 +1,13 @@ package org.jabref.gui.documentviewer; +import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; import org.jabref.preferences.PreferencesService; +import com.airhacks.afterburner.injection.Injector; + import static org.jabref.gui.actions.ActionHelper.needsEntriesSelected; public class ShowDocumentViewerAction extends SimpleCommand { @@ -15,6 +18,7 @@ public ShowDocumentViewerAction(StateManager stateManager, PreferencesService pr @Override public void execute() { - new DocumentViewerView().show(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.show(new DocumentViewerView()); } } diff --git a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java index 230c3165e4d..7f99aebe4df 100644 --- a/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java +++ b/src/main/java/org/jabref/gui/duplicationFinder/DuplicateSearch.java @@ -133,7 +133,8 @@ private DuplicateSearchResult verifyDuplicates() { private void askResolveStrategy(DuplicateSearchResult result, BibEntry first, BibEntry second, DuplicateResolverType resolverType) { DuplicateResolverDialog dialog = new DuplicateResolverDialog(first, second, resolverType, frame.getCurrentLibraryTab().getBibDatabaseContext(), stateManager); - DuplicateResolverResult resolverResult = dialog.showAndWait().orElse(DuplicateResolverResult.BREAK); + DuplicateResolverResult resolverResult = dialogService.showCustomDialogAndWait(dialog) + .orElse(DuplicateResolverResult.BREAK); if ((resolverResult == DuplicateResolverResult.KEEP_LEFT) || (resolverResult == DuplicateResolverResult.AUTOREMOVE_EXACT)) { diff --git a/src/main/java/org/jabref/gui/edit/ManageKeywordsAction.java b/src/main/java/org/jabref/gui/edit/ManageKeywordsAction.java index c2684ae0304..5ea7a6c9565 100644 --- a/src/main/java/org/jabref/gui/edit/ManageKeywordsAction.java +++ b/src/main/java/org/jabref/gui/edit/ManageKeywordsAction.java @@ -1,10 +1,13 @@ package org.jabref.gui.edit; +import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.BindingsHelper; import org.jabref.logic.l10n.Localization; +import com.airhacks.afterburner.injection.Injector; + import static org.jabref.gui.actions.ActionHelper.needsDatabase; import static org.jabref.gui.actions.ActionHelper.needsEntriesSelected; @@ -24,7 +27,7 @@ public ManageKeywordsAction(StateManager stateManager) { @Override public void execute() { - ManageKeywordsDialog dialog = new ManageKeywordsDialog(stateManager.getSelectedEntries()); - dialog.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new ManageKeywordsDialog(stateManager.getSelectedEntries())); } } diff --git a/src/main/java/org/jabref/gui/edit/MassSetFieldsAction.java b/src/main/java/org/jabref/gui/edit/MassSetFieldsAction.java index 5f045678dca..392f90536fc 100644 --- a/src/main/java/org/jabref/gui/edit/MassSetFieldsAction.java +++ b/src/main/java/org/jabref/gui/edit/MassSetFieldsAction.java @@ -37,7 +37,6 @@ public MassSetFieldsAction(StateManager stateManager, DialogService dialogServic @Override public void execute() { BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); - MassSetFieldsDialog dialog = new MassSetFieldsDialog(stateManager.getSelectedEntries(), database, dialogService, undoManager); - dialog.showAndWait(); + dialogService.showCustomDialogAndWait(new MassSetFieldsDialog(stateManager.getSelectedEntries(), database, dialogService, undoManager)); } } diff --git a/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java b/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java index 7b8b9d4a288..bf7b7e579d0 100644 --- a/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java +++ b/src/main/java/org/jabref/gui/edit/ReplaceStringAction.java @@ -1,10 +1,13 @@ package org.jabref.gui.edit; +import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + public class ReplaceStringAction extends SimpleCommand { private final JabRefFrame frame; @@ -16,7 +19,7 @@ public ReplaceStringAction(JabRefFrame frame, StateManager stateManager) { @Override public void execute() { - ReplaceStringView dialog = new ReplaceStringView(frame.getCurrentLibraryTab()); - dialog.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new ReplaceStringView(frame.getCurrentLibraryTab())); } } diff --git a/src/main/java/org/jabref/gui/exporter/ManageCustomExportsAction.java b/src/main/java/org/jabref/gui/exporter/ManageCustomExportsAction.java index 9c716145ad8..991ee60325d 100644 --- a/src/main/java/org/jabref/gui/exporter/ManageCustomExportsAction.java +++ b/src/main/java/org/jabref/gui/exporter/ManageCustomExportsAction.java @@ -1,11 +1,15 @@ package org.jabref.gui.exporter; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + public class ManageCustomExportsAction extends SimpleCommand { @Override public void execute() { - new ExportCustomizationDialogView().show(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.show(new ExportCustomizationDialogView()); } } diff --git a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesAction.java b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesAction.java index 6ed8f965756..2f23e54be25 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesAction.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesAction.java @@ -29,7 +29,6 @@ public FindUnlinkedFilesAction(DialogService dialogService, PreferencesService p @Override public void execute() { BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); - FindUnlinkedFilesDialog dlg = new FindUnlinkedFilesDialog(database, dialogService, preferencesService, undoManager); - dlg.showAndWait(); + dialogService.showCustomDialogAndWait(new FindUnlinkedFilesDialog(database, dialogService, preferencesService, undoManager)); } } diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java index e7ee73267b2..c147c839fc8 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java @@ -7,9 +7,12 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import org.jabref.gui.DialogService; import org.jabref.gui.icon.IconTheme; import org.jabref.logic.l10n.Localization; +import com.airhacks.afterburner.injection.Injector; + public class CustomizeExternalFileTypesViewModel { private final ObservableList fileTypes; @@ -52,9 +55,8 @@ private void showEditDialog(ExternalFileType type, String dialogTitle) { fileTypes.add(fileTypes.indexOf(type), typeForEdit); fileTypes.remove(type); } - - EditExternalFileTypeEntryDialog dlg = new EditExternalFileTypeEntryDialog(typeForEdit, dialogTitle); - dlg.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new EditExternalFileTypeEntryDialog(typeForEdit, dialogTitle)); } public void edit(ExternalFileType type) { diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypesAction.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypesAction.java index d7450556f4f..f2e25f72040 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypesAction.java +++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypesAction.java @@ -1,12 +1,15 @@ package org.jabref.gui.externalfiletype; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + public class EditExternalFileTypesAction extends SimpleCommand { @Override public void execute() { - CustomizeExternalFileTypesDialog editor = new CustomizeExternalFileTypesDialog(); - editor.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new CustomizeExternalFileTypesDialog()); } } diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 7f14652a529..1ace4c89bc3 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -381,9 +381,7 @@ public boolean delete() { } public void edit() { - LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(this.linkedFile); - - Optional editedFile = dialog.showAndWait(); + Optional editedFile = dialogService.showCustomDialogAndWait(new LinkedFileEditDialogView(this.linkedFile)); editedFile.ifPresent(file -> { this.linkedFile.setLink(file.getLink()); this.linkedFile.setDescription(file.getDescription()); diff --git a/src/main/java/org/jabref/gui/help/AboutAction.java b/src/main/java/org/jabref/gui/help/AboutAction.java index 9fae01d07ca..3d142491878 100644 --- a/src/main/java/org/jabref/gui/help/AboutAction.java +++ b/src/main/java/org/jabref/gui/help/AboutAction.java @@ -9,7 +9,6 @@ public class AboutAction extends SimpleCommand { @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - AboutDialogView aboutDialogView = new AboutDialogView(); - dialogService.show(aboutDialogView); + dialogService.show(new AboutDialogView()); } } diff --git a/src/main/java/org/jabref/gui/help/ErrorConsoleAction.java b/src/main/java/org/jabref/gui/help/ErrorConsoleAction.java index 3919b35a17b..992131268a6 100644 --- a/src/main/java/org/jabref/gui/help/ErrorConsoleAction.java +++ b/src/main/java/org/jabref/gui/help/ErrorConsoleAction.java @@ -1,8 +1,11 @@ package org.jabref.gui.help; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.errorconsole.ErrorConsoleView; +import com.airhacks.afterburner.injection.Injector; + /** * Such an error console can be * useful in getting complete bug reports, especially from Windows users, @@ -14,7 +17,7 @@ public class ErrorConsoleAction extends SimpleCommand { @Override public void execute() { - new ErrorConsoleView().show(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.show(new ErrorConsoleView()); } - } diff --git a/src/main/java/org/jabref/gui/help/VersionWorker.java b/src/main/java/org/jabref/gui/help/VersionWorker.java index 3c1235fde9f..139565c9df8 100644 --- a/src/main/java/org/jabref/gui/help/VersionWorker.java +++ b/src/main/java/org/jabref/gui/help/VersionWorker.java @@ -94,7 +94,7 @@ private void showUpdateInfo(Optional newerVersion, boolean manualExecut } } else { // notify the user about a newer version - new NewVersionDialog(installedVersion, newerVersion.get()).showAndWait(); + dialogService.showCustomDialogAndWait(new NewVersionDialog(installedVersion, newerVersion.get())); } } } diff --git a/src/main/java/org/jabref/gui/importer/ImportAction.java b/src/main/java/org/jabref/gui/importer/ImportAction.java index 64286fc30b9..38bf8004dd1 100644 --- a/src/main/java/org/jabref/gui/importer/ImportAction.java +++ b/src/main/java/org/jabref/gui/importer/ImportAction.java @@ -97,7 +97,7 @@ public void automatedImport(List filenames) { ImportEntriesDialog dialog = new ImportEntriesDialog(libraryTab.getBibDatabaseContext(), task); dialog.setTitle(Localization.lang("Import")); - dialog.showAndWait(); + dialogService.showCustomDialogAndWait(dialog); } } diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index 33cc16e8abe..79b50f958d2 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -207,7 +207,8 @@ public void resolveDuplicate(BibEntry entry) { DuplicateResolverDialog dialog = new DuplicateResolverDialog(other.get(), entry, DuplicateResolverDialog.DuplicateResolverType.INSPECTION, databaseContext, stateManager); - DuplicateResolverDialog.DuplicateResolverResult result = dialog.showAndWait().orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK); + DuplicateResolverDialog.DuplicateResolverResult result = dialogService.showCustomDialogAndWait(dialog) + .orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK); if (result == DuplicateResolverDialog.DuplicateResolverResult.KEEP_LEFT) { // TODO: Remove old entry. Or... add it to a list of entries @@ -237,7 +238,8 @@ public void resolveDuplicate(BibEntry entry) { DuplicateResolverDialog diag = new DuplicateResolverDialog(entry, other.get(), DuplicateResolverDialog.DuplicateResolverType.DUPLICATE_SEARCH, databaseContext, stateManager); - DuplicateResolverDialog.DuplicateResolverResult answer = diag.showAndWait().orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK); + DuplicateResolverDialog.DuplicateResolverResult answer = dialogService.showCustomDialogAndWait(diag) + .orElse(DuplicateResolverDialog.DuplicateResolverResult.BREAK); if (answer == DuplicateResolverDialog.DuplicateResolverResult.KEEP_LEFT) { // Remove other entry entries.remove(other.get()); diff --git a/src/main/java/org/jabref/gui/importer/ManageCustomImportsAction.java b/src/main/java/org/jabref/gui/importer/ManageCustomImportsAction.java index 3af1a7a3e74..fc0bb48cff5 100644 --- a/src/main/java/org/jabref/gui/importer/ManageCustomImportsAction.java +++ b/src/main/java/org/jabref/gui/importer/ManageCustomImportsAction.java @@ -1,7 +1,10 @@ package org.jabref.gui.importer; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + public class ManageCustomImportsAction extends SimpleCommand { public ManageCustomImportsAction() { @@ -9,6 +12,7 @@ public ManageCustomImportsAction() { @Override public void execute() { - new ImportCustomizationDialog().showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.show(new ImportCustomizationDialog()); } } diff --git a/src/main/java/org/jabref/gui/importer/NewEntryAction.java b/src/main/java/org/jabref/gui/importer/NewEntryAction.java index 4a8b5220dfe..ef085920713 100644 --- a/src/main/java/org/jabref/gui/importer/NewEntryAction.java +++ b/src/main/java/org/jabref/gui/importer/NewEntryAction.java @@ -57,7 +57,7 @@ public void execute() { jabRefFrame.getCurrentLibraryTab().insertEntry(new BibEntry(type.get())); } else { EntryTypeView typeChoiceDialog = new EntryTypeView(jabRefFrame.getCurrentLibraryTab(), dialogService, preferences); - EntryType selectedType = typeChoiceDialog.showAndWait().orElse(null); + EntryType selectedType = dialogService.showCustomDialogAndWait(typeChoiceDialog).orElse(null); if (selectedType == null) { return; } diff --git a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java index 1da9f8d60de..7bf425228ea 100644 --- a/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.stream.Collectors; +import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.LibraryTab; import org.jabref.gui.importer.ImportCustomEntryTypesDialog; @@ -10,6 +11,8 @@ import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntryType; +import com.airhacks.afterburner.injection.Injector; + /** * This action checks whether any new custom entry types were loaded from this * BIB file. If so, an offer to remember these entry types is given. @@ -24,9 +27,8 @@ public boolean isActionNecessary(ParserResult parserResult) { @Override public void performAction(LibraryTab libraryTab, ParserResult parserResult) { BibDatabaseMode mode = getBibDatabaseModeFromParserResult(parserResult); - - ImportCustomEntryTypesDialog importBibEntryTypesDialog = new ImportCustomEntryTypesDialog(mode, getListOfUnknownAndUnequalCustomizations(parserResult)); - importBibEntryTypesDialog.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new ImportCustomEntryTypesDialog(mode, getListOfUnknownAndUnequalCustomizations(parserResult))); } private List getListOfUnknownAndUnequalCustomizations(ParserResult parserResult) { diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java index 9d59a0f76cf..19057d6b1cd 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java @@ -110,7 +110,7 @@ public void search() { ImportEntriesDialog dialog = new ImportEntriesDialog(stateManager.getActiveDatabase().get(), task); dialog.setTitle(activeFetcher.getName()); - dialog.showAndWait(); + dialogService.showCustomDialogAndWait(dialog); } public void validateQueryStringAndGiveColorFeedback(TextField querySource, String queryString) { diff --git a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java index b26996bc43b..6a525a37198 100644 --- a/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java +++ b/src/main/java/org/jabref/gui/integrity/IntegrityCheckAction.java @@ -6,7 +6,6 @@ import javafx.collections.ObservableList; import javafx.concurrent.Task; -import org.jabref.gui.Dialog; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; @@ -71,8 +70,7 @@ protected List call() { if (messages.isEmpty()) { dialogService.notify(Localization.lang("No problems found.")); } else { - Dialog dialog = new IntegrityCheckDialog(messages, frame.getCurrentLibraryTab()); - dialog.showAndWait(); + dialogService.showCustomDialogAndWait(new IntegrityCheckDialog(messages, frame.getCurrentLibraryTab())); } }); task.setOnFailed(event -> dialogService.showErrorDialogAndWait("Integrity check failed.", task.getException())); diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java b/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java index 5b26c236737..efc12611f90 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java @@ -1,11 +1,15 @@ package org.jabref.gui.journals; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + public class ManageJournalsAction extends SimpleCommand { @Override public void execute() { - new ManageJournalAbbreviationsView().show(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.show(new ManageJournalAbbreviationsView()); } } diff --git a/src/main/java/org/jabref/gui/keyboard/CustomizeKeyBindingAction.java b/src/main/java/org/jabref/gui/keyboard/CustomizeKeyBindingAction.java index 773e866c048..00d10af0a95 100644 --- a/src/main/java/org/jabref/gui/keyboard/CustomizeKeyBindingAction.java +++ b/src/main/java/org/jabref/gui/keyboard/CustomizeKeyBindingAction.java @@ -1,11 +1,15 @@ package org.jabref.gui.keyboard; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + public class CustomizeKeyBindingAction extends SimpleCommand { @Override public void execute() { - new KeyBindingsDialogView().show(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.show(new KeyBindingsDialogView()); } } diff --git a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesAction.java b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesAction.java index ea8729837ee..6846c779831 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesAction.java +++ b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesAction.java @@ -1,9 +1,12 @@ package org.jabref.gui.libraryproperties; +import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + import static org.jabref.gui.actions.ActionHelper.needsDatabase; public class LibraryPropertiesAction extends SimpleCommand { @@ -17,7 +20,7 @@ public LibraryPropertiesAction(JabRefFrame frame, StateManager stateManager) { @Override public void execute() { - LibraryPropertiesDialogView propertiesDialog = new LibraryPropertiesDialogView(frame.getCurrentLibraryTab()); - propertiesDialog.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new LibraryPropertiesDialogView(frame.getCurrentLibraryTab())); } } diff --git a/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java b/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java index 534de7c529f..a0b6ff4602d 100644 --- a/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java +++ b/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java @@ -68,7 +68,7 @@ public void execute() { LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile); - dialog.showAndWait() + dialogService.showCustomDialogAndWait(dialog) .ifPresent(editedLinkedFile -> { Optional fieldChange = entry.addFile(editedLinkedFile); fieldChange.ifPresent(change -> { diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index a64c0232111..0310d5fd823 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -91,7 +91,7 @@ private void showMergeDialog(BibEntry originalEntry, BibEntry fetchedEntry, WebF dialog.setTitle(Localization.lang("Merge entry with %0 information", fetcher.getName())); dialog.setLeftHeaderText(Localization.lang("Original entry")); dialog.setRightHeaderText(Localization.lang("Entry from %0", fetcher.getName())); - Optional mergedEntry = dialog.showAndWait(); + Optional mergedEntry = dialogService.showCustomDialogAndWait(dialog); if (mergedEntry.isPresent()) { NamedCompound ce = new NamedCompound(Localization.lang("Merge entry with %0 information", fetcher.getName())); diff --git a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java index 0b1991cdff6..b4cf0cefa0f 100644 --- a/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java +++ b/src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java @@ -54,7 +54,7 @@ public void execute() { MergeEntriesDialog dlg = new MergeEntriesDialog(one, two); dlg.setTitle(Localization.lang("Merge entries")); - Optional mergedEntry = dlg.showAndWait(); + Optional mergedEntry = dialogService.showCustomDialogAndWait(dlg); if (mergedEntry.isPresent()) { // ToDo: BibDatabase::insertEntry does not contain logic to mark the BasePanel as changed and to mark // entries with a timestamp, only BasePanel::insertEntry does. Workaround for the moment is to get the diff --git a/src/main/java/org/jabref/gui/metadata/BibtexStringEditorAction.java b/src/main/java/org/jabref/gui/metadata/BibtexStringEditorAction.java index af36819dd91..4f2f8b7b67b 100644 --- a/src/main/java/org/jabref/gui/metadata/BibtexStringEditorAction.java +++ b/src/main/java/org/jabref/gui/metadata/BibtexStringEditorAction.java @@ -1,9 +1,12 @@ package org.jabref.gui.metadata; +import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.model.database.BibDatabaseContext; +import com.airhacks.afterburner.injection.Injector; + import static org.jabref.gui.actions.ActionHelper.needsDatabase; public class BibtexStringEditorAction extends SimpleCommand { @@ -18,7 +21,8 @@ public BibtexStringEditorAction(StateManager stateManager) { @Override public void execute() { + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); - new BibtexStringEditorDialogView(database.getDatabase()).showAndWait(); + dialogService.showCustomDialogAndWait(new BibtexStringEditorDialogView(database.getDatabase())); } } diff --git a/src/main/java/org/jabref/gui/openoffice/OOBibBase.java b/src/main/java/org/jabref/gui/openoffice/OOBibBase.java index 145b8fe0d84..e0ef177330f 100644 --- a/src/main/java/org/jabref/gui/openoffice/OOBibBase.java +++ b/src/main/java/org/jabref/gui/openoffice/OOBibBase.java @@ -155,7 +155,7 @@ public boolean isConnectedToDocument() { public XTextDocument selectComponent(List list) { List viewModel = list.stream().map(DocumentTitleViewModel::new).collect(Collectors.toList()); - // this whole method is part of a background task when autodecting instances, so we need to show dialog in FX thread + // this whole method is part of a background task when auto-detecting instances, so we need to show dialog in FX thread Optional selectedDocument = dialogService.showChoiceDialogAndWait(Localization.lang("Select document"), Localization.lang("Found documents:"), Localization.lang("Use selected document"), viewModel); return selectedDocument.map(DocumentTitleViewModel::getXtextDocument).orElse(null); } diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index dd2c0418b1f..daead2c527f 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -89,13 +89,12 @@ public class OpenOfficePanel { private final Button settingsB = new Button(Localization.lang("Settings")); private final Button help; private final VBox vbox = new VBox(); - - private OOBibBase ooBase; private final JabRefFrame frame; - private OOBibStyle style; private final PreferencesService preferencesService; private final TaskExecutor taskExecutor; private final StyleLoader loader; + private OOBibBase ooBase; + private OOBibStyle style; private OpenOfficePreferences ooPrefs; public OpenOfficePanel(JabRefFrame frame, PreferencesService preferencesService, OpenOfficePreferences ooPrefs, KeyBindingRepository keyBindingRepository) { @@ -161,9 +160,7 @@ private void initPanel() { setStyleFile.setMaxWidth(Double.MAX_VALUE); setStyleFile.setOnAction(event -> { - - StyleSelectDialogView styleDialog = new StyleSelectDialogView(loader); - styleDialog.showAndWait().ifPresent(selectedStyle -> { + dialogService.showCustomDialogAndWait(new StyleSelectDialogView(loader)).ifPresent(selectedStyle -> { style = selectedStyle; try { style.ensureUpToDate(); @@ -247,8 +244,7 @@ private void initPanel() { settingsB.setOnAction(e -> settingsMenu.show(settingsB, Side.BOTTOM, 0, 0)); manageCitations.setMaxWidth(Double.MAX_VALUE); manageCitations.setOnAction(e -> { - ManageCitationsDialogView dlg = new ManageCitationsDialogView(ooBase); - dlg.showAndWait(); + dialogService.showCustomDialogAndWait(new ManageCitationsDialogView(ooBase)); }); exportCitations.setMaxWidth(Double.MAX_VALUE); @@ -448,7 +444,7 @@ private OOBibBase createBibBase(List jarUrls) throws IOException, Invocatio } private Optional showManualConnectionDialog() { - return new ManualConnectDialogView(dialogService).showAndWait(); + return dialogService.showCustomDialogAndWait(new ManualConnectDialogView(dialogService)); } private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addPageInfo) { @@ -460,9 +456,7 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP Boolean inParenthesis = inParenthesisIn; String pageInfo = null; if (addPageInfo) { - - AdvancedCiteDialogView citeDialog = new AdvancedCiteDialogView(); - Optional citeDialogViewModel = citeDialog.showAndWait(); + Optional citeDialogViewModel = dialogService.showCustomDialogAndWait(new AdvancedCiteDialogView()); if (citeDialogViewModel.isPresent()) { diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java index 70c3f54cf13..f563af54293 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java @@ -107,7 +107,7 @@ public void exportPreferences() { } public void showPreferences() { - new PreferencesFilterDialog(new PreferencesFilter(preferences)).showAndWait(); + dialogService.showCustomDialogAndWait(new PreferencesFilterDialog(new PreferencesFilter(preferences))); } public void resetPreferences() { diff --git a/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java b/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java index f17774fcb57..8050c866899 100644 --- a/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java +++ b/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java @@ -1,9 +1,12 @@ package org.jabref.gui.preferences; +import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.util.TaskExecutor; +import com.airhacks.afterburner.injection.Injector; + public class ShowPreferencesAction extends SimpleCommand { private final JabRefFrame jabRefFrame; @@ -16,6 +19,7 @@ public ShowPreferencesAction(JabRefFrame jabRefFrame, TaskExecutor taskExecutor) @Override public void execute() { - new PreferencesDialogView(jabRefFrame).show(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.show(new PreferencesDialogView(jabRefFrame)); } } diff --git a/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsAction.java b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsAction.java index 34f4ff3f116..22ea1cbed9c 100644 --- a/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsAction.java +++ b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsAction.java @@ -1,12 +1,15 @@ package org.jabref.gui.protectedterms; +import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + public class ManageProtectedTermsAction extends SimpleCommand { @Override public void execute() { - ManageProtectedTermsDialog protectTermsDialog = new ManageProtectedTermsDialog(); - protectTermsDialog.showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new ManageProtectedTermsDialog()); } } diff --git a/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsViewModel.java b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsViewModel.java index 29e9b46104e..0a36a7cbf0c 100644 --- a/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsViewModel.java +++ b/src/main/java/org/jabref/gui/protectedterms/ManageProtectedTermsViewModel.java @@ -96,8 +96,7 @@ public void removeFile(ProtectedTermsList list) { } public void createNewFile() { - NewProtectedTermsFileDialog newDialog = new NewProtectedTermsFileDialog(termsLoader, dialogService); - newDialog.showAndWait(); + dialogService.showCustomDialogAndWait(new NewProtectedTermsFileDialog(termsLoader, dialogService)); } public void edit(ProtectedTermsList file) { diff --git a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseCommand.java b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseCommand.java index 6d8aee1b301..9a79e714a65 100644 --- a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseCommand.java +++ b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseCommand.java @@ -1,8 +1,11 @@ package org.jabref.gui.shared; +import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.actions.SimpleCommand; +import com.airhacks.afterburner.injection.Injector; + /** * Opens a shared database. */ @@ -16,6 +19,7 @@ public ConnectToSharedDatabaseCommand(JabRefFrame jabRefFrame) { @Override public void execute() { - new SharedDatabaseLoginDialogView(jabRefFrame).showAndWait(); + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showCustomDialogAndWait(new SharedDatabaseLoginDialogView(jabRefFrame)); } } diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java index 9fee4372776..90a63a830f1 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java @@ -63,7 +63,7 @@ public void listen(ConnectionLostEvent connectionLostEvent) { if (answer.isPresent()) { if (answer.get().equals(reconnect)) { jabRefFrame.closeCurrentTab(); - new SharedDatabaseLoginDialogView(jabRefFrame).showAndWait(); + dialogService.showCustomDialogAndWait(new SharedDatabaseLoginDialogView(jabRefFrame)); } else if (answer.get().equals(workOffline)) { connectionLostEvent.getBibDatabaseContext().convertToLocalDatabase(); jabRefFrame.getLibraryTabs().forEach(tab -> tab.updateTabTitle(tab.isModified())); @@ -101,7 +101,7 @@ public void listen(UpdateRefusedEvent updateRefusedEvent) { if (response.isPresent() && response.get().equals(merge)) { MergeEntriesDialog dialog = new MergeEntriesDialog(localBibEntry, sharedBibEntry); - Optional mergedEntry = dialog.showAndWait(); + Optional mergedEntry = dialogService.showCustomDialogAndWait(dialog); mergedEntry.ifPresent(mergedBibEntry -> { mergedBibEntry.getSharedBibEntryData().setSharedID(sharedBibEntry.getSharedBibEntryData().getSharedID()); diff --git a/src/main/java/org/jabref/gui/texparser/ParseLatexAction.java b/src/main/java/org/jabref/gui/texparser/ParseLatexAction.java index 1c5a2bc8274..637feed20fb 100644 --- a/src/main/java/org/jabref/gui/texparser/ParseLatexAction.java +++ b/src/main/java/org/jabref/gui/texparser/ParseLatexAction.java @@ -1,10 +1,13 @@ package org.jabref.gui.texparser; +import org.jabref.gui.DialogService; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; import org.jabref.gui.actions.SimpleCommand; import org.jabref.model.database.BibDatabaseContext; +import com.airhacks.afterburner.injection.Injector; + public class ParseLatexAction extends SimpleCommand { private final StateManager stateManager; @@ -16,8 +19,8 @@ public ParseLatexAction(StateManager stateManager) { @Override public void execute() { + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(NullPointerException::new); - ParseLatexDialogView dialog = new ParseLatexDialogView(database); - dialog.showAndWait(); + dialogService.showCustomDialogAndWait(new ParseLatexDialogView(database)); } } diff --git a/src/main/java/org/jabref/gui/texparser/ParseLatexDialogViewModel.java b/src/main/java/org/jabref/gui/texparser/ParseLatexDialogViewModel.java index cc4ea9f3715..4d5552a8cc0 100644 --- a/src/main/java/org/jabref/gui/texparser/ParseLatexDialogViewModel.java +++ b/src/main/java/org/jabref/gui/texparser/ParseLatexDialogViewModel.java @@ -204,7 +204,8 @@ public void parseButtonClicked() { BackgroundTask.wrap(() -> entriesResolver.resolve(new DefaultLatexParser().parse(fileList))) .onRunning(() -> searchInProgress.set(true)) .onFinished(() -> searchInProgress.set(false)) - .onSuccess(result -> new ParseLatexResultView(result, databaseContext, Path.of(latexFileDirectory.get())).showAndWait()) + .onSuccess(result -> dialogService.showCustomDialogAndWait( + new ParseLatexResultView(result, databaseContext, Path.of(latexFileDirectory.get())))) .onFailure(dialogService::showErrorDialogAndWait) .executeWith(taskExecutor); } diff --git a/src/main/java/org/jabref/gui/texparser/ParseLatexResultViewModel.java b/src/main/java/org/jabref/gui/texparser/ParseLatexResultViewModel.java index dd9b2464d01..c40d86c52ae 100644 --- a/src/main/java/org/jabref/gui/texparser/ParseLatexResultViewModel.java +++ b/src/main/java/org/jabref/gui/texparser/ParseLatexResultViewModel.java @@ -12,6 +12,7 @@ import javafx.collections.ObservableList; import org.jabref.gui.AbstractViewModel; +import org.jabref.gui.DialogService; import org.jabref.gui.importer.ImportEntriesDialog; import org.jabref.gui.util.BackgroundTask; import org.jabref.logic.importer.ParserResult; @@ -20,6 +21,8 @@ import org.jabref.model.texparser.Citation; import org.jabref.model.texparser.LatexBibEntriesResolverResult; +import com.airhacks.afterburner.injection.Injector; + public class ParseLatexResultViewModel extends AbstractViewModel { private final LatexBibEntriesResolverResult resolverResult; @@ -70,9 +73,9 @@ public void activeReferenceChanged(ReferenceViewModel reference) { * Search and import unknown references from associated BIB files. */ public void importButtonClicked() { + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); ImportEntriesDialog dialog = new ImportEntriesDialog(databaseContext, BackgroundTask.wrap(() -> new ParserResult(resolverResult.getNewEntries()))); - dialog.setTitle(Localization.lang("Import entries from LaTeX files")); - dialog.showAndWait(); + dialogService.showCustomDialogAndWait(dialog); } } From edc6d4ba7e20685942e2bb10e9436adb3e28e11d Mon Sep 17 00:00:00 2001 From: Fiyinfolu Eludire <17176053+faeludire@users.noreply.github.com> Date: Wed, 30 Dec 2020 20:11:25 +0000 Subject: [PATCH 4/9] [WIP] Fix for application dialogs opening in wrong displays --- .../java/org/jabref/gui/help/AboutAction.java | 13 +++++++++++- .../org/jabref/gui/help/AboutActionTest.java | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/jabref/gui/help/AboutActionTest.java diff --git a/src/main/java/org/jabref/gui/help/AboutAction.java b/src/main/java/org/jabref/gui/help/AboutAction.java index 3d142491878..d2c225eb686 100644 --- a/src/main/java/org/jabref/gui/help/AboutAction.java +++ b/src/main/java/org/jabref/gui/help/AboutAction.java @@ -6,9 +6,20 @@ import com.airhacks.afterburner.injection.Injector; public class AboutAction extends SimpleCommand { + + private final AboutDialogView aboutDialogView; + + public AboutAction() { + this.aboutDialogView = new AboutDialogView(); + } + @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.show(new AboutDialogView()); + dialogService.show(aboutDialogView); + } + + public AboutDialogView getAboutDialogView() { + return aboutDialogView; } } diff --git a/src/test/java/org/jabref/gui/help/AboutActionTest.java b/src/test/java/org/jabref/gui/help/AboutActionTest.java new file mode 100644 index 00000000000..3d972fd626d --- /dev/null +++ b/src/test/java/org/jabref/gui/help/AboutActionTest.java @@ -0,0 +1,20 @@ +package org.jabref.gui.help; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class AboutActionTest { + + @Test + public void shouldOpenDialogOnSameMonitor() { + // given + AboutAction aboutAction = new AboutAction(); + + // when + aboutAction.execute(); + + // then + assertNotNull(aboutAction.getAboutDialogView().getOwner()); + } +} From f2dc4f2e115c94f37b21316b5c125d398f2b8754 Mon Sep 17 00:00:00 2001 From: Fiyinfolu Eludire <17176053+faeludire@users.noreply.github.com> Date: Thu, 31 Dec 2020 13:40:20 +0000 Subject: [PATCH 5/9] Fix for application dialogs opening in wrong displays - Rename DialogService.show() method to showCustomDialog() - Rename showCustomDialog()'s argument - Add documentation to showCustomDialog method - Make createDialog and createDialogWithOptOut non static --- src/main/java/org/jabref/gui/DialogService.java | 9 +++++++-- .../java/org/jabref/gui/JabRefDialogService.java | 12 ++++++------ .../gui/documentviewer/ShowDocumentViewerAction.java | 2 +- .../gui/exporter/ManageCustomExportsAction.java | 2 +- src/main/java/org/jabref/gui/help/AboutAction.java | 2 +- .../java/org/jabref/gui/help/ErrorConsoleAction.java | 2 +- .../gui/importer/ManageCustomImportsAction.java | 2 +- .../jabref/gui/journals/ManageJournalsAction.java | 2 +- .../gui/keyboard/CustomizeKeyBindingAction.java | 2 +- .../gui/preferences/ShowPreferencesAction.java | 2 +- 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/gui/DialogService.java b/src/main/java/org/jabref/gui/DialogService.java index 8dc6b61248d..367b81bda0d 100644 --- a/src/main/java/org/jabref/gui/DialogService.java +++ b/src/main/java/org/jabref/gui/DialogService.java @@ -161,6 +161,13 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content, String okButtonLabel, String cancelButtonLabel, String optOutMessage, Consumer optOutAction); + /** + * Shows a custom dialog without returning any results. + * + * @param dialog dialog to show + */ + void showCustomDialog(BaseDialog dialog); + /** * This will create and display a new dialog of the specified * {@link Alert.AlertType} but with user defined buttons as optional @@ -273,6 +280,4 @@ Optional showCustomButtonDialogAndWait(Alert.AlertType type, String * @return the selected file or an empty {@link Optional} if no file has been selected */ Optional showFileOpenFromArchiveDialog(Path archivePath) throws IOException; - - void show(BaseDialog aboutDialogView); } diff --git a/src/main/java/org/jabref/gui/JabRefDialogService.java b/src/main/java/org/jabref/gui/JabRefDialogService.java index 1a8af7cee36..2ffe0ad1ae4 100644 --- a/src/main/java/org/jabref/gui/JabRefDialogService.java +++ b/src/main/java/org/jabref/gui/JabRefDialogService.java @@ -70,16 +70,16 @@ public class JabRefDialogService implements DialogService { private static final Logger LOGGER = LoggerFactory.getLogger(JabRefDialogService.class); private static PreferencesService preferences; - private static Window mainWindow; + private final Window mainWindow; private final JFXSnackbar statusLine; public JabRefDialogService(Window mainWindow, Pane mainPane, PreferencesService preferences) { - JabRefDialogService.mainWindow = mainWindow; + this.mainWindow = mainWindow; this.statusLine = new JFXSnackbar(mainPane); JabRefDialogService.preferences = preferences; } - private static FXDialog createDialog(AlertType type, String title, String content) { + private FXDialog createDialog(AlertType type, String title, String content) { FXDialog alert = new FXDialog(type, title, true); preferences.getTheme().installCss(alert.getDialogPane().getScene()); alert.setHeaderText(null); @@ -89,8 +89,8 @@ private static FXDialog createDialog(AlertType type, String title, String conten return alert; } - private static FXDialog createDialogWithOptOut(AlertType type, String title, String content, - String optOutMessage, Consumer optOutAction) { + private FXDialog createDialogWithOptOut(AlertType type, String title, String content, + String optOutMessage, Consumer optOutAction) { FXDialog alert = new FXDialog(type, title, true); // Need to force the alert to layout in order to grab the graphic as we are replacing the dialog pane with a custom pane alert.getDialogPane().applyCss(); @@ -397,7 +397,7 @@ public Optional showFileOpenFromArchiveDialog(Path archivePath) throws IOE } @Override - public void show(BaseDialog aboutDialogView) { + public void showCustomDialog(BaseDialog aboutDialogView) { aboutDialogView.initOwner(mainWindow); aboutDialogView.show(); } diff --git a/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java b/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java index b059c2c5b7f..b05bfae76f6 100644 --- a/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java +++ b/src/main/java/org/jabref/gui/documentviewer/ShowDocumentViewerAction.java @@ -19,6 +19,6 @@ public ShowDocumentViewerAction(StateManager stateManager, PreferencesService pr @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.show(new DocumentViewerView()); + dialogService.showCustomDialog(new DocumentViewerView()); } } diff --git a/src/main/java/org/jabref/gui/exporter/ManageCustomExportsAction.java b/src/main/java/org/jabref/gui/exporter/ManageCustomExportsAction.java index 991ee60325d..9c06dd48f93 100644 --- a/src/main/java/org/jabref/gui/exporter/ManageCustomExportsAction.java +++ b/src/main/java/org/jabref/gui/exporter/ManageCustomExportsAction.java @@ -10,6 +10,6 @@ public class ManageCustomExportsAction extends SimpleCommand { @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.show(new ExportCustomizationDialogView()); + dialogService.showCustomDialog(new ExportCustomizationDialogView()); } } diff --git a/src/main/java/org/jabref/gui/help/AboutAction.java b/src/main/java/org/jabref/gui/help/AboutAction.java index d2c225eb686..9cc3a5447ee 100644 --- a/src/main/java/org/jabref/gui/help/AboutAction.java +++ b/src/main/java/org/jabref/gui/help/AboutAction.java @@ -16,7 +16,7 @@ public AboutAction() { @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.show(aboutDialogView); + dialogService.showCustomDialog(aboutDialogView); } public AboutDialogView getAboutDialogView() { diff --git a/src/main/java/org/jabref/gui/help/ErrorConsoleAction.java b/src/main/java/org/jabref/gui/help/ErrorConsoleAction.java index 992131268a6..16a41242dfe 100644 --- a/src/main/java/org/jabref/gui/help/ErrorConsoleAction.java +++ b/src/main/java/org/jabref/gui/help/ErrorConsoleAction.java @@ -18,6 +18,6 @@ public class ErrorConsoleAction extends SimpleCommand { @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.show(new ErrorConsoleView()); + dialogService.showCustomDialog(new ErrorConsoleView()); } } diff --git a/src/main/java/org/jabref/gui/importer/ManageCustomImportsAction.java b/src/main/java/org/jabref/gui/importer/ManageCustomImportsAction.java index fc0bb48cff5..9d5a28d34ea 100644 --- a/src/main/java/org/jabref/gui/importer/ManageCustomImportsAction.java +++ b/src/main/java/org/jabref/gui/importer/ManageCustomImportsAction.java @@ -13,6 +13,6 @@ public ManageCustomImportsAction() { @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.show(new ImportCustomizationDialog()); + dialogService.showCustomDialog(new ImportCustomizationDialog()); } } diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java b/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java index efc12611f90..07b6b9be911 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalsAction.java @@ -10,6 +10,6 @@ public class ManageJournalsAction extends SimpleCommand { @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.show(new ManageJournalAbbreviationsView()); + dialogService.showCustomDialog(new ManageJournalAbbreviationsView()); } } diff --git a/src/main/java/org/jabref/gui/keyboard/CustomizeKeyBindingAction.java b/src/main/java/org/jabref/gui/keyboard/CustomizeKeyBindingAction.java index 00d10af0a95..2eae884d30b 100644 --- a/src/main/java/org/jabref/gui/keyboard/CustomizeKeyBindingAction.java +++ b/src/main/java/org/jabref/gui/keyboard/CustomizeKeyBindingAction.java @@ -10,6 +10,6 @@ public class CustomizeKeyBindingAction extends SimpleCommand { @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.show(new KeyBindingsDialogView()); + dialogService.showCustomDialog(new KeyBindingsDialogView()); } } diff --git a/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java b/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java index 8050c866899..b070e914aea 100644 --- a/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java +++ b/src/main/java/org/jabref/gui/preferences/ShowPreferencesAction.java @@ -20,6 +20,6 @@ public ShowPreferencesAction(JabRefFrame jabRefFrame, TaskExecutor taskExecutor) @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - dialogService.show(new PreferencesDialogView(jabRefFrame)); + dialogService.showCustomDialog(new PreferencesDialogView(jabRefFrame)); } } From 62ebcad34e1fc5253fa5dd48f22f211fc1f4cfaa Mon Sep 17 00:00:00 2001 From: Fiyinfolu Eludire <17176053+faeludire@users.noreply.github.com> Date: Thu, 31 Dec 2020 16:14:59 +0000 Subject: [PATCH 6/9] Add change description to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ee5078e4fa..247520fab32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue with the style of highlighted check boxes while searching in preferences. [#7226](https://github.com/JabRef/jabref/issues/7226) - We fixed an issue where the option "Move file to file directory" was disabled in the entry editor for all files [#7194](https://github.com/JabRef/jabref/issues/7194) +- We fixed an issue where application dialogs were opening in the wrong display when using multiple screens [#7273](https://github.com/JabRef/jabref/pull/7273) ### Removed From 770273e98645fb20ae6e29c0e00f2aa7d2b4d931 Mon Sep 17 00:00:00 2001 From: Fiyinfolu Eludire <17176053+faeludire@users.noreply.github.com> Date: Fri, 1 Jan 2021 17:06:59 +0000 Subject: [PATCH 7/9] Drop unneeded test AboutActionTest --- .../org/jabref/gui/help/AboutActionTest.java | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/test/java/org/jabref/gui/help/AboutActionTest.java diff --git a/src/test/java/org/jabref/gui/help/AboutActionTest.java b/src/test/java/org/jabref/gui/help/AboutActionTest.java deleted file mode 100644 index 3d972fd626d..00000000000 --- a/src/test/java/org/jabref/gui/help/AboutActionTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.jabref.gui.help; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class AboutActionTest { - - @Test - public void shouldOpenDialogOnSameMonitor() { - // given - AboutAction aboutAction = new AboutAction(); - - // when - aboutAction.execute(); - - // then - assertNotNull(aboutAction.getAboutDialogView().getOwner()); - } -} From f5b9da5f7a7a4762d0381e5d659228d9b6ec719b Mon Sep 17 00:00:00 2001 From: Fiyinfolu Eludire <17176053+faeludire@users.noreply.github.com> Date: Sat, 2 Jan 2021 15:36:41 +0000 Subject: [PATCH 8/9] Document guidelines for creating a new dialog --- docs/getting-into-the-code/code-howtos.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/getting-into-the-code/code-howtos.md b/docs/getting-into-the-code/code-howtos.md index 7005314618c..4525180f252 100644 --- a/docs/getting-into-the-code/code-howtos.md +++ b/docs/getting-into-the-code/code-howtos.md @@ -398,3 +398,19 @@ All radio buttons that should be grouped together need to have a ToggleGroup def ``` +### JavaFX Dialogs +All dialogs should be displayed to the user via `DialogService` interface methods. +`DialogService` provides methods to display various dialogs (including custom ones) to the user. +It also ensures the displayed dialog opens on the correct window via `initOwner()` (for cases where the user has multiple screens). +The following code snippet demonstrates how a custom dialog is displayed to the user: + +```java +dialogService.showCustomDialog(new DocumentViewerView()); +``` + +If an instance of `DialogService` is unavailable within current class/scope in which the dialog needs to be displayed, +`DialogService` can be instantiated via the code snippet shown as follows: + +```java +DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); +``` From bea0e318001656cbbd27ef399e6236767236f8ef Mon Sep 17 00:00:00 2001 From: Fiyinfolu Eludire <17176053+faeludire@users.noreply.github.com> Date: Sat, 2 Jan 2021 16:15:08 +0000 Subject: [PATCH 9/9] Document guidelines for creating a new dialog --- docs/getting-into-the-code/code-howtos.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/getting-into-the-code/code-howtos.md b/docs/getting-into-the-code/code-howtos.md index 4525180f252..f5dea179d80 100644 --- a/docs/getting-into-the-code/code-howtos.md +++ b/docs/getting-into-the-code/code-howtos.md @@ -399,6 +399,7 @@ All radio buttons that should be grouped together need to have a ToggleGroup def ``` ### JavaFX Dialogs + All dialogs should be displayed to the user via `DialogService` interface methods. `DialogService` provides methods to display various dialogs (including custom ones) to the user. It also ensures the displayed dialog opens on the correct window via `initOwner()` (for cases where the user has multiple screens).