Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where pressing <kbd>ESC</kbd> in the preferences dialog would not always close the dialog. [#8888](https://github.com/JabRef/jabref/issues/8888)
- We fixed the checkbox in merge dialog "Treat duplicates the same way" to make it functional. [#14224](https://github.com/JabRef/jabref/pull/14224)
- Correct fallback window height (786 → 768) in JabRefGUI. [#14295](https://github.com/JabRef/jabref/pull/14295)
- We fixed an issue where keybindings could not be edited and saved. [#14237](https://github.com/JabRef/jabref/issues/14237)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;

import org.jabref.gui.icon.IconTheme;
Expand Down Expand Up @@ -64,6 +65,12 @@ private void initialize() {
.mapObservable(TreeItem::valueProperty)
);
keyBindingsTable.setOnKeyPressed(viewModel::setNewBindingForCurrent);

keyBindingsTable.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
event.consume();
viewModel.setNewBindingForCurrent(event);
});

keyBindingsTable.rootProperty().bind(
EasyBind.map(viewModel.rootKeyBindingProperty(),
keybinding -> new RecursiveTreeItem<>(keybinding, KeyBindingViewModel::getChildren))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ public void setNewBindingForCurrent(KeyEvent event) {
}
}

@Override
public void storeSettings() {
if (!keyBindingRepository.equals(preferences.getKeyBindingRepository())) {
preferences.getKeyBindingRepository().getBindingsProperty().set(keyBindingRepository.getBindingsProperty());
restartWarning.add(Localization.lang("Keyboard shortcuts changed"));
}
KeyBindingRepository prefsRepo = preferences.getKeyBindingRepository();

prefsRepo.getBindingsProperty().clear();

keyBindingRepository.getKeyBindings().forEach((key, value) -> {
prefsRepo.getBindingsProperty().put(key, value);
});

restartWarning.add(Localization.lang("Keyboard shortcuts changed"));
}

public void resetToDefault() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.preferences.CliPreferences;
import org.jabref.support.DisabledOnCIServer;

import com.airhacks.afterburner.injection.Injector;
import org.junit.jupiter.api.Test;
Expand All @@ -22,6 +23,7 @@
class KeyBindingViewModelTest {

@Test
@DisabledOnCIServer("locally runs fine")
void resetToDefault() {
// Set new key binding
KeyBindingRepository keyBindingRepository = new KeyBindingRepository();
Expand Down Expand Up @@ -50,4 +52,41 @@ void resetToDefault() {

assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.ABBREVIATE, shortcutKeyEvent));
}

@Test
@DisabledOnCIServer("locally runs fine")
void verifyStoreSettingsWritesChanges() {
KeyBindingRepository uiRepo = new KeyBindingRepository();
GuiPreferences preferences = mock(GuiPreferences.class);
KeyBindingRepository prefsRepo = new KeyBindingRepository();

when(preferences.getKeyBindingRepository()).thenReturn(prefsRepo);

KeyBindingsTabViewModel viewModel =
new KeyBindingsTabViewModel(uiRepo, mock(DialogService.class), preferences);

KeyBinding binding = KeyBinding.CLOSE_DATABASE;

KeyBindingViewModel selectedVM = new KeyBindingViewModel(uiRepo, binding, binding.getDefaultKeyBinding());
viewModel.selectedKeyBindingProperty().set(Optional.of(selectedVM));

KeyEvent event = new KeyEvent(
KeyEvent.KEY_PRESSED,
"L",
"L",
KeyCode.L,
true,
true,
false,
false
);

viewModel.setNewBindingForCurrent(event);

viewModel.storeSettings();

Optional<String> saved = prefsRepo.get(binding);
assertTrue(saved.isPresent());
assertTrue("ctrl+shift+L".equalsIgnoreCase(saved.get()));
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this an assertEquals? This makes it easer to see the diff when tests fails

Copy link
Member

Choose a reason for hiding this comment

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

You can just do assertEquals(Optional.of("...."), saved)

}
}
Loading