From 9a5b7d1c31c4bbbdf945acdbb9a633efd14073d4 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Tue, 4 Jun 2019 23:44:25 +0200 Subject: [PATCH] Select push app in preferences (#5024) * Added Submenu to change external push-app * Rewording, Respacing and Optimizing * Rewording Confusing PushApplications to PushToApplicationsManager * Refactoring and unifying PtAAction with ToolbarButton * Refactor simplified * Reword l10n * Refactor for checks * Added eye-candy * Added eye-candy * Changelog * whitespaces * Rewording, Sorting, Simplifying * Whitespace * Rewording, Sorting * Refactor var-declaration * Removed Submenu and Added Preferences Setting * Fixed compiletime-error * Added App-settings-button * Changelog * Whitespaces and superflous * Revert persistent actionInformation * Removed superfluous declaration * Added eyecandy * Refactor so simplify * Refactor for some minor requests * Refactor of PushToApplicationSettings * Checkstyle --- CHANGELOG.md | 1 + src/main/java/org/jabref/gui/JabRefFrame.java | 25 +++--- .../jabref/gui/preferences/ExternalTab.java | 60 +++++++++----- .../gui/push/PushToApplicationAction.java | 23 +++--- .../gui/push/PushToApplicationSettings.java | 80 +++++++------------ .../push/PushToApplicationSettingsDialog.java | 22 ----- .../gui/push/PushToApplicationsManager.java | 54 ++++++++++--- .../jabref/gui/push/PushToEmacsSettings.java | 15 ++-- .../jabref/gui/push/PushToLyxSettings.java | 7 +- .../jabref/gui/push/PushToVimSettings.java | 15 ++-- .../jabref/preferences/JabRefPreferences.java | 13 +++ src/main/resources/l10n/JabRef_en.properties | 5 +- 12 files changed, 173 insertions(+), 147 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/push/PushToApplicationSettingsDialog.java diff --git a/CHANGELOG.md b/CHANGELOG.md index f5c6b08442d..bc0063bb095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - The Medline fetcher now normalizes the author names according to the BibTeX-Standard [#4345](https://github.com/JabRef/jabref/issues/4345) - We added an option on the Linked File Viewer to rename the attached file of an entry directly on the JabRef. [#4844](https://github.com/JabRef/jabref/issues/4844) - We added an option in the preference dialog box that allows user to enable helpful tooltips.[#3599](https://github.com/JabRef/jabref/issues/3599) +- We moved the dropdown menu for selecting the push-application from the toolbar into the external application preferences. [#674](https://github.com/JabRef/jabref/issues/674) ### Fixed diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index e70d9429b6d..ef9074973d9 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -28,6 +28,7 @@ import javafx.scene.control.ButtonType; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; +import javafx.scene.control.MenuItem; import javafx.scene.control.ProgressBar; import javafx.scene.control.Separator; import javafx.scene.control.SeparatorMenuItem; @@ -154,7 +155,7 @@ public class JabRefFrame extends BorderPane { private final CountingUndoManager undoManager; private SidePaneManager sidePaneManager; private TabPane tabbedPane; - private PushToApplicationsManager pushApplications; + private final PushToApplicationsManager pushToApplicationsManager; private final DialogService dialogService; private SidePane sidePane; @@ -162,6 +163,7 @@ public JabRefFrame(Stage mainStage) { this.mainStage = mainStage; this.dialogService = new JabRefDialogService(mainStage, this); this.stateManager = Globals.stateManager; + this.pushToApplicationsManager = new PushToApplicationsManager(dialogService, stateManager); this.undoManager = Globals.undoManager; } @@ -449,8 +451,6 @@ public boolean quit() { private void initLayout() { setProgressBarVisible(false); - pushApplications = new PushToApplicationsManager(this.getDialogService()); - BorderPane head = new BorderPane(); head.setTop(createMenu()); head.setCenter(createToolbar()); @@ -520,7 +520,10 @@ private Node createToolbar() { leftSide.prefWidthProperty().bind(sidePane.widthProperty()); leftSide.maxWidthProperty().bind(sidePane.widthProperty()); - PushToApplicationAction pushToApplicationAction = new PushToApplicationAction(stateManager, this.getPushApplications(), this.getDialogService()); + final PushToApplicationAction pushToApplicationAction = getPushToApplicationsManager().getPushToApplicationAction(); + final Button pushToApplicationButton = factory.createIconButton(pushToApplicationAction.getActionInformation(), pushToApplicationAction); + pushToApplicationsManager.setToolBarButton(pushToApplicationButton); + HBox rightSide = new HBox( factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, BiblatexEntryTypes.ARTICLE, dialogService, Globals.prefs, stateManager)), factory.createIconButton(StandardActions.DELETE_ENTRY, new OldDatabaseCommandWrapper(Actions.DELETE, this, stateManager)), @@ -531,7 +534,7 @@ private Node createToolbar() { factory.createIconButton(StandardActions.COPY, new OldDatabaseCommandWrapper(Actions.COPY, this, stateManager)), factory.createIconButton(StandardActions.PASTE, new OldDatabaseCommandWrapper(Actions.PASTE, this, stateManager)), new Separator(Orientation.VERTICAL), - factory.createIconButton(pushToApplicationAction.getActionInformation(), pushToApplicationAction), + pushToApplicationButton, factory.createIconButton(StandardActions.GENERATE_CITE_KEYS, new OldDatabaseCommandWrapper(Actions.MAKE_KEY, this, stateManager)), factory.createIconButton(StandardActions.CLEANUP_ENTRIES, new OldDatabaseCommandWrapper(Actions.CLEANUP, this, stateManager)), new Separator(Orientation.VERTICAL), @@ -759,7 +762,11 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.SET_FILE_LINKS, new AutoLinkFilesAction(this, prefs, stateManager, undoManager)) ); - final PushToApplicationAction pushToApplicationAction = new PushToApplicationAction(stateManager, this.getPushApplications(), this.getDialogService()); + // PushToApplication + final PushToApplicationAction pushToApplicationAction = pushToApplicationsManager.getPushToApplicationAction(); + final MenuItem pushToApplicationMenuItem = factory.createMenuItem(pushToApplicationAction.getActionInformation(), pushToApplicationAction); + pushToApplicationsManager.setMenuItem(pushToApplicationMenuItem); + tools.getItems().addAll( factory.createMenuItem(StandardActions.NEW_SUB_LIBRARY_FROM_AUX, new NewSubLibraryAction(this, stateManager)), factory.createMenuItem(StandardActions.FIND_UNLINKED_FILES, new FindUnlinkedFilesAction(this, stateManager)), @@ -776,7 +783,7 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.GENERATE_CITE_KEYS, new OldDatabaseCommandWrapper(Actions.MAKE_KEY, this, stateManager)), factory.createMenuItem(StandardActions.REPLACE_ALL, new OldDatabaseCommandWrapper(Actions.REPLACE_ALL, this, stateManager)), factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new OldDatabaseCommandWrapper(Actions.SEND_AS_EMAIL, this, stateManager)), - factory.createMenuItem(pushToApplicationAction.getActionInformation(), pushToApplicationAction), + pushToApplicationMenuItem, factory.createSubMenu(StandardActions.ABBREVIATE, factory.createMenuItem(StandardActions.ABBREVIATE_ISO, new OldDatabaseCommandWrapper(Actions.ABBREVIATE_ISO, this, stateManager)), @@ -1192,8 +1199,8 @@ public SidePaneManager getSidePaneManager() { return sidePaneManager; } - public PushToApplicationsManager getPushApplications() { - return pushApplications; + public PushToApplicationsManager getPushToApplicationsManager() { + return pushToApplicationsManager; } public GlobalSearchBar getGlobalSearchBar() { diff --git a/src/main/java/org/jabref/gui/preferences/ExternalTab.java b/src/main/java/org/jabref/gui/preferences/ExternalTab.java index afb52861d68..a2bca6c0077 100644 --- a/src/main/java/org/jabref/gui/preferences/ExternalTab.java +++ b/src/main/java/org/jabref/gui/preferences/ExternalTab.java @@ -3,7 +3,10 @@ import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; import javafx.scene.control.CheckBox; +import javafx.scene.control.ComboBox; +import javafx.scene.control.DialogPane; import javafx.scene.control.Label; import javafx.scene.control.RadioButton; import javafx.scene.control.Separator; @@ -18,8 +21,9 @@ import org.jabref.gui.externalfiletype.EditExternalFileTypesAction; import org.jabref.gui.push.PushToApplication; import org.jabref.gui.push.PushToApplicationSettings; -import org.jabref.gui.push.PushToApplicationSettingsDialog; +import org.jabref.gui.push.PushToApplicationsManager; import org.jabref.gui.util.FileDialogConfiguration; +import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.OS; import org.jabref.model.strings.StringUtil; @@ -30,6 +34,8 @@ class ExternalTab implements PrefsTab { private final JabRefFrame frame; private final JabRefPreferences prefs; private final TextField emailSubject; + private final ComboBox pushToApplicationComboBox; + private final TextField citeCommand; private final CheckBox openFoldersOfAttachedFiles; @@ -58,6 +64,10 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere dialogService = frame.getDialogService(); builder.setVgap(7); + pushToApplicationComboBox = new ComboBox<>(); + Button pushToApplicationSettingsButton = new Button(Localization.lang("Application settings")); + pushToApplicationSettingsButton.setOnAction(e -> showPushToApplicationSettings()); + Button editFileTypes = new Button(Localization.lang("Manage external file types")); citeCommand = new TextField(); editFileTypes.setOnAction(e -> new EditExternalFileTypesAction().execute()); @@ -147,13 +157,19 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere externalPrograms.getStyleClass().add("sectionHeader"); builder.add(externalPrograms, 1, 9); - GridPane butpan = new GridPane(); - int index = 0; - for (PushToApplication pushToApplication : frame.getPushApplications().getApplications()) { - addSettingsButton(pushToApplication, butpan, index); - index++; - } - builder.add(butpan, 1, 10); + // PushToApplication configuration + HBox pushToApplicationHBox = new HBox(); + pushToApplicationHBox.setAlignment(Pos.CENTER_LEFT); + pushToApplicationHBox.setSpacing(10); + pushToApplicationHBox.getChildren().add(new Label(Localization.lang("Application to push entries to:"))); + new ViewModelListCellFactory() + .withText(application -> application.getApplicationName()) + .withIcon(application -> application.getIcon()) + .install(pushToApplicationComboBox); + pushToApplicationComboBox.getItems().addAll(frame.getPushToApplicationsManager().getApplications()); + pushToApplicationHBox.getChildren().add(pushToApplicationComboBox); + pushToApplicationHBox.getChildren().add(pushToApplicationSettingsButton); + builder.add(pushToApplicationHBox, 1, 10); // Cite command configuration HBox citeCommandBox = new HBox(); @@ -197,24 +213,13 @@ public Node getBuilder() { return builder; } - private void addSettingsButton(final PushToApplication application, GridPane panel, int index) { - PushToApplicationSettings settings = frame.getPushApplications().getSettings(application); - Button button = new Button(Localization.lang("Settings for %0", application.getApplicationName())); - button.setPrefSize(150, 20); - button.setOnAction(e -> PushToApplicationSettingsDialog.showSettingsDialog(dialogService, settings, index)); - if ((index % 2) == 0) { - panel.add(button, 1, (index / 2) + 1); - } else { - panel.add(button, 2, (index / 2) + 1); - } - } - @Override public void setValues() { emailSubject.setText(prefs.get(JabRefPreferences.EMAIL_SUBJECT)); openFoldersOfAttachedFiles.setSelected(prefs.getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES)); + pushToApplicationComboBox.setValue(prefs.getActivePushToApplication(frame.getPushToApplicationsManager())); citeCommand.setText(prefs.get(JabRefPreferences.CITE_COMMAND)); defaultConsole.setSelected(Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION)); @@ -244,6 +249,7 @@ public void setValues() { public void storeSettings() { prefs.put(JabRefPreferences.EMAIL_SUBJECT, emailSubject.getText()); prefs.putBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES, openFoldersOfAttachedFiles.isSelected()); + prefs.setActivePushToApplication(pushToApplicationComboBox.getValue(), frame.getPushToApplicationsManager()); prefs.put(JabRefPreferences.CITE_COMMAND, citeCommand.getText()); prefs.putBoolean(JabRefPreferences.USE_DEFAULT_CONSOLE_APPLICATION, defaultConsole.isSelected()); prefs.put(JabRefPreferences.CONSOLE_COMMAND, consoleCommand.getText()); @@ -276,6 +282,20 @@ private void updateExecuteConsoleButtonAndFieldEnabledState() { consoleCommand.setDisable(!executeConsole.isSelected()); } + private void showPushToApplicationSettings() { + PushToApplicationsManager manager = frame.getPushToApplicationsManager(); + PushToApplication selectedApplication = pushToApplicationComboBox.getValue(); + PushToApplicationSettings settings = manager.getSettings(selectedApplication); + DialogPane dialogPane = new DialogPane(); + dialogPane.setContent(settings.getSettingsPane()); + + dialogService.showCustomDialogAndWait(Localization.lang("Application settings"), dialogPane, ButtonType.OK, ButtonType.CANCEL).ifPresent(btn -> { + if (btn == ButtonType.OK) { + settings.storeSettings(); + } + }); + } + private void showConsoleChooser() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> consoleCommand.setText(file.toAbsolutePath().toString())); } diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationAction.java b/src/main/java/org/jabref/gui/push/PushToApplicationAction.java index ecfb54763ad..a042a1210cb 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationAction.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationAction.java @@ -25,12 +25,13 @@ */ public class PushToApplicationAction extends SimpleCommand { - private final PushToApplication operation; private final StateManager stateManager; private final DialogService dialogService; + private PushToApplication application; + public PushToApplicationAction(StateManager stateManager, PushToApplicationsManager pushToApplicationsManager, DialogService dialogService) { - this.operation = pushToApplicationsManager.getLastUsedApplication(Globals.prefs); + this.application = Globals.prefs.getActivePushToApplication(pushToApplicationsManager); this.stateManager = stateManager; this.dialogService = dialogService; @@ -38,12 +39,15 @@ public PushToApplicationAction(StateManager stateManager, PushToApplicationsMana this.statusMessage.bind(BindingsHelper.ifThenElse(this.executable, "", Localization.lang("This operation requires one or more entries to be selected."))); } + public void updateApplication(PushToApplication application) { + this.application = application; + } + public Action getActionInformation() { return new Action() { - @Override public Optional getIcon() { - return Optional.of(operation.getIcon()); + return Optional.of(application.getIcon()); } @Override @@ -53,7 +57,7 @@ public Optional getKeyBinding() { @Override public String getText() { - return Localization.lang("Push entries to external application (%0)", operation.getApplicationName()); + return Localization.lang("Push entries to external application (%0)", application.getApplicationName()); } @Override @@ -86,11 +90,11 @@ private static String getKeyString(List entries) { @Override public void execute() { // If required, check that all entries have BibTeX keys defined: - if (operation.requiresBibtexKeys()) { + if (application.requiresBibtexKeys()) { for (BibEntry entry : stateManager.getSelectedEntries()) { if (StringUtil.isBlank(entry.getCiteKeyOptional())) { dialogService.showErrorDialogAndWait( - operation.getApplicationName(), + application.getApplicationName(), Localization.lang("This operation requires all selected entries to have BibTeX keys defined.")); return; @@ -100,13 +104,12 @@ public void execute() { // All set, call the operation in a new thread: BackgroundTask.wrap(this::pushEntries) - .onSuccess(s -> operation.operationCompleted()) + .onSuccess(s -> application.operationCompleted()) .executeWith(Globals.TASK_EXECUTOR); - } private void pushEntries() { BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); - operation.pushEntries(database, stateManager.getSelectedEntries(), getKeyString(stateManager.getSelectedEntries())); + application.pushEntries(database, stateManager.getSelectedEntries(), getKeyString(stateManager.getSelectedEntries())); } } diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationSettings.java b/src/main/java/org/jabref/gui/push/PushToApplicationSettings.java index 5bf9d5a75f7..5758eefb892 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationSettings.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationSettings.java @@ -13,70 +13,42 @@ public class PushToApplicationSettings { - protected final TextField path = new TextField(); - protected Label commandLabel = new Label(); - protected GridPane jfxSettings; - protected AbstractPushToApplication application; - private DialogService dialogService; + protected final Label commandLabel; + protected final TextField path; + protected final GridPane settingsPane; + private final AbstractPushToApplication application; + private final DialogService dialogService; + private final Button browse; - public PushToApplicationSettings(DialogService dialogService) { + public PushToApplicationSettings(PushToApplication application, DialogService dialogService) { + this.application = (AbstractPushToApplication) application; this.dialogService = dialogService; - } + settingsPane = new GridPane(); - public GridPane getJFXSettingPane(int n) { - switch (n) { - case 0: - application = new PushToEmacs(dialogService); - break; - case 1: - application = new PushToLyx(dialogService); - break; - case 2: - application = new PushToTexmaker(dialogService); - break; - case 3: - application = new PushToTeXstudio(dialogService); - break; - case 4: - application = new PushToVim(dialogService); - break; - case 5: - application = new PushToWinEdt(dialogService); - break; - default: - application = null; - break; - } - application.initParameters(); - String commandPath = Globals.prefs.get(application.commandPathPreferenceKey); - if (jfxSettings == null) { - initJFXSettingsPanel(); - } - path.setText(commandPath); + commandLabel = new Label(); + path = new TextField(); + browse = new Button(Localization.lang("Browse")); - return jfxSettings; - } + this.application.initParameters(); - protected void initJFXSettingsPanel() { - jfxSettings = new GridPane(); - StringBuilder label = new StringBuilder(Localization.lang("Path to %0", application.getApplicationName())); // In case the application name and the actual command is not the same, add the command in brackets - if (application.getCommandName() == null) { - label.append(':'); + StringBuilder commandLine = new StringBuilder(Localization.lang("Path to %0", application.getApplicationName())); + if (this.application.getCommandName() == null) { + commandLine.append(':'); } else { - label.append(" (").append(application.getCommandName()).append("):"); + commandLine.append(" (").append(this.application.getCommandName()).append("):"); } - commandLabel = new Label(label.toString()); - jfxSettings.add(commandLabel, 0, 0); - jfxSettings.add(path, 1, 0); - Button browse = new Button(Localization.lang("Browse")); + commandLabel.setText(commandLine.toString()); + settingsPane.add(commandLabel, 0, 0); - FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); + path.setText(Globals.prefs.get(this.application.commandPathPreferenceKey)); + settingsPane.add(path, 1, 0); + FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() + .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); browse.setOnAction(e -> dialogService.showFileOpenDialog(fileDialogConfiguration) .ifPresent(f -> path.setText(f.toAbsolutePath().toString()))); - jfxSettings.add(browse, 2, 0); + settingsPane.add(browse, 2, 0); } /** @@ -87,4 +59,8 @@ protected void initJFXSettingsPanel() { public void storeSettings() { Globals.prefs.put(application.commandPathPreferenceKey, path.getText()); } + + public GridPane getSettingsPane() { + return settingsPane; + } } diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationSettingsDialog.java b/src/main/java/org/jabref/gui/push/PushToApplicationSettingsDialog.java deleted file mode 100644 index 4374c7322a0..00000000000 --- a/src/main/java/org/jabref/gui/push/PushToApplicationSettingsDialog.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.jabref.gui.push; - -import javafx.scene.control.ButtonType; -import javafx.scene.control.DialogPane; - -import org.jabref.gui.DialogService; -import org.jabref.logic.l10n.Localization; - -public class PushToApplicationSettingsDialog { - - public static void showSettingsDialog(DialogService dialogService, PushToApplicationSettings toApp, int n) { - - DialogPane dialogPane = new DialogPane(); - dialogPane.setContent(toApp.getJFXSettingPane(n)); - - dialogService.showCustomDialogAndWait(Localization.lang("App settings"), dialogPane, ButtonType.OK, ButtonType.CANCEL).ifPresent(btn -> { - if (btn == ButtonType.OK) { - toApp.storeSettings(); - } - }); - } -} diff --git a/src/main/java/org/jabref/gui/push/PushToApplicationsManager.java b/src/main/java/org/jabref/gui/push/PushToApplicationsManager.java index e7bfaf78b3b..64dbc4be850 100644 --- a/src/main/java/org/jabref/gui/push/PushToApplicationsManager.java +++ b/src/main/java/org/jabref/gui/push/PushToApplicationsManager.java @@ -3,8 +3,13 @@ import java.util.ArrayList; import java.util.List; +import javafx.scene.control.Button; +import javafx.scene.control.MenuItem; + +import org.jabref.Globals; import org.jabref.gui.DialogService; -import org.jabref.preferences.JabRefPreferences; +import org.jabref.gui.StateManager; +import org.jabref.gui.actions.ActionFactory; public class PushToApplicationsManager { @@ -12,7 +17,11 @@ public class PushToApplicationsManager { private final DialogService dialogService; - public PushToApplicationsManager(DialogService dialogService) { + private final PushToApplicationAction action; + private MenuItem menuItem; + private Button toolBarButton; + + public PushToApplicationsManager(DialogService dialogService, StateManager stateManager) { this.dialogService = dialogService; // Set up the current available choices: applications = new ArrayList<>(); @@ -22,29 +31,56 @@ public PushToApplicationsManager(DialogService dialogService) { applications.add(new PushToTeXstudio(dialogService)); applications.add(new PushToVim(dialogService)); applications.add(new PushToWinEdt(dialogService)); + + this.action = new PushToApplicationAction(stateManager, this, dialogService); } public List getApplications() { return applications; } + public PushToApplicationAction getPushToApplicationAction() { + return action; + } + + public void setMenuItem(MenuItem menuItem) { + this.menuItem = menuItem; + } + + public void setToolBarButton(Button toolBarButton) { + this.toolBarButton = toolBarButton; + } + public PushToApplicationSettings getSettings(PushToApplication application) { if (application instanceof PushToEmacs) { - return new PushToEmacsSettings(dialogService); + return new PushToEmacsSettings(application, dialogService); } else if (application instanceof PushToLyx) { - return new PushToLyxSettings(dialogService); + return new PushToLyxSettings(application, dialogService); } else if (application instanceof PushToVim) { - return new PushToVimSettings(dialogService); + return new PushToVimSettings(application, dialogService); } else { - return new PushToApplicationSettings(dialogService); + return new PushToApplicationSettings(application, dialogService); } } - public PushToApplication getLastUsedApplication(JabRefPreferences preferences) { - String appSelected = preferences.get(JabRefPreferences.PUSH_TO_APPLICATION); + public PushToApplication getApplicationByName(String applicationName) { return applications.stream() - .filter(application -> application.getApplicationName().equals(appSelected)) + .filter(application -> application.getApplicationName().equals(applicationName)) .findAny() .orElse(applications.get(0)); } + + public void updateApplicationAction() { + final ActionFactory factory = new ActionFactory(Globals.getKeyPrefs()); + + action.updateApplication(Globals.prefs.getActivePushToApplication(this)); + + if (menuItem != null) { + factory.configureMenuItem(action.getActionInformation(), action, menuItem); + } + + if (toolBarButton != null) { + factory.configureIconButton(action.getActionInformation(), action, toolBarButton); + } + } } diff --git a/src/main/java/org/jabref/gui/push/PushToEmacsSettings.java b/src/main/java/org/jabref/gui/push/PushToEmacsSettings.java index 0147276b652..5e3364f1939 100644 --- a/src/main/java/org/jabref/gui/push/PushToEmacsSettings.java +++ b/src/main/java/org/jabref/gui/push/PushToEmacsSettings.java @@ -12,19 +12,16 @@ public class PushToEmacsSettings extends PushToApplicationSettings { private final TextField additionalParams = new TextField(); - public PushToEmacsSettings (DialogService dialogService) { super(dialogService); } + public PushToEmacsSettings(PushToApplication application, DialogService dialogService) { + super(application, dialogService); + settingsPane.add(new Label(Localization.lang("Additional parameters") + ":"), 0, 1); + settingsPane.add(additionalParams, 1, 1); + additionalParams.setText(Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS)); + } @Override public void storeSettings() { super.storeSettings(); Globals.prefs.put(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS, additionalParams.getText()); } - - @Override - protected void initJFXSettingsPanel() { - super.initJFXSettingsPanel(); - jfxSettings.add(new Label(Localization.lang("Additional parameters") + ":"), 0, 1); - jfxSettings.add(additionalParams, 1, 1); - additionalParams.setText(Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS)); - } } diff --git a/src/main/java/org/jabref/gui/push/PushToLyxSettings.java b/src/main/java/org/jabref/gui/push/PushToLyxSettings.java index 85fe05a97e4..70ae6e2132e 100644 --- a/src/main/java/org/jabref/gui/push/PushToLyxSettings.java +++ b/src/main/java/org/jabref/gui/push/PushToLyxSettings.java @@ -7,11 +7,8 @@ public class PushToLyxSettings extends PushToApplicationSettings { - public PushToLyxSettings (DialogService dialogService) { super(dialogService); } - - @Override - protected void initJFXSettingsPanel() { - super.initJFXSettingsPanel(); + public PushToLyxSettings(PushToApplication application, DialogService dialogService) { + super(application, dialogService); path.setText(Globals.prefs.get(JabRefPreferences.LYXPIPE)); commandLabel.setText(Localization.lang("Path to LyX pipe") + ":"); } diff --git a/src/main/java/org/jabref/gui/push/PushToVimSettings.java b/src/main/java/org/jabref/gui/push/PushToVimSettings.java index 70438ed9115..fa08f9de83a 100644 --- a/src/main/java/org/jabref/gui/push/PushToVimSettings.java +++ b/src/main/java/org/jabref/gui/push/PushToVimSettings.java @@ -12,19 +12,16 @@ public class PushToVimSettings extends PushToApplicationSettings { private final TextField vimServer = new TextField(); - public PushToVimSettings (DialogService dialogService) { super(dialogService); } + public PushToVimSettings(PushToApplication application, DialogService dialogService) { + super(application, dialogService); + settingsPane.add(new Label(Localization.lang("Vim server name") + ":"), 0, 1); + settingsPane.add(vimServer, 1, 1); + vimServer.setText(Globals.prefs.get(JabRefPreferences.VIM_SERVER)); + } @Override public void storeSettings() { super.storeSettings(); Globals.prefs.put(JabRefPreferences.VIM_SERVER, vimServer.getText()); } - - @Override - protected void initJFXSettingsPanel() { - super.initJFXSettingsPanel(); - jfxSettings.add(new Label(Localization.lang("Vim server name") + ":"), 0, 1); - jfxSettings.add(vimServer, 1, 1); - vimServer.setText(Globals.prefs.get(JabRefPreferences.VIM_SERVER)); - } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 8ea32b20878..253b64cb8e4 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -53,6 +53,8 @@ import org.jabref.gui.maintable.MainTablePreferences; import org.jabref.gui.mergeentries.MergeEntries; import org.jabref.gui.preferences.ImportSettingsTab; +import org.jabref.gui.push.PushToApplication; +import org.jabref.gui.push.PushToApplicationsManager; import org.jabref.gui.util.ThemeLoader; import org.jabref.logic.bibtex.FieldContentParserPreferences; import org.jabref.logic.bibtex.LatexFieldFormatterPreferences; @@ -2105,4 +2107,15 @@ private void saveCustomEntryTypes(BibDatabaseMode bibDatabaseMode) { storeCustomEntryTypes(customBiblatexBibTexTypes, bibDatabaseMode); } + + public PushToApplication getActivePushToApplication(PushToApplicationsManager manager) { + return manager.getApplicationByName(get(JabRefPreferences.PUSH_TO_APPLICATION)); + } + + public void setActivePushToApplication(PushToApplication application, PushToApplicationsManager manager) { + if (application.getApplicationName() != get(PUSH_TO_APPLICATION)) { + put(PUSH_TO_APPLICATION, application.getApplicationName()); + manager.updateApplicationAction(); + } + } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 58822acd1ce..28e5ce1f177 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -67,6 +67,8 @@ Append\ library=Append library Application=Application +Application\ to\ push\ entries\ to\:=Application to push entries to: + Apply=Apply Arguments\ passed\ on\ to\ running\ JabRef\ instance.\ Shutting\ down.=Arguments passed on to running JabRef instance. Shutting down. @@ -1044,7 +1046,6 @@ Reset=Reset Use\ IEEE\ LaTeX\ abbreviations=Use IEEE LaTeX abbreviations When\ opening\ file\ link,\ search\ for\ matching\ file\ if\ no\ link\ is\ defined=When opening file link, search for matching file if no link is defined -Settings\ for\ %0=Settings for %0 Line\ %0\:\ Found\ corrupted\ BibTeX\ key\ %1.=Line %0: Found corrupted BibTeX key %1. Line\ %0\:\ Found\ corrupted\ BibTeX\ key\ %1\ (contains\ whitespaces).=Line %0: Found corrupted BibTeX key %1 (contains whitespaces). Line\ %0\:\ Found\ corrupted\ BibTeX\ key\ %1\ (comma\ missing).=Line %0: Found corrupted BibTeX key %1 (comma missing). @@ -2086,7 +2087,7 @@ Rename\ file\ to\ a\ given\ name=Rename file to a given name New\ Filename=New Filename Rename\ file\ to\ defined\ pattern=Rename file to defined pattern -App\ settings=App settings +Application\ settings=Application settings Export\ an\ input\ to\ a\ file=Export an input to a file Export\ preferences\ to\ a\ file=Export preferences to a file