Skip to content

Commit 4667124

Browse files
authored
Merge branch 'main' into fix-for-issue-JabRef#372
2 parents 262d25d + 982aeb1 commit 4667124

File tree

9 files changed

+82
-10
lines changed

9 files changed

+82
-10
lines changed

.github/workflows/pr-comment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
PR_NUMBER=$(cat pr_number.txt)
3535
echo "Read PR number $PR_NUMBER"
3636
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
37+
- uses: actions/checkout@v4
3738
- name: Determine owner
3839
if: ${{ steps.read-pr_number.outputs.pr_number != '' }}
3940
id: owner

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
export PATH=$PATH:$HOME/.jbang/bin
132132
133133
# run heylogs verification
134-
jbang com.github.nbbrd.heylogs:heylogs-cli:0.7.2:bin check CHANGELOG.md > heylogs.txt || true
134+
jbang com.github.nbbrd.heylogs:heylogs-cli:0.9.2:bin check CHANGELOG.md > heylogs.txt || true
135135
136136
# improve output
137137
sed -i 's/all-h2-contain-a-version/all-h2-contain-a-version (ignored)/' heylogs.txt

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
6767
- We added a new CSS style class `main-table` for the main table. [#11881](https://github.com/JabRef/jabref/pull/11881)
6868
- When renaming a file, the old extension is now used if there is none provided in the new name. [#11903](https://github.com/JabRef/jabref/issues/11903)
6969
- We changed the name of the library-based file directory from 'General File Directory' to 'Library-specific File Directory' per issue [#571](https://github.com/koppor/jabref/issues/571)
70+
- The CitationKey column is now a default shown column for the entry table. [#10510](https://github.com/JabRef/jabref/issues/10510)
7071

7172
### Fixed
7273

@@ -100,6 +101,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
100101
- We fixed an issue where recently opened files were not displayed in the main menu properly. [#9042](https://github.com/JabRef/jabref/issues/9042)
101102
- We fixed an issue where the DOI lookup would show an error when a DOI was found for an entry. [#11850](https://github.com/JabRef/jabref/issues/11850)
102103
- We fixed an issue where <kbd>Tab</kbd> cannot be used to jump to next field in some single-line fields. [#11785](https://github.com/JabRef/jabref/issues/11785)
104+
- We fixed an issue where we display warning message for moving attached open files. [#10121](https://github.com/JabRef/jabref/issues/10121)
103105
- We fixed an issue where it was not possible to select selecting content of other user's comments.[#11106](https://github.com/JabRef/jabref/issues/11106)
104106
- We fixed an issue where web search preferences "Custom API key" table modifications not discarded. [#11925](https://github.com/JabRef/jabref/issues/11925)
105107
- We fixed an issue where trying to open a library from a failed mounted directory on Mac would cause an error. [#10548](https://github.com/JabRef/jabref/issues/10548)

src/main/java/org/jabref/gui/cleanup/CleanupAction.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package org.jabref.gui.cleanup;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45
import java.util.Optional;
56
import java.util.function.Supplier;
7+
import java.util.stream.Collectors;
68

79
import javax.swing.undo.UndoManager;
810

11+
import javafx.application.Platform;
12+
913
import org.jabref.gui.DialogService;
1014
import org.jabref.gui.LibraryTab;
1115
import org.jabref.gui.StateManager;
1216
import org.jabref.gui.actions.ActionHelper;
1317
import org.jabref.gui.actions.SimpleCommand;
1418
import org.jabref.gui.undo.NamedCompound;
1519
import org.jabref.gui.undo.UndoableFieldChange;
20+
import org.jabref.logic.JabRefException;
1621
import org.jabref.logic.cleanup.CleanupPreferences;
1722
import org.jabref.logic.cleanup.CleanupWorker;
1823
import org.jabref.logic.l10n.Localization;
@@ -31,6 +36,7 @@ public class CleanupAction extends SimpleCommand {
3136
private final StateManager stateManager;
3237
private final TaskExecutor taskExecutor;
3338
private final UndoManager undoManager;
39+
private final List<JabRefException> failures;
3440

3541
private boolean isCanceled;
3642
private int modifiedEntriesCount;
@@ -47,6 +53,7 @@ public CleanupAction(Supplier<LibraryTab> tabSupplier,
4753
this.stateManager = stateManager;
4854
this.taskExecutor = taskExecutor;
4955
this.undoManager = undoManager;
56+
this.failures = new ArrayList<>();
5057

5158
this.executable.bind(ActionHelper.needsEntriesSelected(stateManager));
5259
}
@@ -105,14 +112,17 @@ private void doCleanup(BibDatabaseContext databaseContext, CleanupPreferences pr
105112
CleanupWorker cleaner = new CleanupWorker(
106113
databaseContext,
107114
preferences.getFilePreferences(),
108-
preferences.getTimestampPreferences());
115+
preferences.getTimestampPreferences()
116+
);
109117

110118
List<FieldChange> changes = cleaner.cleanup(preset, entry);
111119

112120
// Register undo action
113121
for (FieldChange change : changes) {
114122
ce.addEdit(new UndoableFieldChange(change));
115123
}
124+
125+
failures.addAll(cleaner.getFailures());
116126
}
117127

118128
private void showResults() {
@@ -135,17 +145,36 @@ private void showResults() {
135145
}
136146

137147
private void cleanup(BibDatabaseContext databaseContext, CleanupPreferences cleanupPreferences) {
148+
this.failures.clear();
149+
NamedCompound ce = new NamedCompound(Localization.lang("Cleanup entries"));
150+
138151
for (BibEntry entry : stateManager.getSelectedEntries()) {
139152
// undo granularity is on entry level
140-
NamedCompound ce = new NamedCompound(Localization.lang("Cleanup entry"));
141-
142153
doCleanup(databaseContext, cleanupPreferences, entry, ce);
143154

144-
ce.end();
145155
if (ce.hasEdits()) {
146156
modifiedEntriesCount++;
147-
undoManager.addEdit(ce);
148157
}
149158
}
159+
160+
ce.end();
161+
162+
if (ce.hasEdits()) {
163+
undoManager.addEdit(ce);
164+
}
165+
166+
if (!failures.isEmpty()) {
167+
showFailures(failures);
168+
}
169+
}
170+
171+
private void showFailures(List<JabRefException> failures) {
172+
String message = failures.stream()
173+
.map(exception -> "- " + exception.getLocalizedMessage())
174+
.collect(Collectors.joining("\n"));
175+
176+
Platform.runLater(() ->
177+
dialogService.showErrorDialogAndWait(Localization.lang("File Move Errors"), message)
178+
);
150179
}
151180
}

src/main/java/org/jabref/gui/cleanup/CleanupSingleAction.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66
import javax.swing.undo.UndoManager;
77

8+
import javafx.application.Platform;
9+
810
import org.jabref.gui.DialogService;
911
import org.jabref.gui.StateManager;
1012
import org.jabref.gui.actions.ActionHelper;
1113
import org.jabref.gui.actions.SimpleCommand;
1214
import org.jabref.gui.undo.NamedCompound;
1315
import org.jabref.gui.undo.UndoableFieldChange;
16+
import org.jabref.logic.JabRefException;
1417
import org.jabref.logic.cleanup.CleanupPreferences;
1518
import org.jabref.logic.cleanup.CleanupWorker;
1619
import org.jabref.logic.l10n.Localization;
@@ -81,14 +84,19 @@ private void doCleanup(BibDatabaseContext databaseContext, CleanupPreferences pr
8184
CleanupWorker cleaner = new CleanupWorker(
8285
databaseContext,
8386
preferences.getFilePreferences(),
84-
preferences.getTimestampPreferences());
87+
preferences.getTimestampPreferences()
88+
);
8589

8690
List<FieldChange> changes = cleaner.cleanup(preset, entry);
8791

8892
// Register undo action
8993
for (FieldChange change : changes) {
9094
ce.addEdit(new UndoableFieldChange(change));
9195
}
96+
97+
if (!cleaner.getFailures().isEmpty()) {
98+
this.showFailures(cleaner.getFailures());
99+
}
92100
}
93101

94102
private void cleanup(BibDatabaseContext databaseContext, CleanupPreferences cleanupPreferences) {
@@ -102,4 +110,14 @@ private void cleanup(BibDatabaseContext databaseContext, CleanupPreferences clea
102110
undoManager.addEdit(ce);
103111
}
104112
}
113+
114+
private void showFailures(List<JabRefException> failures) {
115+
StringBuilder sb = new StringBuilder();
116+
for (JabRefException exception : failures) {
117+
sb.append("- ").append(exception.getLocalizedMessage()).append("\n");
118+
}
119+
Platform.runLater(() ->
120+
dialogService.showErrorDialogAndWait(Localization.lang("File Move Errors"), sb.toString())
121+
);
122+
}
105123
}

src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ private JabRefGuiPreferences() {
373373

374374
// region: Main table, main table column, and search dialog column preferences
375375
defaults.put(EXTRA_FILE_COLUMNS, Boolean.FALSE);
376-
defaults.put(COLUMN_NAMES, "groups;group_icons;files;linked_id;field:entrytype;field:author/editor;field:title;field:year;field:journal/booktitle;special:ranking;special:readstatus;special:priority");
377-
defaults.put(COLUMN_WIDTHS, "28;40;28;28;75;300;470;60;130;50;50;50");
376+
defaults.put(COLUMN_NAMES, "groups;group_icons;files;linked_id;field:citationkey;field:entrytype;field:author/editor;field:title;field:year;field:journal/booktitle;special:ranking;special:readstatus;special:priority");
377+
defaults.put(COLUMN_WIDTHS, "28;40;28;28;100;75;300;470;60;130;50;50;50");
378378

379379
defaults.put(SIDE_PANE_COMPONENT_NAMES, "");
380380
defaults.put(SIDE_PANE_COMPONENT_PREFERRED_POSITIONS, "");

src/main/java/org/jabref/logic/cleanup/CleanupWorker.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Objects;
66

77
import org.jabref.logic.FilePreferences;
8+
import org.jabref.logic.JabRefException;
89
import org.jabref.logic.preferences.TimestampPreferences;
910
import org.jabref.model.FieldChange;
1011
import org.jabref.model.database.BibDatabaseContext;
@@ -15,22 +16,26 @@ public class CleanupWorker {
1516
private final BibDatabaseContext databaseContext;
1617
private final FilePreferences filePreferences;
1718
private final TimestampPreferences timestampPreferences;
19+
private final List<JabRefException> failures;
1820

1921
public CleanupWorker(BibDatabaseContext databaseContext, FilePreferences filePreferences, TimestampPreferences timestampPreferences) {
2022
this.databaseContext = databaseContext;
2123
this.filePreferences = filePreferences;
2224
this.timestampPreferences = timestampPreferences;
25+
this.failures = new ArrayList<>();
2326
}
2427

2528
public List<FieldChange> cleanup(CleanupPreferences preset, BibEntry entry) {
2629
Objects.requireNonNull(preset);
2730
Objects.requireNonNull(entry);
2831

2932
List<CleanupJob> jobs = determineCleanupActions(preset);
30-
3133
List<FieldChange> changes = new ArrayList<>();
3234
for (CleanupJob job : jobs) {
3335
changes.addAll(job.cleanup(entry));
36+
if (job instanceof MoveFilesCleanup cleanup) {
37+
failures.addAll(cleanup.getIoExceptions());
38+
}
3439
}
3540

3641
return changes;
@@ -86,4 +91,8 @@ private CleanupJob toJob(CleanupPreferences.CleanupStep action) {
8691
throw new UnsupportedOperationException(action.name());
8792
};
8893
}
94+
95+
public List<JabRefException> getFailures() {
96+
return failures;
97+
}
8998
}

src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package org.jabref.logic.cleanup;
22

33
import java.io.IOException;
4+
import java.util.ArrayList;
45
import java.util.Collections;
56
import java.util.List;
67
import java.util.Objects;
78
import java.util.Optional;
89

910
import org.jabref.logic.FilePreferences;
11+
import org.jabref.logic.JabRefException;
1012
import org.jabref.logic.externalfiles.LinkedFileHandler;
13+
import org.jabref.logic.l10n.Localization;
1114
import org.jabref.model.FieldChange;
1215
import org.jabref.model.database.BibDatabaseContext;
1316
import org.jabref.model.entry.BibEntry;
@@ -26,10 +29,12 @@ public class MoveFilesCleanup implements CleanupJob {
2629

2730
private final BibDatabaseContext databaseContext;
2831
private final FilePreferences filePreferences;
32+
private final List<JabRefException> ioExceptions;
2933

3034
public MoveFilesCleanup(BibDatabaseContext databaseContext, FilePreferences filePreferences) {
3135
this.databaseContext = Objects.requireNonNull(databaseContext);
3236
this.filePreferences = Objects.requireNonNull(filePreferences);
37+
this.ioExceptions = new ArrayList<>();
3338
}
3439

3540
@Override
@@ -43,6 +48,7 @@ public List<FieldChange> cleanup(BibEntry entry) {
4348
changed = fileHandler.moveToDefaultDirectory() || changed;
4449
} catch (IOException exception) {
4550
LOGGER.error("Error while moving file {}", file.getLink(), exception);
51+
ioExceptions.add(new JabRefException(Localization.lang("Could not move file %0. Please close this file and retry.", file.getLink()), exception));
4652
}
4753
}
4854

@@ -53,4 +59,8 @@ public List<FieldChange> cleanup(BibEntry entry) {
5359

5460
return Collections.emptyList();
5561
}
62+
63+
public List<JabRefException> getIoExceptions() {
64+
return ioExceptions;
65+
}
5666
}

src/main/resources/l10n/JabRef_en.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,3 +2804,6 @@ Store\ url\ for\ downloaded\ file=Store url for downloaded file
28042804
Compare\ with\ existing\ entry=Compare with existing entry
28052805
Library\ Entry=Library Entry
28062806
Citation\ Entry=Citation Entry
2807+
2808+
File\ Move\ Errors=File Move Errors
2809+
Could\ not\ move\ file\ %0.\ Please\ close\ this\ file\ and\ retry.=Could not move file %0. Please close this file and retry.

0 commit comments

Comments
 (0)