-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Ported the KeyBindings dialog to JavaFX #1390
Conversation
UI Looks good 👍 Just one thing you should change regarding the UI: Don't ask questions in dialogs. Because that is too much "cognitive expenditure" for the user. Label the buttons with a clear description: (e.g. Reset Keybinding, Back to Dialog). See here for a discussion on Why Questions with Yes/No are a bad idea |
return true; | ||
} else { | ||
return false; | ||
} |
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.
if statement is not necessary, this could be done in one line return combination.equals(pressedCombination)
A few comments regarding the UI:
|
@tobiasdiez I have now adressed most of your comments. I called the default button Here are some new screenshots |
* @param keyEvent as KeEvent | ||
* @return true if matching, else false | ||
*/ | ||
private boolean checkKeyCombinationEquality(KeyCombination combination, KeyEvent keyEvent) { |
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.
I would prefer if you move this code to the KeyBindingPreferences
class. Than you can write something like if(Globals.getKeyPrefs().checkKeyCombinationEquality(KeyBinding.CLOSE_DIALOG, event)
private final KeyBindingCategory category; | ||
|
||
|
||
public KeyBindingViewModel(KeyBinding keyBinding, String binding, KeyBindingCategory category) { |
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.
The third parameter is not required as far as I can see (if it's a binding, then its category is stored in it)
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.
Yes you are right, I forgot to remove it when adding the category constructor.
Good work! The idea of this ViewModels is the following:
So in your case you have two ViewModels:
For the item in the table: (KeyBindingViewModel)
The reason for this "binding over everything else" philosophy is that you can easily write tests. For example: KeyBindingDialogViewModel dialog = new blabla();
dialog.setRepository(some mocked rep);
AssertEqual(expectedTree, dialog.bindingsTree);
% If this test passes then you know that the correct things are displayed in the dialog (except if you forgot to bind the vew to `bindingsTree`)
KeyBindingDialogViewModel dialog = new blabla();
dialog.setRepository(some mocked rep);
AssertCalls(mockedRep.resetBindinings(), dialog.resetBinding());
AssertEquals(defaultTree, dialog.bindingsTree);
% Check that the dialog relays the click to the correct method and updates view (only thing that can fail is again that the binding of the buttonclick is not bound to dialog.resetBinding()
KeyBindingDialogViewModel dialog = new blabla();
dialog.setRepository(some mocked rep);
dialog.selectedIBinding = some mocked binding view model
AssertCalls(mockedBinding.setNewBinding, dialog.keyPressed(event))
KeyBindingViewModel binding = new blabla();
AssertCalls(repository.change(), binding.setNewBinding(event))
AssertEquals("Ctrl + Alt + f4", binding.KeyBinding); Can you please try to add these tests? |
controller.setKeyBindingPreferences(keyBindingPreferences); | ||
controller.initializeView(); | ||
keyBindingsDialog.setResizable(true); | ||
((Stage) keyBindingsDialog.getDialogPane().getScene().getWindow()).setMinHeight(475); |
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.
Can this be set in the fxml file?
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 minimum size of the dialog pane is already set to this dimension in the fxml file. However if you omit these lines you are able to resize the dialog window to whatever you like but not the dialog content. So all properties set in the fxml file only affect the dialog content but not the dialog window itself. With these lines omitted you could resize the dialog to a point where the content doesn't resize and it may look bugged.
I added some tests for the dialog view model |
@Before | ||
public void setUp() { | ||
model = new KeyBindingsDialogViewModel(); | ||
JabRefPreferences preferences = JabRefPreferences.getInstance(); |
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.
Try to pass a mockito mock of the preferences to the keybindingpreferences (see wiki) or mock the repository itself.
Nice! I only have some minor remarks about the naming of the tests and their general structure (only one assert per test). If these small issues are fixed, this PR can be merged from my point of view! |
I refactored the test class. |
try { | ||
preferences.clear(); | ||
mockedPreferences.clear(); |
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.
No need to clear it.
Ok, ready to go from my point of view! @JabRef/developers what do you think? |
Please rebase and remove the |
Current coverage is 28.64%@@ javafx #1390 diff @@
==========================================
Files 703 704 +1
Lines 46304 46395 +91
Methods 0 0
Messages 0 0
Branches 7634 7636 +2
==========================================
+ Hits 5000 13288 +8288
+ Misses 40857 31976 -8881
- Partials 447 1131 +684
|
@tobiasdiez The BibTeX localization key is used in the |
I found out travis ci uses different import orders for javafx than what is specified in eclipse.settings. I quickly changed it in #1518 so using "organize imports" in eclipse will work for javafx. |
Please be aware that menu translations are done using |
* Initial port of the keybindings dialog to javafx * Test javafx import order
The KeyBindings are now organized in categories referring to the JabRef menu titles.
The button graKey has been removed and once a entry is selected the table listens for valid key combinations. The FXAlert class has also been adjusted to listen to the closeDialog shortcut.