Skip to content

Commit

Permalink
Solution for submitting dialog with Ctrl + Enter (#4496) (#4592)
Browse files Browse the repository at this point in the history
* Issue#4496 Added default action invocation in dialog when pressing ctrl+enter

* Issue#4496 Added changelog regarding changes made
  • Loading branch information
AlekssGu authored and tobiasdiez committed Jan 22, 2019
1 parent c7473e7 commit 701e73d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- 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)
- We added the ability to add field names from the Preferences Dialog [#4546](https://github.com/JabRef/jabref/issues/4546)
- We added the ability change the column widths directly in the main table. [#4546](https://github.com/JabRef/jabref/issues/4546)
- We added the ability to execute default action in dialog by using with <kbd>Ctrl</kbd> + <kbd>Enter</kbd> combination [#4496](https://github.com/JabRef/jabref/issues/4496)



Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/keyboard/KeyBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum KeyBinding {
ENTRY_EDITOR_PREVIOUS_PANEL_2("Entry editor, previous panel 2", Localization.lang("Entry editor, previous panel 2"), "ctrl+MINUS", KeyBindingCategory.VIEW),
DECREASE_TABLE_FONT_SIZE("Decrease table font size", Localization.lang("Decrease table font size"), "ctrl+MINUS", KeyBindingCategory.VIEW),
DELETE_ENTRY("Delete entry", Localization.lang("Delete entry"), "DELETE", KeyBindingCategory.BIBTEX),
DEFAULT_DIALOG_ACTION("Execute default action in dialog", Localization.lang("Execute default action in dialog"), "ctrl+ENTER", KeyBindingCategory.VIEW),
DOWNLOAD_FULL_TEXT("Look up full text documents", Localization.lang("Look up full text documents"), "alt+F7", KeyBindingCategory.QUALITY),
EDIT_ENTRY("Edit entry", Localization.lang("Edit entry"), "ctrl+E", KeyBindingCategory.BIBTEX),
EDIT_STRINGS("Edit strings", Localization.lang("Edit strings"), "ctrl+T", KeyBindingCategory.BIBTEX),
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/jabref/gui/util/BaseDialog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.jabref.gui.util;

import java.util.Optional;

import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.image.Image;
import javafx.stage.Stage;
Expand All @@ -16,6 +20,8 @@ protected BaseDialog() {
KeyBindingRepository keyBindingRepository = Globals.getKeyPrefs();
if (keyBindingRepository.checkKeyCombinationEquality(KeyBinding.CLOSE, event)) {
close();
} else if (keyBindingRepository.checkKeyCombinationEquality(KeyBinding.DEFAULT_DIALOG_ACTION, event)) {
getDefaultButton().ifPresent(Button::fire);
}
});

Expand All @@ -24,6 +30,17 @@ protected BaseDialog() {
Globals.getThemeLoader().installCss(getDialogPane().getScene(), Globals.prefs);
}

private Optional<Button> getDefaultButton() {
return Optional.ofNullable((Button) getDialogPane().lookupButton(getDefaultButtonType()));
}

private ButtonType getDefaultButtonType() {
return getDialogPane().getButtonTypes().stream()
.filter(buttonType -> buttonType.getButtonData().isDefaultButton())
.findFirst()
.orElse(ButtonType.OK);
}

private void setDialogIcon(Image image) {
Stage dialogWindow = (Stage) getDialogPane().getScene().getWindow();
dialogWindow.getIcons().add(image);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ Default\ grouping\ field=Default grouping field

Default\ pattern=Default pattern

Execute\ default\ action\ in\ dialog=Execute default action in dialog

Delete=Delete

Delete\ custom\ format=Delete custom format
Expand Down

0 comments on commit 701e73d

Please sign in to comment.