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

Refactor SaveAction #6117

Merged
merged 3 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private void exportFile(List<ParserResult> loaded, String[] data) {
theFile = theFile.getAbsoluteFile();
}
BibDatabaseContext databaseContext = pr.getDatabaseContext();
databaseContext.setDatabaseFile(theFile);
databaseContext.setDatabasePath(theFile.toPath());
Globals.prefs.fileDirForDatabase = databaseContext
.getFileDirectories(Globals.prefs.getFilePreferences());
System.out.println(Localization.lang("Exporting") + ": " + data[0]);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import org.jabref.gui.copyfiles.CopyFilesAction;
import org.jabref.gui.customentrytypes.CustomizeEntryAction;
import org.jabref.gui.customizefields.SetupGeneralFieldsAction;
import org.jabref.gui.dialogs.AutosaveUIManager;
import org.jabref.gui.dialogs.AutosaveUiManager;
import org.jabref.gui.documentviewer.ShowDocumentViewerAction;
import org.jabref.gui.duplicationFinder.DuplicateSearch;
import org.jabref.gui.edit.CopyMoreAction;
Expand Down Expand Up @@ -1018,7 +1018,7 @@ public void addTab(BasePanel basePanel, boolean raisePanel) {

if (readyForAutosave(context)) {
AutosaveManager autosaver = AutosaveManager.start(context);
autosaver.registerListener(new AutosaveUIManager(basePanel));
autosaver.registerListener(new AutosaveUiManager(basePanel));
}

BackupManager.start(context, Globals.entryTypesManager, prefs);
Expand Down Expand Up @@ -1138,7 +1138,6 @@ private boolean confirmClose(BasePanel panel) {
try {
SaveDatabaseAction saveAction = new SaveDatabaseAction(panel, Globals.prefs, Globals.entryTypesManager);
if (saveAction.save()) {
// Saved, now exit.
return true;
}
// The action was either canceled or unsuccessful.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
import org.slf4j.LoggerFactory;

/**
* This class has an abstract UI role as it listens for an {@link AutosaveEvent}
* and saves the bib file associated with the given {@link BasePanel}.
* This class has an abstract UI role as it listens for an {@link AutosaveEvent} and saves the bib file associated with
* the given {@link BasePanel}.
*/
public class AutosaveUIManager {
public class AutosaveUiManager {
private static final Logger LOGGER = LoggerFactory.getLogger(AutosaveUiManager.class);

private static final Logger LOGGER = LoggerFactory.getLogger(AutosaveUIManager.class);
private final BasePanel panel;


public AutosaveUIManager(BasePanel panel) {
public AutosaveUiManager(BasePanel panel) {
this.panel = panel;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/exporter/SaveAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public class SaveAction extends SimpleCommand {

public enum SaveMethod { SAVE, SAVE_AS, SAVE_SELECTED }
public enum SaveMethod {SAVE, SAVE_AS, SAVE_SELECTED}

private final SaveMethod saveMethod;
private final JabRefFrame frame;
Expand All @@ -20,7 +20,6 @@ public SaveAction(SaveMethod saveMethod, JabRefFrame frame, StateManager stateMa
this.saveMethod = saveMethod;
this.frame = frame;


if (saveMethod == SaveMethod.SAVE_SELECTED) {
this.executable.bind(ActionHelper.needsEntriesSelected(stateManager));
} else {
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/jabref/gui/exporter/SaveAllAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ public void execute() {

for (BasePanel panel : frame.getBasePanelList()) {
SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction(panel, Globals.prefs, Globals.entryTypesManager);
if (panel.getBibDatabaseContext().getDatabasePath().isEmpty()) {
//It will ask a path before saving.
saveDatabaseAction.saveAs();
} else {
saveDatabaseAction.save();
// TODO: can we find out whether the save was actually done or not?
boolean saveResult = saveDatabaseAction.save();
if (!saveResult) {
dialogService.notify(Localization.lang("Could not save file."));
}
}

Expand Down
Loading