From 9f287542abd714ae25d30e727e1dc2e4a040b5bc Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Thu, 6 Oct 2016 14:08:57 +0200 Subject: [PATCH 1/4] add shortcuts to context menu --- .../sf/jabref/gui/menus/RightClickMenu.java | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) 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..13296aaf0af 100644 --- a/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java +++ b/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java @@ -7,6 +7,7 @@ import java.util.Optional; import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.Icon; import javax.swing.JCheckBoxMenuItem; import javax.swing.JLabel; @@ -23,6 +24,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; @@ -67,20 +69,18 @@ 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.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)); add(new GeneralAction(Actions.PRINT_PREVIEW, Localization.lang("Print entry preview"), IconTheme.JabRefIcon.PRINTED.getSmallIcon()) { { if (multiple) { @@ -94,23 +94,24 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { 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,7 +151,7 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { addSeparator(); - add(new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder")) { + add(new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder"), KeyBinding.OPEN_FOLDER) { { if (!isFieldSetForSelectedEntry(FieldName.FILE)) { this.setEnabled(false); @@ -158,7 +159,7 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { } }); - add(new GeneralAction(Actions.OPEN_EXTERNAL_FILE, Localization.lang("Open file"), getFileIconForSelectedEntry()) { + add(new GeneralAction(Actions.OPEN_EXTERNAL_FILE, Localization.lang("Open file"), getFileIconForSelectedEntry(), KeyBinding.OPEN_FILE) { { if (!isFieldSetForSelectedEntry(FieldName.FILE)) { this.setEnabled(false); @@ -166,7 +167,7 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { } }); - add(new GeneralAction(Actions.OPEN_URL, Localization.lang("Open URL or DOI"), IconTheme.JabRefIcon.WWW.getSmallIcon()) { + add(new GeneralAction(Actions.OPEN_URL, Localization.lang("Open URL or DOI"), IconTheme.JabRefIcon.WWW.getSmallIcon(), KeyBinding.OPEN_URL_OR_DOI) { { if(!(isFieldSetForSelectedEntry(FieldName.URL) || isFieldSetForSelectedEntry(FieldName.DOI))) { this.setEnabled(false); @@ -308,6 +309,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 { From cfe11b2de78019d4d8338fd149ef606c9dc9d3b5 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Thu, 6 Oct 2016 14:58:22 +0200 Subject: [PATCH 2/4] refactor action construction --- .../sf/jabref/gui/menus/RightClickMenu.java | 101 +++++++----------- 1 file changed, 36 insertions(+), 65 deletions(-) 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 13296aaf0af..9d3c98a89f5 100644 --- a/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java +++ b/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java @@ -9,7 +9,6 @@ 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; @@ -50,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) { @@ -81,13 +78,10 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { 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)); - add(new GeneralAction(Actions.PRINT_PREVIEW, Localization.lang("Print entry preview"), IconTheme.JabRefIcon.PRINTED.getSmallIcon()) { - { - if (multiple) { - this.setEnabled(false); - } - } - }); + 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())); @@ -151,62 +145,43 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { addSeparator(); - add(new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder"), KeyBinding.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(), KeyBinding.OPEN_FILE) { - { - 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(), KeyBinding.OPEN_URL_OR_DOI) { - { - 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) @@ -248,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); } From 3eddb772a5a197cae2522f634c3e937cf42e7cb1 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Thu, 6 Oct 2016 15:02:57 +0200 Subject: [PATCH 3/4] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From 57075b52127721dc6556915b4812184cd5923d4a Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Tue, 11 Oct 2016 13:26:36 +0200 Subject: [PATCH 4/4] fix slip --- src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9d3c98a89f5..be474171ecd 100644 --- a/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java +++ b/src/main/java/net/sf/jabref/gui/menus/RightClickMenu.java @@ -79,7 +79,7 @@ public RightClickMenu(JabRefFrame frame, BasePanel panel) { 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); + printPreviewAction.setEnabled(!multiple); add(printPreviewAction); addSeparator();