[gnome-control-center] region: Simplify placeholder input row
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] region: Simplify placeholder input row
- Date: Mon, 17 Sep 2018 14:19:42 +0000 (UTC)
commit 5d167f024fc7251ef805774dcfc3223d30e6f5f9
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Sep 11 14:45:51 2018 +1200
region: Simplify placeholder input row
Instead of adding/removing a row, create one in the .ui file and show/hide it.
panels/region/cc-region-panel.c | 61 +++++++++++++++++++++--------------------
panels/region/region.ui | 16 +++++++++++
2 files changed, 47 insertions(+), 30 deletions(-)
---
diff --git a/panels/region/cc-region-panel.c b/panels/region/cc-region-panel.c
index 30b1b9d31..98e2f5b1e 100644
--- a/panels/region/cc-region-panel.c
+++ b/panels/region/cc-region-panel.c
@@ -100,6 +100,7 @@ struct _CcRegionPanel {
GtkWidget *input_section;
GtkWidget *options_button;
GtkWidget *input_list;
+ GtkWidget *no_inputs_row;
GtkWidget *add_input;
GtkWidget *remove_input;
GtkWidget *move_up_input;
@@ -640,9 +641,13 @@ update_ibus_active_sources (CcRegionPanel *self)
rows = gtk_container_get_children (GTK_CONTAINER (self->input_list));
for (l = rows; l; l = l->next) {
- CcInputRow *row = CC_INPUT_ROW (l->data);
+ CcInputRow *row;
IBusEngineDesc *engine_desc;
+ if (!CC_IS_INPUT_ROW (l->data))
+ continue;
+ row = CC_INPUT_ROW (l->data);
+
if (g_strcmp0 (cc_input_row_get_input_type (row), INPUT_SOURCE_TYPE_IBUS) != 0)
continue;
@@ -741,20 +746,6 @@ setup_app_info_for_id (const gchar *id)
}
#endif
-static void
-remove_no_input_row (GtkContainer *list)
-{
- g_autoptr(GList) l = NULL;
-
- l = gtk_container_get_children (list);
- if (!l)
- return;
- if (l->next != NULL)
- return;
- if (g_strcmp0 (cc_input_row_get_input_type (CC_INPUT_ROW (l->data)), "none") == 0)
- gtk_container_remove (list, GTK_WIDGET (l->data));
-}
-
static void
add_input_row (CcRegionPanel *self,
const gchar *type,
@@ -764,7 +755,7 @@ add_input_row (CcRegionPanel *self,
{
CcInputRow *row;
- remove_no_input_row (GTK_CONTAINER (self->input_list));
+ gtk_widget_set_visible (GTK_WIDGET (self->no_inputs_row), FALSE);
row = cc_input_row_new (type, id, app_info);
gtk_widget_show (GTK_WIDGET (row));
@@ -775,12 +766,6 @@ add_input_row (CcRegionPanel *self,
cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->input_list));
}
-static void
-add_no_input_row (CcRegionPanel *self)
-{
- add_input_row (self, "none", "none", _("No input source selected"), NULL);
-}
-
static void
add_input_sources (CcRegionPanel *self,
GVariant *sources)
@@ -789,7 +774,7 @@ add_input_sources (CcRegionPanel *self,
const gchar *type, *id;
if (g_variant_n_children (sources) < 1) {
- add_no_input_row (self);
+ gtk_widget_set_visible (GTK_WIDGET (self->no_inputs_row), TRUE);
return;
}
@@ -845,7 +830,8 @@ clear_input_sources (CcRegionPanel *self)
list = gtk_container_get_children (GTK_CONTAINER (self->input_list));
for (l = list; l; l = l->next) {
- gtk_container_remove (GTK_CONTAINER (self->input_list), GTK_WIDGET (l->data));
+ if (CC_IS_INPUT_ROW (l->data))
+ gtk_container_remove (GTK_CONTAINER (self->input_list), GTK_WIDGET (l->data));
}
cc_list_box_adjust_scrolling (GTK_LIST_BOX (self->input_list));
@@ -857,6 +843,9 @@ select_by_id (GtkWidget *row,
{
const gchar *id = data;
+ if (!CC_IS_INPUT_ROW (row))
+ return;
+
if (g_strcmp0 (cc_input_row_get_id (CC_INPUT_ROW (row)), id) == 0)
gtk_list_box_select_row (GTK_LIST_BOX (gtk_widget_get_parent (row)), GTK_LIST_BOX_ROW (row));
}
@@ -932,7 +921,12 @@ set_input_settings (CcRegionPanel *self)
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss)"));
list = gtk_container_get_children (GTK_CONTAINER (self->input_list));
for (l = list; l; l = l->next) {
- CcInputRow *row = CC_INPUT_ROW (l->data);
+ CcInputRow *row;
+
+ if (!CC_IS_INPUT_ROW (l->data))
+ continue;
+
+ row = CC_INPUT_ROW (l->data);
g_variant_builder_add (&builder, "(ss)", cc_input_row_get_input_type (row),
cc_input_row_get_id (row));
}
@@ -962,10 +956,14 @@ input_source_already_added (CcRegionPanel *self,
GList *l;
list = gtk_container_get_children (GTK_CONTAINER (self->input_list));
- for (l = list; l; l = l->next)
+ for (l = list; l; l = l->next) {
+ if (!CC_IS_INPUT_ROW (l->data))
+ continue;
+
if (g_str_equal (id, cc_input_row_get_id (CC_INPUT_ROW (l->data)))) {
return TRUE;
}
+ }
return FALSE;
}
@@ -1459,9 +1457,7 @@ add_input_sources_from_localed (CcRegionPanel *self)
add_input_row (self, INPUT_SOURCE_TYPE_XKB, id, name ? name : id, NULL);
}
- if (n == 0) {
- add_no_input_row (self);
- }
+ gtk_widget_set_visible (GTK_WIDGET (self->no_inputs_row), n == 0);
}
static void
@@ -1512,9 +1508,13 @@ set_localed_input (CcRegionPanel *self)
list = gtk_container_get_children (GTK_CONTAINER (self->input_list));
for (li = list; li; li = li->next) {
- CcInputRow *row = CC_INPUT_ROW (li->data);
+ CcInputRow *row;
const gchar *l, *v;
+ if (!CC_IS_INPUT_ROW (li->data))
+ continue;
+ row = CC_INPUT_ROW (li->data);
+
if (g_str_equal (cc_input_row_get_input_type (row), INPUT_SOURCE_TYPE_IBUS))
continue;
@@ -1689,6 +1689,7 @@ cc_region_panel_class_init (CcRegionPanelClass * klass)
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, input_section);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, options_button);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, input_list);
+ gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, no_inputs_row);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, add_input);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, remove_input);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, move_up_input);
diff --git a/panels/region/region.ui b/panels/region/region.ui
index 34d7b4989..e5b4646a1 100644
--- a/panels/region/region.ui
+++ b/panels/region/region.ui
@@ -278,6 +278,22 @@
<accessibility>
<relation target="input_heading" type="labelled-by"/>
</accessibility>
+ <child>
+ <object class="GtkListBoxRow" id="no_inputs_row">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="selectable">False</property>
+ <property name="activatable">False</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin">18</property>
+ <property name="label" translatable="yes">No input source selected</property>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]