Merge branch 'matthiasc/for-master' into 'master'

Keynav improvements for widget-factory

See merge request GNOME/gtk!1804
This commit is contained in:
Matthias Clasen 2020-05-01 12:02:13 +00:00
commit 850549ba83
4 changed files with 63 additions and 11 deletions

View File

@ -1816,21 +1816,27 @@ activate (GApplication *app)
{ "app.about", { "F1", NULL } },
{ "app.quit", { "<Control>q", NULL } },
{ "app.open-in", { "<Control>n", NULL } },
{ "app.cut", { "<Control>x", NULL } },
{ "app.copy", { "<Control>c", NULL } },
{ "app.paste", { "<Control>v", NULL } },
{ "win.dark", { "<Control>d", NULL } },
{ "win.search", { "<Control>s", NULL } },
{ "win.delete", { "Delete", NULL } },
{ "win.background", { "<Control>b", NULL } },
{ "win.open", { "<Control>o", NULL } },
{ "win.record", { "<Control>r", NULL } },
{ "win.lock", { "<Control>l", NULL } },
};
struct {
const gchar *action_and_target;
const gchar *accelerators[2];
} late_accels[] = {
{ "app.cut", { "<Control>x", NULL } },
{ "app.copy", { "<Control>c", NULL } },
{ "app.paste", { "<Control>v", NULL } },
{ "win.delete", { "Delete", NULL } },
};
gint i;
GPermission *permission;
GAction *action;
GError *error = NULL;
GtkEventController *controller;
g_type_ensure (my_text_view_get_type ());
@ -1870,6 +1876,24 @@ activate (GApplication *app)
win_entries, G_N_ELEMENTS (win_entries),
window);
controller = gtk_shortcut_controller_new ();
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
for (i = 0; i < G_N_ELEMENTS (late_accels); i++)
{
guint key;
GdkModifierType mods;
GtkShortcutTrigger *trigger;
GtkShortcutAction *ac;
gtk_accelerator_parse (late_accels[i].accelerators[0], &key, &mods);
trigger = gtk_keyval_trigger_new (key, mods);
ac = gtk_named_action_new (late_accels[i].action_and_target);
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller),
gtk_shortcut_new (trigger, ac));
}
gtk_widget_add_controller (GTK_WIDGET (window), controller);
for (i = 0; i < G_N_ELEMENTS (accels); i++)
gtk_application_set_accels_for_action (GTK_APPLICATION (app), accels[i].action_and_target, accels[i].accelerators);

View File

@ -465,7 +465,8 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child>
<object class="GtkStackPage">
<property name="name">page1</property>
<property name="title" translatable="yes">Page 1</property>
<property name="title" translatable="yes">Page _1</property>
<property name="use-underline">1</property>
<property name="child">
<object class="GtkBox" id="page1">
<property name="orientation">vertical</property>
@ -1459,7 +1460,8 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child>
<object class="GtkStackPage">
<property name="name">page2</property>
<property name="title" translatable="yes">Page 2</property>
<property name="title" translatable="yes">Page _2</property>
<property name="use-underline">1</property>
<property name="child">
<object class="GtkOverlay" id="page2">
<child type="overlay">
@ -2175,7 +2177,8 @@ microphone-sensitivity-medium-symbolic</property>
<child>
<object class="GtkStackPage">
<property name="name">page3</property>
<property name="title" translatable="yes">Page 3</property>
<property name="title" translatable="yes">Page _3</property>
<property name="use-underline">1</property>
<property name="child">
<object class="GtkBox">
<property name="spacing">10</property>

View File

@ -184,6 +184,7 @@ enum
CHILD_PROP_ICON_NAME,
CHILD_PROP_NEEDS_ATTENTION,
CHILD_PROP_VISIBLE,
CHILD_PROP_USE_UNDERLINE,
LAST_CHILD_PROP
};
@ -195,9 +196,10 @@ struct _GtkStackPage
char *name;
char *title;
char *icon_name;
gboolean needs_attention;
gboolean visible;
GtkWidget *last_focus;
guint needs_attention : 1;
guint visible : 1;
guint use_underline : 1;
};
typedef struct _GtkStackPageClass GtkStackPageClass;
@ -268,6 +270,10 @@ gtk_stack_page_get_property (GObject *object,
g_value_set_boolean (value, gtk_stack_page_get_visible (info));
break;
case CHILD_PROP_USE_UNDERLINE:
g_value_set_boolean (value, info->use_underline);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -348,6 +354,14 @@ gtk_stack_page_set_property (GObject *object,
gtk_stack_page_set_visible (info, g_value_get_boolean (value));
break;
case CHILD_PROP_USE_UNDERLINE:
if (info->use_underline != g_value_get_boolean (value))
{
info->use_underline = g_value_get_boolean (value);
g_object_notify_by_pspec (object, pspec);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -412,6 +426,13 @@ gtk_stack_page_class_init (GtkStackPageClass *class)
TRUE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
stack_child_props[CHILD_PROP_USE_UNDERLINE] =
g_param_spec_boolean ("use-underline",
P_("Use underline"),
P_("If set, an underline in the title indicates the next character should be used for the mnemonic accelerator key"),
FALSE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, LAST_CHILD_PROP, stack_child_props);
}

View File

@ -123,7 +123,8 @@ on_button_toggled (GtkWidget *button,
static void
rebuild_child (GtkWidget *self,
const gchar *icon_name,
const gchar *title)
const gchar *title,
gboolean use_underline)
{
GtkWidget *button_child;
@ -145,6 +146,7 @@ rebuild_child (GtkWidget *self,
else if (title != NULL)
{
button_child = gtk_label_new (title);
gtk_label_set_use_underline (GTK_LABEL (button_child), use_underline);
gtk_widget_set_tooltip_text (GTK_WIDGET (self), NULL);
@ -168,15 +170,17 @@ update_button (GtkStackSwitcher *self,
gchar *icon_name;
gboolean needs_attention;
gboolean visible;
gboolean use_underline;
g_object_get (page,
"title", &title,
"icon-name", &icon_name,
"needs-attention", &needs_attention,
"visible", &visible,
"use-underline", &use_underline,
NULL);
rebuild_child (button, icon_name, title);
rebuild_child (button, icon_name, title, use_underline);
gtk_widget_set_visible (button, visible && (title != NULL || icon_name != NULL));