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

[WIP] Remove BaseAction from JabRefFrame #6056

Merged
merged 24 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f470d0e
Added UndoRedoAction
calixtus Feb 29, 2020
c216bb0
Refactored AppendDatabaseAction
calixtus Feb 29, 2020
cd6ea76
Refactored ReplaceStringAction and GenerateBibtexKeyAction
calixtus Mar 1, 2020
2245ae5
Refactored CleanupAction
calixtus Mar 1, 2020
2f4fa43
Merge remote-tracking branch 'upstream/master' into replace_baseactio…
calixtus Mar 1, 2020
6e8a2c8
Added OpenEntryEditorAction, fixed bug about selected entries without…
calixtus Mar 1, 2020
15c5c56
Refactored AbbreviateAction, merged UnabbreviateAction, removed unuse…
calixtus Mar 1, 2020
aa5f1d5
Refactored DownloadFullTextAction
calixtus Mar 1, 2020
eff5792
Added PullChangesFromSharedAction
calixtus Mar 1, 2020
cf73d38
Added SaveAction, removed remaining deprecated OldDatabaseCommandWrap…
calixtus Mar 3, 2020
2a15b80
Merge branch 'replace_deprecated' into replace_baseaction_frame
calixtus Mar 3, 2020
8b73ac3
Added UndoRedoAction
calixtus Feb 29, 2020
c6d3641
Refactored AppendDatabaseAction
calixtus Feb 29, 2020
cdd65a5
Refactored ReplaceStringAction and GenerateBibtexKeyAction
calixtus Mar 1, 2020
e328bd6
Refactored CleanupAction
calixtus Mar 1, 2020
c1685a7
Added OpenEntryEditorAction, fixed bug about selected entries without…
calixtus Mar 1, 2020
1b61ca3
Refactored AbbreviateAction, merged UnabbreviateAction, removed unuse…
calixtus Mar 1, 2020
4c30bfd
Refactored DownloadFullTextAction
calixtus Mar 1, 2020
fb54047
Added PullChangesFromSharedAction
calixtus Mar 1, 2020
70bc3c6
Added SaveAction, removed remaining deprecated OldDatabaseCommandWrap…
calixtus Mar 3, 2020
1cf1812
Merge branch 'replace_baseaction_frame' of https://github.com/calixtu…
calixtus Mar 3, 2020
5ee36f4
Removed test, added default case for codacy compliance
calixtus Mar 3, 2020
6d25ebe
Removed test for notifications
calixtus Mar 5, 2020
640b0a4
Merge remote-tracking branch 'upstream/master' into replace_baseactio…
calixtus Mar 6, 2020
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
131 changes: 4 additions & 127 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;

import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.geometry.Orientation;
Expand All @@ -20,25 +15,14 @@

import org.jabref.Globals;
import org.jabref.JabRefExecutorService;
import org.jabref.gui.actions.Actions;
import org.jabref.gui.actions.BaseAction;
import org.jabref.gui.autocompleter.AutoCompletePreferences;
import org.jabref.gui.autocompleter.AutoCompleteUpdater;
import org.jabref.gui.autocompleter.PersonNameSuggestionProvider;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.bibtexkeypattern.GenerateBibtexKeyAction;
import org.jabref.gui.cleanup.CleanupAction;
import org.jabref.gui.collab.DatabaseChangeMonitor;
import org.jabref.gui.collab.DatabaseChangePane;
import org.jabref.gui.edit.ReplaceStringAction;
import org.jabref.gui.entryeditor.EntryEditor;
import org.jabref.gui.exporter.SaveDatabaseAction;
import org.jabref.gui.externalfiles.DownloadFullTextAction;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.importer.actions.AppendDatabaseAction;
import org.jabref.gui.journals.AbbreviateAction;
import org.jabref.gui.journals.AbbreviationType;
import org.jabref.gui.journals.UnabbreviateAction;
import org.jabref.gui.maintable.MainTable;
import org.jabref.gui.maintable.MainTableDataModel;
import org.jabref.gui.specialfields.SpecialFieldDatabaseChangeListener;
Expand All @@ -62,7 +46,6 @@
import org.jabref.model.database.event.EntriesAddedEvent;
import org.jabref.model.database.event.EntriesRemovedEvent;
import org.jabref.model.database.shared.DatabaseLocation;
import org.jabref.model.database.shared.DatabaseSynchronizer;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.event.EntriesEventSource;
import org.jabref.model.entry.event.EntryChangedEvent;
Expand All @@ -88,11 +71,8 @@ public class BasePanel extends StackPane {

private final JabRefFrame frame;
// The undo manager.
private final UndoAction undoAction = new UndoAction();
private final RedoAction redoAction = new RedoAction();
private final CountingUndoManager undoManager;
// Keeps track of the string dialog if it is open.
private final Map<Actions, BaseAction> actions = new HashMap<>();

private final SidePaneManager sidePaneManager;
private final ExternalFileTypes externalFileTypes;

Expand Down Expand Up @@ -139,8 +119,6 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas

setupMainPanel();

setupActions();

this.getDatabase().registerListener(new SearchListener());
this.getDatabase().registerListener(new EntriesRemovedListener());

Expand All @@ -153,7 +131,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas

this.entryEditor = new EntryEditor(this, externalFileTypes);
// Open entry editor for first entry on start up.
Platform.runLater(() -> clearAndSelectFirst());
Platform.runLater(this::clearAndSelectFirst);
}

@Subscribe
Expand Down Expand Up @@ -216,48 +194,6 @@ public void output(String s) {
dialogService.notify(s);
}

private void setupActions() {
SaveDatabaseAction saveAction = new SaveDatabaseAction(this, Globals.prefs, Globals.entryTypesManager);
CleanupAction cleanUpAction = new CleanupAction(this, Globals.prefs, Globals.TASK_EXECUTOR);

actions.put(Actions.UNDO, undoAction);
actions.put(Actions.REDO, redoAction);

// The action for opening an entry editor.
actions.put(Actions.EDIT, this::showAndEdit);

// The action for saving a database.
actions.put(Actions.SAVE, saveAction::save);

actions.put(Actions.SAVE_AS, saveAction::saveAs);

actions.put(Actions.SAVE_SELECTED_AS_PLAIN, saveAction::saveSelectedAsPlain);

actions.put(Actions.SELECT_ALL, mainTable.getSelectionModel()::selectAll);

// The action for auto-generating keys.
actions.put(Actions.MAKE_KEY, new GenerateBibtexKeyAction(this, frame.getDialogService()));

// The action for cleaning up entry.
actions.put(Actions.CLEANUP, cleanUpAction);

actions.put(Actions.MERGE_DATABASE, new AppendDatabaseAction(frame, this));

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

actions.put(Actions.REPLACE_ALL, () -> (new ReplaceStringAction(this)).execute());

actions.put(Actions.ABBREVIATE_DEFAULT, new AbbreviateAction(this, AbbreviationType.DEFAULT));
actions.put(Actions.ABBREVIATE_MEDLINE, new AbbreviateAction(this, AbbreviationType.MEDLINE));
actions.put(Actions.ABBREVIATE_SHORTEST_UNIQUE, new AbbreviateAction(this, AbbreviationType.SHORTEST_UNIQUE));
actions.put(Actions.UNABBREVIATE, new UnabbreviateAction(this));

actions.put(Actions.DOWNLOAD_FULL_TEXT, new DownloadFullTextAction(this)::execute);
}

/**
* Removes the selected entries from the database
*
Expand Down Expand Up @@ -297,26 +233,6 @@ public void delete(BibEntry entry) {
delete(false, Collections.singletonList(entry));
}

/**
* 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.
*/
public void runCommand(final Actions command) {
if (!actions.containsKey(command)) {
LOGGER.info("No action defined for '" + command + '\'');
return;
}

BaseAction action = actions.get(command);
try {
action.action();
} catch (Throwable ex) {
LOGGER.error("runCommand error: " + ex.getMessage(), ex);
}
}

public void registerUndoableChanges(List<FieldChange> changes) {
NamedCompound ce = new NamedCompound(Localization.lang("Save actions"));
for (FieldChange change : changes) {
Expand Down Expand Up @@ -567,12 +483,6 @@ private void showBottomPane(BasePanelMode newMode) {
adjustSplitter();
}

private void showAndEdit() {
if (!mainTable.getSelectedEntries().isEmpty()) {
showAndEdit(mainTable.getSelectedEntries().get(0));
}
}

/**
* Removes the bottom component.
*/
Expand All @@ -594,7 +504,7 @@ public void clearAndSelect(final BibEntry bibEntry) {
*/
private void clearAndSelectFirst() {
mainTable.clearAndSelectFirst();
showAndEdit();
showAndEdit(mainTable.getSelectedEntries().get(0));
}

public void selectPreviousEntry() {
Expand Down Expand Up @@ -645,7 +555,7 @@ public void markNonUndoableBaseChanged() {
markBaseChanged();
}

private synchronized void markChangedOrUnChanged() {
public synchronized void markChangedOrUnChanged() {
if (getUndoManager().hasChanged()) {
if (!baseChanged) {
markBaseChanged();
Expand Down Expand Up @@ -864,37 +774,4 @@ public void listen(EntriesRemovedEvent removedEntriesEvent) {
DefaultTaskExecutor.runInJavaFXThread(() -> frame.getGlobalSearchBar().performSearch());
}
}

private class UndoAction implements BaseAction {

@Override
public void action() {
try {
getUndoManager().undo();
markBaseChanged();
output(Localization.lang("Undo"));
} catch (CannotUndoException ex) {
LOGGER.warn("Nothing to undo", ex);
output(Localization.lang("Nothing to undo") + '.');
}

markChangedOrUnChanged();
}
}

private class RedoAction implements BaseAction {

@Override
public void action() {
try {
getUndoManager().redo();
markBaseChanged();
output(Localization.lang("Redo"));
} catch (CannotRedoException ex) {
output(Localization.lang("Nothing to redo") + '.');
}

markChangedOrUnChanged();
}
}
}
Loading