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

Multiple shortcut keys for a single command #731

Open
jtrakk opened this issue Aug 26, 2019 · 6 comments
Open

Multiple shortcut keys for a single command #731

jtrakk opened this issue Aug 26, 2019 · 6 comments
Labels
enhancement New features, or improvements to existing features.

Comments

@jtrakk
Copy link

jtrakk commented Aug 26, 2019

I just tried Podium in Python3.7 on Ubuntu 18.04, it worked great.

There was no support for my editor's bindings though, which I think is because toga.command.Command only has one shortcut attribute. I propose changing it to a shortcuts collection. It could retain the shortcut api for backward compatibility.

@freakboy3742
Copy link
Member

Glad to hear Podium worked for you!

Not sure I understand the feature request, though. What is the significance of your editors bindings? Are shortcut collections a feature of GTK/Linux/Ubuntu that I'm not aware of?

Or are you suggesting that we allow multiple shortcuts for a single Command? In which case - how would we determine which shortcut was currently "active"?

@jtrakk
Copy link
Author

jtrakk commented Aug 26, 2019

What is the significance of your editors bindings?

To accommodate those of us who've melded our brains with our editor, many popular tools provide support for the bindings of Vim and/or Emacs in addition to the more "modern" bindings.

Are shortcut collections a feature of GTK/Linux/Ubuntu that I'm not aware of?

There is ~/.inputrc for line-editing bindings (see man readline) (but this feature request isn't intended to ask for support of that feature).

Or are you suggesting that we allow multiple shortcuts for a single Command?

Exactly. For example, I would like down-arrow or j (Vim's "down" command) or ctrl-n (emacs's down command) to go to the next slide.

In which case - how would we determine which shortcut was currently "active"?

I'm thinking it needn't be just one; pressing any of down-arrow or j or ctrl-n could advance the slide. Or maybe I don't understand the question?

@jtrakk
Copy link
Author

jtrakk commented Aug 26, 2019

Sorry about the confusion, re-reading my message I can see why it's not clear. By "shortcuts collection" I just meant a collections.abc.Collection like a set or list, not like a global system setting or anything. So for example instead of

            toga.Command(
                self.next_slide,
                label='Next slide',
                shortcut=toga.Key.RIGHT,
            ),

it could be

            toga.Command(
                self.next_slide,
                label='Next slide',
                shortcuts={toga.Key.RIGHT, toga.KEY.j},
            ),

@freakboy3742
Copy link
Member

Ok; I think I've got a better understanding now.

I'm not sure what you're asking for is strictly possible - at least, not at the Toga level. Most operating systems only allow a single keybinding to a menu command (that's definintely true of macOS and Windows). Can you give an example of a GUI application that has multiple keybindings for a single command?

In the specific case of Podium, it might be possible - but only because the slide deck has an additional layer of control that is independent of the command definition. For example, although the menu lists left/right arrow as the binding for next/previous, up/down are also bound to the same action at the level of the slide deck. I'm a little wary of adding dozens of key bindings for forward/backward - but that's a feature request that can be discussed on the Podium issue tracker.

@jtrakk
Copy link
Author

jtrakk commented Aug 26, 2019

Can you give an example of a GUI application that has multiple keybindings for a single command?

  • The editors I'm familiar with (Vim/Emacs/VSCode) do
  • This answer claims that dconf-editor supports binding multiple keys to the same command.
  • This answer says it's possible in Qt
  • The browsers support ctrl-r and F5 for refresh and alt-d and F6 for selecting the address bar

I realize most of these are not the targets that Toga supports. If some/most/all GUI systems don't support it natively, I still think it's a useful enough feature that it'd be worth providing a workaround so that other keys would work, even if they're not displayed in the GUI menu. For example,

Command(shortcut=toga.Key.RIGHT, shortcut_aliases=[toga.KEY('l')])

If that's not possible, or possibly as a separate feature, it'd be nice to have an interface for switching between "basic bindings", "emacs bindings", and "vim bindings". RStudio (a Qt app) has a setting for that, for example.

@jtrakk jtrakk changed the title Multiple shortcut keys Multiple shortcut keys for a single command Aug 26, 2019
@freakboy3742
Copy link
Member

For clarity - there's a difference between "has multiple keyboard shortcuts" and "has multiple keyboard shortcuts displayed in the menu". In the Browser example, for example, you'll only see one shortcut (usually CMD R) displayed as a hint; the other Just Works.

To that end - the "alias" approach you've described seems reasonable; menus will use the shortcut, and alias bindings will be added as allowed on each platforms.

We may also want to consider allowing making Shortcut a dictionary, so you can make shortcuts that are platform specific. For example, in Podium, MOD1-Tab is the current command for switch screens, which is CMD-Tab on macOS; but Ctrl-TAB is reserved by the OS (AFAICT) on Linux. Collisions with existing or system key bindings are likely to be common, so we should accomodate them, and any system-wide alias tooling that exists (like dconf-editor).

The separate feature of "use X bindings" is also a nice idea; it's more of a feature that would be specific to Podium in this case, although Toga would need to provide the infrastructure to make it possible - specifically, an implementation of #90.

@freakboy3742 freakboy3742 added enhancement New features, or improvements to existing features. up-for-grabs labels Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

2 participants