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 11 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
45 changes: 37 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,27 @@ 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());
final PushToApplicationAction pushToApplicationAction = pushToApplicationsManager.getPushToApplicationAction();
final MenuItem pushToApplicationMenuItem = factory.createMenuItem(pushToApplicationAction.getActionInformation(), pushToApplicationAction);
pushToApplicationsManager.setMenuItem(pushToApplicationMenuItem);

final Menu pushApplicationsMenu = factory.createSubMenu(StandardActions.SELECT_PUSH_APPLICATION);
final ToggleGroup pushToToggleGroup = new ToggleGroup();
RadioMenuItem pushToApplication;
calixtus marked this conversation as resolved.
Show resolved Hide resolved
PushToApplicationMenuAction pushToApplicationMenuAction;
final String activePushToApplication = Globals.prefs.get(JabRefPreferences.PUSH_TO_APPLICATION);

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

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

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 +804,8 @@ 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),
pushApplicationsMenu,
pushToApplicationMenuItem,

factory.createSubMenu(StandardActions.ABBREVIATE,
factory.createMenuItem(StandardActions.ABBREVIATE_ISO, new OldDatabaseCommandWrapper(Actions.ABBREVIATE_ISO, this, stateManager)),
Expand Down Expand Up @@ -1192,8 +1221,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
18 changes: 15 additions & 3 deletions src/main/java/org/jabref/gui/push/PushToApplicationAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,34 @@
*/
public class PushToApplicationAction extends SimpleCommand {

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

private Action action;

public PushToApplicationAction(StateManager stateManager, PushToApplicationsManager pushToApplicationsManager, DialogService dialogService) {
this.operation = pushToApplicationsManager.getLastUsedApplication(Globals.prefs);
this.operation = 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.operation = 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());
Expand Down
74 changes: 74 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,74 @@
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 PushToApplicationAction pushToApplicationAction;

private PushToApplicationsManager manager;

public PushToApplicationMenuAction(PushToApplication pushToApplication, PushToApplicationAction pushToApplicationAction, PushToApplicationsManager manager) {
this.application = pushToApplication;
this.pushToApplicationAction = pushToApplicationAction;
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() {
Globals.prefs.put(JabRefPreferences.PUSH_TO_APPLICATION, application.getApplicationName());
pushToApplicationAction.updateApplication(application);
ActionFactory factory = new ActionFactory(Globals.getKeyPrefs());

MenuItem menuItem = manager.getMenuItem();
Button toolBarButton = manager.getToolBarButton();

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

if (toolBarButton != null) {
factory.configureIconButton(pushToApplicationAction.getActionInformation(),pushToApplicationAction, toolBarButton);
}
}
}
34 changes: 32 additions & 2 deletions src/main/java/org/jabref/gui/push/PushToApplicationsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import java.util.ArrayList;
import java.util.List;

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

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.preferences.JabRefPreferences;

public class PushToApplicationsManager {
Expand All @@ -12,7 +16,11 @@ public class PushToApplicationsManager {

private final DialogService dialogService;

public PushToApplicationsManager(DialogService dialogService) {
private final PushToApplicationAction pushToApplicationAction;
private MenuItem menuItem;
private Button toolBarButton;

public PushToApplicationsManager(DialogService dialogService, StateManager stateManager) {
this.dialogService = dialogService;
// Set up the current available choices:
applications = new ArrayList<>();
Expand All @@ -22,12 +30,34 @@ public PushToApplicationsManager(DialogService dialogService) {
applications.add(new PushToTeXstudio(dialogService));
applications.add(new PushToVim(dialogService));
applications.add(new PushToWinEdt(dialogService));

this.pushToApplicationAction = new PushToApplicationAction(stateManager, this, dialogService);
}

public void setMenuItem(MenuItem menuItem) {
this.menuItem = menuItem;
}

public MenuItem getMenuItem() {
return menuItem;
}

public void setToolBarButton(Button pushToApplicationToolBarButton) {
this.toolBarButton = pushToApplicationToolBarButton;
}

public Button getToolBarButton() {
return toolBarButton;
}

public List<PushToApplication> getApplications() {
return applications;
}

public PushToApplicationAction getPushToApplicationAction() {
return pushToApplicationAction;
}

public PushToApplicationSettings getSettings(PushToApplication application) {
if (application instanceof PushToEmacs) {
return new PushToEmacsSettings(dialogService);
Expand All @@ -40,7 +70,7 @@ public PushToApplicationSettings getSettings(PushToApplication application) {
}
}

public PushToApplication getLastUsedApplication(JabRefPreferences preferences) {
public PushToApplication getActiveApplication(JabRefPreferences preferences) {
String appSelected = preferences.get(JabRefPreferences.PUSH_TO_APPLICATION);
return applications.stream()
.filter(application -> application.getApplicationName().equals(appSelected))
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,7 @@ Open\ %0\ file=Open %0 file

Cannot\ delete\ file=Cannot delete file
File\ permission\ error=File permission error
Select\ external\ application=Select external application
Push\ to\ %0=Push to %0
Path\ to\ %0=Path to %0
Convert=Convert
Expand Down