region: Move input settings button inside each row

This matches the new designs in
https://gitlab.gnome.org/Teams/Design/settings-mockups/blob/master/region-and-language/region-and-language.png
This commit is contained in:
Robert Ancell 2018-11-19 11:12:27 +13:00 committed by Georges Basile Stavracas Neto
parent 7a9d2b83df
commit 0a70d5ab34
4 changed files with 60 additions and 84 deletions

View file

@ -26,14 +26,15 @@ struct _CcInputRow
CcInputSource *source;
GtkLabel *name_label;
GtkWidget *icon_image;
GtkButton *remove_button;
GtkButton *settings_button;
};
G_DEFINE_TYPE (CcInputRow, cc_input_row, GTK_TYPE_LIST_BOX_ROW)
enum
{
SIGNAL_SHOW_SETTINGS,
SIGNAL_SHOW_LAYOUT,
SIGNAL_REMOVE_ROW,
SIGNAL_LAST
@ -41,6 +42,14 @@ enum
static guint signals[SIGNAL_LAST] = { 0, };
static void
settings_button_clicked_cb (CcInputRow *self)
{
g_signal_emit (self,
signals[SIGNAL_SHOW_SETTINGS],
0);
}
static void
layout_button_clicked_cb (CcInputRow *self)
{
@ -79,11 +88,22 @@ cc_input_row_class_init (CcInputRowClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcInputRow, remove_button);
gtk_widget_class_bind_template_child (widget_class, CcInputRow, name_label);
gtk_widget_class_bind_template_child (widget_class, CcInputRow, icon_image);
gtk_widget_class_bind_template_child (widget_class, CcInputRow, settings_button);
gtk_widget_class_bind_template_callback (widget_class, layout_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, settings_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, remove_button_clicked_cb);
signals[SIGNAL_SHOW_SETTINGS] =
g_signal_new ("show-settings",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
NULL,
G_TYPE_NONE,
0);
signals[SIGNAL_SHOW_LAYOUT] =
g_signal_new ("show-layout",
G_TYPE_FROM_CLASS (object_class),
@ -129,7 +149,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 (self->icon_image, CC_IS_INPUT_SOURCE_IBUS (source));
gtk_widget_set_visible (GTK_WIDGET (self->settings_button), CC_IS_INPUT_SOURCE_IBUS (source));
return self;
}

View file

@ -17,12 +17,18 @@
</object>
</child>
<child>
<object class="GtkImage" id="icon_image">
<property name="visible">True</property>
<property name="icon_name">system-run-symbolic</property>
<object class="GtkButton" id="settings_button">
<property name="visible">False</property>
<signal name="clicked" handler="settings_button_clicked_cb" object="CcInputRow" swapped="yes"/>
<style>
<class name="dim-label"/>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon_name">emblem-system-symbolic</property>
</object>
</child>
</object>
</child>
<child>

View file

@ -83,7 +83,6 @@ struct _CcRegionPanel {
GtkButton *restart_button;
GtkRevealer *restart_revealer;
GtkRadioButton *same_source;
GtkButton *show_config_button;
gboolean login;
gboolean login_auto_apply;
@ -715,6 +714,32 @@ maybe_start_ibus (void)
#endif
static void
row_settings_cb (CcRegionPanel *self,
CcInputRow *row)
{
CcInputSourceIBus *source;
g_autoptr(GdkAppLaunchContext) ctx = NULL;
GDesktopAppInfo *app_info;
g_autoptr(GError) error = NULL;
g_return_if_fail (CC_IS_INPUT_SOURCE_IBUS (cc_input_row_get_source (row)));
source = CC_INPUT_SOURCE_IBUS (cc_input_row_get_source (row));
app_info = cc_input_source_ibus_get_app_info (source);
if (app_info == NULL)
return;
ctx = gdk_display_get_app_launch_context (gdk_display_get_default ());
gdk_app_launch_context_set_timestamp (ctx, gtk_get_current_event_time ());
g_app_launch_context_setenv (G_APP_LAUNCH_CONTEXT (ctx),
"IBUS_ENGINE_NAME", cc_input_source_ibus_get_engine_name (source));
if (!g_app_info_launch (G_APP_INFO (app_info), NULL, G_APP_LAUNCH_CONTEXT (ctx), &error))
g_warning ("Failed to launch input source setup: %s", error->message);
}
static void
row_layout_cb (CcRegionPanel *self,
CcInputRow *row)
@ -778,6 +803,7 @@ add_input_row (CcRegionPanel *self, CcInputSource *source)
row = cc_input_row_new (source);
gtk_widget_show (GTK_WIDGET (row));
g_signal_connect_object (row, "show-settings", G_CALLBACK (row_settings_cb), self, G_CONNECT_SWAPPED);
g_signal_connect_object (row, "show-layout", G_CALLBACK (row_layout_cb), self, G_CONNECT_SWAPPED);
g_signal_connect_object (row, "remove-row", G_CALLBACK (row_removed_cb), self, G_CONNECT_SWAPPED);
gtk_container_add (GTK_CONTAINER (self->input_list), GTK_WIDGET (row));
@ -897,7 +923,6 @@ update_buttons (CcRegionPanel *self)
selected = CC_INPUT_ROW (gtk_list_box_get_selected_row (self->input_list));
if (selected == NULL) {
gtk_widget_set_visible (GTK_WIDGET (self->show_config_button), FALSE);
gtk_widget_set_sensitive (GTK_WIDGET (self->move_up_input_button), FALSE);
gtk_widget_set_sensitive (GTK_WIDGET (self->move_down_input_button), FALSE);
} else {
@ -905,7 +930,6 @@ update_buttons (CcRegionPanel *self)
index = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (selected));
gtk_widget_set_visible (GTK_WIDGET (self->show_config_button), CC_IS_INPUT_SOURCE_IBUS (cc_input_row_get_source (selected)));
gtk_widget_set_sensitive (GTK_WIDGET (self->move_up_input_button), index > 1);
gtk_widget_set_sensitive (GTK_WIDGET (self->move_down_input_button), index < n_rows - 1);
}
@ -1147,35 +1171,6 @@ move_selected_input_down (CcRegionPanel *self)
move_input (self, CC_INPUT_ROW (selected), 1);
}
static void
show_selected_settings (CcRegionPanel *self)
{
CcInputRow *selected;
CcInputSourceIBus *source;
g_autoptr(GdkAppLaunchContext) ctx = NULL;
g_autoptr(GDesktopAppInfo) app_info = NULL;
g_autoptr(GError) error = NULL;
selected = CC_INPUT_ROW (gtk_list_box_get_selected_row (self->input_list));
if (selected == NULL)
return;
g_return_if_fail (CC_IS_INPUT_SOURCE_IBUS (cc_input_row_get_source (selected)));
source = CC_INPUT_SOURCE_IBUS (cc_input_row_get_source (selected));
app_info = cc_input_source_ibus_get_app_info (source);
if (app_info == NULL)
return;
ctx = gdk_display_get_app_launch_context (gdk_display_get_default ());
gdk_app_launch_context_set_timestamp (ctx, gtk_get_current_event_time ());
g_app_launch_context_setenv (G_APP_LAUNCH_CONTEXT (ctx),
"IBUS_ENGINE_NAME", cc_input_source_ibus_get_engine_name (source));
if (!g_app_info_launch (G_APP_INFO (app_info), NULL, G_APP_LAUNCH_CONTEXT (ctx), &error))
g_warning ("Failed to launch input source setup: %s", error->message);
}
static void
update_shortcut_label (GtkLabel *label,
const gchar *value)
@ -1629,13 +1624,11 @@ cc_region_panel_class_init (CcRegionPanelClass * klass)
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, restart_button);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, restart_revealer);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, same_source);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, show_config_button);
gtk_widget_class_bind_template_callback (widget_class, restart_now);
gtk_widget_class_bind_template_callback (widget_class, add_input);
gtk_widget_class_bind_template_callback (widget_class, move_selected_input_up);
gtk_widget_class_bind_template_callback (widget_class, move_selected_input_down);
gtk_widget_class_bind_template_callback (widget_class, show_selected_settings);
}
static void

View file

@ -383,49 +383,6 @@
</child>
</object>
</child>
<child>
<object class="GtkSeparatorToolItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="draw">False</property>
</object>
<packing>
<property name="expand">True</property>
</packing>
</child>
<child>
<object class="GtkToolItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="show_config_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="show_selected_settings" object="CcRegionPanel" swapped="yes"/>
<child internal-child="accessible">
<object class="AtkObject">
<property name="accessible-name" translatable="yes">Configure input source</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">emblem-system-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>