Skip to content

Commit

Permalink
Select push app in preferences (#5024)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
calixtus authored and tobiasdiez committed Jun 4, 2019
1 parent c6ce82d commit 9a5b7d1
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 147 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,14 +155,15 @@ 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;

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;
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)),
Expand All @@ -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),
Expand Down Expand Up @@ -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)),
Expand All @@ -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)),
Expand Down Expand Up @@ -1192,8 +1199,8 @@ public SidePaneManager getSidePaneManager() {
return sidePaneManager;
}

public PushToApplicationsManager getPushApplications() {
return pushApplications;
public PushToApplicationsManager getPushToApplicationsManager() {
return pushToApplicationsManager;
}

public GlobalSearchBar getGlobalSearchBar() {
Expand Down
60 changes: 40 additions & 20 deletions src/main/java/org/jabref/gui/preferences/ExternalTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -30,6 +34,8 @@ class ExternalTab implements PrefsTab {
private final JabRefFrame frame;
private final JabRefPreferences prefs;
private final TextField emailSubject;
private final ComboBox<PushToApplication> pushToApplicationComboBox;

private final TextField citeCommand;
private final CheckBox openFoldersOfAttachedFiles;

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<PushToApplication>()
.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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()));
}
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/org/jabref/gui/push/PushToApplicationAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,29 @@
*/
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;

this.executable.bind(needsDatabase(stateManager).and(needsEntriesSelected(stateManager)));
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<JabRefIcon> getIcon() {
return Optional.of(operation.getIcon());
return Optional.of(application.getIcon());
}

@Override
Expand All @@ -53,7 +57,7 @@ public Optional<KeyBinding> 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
Expand Down Expand Up @@ -86,11 +90,11 @@ private static String getKeyString(List<BibEntry> 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;
Expand All @@ -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()));
}
}
Loading

0 comments on commit 9a5b7d1

Please sign in to comment.