Skip to content

Commit bca3a0b

Browse files
committed
Refactored ActionHelper, removed some deprecated Actions and minor corrections
1 parent f922be3 commit bca3a0b

10 files changed

+36
-91
lines changed

src/main/java/org/jabref/gui/BasePanel.java

-40
Original file line numberDiff line numberDiff line change
@@ -260,42 +260,13 @@ private void setupActions() {
260260
// The action for cleaning up entry.
261261
actions.put(Actions.CLEANUP, cleanUpAction);
262262

263-
// actions.put(Actions.MERGE_ENTRIES, () -> new MergeEntriesAction(frame, Globals.stateManager).execute());
264-
265-
// The action for copying the selected entry's key.
266-
// actions.put(Actions.COPY_KEY, this::copyKey);
267-
268-
// The action for copying the selected entry's title.
269-
// actions.put(Actions.COPY_TITLE, this::copyTitle);
270-
271-
// The action for copying a cite for the selected entry.
272-
// actions.put(Actions.COPY_CITE_KEY, this::copyCiteKey);
273-
274-
// The action for copying the BibTeX key and the title for the first selected entry
275-
// actions.put(Actions.COPY_KEY_AND_TITLE, this::copyKeyAndTitle);
276-
277-
/*
278-
actions.put(Actions.COPY_CITATION_ASCII_DOC, () -> copyCitationToClipboard(CitationStyleOutputFormat.ASCII_DOC));
279-
actions.put(Actions.COPY_CITATION_XSLFO, () -> copyCitationToClipboard(CitationStyleOutputFormat.XSL_FO));
280-
actions.put(Actions.COPY_CITATION_HTML, () -> copyCitationToClipboard(CitationStyleOutputFormat.HTML));
281-
actions.put(Actions.COPY_CITATION_RTF, () -> copyCitationToClipboard(CitationStyleOutputFormat.RTF));
282-
actions.put(Actions.COPY_CITATION_TEXT, () -> copyCitationToClipboard(CitationStyleOutputFormat.TEXT));
283-
*/
284-
285-
// The action for copying the BibTeX keys as hyperlinks to the urls of the selected entries
286-
// actions.put(Actions.COPY_KEY_AND_LINK, new CopyBibTeXKeyAndLinkAction(mainTable, Globals.clipboardManager));
287-
288263
actions.put(Actions.MERGE_DATABASE, new AppendDatabaseAction(frame, this));
289264

290265
actions.put(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, () -> {
291266
DatabaseSynchronizer dbmsSynchronizer = frame.getCurrentBasePanel().getBibDatabaseContext().getDBMSSynchronizer();
292267
dbmsSynchronizer.pullChanges();
293268
});
294269

295-
// actions.put(Actions.OPEN_URL, new OpenURLAction());
296-
297-
// actions.put(Actions.MERGE_WITH_FETCHED_ENTRY, new MergeWithFetchedEntryAction(this, frame.getDialogService()));
298-
299270
actions.put(Actions.REPLACE_ALL, () -> (new ReplaceStringAction(this)).execute());
300271

301272
actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(),
@@ -320,17 +291,6 @@ private void setupActions() {
320291
new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame));
321292
}
322293

323-
/* actions.put(Actions.NEXT_PREVIEW_STYLE, () -> {
324-
entryEditor.nextPreviewStyle();
325-
});
326-
actions.put(Actions.PREVIOUS_PREVIEW_STYLE, () -> {
327-
entryEditor.previousPreviewStyle();
328-
}); */
329-
330-
// actions.put(Actions.SEND_AS_EMAIL, new SendAsEMailAction(frame));
331-
332-
// actions.put(Actions.WRITE_XMP, new WriteXMPAction(this)::execute);
333-
334294
actions.put(Actions.ABBREVIATE_DEFAULT, new AbbreviateAction(this, AbbreviationType.DEFAULT));
335295
actions.put(Actions.ABBREVIATE_MEDLINE, new AbbreviateAction(this, AbbreviationType.MEDLINE));
336296
actions.put(Actions.ABBREVIATE_SHORTEST_UNIQUE, new AbbreviateAction(this, AbbreviationType.SHORTEST_UNIQUE));

src/main/java/org/jabref/gui/JabRefFrame.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.jabref.gui.dialogs.AutosaveUIManager;
6161
import org.jabref.gui.documentviewer.ShowDocumentViewerAction;
6262
import org.jabref.gui.duplicationFinder.DuplicateSearch;
63+
import org.jabref.gui.edit.CopyMoreAction;
6364
import org.jabref.gui.edit.ManageKeywordsAction;
6465
import org.jabref.gui.edit.MassSetFieldsAction;
6566
import org.jabref.gui.edit.OpenBrowserAction;
@@ -703,11 +704,11 @@ private MenuBar createMenu() {
703704

704705
factory.createMenuItem(StandardActions.COPY, new EditAction(Actions.COPY)),
705706
factory.createSubMenu(StandardActions.COPY_MORE,
706-
factory.createMenuItem(StandardActions.COPY_TITLE, new OldDatabaseCommandWrapper(Actions.COPY_TITLE, this, stateManager)),
707-
factory.createMenuItem(StandardActions.COPY_KEY, new OldDatabaseCommandWrapper(Actions.COPY_KEY, this, stateManager)),
708-
factory.createMenuItem(StandardActions.COPY_CITE_KEY, new OldDatabaseCommandWrapper(Actions.COPY_CITE_KEY, this, stateManager)),
709-
factory.createMenuItem(StandardActions.COPY_KEY_AND_TITLE, new OldDatabaseCommandWrapper(Actions.COPY_KEY_AND_TITLE, this, stateManager)),
710-
factory.createMenuItem(StandardActions.COPY_KEY_AND_LINK, new OldDatabaseCommandWrapper(Actions.COPY_KEY_AND_LINK, this, stateManager)),
707+
factory.createMenuItem(StandardActions.COPY_TITLE, new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, Globals.clipboardManager, prefs)),
708+
factory.createMenuItem(StandardActions.COPY_KEY, new CopyMoreAction(StandardActions.COPY_KEY, dialogService, stateManager, Globals.clipboardManager, prefs)),
709+
factory.createMenuItem(StandardActions.COPY_CITE_KEY, new CopyMoreAction(StandardActions.COPY_CITE_KEY, dialogService, stateManager, Globals.clipboardManager, prefs)),
710+
factory.createMenuItem(StandardActions.COPY_KEY_AND_TITLE, new CopyMoreAction(StandardActions.COPY_KEY_AND_TITLE, dialogService, stateManager, Globals.clipboardManager, prefs)),
711+
factory.createMenuItem(StandardActions.COPY_KEY_AND_LINK, new CopyMoreAction(StandardActions.COPY_KEY_AND_LINK, dialogService, stateManager, Globals.clipboardManager, prefs)),
711712
factory.createMenuItem(StandardActions.COPY_CITATION_PREVIEW, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, Globals.clipboardManager, prefs.getPreviewPreferences())),
712713
factory.createMenuItem(StandardActions.EXPORT_SELECTED_TO_CLIPBOARD, new ExportToClipboardAction(this, dialogService))),
713714

@@ -752,7 +753,7 @@ private MenuBar createMenu() {
752753

753754
quality.getItems().addAll(
754755
factory.createMenuItem(StandardActions.FIND_DUPLICATES, new DuplicateSearch(this, dialogService, stateManager)),
755-
factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(this.getCurrentBasePanel(), dialogService, stateManager)),
756+
factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager)),
756757
factory.createMenuItem(StandardActions.CHECK_INTEGRITY, new IntegrityCheckAction(this, stateManager, Globals.TASK_EXECUTOR)),
757758
factory.createMenuItem(StandardActions.CLEANUP_ENTRIES, new OldDatabaseCommandWrapper(Actions.CLEANUP, this, stateManager)),
758759

src/main/java/org/jabref/gui/OpenConsoleAction.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.jabref.gui.actions.SimpleCommand;
77
import org.jabref.gui.desktop.JabRefDesktop;
88
import org.jabref.model.database.BibDatabaseContext;
9-
import org.jabref.model.entry.field.StandardField;
109

1110
import org.slf4j.Logger;
1211
import org.slf4j.LoggerFactory;
@@ -19,7 +18,7 @@ public class OpenConsoleAction extends SimpleCommand {
1918
public OpenConsoleAction(StateManager stateManager) {
2019
this.stateManager = stateManager;
2120

22-
this.executable.bind(ActionHelper.isFieldSetForSelectedEntry(StandardField.FILE, stateManager));
21+
this.executable.bind(ActionHelper.needsDatabase(stateManager));
2322
}
2423

2524
@Override

src/main/java/org/jabref/gui/actions/ActionHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static BooleanExpression isFieldSetForSelectedEntry(Field field, StateMan
3232
public static BooleanExpression isAnyFieldSetForSelectedEntry(List<Field> fields, StateManager stateManager) {
3333
BibEntry entry = stateManager.getSelectedEntries().get(0);
3434
return Bindings.createBooleanBinding(
35-
() -> !Collections.disjoint(fields, entry.getFields()),
35+
() -> entry.getFields().stream().anyMatch(fields::contains),
3636
entry.getFieldsObservable(),
3737
stateManager.getSelectedEntries());
3838
}

src/main/java/org/jabref/gui/actions/Actions.java

-20
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ public enum Actions {
1111
ADD_FILE_LINK,
1212
CLEANUP,
1313
COPY,
14-
COPY_CITATION_ASCII_DOC,
15-
COPY_CITATION_XSLFO,
16-
COPY_CITATION_HTML,
17-
COPY_CITATION_RTF,
18-
COPY_CITATION_TEXT,
19-
COPY_KEY,
20-
COPY_CITE_KEY,
21-
COPY_KEY_AND_TITLE,
22-
COPY_KEY_AND_LINK,
23-
COPY_TITLE,
2414
CUT,
2515
DELETE,
2616
DOWNLOAD_FULL_TEXT,
@@ -31,27 +21,17 @@ public enum Actions {
3121
MAKE_KEY,
3222
MANAGE_SELECTORS,
3323
MERGE_DATABASE,
34-
MERGE_ENTRIES,
35-
MERGE_WITH_FETCHED_ENTRY,
36-
NEXT_PREVIEW_STYLE,
37-
OPEN_CONSOLE,
38-
OPEN_EXTERNAL_FILE,
39-
OPEN_FOLDER,
40-
OPEN_URL,
4124
PASTE,
42-
PREVIOUS_PREVIEW_STYLE,
4325
PULL_CHANGES_FROM_SHARED_DATABASE,
4426
REDO,
4527
REPLACE_ALL,
4628
SAVE,
4729
SAVE_AS,
4830
SAVE_SELECTED_AS_PLAIN,
4931
SELECT_ALL,
50-
SEND_AS_EMAIL,
5132
TOGGLE_GROUPS,
5233
UNABBREVIATE,
5334
UNDO,
54-
WRITE_XMP,
5535
PRINT_PREVIEW,
5636
TOGGLE_PRINTED,
5737
CLEAR_PRIORITY,

src/main/java/org/jabref/gui/edit/CopyMoreAction.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
public class CopyMoreAction extends SimpleCommand {
3030

3131
private static final Logger LOGGER = LoggerFactory.getLogger(CopyMoreAction.class);
32-
private StandardActions action;
33-
private DialogService dialogService;
34-
private StateManager stateManager;
32+
private final StandardActions action;
33+
private final DialogService dialogService;
34+
private final StateManager stateManager;
3535
private final ClipBoardManager clipBoardManager;
36-
private PreferencesService preferencesService;
36+
private final PreferencesService preferencesService;
3737

3838
public CopyMoreAction(StandardActions action, DialogService dialogService, StateManager stateManager, ClipBoardManager clipBoardManager, PreferencesService preferencesService) {
3939
this.action = action;

src/main/java/org/jabref/gui/maintable/OpenUrlAction.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.List;
55
import java.util.Optional;
66

7-
import javafx.beans.binding.BooleanBinding;
7+
import javafx.beans.binding.BooleanExpression;
88

99
import org.jabref.gui.DialogService;
1010
import org.jabref.gui.StateManager;
@@ -25,10 +25,9 @@ public OpenUrlAction(DialogService dialogService, StateManager stateManager) {
2525
this.dialogService = dialogService;
2626
this.stateManager = stateManager;
2727

28-
BooleanBinding fieldIsSet = ActionHelper.isFieldSetForSelectedEntry(StandardField.URL, stateManager)
29-
.or(ActionHelper.isFieldSetForSelectedEntry(StandardField.DOI, stateManager)
30-
.or(ActionHelper.isFieldSetForSelectedEntry(StandardField.URI, stateManager)
31-
.or(ActionHelper.isFieldSetForSelectedEntry(StandardField.EPRINT, stateManager))));
28+
BooleanExpression fieldIsSet = ActionHelper.isAnyFieldSetForSelectedEntry(
29+
List.of(StandardField.URL, StandardField.DOI, StandardField.URI, StandardField.EPRINT),
30+
stateManager);
3231
this.executable.bind(ActionHelper.needsEntriesSelected(1, stateManager).and(fieldIsSet));
3332
}
3433

src/main/java/org/jabref/gui/maintable/RightClickMenu.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static ContextMenu create(BibEntryTableViewModel entry, KeyBindingReposit
6868
contextMenu.getItems().add(new ChangeEntryTypeMenu().getChangeEntryTypeMenu(entry.getEntry(), panel.getBibDatabaseContext(), panel.getUndoManager()));
6969
contextMenu.getItems().add(factory.createMenuItem(StandardActions.MERGE_WITH_FETCHED_ENTRY, new MergeWithFetchedEntryAction(panel, dialogService, stateManager)));
7070
contextMenu.getItems().add(factory.createMenuItem(StandardActions.ATTACH_FILE, new AttachFileAction(panel, dialogService, stateManager, preferencesService)));
71-
contextMenu.getItems().add(factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(panel, dialogService, stateManager)));
71+
contextMenu.getItems().add(factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager)));
7272

7373
return contextMenu;
7474
}

src/main/java/org/jabref/gui/mergeentries/MergeEntriesAction.java

+17-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.List;
55
import java.util.Optional;
66

7-
import org.jabref.gui.BasePanel;
7+
import org.jabref.Globals;
88
import org.jabref.gui.DialogService;
99
import org.jabref.gui.StateManager;
1010
import org.jabref.gui.actions.ActionHelper;
@@ -13,31 +13,35 @@
1313
import org.jabref.gui.undo.UndoableInsertEntries;
1414
import org.jabref.gui.undo.UndoableRemoveEntries;
1515
import org.jabref.logic.l10n.Localization;
16+
import org.jabref.model.database.BibDatabaseContext;
1617
import org.jabref.model.entry.BibEntry;
1718

1819
public class MergeEntriesAction extends SimpleCommand {
1920

20-
private final BasePanel basePanel;
2121
private final DialogService dialogService;
22+
private final StateManager stateManager;
2223

23-
public MergeEntriesAction(BasePanel panel, DialogService dialogService, StateManager stateManager) {
24-
this.basePanel = panel;
24+
public MergeEntriesAction(DialogService dialogService, StateManager stateManager) {
2525
this.dialogService = dialogService;
26+
this.stateManager = stateManager;
2627

2728
this.executable.bind(ActionHelper.needsEntriesSelected(2, stateManager));
2829
}
2930

3031
@Override
3132
public void execute() {
33+
if (stateManager.getActiveDatabase().isEmpty()) {
34+
return;
35+
}
36+
BibDatabaseContext databaseContext = stateManager.getActiveDatabase().get();
3237

3338
// Check if there are two entries selected
34-
List<BibEntry> selectedEntries = basePanel.getSelectedEntries();
39+
List<BibEntry> selectedEntries = stateManager.getSelectedEntries();
3540
if (selectedEntries.size() != 2) {
3641
// Inform the user to select entries first.
3742
dialogService.showInformationDialogAndWait(
3843
Localization.lang("Merge entries"),
3944
Localization.lang("You have to choose exactly two entries to merge."));
40-
4145
return;
4246
}
4347

@@ -49,17 +53,19 @@ public void execute() {
4953
dlg.setTitle(Localization.lang("Merge entries"));
5054
Optional<BibEntry> mergedEntry = dlg.showAndWait();
5155
if (mergedEntry.isPresent()) {
52-
basePanel.insertEntry(mergedEntry.get());
56+
// FixMe: BibDatabase::insertEntry does not contain logic to mark the BasePanel as changed and to mark
57+
// entries with a timestamp, only BasePanel::insertEntry does.
58+
databaseContext.getDatabase().insertEntry(mergedEntry.get());
5359

5460
// Create a new entry and add it to the undo stack
5561
// Remove the other two entries and add them to the undo stack (which is not working...)
5662
NamedCompound ce = new NamedCompound(Localization.lang("Merge entries"));
57-
ce.addEdit(new UndoableInsertEntries(basePanel.getDatabase(), mergedEntry.get()));
63+
ce.addEdit(new UndoableInsertEntries(databaseContext.getDatabase(), mergedEntry.get()));
5864
List<BibEntry> entriesToRemove = Arrays.asList(one, two);
59-
ce.addEdit(new UndoableRemoveEntries(basePanel.getDatabase(), entriesToRemove));
60-
basePanel.getDatabase().removeEntries(entriesToRemove);
65+
ce.addEdit(new UndoableRemoveEntries(databaseContext.getDatabase(), entriesToRemove));
66+
databaseContext.getDatabase().removeEntries(entriesToRemove);
6167
ce.end();
62-
basePanel.getUndoManager().addEdit(ce);
68+
Globals.undoManager.addEdit(ce); // ToDo: Rework UndoManager and extract Globals
6369

6470
dialogService.notify(Localization.lang("Merged entries"));
6571
} else {

src/main/java/org/jabref/gui/preview/CopyCitationAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class CopyCitationAction extends SimpleCommand {
3939
private static final Logger LOGGER = LoggerFactory.getLogger(CopyCitationAction.class);
4040

4141
private final List<BibEntry> selectedEntries;
42-
private StateManager stateManager;
42+
private final StateManager stateManager;
4343
private final PreviewLayout style;
4444
private final String previewStyle;
4545
private final CitationStyleOutputFormat outputFormat;

0 commit comments

Comments
 (0)