From def0e67d43a7d604479bf17ba125f0dae43e673e Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Wed, 19 Feb 2020 17:11:58 +0100 Subject: [PATCH] l10n and some minor corrections --- src/main/java/org/jabref/gui/JabRefFrame.java | 6 +- .../org/jabref/gui/SendAsEMailAction.java | 20 +-- .../org/jabref/gui/edit/CopyMoreAction.java | 137 ++++++++++-------- ...geAction.java => PreviewSwitchAction.java} | 4 +- src/main/resources/l10n/JabRef_en.properties | 7 +- 5 files changed, 91 insertions(+), 83 deletions(-) rename src/main/java/org/jabref/gui/entryeditor/{EntryEditorPreviewChangeAction.java => PreviewSwitchAction.java} (80%) diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 8a325a92b91..0643f67c6a4 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -62,7 +62,7 @@ import org.jabref.gui.edit.ManageKeywordsAction; import org.jabref.gui.edit.MassSetFieldsAction; import org.jabref.gui.edit.OpenBrowserAction; -import org.jabref.gui.entryeditor.EntryEditorPreviewChangeAction; +import org.jabref.gui.entryeditor.PreviewSwitchAction; import org.jabref.gui.exporter.ExportCommand; import org.jabref.gui.exporter.ExportToClipboardAction; import org.jabref.gui.exporter.ManageCustomExportsAction; @@ -807,8 +807,8 @@ private MenuBar createMenu() { new SeparatorMenuItem(), - factory.createMenuItem(StandardActions.NEXT_PREVIEW_STYLE, new EntryEditorPreviewChangeAction(EntryEditorPreviewChangeAction.Direction.NEXT, this, stateManager)), - factory.createMenuItem(StandardActions.PREVIOUS_PREVIEW_STYLE, new EntryEditorPreviewChangeAction(EntryEditorPreviewChangeAction.Direction.PREVIOUS, this, stateManager)), + factory.createMenuItem(StandardActions.NEXT_PREVIEW_STYLE, new PreviewSwitchAction(PreviewSwitchAction.Direction.NEXT, this, stateManager)), + factory.createMenuItem(StandardActions.PREVIOUS_PREVIEW_STYLE, new PreviewSwitchAction(PreviewSwitchAction.Direction.PREVIOUS, this, stateManager)), new SeparatorMenuItem(), diff --git a/src/main/java/org/jabref/gui/SendAsEMailAction.java b/src/main/java/org/jabref/gui/SendAsEMailAction.java index 06031631dde..08f412b6a28 100644 --- a/src/main/java/org/jabref/gui/SendAsEMailAction.java +++ b/src/main/java/org/jabref/gui/SendAsEMailAction.java @@ -68,16 +68,16 @@ private String sendEmail() throws Exception { return Localization.lang("This operation requires one or more entries to be selected."); } - StringWriter sw = new StringWriter(); + StringWriter rawEntries = new StringWriter(); BibDatabaseContext databaseContext = stateManager.getActiveDatabase().get(); - List bes = stateManager.getSelectedEntries(); + List entries = stateManager.getSelectedEntries(); // write the entries using sw, which is used later to form the email content BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(Globals.prefs.getFieldWriterPreferences()), Globals.entryTypesManager); - for (BibEntry entry : bes) { + for (BibEntry entry : entries) { try { - bibtexEntryWriter.write(entry, sw, databaseContext.getMode()); + bibtexEntryWriter.write(entry, rawEntries, databaseContext.getMode()); } catch (IOException e) { LOGGER.warn("Problem creating BibTeX file for mailing.", e); } @@ -89,19 +89,19 @@ private String sendEmail() throws Exception { // the unofficial "mailto:attachment" property boolean openFolders = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES); - List fileList = FileUtil.getListOfLinkedFiles(bes, databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences())); - for (Path f : fileList) { - attachments.add(f.toAbsolutePath().toString()); + List fileList = FileUtil.getListOfLinkedFiles(entries, databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences())); + for (Path path : fileList) { + attachments.add(path.toAbsolutePath().toString()); if (openFolders) { try { - JabRefDesktop.openFolderAndSelectFile(f.toAbsolutePath()); + JabRefDesktop.openFolderAndSelectFile(path.toAbsolutePath()); } catch (IOException e) { LOGGER.debug("Cannot open file", e); } } } - String mailTo = "?Body=".concat(sw.getBuffer().toString()); + String mailTo = "?Body=".concat(rawEntries.getBuffer().toString()); mailTo = mailTo.concat("&Subject="); mailTo = mailTo.concat(JabRefPreferences.getInstance().get(JabRefPreferences.EMAIL_SUBJECT)); for (String path : attachments) { @@ -114,6 +114,6 @@ private String sendEmail() throws Exception { Desktop desktop = Desktop.getDesktop(); desktop.mail(uriMailTo); - return String.format("%s: %d", Localization.lang("Entries added to an email"), bes.size()); + return String.format("%s: %d", Localization.lang("Entries added to an email"), entries.size()); } } diff --git a/src/main/java/org/jabref/gui/edit/CopyMoreAction.java b/src/main/java/org/jabref/gui/edit/CopyMoreAction.java index b40353bc365..0026bfcb374 100644 --- a/src/main/java/org/jabref/gui/edit/CopyMoreAction.java +++ b/src/main/java/org/jabref/gui/edit/CopyMoreAction.java @@ -2,14 +2,11 @@ import java.io.IOException; import java.io.StringReader; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.jabref.Globals; -import org.jabref.JabRefGUI; import org.jabref.gui.ClipBoardManager; import org.jabref.gui.DialogService; import org.jabref.gui.JabRefDialogService; @@ -54,22 +51,24 @@ public void execute() { return; } - if (!Arrays.asList( - StandardActions.COPY_TITLE, - StandardActions.COPY_KEY, - StandardActions.COPY_CITE_KEY, - StandardActions.COPY_KEY_AND_TITLE, - StandardActions.COPY_KEY_AND_LINK) - .contains(action)) { - return; - } - switch (action) { - case COPY_TITLE: copyTitle(); break; - case COPY_KEY: copyKey(); break; - case COPY_CITE_KEY: copyCiteKey(); break; - case COPY_KEY_AND_TITLE: copyKeyAndTitle(); break; - case COPY_KEY_AND_LINK: copyKeyAndLink(); break; + case COPY_TITLE: + copyTitle(); + break; + case COPY_KEY: + copyKey(); + break; + case COPY_CITE_KEY: + copyCiteKey(); + break; + case COPY_KEY_AND_TITLE: + copyKeyAndTitle(); + break; + case COPY_KEY_AND_LINK: + copyKeyAndLink(); + break; + default: + LOGGER.info("Unknown copy command."); } } @@ -91,44 +90,50 @@ private void copyTitle() { if (titles.size() == selectedBibEntries.size()) { // All entries had titles. - dialogService.notify(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(copiedTitles) + "'."); + dialogService.notify(Localization.lang("Copied '%0' to clipboard.", + JabRefDialogService.shortenDialogMessage(copiedTitles))); } else { - dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined title.", Integer.toString(selectedBibEntries.size() - titles.size()), Integer.toString(selectedBibEntries.size()))); + dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined title.", + Integer.toString(selectedBibEntries.size() - titles.size()), Integer.toString(selectedBibEntries.size()))); } } private void copyKey() { List entries = stateManager.getSelectedEntries(); - List keys = new ArrayList<>(entries.size()); - // Collect all non-null keys. - for (BibEntry entry : entries) { - entry.getCiteKeyOptional().ifPresent(keys::add); - } - if (keys.isEmpty()) { - dialogService.notify(Localization.lang("None of the selected entries have BibTeX keys.")); - return; - } + // Collect all non-null keys. + List keys = entries.stream() + .filter(entry -> entry.getCiteKeyOptional().isPresent()) + .map(entry -> entry.getCiteKeyOptional().get()) + .collect(Collectors.toList()); + + if (keys.isEmpty()) { + dialogService.notify(Localization.lang("None of the selected entries have BibTeX keys.")); + return; + } - final String copiedKeys = String.join(",", keys); - clipBoardManager.setContent(copiedKeys); + final String copiedKeys = String.join(",", keys); + clipBoardManager.setContent(copiedKeys); - if (keys.size() == entries.size()) { - // All entries had keys. - dialogService.notify(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(copiedKeys) + "'."); - } else { - dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(entries.size() - keys.size()), Integer.toString(entries.size()))); - } + if (keys.size() == entries.size()) { + // All entries had keys. + dialogService.notify(Localization.lang("Copied '%0' to clipboard.", + JabRefDialogService.shortenDialogMessage(copiedKeys))); + } else { + dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", + Integer.toString(entries.size() - keys.size()), Integer.toString(entries.size()))); + } } private void copyCiteKey() { List entries = stateManager.getSelectedEntries(); - List keys = new ArrayList<>(entries.size()); // Collect all non-null keys. - for (BibEntry entry : entries) { - entry.getCiteKeyOptional().ifPresent(keys::add); - } + List keys = entries.stream() + .filter(entry -> entry.getCiteKeyOptional().isPresent()) + .map(entry -> entry.getCiteKeyOptional().get()) + .collect(Collectors.toList()); + if (keys.isEmpty()) { dialogService.notify(Localization.lang("None of the selected entries have BibTeX keys.")); return; @@ -143,66 +148,71 @@ private void copyCiteKey() { if (keys.size() == entries.size()) { // All entries had keys. - dialogService.notify(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(copiedCiteCommand) + "'."); + dialogService.notify(Localization.lang("Copied '%0' to clipboard.", + JabRefDialogService.shortenDialogMessage(copiedCiteCommand))); } else { - dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(entries.size() - keys.size()), Integer.toString(entries.size()))); + dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", + Integer.toString(entries.size() - keys.size()), Integer.toString(entries.size()))); } } private void copyKeyAndTitle() { List entries = stateManager.getSelectedEntries(); - // ToDo: in a future version, this string should be configurable to allow arbitrary exports + // ToDo: this string should be configurable to allow arbitrary exports StringReader layoutString = new StringReader("\\bibtexkey - \\begin{title}\\format[RemoveBrackets]{\\title}\\end{title}\n"); Layout layout; try { - layout = new LayoutHelper(layoutString, preferencesService.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader)) - .getLayoutFromText(); + layout = new LayoutHelper(layoutString, preferencesService.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader)).getLayoutFromText(); } catch (IOException e) { - LOGGER.info("Could not get layout", e); + LOGGER.info("Could not get layout.", e); return; } StringBuilder keyAndTitle = new StringBuilder(); - int copied = 0; + int entriesWithKeys = 0; // Collect all non-null keys. for (BibEntry entry : entries) { if (entry.hasCiteKey()) { - copied++; + entriesWithKeys++; keyAndTitle.append(layout.doLayout(entry, stateManager.getActiveDatabase().get().getDatabase())); } } - if (copied == 0) { + if (entriesWithKeys == 0) { dialogService.notify(Localization.lang("None of the selected entries have BibTeX keys.")); return; } clipBoardManager.setContent(keyAndTitle.toString()); - if (copied == entries.size()) { + if (entriesWithKeys == entries.size()) { // All entries had keys. - dialogService.notify(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(keyAndTitle.toString()) + "'."); + dialogService.notify(Localization.lang("Copied '%0' to clipboard.", + JabRefDialogService.shortenDialogMessage(keyAndTitle.toString()))); } else { - dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(entries.size() - copied), Integer.toString(entries.size()))); + dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", + Integer.toString(entries.size() - entriesWithKeys), Integer.toString(entries.size()))); } } /** - * This method will copy each selected entry's BibTeX key as a hyperlink to its url to the clipboard. - * In case an entry doesn't have a BibTeX key it will not be copied. - * In case an entry doesn't have an url this will only copy the BibTeX key. + * This method will copy each selected entry's BibTeX key as a hyperlink to its url to the clipboard. In case an + * entry doesn't have a BibTeX key it will not be copied. In case an entry doesn't have an url this will only copy + * the BibTeX key. */ private void copyKeyAndLink() { List entries = stateManager.getSelectedEntries(); StringBuilder keyAndLink = new StringBuilder(); - List entriesWithKey = entries.stream().filter(BibEntry::hasCiteKey).collect(Collectors.toList()); + List entriesWithKey = entries.stream() + .filter(BibEntry::hasCiteKey) + .collect(Collectors.toList()); if (entriesWithKey.isEmpty()) { - JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("None of the selected entries have BibTeX keys.")); + dialogService.notify(Localization.lang("None of the selected entries have BibTeX keys.")); return; } @@ -215,14 +225,13 @@ private void copyKeyAndLink() { clipBoardManager.setHtmlContent(keyAndLink.toString()); - int copied = entriesWithKey.size(); - int toCopy = entries.size(); - if (copied == toCopy) { + if (entriesWithKey.size() == entries.size()) { // All entries had keys. - JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Copied") + " '" + JabRefDialogService.shortenDialogMessage(keyAndLink.toString()) + "'."); + dialogService.notify(Localization.lang("Copied '%0' to clipboard.", + JabRefDialogService.shortenDialogMessage(keyAndLink.toString()))); } else { - JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", - Long.toString(toCopy - copied), Integer.toString(toCopy))); + dialogService.notify(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", + Long.toString(entries.size() - entriesWithKey.size()), Integer.toString(entries.size()))); } } } diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreviewChangeAction.java b/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java similarity index 80% rename from src/main/java/org/jabref/gui/entryeditor/EntryEditorPreviewChangeAction.java rename to src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java index d6f0ce47ea7..03247c4fdd0 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreviewChangeAction.java +++ b/src/main/java/org/jabref/gui/entryeditor/PreviewSwitchAction.java @@ -6,14 +6,14 @@ import static org.jabref.gui.actions.ActionHelper.needsDatabase; -public class EntryEditorPreviewChangeAction extends SimpleCommand { +public class PreviewSwitchAction extends SimpleCommand { public enum Direction { PREVIOUS, NEXT } private final JabRefFrame frame; private final Direction direction; - public EntryEditorPreviewChangeAction(Direction direction, JabRefFrame frame, StateManager stateManager) { + public PreviewSwitchAction(Direction direction, JabRefFrame frame, StateManager stateManager) { this.frame = frame; this.direction = direction; diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 7b0b9e6ec57..4f93dc17e6f 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -171,7 +171,6 @@ Could\ not\ import\ preferences=Could not import preferences Could\ not\ instantiate\ %0=Could not instantiate %0 Could\ not\ instantiate\ %0\ %1=Could not instantiate %0 %1 Could\ not\ instantiate\ %0.\ Have\ you\ chosen\ the\ correct\ package\ path?=Could not instantiate %0. Have you chosen the correct package path? -Could\ not\ open\ link=Could not open link Could\ not\ print\ preview=Could not print preview @@ -334,8 +333,6 @@ External\ file\ links=External file links External\ programs=External programs -External\ viewer\ called=External viewer called - Field=Field field=field @@ -569,7 +566,6 @@ No\ journal\ names\ could\ be\ unabbreviated.=No journal names could be unabbrev Open\ PDF=Open PDF -No\ URL\ defined=No URL defined not=not not\ found=not found @@ -2098,3 +2094,6 @@ Invalid\ regular\ expression.=Invalid regular expression. Keyword\ delimiter=Keyword delimiter Hierarchical\ keyword\ delimiter=Hierarchical keyword delimiter Escape\ ampersands=Escape ampersands + +Copied\ '%0'\ to\ clipboard.=Copied '%0' to clipboard. +This\ operation\ requires\ exactly\ an\ open\ library.=This operation requires exactly an open library.