-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Improve Snackbar Dialogs for Copy to Clipboard Menu #4884
Changes from 3 commits
bd925c3
9369c81
8c42018
375430e
990b844
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revisiting the code, I decided to move the method to the JabRefDialogService (formerly FXDialogService) |
||
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<BibEntry> 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(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a JavaFX util method that shortens text based on its display size (e.g taking the current font into account). The difference is probably negligible through.
https://github.com/javafxports/openjdk-jfx/blob/develop/modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/skin/Utils.java#L212
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, the alternative would be to directly hack a hard limit into the snackbar dialog system. I didn't do that, because maybe another type of messages should be independent of this 300 char limit.