Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preselect last used export format in export to clipboard dialog #4533

Merged
merged 8 commits into from
Dec 14, 2018
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We added an option in the preference dialog box, that allows user to pick the dark or light theme option. [#4130] (https://github.com/JabRef/jabref/issues/4130)
- We updated updated the Related Articles tab to accept JSON from the new version of the Mr. DLib service
- We added an option in the preference dialog box that allows user to choose behavior after dragging and dropping files in Entry Editor. [#4356](https://github.com/JabRef/jabref/issues/4356)
- We added the ability to have an export preference where previously "File"-->"Export"/"Export selected entries" would not save the user's preference[#4495](https://github.com/JabRef/jabref/issues/4495)



Expand Down Expand Up @@ -94,7 +95,6 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#




### Removed
- The feature to "mark entries" was removed and merged with the groups functionality. For migration, a group is created for every value of the `__markedentry` field and the entry is added to this group.
- The number column was removed.
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/org/jabref/gui/exporter/ExportToClipboardAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.JabRefPreferences;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -60,12 +61,22 @@ public void execute() {
.sorted(Comparator.comparing(Exporter::getName))
.collect(Collectors.toList());

//Create exporter for default choice
Exporter defaultChoice = null;

//Iterate through exporters looking for match
for (Exporter e: exporters) {
if (e.getName().equals(Globals.prefs.get(JabRefPreferences.LAST_USED_EXPORT))) {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
defaultChoice = e;
}
}

Optional<Exporter> selectedExporter = dialogService.showChoiceDialogAndWait(Localization.lang("Export"), Localization.lang("Select export format"),
Localization.lang("Export"), exporters);
Localization.lang("Export"),defaultChoice, exporters);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please insert a space:

Suggested change
Localization.lang("Export"),defaultChoice, exporters);
Localization.lang("Export"), defaultChoice, exporters);


selectedExporter.ifPresent(exporter -> BackgroundTask.wrap(() -> exportToClipboard(exporter))
.onSuccess(this::setContentToClipboard)
.executeWith(Globals.TASK_EXECUTOR));
selectedExporter.ifPresent(exporter -> BackgroundTask.wrap(() -> exportToClipboard(exporter))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indent seems to be wrong here (it was correct before)

.onSuccess(this::setContentToClipboard)
.executeWith(Globals.TASK_EXECUTOR));

}

Expand All @@ -75,6 +86,9 @@ private String exportToClipboard(Exporter exporter) {
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()).stream().map(Path::toString).collect(Collectors.toList());

//Add chosen export type to last used pref
Globals.prefs.put(JabRefPreferences.LAST_USED_EXPORT, exporter.getName());

Path tmp = null;
try {
// To simplify the exporter API we simply do a normal export to a temporary
Expand Down