-
Notifications
You must be signed in to change notification settings - Fork 271
A helper to add key combinations to buttons #205
Comments
Do you feel that it is necessary to listen to scene changes and reapply the keyCodeCombination or should we simply assign to the current or the first scene? The way you have written it, I suspect it would fail if the button is already part of a Scene (ie. the call to |
I also wonder if the most common use case is to use mnemonics, or do you generally use more exotic combinations than modifier+single letter? |
The thing is that inside the dsl a button does not have a scene yet, so |
I have no statistics on the usage of key combinations (the only thing I've ever used is |
I realize that the button doesn't have a scene inside a dsl, but there are two (better) solutions to that.
I suggest going with approach number two. What do you think? |
The 2nd sounds very good to me! Much better than my |
Do you want to create a PR for this or should I? :) |
Let me try and make a PR till the end of the week. If I can't - add it yourself :) |
Good plan :) |
This seems to be more complicated than we initially thought. If you open multiple versions of the same fragment you will bind these keys multiple times. Also, if you use the new InternalWindow, the accelerator needs to go away when the window closes. I'm looking for solutions now. |
I think I found a good solution now. Instead of relying on the scene directly, I hook onto the fun Button.accelerator(combo: KeyCombination) {
var oldCombo: Runnable? = null
var currentScene: Scene? = null
whenDocked {
scene?.accelerators?.apply {
currentScene = scene
oldCombo = get(combo)
put(combo, Runnable { fire() })
}
}
whenUndocked {
currentScene?.accelerators?.apply {
if (oldCombo != null) put(combo, oldCombo)
else remove(combo)
}
}
} I have committed it now. Does this work for you? |
Usage example: button("Save") {
accelerator(KeyCodeCombination.valueOf("Alt+S"))
setOnAction {
alert(CONFIRMATION, "Saved!", "You did it!")
}
} |
I am glad to hear that you are working on it. I myself could not find any time :(
|
I also like the parallell to scene.accelerators, so I think we'll keep it, especially since it is actually implemented as accelerators on the scene. I'll make sure to mention "key, code, combination" in the docs, so at least it will be possible to find there :) Do you have a chance to try it before I release 1.5.8? |
Sorry, no testing from me :) With our set up it turned out to be a real pain to update libraries :( But I have a new small project coming, I'll try it then! |
OK, I added a framework test for it, so it seems good. I'll close the issue now. |
Oh, I will add one more option to it: It could take a accelerator("Alt+S") |
I strongly believe that it should utilise enum values of It may be possibly combined with an overloaded operator |
It still supports the KeyCombination parameter, but it has an overload to support a String, that's all :) We can for sure add the KeyCode.plus function as well, that's a good idea. |
I 've found that connecting a key combinations to a button is unusually hard.
Here is a helper I use in my project:
May be it might be abstracted to add key buildings to any action, but for buttons it should be really easy. Also note that theoretically one button can have more than one key combination.
The text was updated successfully, but these errors were encountered: