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

Submenu to select push-application #4991

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
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 tools menu. [#674](https://github.com/JabRef/jabref/issues/674)


### Fixed
Expand Down
53 changes: 45 additions & 8 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
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.RadioMenuItem;
import javafx.scene.control.Separator;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextInputControl;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.ToolBar;
import javafx.scene.control.Tooltip;
import javafx.scene.input.DataFormat;
Expand Down Expand Up @@ -95,7 +98,9 @@
import org.jabref.gui.metadata.PreambleEditor;
import org.jabref.gui.preferences.ShowPreferencesAction;
import org.jabref.gui.protectedterms.ManageProtectedTermsAction;
import org.jabref.gui.push.PushToApplication;
import org.jabref.gui.push.PushToApplicationAction;
import org.jabref.gui.push.PushToApplicationMenuAction;
import org.jabref.gui.push.PushToApplicationsManager;
import org.jabref.gui.search.GlobalSearchBar;
import org.jabref.gui.shared.ConnectToSharedDatabaseCommand;
Expand Down Expand Up @@ -154,7 +159,7 @@ public class JabRefFrame extends BorderPane {
private final CountingUndoManager undoManager;
private SidePaneManager sidePaneManager;
private TabPane tabbedPane;
private PushToApplicationsManager pushApplications;
private PushToApplicationsManager pushToApplicationsManager;
private final DialogService dialogService;
private SidePane sidePane;

Expand Down Expand Up @@ -449,7 +454,7 @@ public boolean quit() {
private void initLayout() {
setProgressBarVisible(false);

pushApplications = new PushToApplicationsManager(this.getDialogService());
pushToApplicationsManager = new PushToApplicationsManager(dialogService, stateManager);

BorderPane head = new BorderPane();
head.setTop(createMenu());
Expand Down Expand Up @@ -520,7 +525,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 +539,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 +767,30 @@ 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 submenu
final Menu pushApplicationsMenu = factory.createSubMenu(StandardActions.SELECT_PUSH_APPLICATION);
final String activePushToApplicationName = Globals.prefs.get(JabRefPreferences.PUSH_TO_APPLICATION);

final ToggleGroup pushToToggleGroup = new ToggleGroup();
RadioMenuItem pushToApplication;
calixtus marked this conversation as resolved.
Show resolved Hide resolved
PushToApplicationMenuAction pushToApplicationMenuAction;

for (PushToApplication application : pushToApplicationsManager.getApplications()) {
pushToApplicationMenuAction = new PushToApplicationMenuAction(application, pushToApplicationsManager);
pushToApplication = factory.createRadioMenuItem(
pushToApplicationMenuAction.getActionInformation(),
pushToApplicationMenuAction,
application.getApplicationName().equals(activePushToApplicationName));

pushApplicationsMenu.getItems().add(pushToApplication);
pushToApplication.setToggleGroup(pushToToggleGroup);
}

// 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 +807,13 @@ 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),

new SeparatorMenuItem(),

pushApplicationsMenu,
pushToApplicationMenuItem,

new SeparatorMenuItem(),

factory.createSubMenu(StandardActions.ABBREVIATE,
factory.createMenuItem(StandardActions.ABBREVIATE_ISO, new OldDatabaseCommandWrapper(Actions.ABBREVIATE_ISO, this, stateManager)),
Expand Down Expand Up @@ -1192,8 +1229,8 @@ public SidePaneManager getSidePaneManager() {
return sidePaneManager;
}

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

public GlobalSearchBar getGlobalSearchBar() {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/gui/actions/ActionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.Tooltip;

import org.jabref.gui.keyboard.KeyBindingRepository;
Expand Down Expand Up @@ -112,6 +113,14 @@ public CheckMenuItem createCheckMenuItem(Action action, Command command, boolean
return checkMenuItem;
}

public RadioMenuItem createRadioMenuItem(Action action, Command command, boolean selected) {
RadioMenuItem radioMenuItem = ActionUtils.createRadioMenuItem(new JabRefAction(action, command, keyBindingRepository));
radioMenuItem.setSelected(selected);
setGraphic(radioMenuItem, action);

return radioMenuItem;
}

public Menu createMenu(Action action) {
Menu menu = ActionUtils.createMenu(new JabRefAction(action, keyBindingRepository));

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public enum StandardActions implements Action {
OPEN_CONSOLE(Localization.lang("Open terminal here"), Localization.lang("Open terminal here"), IconTheme.JabRefIcons.CONSOLE, KeyBinding.OPEN_CONSOLE),
COPY_LINKED_FILES(Localization.lang("Copy linked files to folder...")),
COPY_DOI(Localization.lang("Copy DOI url")),
SELECT_PUSH_APPLICATION(Localization.lang("Select external application")),
ABBREVIATE(Localization.lang("Abbreviate journal names")),
ABBREVIATE_ISO("ISO", Localization.lang("Abbreviate journal names of the selected entries (ISO abbreviation)"), KeyBinding.ABBREVIATE),
ABBREVIATE_MEDLINE("MEDLINE", Localization.lang("Abbreviate journal names of the selected entries (MEDLINE abbreviation)")),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/preferences/ExternalTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public ExternalTab(JabRefFrame frame, PreferencesDialog prefsDiag, JabRefPrefere

GridPane butpan = new GridPane();
int index = 0;
for (PushToApplication pushToApplication : frame.getPushApplications().getApplications()) {
for (PushToApplication pushToApplication : frame.getPushToApplicationsManager().getApplications()) {
addSettingsButton(pushToApplication, butpan, index);
index++;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public Node getBuilder() {
}

private void addSettingsButton(final PushToApplication application, GridPane panel, int index) {
PushToApplicationSettings settings = frame.getPushApplications().getSettings(application);
PushToApplicationSettings settings = frame.getPushToApplicationsManager().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));
Expand Down
30 changes: 21 additions & 9 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,37 @@
*/
public class PushToApplicationAction extends SimpleCommand {

private final PushToApplication operation;
private final StateManager stateManager;
private final DialogService dialogService;

private PushToApplication application;
private Action action;

public PushToApplicationAction(StateManager stateManager, PushToApplicationsManager pushToApplicationsManager, DialogService dialogService) {
this.operation = pushToApplicationsManager.getLastUsedApplication(Globals.prefs);
this.application = pushToApplicationsManager.getActiveApplication(Globals.prefs);
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.")));

updateAction();
}

public void updateApplication (PushToApplication application) {
this.application = application;
updateAction();
}

public Action getActionInformation() {
return new Action() {
return action;
calixtus marked this conversation as resolved.
Show resolved Hide resolved
}

public void updateAction() {
action = new Action() {
@Override
public Optional<JabRefIcon> getIcon() {
return Optional.of(operation.getIcon());
return Optional.of(application.getIcon());
}

@Override
Expand All @@ -53,7 +65,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 +98,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 +112,13 @@ 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()));
}
}
78 changes: 78 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToApplicationMenuAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.jabref.gui.push;

import java.util.Optional;

import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;

import org.jabref.Globals;
import org.jabref.gui.actions.Action;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.preferences.JabRefPreferences;

/**
* An Action class representing the process of invoking a PushToApplicationMenu operation.
*/
public class PushToApplicationMenuAction extends SimpleCommand {

private final PushToApplication application;
private final PushToApplicationsManager manager;

public PushToApplicationMenuAction(PushToApplication pushToApplication, PushToApplicationsManager manager) {
this.application = pushToApplication;
this.manager = manager;
}

public Action getActionInformation() {
return new Action() {

@Override
public Optional<JabRefIcon> getIcon() {
return Optional.of(application.getIcon());
}

@Override
public Optional<KeyBinding> getKeyBinding() {
return Optional.empty();
}

@Override
public String getText() {
return application.getApplicationName();
}

@Override
public String getDescription() {
return "";
}
};
}

@Override
public void execute() {
final ActionFactory factory = new ActionFactory(Globals.getKeyPrefs());
final PushToApplicationAction pushToApplicationAction = manager.getPushToApplicationAction();
final MenuItem menuItem = manager.getMenuItem();
final Button toolBarButton = manager.getToolBarButton();

Globals.prefs.put(JabRefPreferences.PUSH_TO_APPLICATION, application.getApplicationName());
pushToApplicationAction.updateApplication(application);

if (menuItem != null) {
factory.configureMenuItem(
pushToApplicationAction.getActionInformation(),
pushToApplicationAction,
menuItem);
}

if (toolBarButton != null) {
factory.configureIconButton(
pushToApplicationAction.getActionInformation(),
pushToApplicationAction,
toolBarButton);
}
}
}
Loading