Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for application dialogs opening in wrong displays #7273

Merged
merged 10 commits into from
Jan 2, 2021
5 changes: 4 additions & 1 deletion src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -184,7 +185,7 @@ Optional<ButtonType> showCustomButtonDialogAndWait(Alert.AlertType type, String
* @param dialog dialog to show
* @param <R> type of result
*/
<R> Optional<R> showCustomDialogAndWait(Dialog<R> dialog);
<R> Optional<R> showCustomDialogAndWait(javafx.scene.control.Dialog<R> dialog);

/**
* Constructs and shows a canceable {@link ProgressDialog}. Clicking cancel will cancel the underlying service and close the dialog
Expand Down Expand Up @@ -272,4 +273,6 @@ Optional<ButtonType> showCustomButtonDialogAndWait(Alert.AlertType type, String
* @return the selected file or an empty {@link Optional} if no file has been selected
*/
Optional<Path> showFileOpenFromArchiveDialog(Path archivePath) throws IOException;

void show(BaseDialog<?> aboutDialogView);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename it to showCustomDialog to be coherent with the above method. Or rename that to showAndWait...yeah maybe the later?

Please also rename the argument, and add a bit of documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename it to showCustomDialog to be coherent with the above method. Or rename that to showAndWait...yeah maybe the later?

Please also rename the argument, and add a bit of documentation.

Decided to go with showCustomDialog() as it seems to be more consistent with other methods in that interface.

}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/EntryTypeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void runFetcherWorker() {
Optional<BibEntry> 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);
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,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;
eludif marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Expand All @@ -84,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;
}

Expand Down Expand Up @@ -117,6 +119,7 @@ protected Node createDetailsButton() {
alert.setHeaderText(null);
alert.setContentText(content);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.initOwner(mainWindow);
return alert;
}

Expand All @@ -136,6 +139,7 @@ public <T> Optional<T> 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();
}
Expand All @@ -145,6 +149,7 @@ public Optional<String> 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();
}
Expand All @@ -154,6 +159,7 @@ public Optional<String> 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();
}
Expand Down Expand Up @@ -181,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();
}
Expand All @@ -190,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();
}
Expand Down Expand Up @@ -259,12 +267,14 @@ public Optional<ButtonType> 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 <R> Optional<R> showCustomDialogAndWait(Dialog<R> dialog) {
public <R> Optional<R> showCustomDialogAndWait(javafx.scene.control.Dialog<R> dialog) {
dialog.initOwner(mainWindow);
return dialog.showAndWait();
}

Expand All @@ -285,6 +295,7 @@ public <V> void showProgressDialog(String title, String content, Task<V> task) {
progressDialog.close();
});
preferences.getTheme().installCss(progressDialog.getDialogPane().getScene());
progressDialog.initOwner(mainWindow);
progressDialog.show();
}

Expand All @@ -307,6 +318,7 @@ public <V> Optional<ButtonType> 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) -> {
Expand All @@ -316,9 +328,7 @@ public <V> Optional<ButtonType> showBackgroundProgressDialogAndWait(String title
}
});

Dialog<ButtonType> dialog = alert::showAndWait;

return showCustomDialogAndWait(dialog);
return alert.showAndWait();
}

@Override
Expand Down Expand Up @@ -385,4 +395,10 @@ public Optional<Path> 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();
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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()));
}
}
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/gui/cleanup/CleanupAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ public void execute() {
isCanceled = false;
modifiedEntriesCount = 0;

Optional<CleanupPreset> chosenPreset = new CleanupDialog(
CleanupDialog cleanupDialog = new CleanupDialog(
stateManager.getActiveDatabase().get(),
preferences.getCleanupPreset(),
preferences.getFilePreferences()).showAndWait();
preferences.getFilePreferences()
);

Optional<CleanupPreset> chosenPreset = dialogService.showCustomDialogAndWait(cleanupDialog);

chosenPreset.ifPresent(preset -> {
if (preset.isRenamePDFActive() && preferences.getAutoLinkPreferences().shouldAskAutoNamingPdfs()) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/jabref/gui/collab/DatabaseChangePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,9 +35,8 @@ private void onDatabaseChanged(List<DatabaseChangeViewModel> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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));
}
}
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/copyfiles/CopyFilesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ private void showDialog(List<CopyFilesResultItemViewModel> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Loading