Skip to content

Commit 5565ee2

Browse files
author
Amrithadas P Anil
committed
fix for Library is marked as unsaved (*) after accepting changes from the file JabRef#11027
1 parent 8ff0ae6 commit 5565ee2

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,8 @@ public void resetChangeMonitor() {
910910
taskExecutor,
911911
dialogService,
912912
preferencesService,
913-
databaseNotificationPane));
913+
databaseNotificationPane,
914+
this));
914915
}
915916

916917
public void copy() {

src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ public class DatabaseChangeMonitor implements FileUpdateListener {
3131
private final TaskExecutor taskExecutor;
3232
private final DialogService dialogService;
3333
private final PreferencesService preferencesService;
34+
private final LibraryTab libraryTab;
3435

3536
public DatabaseChangeMonitor(BibDatabaseContext database,
3637
FileUpdateMonitor fileMonitor,
3738
TaskExecutor taskExecutor,
3839
DialogService dialogService,
3940
PreferencesService preferencesService,
40-
LibraryTab.DatabaseNotification notificationPane) {
41+
LibraryTab.DatabaseNotification notificationPane,
42+
LibraryTab libraryTab) {
4143
this.database = database;
4244
this.fileMonitor = fileMonitor;
4345
this.taskExecutor = taskExecutor;
4446
this.dialogService = dialogService;
4547
this.preferencesService = preferencesService;
48+
this.libraryTab = libraryTab;
4649

4750
this.listeners = new ArrayList<>();
4851

@@ -59,7 +62,7 @@ public DatabaseChangeMonitor(BibDatabaseContext database,
5962
Localization.lang("The library has been modified by another program."),
6063
List.of(new Action(Localization.lang("Dismiss changes"), event -> notificationPane.hide()),
6164
new Action(Localization.lang("Review changes"), event -> {
62-
dialogService.showCustomDialogAndWait(new DatabaseChangesResolverDialog(changes, database, Localization.lang("External Changes Resolver")));
65+
dialogService.showCustomDialogAndWait(new DatabaseChangesResolverDialog(changes, database, Localization.lang("External Changes Resolver"),libraryTab));
6366
notificationPane.hide();
6467
})),
6568
Duration.ZERO));

src/main/java/org/jabref/gui/collab/DatabaseChangesResolverDialog.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import javafx.scene.layout.BorderPane;
1616

1717
import org.jabref.gui.DialogService;
18+
import org.jabref.gui.LibraryTab;
1819
import org.jabref.gui.StateManager;
20+
import org.jabref.gui.exporter.SaveDatabaseAction;
1921
import org.jabref.gui.preview.PreviewViewer;
2022
import org.jabref.gui.theme.ThemeManager;
2123
import org.jabref.gui.util.BaseDialog;
@@ -52,6 +54,7 @@ public class DatabaseChangesResolverDialog extends BaseDialog<Boolean> {
5254
private final BibDatabaseContext database;
5355

5456
private ExternalChangesResolverViewModel viewModel;
57+
private final LibraryTab libraryTab;
5558

5659
@Inject private UndoManager undoManager;
5760
@Inject private StateManager stateManager;
@@ -68,9 +71,10 @@ public class DatabaseChangesResolverDialog extends BaseDialog<Boolean> {
6871
* @param changes The list of changes
6972
* @param database The database to apply the changes to
7073
*/
71-
public DatabaseChangesResolverDialog(List<DatabaseChange> changes, BibDatabaseContext database, String dialogTitle) {
74+
public DatabaseChangesResolverDialog(List<DatabaseChange> changes, BibDatabaseContext database, String dialogTitle, LibraryTab libraryTab) {
7275
this.changes = changes;
7376
this.database = database;
77+
this.libraryTab = libraryTab;
7478

7579
this.setTitle(dialogTitle);
7680
ViewLoader.view(this)
@@ -114,6 +118,8 @@ private void initialize() {
114118
EasyBind.subscribe(viewModel.areAllChangesResolvedProperty(), isResolved -> {
115119
if (isResolved) {
116120
viewModel.applyChanges();
121+
SaveDatabaseAction saveAction = new SaveDatabaseAction(libraryTab,dialogService,preferencesService,entryTypesManager);
122+
saveAction.save();
117123
close();
118124
}
119125
});

src/main/java/org/jabref/gui/dialogs/BackupUIManager.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javafx.scene.control.ButtonType;
99

1010
import org.jabref.gui.DialogService;
11+
import org.jabref.gui.LibraryTab;
1112
import org.jabref.gui.autosaveandbackup.BackupManager;
1213
import org.jabref.gui.backup.BackupResolverDialog;
1314
import org.jabref.gui.collab.DatabaseChange;
@@ -41,7 +42,8 @@ private BackupUIManager() {
4142
public static Optional<ParserResult> showRestoreBackupDialog(DialogService dialogService,
4243
Path originalPath,
4344
PreferencesService preferencesService,
44-
FileUpdateMonitor fileUpdateMonitor) {
45+
FileUpdateMonitor fileUpdateMonitor,
46+
LibraryTab libraryTab) {
4547
var actionOpt = showBackupResolverDialog(
4648
dialogService,
4749
preferencesService.getExternalApplicationsPreferences(),
@@ -52,7 +54,7 @@ public static Optional<ParserResult> showRestoreBackupDialog(DialogService dialo
5254
BackupManager.restoreBackup(originalPath, preferencesService.getFilePreferences().getBackupDirectory());
5355
return Optional.empty();
5456
} else if (action == BackupResolverDialog.REVIEW_BACKUP) {
55-
return showReviewBackupDialog(dialogService, originalPath, preferencesService, fileUpdateMonitor);
57+
return showReviewBackupDialog(dialogService, originalPath, preferencesService, fileUpdateMonitor, libraryTab);
5658
}
5759
return Optional.empty();
5860
});
@@ -70,7 +72,8 @@ private static Optional<ParserResult> showReviewBackupDialog(
7072
DialogService dialogService,
7173
Path originalPath,
7274
PreferencesService preferencesService,
73-
FileUpdateMonitor fileUpdateMonitor) {
75+
FileUpdateMonitor fileUpdateMonitor,
76+
LibraryTab libraryTab) {
7477
try {
7578
ImportFormatPreferences importFormatPreferences = preferencesService.getImportFormatPreferences();
7679

@@ -88,12 +91,13 @@ private static Optional<ParserResult> showReviewBackupDialog(
8891
List<DatabaseChange> changes = DatabaseChangeList.compareAndGetChanges(originalDatabase, backupDatabase, changeResolverFactory);
8992
DatabaseChangesResolverDialog reviewBackupDialog = new DatabaseChangesResolverDialog(
9093
changes,
91-
originalDatabase, "Review Backup"
94+
originalDatabase, "Review Backup",
95+
libraryTab
9296
);
9397
var allChangesResolved = dialogService.showCustomDialogAndWait(reviewBackupDialog);
9498
if (allChangesResolved.isEmpty() || !allChangesResolved.get()) {
9599
// In case not all changes are resolved, start from scratch
96-
return showRestoreBackupDialog(dialogService, originalPath, preferencesService, fileUpdateMonitor);
100+
return showRestoreBackupDialog(dialogService, originalPath, preferencesService, fileUpdateMonitor, libraryTab);
97101
}
98102

99103
// This does NOT return the original ParserResult, but a modified version with all changes accepted or rejected

src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private ParserResult loadDatabase(Path file) throws Exception {
219219
if (BackupManager.backupFileDiffers(fileToLoad, backupDir)) {
220220
// In case the backup differs, ask the user what to do.
221221
// In case the user opted for restoring a backup, the content of the backup is contained in parserResult.
222-
parserResult = BackupUIManager.showRestoreBackupDialog(dialogService, fileToLoad, preferencesService, fileUpdateMonitor)
222+
parserResult = BackupUIManager.showRestoreBackupDialog(dialogService, fileToLoad, preferencesService, fileUpdateMonitor, tabContainer.getCurrentLibraryTab())
223223
.orElse(null);
224224
}
225225

0 commit comments

Comments
 (0)