Skip to content
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

Corrected shortcut #6960

Merged
merged 10 commits into from
Oct 18, 2020
Merged

Corrected shortcut #6960

merged 10 commits into from
Oct 18, 2020

Conversation

Gena928
Copy link
Contributor

@Gena928 Gena928 commented Sep 29, 2020

Fixes #6867
A new shortcut combination added for "Pull changes from shared database", because current ctrl+shift+R is already assigned for "Create tech report" command.

  • Change in CHANGELOG.md described (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked documentation: Is the information available and up to date? If not created an issue at https://github.com/JabRef/user-documentation/issues or, even better, submitted a pull request to the documentation repository.

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 29, 2020
@tobiasdiez
Copy link
Member

I would remove all the standard keybindings for https://github.com/JabRef/jabref/pull/6960/files#diff-920a3cf78140f82ffcd3ba5b495cf73fL49-L54. Then you can leave the pull changes keybinding at "ctrl + shift + r". What do you think?

@Siedlerchr
Copy link
Member

I'm against removing the shortcuts, at least article should be kept. Let's say what the other @JabRef/developers say about this

@tobiasdiez
Copy link
Member

Yes, article, book, new entry and new entry from plaintext should be kept. But masterthesis, phdthesis etc are not that important to have a default keybinding. (I don't suggest to completely remove these bindings, just their default value so that users can still activate them if they want).

@Gena928
Copy link
Contributor Author

Gena928 commented Oct 5, 2020

@tobiasdiez ,
So the following "new" shortcuts will be removed (see gray color):
Screenshot 2020-10-05 at 10 51 53

correct?

@calixtus
Copy link
Member

calixtus commented Oct 5, 2020

I wouldn't remove them at all, but their default value.
So the user is still able to bind keys to the shortcuts, if he likes.

@tobiasdiez
Copy link
Member

Yes, just provide an empty string as the third argument of these enum values, and include NEW_TECHREPORT as well.

@Gena928
Copy link
Contributor Author

Gena928 commented Oct 5, 2020

Empty string doesn't works. )) When I try to open the menu, it shows an error.
I'll try to find the problem.

java.lang.StringIndexOutOfBoundsException: begin 0, end 1, length 0
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3756)
at java.base/java.lang.String.substring(String.java:1902)
at javafx.graphics/javafx.scene.input.KeyCombination.normalizeToken(KeyCombination.java:630)
at javafx.graphics/javafx.scene.input.KeyCombination.valueOf(KeyCombination.java:409)
at org.jabref@100.0.0/org.jabref.gui.keyboard.KeyBindingRepository.getKeyCombination(KeyBindingRepository.java:129)
at org.jabref@100.0.0/org.jabref.gui.keyboard.KeyBindingRepository.checkKeyCombinationEquality(KeyBindingRepository.java:140)
at org.jabref@100.0.0/org.jabref.gui.keyboard.KeyBindingRepository.mapToKeyBinding(KeyBindingRepository.java:116)
at org.jabref@100.0.0/org.jabref.gui.JabRefFrame.lambda$initKeyBindings$5(JabRefFrame.java:236)
at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventFilterRecord.handleCapturingEvent(CompositeEventHandler.java:321)
at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchCapturingEvent(CompositeEventHandler.java:98)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:221)
at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:180)
at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchCapturingEvent(CompositeEventDispatcher.java:43)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:52)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Scene.java:4098)
at javafx.graphics/javafx.scene.Scene.processKeyEvent(Scene.java:2157)
at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2625)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(View.java:547)
at javafx.graphics/com.sun.glass.ui.View.notifyKey(View.java:971)

@koppor
Copy link
Member

koppor commented Oct 12, 2020

@Gena928 You pasated a PNG instead of using a link into the code (offered by the GitHub UI) (or maybe additoinally)

The affected keys are at org.jabref.gui.keyboard.KeyBinding#NEW_MASTERSTHESIS.

Can't we just add alt+ at them to a) provide a shortcut (seems to be required according to the comment) and b) having a default short cut surely not conflicting?

@Gena928 While you are on it, could you please add a shortcot for New inproceedings? In computer science we use that type in 80% of our cases and that would make JabRef more comfortable to use.

@Gena928
Copy link
Contributor Author

Gena928 commented Oct 13, 2020

@koppor
I'm very sorry for delay with this Issue. I'll try to fix it today, including shortcut for New inprocessing.

@tobiasdiez
Copy link
Member

@Gena928 You should be able to fix this error by adding a few additional if-statements if the keybinding string is empty.

@Gena928
Copy link
Contributor Author

Gena928 commented Oct 13, 2020

@tobiasdiez , @koppor Please review changes.

  1. I solved the problem with empty defaultKeyBinding string by adding an if statement in KeyBindingRepository.java.

  2. Key combinations for NEW_INBOOK...NEW_TECHREPORT changed from ctrl+.... to alt+....

  3. I think now we can keep ctrl+shift+R for PULL_CHANGES_FROM_SHARED_DATABASE.
    As it was initially. What do you think?

  4. I also created NEW_INPROCEEDINGS KeyBinding.
    But I cant't find this menu item in createMenu() method of JabRefFrame class. ))) Sorry, need help. Do we have such menu item? Where? )))

@koppor
Copy link
Member

koppor commented Oct 14, 2020

@tobiasdiez , @koppor Please review changes.

Could you please resolve the conflicts. Please merge upstream/master.

1. I solved the problem with empty `defaultKeyBinding` string by adding an `if` statement in `KeyBindingRepository.java`.

LGTM.

2. Key combinations for NEW_INBOOK...NEW_TECHREPORT changed from `ctrl+....` to `alt+....`

It was on purpose to add an additional modifier and not to change the modifier. I was thinking that an additoinal moddifier is easer to remember instead of another modifier.

However, having our discussion in mind, we should just leave these shortcuts empty. A user seldomly will use these shortcuts.

3. I think now we can keep `ctrl+shift+R` for PULL_CHANGES_FROM_SHARED_DATABASE.
   As it was initially. What do you think?

That's good. Please revert your change to change the modifier to alt+shift+D.

4. I also created NEW_INPROCEEDINGS KeyBinding.

Looks good.

   But I cant't find this menu item in `createMenu()` method of `JabRefFrame` class. ))) Sorry, need help. Do we have such menu item? Where? )))

I don't quite get what you are referring to with "this menu item". In the normal entry creation menu, it is already there: https://docs.jabref.org/collect/add-entry-manually I think, your current code enough.

I think, it should also be added to org.jabref.gui.fieldeditors.TypeEditorViewModel#TypeEditorViewModel

Corrected TypeEditorViewModel & KeyBinding
@Gena928
Copy link
Contributor Author

Gena928 commented Oct 14, 2020

@koppor
Done. Sorry, for "menu item". I thought you can attach key bindings only to menu items, but now I know about keys for https://docs.jabref.org/collect/add-entry-manually. New InProceedings works via shortcut alt+shift+C.

Please review org.jabref.gui.fieldeditors.TypeEditorViewModel. I added new line there, but I still can't understand where and how it's used. ))) Can you give a small comment?

src/main/java/org/jabref/gui/keyboard/KeyBinding.java Outdated Show resolved Hide resolved
src/main/java/org/jabref/gui/keyboard/KeyBinding.java Outdated Show resolved Hide resolved
@@ -113,8 +113,10 @@ public int size() {

public Optional<KeyBinding> mapToKeyBinding(KeyEvent keyEvent) {
for (KeyBinding binding : KeyBinding.values()) {
if (checkKeyCombinationEquality(binding, keyEvent)) {
return Optional.of(binding);
if (!binding.getDefaultKeyBinding().isEmpty()){
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this works? I would gess getDefaultKeyBinding is always empty for NEW_INBOOK even though the user has overwritten it. On first glance, I would suggest to change the getKeyCombination method below to public Optional<KeyCombination> getKeyCombination(KeyBinding bindName) and return an empty optional if binding is empty.

Moreover, get should probably return en empty string instead of "Not associated" to be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works. If I change the next statement
from public KeyCombination getKeyCombination(KeyBinding bindName)
to Optional<KeyCombination> getKeyCombination(KeyBinding bindName)

I have to change other parts of code. For example line 141
from KeyCombination keyCombination = getKeyCombination(binding);
to KeyCombination keyCombination = getKeyCombination(binding).get();

Is this what you mean?

Copy link
Member

Choose a reason for hiding this comment

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

Okay, can you briefly explain why it works? I thought "getDefaultKeyBinding" then always returns an empty string, so this check is always false.

Yeah, there are more code changes required for my suggestion. I think it would provide a clean solution to handle the case that for a given keybinding there is not necessarily a keycombination. But I didn't had the time yet to check the code in detail. So if your solution indeed works, then it's fine with me as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I started debugger and see that it always returns shortcut from KeyBinding.java file.

Screenshot 2020-10-14 at 12 56 37

Solution with Optional looks more clean. I just want to confirm that if we implement it, we also change other parts of code to getKeyCombination(binding).get().

Copy link
Member

Choose a reason for hiding this comment

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

In case this is done, the code fragment is getKeyCombination(binding).ifpresent(combination -> ...)

Copy link
Member

Choose a reason for hiding this comment

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

@Gena928 Exactly! So if you change the keybinding for "New inbook" to something, then getDefaultKeybinding should still return an empty string, so the code never goes into the if body in this case (although it should to match the new-user defined key).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tobiasdiez
I agree. If you change default shortcut, this code will not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try to fix today.

@koppor
Copy link
Member

koppor commented Oct 14, 2020

@Gena928 Please try to merge upstream/master to resolve the merge conflicts.

@Gena928
Copy link
Contributor Author

Gena928 commented Oct 15, 2020

@koppor , @tobiasdiez ,
please review changes. Sorry for delay - I'm trying to learn Java with mentor and become valuable contributor )). So thank you for your comments here. They really help.
I changed getKeyCombination method of KeyBindingRepository class and all it's dependencies.

Also please give your comments for TypeEditorViewModel class - this comment from @tobiasdiez

Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

Good work so far, keep on coding and learning.
Got three little remarks.

CHANGELOG.md Outdated Show resolved Hide resolved
@Gena928
Copy link
Contributor Author

Gena928 commented Oct 18, 2020

@calixtus ,
thanks for comments. Please review changes.

Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

Still three issues. ;-)

CHANGELOG.md Show resolved Hide resolved
src/main/resources/l10n/JabRef_en.properties Outdated Show resolved Hide resolved
@Gena928
Copy link
Contributor Author

Gena928 commented Oct 18, 2020

@calixtus
thanks again, corrected.
Looks like my "CheckStyle" was disabled. Maybe because of Intellij update?

Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

LGTM to me now. Thanks for your efforts!

@koppor
Copy link
Member

koppor commented Oct 18, 2020

Also OK for me. Still have to update CHANGELOG.md, because keyboard shortcuts were removed in this PR.

@koppor koppor merged commit d5922d9 into JabRef:master Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Double key binding for inserting new TechReport and pulling changes from shared database
5 participants