[gnome-builder/wip/gtk4-port: 938/1774] plugins/buildui: add busy state and setup actions
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 938/1774] plugins/buildui: add busy state and setup actions
- Date: Mon, 11 Jul 2022 22:31:29 +0000 (UTC)
commit 7093dea05ba0c49020160f0ef4385a76f2b0e331
Author: Christian Hergert <chergert redhat com>
Date: Tue May 10 11:22:29 2022 -0700
plugins/buildui: add busy state and setup actions
The action implementation is not there yet, but we can setup the rows to
have the proper action/target as well as show a spinner for long running
operations which might need to complete before we can display contents.
src/plugins/buildui/gbp-buildui-targets-dialog.c | 72 +++++++++++++++++++++--
src/plugins/buildui/gbp-buildui-targets-dialog.ui | 7 ++-
2 files changed, 72 insertions(+), 7 deletions(-)
---
diff --git a/src/plugins/buildui/gbp-buildui-targets-dialog.c
b/src/plugins/buildui/gbp-buildui-targets-dialog.c
index e8ffe215a..4b2b46590 100644
--- a/src/plugins/buildui/gbp-buildui-targets-dialog.c
+++ b/src/plugins/buildui/gbp-buildui-targets-dialog.c
@@ -34,15 +34,20 @@
struct _GbpBuilduiTargetsDialog
{
AdwWindow parent_instance;
+
GtkListBox *list_box;
+ GtkSpinner *spinner;
GListStore *store;
IdeExtensionSetAdapter *set;
+
+ guint busy_count;
};
G_DEFINE_FINAL_TYPE (GbpBuilduiTargetsDialog, gbp_buildui_targets_dialog, ADW_TYPE_WINDOW)
enum {
PROP_0,
+ PROP_BUSY,
PROP_CONTEXT,
N_PROPS
};
@@ -53,9 +58,31 @@ static GtkWidget *
create_target_row (gpointer item,
gpointer user_data)
{
- return g_object_new (ADW_TYPE_ACTION_ROW,
- "title", ide_build_target_get_display_name (item),
- NULL);
+ IdeBuildTarget *target = item;
+ g_autoptr(GVariant) namev = NULL;
+ AdwActionRow *row;
+ const char *name;
+ GtkWidget *check;
+
+ g_assert (IDE_IS_BUILD_TARGET (target));
+
+ name = ide_build_target_get_name (target);
+ namev = g_variant_take_ref (g_variant_new_string (name ? name : ""));
+
+ check = g_object_new (GTK_TYPE_CHECK_BUTTON,
+ "action-name", "build-manager.default-build-target",
+ "action-target", namev,
+ "valign", GTK_ALIGN_CENTER,
+ "can-focus", FALSE,
+ NULL);
+ row = g_object_new (ADW_TYPE_ACTION_ROW,
+ "title", ide_build_target_get_display_name (item),
+ "activatable-widget", check,
+ NULL);
+ gtk_widget_add_css_class (check, "checkimage");
+ adw_action_row_add_suffix (row, check);
+
+ return GTK_WIDGET (row);
}
static void
@@ -86,6 +113,10 @@ gbp_buildui_targets_dialog_get_targets_cb (GObject *object,
}
}
+ self->busy_count--;
+
+ if (self->busy_count == 0)
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUSY]);
}
static void
@@ -102,10 +133,15 @@ gbp_buildui_targets_dialog_foreach_cb (IdeExtensionSetAdapter *set,
g_assert (IDE_IS_BUILD_TARGET_PROVIDER (provider));
g_assert (GBP_IS_BUILDUI_TARGETS_DIALOG (self));
+ self->busy_count++;
+
ide_build_target_provider_get_targets_async (provider,
NULL,
gbp_buildui_targets_dialog_get_targets_cb,
g_object_ref (self));
+
+ if (self->busy_count == 1)
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUSY]);
}
static void
@@ -145,6 +181,25 @@ gbp_buildui_targets_dialog_dispose (GObject *object)
G_OBJECT_CLASS (gbp_buildui_targets_dialog_parent_class)->dispose (object);
}
+static void
+gbp_buildui_targets_dialog_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbpBuilduiTargetsDialog *self = GBP_BUILDUI_TARGETS_DIALOG (object);
+
+ switch (prop_id)
+ {
+ case PROP_BUSY:
+ g_value_set_boolean (value, self->busy_count > 0);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
static void
gbp_buildui_targets_dialog_set_property (GObject *object,
guint prop_id,
@@ -171,12 +226,16 @@ gbp_buildui_targets_dialog_class_init (GbpBuilduiTargetsDialogClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = gbp_buildui_targets_dialog_dispose;
+ object_class->get_property = gbp_buildui_targets_dialog_get_property;
object_class->set_property = gbp_buildui_targets_dialog_set_property;
+ properties [PROP_BUSY] =
+ g_param_spec_boolean ("busy", NULL, NULL,
+ FALSE,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
properties [PROP_CONTEXT] =
- g_param_spec_object ("context",
- "Context",
- "The context for the build targets",
+ g_param_spec_object ("context", NULL, NULL,
IDE_TYPE_CONTEXT,
(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
@@ -184,6 +243,7 @@ gbp_buildui_targets_dialog_class_init (GbpBuilduiTargetsDialogClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/plugins/buildui/gbp-buildui-targets-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, GbpBuilduiTargetsDialog, list_box);
+ gtk_widget_class_bind_template_child (widget_class, GbpBuilduiTargetsDialog, spinner);
}
static void
diff --git a/src/plugins/buildui/gbp-buildui-targets-dialog.ui
b/src/plugins/buildui/gbp-buildui-targets-dialog.ui
index c2d8b038b..ad1ecf45e 100644
--- a/src/plugins/buildui/gbp-buildui-targets-dialog.ui
+++ b/src/plugins/buildui/gbp-buildui-targets-dialog.ui
@@ -15,7 +15,12 @@
<object class="AdwPreferencesPage">
<child>
<object class="AdwPreferencesGroup">
- <property name="title" translatable="yes">Build Targets</property>
+ <property name="title" translatable="yes">Available Build Targets</property>
+ <property name="header-suffix">
+ <object class="GtkSpinner" id="spinner">
+ <property name="spinning" bind-source="GbpBuilduiTargetsDialog" bind-property="busy"
bind-flags="sync-create"/>
+ </object>
+ </property>
<child>
<object class="GtkListBox" id="list_box">
<style>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]