[gnome-builder] prefs: make switch handle gtk_widget_activate()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] prefs: make switch handle gtk_widget_activate()
- Date: Mon, 21 Dec 2015 07:40:53 +0000 (UTC)
commit 2c273c67d5436641162a25c4900fc28150dd8764
Author: Christian Hergert <chergert redhat com>
Date: Sat Nov 7 00:39:53 2015 -0800
prefs: make switch handle gtk_widget_activate()
libide/preferences/ide-preferences-group.c | 22 +++++++++
libide/preferences/ide-preferences-switch.c | 65 +++++++++++++++++++++++----
2 files changed, 78 insertions(+), 9 deletions(-)
---
diff --git a/libide/preferences/ide-preferences-group.c b/libide/preferences/ide-preferences-group.c
index 54da112..322418d 100644
--- a/libide/preferences/ide-preferences-group.c
+++ b/libide/preferences/ide-preferences-group.c
@@ -45,6 +45,22 @@ enum {
static GParamSpec *properties [LAST_PROP];
static void
+ide_preferences_group_row_activated (IdePreferencesGroup *self,
+ GtkListBoxRow *row,
+ GtkListBox *list_box)
+{
+ GtkWidget *child;
+
+ g_assert (IDE_IS_PREFERENCES_GROUP (self));
+ g_assert (GTK_IS_LIST_BOX_ROW (row));
+ g_assert (GTK_IS_LIST_BOX (list_box));
+
+ child = gtk_bin_get_child (GTK_BIN (row));
+ if (child != NULL)
+ gtk_widget_activate (child);
+}
+
+static void
ide_preferences_group_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -146,6 +162,12 @@ static void
ide_preferences_group_init (IdePreferencesGroup *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
+
+ g_signal_connect_object (self->list_box,
+ "row-activated",
+ G_CALLBACK (ide_preferences_group_row_activated),
+ self,
+ G_CONNECT_SWAPPED);
}
void
diff --git a/libide/preferences/ide-preferences-switch.c b/libide/preferences/ide-preferences-switch.c
index f3c8ed3..e1403f1 100644
--- a/libide/preferences/ide-preferences-switch.c
+++ b/libide/preferences/ide-preferences-switch.c
@@ -50,7 +50,13 @@ enum {
LAST_PROP
};
+enum {
+ ACTIVATED,
+ LAST_SIGNAL
+};
+
static GParamSpec *properties [LAST_PROP];
+static guint signals [LAST_SIGNAL];
static void
ide_preferences_switch_changed (IdePreferencesSwitch *self,
@@ -86,9 +92,14 @@ ide_preferences_switch_changed (IdePreferencesSwitch *self,
self->updating = TRUE;
if (self->is_radio)
- gtk_widget_set_visible (GTK_WIDGET (self->image), active);
+ {
+ gtk_widget_set_visible (GTK_WIDGET (self->image), active);
+ }
else
- gtk_switch_set_active (self->widget, active);
+ {
+ gtk_switch_set_active (self->widget, active);
+ gtk_switch_set_state (self->widget, active);
+ }
self->updating = FALSE;
@@ -129,18 +140,16 @@ chainup:
G_OBJECT_CLASS (ide_preferences_switch_parent_class)->constructed (object);
}
-static gboolean
-ide_preferences_switch_state_set (IdePreferencesSwitch *self,
- gboolean state,
- GtkSwitch *widget)
+static void
+ide_preferences_switch_toggle (IdePreferencesSwitch *self,
+ gboolean state)
{
GVariant *value;
g_assert (IDE_IS_PREFERENCES_SWITCH (self));
- g_assert (GTK_IS_SWITCH (widget));
if (self->updating)
- return FALSE;
+ return;
self->updating = TRUE;
@@ -191,14 +200,43 @@ ide_preferences_switch_state_set (IdePreferencesSwitch *self,
g_variant_unref (value);
- gtk_switch_set_state (widget, state);
+ if (self->is_radio)
+ gtk_widget_set_visible (GTK_WIDGET (self->image), state);
+ else
+ gtk_switch_set_state (self->widget, state);
self->updating = FALSE;
+}
+
+static gboolean
+ide_preferences_switch_state_set (IdePreferencesSwitch *self,
+ gboolean state,
+ GtkSwitch *widget)
+{
+ g_assert (IDE_IS_PREFERENCES_SWITCH (self));
+ g_assert (GTK_IS_SWITCH (widget));
+
+ ide_preferences_switch_toggle (self, state);
return TRUE;
}
static void
+ide_preferences_switch_activate (IdePreferencesSwitch *self)
+{
+ gboolean state;
+
+ g_assert (IDE_IS_PREFERENCES_SWITCH (self));
+
+ if (self->is_radio)
+ state = !gtk_widget_get_visible (GTK_WIDGET (self->image));
+ else
+ state = !gtk_switch_get_active (self->widget);
+
+ ide_preferences_switch_toggle (self, state);
+}
+
+static void
ide_preferences_switch_finalize (GObject *object)
{
IdePreferencesSwitch *self = (IdePreferencesSwitch *)object;
@@ -305,6 +343,15 @@ ide_preferences_switch_class_init (IdePreferencesSwitchClass *klass)
object_class->get_property = ide_preferences_switch_get_property;
object_class->set_property = ide_preferences_switch_set_property;
+ signals [ACTIVATED] =
+ g_signal_new_class_handler ("activated",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_CALLBACK (ide_preferences_switch_activate),
+ NULL, NULL, NULL, G_TYPE_NONE, 0);
+
+ widget_class->activate_signal = signals [ACTIVATED];
+
properties [PROP_IS_RADIO] =
g_param_spec_boolean ("is-radio",
"Is Radio",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]