Skip to content

Commit

Permalink
Merge branch 'main' into 11219-adapt-ui-font-size
Browse files Browse the repository at this point in the history
  • Loading branch information
harry924 authored Oct 26, 2024
2 parents 50fef5f + 982aeb1 commit 206ec49
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
PR_NUMBER=$(cat pr_number.txt)
echo "Read PR number $PR_NUMBER"
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
- name: Determine owner
if: ${{ steps.read-pr_number.outputs.pr_number != '' }}
id: owner
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
export PATH=$PATH:$HOME/.jbang/bin
# run heylogs verification
jbang com.github.nbbrd.heylogs:heylogs-cli:0.7.2:bin check CHANGELOG.md > heylogs.txt || true
jbang com.github.nbbrd.heylogs:heylogs-cli:0.9.2:bin check CHANGELOG.md > heylogs.txt || true
# improve output
sed -i 's/all-h2-contain-a-version/all-h2-contain-a-version (ignored)/' heylogs.txt
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added a new CSS style class `main-table` for the main table. [#11881](https://github.com/JabRef/jabref/pull/11881)
- 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)
- 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)
- The CitationKey column is now a default shown column for the entry table. [#10510](https://github.com/JabRef/jabref/issues/10510)

### Fixed

Expand Down Expand Up @@ -99,6 +100,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where recently opened files were not displayed in the main menu properly. [#9042](https://github.com/JabRef/jabref/issues/9042)
- 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)
- 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)
- We fixed an issue where we display warning message for moving attached open files. [#10121](https://github.com/JabRef/jabref/issues/10121)
- 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)
- We fixed an issue where web search preferences "Custom API key" table modifications not discarded. [#11925](https://github.com/JabRef/jabref/issues/11925)
- 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)
Expand Down
39 changes: 34 additions & 5 deletions src/main/java/org/jabref/gui/cleanup/CleanupAction.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package org.jabref.gui.cleanup;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import javax.swing.undo.UndoManager;

import javafx.application.Platform;

import org.jabref.gui.DialogService;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.logic.JabRefException;
import org.jabref.logic.cleanup.CleanupPreferences;
import org.jabref.logic.cleanup.CleanupWorker;
import org.jabref.logic.l10n.Localization;
Expand All @@ -31,6 +36,7 @@ public class CleanupAction extends SimpleCommand {
private final StateManager stateManager;
private final TaskExecutor taskExecutor;
private final UndoManager undoManager;
private final List<JabRefException> failures;

private boolean isCanceled;
private int modifiedEntriesCount;
Expand All @@ -47,6 +53,7 @@ public CleanupAction(Supplier<LibraryTab> tabSupplier,
this.stateManager = stateManager;
this.taskExecutor = taskExecutor;
this.undoManager = undoManager;
this.failures = new ArrayList<>();

this.executable.bind(ActionHelper.needsEntriesSelected(stateManager));
}
Expand Down Expand Up @@ -105,14 +112,17 @@ private void doCleanup(BibDatabaseContext databaseContext, CleanupPreferences pr
CleanupWorker cleaner = new CleanupWorker(
databaseContext,
preferences.getFilePreferences(),
preferences.getTimestampPreferences());
preferences.getTimestampPreferences()
);

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

// Register undo action
for (FieldChange change : changes) {
ce.addEdit(new UndoableFieldChange(change));
}

failures.addAll(cleaner.getFailures());
}

private void showResults() {
Expand All @@ -135,17 +145,36 @@ private void showResults() {
}

private void cleanup(BibDatabaseContext databaseContext, CleanupPreferences cleanupPreferences) {
this.failures.clear();
NamedCompound ce = new NamedCompound(Localization.lang("Cleanup entries"));

for (BibEntry entry : stateManager.getSelectedEntries()) {
// undo granularity is on entry level
NamedCompound ce = new NamedCompound(Localization.lang("Cleanup entry"));

doCleanup(databaseContext, cleanupPreferences, entry, ce);

ce.end();
if (ce.hasEdits()) {
modifiedEntriesCount++;
undoManager.addEdit(ce);
}
}

ce.end();

if (ce.hasEdits()) {
undoManager.addEdit(ce);
}

if (!failures.isEmpty()) {
showFailures(failures);
}
}

private void showFailures(List<JabRefException> failures) {
String message = failures.stream()
.map(exception -> "- " + exception.getLocalizedMessage())
.collect(Collectors.joining("\n"));

Platform.runLater(() ->
dialogService.showErrorDialogAndWait(Localization.lang("File Move Errors"), message)
);
}
}
20 changes: 19 additions & 1 deletion src/main/java/org/jabref/gui/cleanup/CleanupSingleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

import javax.swing.undo.UndoManager;

import javafx.application.Platform;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.logic.JabRefException;
import org.jabref.logic.cleanup.CleanupPreferences;
import org.jabref.logic.cleanup.CleanupWorker;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -81,14 +84,19 @@ private void doCleanup(BibDatabaseContext databaseContext, CleanupPreferences pr
CleanupWorker cleaner = new CleanupWorker(
databaseContext,
preferences.getFilePreferences(),
preferences.getTimestampPreferences());
preferences.getTimestampPreferences()
);

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

// Register undo action
for (FieldChange change : changes) {
ce.addEdit(new UndoableFieldChange(change));
}

if (!cleaner.getFailures().isEmpty()) {
this.showFailures(cleaner.getFailures());
}
}

private void cleanup(BibDatabaseContext databaseContext, CleanupPreferences cleanupPreferences) {
Expand All @@ -102,4 +110,14 @@ private void cleanup(BibDatabaseContext databaseContext, CleanupPreferences clea
undoManager.addEdit(ce);
}
}

private void showFailures(List<JabRefException> failures) {
StringBuilder sb = new StringBuilder();
for (JabRefException exception : failures) {
sb.append("- ").append(exception.getLocalizedMessage()).append("\n");
}
Platform.runLater(() ->
dialogService.showErrorDialogAndWait(Localization.lang("File Move Errors"), sb.toString())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ private JabRefGuiPreferences() {

// region: Main table, main table column, and search dialog column preferences
defaults.put(EXTRA_FILE_COLUMNS, Boolean.FALSE);
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");
defaults.put(COLUMN_WIDTHS, "28;40;28;28;75;300;470;60;130;50;50;50");
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");
defaults.put(COLUMN_WIDTHS, "28;40;28;28;100;75;300;470;60;130;50;50;50");

defaults.put(SIDE_PANE_COMPONENT_NAMES, "");
defaults.put(SIDE_PANE_COMPONENT_PREFERRED_POSITIONS, "");
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/jabref/logic/cleanup/CleanupWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Objects;

import org.jabref.logic.FilePreferences;
import org.jabref.logic.JabRefException;
import org.jabref.logic.preferences.TimestampPreferences;
import org.jabref.model.FieldChange;
import org.jabref.model.database.BibDatabaseContext;
Expand All @@ -15,22 +16,26 @@ public class CleanupWorker {
private final BibDatabaseContext databaseContext;
private final FilePreferences filePreferences;
private final TimestampPreferences timestampPreferences;
private final List<JabRefException> failures;

public CleanupWorker(BibDatabaseContext databaseContext, FilePreferences filePreferences, TimestampPreferences timestampPreferences) {
this.databaseContext = databaseContext;
this.filePreferences = filePreferences;
this.timestampPreferences = timestampPreferences;
this.failures = new ArrayList<>();
}

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

List<CleanupJob> jobs = determineCleanupActions(preset);

List<FieldChange> changes = new ArrayList<>();
for (CleanupJob job : jobs) {
changes.addAll(job.cleanup(entry));
if (job instanceof MoveFilesCleanup cleanup) {
failures.addAll(cleanup.getIoExceptions());
}
}

return changes;
Expand Down Expand Up @@ -86,4 +91,8 @@ private CleanupJob toJob(CleanupPreferences.CleanupStep action) {
throw new UnsupportedOperationException(action.name());
};
}

public List<JabRefException> getFailures() {
return failures;
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.jabref.logic.cleanup;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.jabref.logic.FilePreferences;
import org.jabref.logic.JabRefException;
import org.jabref.logic.externalfiles.LinkedFileHandler;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.FieldChange;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -26,10 +29,12 @@ public class MoveFilesCleanup implements CleanupJob {

private final BibDatabaseContext databaseContext;
private final FilePreferences filePreferences;
private final List<JabRefException> ioExceptions;

public MoveFilesCleanup(BibDatabaseContext databaseContext, FilePreferences filePreferences) {
this.databaseContext = Objects.requireNonNull(databaseContext);
this.filePreferences = Objects.requireNonNull(filePreferences);
this.ioExceptions = new ArrayList<>();
}

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

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

return Collections.emptyList();
}

public List<JabRefException> getIoExceptions() {
return ioExceptions;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2800,3 +2800,6 @@ Store\ url\ for\ downloaded\ file=Store url for downloaded file
Compare\ with\ existing\ entry=Compare with existing entry
Library\ Entry=Library Entry
Citation\ Entry=Citation Entry
File\ Move\ Errors=File Move Errors
Could\ not\ move\ file\ %0.\ Please\ close\ this\ file\ and\ retry.=Could not move file %0. Please close this file and retry.

0 comments on commit 206ec49

Please sign in to comment.