From c58fcddb46e4d35cfe682b91af8f98a88fbf65d7 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Sat, 5 Jun 2021 11:40:26 +0200 Subject: [PATCH 01/13] Added auto-key-generation task to task-progress Auto-key-generation tasks are now shown in the list of background tasks, together with a progress representing entries done / entries. Fixes koppor/jabref#7267 --- CHANGELOG.md | 1 + .../GenerateCitationKeyAction.java | 21 ++++++++++++++++--- .../org/jabref/gui/util/BackgroundTask.java | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f346511957..16142b666ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We added a feature that allows the user to choose whether to trust the target site when unable to find a valid certification path from the file download site. [#7616](https://github.com/JabRef/jabref/issues/7616) - We added a feature that allows the user to open all linked files of multiple selected entries by "Open file" option. [#6966](https://github.com/JabRef/jabref/issues/6966) - We added a keybinding preset for new entries. [#7705](https://github.com/JabRef/jabref/issues/7705) +- We added auto-key-generation progress to the background task list. [#7267](https://github.com/JabRef/jabref/issues/7267) ### Changed diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 0c52d0374df..75d7059a412 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -2,6 +2,9 @@ import java.util.List; +import javafx.beans.property.Property; +import javafx.beans.property.SimpleObjectProperty; + import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; @@ -45,8 +48,17 @@ public void execute() { checkOverwriteKeysChosen(); - BackgroundTask.wrap(this::generateKeys) - .executeWith(Globals.TASK_EXECUTOR); + if (!this.isCanceled) { + Property backgroundProgressProperty = new SimpleObjectProperty<>(new BackgroundTask.BackgroundProgress(0, entries.size())); + BackgroundTask backgroundTask = BackgroundTask.wrap(() -> { + this.generateKeys(backgroundProgressProperty); + }); + backgroundTask.showToUser(true); + backgroundTask.titleProperty().set(Localization.lang("Autogenerate citation keys")); + backgroundTask.messageProperty().set(entries.size() + " " + Localization.lang("entries")); + backgroundTask.progressProperty().bindBidirectional(backgroundProgressProperty); + backgroundTask.executeWith(Globals.TASK_EXECUTOR); + } } public static boolean confirmOverwriteKeys(DialogService dialogService) { @@ -80,7 +92,7 @@ private void checkOverwriteKeysChosen() { } } - private void generateKeys() { + private void generateKeys(Property backgroundProgressProperty) { if (isCanceled) { return; } @@ -90,9 +102,12 @@ private void generateKeys() { final NamedCompound compound = new NamedCompound(Localization.lang("Autogenerate citation keys")); CitationKeyGenerator keyGenerator = new CitationKeyGenerator(databaseContext, Globals.prefs.getCitationKeyPatternPreferences()); + int entriesDone = 0; for (BibEntry entry : entries) { keyGenerator.generateAndSetKey(entry) .ifPresent(fieldChange -> compound.addEdit(new UndoableKeyChange(fieldChange))); + entriesDone++; + backgroundProgressProperty.setValue(new BackgroundTask.BackgroundProgress(entriesDone, entries.size())); } compound.end(); diff --git a/src/main/java/org/jabref/gui/util/BackgroundTask.java b/src/main/java/org/jabref/gui/util/BackgroundTask.java index 9c9626354d1..3aaedad406c 100644 --- a/src/main/java/org/jabref/gui/util/BackgroundTask.java +++ b/src/main/java/org/jabref/gui/util/BackgroundTask.java @@ -261,7 +261,7 @@ public static Node getIcon(Task task) { return BackgroundTask.iconMap.getOrDefault(task.getTitle(), null); } - static class BackgroundProgress { + public static class BackgroundProgress { private final double workDone; private final double max; From 20530a283b1fb205d994d92319a9614fbfc88051 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Sat, 5 Jun 2021 13:41:16 +0200 Subject: [PATCH 02/13] Run progress-update on JavaFX Thread --- .../gui/citationkeypattern/GenerateCitationKeyAction.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 75d7059a412..e2682e1738d 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -14,6 +14,7 @@ import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableKeyChange; import org.jabref.gui.util.BackgroundTask; +import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.citationkeypattern.CitationKeyGenerator; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; @@ -107,7 +108,10 @@ private void generateKeys(Property background keyGenerator.generateAndSetKey(entry) .ifPresent(fieldChange -> compound.addEdit(new UndoableKeyChange(fieldChange))); entriesDone++; - backgroundProgressProperty.setValue(new BackgroundTask.BackgroundProgress(entriesDone, entries.size())); + int finalEntriesDone = entriesDone; + DefaultTaskExecutor.runInJavaFXThread(() -> { + backgroundProgressProperty.setValue(new BackgroundTask.BackgroundProgress(finalEntriesDone, entries.size())); + }); } compound.end(); From 09a9cdf60429b35b0133dd068d92eb7dac5056f4 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Sun, 6 Jun 2021 12:05:24 +0200 Subject: [PATCH 03/13] Created anonymous class for background task To simplify thread synchronization, the background task is now wrapped in an anonymous class, just as in https://github.com/JabRef/jabref/blob/fa8cc829727ffddd97a9056fd466e7098577f4d7/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java --- .../GenerateCitationKeyAction.java | 80 ++++++++++--------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index e2682e1738d..822d2167d2f 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -50,14 +50,7 @@ public void execute() { checkOverwriteKeysChosen(); if (!this.isCanceled) { - Property backgroundProgressProperty = new SimpleObjectProperty<>(new BackgroundTask.BackgroundProgress(0, entries.size())); - BackgroundTask backgroundTask = BackgroundTask.wrap(() -> { - this.generateKeys(backgroundProgressProperty); - }); - backgroundTask.showToUser(true); - backgroundTask.titleProperty().set(Localization.lang("Autogenerate citation keys")); - backgroundTask.messageProperty().set(entries.size() + " " + Localization.lang("entries")); - backgroundTask.progressProperty().bindBidirectional(backgroundProgressProperty); + BackgroundTask backgroundTask = this.generateKeysInBackground(); backgroundTask.executeWith(Globals.TASK_EXECUTOR); } } @@ -93,36 +86,51 @@ private void checkOverwriteKeysChosen() { } } - private void generateKeys(Property backgroundProgressProperty) { - if (isCanceled) { - return; - } - - stateManager.getActiveDatabase().ifPresent(databaseContext -> { - // generate the new citation keys for each entry - final NamedCompound compound = new NamedCompound(Localization.lang("Autogenerate citation keys")); - CitationKeyGenerator keyGenerator = - new CitationKeyGenerator(databaseContext, Globals.prefs.getCitationKeyPatternPreferences()); - int entriesDone = 0; - for (BibEntry entry : entries) { - keyGenerator.generateAndSetKey(entry) - .ifPresent(fieldChange -> compound.addEdit(new UndoableKeyChange(fieldChange))); - entriesDone++; - int finalEntriesDone = entriesDone; - DefaultTaskExecutor.runInJavaFXThread(() -> { - backgroundProgressProperty.setValue(new BackgroundTask.BackgroundProgress(finalEntriesDone, entries.size())); - }); - } - compound.end(); - - // register the undo event only if new citation keys were generated - if (compound.hasEdits()) { - frame.getUndoManager().addEdit(compound); + private BackgroundTask generateKeysInBackground() { + return new BackgroundTask() { + + @Override + protected Void call() { + + if (isCanceled) { + return null; + } + showToUser(true); + titleProperty().set(Localization.lang("Autogenerate citation keys")); + messageProperty().set(entries.size() + " " + Localization.lang("entries")); + + DefaultTaskExecutor.runInJavaFXThread(() -> { + updateProgress(0, entries.size()); + }); + stateManager.getActiveDatabase().ifPresent(databaseContext -> { + // generate the new citation keys for each entry + final NamedCompound compound = new NamedCompound(Localization.lang("Autogenerate citation keys")); + CitationKeyGenerator keyGenerator = + new CitationKeyGenerator(databaseContext, Globals.prefs.getCitationKeyPatternPreferences()); + int entriesDone = 0; + for (BibEntry entry : entries) { + keyGenerator.generateAndSetKey(entry) + .ifPresent(fieldChange -> compound.addEdit(new UndoableKeyChange(fieldChange))); + entriesDone++; + int finalEntriesDone = entriesDone; + DefaultTaskExecutor.runInJavaFXThread(() -> { + updateProgress(finalEntriesDone, entries.size()); + }); + } + compound.end(); + + // register the undo event only if new citation keys were generated + if (compound.hasEdits()) { + frame.getUndoManager().addEdit(compound); + } + + frame.getCurrentLibraryTab().markBaseChanged(); + dialogService.notify(formatOutputMessage(Localization.lang("Generated citation key for"), entries.size())); + }); + return null; } + }; - frame.getCurrentLibraryTab().markBaseChanged(); - dialogService.notify(formatOutputMessage(Localization.lang("Generated citation key for"), entries.size())); - }); } private String formatOutputMessage(String start, int count) { From d3e1334cabc2b508788c95425a36dcfa4a60f652 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Sun, 6 Jun 2021 12:11:59 +0200 Subject: [PATCH 04/13] Checkstyle fix --- .../gui/citationkeypattern/GenerateCitationKeyAction.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 822d2167d2f..2f6546dd5d9 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -2,9 +2,6 @@ import java.util.List; -import javafx.beans.property.Property; -import javafx.beans.property.SimpleObjectProperty; - import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; From 258b26ae81e0850c6f516e11e4cd931499d9c2de Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Sun, 6 Jun 2021 13:49:58 +0200 Subject: [PATCH 05/13] Fixes for JavaFX concurrency UI-facing properties are done on correct task now, and onSuccess is used. --- .../GenerateCitationKeyAction.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 2f6546dd5d9..d88bfb422cd 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -1,6 +1,7 @@ package org.jabref.gui.citationkeypattern; import java.util.List; +import java.util.function.Consumer; import org.jabref.gui.DialogService; import org.jabref.gui.Globals; @@ -48,6 +49,10 @@ public void execute() { if (!this.isCanceled) { BackgroundTask backgroundTask = this.generateKeysInBackground(); + backgroundTask.showToUser(true); + backgroundTask.titleProperty().set(Localization.lang("Autogenerate citation keys")); + backgroundTask.messageProperty().set(entries.size() + " " + Localization.lang("entries")); + backgroundTask.executeWith(Globals.TASK_EXECUTOR); } } @@ -86,22 +91,19 @@ private void checkOverwriteKeysChosen() { private BackgroundTask generateKeysInBackground() { return new BackgroundTask() { + private NamedCompound compound; + @Override protected Void call() { - if (isCanceled) { return null; } - showToUser(true); - titleProperty().set(Localization.lang("Autogenerate citation keys")); - messageProperty().set(entries.size() + " " + Localization.lang("entries")); - DefaultTaskExecutor.runInJavaFXThread(() -> { updateProgress(0, entries.size()); }); stateManager.getActiveDatabase().ifPresent(databaseContext -> { // generate the new citation keys for each entry - final NamedCompound compound = new NamedCompound(Localization.lang("Autogenerate citation keys")); + compound = new NamedCompound(Localization.lang("Autogenerate citation keys")); CitationKeyGenerator keyGenerator = new CitationKeyGenerator(databaseContext, Globals.prefs.getCitationKeyPatternPreferences()); int entriesDone = 0; @@ -115,17 +117,21 @@ protected Void call() { }); } compound.end(); - - // register the undo event only if new citation keys were generated - if (compound.hasEdits()) { - frame.getUndoManager().addEdit(compound); - } - - frame.getCurrentLibraryTab().markBaseChanged(); - dialogService.notify(formatOutputMessage(Localization.lang("Generated citation key for"), entries.size())); }); return null; } + + @Override + public BackgroundTask onSuccess(Consumer onSuccess) { + // register the undo event only if new citation keys were generated + if (compound.hasEdits()) { + frame.getUndoManager().addEdit(compound); + } + + frame.getCurrentLibraryTab().markBaseChanged(); + dialogService.notify(formatOutputMessage(Localization.lang("Generated citation key for"), entries.size())); + return super.onSuccess(onSuccess); + } }; } From db726408005b8d3ad679aa1a015c9b7170760b94 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Mon, 7 Jun 2021 20:04:39 +0200 Subject: [PATCH 06/13] Reverted making BackgroundProgress public --- src/main/java/org/jabref/gui/util/BackgroundTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/util/BackgroundTask.java b/src/main/java/org/jabref/gui/util/BackgroundTask.java index 3aaedad406c..f50031e7c52 100644 --- a/src/main/java/org/jabref/gui/util/BackgroundTask.java +++ b/src/main/java/org/jabref/gui/util/BackgroundTask.java @@ -261,7 +261,7 @@ public static Node getIcon(Task task) { return BackgroundTask.iconMap.getOrDefault(task.getTitle(), null); } - public static class BackgroundProgress { + private static class BackgroundProgress { private final double workDone; private final double max; From 357219d08abdd811134d8419d0f020e27e0a2ec6 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Mon, 7 Jun 2021 20:08:19 +0200 Subject: [PATCH 07/13] Revert "Reverted making BackgroundProgress public" This reverts commit db726408005b8d3ad679aa1a015c9b7170760b94. --- src/main/java/org/jabref/gui/util/BackgroundTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/util/BackgroundTask.java b/src/main/java/org/jabref/gui/util/BackgroundTask.java index f50031e7c52..3aaedad406c 100644 --- a/src/main/java/org/jabref/gui/util/BackgroundTask.java +++ b/src/main/java/org/jabref/gui/util/BackgroundTask.java @@ -261,7 +261,7 @@ public static Node getIcon(Task task) { return BackgroundTask.iconMap.getOrDefault(task.getTitle(), null); } - private static class BackgroundProgress { + public static class BackgroundProgress { private final double workDone; private final double max; From 99709662956a214847247ca1bec6b6013ab31e68 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Tue, 8 Jun 2021 08:14:20 +0200 Subject: [PATCH 08/13] Actually reverted making BackgroundProgress public --- src/main/java/org/jabref/gui/util/BackgroundTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/util/BackgroundTask.java b/src/main/java/org/jabref/gui/util/BackgroundTask.java index 3aaedad406c..9c9626354d1 100644 --- a/src/main/java/org/jabref/gui/util/BackgroundTask.java +++ b/src/main/java/org/jabref/gui/util/BackgroundTask.java @@ -261,7 +261,7 @@ public static Node getIcon(Task task) { return BackgroundTask.iconMap.getOrDefault(task.getTitle(), null); } - public static class BackgroundProgress { + static class BackgroundProgress { private final double workDone; private final double max; From 721a9f1c9db1431d8f19a99e3f1d74065345f475 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Tue, 8 Jun 2021 08:27:11 +0200 Subject: [PATCH 09/13] Better message (and correct localization usage) --- .../gui/citationkeypattern/GenerateCitationKeyAction.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index d88bfb422cd..8efd61b95e5 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -51,7 +51,7 @@ public void execute() { BackgroundTask backgroundTask = this.generateKeysInBackground(); backgroundTask.showToUser(true); backgroundTask.titleProperty().set(Localization.lang("Autogenerate citation keys")); - backgroundTask.messageProperty().set(entries.size() + " " + Localization.lang("entries")); + backgroundTask.messageProperty().set(Localization.lang("0/%0 entries", entries.size())); backgroundTask.executeWith(Globals.TASK_EXECUTOR); } @@ -100,6 +100,7 @@ protected Void call() { } DefaultTaskExecutor.runInJavaFXThread(() -> { updateProgress(0, entries.size()); + messageProperty().set(Localization.lang("0/%0 entries", entries.size())); }); stateManager.getActiveDatabase().ifPresent(databaseContext -> { // generate the new citation keys for each entry @@ -114,6 +115,7 @@ protected Void call() { int finalEntriesDone = entriesDone; DefaultTaskExecutor.runInJavaFXThread(() -> { updateProgress(finalEntriesDone, entries.size()); + messageProperty().set(Localization.lang("%0/%1 entries", finalEntriesDone, entries.size())); }); } compound.end(); From 18581e4d3e5af11d4ab176bb4e588ae11fb7f8fd Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Tue, 8 Jun 2021 08:31:01 +0200 Subject: [PATCH 10/13] Removed progress from message Some languages place the number after the word 'counter', this would result in an ugly message for those languages. --- .../gui/citationkeypattern/GenerateCitationKeyAction.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 8efd61b95e5..4a42c669923 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -51,7 +51,7 @@ public void execute() { BackgroundTask backgroundTask = this.generateKeysInBackground(); backgroundTask.showToUser(true); backgroundTask.titleProperty().set(Localization.lang("Autogenerate citation keys")); - backgroundTask.messageProperty().set(Localization.lang("0/%0 entries", entries.size())); + backgroundTask.messageProperty().set(Localization.lang("%0 entries", entries.size())); backgroundTask.executeWith(Globals.TASK_EXECUTOR); } @@ -100,7 +100,7 @@ protected Void call() { } DefaultTaskExecutor.runInJavaFXThread(() -> { updateProgress(0, entries.size()); - messageProperty().set(Localization.lang("0/%0 entries", entries.size())); + messageProperty().set(Localization.lang("%0 entries", entries.size())); }); stateManager.getActiveDatabase().ifPresent(databaseContext -> { // generate the new citation keys for each entry @@ -115,7 +115,7 @@ protected Void call() { int finalEntriesDone = entriesDone; DefaultTaskExecutor.runInJavaFXThread(() -> { updateProgress(finalEntriesDone, entries.size()); - messageProperty().set(Localization.lang("%0/%1 entries", finalEntriesDone, entries.size())); + messageProperty().set(Localization.lang("%0 entries", entries.size())); }); } compound.end(); From f5e67b18951a239a4b3b4676811762c08046234c Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Tue, 8 Jun 2021 10:31:47 +0200 Subject: [PATCH 11/13] Fixed localization --- .../gui/citationkeypattern/GenerateCitationKeyAction.java | 6 +++--- src/main/resources/l10n/JabRef_en.properties | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 4a42c669923..4ee27b5d3dc 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -51,7 +51,7 @@ public void execute() { BackgroundTask backgroundTask = this.generateKeysInBackground(); backgroundTask.showToUser(true); backgroundTask.titleProperty().set(Localization.lang("Autogenerate citation keys")); - backgroundTask.messageProperty().set(Localization.lang("%0 entries", entries.size())); + backgroundTask.messageProperty().set(Localization.lang("%0/%1 entries", 0, entries.size())); backgroundTask.executeWith(Globals.TASK_EXECUTOR); } @@ -100,7 +100,7 @@ protected Void call() { } DefaultTaskExecutor.runInJavaFXThread(() -> { updateProgress(0, entries.size()); - messageProperty().set(Localization.lang("%0 entries", entries.size())); + messageProperty().set(Localization.lang("%0/%1 entries", 0, entries.size())); }); stateManager.getActiveDatabase().ifPresent(databaseContext -> { // generate the new citation keys for each entry @@ -115,7 +115,7 @@ protected Void call() { int finalEntriesDone = entriesDone; DefaultTaskExecutor.runInJavaFXThread(() -> { updateProgress(finalEntriesDone, entries.size()); - messageProperty().set(Localization.lang("%0 entries", entries.size())); + messageProperty().set(Localization.lang("%0/%1 entries", finalEntriesDone, entries.size())); }); } compound.end(); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 0d5281b27a2..f1c5c40c1d1 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -7,6 +7,8 @@ Unable\ to\ monitor\ file\ changes.\ Please\ close\ files\ and\ processes\ and\ %0\ doesn't\ contain\ the\ term\ %1=%0 doesn't contain the term %1 +%0/%1\ entries=%0/%1 entries + %0\ export\ successful=%0 export successful %0\ matches\ the\ regular\ expression\ %1=%0 matches the regular expression %1 From 3b0dfed26ee6d257224c387a4c9cc1fa78259d35 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Tue, 8 Jun 2021 10:38:07 +0200 Subject: [PATCH 12/13] Pass TaskExecutor instead of using Globals --- src/main/java/org/jabref/gui/JabRefFrame.java | 4 ++-- .../gui/citationkeypattern/GenerateCitationKeyAction.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index ecbb1fa02c6..4ba6255d082 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -506,7 +506,7 @@ private Node createToolbar() { new HBox( pushToApplicationButton, - factory.createIconButton(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(this, dialogService, stateManager)), + factory.createIconButton(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(this, dialogService, stateManager, taskExecutor)), factory.createIconButton(StandardActions.CLEANUP_ENTRIES, new CleanupAction(this, prefs, dialogService, stateManager)) ), @@ -727,7 +727,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), factory.createMenuItem(StandardActions.REPLACE_ALL, new ReplaceStringAction(this, stateManager)), - factory.createMenuItem(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(this, dialogService, stateManager)), + factory.createMenuItem(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(this, dialogService, stateManager, taskExecutor)), new SeparatorMenuItem(), diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 4ee27b5d3dc..06d692d94c6 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -13,6 +13,7 @@ import org.jabref.gui.undo.UndoableKeyChange; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.DefaultTaskExecutor; +import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.citationkeypattern.CitationKeyGenerator; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; @@ -26,10 +27,13 @@ public class GenerateCitationKeyAction extends SimpleCommand { private List entries; private boolean isCanceled; - public GenerateCitationKeyAction(JabRefFrame frame, DialogService dialogService, StateManager stateManager) { + private TaskExecutor taskExecutor; + + public GenerateCitationKeyAction(JabRefFrame frame, DialogService dialogService, StateManager stateManager, TaskExecutor taskExecutor) { this.frame = frame; this.dialogService = dialogService; this.stateManager = stateManager; + this.taskExecutor = taskExecutor; this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); } @@ -53,7 +57,7 @@ public void execute() { backgroundTask.titleProperty().set(Localization.lang("Autogenerate citation keys")); backgroundTask.messageProperty().set(Localization.lang("%0/%1 entries", 0, entries.size())); - backgroundTask.executeWith(Globals.TASK_EXECUTOR); + backgroundTask.executeWith(this.taskExecutor); } } From ff6e55fbd6e335f3e2dcd489293ca90627b0fe1b Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Wed, 9 Jun 2021 09:54:46 +0200 Subject: [PATCH 13/13] Removed dependency on Globals --- src/main/java/org/jabref/gui/JabRefFrame.java | 4 ++-- .../GenerateCitationKeyAction.java | 22 ++++++++++--------- .../GenerateCitationKeySingleAction.java | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 4ba6255d082..ee01c038883 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -506,7 +506,7 @@ private Node createToolbar() { new HBox( pushToApplicationButton, - factory.createIconButton(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(this, dialogService, stateManager, taskExecutor)), + factory.createIconButton(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(this, dialogService, stateManager, taskExecutor, prefs)), factory.createIconButton(StandardActions.CLEANUP_ENTRIES, new CleanupAction(this, prefs, dialogService, stateManager)) ), @@ -727,7 +727,7 @@ private MenuBar createMenu() { new SeparatorMenuItem(), factory.createMenuItem(StandardActions.REPLACE_ALL, new ReplaceStringAction(this, stateManager)), - factory.createMenuItem(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(this, dialogService, stateManager, taskExecutor)), + factory.createMenuItem(StandardActions.GENERATE_CITE_KEYS, new GenerateCitationKeyAction(this, dialogService, stateManager, taskExecutor, prefs)), new SeparatorMenuItem(), diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java index 06d692d94c6..b70d511dd64 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeyAction.java @@ -4,7 +4,6 @@ import java.util.function.Consumer; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.JabRefFrame; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionHelper; @@ -17,6 +16,7 @@ import org.jabref.logic.citationkeypattern.CitationKeyGenerator; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; +import org.jabref.preferences.PreferencesService; public class GenerateCitationKeyAction extends SimpleCommand { @@ -27,13 +27,15 @@ public class GenerateCitationKeyAction extends SimpleCommand { private List entries; private boolean isCanceled; - private TaskExecutor taskExecutor; + private final TaskExecutor taskExecutor; + private final PreferencesService preferencesService; - public GenerateCitationKeyAction(JabRefFrame frame, DialogService dialogService, StateManager stateManager, TaskExecutor taskExecutor) { + public GenerateCitationKeyAction(JabRefFrame frame, DialogService dialogService, StateManager stateManager, TaskExecutor taskExecutor, PreferencesService preferencesService) { this.frame = frame; this.dialogService = dialogService; this.stateManager = stateManager; this.taskExecutor = taskExecutor; + this.preferencesService = preferencesService; this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); } @@ -61,16 +63,16 @@ public void execute() { } } - public static boolean confirmOverwriteKeys(DialogService dialogService) { - if (Globals.prefs.getCitationKeyPatternPreferences().shouldWarnBeforeOverwriteCiteKey()) { + public static boolean confirmOverwriteKeys(DialogService dialogService, PreferencesService preferencesService) { + if (preferencesService.getCitationKeyPatternPreferences().shouldWarnBeforeOverwriteCiteKey()) { return dialogService.showConfirmationDialogWithOptOutAndWait( Localization.lang("Overwrite keys"), Localization.lang("One or more keys will be overwritten. Continue?"), Localization.lang("Overwrite keys"), Localization.lang("Cancel"), Localization.lang("Do not ask again"), - optOut -> Globals.prefs.storeCitationKeyPatternPreferences( - Globals.prefs.getCitationKeyPatternPreferences().withWarnBeforeOverwriteCiteKey(!optOut))); + optOut -> preferencesService.storeCitationKeyPatternPreferences( + preferencesService.getCitationKeyPatternPreferences().withWarnBeforeOverwriteCiteKey(!optOut))); } else { // Always overwrite keys by default return true; @@ -79,11 +81,11 @@ public static boolean confirmOverwriteKeys(DialogService dialogService) { private void checkOverwriteKeysChosen() { // We don't want to generate keys for entries which already have one thus remove the entries - if (Globals.prefs.getCitationKeyPatternPreferences().shouldAvoidOverwriteCiteKey()) { + if (this.preferencesService.getCitationKeyPatternPreferences().shouldAvoidOverwriteCiteKey()) { entries.removeIf(BibEntry::hasCitationKey); // if we're going to override some citation keys warn the user about it } else if (entries.parallelStream().anyMatch(BibEntry::hasCitationKey)) { - boolean overwriteKeys = confirmOverwriteKeys(dialogService); + boolean overwriteKeys = confirmOverwriteKeys(dialogService, this.preferencesService); // The user doesn't want to override citation keys if (!overwriteKeys) { @@ -110,7 +112,7 @@ protected Void call() { // generate the new citation keys for each entry compound = new NamedCompound(Localization.lang("Autogenerate citation keys")); CitationKeyGenerator keyGenerator = - new CitationKeyGenerator(databaseContext, Globals.prefs.getCitationKeyPatternPreferences()); + new CitationKeyGenerator(databaseContext, preferencesService.getCitationKeyPatternPreferences()); int entriesDone = 0; for (BibEntry entry : entries) { keyGenerator.generateAndSetKey(entry) diff --git a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeySingleAction.java b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeySingleAction.java index b66beef36be..04678963e34 100644 --- a/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeySingleAction.java +++ b/src/main/java/org/jabref/gui/citationkeypattern/GenerateCitationKeySingleAction.java @@ -32,7 +32,7 @@ public GenerateCitationKeySingleAction(BibEntry entry, BibDatabaseContext databa @Override public void execute() { - if (!entry.hasCitationKey() || GenerateCitationKeyAction.confirmOverwriteKeys(dialogService)) { + if (!entry.hasCitationKey() || GenerateCitationKeyAction.confirmOverwriteKeys(dialogService, preferencesService)) { new CitationKeyGenerator(databaseContext, preferencesService.getCitationKeyPatternPreferences()) .generateAndSetKey(entry) .ifPresent(change -> undoManager.addEdit(new UndoableKeyChange(change)));