[gnome-control-center] region: Move remove button inside each row
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] region: Move remove button inside each row
- Date: Mon, 4 Feb 2019 14:04:42 +0000 (UTC)
commit d4683a9ddd22435418e05f48cdc50c7ad028d72c
Author: Robert Ancell <robert ancell canonical com>
Date: Mon Nov 19 10:48:01 2018 +1300
region: Move remove 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
panels/region/cc-input-row.c | 38 +++++++++++++++++++++++++++++
panels/region/cc-input-row.h | 7 ++++--
panels/region/cc-input-row.ui | 16 +++++++++++++
panels/region/cc-region-panel.c | 52 +++++++++++++++++++++++++++++-----------
panels/region/cc-region-panel.ui | 21 ----------------
5 files changed, 97 insertions(+), 37 deletions(-)
---
diff --git a/panels/region/cc-input-row.c b/panels/region/cc-input-row.c
index c3f3c1fca..cb6587a9b 100644
--- a/panels/region/cc-input-row.c
+++ b/panels/region/cc-input-row.c
@@ -27,10 +27,27 @@ struct _CcInputRow
GtkLabel *name_label;
GtkWidget *icon_image;
+ GtkButton *remove_button;
};
G_DEFINE_TYPE (CcInputRow, cc_input_row, GTK_TYPE_LIST_BOX_ROW)
+enum
+{
+ SIGNAL_REMOVE_ROW,
+ SIGNAL_LAST
+};
+
+static guint signals[SIGNAL_LAST] = { 0, };
+
+static void
+remove_button_clicked_cb (CcInputRow *self)
+{
+ g_signal_emit (self,
+ signals[SIGNAL_REMOVE_ROW],
+ 0);
+}
+
static void
cc_input_row_dispose (GObject *object)
{
@@ -51,8 +68,21 @@ cc_input_row_class_init (CcInputRowClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/region/cc-input-row.ui");
+ 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_callback (widget_class, remove_button_clicked_cb);
+
+ signals[SIGNAL_REMOVE_ROW] =
+ g_signal_new ("remove-row",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE,
+ 0);
}
void
@@ -90,3 +120,11 @@ cc_input_row_get_source (CcInputRow *self)
g_return_val_if_fail (CC_IS_INPUT_ROW (self), NULL);
return self->source;
}
+
+void
+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);
+}
diff --git a/panels/region/cc-input-row.h b/panels/region/cc-input-row.h
index a5c0ec62c..1200b09ea 100644
--- a/panels/region/cc-input-row.h
+++ b/panels/region/cc-input-row.h
@@ -27,8 +27,11 @@ G_BEGIN_DECLS
#define CC_TYPE_INPUT_ROW (cc_input_row_get_type ())
G_DECLARE_FINAL_TYPE (CcInputRow, cc_input_row, CC, INPUT_ROW, GtkListBoxRow)
-CcInputRow *cc_input_row_new (CcInputSource *source);
+CcInputRow *cc_input_row_new (CcInputSource *source);
-CcInputSource *cc_input_row_get_source (CcInputRow *row);
+CcInputSource *cc_input_row_get_source (CcInputRow *row);
+
+void cc_input_row_set_removable (CcInputRow *row,
+ gboolean removable);
G_END_DECLS
diff --git a/panels/region/cc-input-row.ui b/panels/region/cc-input-row.ui
index 4a3051efa..a6dab8555 100644
--- a/panels/region/cc-input-row.ui
+++ b/panels/region/cc-input-row.ui
@@ -9,6 +9,7 @@
<object class="GtkBox">
<property name="visible">True</property>
<property name="border-width">18</property>
+ <property name="spacing">12</property>
<child>
<object class="GtkLabel" id="name_label">
<property name="visible">True</property>
@@ -25,6 +26,21 @@
</style>
</object>
</child>
+ <child>
+ <object class="GtkButton" id="remove_button">
+ <property name="visible">True</property>
+ <signal name="clicked" handler="remove_button_clicked_cb" object="CcInputRow" swapped="yes"/>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon_name">edit-delete-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
</template>
diff --git a/panels/region/cc-region-panel.c b/panels/region/cc-region-panel.c
index 94c71cd11..e182bb3fa 100644
--- a/panels/region/cc-region-panel.c
+++ b/panels/region/cc-region-panel.c
@@ -80,7 +80,6 @@ struct _CcRegionPanel {
GtkRadioButton *per_window_source;
GtkLabel *previous_source;
GtkLabel *previous_source_label;
- GtkButton *remove_input_button;
GtkButton *restart_button;
GtkRevealer *restart_revealer;
GtkRadioButton *same_source;
@@ -717,6 +716,37 @@ maybe_start_ibus (void)
#endif
+static void remove_input (CcRegionPanel *self, CcInputRow *row);
+
+static void
+row_removed_cb (CcRegionPanel *self,
+ CcInputRow *row)
+{
+ remove_input (self, row);
+}
+
+static void
+update_input_rows (CcRegionPanel *self)
+{
+ g_autoptr(GList) rows = NULL;
+ GList *l;
+ guint n_input_rows = 0;
+
+ rows = gtk_container_get_children (GTK_CONTAINER (self->input_list));
+ for (l = rows; l; l = l->next)
+ if (CC_IS_INPUT_ROW (l->data))
+ n_input_rows++;
+ for (l = rows; l; l = l->next) {
+ CcInputRow *row;
+
+ if (!CC_IS_INPUT_ROW (l->data))
+ continue;
+ row = CC_INPUT_ROW (l->data);
+
+ cc_input_row_set_removable (row, n_input_rows > 1);
+ }
+}
+
static void
add_input_row (CcRegionPanel *self, CcInputSource *source)
{
@@ -726,7 +756,9 @@ add_input_row (CcRegionPanel *self, CcInputSource *source)
row = cc_input_row_new (source);
gtk_widget_show (GTK_WIDGET (row));
+ 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));
+ update_input_rows (self);
cc_list_box_adjust_scrolling (self->input_list);
}
@@ -843,7 +875,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->remove_input_button), FALSE);
gtk_widget_set_sensitive (GTK_WIDGET (self->show_layout_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);
@@ -854,7 +885,6 @@ update_buttons (CcRegionPanel *self)
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->show_layout_button), TRUE);
- gtk_widget_set_sensitive (GTK_WIDGET (self->remove_input_button), n_rows > 1);
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);
}
@@ -997,6 +1027,7 @@ do_remove_input (CcRegionPanel *self, CcInputRow *row)
update_buttons (self);
update_input (self);
+ update_input_rows (self);
}
static void
@@ -1008,22 +1039,17 @@ remove_input_permission_cb (GObject *source, GAsyncResult *res, gpointer user_da
}
static void
-remove_selected_input (CcRegionPanel *self)
+remove_input (CcRegionPanel *self, CcInputRow *row)
{
- GtkListBoxRow *selected;
-
- selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (self->input_list));
- g_return_if_fail (selected != NULL);
-
if (!self->login) {
- do_remove_input (self, CC_INPUT_ROW (selected));
+ do_remove_input (self, row);
} else if (g_permission_get_allowed (self->permission)) {
- do_remove_input (self, CC_INPUT_ROW (selected));
+ do_remove_input (self, row);
} else if (g_permission_get_can_acquire (self->permission)) {
g_permission_acquire_async (self->permission,
self->cancellable,
remove_input_permission_cb,
- row_data_new (self, CC_INPUT_ROW (selected), -1));
+ row_data_new (self, row, -1));
}
}
@@ -1605,7 +1631,6 @@ cc_region_panel_class_init (CcRegionPanelClass * klass)
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, per_window_source);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, previous_source);
gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, previous_source_label);
- gtk_widget_class_bind_template_child (widget_class, CcRegionPanel, remove_input_button);
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);
@@ -1614,7 +1639,6 @@ cc_region_panel_class_init (CcRegionPanelClass * klass)
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, remove_selected_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);
diff --git a/panels/region/cc-region-panel.ui b/panels/region/cc-region-panel.ui
index b05cce0f6..7d798c43e 100644
--- a/panels/region/cc-region-panel.ui
+++ b/panels/region/cc-region-panel.ui
@@ -315,27 +315,6 @@
</child>
</object>
</child>
- <child>
- <object class="GtkButton" id="remove_input_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <signal name="clicked" handler="remove_selected_input"
object="CcRegionPanel" swapped="yes"/>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="accessible-name" translatable="yes">Remove input
source</property>
- </object>
- </child>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">list-remove-symbolic</property>
- <property name="icon-size">1</property>
- </object>
- </child>
- </object>
- </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]