From bd925c3e22f158678126330ccee35e8333975a2d Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 12 Apr 2019 16:37:27 +0200 Subject: [PATCH 1/5] Removed unnecessary 'Copying...' message --- .../org/jabref/gui/worker/CitationStyleToClipboardWorker.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/worker/CitationStyleToClipboardWorker.java b/src/main/java/org/jabref/gui/worker/CitationStyleToClipboardWorker.java index 6308ce55d7a..21b272eaff2 100644 --- a/src/main/java/org/jabref/gui/worker/CitationStyleToClipboardWorker.java +++ b/src/main/java/org/jabref/gui/worker/CitationStyleToClipboardWorker.java @@ -54,7 +54,6 @@ public CitationStyleToClipboardWorker(BasePanel basePanel, CitationStyleOutputFo } public void copyCitationStyleToClipboard(TaskExecutor taskExecutor) { - dialogService.notify(Localization.lang("Copying...")); BackgroundTask.wrap(this::generateCitations) .onFailure(ex -> LOGGER.error("Error while copying citations to the clipboard", ex)) .onSuccess(this::setClipBoardContent) From 9369c819c6fd4f1535253c4c058096a6d54fd90c Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 12 Apr 2019 17:37:00 +0200 Subject: [PATCH 2/5] Display the contents of the clipboard in the DialogService. --- src/main/java/org/jabref/gui/BasePanel.java | 31 ++++++++++++------- .../java/org/jabref/gui/FXDialogService.java | 2 -- .../actions/CopyBibTeXKeyAndLinkAction.java | 7 +++-- .../jabref/preferences/JabRefPreferences.java | 3 ++ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index c6501ec7da9..e485d241350 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -190,7 +190,6 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences(), dialogService, externalFileTypes); frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview); - } @Subscribe @@ -464,11 +463,12 @@ private void copyTitle() { output(Localization.lang("None of the selected entries have titles.")); return; } - Globals.clipboardManager.setContent(String.join("\n", titles)); + final String copiedTitles = String.join("\n", titles); + Globals.clipboardManager.setContent(copiedTitles); if (titles.size() == selectedBibEntries.size()) { // All entries had titles. - output((selectedBibEntries.size() > 1 ? Localization.lang("Copied titles") : Localization.lang("Copied title")) + '.'); + output(Localization.lang("Copied") + " '" + shortenDialogMessage(copiedTitles) + "'."); } else { output(Localization.lang("Warning: %0 out of %1 entries have undefined title.", Integer.toString(selectedBibEntries.size() - titles.size()), Integer.toString(selectedBibEntries.size()))); } @@ -488,15 +488,15 @@ private void copyCiteKey() { return; } - String sb = String.join(",", keys); String citeCommand = Optional.ofNullable(Globals.prefs.get(JabRefPreferences.CITE_COMMAND)) .filter(cite -> cite.contains("\\")) // must contain \ .orElse("\\cite"); - Globals.clipboardManager.setContent(citeCommand + "{" + sb + '}'); + final String copiedCiteCommand = citeCommand + "{" + String.join(",", keys) + '}'; + Globals.clipboardManager.setContent(copiedCiteCommand); if (keys.size() == bes.size()) { // All entries had keys. - output(bes.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key") + '.'); + output(Localization.lang("Copied") + " '" + shortenDialogMessage(copiedCiteCommand) + "'."); } else { output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size()))); } @@ -516,11 +516,12 @@ private void copyKey() { return; } - Globals.clipboardManager.setContent(String.join(",", keys)); + final String copiedKeys = String.join(",", keys); + Globals.clipboardManager.setContent(copiedKeys); if (keys.size() == bes.size()) { // All entries had keys. - output((bes.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key")) + '.'); + output(Localization.lang("Copied") + " '" + shortenDialogMessage(copiedKeys) + "'."); } else { output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size()))); } @@ -557,17 +558,25 @@ private void copyKeyAndTitle() { return; } - Globals.clipboardManager.setContent(sb.toString()); + final String copiedKeysAndTitles = sb.toString(); + Globals.clipboardManager.setContent(copiedKeysAndTitles); if (copied == bes.size()) { // All entries had keys. - output((bes.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key")) + '.'); + output(Localization.lang("Copied") + " '" + shortenDialogMessage(copiedKeysAndTitles) + "'."); } else { output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - copied), Integer.toString(bes.size()))); } } } + private String shortenDialogMessage(String dialogMessage) { + if (dialogMessage.length() < JabRefPreferences.SNACKBAR_DIALOG_SIZE_LIMIT) { + return dialogMessage; + } + return dialogMessage.substring(0, Math.min(dialogMessage.length(), JabRefPreferences.SNACKBAR_DIALOG_SIZE_LIMIT)) + "..."; + } + private void openExternalFile() { final List selectedEntries = mainTable.getSelectedEntries(); if (selectedEntries.size() != 1) { @@ -952,7 +961,7 @@ public void entryEditorClosing(EntryEditor editor) { */ public void ensureNotShowingBottomPanel(BibEntry entry) { if (((mode == BasePanelMode.SHOWING_EDITOR) && (entryEditor.getEntry() == entry)) - || ((mode == BasePanelMode.SHOWING_PREVIEW) && (preview.getEntry() == entry))) { + || ((mode == BasePanelMode.SHOWING_PREVIEW) && (preview.getEntry() == entry))) { closeBottomPane(); } } diff --git a/src/main/java/org/jabref/gui/FXDialogService.java b/src/main/java/org/jabref/gui/FXDialogService.java index 579b4de8bdd..fa1cf9c186b 100644 --- a/src/main/java/org/jabref/gui/FXDialogService.java +++ b/src/main/java/org/jabref/gui/FXDialogService.java @@ -59,7 +59,6 @@ public class FXDialogService implements DialogService { private static final Duration TOAST_MESSAGE_DISPLAY_TIME = Duration.millis(3000); private static final Logger LOGGER = LoggerFactory.getLogger(FXDialogService.class); - private final Window mainWindow; private final JFXSnackbar statusLine; @@ -118,7 +117,6 @@ public Optional showChoiceDialogAndWait(String title, String content, Str choiceDialog.setTitle(title); choiceDialog.setContentText(content); return choiceDialog.showAndWait(); - } @Override diff --git a/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java b/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java index 49c8a5f46ec..bc076f51f5b 100644 --- a/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java +++ b/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java @@ -11,6 +11,7 @@ import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; +import org.jabref.preferences.JabRefPreferences; /** * This class will copy each selected entry's BibTeX key as a hyperlink to its url to the clipboard. @@ -46,14 +47,14 @@ public void action() throws Exception { sb.append(url.isEmpty() ? key : String.format("%s", url, key)); sb.append(OS.NEWLINE); } - - DefaultTaskExecutor.runInJavaFXThread(() -> clipboardManager.setHtmlContent(sb.toString())); + final String keyAndLink = sb.toString(); + DefaultTaskExecutor.runInJavaFXThread(() -> clipboardManager.setHtmlContent(keyAndLink)); int copied = entriesWithKey.size(); int toCopy = entries.size(); if (copied == toCopy) { // All entries had keys. - JabRefGUI.getMainFrame().getDialogService().notify((entries.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key")) + '.'); + JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Copied") + " '" + keyAndLink.substring(0, Math.min(keyAndLink.length(), JabRefPreferences.SNACKBAR_DIALOG_SIZE_LIMIT)) + "'."); } else { JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Long.toString(toCopy - copied), Integer.toString(toCopy))); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 88eae71f20a..8d88826a549 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -399,6 +399,9 @@ public class JabRefPreferences implements PreferencesService { // Dialog states private static final String PREFS_EXPORT_PATH = "prefsExportPath"; + // Snackbar dialog maximum size + public static final int SNACKBAR_DIALOG_SIZE_LIMIT = 300; + // Helper string private static final String USER_HOME = System.getProperty("user.home"); From 8c42018466d9cad5fdfebfe58e70d9ff767297b3 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 12 Apr 2019 17:46:12 +0200 Subject: [PATCH 3/5] Fix checkstyle --- src/main/java/org/jabref/preferences/JabRefPreferences.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 8d88826a549..0844078079b 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -355,6 +355,8 @@ public class JabRefPreferences implements PreferencesService { // Id Entry Generator Preferences public static final String ID_ENTRY_GENERATOR = "idEntryGenerator"; + // Snackbar dialog maximum size + public static final int SNACKBAR_DIALOG_SIZE_LIMIT = 300; //File linking Options for entry editor public static final String ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE = "DragDropPreferenceType"; @@ -399,9 +401,6 @@ public class JabRefPreferences implements PreferencesService { // Dialog states private static final String PREFS_EXPORT_PATH = "prefsExportPath"; - // Snackbar dialog maximum size - public static final int SNACKBAR_DIALOG_SIZE_LIMIT = 300; - // Helper string private static final String USER_HOME = System.getProperty("user.home"); From 375430e0ee66637264f925d7eb8458359648feb0 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Mon, 15 Apr 2019 08:43:42 +0200 Subject: [PATCH 4/5] Removed obsolete keys --- src/main/resources/l10n/JabRef_en.properties | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 7398d8fc491..e13a18398fd 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -154,13 +154,6 @@ Content=Content Copied=Copied -Copied\ title=Copied title - -Copied\ key=Copied key - -Copied\ titles=Copied titles - -Copied\ keys=Copied keys Copy=Copy @@ -1869,7 +1862,6 @@ Different\ customization,\ current\ settings\ will\ be\ overwritten=Different cu Entry\ type\ %0\ is\ only\ defined\ for\ Biblatex\ but\ not\ for\ BibTeX=Entry type %0 is only defined for Biblatex but not for BibTeX Copied\ %0\ citations.=Copied %0 citations. -Copying...=Copying... journal\ not\ found\ in\ abbreviation\ list=journal not found in abbreviation list Unhandled\ exception\ occurred.=Unhandled exception occurred. From 990b844907acb5b1758ef9b95bcfdf95e4cf7228 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Mon, 15 Apr 2019 09:04:38 +0200 Subject: [PATCH 5/5] Moved shortenMessage to DialogService --- src/main/java/org/jabref/gui/BasePanel.java | 15 ++++----------- ...ialogService.java => JabRefDialogService.java} | 15 ++++++++++++--- src/main/java/org/jabref/gui/JabRefFrame.java | 2 +- .../gui/actions/CopyBibTeXKeyAndLinkAction.java | 4 ++-- .../org/jabref/preferences/JabRefPreferences.java | 3 --- 5 files changed, 19 insertions(+), 20 deletions(-) rename src/main/java/org/jabref/gui/{FXDialogService.java => JabRefDialogService.java} (96%) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index e485d241350..7d4900ab67a 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -468,7 +468,7 @@ private void copyTitle() { if (titles.size() == selectedBibEntries.size()) { // All entries had titles. - output(Localization.lang("Copied") + " '" + shortenDialogMessage(copiedTitles) + "'."); + output(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(copiedTitles) + "'."); } else { output(Localization.lang("Warning: %0 out of %1 entries have undefined title.", Integer.toString(selectedBibEntries.size() - titles.size()), Integer.toString(selectedBibEntries.size()))); } @@ -496,7 +496,7 @@ private void copyCiteKey() { if (keys.size() == bes.size()) { // All entries had keys. - output(Localization.lang("Copied") + " '" + shortenDialogMessage(copiedCiteCommand) + "'."); + output(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(copiedCiteCommand) + "'."); } else { output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size()))); } @@ -521,7 +521,7 @@ private void copyKey() { if (keys.size() == bes.size()) { // All entries had keys. - output(Localization.lang("Copied") + " '" + shortenDialogMessage(copiedKeys) + "'."); + output(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(copiedKeys) + "'."); } else { output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size()))); } @@ -563,20 +563,13 @@ private void copyKeyAndTitle() { if (copied == bes.size()) { // All entries had keys. - output(Localization.lang("Copied") + " '" + shortenDialogMessage(copiedKeysAndTitles) + "'."); + output(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(copiedKeysAndTitles) + "'."); } else { output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - copied), Integer.toString(bes.size()))); } } } - private String shortenDialogMessage(String dialogMessage) { - if (dialogMessage.length() < JabRefPreferences.SNACKBAR_DIALOG_SIZE_LIMIT) { - return dialogMessage; - } - return dialogMessage.substring(0, Math.min(dialogMessage.length(), JabRefPreferences.SNACKBAR_DIALOG_SIZE_LIMIT)) + "..."; - } - private void openExternalFile() { final List selectedEntries = mainTable.getSelectedEntries(); if (selectedEntries.size() != 1) { diff --git a/src/main/java/org/jabref/gui/FXDialogService.java b/src/main/java/org/jabref/gui/JabRefDialogService.java similarity index 96% rename from src/main/java/org/jabref/gui/FXDialogService.java rename to src/main/java/org/jabref/gui/JabRefDialogService.java index fa1cf9c186b..ca3f0deec4c 100644 --- a/src/main/java/org/jabref/gui/FXDialogService.java +++ b/src/main/java/org/jabref/gui/JabRefDialogService.java @@ -55,14 +55,16 @@ * rather than complex windows. For more complex dialogs it is * advised to rather create a new sub class of {@link FXDialog}. */ -public class FXDialogService implements DialogService { +public class JabRefDialogService implements DialogService { + // Snackbar dialog maximum size + public static final int DIALOG_SIZE_LIMIT = 300; private static final Duration TOAST_MESSAGE_DISPLAY_TIME = Duration.millis(3000); - private static final Logger LOGGER = LoggerFactory.getLogger(FXDialogService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(JabRefDialogService.class); private final Window mainWindow; private final JFXSnackbar statusLine; - public FXDialogService(Window mainWindow, Pane mainPane) { + public JabRefDialogService(Window mainWindow, Pane mainPane) { this.mainWindow = mainWindow; this.statusLine = new JFXSnackbar(mainPane); } @@ -108,6 +110,13 @@ protected Node createDetailsButton() { return alert; } + public static String shortenDialogMessage(String dialogMessage) { + if (dialogMessage.length() < JabRefDialogService.DIALOG_SIZE_LIMIT) { + return dialogMessage.trim(); + } + return (dialogMessage.substring(0, Math.min(dialogMessage.length(), JabRefDialogService.DIALOG_SIZE_LIMIT)) + "...").trim(); + } + @Override public Optional showChoiceDialogAndWait(String title, String content, String okButtonLabel, T defaultChoice, Collection choices) { ChoiceDialog choiceDialog = new ChoiceDialog<>(defaultChoice, choices); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index abc4abf83a2..9b2a792ec93 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -175,7 +175,7 @@ public class JabRefFrame extends BorderPane { public JabRefFrame(Stage mainStage) { this.mainStage = mainStage; - this.dialogService = new FXDialogService(mainStage, this); + this.dialogService = new JabRefDialogService(mainStage, this); } /** diff --git a/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java b/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java index bc076f51f5b..9c6b1e21f4a 100644 --- a/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java +++ b/src/main/java/org/jabref/gui/actions/CopyBibTeXKeyAndLinkAction.java @@ -5,13 +5,13 @@ import org.jabref.JabRefGUI; import org.jabref.gui.ClipBoardManager; +import org.jabref.gui.JabRefDialogService; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; -import org.jabref.preferences.JabRefPreferences; /** * This class will copy each selected entry's BibTeX key as a hyperlink to its url to the clipboard. @@ -54,7 +54,7 @@ public void action() throws Exception { int toCopy = entries.size(); if (copied == toCopy) { // All entries had keys. - JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Copied") + " '" + keyAndLink.substring(0, Math.min(keyAndLink.length(), JabRefPreferences.SNACKBAR_DIALOG_SIZE_LIMIT)) + "'."); + JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(keyAndLink) + "'."); } else { JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Long.toString(toCopy - copied), Integer.toString(toCopy))); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 0844078079b..e7ea9515206 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -355,9 +355,6 @@ public class JabRefPreferences implements PreferencesService { // Id Entry Generator Preferences public static final String ID_ENTRY_GENERATOR = "idEntryGenerator"; - // Snackbar dialog maximum size - public static final int SNACKBAR_DIALOG_SIZE_LIMIT = 300; - //File linking Options for entry editor public static final String ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE = "DragDropPreferenceType";