diff --git a/CHANGELOG.md b/CHANGELOG.md index 0661a825372..1ccee441d09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# ### Changed - Source tab in the entry editor displays "BibLaTeX Source" when using biblatex mode +- [koppor#171](https://github.com/koppor/jabref/issues/171): Add Shortcuts to context menu - Add session restoring functionality for shared database. Related to [#1703](https://github.com/JabRef/jabref/issues/1703) - Implementation of LiveUpdate for PostgreSQL & Oracle systems. Related to [#970](https://github.com/JabRef/jabref/issues/970). - [koppor#31](https://github.com/koppor/jabref/issues/31): Number column in the main table is always Left aligned diff --git a/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java b/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java index 0d396133873..be474171ecd 100644 --- a/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java +++ b/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java @@ -7,8 +7,8 @@ import java.util.Optional; import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.Icon; -import javax.swing.JCheckBoxMenuItem; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -23,6 +23,7 @@ import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.actions.Actions; import net.sf.jabref.gui.filelist.FileListTableModel; +import net.sf.jabref.gui.keyboard.KeyBinding; import net.sf.jabref.gui.mergeentries.FetchAndMergeEntry; import net.sf.jabref.gui.worker.MarkEntriesAction; import net.sf.jabref.logic.l10n.Localization; @@ -48,8 +49,6 @@ public class RightClickMenu extends JPopupMenu implements PopupMenuListener { private final JMenuItem groupAdd; private final JMenuItem groupRemove; private final JMenuItem groupMoveTo; - private final JCheckBoxMenuItem floatMarked = new JCheckBoxMenuItem(Localization.lang("Float marked entries"), - Globals.prefs.getBoolean(JabRefPreferences.FLOAT_MARKED_ENTRIES)); public RightClickMenu(JabRefFrame frame, BasePanel panel) { @@ -67,50 +66,46 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { addPopupMenuListener(this); JMenu copySpecialMenu = new JMenu(Localization.lang("Copy") + "..."); - copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY, Localization.lang("Copy BibTeX key"))); - copySpecialMenu.add(new GeneralAction(Actions.COPY_CITE_KEY, Localization.lang("Copy \\cite{BibTeX key}"))); - copySpecialMenu - .add(new GeneralAction(Actions.COPY_KEY_AND_TITLE, Localization.lang("Copy BibTeX key and title"))); - copySpecialMenu - .add(new GeneralAction(Actions.COPY_KEY_AND_LINK, Localization.lang("Copy BibTeX key and link"))); + copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY, Localization.lang("Copy BibTeX key"), KeyBinding.COPY_BIBTEX_KEY)); + copySpecialMenu.add(new GeneralAction(Actions.COPY_CITE_KEY, Localization.lang("Copy \\cite{BibTeX key}"), KeyBinding.COPY_CITE_BIBTEX_KEY)); + copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY_AND_TITLE, Localization.lang("Copy BibTeX key and title"), KeyBinding.COPY_BIBTEX_KEY_AND_TITLE)); + copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY_AND_LINK, Localization.lang("Copy BibTeX key and link"), KeyBinding.COPY_BIBTEX_KEY_AND_LINK)); copySpecialMenu.add(new GeneralAction(Actions.EXPORT_TO_CLIPBOARD, Localization.lang("Export to clipboard"), IconTheme.JabRefIcon.EXPORT_TO_CLIPBOARD.getSmallIcon())); - add(new GeneralAction(Actions.COPY, Localization.lang("Copy"), IconTheme.JabRefIcon.COPY.getSmallIcon())); + add(new GeneralAction(Actions.COPY, Localization.lang("Copy"), IconTheme.JabRefIcon.COPY.getSmallIcon(), KeyBinding.COPY)); add(copySpecialMenu); - add(new GeneralAction(Actions.PASTE, Localization.lang("Paste"), IconTheme.JabRefIcon.PASTE.getSmallIcon())); - add(new GeneralAction(Actions.CUT, Localization.lang("Cut"), IconTheme.JabRefIcon.CUT.getSmallIcon())); - add(new GeneralAction(Actions.DELETE, Localization.lang("Delete"), IconTheme.JabRefIcon.DELETE_ENTRY.getSmallIcon())); - add(new GeneralAction(Actions.PRINT_PREVIEW, Localization.lang("Print entry preview"), IconTheme.JabRefIcon.PRINTED.getSmallIcon()) { - { - if (multiple) { - this.setEnabled(false); - } - } - }); + add(new GeneralAction(Actions.PASTE, Localization.lang("Paste"), IconTheme.JabRefIcon.PASTE.getSmallIcon(), KeyBinding.PASTE)); + add(new GeneralAction(Actions.CUT, Localization.lang("Cut"), IconTheme.JabRefIcon.CUT.getSmallIcon(), KeyBinding.CUT)); + add(new GeneralAction(Actions.DELETE, Localization.lang("Delete"), IconTheme.JabRefIcon.DELETE_ENTRY.getSmallIcon(), KeyBinding.DELETE_ENTRY)); + GeneralAction printPreviewAction = new GeneralAction(Actions.PRINT_PREVIEW, Localization.lang("Print entry preview"), IconTheme.JabRefIcon.PRINTED.getSmallIcon()); + printPreviewAction.setEnabled(!multiple); + add(printPreviewAction); + addSeparator(); add(new GeneralAction(Actions.SEND_AS_EMAIL, Localization.lang("Send as email"), IconTheme.JabRefIcon.EMAIL.getSmallIcon())); addSeparator(); JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color")); + markSpecific.setIcon(IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon()); for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) { markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem()); } if (multiple) { - add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entries"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon())); + add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entries"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon(), KeyBinding.MARK_ENTRIES)); add(markSpecific); - add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entries"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon())); + add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entries"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon(), KeyBinding.UNMARK_ENTRIES)); } else if (be != null) { Optional marked = be.getField(FieldName.MARKED_INTERNAL); // We have to check for "" too as the marked field may be empty if ((!marked.isPresent()) || marked.get().isEmpty()) { - add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entry"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon())); + add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entry"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon(), KeyBinding.MARK_ENTRIES)); add(markSpecific); } else { add(markSpecific); - add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entry"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon())); + add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entry"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon(), KeyBinding.UNMARK_ENTRIES)); } } @@ -150,62 +145,43 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { addSeparator(); - add(new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder")) { - { - if (!isFieldSetForSelectedEntry(FieldName.FILE)) { - this.setEnabled(false); - } - } - }); + GeneralAction openFolderAction = new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder"), + KeyBinding.OPEN_FOLDER); + openFolderAction.setEnabled(isFieldSetForSelectedEntry(FieldName.FILE)); + add(openFolderAction); - add(new GeneralAction(Actions.OPEN_EXTERNAL_FILE, Localization.lang("Open file"), getFileIconForSelectedEntry()) { - { - if (!isFieldSetForSelectedEntry(FieldName.FILE)) { - this.setEnabled(false); - } - } - }); + GeneralAction openFileAction = new GeneralAction(Actions.OPEN_EXTERNAL_FILE, Localization.lang("Open file"), + getFileIconForSelectedEntry(), KeyBinding.OPEN_FILE); + openFileAction.setEnabled(isFieldSetForSelectedEntry(FieldName.FILE)); + add(openFileAction); - add(new GeneralAction(Actions.OPEN_URL, Localization.lang("Open URL or DOI"), IconTheme.JabRefIcon.WWW.getSmallIcon()) { - { - if(!(isFieldSetForSelectedEntry(FieldName.URL) || isFieldSetForSelectedEntry(FieldName.DOI))) { - this.setEnabled(false); - } - } - }); + GeneralAction openUrlAction = new GeneralAction(Actions.OPEN_URL, Localization.lang("Open URL or DOI"), + IconTheme.JabRefIcon.WWW.getSmallIcon(), KeyBinding.OPEN_URL_OR_DOI); + openUrlAction.setEnabled(isFieldSetForSelectedEntry(FieldName.URL) || isFieldSetForSelectedEntry(FieldName.DOI)); + add(openUrlAction); addSeparator(); add(typeMenu); - add(new GeneralAction(Actions.MERGE_WITH_FETCHED_ENTRY, - Localization.lang("Get BibTeX data from %0", FetchAndMergeEntry.getDisplayNameOfSupportedFields())) { - { - if (!(isAnyFieldSetForSelectedEntry(FetchAndMergeEntry.SUPPORTED_FIELDS))) { - this.setEnabled(false); - } - } - }); + GeneralAction mergeFetchedEntryAction = new GeneralAction(Actions.MERGE_WITH_FETCHED_ENTRY, + Localization.lang("Get BibTeX data from %0", FetchAndMergeEntry.getDisplayNameOfSupportedFields())); + mergeFetchedEntryAction.setEnabled(isAnyFieldSetForSelectedEntry(FetchAndMergeEntry.SUPPORTED_FIELDS)); + add(mergeFetchedEntryAction); + add(frame.getMassSetField()); - add(new GeneralAction(Actions.ADD_FILE_LINK, Localization.lang("Attach file"), IconTheme.JabRefIcon.ATTACH_FILE.getSmallIcon()) { - { - if (multiple) { - this.setEnabled(false); - } - } - }); - add(frame.getManageKeywords()); - add(new GeneralAction(Actions.MERGE_ENTRIES, - Localization.lang("Merge entries") + "...", - IconTheme.JabRefIcon.MERGE_ENTRIES.getSmallIcon()) { - { - if (!(areExactlyTwoEntriesSelected())) { - this.setEnabled(false); - } - } + GeneralAction attachFileAction = new GeneralAction(Actions.ADD_FILE_LINK, Localization.lang("Attach file"), + IconTheme.JabRefIcon.ATTACH_FILE.getSmallIcon()); + attachFileAction.setEnabled(!multiple); + add(attachFileAction); + + add(frame.getManageKeywords()); - }); + GeneralAction mergeEntriesAction = new GeneralAction(Actions.MERGE_ENTRIES, + Localization.lang("Merge entries") + "...", IconTheme.JabRefIcon.MERGE_ENTRIES.getSmallIcon()); + mergeEntriesAction.setEnabled(areExactlyTwoEntriesSelected()); + add(mergeEntriesAction); addSeparator(); // for "add/move/remove to/from group" entries (appended here) @@ -247,15 +223,11 @@ public static void populateSpecialFieldMenu(JMenu menu, SpecialField field, JabR @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { panel.storeCurrentEdit(); - if (panel.getBibDatabaseContext().getMetaData().getGroups().isPresent()) { - groupAdd.setEnabled(true); - groupRemove.setEnabled(true); - groupMoveTo.setEnabled(true); - } else { - groupAdd.setEnabled(false); - groupRemove.setEnabled(false); - groupMoveTo.setEnabled(false); - } + + boolean groupsPresent = panel.getBibDatabaseContext().getMetaData().getGroups().isPresent(); + groupAdd.setEnabled(groupsPresent); + groupRemove.setEnabled(groupsPresent); + groupMoveTo.setEnabled(groupsPresent); } @@ -308,6 +280,18 @@ public GeneralAction(String command, String name, Icon icon) { this.command = command; } + public GeneralAction(String command, String name, KeyBinding key) { + super(name); + this.command = command; + putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(key)); + } + + public GeneralAction(String command, String name, Icon icon, KeyBinding key) { + super(name, icon); + this.command = command; + putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(key)); + } + @Override public void actionPerformed(ActionEvent e) { try {