diff options
author | Christopher Davis <christopherdavis@gnome.org> | 2022-02-12 17:16:00 -0800 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2022-02-13 13:33:25 +0000 |
commit | ced8c1cb998b905a4494f6f8d675d376165f0c28 (patch) | |
tree | 7be49b6b519abe3df2dd7015d31794174cd83c3f | |
parent | 530fbac68e061c4e0f63968641e19beddfc50c5f (diff) | |
download | gnome-control-center-ced8c1cb998b905a4494f6f8d675d376165f0c28.tar.gz |
keyboard: Use GAction and GMenuModel for input row popovers
Gives these menus proper styling without having to
roll our own widgets.
Also removes the Remove button when the action is
disabled.
-rw-r--r-- | panels/keyboard/cc-input-row.c | 52 | ||||
-rw-r--r-- | panels/keyboard/cc-input-row.ui | 134 |
2 files changed, 61 insertions, 125 deletions
diff --git a/panels/keyboard/cc-input-row.c b/panels/keyboard/cc-input-row.c index 60e1cec21..966882451 100644 --- a/panels/keyboard/cc-input-row.c +++ b/panels/keyboard/cc-input-row.c @@ -25,10 +25,6 @@ struct _CcInputRow CcInputSource *source; - GtkButton *remove_button; - GtkButton *settings_button; - GtkSeparator *settings_separator; - GtkListBox *drag_widget; GtkDragSource *drag_source; @@ -107,9 +103,11 @@ drop_cb (GtkDropTarget *drop_target, } static void -move_up_button_clicked_cb (CcInputRow *self, - GtkButton *button) +move_up_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); GtkListBox *list_box = GTK_LIST_BOX (gtk_widget_get_parent (GTK_WIDGET (self))); gint previous_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (self)) - 1; GtkListBoxRow *previous_row = gtk_list_box_get_row_at_index (list_box, previous_idx); @@ -124,9 +122,11 @@ move_up_button_clicked_cb (CcInputRow *self, } static void -move_down_button_clicked_cb (CcInputRow *self, - GtkButton *button) +move_down_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); GtkListBox *list_box = GTK_LIST_BOX (gtk_widget_get_parent (GTK_WIDGET (self))); gint next_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (self)) + 1; GtkListBoxRow *next_row = gtk_list_box_get_row_at_index (list_box, next_idx); @@ -141,24 +141,33 @@ move_down_button_clicked_cb (CcInputRow *self, } static void -settings_button_clicked_cb (CcInputRow *self) +show_settings_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); g_signal_emit (self, signals[SIGNAL_SHOW_SETTINGS], 0); } static void -layout_button_clicked_cb (CcInputRow *self) +show_layout_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); g_signal_emit (self, signals[SIGNAL_SHOW_LAYOUT], 0); } static void -remove_button_clicked_cb (CcInputRow *self) +remove_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); g_signal_emit (self, signals[SIGNAL_REMOVE_ROW], 0); @@ -184,16 +193,6 @@ cc_input_row_class_init (CcInputRowClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/keyboard/cc-input-row.ui"); - gtk_widget_class_bind_template_child (widget_class, CcInputRow, remove_button); - gtk_widget_class_bind_template_child (widget_class, CcInputRow, settings_button); - gtk_widget_class_bind_template_child (widget_class, CcInputRow, settings_separator); - - gtk_widget_class_bind_template_callback (widget_class, layout_button_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, move_down_button_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, move_up_button_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, remove_button_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, settings_button_clicked_cb); - signals[SIGNAL_SHOW_SETTINGS] = g_signal_new ("show-settings", G_TYPE_FROM_CLASS (object_class), @@ -233,6 +232,12 @@ cc_input_row_class_init (CcInputRowClass *klass) NULL, G_TYPE_NONE, 0); + + gtk_widget_class_install_action (widget_class, "row.move-up", NULL, move_up_cb); + gtk_widget_class_install_action (widget_class, "row.move-down", NULL, move_down_cb); + gtk_widget_class_install_action (widget_class, "row.show-layout", NULL, show_layout_cb); + gtk_widget_class_install_action (widget_class, "row.show-settings", NULL, show_settings_cb); + gtk_widget_class_install_action (widget_class, "row.remove", NULL, remove_cb); } void @@ -272,8 +277,7 @@ cc_input_row_new (CcInputSource *source) g_signal_connect_object (source, "label-changed", G_CALLBACK (label_changed_cb), self, G_CONNECT_SWAPPED); label_changed_cb (self); - gtk_widget_set_visible (GTK_WIDGET (self->settings_button), CC_IS_INPUT_SOURCE_IBUS (source)); - gtk_widget_set_visible (GTK_WIDGET (self->settings_separator), CC_IS_INPUT_SOURCE_IBUS (source)); + gtk_widget_action_set_enabled (GTK_WIDGET (self), "row.show-settings", CC_IS_INPUT_SOURCE_IBUS (source)); return self; } @@ -290,7 +294,7 @@ cc_input_row_set_removable (CcInputRow *self, gboolean removable) { g_return_if_fail (CC_IS_INPUT_ROW (self)); - gtk_widget_set_sensitive (GTK_WIDGET (self->remove_button), removable); + gtk_widget_action_set_enabled (GTK_WIDGET (self), "row.remove", removable); } void diff --git a/panels/keyboard/cc-input-row.ui b/panels/keyboard/cc-input-row.ui index 79d73137b..e3a28d718 100644 --- a/panels/keyboard/cc-input-row.ui +++ b/panels/keyboard/cc-input-row.ui @@ -15,111 +15,43 @@ <object class="GtkMenuButton"> <property name="valign">center</property> <property name="icon_name">view-more-symbolic</property> - <property name="popover">popover_menu</property> + <property name="menu_model">popover_menu</property> <style> <class name="flat"/> </style> </object> </child> </template> - <object class="GtkPopover" id="popover_menu"> - <style> - <class name="menu" /> - </style> - <child> - <object class="GtkBox"> - <property name="margin-top">6</property> - <property name="margin-bottom">6</property> - <property name="margin-start">6</property> - <property name="margin-end">6</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkButton"> - <signal name="clicked" handler="move_up_button_clicked_cb" object="CcInputRow" swapped="yes"/> - <style> - <class name="flat"/> - </style> - <child> - <object class="GtkLabel"> - <property name="label" translatable="yes">Move up</property> - <property name="xalign">0.0</property> - </object> - </child> - </object> - </child> - <child> - <object class="GtkButton"> - <signal name="clicked" handler="move_down_button_clicked_cb" object="CcInputRow" swapped="yes"/> - <style> - <class name="flat"/> - </style> - <child> - <object class="GtkLabel"> - <property name="label" translatable="yes">Move down</property> - <property name="xalign">0.0</property> - </object> - </child> - </object> - </child> - <child> - <object class="GtkSeparator"> - <property name="orientation">horizontal</property> - </object> - </child> - <child> - <object class="GtkButton" id="settings_button"> - <property name="visible">False</property> - <signal name="clicked" handler="settings_button_clicked_cb" object="CcInputRow" swapped="yes"/> - <child> - <object class="GtkLabel"> - <property name="label" translatable="yes">Preferences</property> - <property name="xalign">0.0</property> - </object> - </child> - <style> - <class name="flat"/> - </style> - </object> - </child> - <child> - <object class="GtkSeparator" id="settings_separator"> - <property name="orientation">horizontal</property> - </object> - </child> - <child> - <object class="GtkButton"> - <signal name="clicked" handler="layout_button_clicked_cb" object="CcInputRow" swapped="yes"/> - <style> - <class name="flat"/> - </style> - <child> - <object class="GtkLabel"> - <property name="label" translatable="yes">View Keyboard Layout</property> - <property name="xalign">0.0</property> - </object> - </child> - </object> - </child> - <child> - <object class="GtkSeparator"> - <property name="orientation">horizontal</property> - </object> - </child> - <child> - <object class="GtkButton" id="remove_button"> - <signal name="clicked" handler="remove_button_clicked_cb" object="CcInputRow" swapped="yes"/> - <style> - <class name="flat"/> - </style> - <child> - <object class="GtkLabel"> - <property name="label" translatable="yes">Remove</property> - <property name="xalign">0.0</property> - </object> - </child> - </object> - </child> - </object> - </child> - </object> + <menu id="popover_menu"> + <section> + <item> + <attribute name="label" translatable="yes">Move Up</attribute> + <attribute name="action">row.move-up</attribute> + </item> + <item> + <attribute name="label" translatable="yes">Move Down</attribute> + <attribute name="action">row.move-down</attribute> + </item> + </section> + <section> + <item> + <attribute name="label" translatable="yes">Preferences</attribute> + <attribute name="action">row.show-settings</attribute> + <attribute name="hidden-when">action-disabled</attribute> + </item> + </section> + <section> + <item> + <attribute name="label" translatable="yes">View Keyboard Layout</attribute> + <attribute name="action">row.show-layout</attribute> + </item> + </section> + <section> + <item> + <attribute name="label" translatable="yes">Remove</attribute> + <attribute name="action">row.remove</attribute> + <attribute name="hidden-when">action-disabled</attribute> + </item> + </section> + </menu> </interface> |