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.
This commit is contained in:
parent
530fbac68e
commit
ced8c1cb99
2 changed files with 61 additions and 125 deletions
|
@ -25,10 +25,6 @@ struct _CcInputRow
|
||||||
|
|
||||||
CcInputSource *source;
|
CcInputSource *source;
|
||||||
|
|
||||||
GtkButton *remove_button;
|
|
||||||
GtkButton *settings_button;
|
|
||||||
GtkSeparator *settings_separator;
|
|
||||||
|
|
||||||
GtkListBox *drag_widget;
|
GtkListBox *drag_widget;
|
||||||
|
|
||||||
GtkDragSource *drag_source;
|
GtkDragSource *drag_source;
|
||||||
|
@ -107,9 +103,11 @@ drop_cb (GtkDropTarget *drop_target,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
move_up_button_clicked_cb (CcInputRow *self,
|
move_up_cb (GtkWidget *widget,
|
||||||
GtkButton *button)
|
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)));
|
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;
|
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);
|
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
|
static void
|
||||||
move_down_button_clicked_cb (CcInputRow *self,
|
move_down_cb (GtkWidget *widget,
|
||||||
GtkButton *button)
|
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)));
|
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;
|
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);
|
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
|
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,
|
g_signal_emit (self,
|
||||||
signals[SIGNAL_SHOW_SETTINGS],
|
signals[SIGNAL_SHOW_SETTINGS],
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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,
|
g_signal_emit (self,
|
||||||
signals[SIGNAL_SHOW_LAYOUT],
|
signals[SIGNAL_SHOW_LAYOUT],
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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,
|
g_signal_emit (self,
|
||||||
signals[SIGNAL_REMOVE_ROW],
|
signals[SIGNAL_REMOVE_ROW],
|
||||||
0);
|
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_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] =
|
signals[SIGNAL_SHOW_SETTINGS] =
|
||||||
g_signal_new ("show-settings",
|
g_signal_new ("show-settings",
|
||||||
G_TYPE_FROM_CLASS (object_class),
|
G_TYPE_FROM_CLASS (object_class),
|
||||||
|
@ -233,6 +232,12 @@ cc_input_row_class_init (CcInputRowClass *klass)
|
||||||
NULL,
|
NULL,
|
||||||
G_TYPE_NONE,
|
G_TYPE_NONE,
|
||||||
0);
|
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
|
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);
|
g_signal_connect_object (source, "label-changed", G_CALLBACK (label_changed_cb), self, G_CONNECT_SWAPPED);
|
||||||
label_changed_cb (self);
|
label_changed_cb (self);
|
||||||
|
|
||||||
gtk_widget_set_visible (GTK_WIDGET (self->settings_button), CC_IS_INPUT_SOURCE_IBUS (source));
|
gtk_widget_action_set_enabled (GTK_WIDGET (self), "row.show-settings", CC_IS_INPUT_SOURCE_IBUS (source));
|
||||||
gtk_widget_set_visible (GTK_WIDGET (self->settings_separator), CC_IS_INPUT_SOURCE_IBUS (source));
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -290,7 +294,7 @@ cc_input_row_set_removable (CcInputRow *self,
|
||||||
gboolean removable)
|
gboolean removable)
|
||||||
{
|
{
|
||||||
g_return_if_fail (CC_IS_INPUT_ROW (self));
|
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
|
void
|
||||||
|
|
|
@ -15,111 +15,43 @@
|
||||||
<object class="GtkMenuButton">
|
<object class="GtkMenuButton">
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="icon_name">view-more-symbolic</property>
|
<property name="icon_name">view-more-symbolic</property>
|
||||||
<property name="popover">popover_menu</property>
|
<property name="menu_model">popover_menu</property>
|
||||||
<style>
|
<style>
|
||||||
<class name="flat"/>
|
<class name="flat"/>
|
||||||
</style>
|
</style>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</template>
|
</template>
|
||||||
<object class="GtkPopover" id="popover_menu">
|
<menu id="popover_menu">
|
||||||
<style>
|
<section>
|
||||||
<class name="menu" />
|
<item>
|
||||||
</style>
|
<attribute name="label" translatable="yes">Move Up</attribute>
|
||||||
<child>
|
<attribute name="action">row.move-up</attribute>
|
||||||
<object class="GtkBox">
|
</item>
|
||||||
<property name="margin-top">6</property>
|
<item>
|
||||||
<property name="margin-bottom">6</property>
|
<attribute name="label" translatable="yes">Move Down</attribute>
|
||||||
<property name="margin-start">6</property>
|
<attribute name="action">row.move-down</attribute>
|
||||||
<property name="margin-end">6</property>
|
</item>
|
||||||
<property name="orientation">vertical</property>
|
</section>
|
||||||
<child>
|
<section>
|
||||||
<object class="GtkButton">
|
<item>
|
||||||
<signal name="clicked" handler="move_up_button_clicked_cb" object="CcInputRow" swapped="yes"/>
|
<attribute name="label" translatable="yes">Preferences</attribute>
|
||||||
<style>
|
<attribute name="action">row.show-settings</attribute>
|
||||||
<class name="flat"/>
|
<attribute name="hidden-when">action-disabled</attribute>
|
||||||
</style>
|
</item>
|
||||||
<child>
|
</section>
|
||||||
<object class="GtkLabel">
|
<section>
|
||||||
<property name="label" translatable="yes">Move up</property>
|
<item>
|
||||||
<property name="xalign">0.0</property>
|
<attribute name="label" translatable="yes">View Keyboard Layout</attribute>
|
||||||
</object>
|
<attribute name="action">row.show-layout</attribute>
|
||||||
</child>
|
</item>
|
||||||
</object>
|
</section>
|
||||||
</child>
|
<section>
|
||||||
<child>
|
<item>
|
||||||
<object class="GtkButton">
|
<attribute name="label" translatable="yes">Remove</attribute>
|
||||||
<signal name="clicked" handler="move_down_button_clicked_cb" object="CcInputRow" swapped="yes"/>
|
<attribute name="action">row.remove</attribute>
|
||||||
<style>
|
<attribute name="hidden-when">action-disabled</attribute>
|
||||||
<class name="flat"/>
|
</item>
|
||||||
</style>
|
</section>
|
||||||
<child>
|
</menu>
|
||||||
<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>
|
|
||||||
</interface>
|
</interface>
|
||||||
|
|
Loading…
Add table
Reference in a new issue