Commit f1c46cb5 authored by Egmont Koblinger's avatar Egmont Koblinger

all: Improve mnemonic handling

Disable mnemonics for the submenus (Alt+F for File etc.) when the menubar
is shown by the shell (e.g. Unity) so that they are usable in the terminal.
(As of the GMenu port, disabling them via the config option didn't work.)
Also hide the corresponding preference checkbox.

Make mnemonics work in the Find and Preferences windows.

https://bugzilla.gnome.org/show_bug.cgi?id=792978
parent d6f1dd28
......@@ -16,7 +16,7 @@ src/terminal-app.c
src/terminal.c
src/terminal-encoding.c
src/terminal-mdi-container.c
[type: gettext/glade]src/terminal-menubar.ui
[type: gettext/glade]src/terminal-menubar.ui.in
src/terminal-menu-button.c
src/terminal-nautilus.c
src/terminal-notebook.c
......
......@@ -30,6 +30,8 @@ gnome_terminal_server_built = \
terminal-gdbus-generated.h \
terminal-resources.c \
terminal-resources.h \
terminal-menubar-with-mnemonics.ui \
terminal-menubar-without-mnemonics.ui \
$(NULL)
BUILT_SOURCES += $(gnome_terminal_server_built)
......@@ -167,6 +169,12 @@ terminal-gdbus-generated.c terminal-gdbus-generated.h: org.gnome.Terminal.xml Ma
--generate-c-code terminal-gdbus-generated \
$<
terminal-menubar-with-mnemonics.ui: terminal-menubar.ui.in
sed -e 's|<WITH_MNEMONIC>||g' -e 's|</WITH_MNEMONIC>||g' -e 's|<WITHOUT_MNEMONIC>|<!-- |g' -e 's|</WITHOUT_MNEMONIC>| -->|g' $< > $@
terminal-menubar-without-mnemonics.ui: terminal-menubar.ui.in
sed -e 's|<WITH_MNEMONIC>|<!-- |g' -e 's|</WITH_MNEMONIC>| -->|g' -e 's|<WITHOUT_MNEMONIC>||g' -e 's|</WITHOUT_MNEMONIC>||g' $< > $@
terminal-resources.h terminal-resources.c: terminal.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir $(srcdir) $(srcdir)/terminal.gresource.xml)
$(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) --generate --c-name terminal $<
......@@ -354,7 +362,7 @@ CLEANFILES = \
EXTRA_DIST = \
terminal.about \
terminal-appmenu.ui \
terminal-menubar.ui \
terminal-menubar.ui.in \
terminal-notebook-menu.ui \
terminal-window.ui \
terminal.gresource.xml \
......
......@@ -689,13 +689,30 @@ terminal_app_startup (GApplication *application)
app_load_css (application);
/* Figure out whether the shell shows appmenu/menubar */
gboolean shell_shows_appmenu, shell_shows_menubar;
g_object_get (gtk_settings_get_default (),
"gtk-shell-shows-app-menu", &shell_shows_appmenu,
"gtk-shell-shows-menubar", &shell_shows_menubar,
NULL);
/* App menu */
GMenu *appmenu_new_terminal_section = gtk_application_get_menu_by_id (gtk_application,
"new-terminal-section");
fill_new_terminal_section (appmenu_new_terminal_section, NULL, 0); /* no submenu */
/* Menubar */
terminal_util_load_objects_resource ("/org/gnome/terminal/ui/menubar.ui",
/* If the menubar is shown by the shell, omit mnemonics for the submenus. This is because Alt+F etc.
* are more important to be usable in the terminal, the menu cannot be replaced runtime (to toggle
* between mnemonic and non-mnemonic versions), gtk-enable-mnemonics or gtk_window_set_mnemonic_modifier()
* don't effect the menubar either, so there wouldn't be a way to disable Alt+F for File etc. otherwise.
* Furthermore, the menu would even grab mnemonics from the File and Preferences windows.
* In Unity, Alt+F10 opens the menubar, this should be good enough for keyboard navigation.
* If the menubar is shown by the app, toggling mnemonics is handled in terminal-window.c using
* gtk_window_set_mnemonic_modifier().
* See bug 792978 for details. */
terminal_util_load_objects_resource (shell_shows_menubar ? "/org/gnome/terminal/ui/menubar-without-mnemonics.ui"
: "/org/gnome/terminal/ui/menubar-with-mnemonics.ui",
"menubar", &app->menubar,
"new-terminal-section", &app->menubar_new_terminal_section,
"set-profile-section", &app->menubar_set_profile_section,
......@@ -710,12 +727,7 @@ terminal_app_startup (GApplication *application)
/* Install the encodings submenu */
terminal_encodings_append_menu (app->menubar_set_encoding_submenu);
/* If the shell wants to show the appmenu/menubar, make it available */
gboolean shell_shows_appmenu, shell_shows_menubar;
g_object_get (gtk_settings_get_default (),
"gtk-shell-shows-app-menu", &shell_shows_appmenu,
"gtk-shell-shows-menubar", &shell_shows_menubar,
NULL);
/* Show/hide the appmenu/menubar as appropriate */
if (!shell_shows_appmenu)
gtk_application_set_app_menu (GTK_APPLICATION (app), NULL);
if (shell_shows_menubar)
......
......@@ -18,7 +18,8 @@
<interface>
<menu id="menubar">
<submenu>
<attribute name="label" translatable="yes">_File</attribute>
<WITH_MNEMONIC><attribute name="label" translatable="yes">_File</attribute></WITH_MNEMONIC>
<WITHOUT_MNEMONIC><attribute name="label" translatable="yes">File</attribute></WITHOUT_MNEMONIC>
<section id="new-terminal-section" />
<section>
<item>
......@@ -51,7 +52,8 @@
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">_Edit</attribute>
<WITH_MNEMONIC><attribute name="label" translatable="yes">_Edit</attribute></WITH_MNEMONIC>
<WITHOUT_MNEMONIC><attribute name="label" translatable="yes">Edit</attribute></WITHOUT_MNEMONIC>
<section>
<item>
<attribute name="label" translatable="yes">_Copy</attribute>
......@@ -87,7 +89,8 @@
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">_View</attribute>
<WITH_MNEMONIC><attribute name="label" translatable="yes">_View</attribute></WITH_MNEMONIC>
<WITHOUT_MNEMONIC><attribute name="label" translatable="yes">View</attribute></WITHOUT_MNEMONIC>
<section>
<item>
<attribute name="label" translatable="yes">Show _Menubar</attribute>
......@@ -115,7 +118,8 @@
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">_Search</attribute>
<WITH_MNEMONIC><attribute name="label" translatable="yes">_Search</attribute></WITH_MNEMONIC>
<WITHOUT_MNEMONIC><attribute name="label" translatable="yes">Search</attribute></WITHOUT_MNEMONIC>
<section>
<item>
<attribute name="label" translatable="yes">_Find…</attribute>
......@@ -136,7 +140,8 @@
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">_Terminal</attribute>
<WITH_MNEMONIC><attribute name="label" translatable="yes">_Terminal</attribute></WITH_MNEMONIC>
<WITHOUT_MNEMONIC><attribute name="label" translatable="yes">Terminal</attribute></WITHOUT_MNEMONIC>
<section>
<section id="set-profile-section" />
<item>
......@@ -190,7 +195,8 @@
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">Ta_bs</attribute>
<WITH_MNEMONIC><attribute name="label" translatable="yes">Ta_bs</attribute></WITH_MNEMONIC>
<WITHOUT_MNEMONIC><attribute name="label" translatable="yes">Tabs</attribute></WITHOUT_MNEMONIC>
<attribute name="action">win.tabs-menu</attribute>
<attribute name="hidden-when">action-disabled</attribute>
<section>
......@@ -221,7 +227,8 @@
</section>
</submenu>
<submenu>
<attribute name="label" translatable="yes">_Help</attribute>
<WITH_MNEMONIC><attribute name="label" translatable="yes">_Help</attribute></WITH_MNEMONIC>
<WITHOUT_MNEMONIC><attribute name="label" translatable="yes">Help</attribute></WITHOUT_MNEMONIC>
<section>
<item>
<attribute name="label" translatable="yes">_Contents</attribute>
......
......@@ -859,11 +859,15 @@ terminal_prefs_show_preferences (GSettings *profile, const char *widget_name)
gtk_widget_set_visible (new_terminal_mode_combo, FALSE);
#endif
g_settings_bind (settings,
TERMINAL_SETTING_ENABLE_MNEMONICS_KEY,
disable_mnemonics_button,
"active",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
if (shell_shows_menubar) {
gtk_widget_set_visible (disable_mnemonics_button, FALSE);
} else {
g_settings_bind (settings,
TERMINAL_SETTING_ENABLE_MNEMONICS_KEY,
disable_mnemonics_button,
"active",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
}
g_settings_bind (settings,
TERMINAL_SETTING_ENABLE_MENU_BAR_ACCEL_KEY,
disable_menu_accel_button,
......
......@@ -1381,6 +1381,23 @@ enable_menubar_accel_changed_cb (GSettings *settings,
#endif
}
/* The menubar is shown by the app, and the use of mnemonics (e.g. Alt+F for File) is toggled.
* The mnemonic modifier is per window, so it doesn't affect the Find or Preferences windows.
* If the menubar is shown by the shell, a non-mnemonic variant of the menu is loaded instead
* in terminal-app.c. See over there for further details. */
static void
enable_mnemonics_changed_cb (GSettings *settings,
const char *key,
TerminalWindow *window)
{
gboolean enabled = g_settings_get_boolean (settings, key);
if (enabled)
gtk_window_set_mnemonic_modifier (GTK_WINDOW (window), GDK_MOD1_MASK);
else
gtk_window_set_mnemonic_modifier (GTK_WINDOW (window), GDK_MODIFIER_MASK & ~GDK_RELEASE_MASK);
}
static void
app_setting_notify_destroy_cb (GtkSettings *gtk_settings)
{
......@@ -2040,12 +2057,6 @@ terminal_window_screen_update (TerminalWindow *window,
gtk_settings,
(GDestroyNotify) app_setting_notify_destroy_cb);
g_settings_bind (settings,
TERMINAL_SETTING_ENABLE_MNEMONICS_KEY,
gtk_settings,
"gtk-enable-mnemonics",
G_SETTINGS_BIND_GET);
g_settings_bind (settings,
TERMINAL_SETTING_ENABLE_SHORTCUTS_KEY,
gtk_settings,
......@@ -2232,6 +2243,11 @@ terminal_window_init (TerminalWindow *window)
g_simple_action_set_enabled (lookup_action (window, "leave-fullscreen"), FALSE);
GSettings *global_settings = terminal_app_get_global_settings (app);
enable_mnemonics_changed_cb (global_settings, TERMINAL_SETTING_ENABLE_MNEMONICS_KEY, window);
g_signal_connect (global_settings, "changed::" TERMINAL_SETTING_ENABLE_MNEMONICS_KEY,
G_CALLBACK (enable_mnemonics_changed_cb), window);
/* Hide "menubar-visible" when the menubar is shown by the shell */
g_object_get (gtk_widget_get_settings (GTK_WIDGET (window)),
"gtk-shell-shows-menubar", &shell_shows_menubar,
......@@ -2337,6 +2353,13 @@ terminal_window_dispose (GObject *object)
TerminalWindowPrivate *priv = window->priv;
TerminalApp *app = terminal_app_get ();
if (!priv->disposed) {
GSettings *global_settings = terminal_app_get_global_settings (app);
g_signal_handlers_disconnect_by_func (global_settings,
G_CALLBACK (enable_mnemonics_changed_cb),
window);
}
priv->disposed = TRUE;
if (priv->clipboard != NULL) {
......
......@@ -19,7 +19,8 @@
<gresource prefix="/org/gnome/terminal">
<file alias="css/terminal.css" compressed="true">terminal.common.css</file>
<file alias="gtk/menus.ui" compressed="true" preprocess="xml-stripblanks">terminal-appmenu.ui</file>
<file alias="ui/menubar.ui" compressed="true" preprocess="xml-stripblanks">terminal-menubar.ui</file>
<file alias="ui/menubar-with-mnemonics.ui" compressed="true" preprocess="xml-stripblanks">terminal-menubar-with-mnemonics.ui</file>
<file alias="ui/menubar-without-mnemonics.ui" compressed="true" preprocess="xml-stripblanks">terminal-menubar-without-mnemonics.ui</file>
<file alias="ui/notebook-menu.ui" compressed="true" preprocess="xml-stripblanks">terminal-notebook-menu.ui</file>
<file alias="ui/preferences.ui" compressed="true" preprocess="xml-stripblanks">preferences.ui</file>
<file alias="ui/search-popover.ui" compressed="true" preprocess="xml-stripblanks">search-popover.ui</file>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment