[gnome-builder] greeter: propagate selection status to perspective
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] greeter: propagate selection status to perspective
- Date: Sat, 18 Nov 2017 05:23:42 +0000 (UTC)
commit d9df81550eaa98c82e71b3827e53630e5228af34
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 17 21:23:07 2017 -0800
greeter: propagate selection status to perspective
This allows the perspective to update the action bar when the
selection changes in various sections.
src/libide/greeter/ide-greeter-perspective.c | 45 +++++++++++++++++
src/libide/greeter/ide-greeter-section.c | 7 +++
src/plugins/newcomers/gbp-newcomers-section.c | 32 ++++++++++++
src/plugins/recent/gbp-recent-section.c | 64 +++++++++++++++++++++++++
4 files changed, 148 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/greeter/ide-greeter-perspective.c b/src/libide/greeter/ide-greeter-perspective.c
index bfa763b..08d0763 100644
--- a/src/libide/greeter/ide-greeter-perspective.c
+++ b/src/libide/greeter/ide-greeter-perspective.c
@@ -901,6 +901,45 @@ ide_greeter_perspective_project_activated (IdeGreeterPerspective *self,
}
static void
+ide_greeter_perspective_notify_has_selection_cb (PeasExtensionSet *set,
+ PeasPluginInfo *plugin_info,
+ PeasExtension *exten,
+ gpointer user_data)
+{
+ IdeGreeterSection *section = (IdeGreeterSection *)exten;
+ gboolean *has_selection = user_data;
+
+ g_return_if_fail (PEAS_IS_EXTENSION_SET (set));
+ g_return_if_fail (plugin_info != NULL);
+ g_return_if_fail (has_selection != NULL);
+ g_return_if_fail (IDE_IS_GREETER_SECTION (section));
+
+ if (*has_selection)
+ return;
+
+ g_object_get (section, "has-selection", has_selection, NULL);
+}
+
+static void
+ide_greeter_perspective_notify_has_selection (IdeGreeterPerspective *self,
+ GParamSpec *pspec,
+ IdeGreeterSection *section)
+{
+ gboolean has_selection = FALSE;
+
+ g_assert (IDE_IS_GREETER_PERSPECTIVE (self));
+ g_assert (IDE_IS_GREETER_SECTION (section));
+
+ peas_extension_set_foreach (self->sections,
+ ide_greeter_perspective_notify_has_selection_cb,
+ &has_selection);
+
+ dzl_gtk_widget_action_set (GTK_WIDGET (self), "greeter", "delete-selected-rows",
+ "enabled", has_selection,
+ NULL);
+}
+
+static void
ide_greeter_perspective_section_added (PeasExtensionSet *set,
PeasPluginInfo *plugin_info,
PeasExtension *exten,
@@ -922,6 +961,12 @@ ide_greeter_perspective_section_added (PeasExtensionSet *set,
g_object_ref_sink (section);
g_signal_connect_object (section,
+ "notify::has-selection",
+ G_CALLBACK (ide_greeter_perspective_notify_has_selection),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (section,
"project-activated",
G_CALLBACK (ide_greeter_perspective_project_activated),
self,
diff --git a/src/libide/greeter/ide-greeter-section.c b/src/libide/greeter/ide-greeter-section.c
index dcd013e..3168c05 100644
--- a/src/libide/greeter/ide-greeter-section.c
+++ b/src/libide/greeter/ide-greeter-section.c
@@ -32,6 +32,13 @@ static guint signals [N_SIGNALS];
static void
ide_greeter_section_default_init (IdeGreeterSectionInterface *iface)
{
+ g_object_interface_install_property (iface,
+ g_param_spec_boolean ("has-selection",
+ "Has Selection",
+ "If the greeter has a selection",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
/**
* IdeGreeterSection::project-activated:
*
diff --git a/src/plugins/newcomers/gbp-newcomers-section.c b/src/plugins/newcomers/gbp-newcomers-section.c
index d55eb90..ea14089 100644
--- a/src/plugins/newcomers/gbp-newcomers-section.c
+++ b/src/plugins/newcomers/gbp-newcomers-section.c
@@ -29,6 +29,12 @@ struct _GbpNewcomersSection
GtkFlowBox *flowbox;
};
+enum {
+ PROP_0,
+ PROP_HAS_SELECTION,
+ N_PROPS
+};
+
static void gbp_newcomers_section_child_activated (GbpNewcomersSection *self,
GbpNewcomersProject *project,
GtkFlowBox *flowbox);
@@ -175,9 +181,35 @@ gbp_newcomers_section_child_activated (GbpNewcomersSection *self,
}
static void
+gbp_newcomers_section_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id)
+ {
+ case PROP_HAS_SELECTION:
+ g_value_set_boolean (value, FALSE);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
gbp_newcomers_section_class_init (GbpNewcomersSectionClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = gbp_newcomers_section_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_HAS_SELECTION,
+ g_param_spec_boolean ("has-selection", NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
gtk_widget_class_set_css_name (widget_class, "newcomers");
gtk_widget_class_set_template_from_resource (widget_class,
diff --git a/src/plugins/recent/gbp-recent-section.c b/src/plugins/recent/gbp-recent-section.c
index 23f45bd..2d96de9 100644
--- a/src/plugins/recent/gbp-recent-section.c
+++ b/src/plugins/recent/gbp-recent-section.c
@@ -32,6 +32,39 @@ struct _GbpRecentSection
guint selection_mode : 1;
};
+enum {
+ PROP_0,
+ PROP_HAS_SELECTION,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+gbp_recent_section_get_has_selection_cb (GtkWidget *widget,
+ gpointer user_data)
+{
+ gboolean *has_selection = user_data;
+ gboolean selected = FALSE;
+
+ g_object_get (widget, "selected", &selected, NULL);
+ *has_selection |= selected;
+}
+
+static gboolean
+gbp_recent_section_get_has_selection (GbpRecentSection *self)
+{
+ gboolean has_selection = FALSE;
+
+ g_assert (GBP_IS_RECENT_SECTION (self));
+
+ gtk_container_foreach (GTK_CONTAINER (self->listbox),
+ gbp_recent_section_get_has_selection_cb,
+ &has_selection);
+
+ return has_selection;
+}
+
static gint
gbp_recent_section_get_priority (IdeGreeterSection *section)
{
@@ -158,6 +191,8 @@ gbp_recent_section_set_selection_mode (IdeGreeterSection *section,
&selection_mode);
self->selection_mode = selection_mode;
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAS_SELECTION]);
}
static void
@@ -188,6 +223,8 @@ gbp_recent_section_row_activated (GbpRecentSection *self,
g_object_get (row, "selected", &selected, NULL);
g_object_set (row, "selected", !selected, NULL);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAS_SELECTION]);
}
else
{
@@ -231,12 +268,39 @@ gbp_recent_section_constructed (GObject *object)
}
static void
+gbp_recent_section_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbpRecentSection *self = GBP_RECENT_SECTION (object);
+
+ switch (prop_id)
+ {
+ case PROP_HAS_SELECTION:
+ g_value_set_boolean (value, gbp_recent_section_get_has_selection (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
gbp_recent_section_class_init (GbpRecentSectionClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = gbp_recent_section_constructed;
+ object_class->get_property = gbp_recent_section_get_property;
+
+ properties [PROP_HAS_SELECTION] =
+ g_param_spec_boolean ("has-selection", NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_css_name (widget_class, "recent");
gtk_widget_class_set_template_from_resource (widget_class,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]