Skip to content

Show keyboard shortcuts for zoom, maximize and restore in the context menu - #1147

Open
ricky-rav wants to merge 2 commits into
gnome-terminator:masterfrom
ricky-rav:popup-menu-zoom-accels
Open

ricky-rav wants to merge 2 commits into
gnome-terminator:masterfrom
ricky-rav:popup-menu-zoom-accels

Conversation

@ricky-rav

Copy link
Copy Markdown

Two problems with the shortcuts shown in the terminal context menu:

  1. The "Zoom terminal", "Maximize terminal" and "Restore all terminals" entries are built with a plain Gtk.MenuItem, unlike Copy, Paste, Split, Open Tab or Close, which go through TerminalPopupMenu.menu_item() and show their keybinding. From the menu alone there is no way to find out that Ctrl+Shift+Z and Ctrl+Shift+X do the same thing as these entries.
  2. menu_item() parses the binding by hand: it recognises only <Shift>, <Control>/<Primary> and <Alt>, takes the key from the last character of the binding and otherwise falls back to the entry's mnemonic letter. A custom binding like <Control>F5 is therefore shown as Ctrl+Z on "Zoom terminal" (the key handler honours F5 just fine), and a <Super> binding is not shown at all.

What this PR does:

  • builds the three zoom entries through menu_item(), so they show the scaled_zoom and toggle_zoom bindings; "Restore all terminals" shows toggle_zoom, or scaled_zoom when toggle_zoom is unbound (both restore the layout)
  • parses bindings with Gtk.accelerator_parse(), which handles the modifiers and key names used in the [keybindings] section; a binding GTK cannot parse yields an entry without shortcut rather than a wrong one
  • reads the keybindings table with get_item('keybindings') instead of passing the action name as the profile argument, and treats "", None and "None" alike as unbound
  • adds tests for menu_item() in tests/test_terminal_popup_menu.py

The tests run as part of the existing pytest suite (xvfb-run -a pytest-3, same as CI).

… menu

The terminal context menu shows the configured keybinding next to most
of its entries (Copy, Paste, Split, Open Tab, Close...), because they are
built through TerminalPopupMenu.menu_item(). The "Zoom terminal",
"Maximize terminal" and "Restore all terminals" entries were still built
with a plain Gtk.MenuItem, so users had no way to discover from the menu
that Ctrl+Shift+Z and Ctrl+Shift+X do the same thing as these entries.

Build those three entries through menu_item() as well, so they display
the scaled_zoom and toggle_zoom shortcuts. Both bindings restore the
layout when a terminal is zoomed, so "Restore all terminals" shows
toggle_zoom, or scaled_zoom when toggle_zoom is unbound.

Add tests covering menu_item() for the two zoom actions.

Signed-off-by: Riccardo Ravaioli <rravaioli@nvidia.com>
TerminalPopupMenu.menu_item() built the accelerator shown next to a menu
entry by hand: it recognised only <Shift>, <Control>/<Primary> and <Alt>,
and took the key from the last character of the binding, falling back to
the entry's mnemonic letter. A binding such as "<Control>F5" was shown as
Ctrl+Z on "Zoom terminal" while the key handler honoured F5, and a
binding on <Super> was not shown at all.

Let Gtk.accelerator_parse() do the parsing: it handles the modifiers and
key names used in the keybindings section, and yields no key for a
binding it cannot parse, in which case the entry is shown without a
shortcut instead of with a wrong one.

While at it, read the keybindings table with get_item('keybindings')
instead of passing the action name as the profile argument, and treat
"", None and "None" alike as unbound.

Signed-off-by: Riccardo Ravaioli <rravaioli@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant