Skip to content

Commit

Permalink
Improve Snackbar Dialogs for Copy to Clipboard Menu (#4884)
Browse files Browse the repository at this point in the history
* Removed unnecessary 'Copying...' message

* Display the contents of the clipboard in the DialogService.

* Fix checkstyle

* Removed obsolete keys

* Moved shortenMessage to DialogService
  • Loading branch information
LinusDietz authored and tobiasdiez committed Apr 15, 2019
1 parent 47f43ca commit 9ab59d0
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
24 changes: 13 additions & 11 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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") + " '" + 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())));
}
Expand All @@ -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") + " '" + 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())));
}
Expand All @@ -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") + " '" + 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())));
}
Expand Down Expand Up @@ -557,11 +558,12 @@ 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") + " '" + 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())));
}
Expand Down Expand Up @@ -952,7 +954,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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +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);
}
Expand Down Expand Up @@ -109,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 <T> Optional<T> showChoiceDialogAndWait(String title, String content, String okButtonLabel, T defaultChoice, Collection<T> choices) {
ChoiceDialog<T> choiceDialog = new ChoiceDialog<>(defaultChoice, choices);
Expand All @@ -118,7 +126,6 @@ public <T> Optional<T> showChoiceDialogAndWait(String title, String content, Str
choiceDialog.setTitle(title);
choiceDialog.setContentText(content);
return choiceDialog.showAndWait();

}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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;
Expand Down Expand Up @@ -46,14 +47,14 @@ public void action() throws Exception {
sb.append(url.isEmpty() ? key : String.format("<a href=\"%s\">%s</a>", 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") + " '" + 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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ public class JabRefPreferences implements PreferencesService {
// Id Entry Generator Preferences
public static final String ID_ENTRY_GENERATOR = "idEntryGenerator";


//File linking Options for entry editor
public static final String ENTRY_EDITOR_DRAG_DROP_PREFERENCE_TYPE = "DragDropPreferenceType";

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

Expand Down Expand Up @@ -1868,7 +1861,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.
Expand Down

0 comments on commit 9ab59d0

Please sign in to comment.