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

Bring back the context menu #3666

Merged
merged 4 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all 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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ dependencies {
compile 'de.codecentric.centerdevice:javafxsvg:1.2.1'
compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22-4'
compile 'de.saxsys:mvvmfx-validation:1.7.0'
compile 'de.saxsys:mvvmfx:1.7.0'
compile 'org.fxmisc.easybind:easybind:1.0.3'
compile 'org.fxmisc.flowless:flowless:0.6'
compile 'org.fxmisc.richtext:richtextfx:0.8.1'
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public class BasePanel extends StackPane implements ClipboardOwner {
private final List<BibEntry> previousEntries = new ArrayList<>();
private final List<BibEntry> nextEntries = new ArrayList<>();
// Keeps track of the string dialog if it is open.
private final Map<String, Object> actions = new HashMap<>();
private final Map<Actions, Object> actions = new HashMap<>();
private final SidePaneManager sidePaneManager;
private final PreviewPanel preview;
private final BasePanelPreferences preferences;
Expand Down Expand Up @@ -395,7 +395,7 @@ private void setupActions() {
}
});

actions.put(FindUnlinkedFilesDialog.ACTION_COMMAND, (BaseAction) () -> {
actions.put(Actions.findUnlinkedFiles, (BaseAction) () -> {
final FindUnlinkedFilesDialog dialog = new FindUnlinkedFilesDialog(frame, frame, BasePanel.this);
dialog.setLocationRelativeTo(frame);
dialog.setVisible(true);
Expand Down Expand Up @@ -637,26 +637,26 @@ public void update() {
});

// Note that we can't put the number of entries that have been reverted into the undoText as the concrete number cannot be injected
actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getActionName(),
actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.RELEVANCE).getSpecialFieldAction(
SpecialField.RELEVANCE.getValues().get(0), frame));
actions.put(new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getActionName(),
actions.put(new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.QUALITY)
.getSpecialFieldAction(SpecialField.QUALITY.getValues().get(0), frame));
actions.put(new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getActionName(),
actions.put(new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.PRINTED).getSpecialFieldAction(
SpecialField.PRINTED.getValues().get(0), frame));

for (SpecialFieldValue prio : SpecialField.PRIORITY.getValues()) {
actions.put(new SpecialFieldValueViewModel(prio).getActionName(),
actions.put(new SpecialFieldValueViewModel(prio).getCommand(),
new SpecialFieldViewModel(SpecialField.PRIORITY).getSpecialFieldAction(prio, this.frame));
}
for (SpecialFieldValue rank : SpecialField.RANKING.getValues()) {
actions.put(new SpecialFieldValueViewModel(rank).getActionName(),
actions.put(new SpecialFieldValueViewModel(rank).getCommand(),
new SpecialFieldViewModel(SpecialField.RANKING).getSpecialFieldAction(rank, this.frame));
}
for (SpecialFieldValue status : SpecialField.READ_STATUS.getValues()) {
actions.put(new SpecialFieldValueViewModel(status).getActionName(),
actions.put(new SpecialFieldValueViewModel(status).getCommand(),
new SpecialFieldViewModel(SpecialField.READ_STATUS).getSpecialFieldAction(status, this.frame));
}

Expand Down Expand Up @@ -998,15 +998,15 @@ private void openExternalFile() {
* This method is called from JabRefFrame if a database specific action is requested by the user. Runs the command
* if it is defined, or prints an error message to the standard error stream.
*
* @param _command The name of the command to run.
* @param command The name of the command to run.
*/
public void runCommand(final String _command) {
if (!actions.containsKey(_command)) {
LOGGER.info("No action defined for '" + _command + '\'');
public void runCommand(final Actions command) {
if (!actions.containsKey(command)) {
LOGGER.info("No action defined for '" + command + '\'');
return;
}

Object o = actions.get(_command);
Object o = actions.get(command);
try {
if (o instanceof BaseAction) {
((BaseAction) o).action();
Expand Down Expand Up @@ -1211,7 +1211,7 @@ public void updateTableFont() {
private void createMainTable() {
bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance());

mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase(), preferences.getTablePreferences(), externalFileTypes);
mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase(), preferences.getTablePreferences(), externalFileTypes, Globals.getKeyPrefs());

mainTable.updateFont();

Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public class FindUnlinkedFilesDialog extends JabRefDialog {
/**
* Keys to be used for referencing this Action.
*/
public static final String ACTION_COMMAND = "findUnlinkedFiles";
public static final String ACTION_MENU_TITLE = Localization.menuTitle("Find unlinked files...");

public static final String ACTION_SHORT_DESCRIPTION = Localization
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
import org.jabref.gui.journals.ManageJournalsAction;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.keyboard.KeyBindingAction;
import org.jabref.gui.maintable.RightClickMenu;
import org.jabref.gui.menus.ChangeEntryTypeMenu;
import org.jabref.gui.menus.FileHistoryMenu;
import org.jabref.gui.openoffice.OpenOfficePanel;
Expand Down Expand Up @@ -274,17 +273,17 @@ public class JabRefFrame extends JFrame implements OutputPrinter {
Globals.getKeyPrefs().getKey(KeyBinding.UNMARK_ENTRIES), IconTheme.JabRefIcons.UNMARK_ENTRIES.getIcon());
private final AbstractAction unmarkAll = new GeneralAction(Actions.UNMARK_ALL, Localization.menuTitle("Unmark all"));
private final AbstractAction toggleRelevance = new GeneralAction(
new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getActionName(),
new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(),
new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getMenuString(),
new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getToolTipText(),
IconTheme.JabRefIcons.RELEVANCE.getIcon());
private final AbstractAction toggleQualityAssured = new GeneralAction(
new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getActionName(),
new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getCommand(),
new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getMenuString(),
new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getToolTipText(),
IconTheme.JabRefIcons.QUALITY_ASSURED.getIcon());
private final AbstractAction togglePrinted = new GeneralAction(
new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getActionName(),
new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getCommand(),
new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getMenuString(),
new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getToolTipText(),
IconTheme.JabRefIcons.PRINTED.getIcon());
Expand Down Expand Up @@ -427,7 +426,7 @@ public void actionPerformed(ActionEvent e) {
private final ManageKeywordsAction manageKeywords = new ManageKeywordsAction(this);
private final JMenu lookupIdentifiers = JabRefFrame.subMenu(Localization.menuTitle("Look up document identifier..."));
private final GeneralAction findUnlinkedFiles = new GeneralAction(
FindUnlinkedFilesDialog.ACTION_COMMAND,
Actions.findUnlinkedFiles,
FindUnlinkedFilesDialog.ACTION_MENU_TITLE, FindUnlinkedFilesDialog.ACTION_SHORT_DESCRIPTION,
Globals.getKeyPrefs().getKey(KeyBinding.FIND_UNLINKED_FILES)
);
Expand Down Expand Up @@ -1131,7 +1130,7 @@ private void fillMenu() {
boolean menuitem = false;
if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) {
rankSubMenu = new JMenu();
RightClickMenu.populateSpecialFieldMenu(rankSubMenu, SpecialField.RANKING, this);
// TODO RightClickMenu.createSpecialFieldMenu(rankSubMenu, SpecialField.RANKING, this);
edit.add(rankSubMenu);
menuitem = true;
}
Expand All @@ -1145,7 +1144,7 @@ private void fillMenu() {
}
if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) {
rankSubMenu = new JMenu();
RightClickMenu.populateSpecialFieldMenu(rankSubMenu, SpecialField.PRIORITY, this);
// TODO RightClickMenu.createSpecialFieldMenu(rankSubMenu, SpecialField.PRIORITY, this);
edit.add(rankSubMenu);
menuitem = true;
}
Expand All @@ -1155,7 +1154,7 @@ private void fillMenu() {
}
if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) {
rankSubMenu = new JMenu();
RightClickMenu.populateSpecialFieldMenu(rankSubMenu, SpecialField.READ_STATUS, this);
// TODO RightClickMenu.createSpecialFieldMenu(rankSubMenu, SpecialField.READ_STATUS, this);
edit.add(rankSubMenu);
menuitem = true;
}
Expand Down Expand Up @@ -2033,48 +2032,48 @@ public void actionPerformed(ActionEvent evt) {

private class GeneralAction extends MnemonicAwareAction {

private final String command;
private final Actions command;

public GeneralAction(String command, String text) {
public GeneralAction(Actions command, String text) {
this.command = command;
putValue(Action.NAME, text);
}

public GeneralAction(String command, String text, String description) {
public GeneralAction(Actions command, String text, String description) {
this.command = command;
putValue(Action.NAME, text);
putValue(Action.SHORT_DESCRIPTION, description);
}

public GeneralAction(String command, String text, Icon icon) {
public GeneralAction(Actions command, String text, Icon icon) {
super(icon);

this.command = command;
putValue(Action.NAME, text);
}

public GeneralAction(String command, String text, String description, Icon icon) {
public GeneralAction(Actions command, String text, String description, Icon icon) {
super(icon);

this.command = command;
putValue(Action.NAME, text);
putValue(Action.SHORT_DESCRIPTION, description);
}

public GeneralAction(String command, String text, KeyStroke key) {
public GeneralAction(Actions command, String text, KeyStroke key) {
this.command = command;
putValue(Action.NAME, text);
putValue(Action.ACCELERATOR_KEY, key);
}

public GeneralAction(String command, String text, String description, KeyStroke key) {
public GeneralAction(Actions command, String text, String description, KeyStroke key) {
this.command = command;
putValue(Action.NAME, text);
putValue(Action.SHORT_DESCRIPTION, description);
putValue(Action.ACCELERATOR_KEY, key);
}

public GeneralAction(String command, String text, String description, KeyStroke key, Icon icon) {
public GeneralAction(Actions command, String text, String description, KeyStroke key, Icon icon) {
super(icon);

this.command = command;
Expand Down Expand Up @@ -2158,9 +2157,9 @@ public void actionPerformed(ActionEvent e) {
*/
private class EditAction extends MnemonicAwareAction {

private final String command;
private final Actions command;

public EditAction(String command, String menuTitle, String description, KeyStroke key, Icon icon) {
public EditAction(Actions command, String menuTitle, String description, KeyStroke key, Icon icon) {
super(icon);
this.command = command;
putValue(Action.NAME, menuTitle);
Expand All @@ -2174,7 +2173,7 @@ public EditAction(String command, String menuTitle, String description, KeyStrok
JComponent source = Globals.getFocusListener().getFocused();
Action action = source.getActionMap().get(command);
if (action != null) {
action.actionPerformed(new ActionEvent(source, 0, command));
action.actionPerformed(new ActionEvent(source, 0, command.name()));
}
}
}
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/org/jabref/gui/actions/ActionFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.jabref.gui.actions;

import java.util.Objects;

import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;

import org.jabref.gui.keyboard.KeyBindingRepository;

import de.saxsys.mvvmfx.utils.commands.Command;
import org.controlsfx.control.action.ActionUtils;

/**
* Helper class to create and style controls according to an {@link ActionsFX}.
*/
public class ActionFactory {

private KeyBindingRepository keyBindingRepository;

public ActionFactory(KeyBindingRepository keyBindingRepository) {
this.keyBindingRepository = Objects.requireNonNull(keyBindingRepository);
}

public MenuItem configureMenuItem(ActionsFX action, Command command, MenuItem menuItem) {
return ActionUtils.configureMenuItem(new JabRefAction(action, command, keyBindingRepository), menuItem);
}

public MenuItem createMenuItem(ActionsFX action, Command command) {
MenuItem menuItem = ActionUtils.createMenuItem(new JabRefAction(action, command, keyBindingRepository));

// For some reason the graphic is not set correctly, so let's fix this
menuItem.graphicProperty().unbind();
action.getIcon().ifPresent(icon -> menuItem.setGraphic(icon.getGraphicNode()));
return menuItem;
}

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

// For some reason the graphic is not set correctly, so let's fix this
menu.graphicProperty().unbind();
action.getIcon().ifPresent(icon -> menu.setGraphic(icon.getGraphicNode()));
return menu;
}
}
Loading