Skip to content

Commit

Permalink
l10n and some minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus committed Feb 19, 2020
1 parent b83d547 commit def0e67
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 83 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/jabref/gui/SendAsEMailAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<BibEntry> bes = stateManager.getSelectedEntries();
List<BibEntry> 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);
}
Expand All @@ -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<Path> fileList = FileUtil.getListOfLinkedFiles(bes, databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()));
for (Path f : fileList) {
attachments.add(f.toAbsolutePath().toString());
List<Path> 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) {
Expand All @@ -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());
}
}
137 changes: 73 additions & 64 deletions src/main/java/org/jabref/gui/edit/CopyMoreAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
}
}

Expand All @@ -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<BibEntry> entries = stateManager.getSelectedEntries();

List<String> 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<String> 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<BibEntry> entries = stateManager.getSelectedEntries();
List<String> keys = new ArrayList<>(entries.size());

// Collect all non-null keys.
for (BibEntry entry : entries) {
entry.getCiteKeyOptional().ifPresent(keys::add);
}
List<String> 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;
Expand All @@ -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<BibEntry> 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<BibEntry> entries = stateManager.getSelectedEntries();

StringBuilder keyAndLink = new StringBuilder();

List<BibEntry> entriesWithKey = entries.stream().filter(BibEntry::hasCiteKey).collect(Collectors.toList());
List<BibEntry> 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;
}

Expand All @@ -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())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 3 additions & 4 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -334,8 +333,6 @@ External\ file\ links=External file links

External\ programs=External programs

External\ viewer\ called=External viewer called

Field=Field

field=field
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

0 comments on commit def0e67

Please sign in to comment.