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

Select push app in preferences #5024

Merged
merged 30 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2e6896b
Added Submenu to change external push-app
calixtus May 22, 2019
f420082
Rewording, Respacing and Optimizing
calixtus May 22, 2019
1883f6f
Rewording Confusing PushApplications to PushToApplicationsManager
calixtus May 22, 2019
d0aa24c
Refactoring and unifying PtAAction with ToolbarButton
calixtus May 22, 2019
6fa926f
Refactor simplified
calixtus May 22, 2019
f48a9d4
Reword l10n
calixtus May 22, 2019
746e025
Refactor for checks
calixtus May 22, 2019
5d6a7cf
Added eye-candy
calixtus May 22, 2019
a8b6489
Added eye-candy
calixtus May 22, 2019
186f9bc
Changelog
calixtus May 22, 2019
ec5f96b
whitespaces
calixtus May 22, 2019
91e4393
Merge remote-tracking branch 'upstream/master' into menu_select_push_app
calixtus May 30, 2019
2ce9d37
Rewording, Sorting, Simplifying
calixtus May 30, 2019
e66586e
Whitespace
calixtus May 30, 2019
a91455d
Rewording, Sorting
calixtus May 30, 2019
eddbe0a
Refactor var-declaration
calixtus Jun 2, 2019
fadd6ce
Removed Submenu and Added Preferences Setting
calixtus Jun 2, 2019
96e4b6f
Fixed compiletime-error
calixtus Jun 2, 2019
734e8c9
Added App-settings-button
calixtus Jun 2, 2019
fd18502
Changelog
calixtus Jun 2, 2019
6ae31aa
Whitespaces and superflous
calixtus Jun 2, 2019
26a1c93
Revert persistent actionInformation
calixtus Jun 2, 2019
4084701
Merge branch 'menu_select_push_app' into pref_select_push_app
calixtus Jun 2, 2019
2f1637a
Removed superfluous declaration
calixtus Jun 2, 2019
3fa27df
Merge branch 'menu_select_push_app' into pref_select_push_app
calixtus Jun 2, 2019
4b0862c
Added eyecandy
calixtus Jun 4, 2019
435a87f
Refactor so simplify
calixtus Jun 4, 2019
4406e1a
Refactor for some minor requests
calixtus Jun 4, 2019
89ac2fe
Refactor of PushToApplicationSettings
calixtus Jun 4, 2019
dbed029
Checkstyle
calixtus Jun 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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