yyyyyyyyyy(Path targetFile, BackupFileType fileType) {
- return getPathOfLatestExistingBackupFile(targetFile, fileType, Path.of(""));
- }
-
/**
*
* Determines a unique file prefix.
diff --git a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerDiscardedTest.java b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerDiscardedTest.java
index 5a05afe1c24..b7e2e79da8c 100644
--- a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerDiscardedTest.java
+++ b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerDiscardedTest.java
@@ -82,7 +82,7 @@ private void databaseModification() {
}
private void makeBackup() {
- backupManager.determineBackupPathForNewBackup(backupDir).ifPresent(path -> backupManager.performBackup(backupDir));
+ backupManager.determineBackupPathForNewBackup(backupDir).ifPresent(path -> backupManager.performBackup(path));
}
@Test
@@ -104,7 +104,7 @@ public void noDiscardingASavedChange() throws Exception {
public void discardingAChangeLeadsToNewerBackupToBeIgnored() throws Exception {
databaseModification();
makeBackup();
- backupManager.discardBackup();
+ backupManager.discardBackup(backupDir);
assertFalse(BackupManager.backupFileDiffers(testBib, backupDir));
}
}
From 7c534b26001bc4a69a500193504b44fec869cb10 Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Fri, 28 Apr 2023 22:27:20 +0200
Subject: [PATCH 03/17] =?UTF-8?q?fix=20l1=C3=9Fn?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/resources/l10n/JabRef_en.properties | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties
index 8a955defa7a..8f54e71c313 100644
--- a/src/main/resources/l10n/JabRef_en.properties
+++ b/src/main/resources/l10n/JabRef_en.properties
@@ -2543,3 +2543,5 @@ Delete\ %0\ files=Delete %0 files
Delete\ %0\ files\ permanently\ from\ disk,\ or\ just\ remove\ the\ files\ from\ the\ entry?\ Pressing\ Delete\ will\ delete\ the\ files\ permanently\ from\ disk.=Delete %0 files permanently from disk, or just remove the files from the entry? Pressing Delete will delete the files permanently from disk.
Error\ accessing\ file\ '%0'.=Error accessing file '%0'.
This\ operation\ requires\ selected\ linked\ files.=This operation requires selected linked files.
+
+Create\ backup=Create backup
\ No newline at end of file
From 473a5e06f3ddab771e4ed3d4bf22f5ae74342af6 Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Fri, 28 Apr 2023 22:31:26 +0200
Subject: [PATCH 04/17] checkstyle and l10n
---
src/main/java/org/jabref/gui/dialogs/BackupUIManager.java | 2 +-
.../java/org/jabref/logic/autosaveandbackup/BackupManager.java | 1 +
src/test/java/org/jabref/logic/util/io/BackupFileUtilTest.java | 1 -
3 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/jabref/gui/dialogs/BackupUIManager.java b/src/main/java/org/jabref/gui/dialogs/BackupUIManager.java
index 4a820615a48..b1c4981e744 100644
--- a/src/main/java/org/jabref/gui/dialogs/BackupUIManager.java
+++ b/src/main/java/org/jabref/gui/dialogs/BackupUIManager.java
@@ -56,7 +56,7 @@ private static Optional showBackupResolverDialog(DialogService dialo
private static Optional showReviewBackupDialog(DialogService dialogService, Path originalPath, PreferencesService preferencesService) {
try {
- ImportFormatPreferences importFormatPreferences = preferencesService.getImportFormatPreferences();
+ ImportFormatPreferences importFormatPreferences = preferencesService.getImportFormatPreferences();
// The database of the originalParserResult will be modified
ParserResult originalParserResult = OpenDatabase.loadDatabase(originalPath, importFormatPreferences, Globals.getFileUpdateMonitor());
diff --git a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
index bf3f9365b66..5ba5d436784 100644
--- a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
+++ b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
@@ -323,6 +323,7 @@ private void fillQueue() {
/**
* Unregisters the BackupManager from the eventBus of {@link BibDatabaseContext}.
* This method should only be used when closing a database/JabRef in a normal way.
+ *
* @param path The backup directory
*/
private void shutdown(Path backupDir) {
diff --git a/src/test/java/org/jabref/logic/util/io/BackupFileUtilTest.java b/src/test/java/org/jabref/logic/util/io/BackupFileUtilTest.java
index c705be1f09c..bedea46b580 100644
--- a/src/test/java/org/jabref/logic/util/io/BackupFileUtilTest.java
+++ b/src/test/java/org/jabref/logic/util/io/BackupFileUtilTest.java
@@ -42,7 +42,6 @@ void getPathOfBackupFileAndCreateDirectoryReturnsAppDirectoryInCaseOfNoError() {
@Test
void getPathOfBackupFileAndCreateDirectoryReturnsSameDirectoryInCaseOfException() {
-
backupDir = BackupFileUtil.getAppDataBackupDir();
try (MockedStatic files = Mockito.mockStatic(Files.class, Answers.RETURNS_DEEP_STUBS)) {
files.when(() -> Files.createDirectories(BackupFileUtil.getAppDataBackupDir()))
From 0bb9321a19041efd88b66e30774b0f6f6bdd06dd Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Fri, 28 Apr 2023 22:33:45 +0200
Subject: [PATCH 05/17] checkstyle
---
.../java/org/jabref/logic/autosaveandbackup/BackupManager.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
index 5ba5d436784..733dadf6462 100644
--- a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
+++ b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
@@ -71,7 +71,7 @@ public class BackupManager {
this.entryTypesManager = entryTypesManager;
this.preferences = preferences;
this.executor = new ScheduledThreadPoolExecutor(2);
- this.createBackup = preferences.getFilePreferences().shouldCreateBackup();
+ this.createBackup = preferences.getFilePreferences().shouldCreateBackup();
changeFilter = new CoarseChangeFilter(bibDatabaseContext);
changeFilter.registerListener(this);
From b935fde92cb20a8461ab4afddf78ee1f6666ba10 Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Mon, 1 May 2023 20:34:18 +0200
Subject: [PATCH 06/17] fix merge conflicts
---
.../org/jabref/gui/preferences/file/FileTab.java | 2 +-
.../gui/preferences/file/FileTabViewModel.java | 16 +++++++++++-----
.../logic/autosaveandbackup/BackupManager.java | 12 +++++++-----
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTab.java b/src/main/java/org/jabref/gui/preferences/file/FileTab.java
index 1e2424c5297..04c01de911b 100644
--- a/src/main/java/org/jabref/gui/preferences/file/FileTab.java
+++ b/src/main/java/org/jabref/gui/preferences/file/FileTab.java
@@ -40,7 +40,7 @@ public FileTab() {
}
public void initialize() {
- this.viewModel = new FileTabViewModel(preferencesService.getImportExportPreferences(), preferencesService.getFieldPreferences());
+ this.viewModel = new FileTabViewModel(preferencesService.getImportExportPreferences(), preferencesService.getFieldPreferences(), preferencesService.getFilePreferences(), dialogService);
noWrapFiles.textProperty().bindBidirectional(viewModel.noWrapFilesProperty());
diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java
index c37c3762bbb..c64626c39ec 100644
--- a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java
+++ b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java
@@ -12,6 +12,7 @@
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.model.entry.field.FieldFactory;
+import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.ImportExportPreferences;
public class FileTabViewModel implements PreferenceTabViewModel {
@@ -23,12 +24,17 @@ public class FileTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty alwaysReformatBibProperty = new SimpleBooleanProperty();
private final BooleanProperty autosaveLocalLibraries = new SimpleBooleanProperty();
+ private final BooleanProperty createBackupProperty = new SimpleBooleanProperty();
+ private final StringProperty backupDirectoryProperty = new SimpleStringProperty("");
+
private final ImportExportPreferences importExportPreferences;
private final FieldPreferences fieldPreferences;
private final DialogService dialogService;
+ private final FilePreferences filePreferences;
- FileTabViewModel(ImportExportPreferences importExportPreferences, FieldPreferences fieldPreferences) {
+ FileTabViewModel(ImportExportPreferences importExportPreferences, FieldPreferences fieldPreferences, FilePreferences filePreferences, DialogService dialogService) {
this.importExportPreferences = importExportPreferences;
+ this.fieldPreferences = fieldPreferences;
this.filePreferences = filePreferences;
this.dialogService = dialogService;
}
@@ -43,8 +49,8 @@ public void setValues() {
alwaysReformatBibProperty.setValue(importExportPreferences.shouldAlwaysReformatOnSave());
autosaveLocalLibraries.setValue(importExportPreferences.shouldAutoSave());
- createBackupProperty.setValue(fieldPreferences.shouldCreateBackup());
- backupDirectoryProperty.setValue(fieldPreferences.getBackupDirectory().toString());
+ createBackupProperty.setValue(filePreferences.shouldCreateBackup());
+ backupDirectoryProperty.setValue(filePreferences.getBackupDirectory().toString());
}
@Override
@@ -55,8 +61,8 @@ public void storeSettings() {
importExportPreferences.setAlwaysReformatOnSave(alwaysReformatBibProperty.getValue());
importExportPreferences.setAutoSave(autosaveLocalLibraries.getValue());
- fieldPreferences.createBackupProperty().setValue(createBackupProperty.getValue());
- fieldPreferences.backupDirectoryProperty().setValue(Path.of(backupDirectoryProperty.getValue()));
+ filePreferences.createBackupProperty().setValue(createBackupProperty.getValue());
+ filePreferences.backupDirectoryProperty().setValue(Path.of(backupDirectoryProperty.getValue()));
}
// ImportExport
diff --git a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
index 4c9588f6228..a22f977761a 100644
--- a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
+++ b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
@@ -64,12 +64,12 @@ public class BackupManager {
private boolean needsBackup = false;
+
BackupManager(BibDatabaseContext bibDatabaseContext, BibEntryTypesManager entryTypesManager, PreferencesService preferences) {
this.bibDatabaseContext = bibDatabaseContext;
this.entryTypesManager = entryTypesManager;
this.preferences = preferences;
this.executor = new ScheduledThreadPoolExecutor(2);
- this.createBackup = preferences.getFilePreferences().shouldCreateBackup();
changeFilter = new CoarseChangeFilter(bibDatabaseContext);
changeFilter.registerListener(this);
@@ -117,10 +117,11 @@ public static void discardBackup(BibDatabaseContext bibDatabaseContext, Path bac
* Shuts down the BackupManager which is associated with the given {@link BibDatabaseContext}.
*
* @param bibDatabaseContext Associated {@link BibDatabaseContext}
+ * @param b
+ * @param path
*/
- public static void shutdown(BibDatabaseContext bibDatabaseContext) {
- runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(
- BackupManager::shutdown);
+ public static void shutdown(BibDatabaseContext bibDatabaseContext, Path path, boolean createBackup) {
+ runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.shutdown(path, createBackup));
runningInstances.removeIf(instance -> instance.bibDatabaseContext == bibDatabaseContext);
}
@@ -328,8 +329,9 @@ private void fillQueue() {
* This method should only be used when closing a database/JabRef in a normal way.
*
* @param path The backup directory
+ * @param createBackup If the backup manager should still perform a backup
*/
- private void shutdown(Path backupDir) {
+ private void shutdown(Path backupDir, boolean createBackup) {
changeFilter.unregisterListener(this);
changeFilter.shutdown();
executor.shutdown();
From 5dae3721f89884622da1edfeb0f9df04b7c71f61 Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Mon, 1 May 2023 21:00:47 +0200
Subject: [PATCH 07/17] add comment
---
src/main/java/org/jabref/preferences/JabRefPreferences.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java
index 08b5999c8ab..4494cd93b6f 100644
--- a/src/main/java/org/jabref/preferences/JabRefPreferences.java
+++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java
@@ -2122,6 +2122,7 @@ public FilePreferences getFilePreferences() {
Path.of(get(WORKING_DIRECTORY)),
ExternalFileTypes.fromString(get(EXTERNAL_FILE_TYPES)),
getBoolean(CREATE_BACKUP),
+ // We choose the data directory, because a ".bak" file should survive cache cleanups
getPath(BACKUP_DIRECTORY, BackupFileUtil.getAppDataBackupDir()));
EasyBind.listen(filePreferences.mainFileDirectoryProperty(), (obs, oldValue, newValue) -> put(MAIN_FILE_DIRECTORY, newValue));
From 2f447d9660c77c23ad2828677a225ddb6c383f4e Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Thu, 4 May 2023 20:56:32 +0200
Subject: [PATCH 08/17] fix checkstyle
---
.../logic/autosaveandbackup/BackupManager.java | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
index a22f977761a..858eaae4824 100644
--- a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
+++ b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
@@ -61,10 +61,8 @@ public class BackupManager {
// Contains a list of all backup paths
// During a write, the less recent backup file is deleted
private final Queue backupFilesQueue = new LinkedBlockingQueue<>();
-
private boolean needsBackup = false;
-
BackupManager(BibDatabaseContext bibDatabaseContext, BibEntryTypesManager entryTypesManager, PreferencesService preferences) {
this.bibDatabaseContext = bibDatabaseContext;
this.entryTypesManager = entryTypesManager;
@@ -117,11 +115,11 @@ public static void discardBackup(BibDatabaseContext bibDatabaseContext, Path bac
* Shuts down the BackupManager which is associated with the given {@link BibDatabaseContext}.
*
* @param bibDatabaseContext Associated {@link BibDatabaseContext}
- * @param b
- * @param path
+ * @param createBackup True, if a backup should be created
+ * @param backupDir The path to the backup directory
*/
- public static void shutdown(BibDatabaseContext bibDatabaseContext, Path path, boolean createBackup) {
- runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.shutdown(path, createBackup));
+ public static void shutdown(BibDatabaseContext bibDatabaseContext, Path backupDir, boolean createBackup) {
+ runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.shutdown(backupDir, createBackup));
runningInstances.removeIf(instance -> instance.bibDatabaseContext == bibDatabaseContext);
}
@@ -328,7 +326,7 @@ private void fillQueue() {
* Unregisters the BackupManager from the eventBus of {@link BibDatabaseContext}.
* This method should only be used when closing a database/JabRef in a normal way.
*
- * @param path The backup directory
+ * @param backupDir The backup directory
* @param createBackup If the backup manager should still perform a backup
*/
private void shutdown(Path backupDir, boolean createBackup) {
From bf4c43dc8a56132d1edec2a5b29403856b4f5877 Mon Sep 17 00:00:00 2001
From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Date: Thu, 4 May 2023 21:01:41 +0200
Subject: [PATCH 09/17] Moved backup settings to GeneralTab
---
.../jabref/gui/preferences/file/FileTab.fxml | 21 +---------
.../jabref/gui/preferences/file/FileTab.java | 9 -----
.../preferences/file/FileTabViewModel.java | 27 -------------
.../gui/preferences/general/GeneralTab.fxml | 20 ++++++++++
.../gui/preferences/general/GeneralTab.java | 13 ++++++-
.../general/GeneralTabViewModel.java | 38 +++++++++++++++++--
6 files changed, 69 insertions(+), 59 deletions(-)
diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTab.fxml b/src/main/java/org/jabref/gui/preferences/file/FileTab.fxml
index 52d7772599b..8a68749dd2f 100644
--- a/src/main/java/org/jabref/gui/preferences/file/FileTab.fxml
+++ b/src/main/java/org/jabref/gui/preferences/file/FileTab.fxml
@@ -6,12 +6,8 @@
-
-
-
-
@@ -42,19 +38,6 @@
-
-
-
-
-
-
+
+
diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTab.java b/src/main/java/org/jabref/gui/preferences/file/FileTab.java
index 04c01de911b..36bd53ff158 100644
--- a/src/main/java/org/jabref/gui/preferences/file/FileTab.java
+++ b/src/main/java/org/jabref/gui/preferences/file/FileTab.java
@@ -25,8 +25,6 @@ public class FileTab extends AbstractPreferenceTabView impleme
@FXML private RadioButton resolveStrings;
@FXML private TextField resolveStringsForFields;
@FXML private CheckBox alwaysReformatBib;
- @FXML private CheckBox createBackup;
- @FXML private TextField backupDirectory;
@FXML private CheckBox autosaveLocalLibraries;
@FXML private Button autosaveLocalLibrariesHelp;
@@ -52,9 +50,6 @@ public void initialize() {
alwaysReformatBib.selectedProperty().bindBidirectional(viewModel.alwaysReformatBibProperty());
autosaveLocalLibraries.selectedProperty().bindBidirectional(viewModel.autosaveLocalLibrariesProperty());
- createBackup.selectedProperty().bindBidirectional(viewModel.createBackupProperty());
- backupDirectory.textProperty().bindBidirectional(viewModel.backupDirectoryProperty());
-
ActionFactory actionFactory = new ActionFactory(preferencesService.getKeyBindingRepository());
actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.AUTOSAVE, dialogService), autosaveLocalLibrariesHelp);
}
@@ -63,8 +58,4 @@ public void initialize() {
public String getTabName() {
return Localization.lang("File");
}
-
- public void backupFileDirBrowse() {
- viewModel.backupFileDirBrowse();
- }
}
diff --git a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java
index c64626c39ec..da087e3bdcb 100644
--- a/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java
+++ b/src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java
@@ -1,7 +1,5 @@
package org.jabref.gui.preferences.file;
-import java.nio.file.Path;
-
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
@@ -9,7 +7,6 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.preferences.PreferenceTabViewModel;
-import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.preferences.FilePreferences;
@@ -24,9 +21,6 @@ public class FileTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty alwaysReformatBibProperty = new SimpleBooleanProperty();
private final BooleanProperty autosaveLocalLibraries = new SimpleBooleanProperty();
- private final BooleanProperty createBackupProperty = new SimpleBooleanProperty();
- private final StringProperty backupDirectoryProperty = new SimpleStringProperty("");
-
private final ImportExportPreferences importExportPreferences;
private final FieldPreferences fieldPreferences;
private final DialogService dialogService;
@@ -48,9 +42,6 @@ public void setValues() {
resolveStringsForFieldsProperty.setValue(FieldFactory.serializeFieldsList(fieldPreferences.getResolvableFields()));
alwaysReformatBibProperty.setValue(importExportPreferences.shouldAlwaysReformatOnSave());
autosaveLocalLibraries.setValue(importExportPreferences.shouldAutoSave());
-
- createBackupProperty.setValue(filePreferences.shouldCreateBackup());
- backupDirectoryProperty.setValue(filePreferences.getBackupDirectory().toString());
}
@Override
@@ -60,9 +51,6 @@ public void storeSettings() {
fieldPreferences.setResolvableFields(FieldFactory.parseFieldList(resolveStringsForFieldsProperty.getValue().trim()));
importExportPreferences.setAlwaysReformatOnSave(alwaysReformatBibProperty.getValue());
importExportPreferences.setAutoSave(autosaveLocalLibraries.getValue());
-
- filePreferences.createBackupProperty().setValue(createBackupProperty.getValue());
- filePreferences.backupDirectoryProperty().setValue(Path.of(backupDirectoryProperty.getValue()));
}
// ImportExport
@@ -91,19 +79,4 @@ public BooleanProperty alwaysReformatBibProperty() {
public BooleanProperty autosaveLocalLibrariesProperty() {
return autosaveLocalLibraries;
}
-
- public BooleanProperty createBackupProperty() {
- return this.createBackupProperty;
- }
-
- public StringProperty backupDirectoryProperty() {
- return this.backupDirectoryProperty;
- }
-
- public void backupFileDirBrowse() {
- DirectoryDialogConfiguration dirDialogConfiguration =
- new DirectoryDialogConfiguration.Builder().withInitialDirectory(Path.of(backupDirectoryProperty().getValue())).build();
- dialogService.showDirectorySelectionDialog(dirDialogConfiguration)
- .ifPresent(dir -> backupDirectoryProperty.setValue(dir.toString()));
- }
}
diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml
index a108e2fec39..d5b921ca7e0 100644
--- a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml
+++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml
@@ -1,12 +1,17 @@
+
+
+
+
+
@@ -35,4 +40,19 @@
+
+
+
+
+
+
diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java
index 6a28b84db3a..85cf7f50af7 100644
--- a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java
+++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java
@@ -3,6 +3,7 @@
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
+import javafx.scene.control.TextField;
import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.gui.preferences.PreferencesTab;
@@ -24,6 +25,9 @@ public class GeneralTab extends AbstractPreferenceTabView i
@FXML private CheckBox collectTelemetry;
@FXML private CheckBox showAdvancedHints;
+ @FXML private CheckBox createBackup;
+ @FXML private TextField backupDirectory;
+
public GeneralTab() {
ViewLoader.view(this)
.root(this)
@@ -36,7 +40,7 @@ public String getTabName() {
}
public void initialize() {
- this.viewModel = new GeneralTabViewModel(dialogService, preferencesService.getGeneralPreferences(), preferencesService.getTelemetryPreferences());
+ this.viewModel = new GeneralTabViewModel(preferencesService, dialogService);
new ViewModelListCellFactory()
.withText(Language::getDisplayName)
@@ -56,5 +60,12 @@ public void initialize() {
openLastStartup.selectedProperty().bindBidirectional(viewModel.openLastStartupProperty());
collectTelemetry.selectedProperty().bindBidirectional(viewModel.collectTelemetryProperty());
showAdvancedHints.selectedProperty().bindBidirectional(viewModel.showAdvancedHintsProperty());
+
+ createBackup.selectedProperty().bindBidirectional(viewModel.createBackupProperty());
+ backupDirectory.textProperty().bindBidirectional(viewModel.backupDirectoryProperty());
+ }
+
+ public void backupFileDirBrowse() {
+ viewModel.backupFileDirBrowse();
}
}
diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java b/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java
index 68130266435..61cbeaeced9 100644
--- a/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java
+++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java
@@ -1,5 +1,6 @@
package org.jabref.gui.preferences.general;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@@ -10,15 +11,20 @@
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.property.SimpleStringProperty;
+import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.transformation.SortedList;
import org.jabref.gui.DialogService;
import org.jabref.gui.preferences.PreferenceTabViewModel;
+import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.logic.l10n.Language;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseMode;
+import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.GeneralPreferences;
+import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.TelemetryPreferences;
public class GeneralTabViewModel implements PreferenceTabViewModel {
@@ -34,17 +40,22 @@ public class GeneralTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty openLastStartupProperty = new SimpleBooleanProperty();
private final BooleanProperty showAdvancedHintsProperty = new SimpleBooleanProperty();
+ private final BooleanProperty createBackupProperty = new SimpleBooleanProperty();
+ private final StringProperty backupDirectoryProperty = new SimpleStringProperty("");
+
private final DialogService dialogService;
private final GeneralPreferences generalPreferences;
private final TelemetryPreferences telemetryPreferences;
+ private final FilePreferences filePreferences;
private final List restartWarning = new ArrayList<>();
@SuppressWarnings("ReturnValueIgnored")
- public GeneralTabViewModel(DialogService dialogService, GeneralPreferences generalPreferences, TelemetryPreferences telemetryPreferences) {
+ public GeneralTabViewModel(PreferencesService preferencesService, DialogService dialogService) {
this.dialogService = dialogService;
- this.generalPreferences = generalPreferences;
- this.telemetryPreferences = telemetryPreferences;
+ this.generalPreferences = preferencesService.getGeneralPreferences();
+ this.telemetryPreferences = preferencesService.getTelemetryPreferences();
+ this.filePreferences = preferencesService.getFilePreferences();
}
public void setValues() {
@@ -60,6 +71,9 @@ public void setValues() {
collectTelemetryProperty.setValue(telemetryPreferences.shouldCollectTelemetry());
openLastStartupProperty.setValue(generalPreferences.shouldOpenLastEdited());
showAdvancedHintsProperty.setValue(generalPreferences.shouldShowAdvancedHints());
+
+ createBackupProperty.setValue(filePreferences.shouldCreateBackup());
+ backupDirectoryProperty.setValue(filePreferences.getBackupDirectory().toString());
}
public void storeSettings() {
@@ -84,6 +98,9 @@ public void storeSettings() {
generalPreferences.setShowAdvancedHints(showAdvancedHintsProperty.getValue());
telemetryPreferences.setCollectTelemetry(collectTelemetryProperty.getValue());
+
+ filePreferences.createBackupProperty().setValue(createBackupProperty.getValue());
+ filePreferences.backupDirectoryProperty().setValue(Path.of(backupDirectoryProperty.getValue()));
}
@Override
@@ -132,4 +149,19 @@ public BooleanProperty openLastStartupProperty() {
public BooleanProperty showAdvancedHintsProperty() {
return this.showAdvancedHintsProperty;
}
+
+ public BooleanProperty createBackupProperty() {
+ return this.createBackupProperty;
+ }
+
+ public StringProperty backupDirectoryProperty() {
+ return this.backupDirectoryProperty;
+ }
+
+ public void backupFileDirBrowse() {
+ DirectoryDialogConfiguration dirDialogConfiguration =
+ new DirectoryDialogConfiguration.Builder().withInitialDirectory(Path.of(backupDirectoryProperty().getValue())).build();
+ dialogService.showDirectorySelectionDialog(dirDialogConfiguration)
+ .ifPresent(dir -> backupDirectoryProperty.setValue(dir.toString()));
+ }
}
From 9a270dcf2907e3d0cf3defdfd165a4314f861483 Mon Sep 17 00:00:00 2001
From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Date: Thu, 4 May 2023 21:11:22 +0200
Subject: [PATCH 10/17] Refine ui
---
.../java/org/jabref/gui/preferences/general/GeneralTab.fxml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml
index d5b921ca7e0..8044c84f7e7 100644
--- a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml
+++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.fxml
@@ -1,5 +1,6 @@
+
@@ -54,5 +55,8 @@
+
+
+
From de977791706ef424b596378eada3586213ebdb69 Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Thu, 4 May 2023 21:22:39 +0200
Subject: [PATCH 11/17] fix unit tests
---
.../org/jabref/logic/autosaveandbackup/BackupManagerTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
index 5ad86ed2c32..3fdf7a456d0 100644
--- a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
+++ b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
@@ -76,7 +76,7 @@ public void correctBackupFileDeterminedForMultipleBakFiles() throws Exception {
// create "older" .bak files containing changes
for (int i = 0; i < 10; i++) {
Path changesBibBak = Path.of(BackupManagerTest.class.getResource("changes.bib").toURI());
- Path directory = BackupFileUtil.getAppDataBackupDir();
+ Path directory = backupDir;
String timeSuffix = "2020-02-03--00.00.0" + Integer.toString(i);
String fileName = BackupFileUtil.getUniqueFilePrefix(noChangesBib) + "--no-changes.bib--" + timeSuffix + ".bak";
target = directory.resolve(fileName);
From cfebdbee8ab16b556993f119bc0e7793c977cc08 Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Thu, 4 May 2023 22:14:06 +0200
Subject: [PATCH 12/17] add tests
---
.../autosaveandbackup/BackupManager.java | 2 +-
.../autosaveandbackup/BackupManagerTest.java | 68 +++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
index 858eaae4824..b50beb7a1d0 100644
--- a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
+++ b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
@@ -206,7 +206,7 @@ Optional determineBackupPathForNewBackup(Path backupDir) {
* SIDE EFFECT: Deletes oldest backup file
*
*
- * @param backupPath the path where the library should be backed up to
+ * @param backupPath the full path to the file where the library should be backed up to
*/
void performBackup(Path backupPath) {
if (!needsBackup) {
diff --git a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
index 3fdf7a456d0..b124b8d3d7b 100644
--- a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
+++ b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
@@ -4,17 +4,32 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileTime;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
import org.jabref.logic.util.BackupFileType;
import org.jabref.logic.util.io.BackupFileUtil;
+import org.jabref.model.database.BibDatabase;
+import org.jabref.model.database.BibDatabaseContext;
+import org.jabref.model.entry.BibEntryTypesManager;
+import org.jabref.model.groups.event.GroupUpdatedEvent;
+import org.jabref.model.metadata.MetaData;
+import org.jabref.model.metadata.event.MetaDataChangedEvent;
+import org.jabref.preferences.FilePreferences;
+import org.jabref.preferences.PreferencesService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import org.mockito.Answers;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class BackupManagerTest {
@@ -111,4 +126,57 @@ public void bakFileWithOlderTimeStampDoesNotLeadToDiff() throws Exception {
assertFalse(BackupManager.backupFileDiffers(changesBib, backupDir));
}
+
+ @Test
+ public void shouldNotCreateABackup(@TempDir Path customDir) throws Exception {
+ Path backupDir = customDir.resolve("subBackupDir");
+ Files.createDirectories(backupDir);
+
+ var database = new BibDatabaseContext(new BibDatabase());
+ database.setDatabasePath(customDir.resolve("Bibfile.bib"));
+
+ var preferences = mock(PreferencesService.class, Answers.RETURNS_DEEP_STUBS);
+ var filePreferences = mock(FilePreferences.class);
+ when(preferences.getFilePreferences()).thenReturn(filePreferences);
+ when(filePreferences.getBackupDirectory()).thenReturn(backupDir);
+
+ BackupManager manager = BackupManager.start(database, mock(BibEntryTypesManager.class, Answers.RETURNS_DEEP_STUBS), preferences);
+ manager.listen(new MetaDataChangedEvent(new MetaData()));
+
+ BackupManager.shutdown(database, backupDir, false);
+
+ List files = Files.list(backupDir).toList();
+ assertEquals(Collections.emptyList(), files);
+ }
+
+ @Test
+ public void shouldCreateABackup(@TempDir Path customDir) throws Exception {
+ Path backupDir = customDir.resolve("subBackupDir");
+ Files.createDirectories(backupDir);
+
+ var database = new BibDatabaseContext(new BibDatabase());
+ database.setDatabasePath(customDir.resolve("Bibfile.bib"));
+
+ var preferences = mock(PreferencesService.class, Answers.RETURNS_DEEP_STUBS);
+ var filePreferences = mock(FilePreferences.class);
+ when(preferences.getFilePreferences()).thenReturn(filePreferences);
+ when(filePreferences.getBackupDirectory()).thenReturn(backupDir);
+ when(filePreferences.shouldCreateBackup()).thenReturn(true);
+
+ BackupManager manager = BackupManager.start(database, mock(BibEntryTypesManager.class, Answers.RETURNS_DEEP_STUBS), preferences);
+ manager.listen(new MetaDataChangedEvent(new MetaData()));
+
+ Optional fullBackupPath = manager.determineBackupPathForNewBackup(backupDir);
+ fullBackupPath.ifPresent(manager::performBackup);
+ manager.listen(new GroupUpdatedEvent(new MetaData()));
+ // We have to wait a bit so that the backup time differs and the path is different
+ Thread.sleep(600);
+
+ BackupManager.shutdown(database, backupDir, true);
+
+ List files = Files.list(backupDir).sorted().toList();
+ assertEquals(2, files.size());
+ // we only know the first backup path because the second one is created on shutdown
+ assertEquals(fullBackupPath.get(), files.get(0));
+ }
}
From 243f73a4cc6574ae61981d177c02104ec1bc7f5e Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Thu, 4 May 2023 22:17:02 +0200
Subject: [PATCH 13/17] fix indentation
---
.../jabref/logic/util/io/BackupFileUtil.java | 50 +++++++++----------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/src/main/java/org/jabref/logic/util/io/BackupFileUtil.java b/src/main/java/org/jabref/logic/util/io/BackupFileUtil.java
index 76b9ca753f3..d64446b9949 100644
--- a/src/main/java/org/jabref/logic/util/io/BackupFileUtil.java
+++ b/src/main/java/org/jabref/logic/util/io/BackupFileUtil.java
@@ -68,37 +68,37 @@ public static Path getPathForNewBackupFileAndCreateDirectory(Path targetFile, Ba
}
public static Optional getPathOfLatestExistingBackupFile(Path targetFile, BackupFileType fileType, Path backupDir) {
- // The code is similar to "getPathForNewBackupFileAndCreateDirectory"
+ // The code is similar to "getPathForNewBackupFileAndCreateDirectory"
- String extension = "." + fileType.getExtensions().get(0);
-
- Path directory = backupDir;
- if (Files.notExists(directory)) {
- // In case there is no app directory, we search in the directory of the bib file
- Path result = FileUtil.addExtension(targetFile, extension);
- if (Files.exists(result)) {
- return Optional.of(result);
- } else {
- return Optional.empty();
- }
- }
+ String extension = "." + fileType.getExtensions().get(0);
- // Search the directory for the latest file
- final String prefix = getUniqueFilePrefix(targetFile) + "--" + targetFile.getFileName();
- Optional mostRecentFile;
- try {
- mostRecentFile = Files.list(directory)
- // just list the .sav belonging to the given targetFile
- .filter(p -> p.getFileName().toString().startsWith(prefix))
- .sorted()
- .reduce((first, second) -> second);
- } catch (IOException e) {
- LOGGER.error("Could not determine most recent file", e);
+ Path directory = backupDir;
+ if (Files.notExists(directory)) {
+ // In case there is no app directory, we search in the directory of the bib file
+ Path result = FileUtil.addExtension(targetFile, extension);
+ if (Files.exists(result)) {
+ return Optional.of(result);
+ } else {
return Optional.empty();
}
- return mostRecentFile;
}
+ // Search the directory for the latest file
+ final String prefix = getUniqueFilePrefix(targetFile) + "--" + targetFile.getFileName();
+ Optional mostRecentFile;
+ try {
+ mostRecentFile = Files.list(directory)
+ // just list the .sav belonging to the given targetFile
+ .filter(p -> p.getFileName().toString().startsWith(prefix))
+ .sorted()
+ .reduce((first, second) -> second);
+ } catch (IOException e) {
+ LOGGER.error("Could not determine most recent file", e);
+ return Optional.empty();
+ }
+ return mostRecentFile;
+ }
+
/**
*
* Determines a unique file prefix.
From ad52f328205476e31f8a2ac723e7683d374ee8ce Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Thu, 4 May 2023 22:17:57 +0200
Subject: [PATCH 14/17] remove useless var
---
src/main/java/org/jabref/logic/util/io/BackupFileUtil.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/jabref/logic/util/io/BackupFileUtil.java b/src/main/java/org/jabref/logic/util/io/BackupFileUtil.java
index d64446b9949..d2b42eef98f 100644
--- a/src/main/java/org/jabref/logic/util/io/BackupFileUtil.java
+++ b/src/main/java/org/jabref/logic/util/io/BackupFileUtil.java
@@ -72,8 +72,7 @@ public static Optional getPathOfLatestExistingBackupFile(Path targetFile,
String extension = "." + fileType.getExtensions().get(0);
- Path directory = backupDir;
- if (Files.notExists(directory)) {
+ if (Files.notExists(backupDir)) {
// In case there is no app directory, we search in the directory of the bib file
Path result = FileUtil.addExtension(targetFile, extension);
if (Files.exists(result)) {
@@ -87,7 +86,7 @@ public static Optional getPathOfLatestExistingBackupFile(Path targetFile,
final String prefix = getUniqueFilePrefix(targetFile) + "--" + targetFile.getFileName();
Optional mostRecentFile;
try {
- mostRecentFile = Files.list(directory)
+ mostRecentFile = Files.list(backupDir)
// just list the .sav belonging to the given targetFile
.filter(p -> p.getFileName().toString().startsWith(prefix))
.sorted()
From b9c1af2dbb1edf59f8eeab76e8df92afe9cc8ce0 Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Fri, 5 May 2023 19:46:07 +0200
Subject: [PATCH 15/17] disable backup dir when unchecked
---
src/main/java/org/jabref/gui/preferences/general/GeneralTab.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java
index 85cf7f50af7..0f3811c47cb 100644
--- a/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java
+++ b/src/main/java/org/jabref/gui/preferences/general/GeneralTab.java
@@ -63,6 +63,7 @@ public void initialize() {
createBackup.selectedProperty().bindBidirectional(viewModel.createBackupProperty());
backupDirectory.textProperty().bindBidirectional(viewModel.backupDirectoryProperty());
+ backupDirectory.disableProperty().bind(viewModel.createBackupProperty().not());
}
public void backupFileDirBrowse() {
From 2df54e8085c45cd15eefeb4752659e571aab1218 Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Fri, 5 May 2023 20:12:19 +0200
Subject: [PATCH 16/17] remove test for second file
---
.../org/jabref/logic/autosaveandbackup/BackupManagerTest.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
index b124b8d3d7b..7bf69d79f91 100644
--- a/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
+++ b/src/test/java/org/jabref/logic/autosaveandbackup/BackupManagerTest.java
@@ -169,14 +169,12 @@ public void shouldCreateABackup(@TempDir Path customDir) throws Exception {
Optional fullBackupPath = manager.determineBackupPathForNewBackup(backupDir);
fullBackupPath.ifPresent(manager::performBackup);
manager.listen(new GroupUpdatedEvent(new MetaData()));
- // We have to wait a bit so that the backup time differs and the path is different
- Thread.sleep(600);
BackupManager.shutdown(database, backupDir, true);
List files = Files.list(backupDir).sorted().toList();
- assertEquals(2, files.size());
// we only know the first backup path because the second one is created on shutdown
+ // due to timing issues we cannot test that reliable
assertEquals(fullBackupPath.get(), files.get(0));
}
}
From 5547e35873af1c6293effdb2a3afc7c996d6b3f3 Mon Sep 17 00:00:00 2001
From: Siedlerchr
Date: Fri, 5 May 2023 21:20:46 +0200
Subject: [PATCH 17/17] fix missing path parameter
---
.../org/jabref/logic/autosaveandbackup/BackupManager.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
index dc8b7c3ab6c..599ac265fc9 100644
--- a/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
+++ b/src/main/java/org/jabref/logic/autosaveandbackup/BackupManager.java
@@ -292,7 +292,7 @@ public synchronized void listen(@SuppressWarnings("unused") BibDatabaseContextCh
}
private void startBackupTask(Path backupDir) {
- fillQueue();
+ fillQueue(backupDir);
executor.scheduleAtFixedRate(
// We need to determine the backup path on each action, because we use the timestamp in the filename
@@ -302,8 +302,7 @@ private void startBackupTask(Path backupDir) {
TimeUnit.SECONDS);
}
- private void fillQueue() {
- Path backupDir = BackupFileUtil.getAppDataBackupDir();
+ private void fillQueue(Path backupDir) {
if (!Files.exists(backupDir)) {
return;
}