[gnome-builder] gui: add notification while updating dependencies
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] gui: add notification while updating dependencies
- Date: Tue, 29 Jan 2019 00:25:31 +0000 (UTC)
commit 62437eb7c574792c01e3f1b911db7d307017d7fb
Author: Christian Hergert <chergert redhat com>
Date: Mon Jan 28 16:25:03 2019 -0800
gui: add notification while updating dependencies
po/POTFILES.in | 1 +
src/libide/gui/ide-primary-workspace-actions.c | 73 +++++++++++++++++++++++---
2 files changed, 68 insertions(+), 6 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9166b14a9..3877a8c1d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -95,6 +95,7 @@ src/libide/gui/ide-panel.c
src/libide/gui/ide-preferences-builtin.c
src/libide/gui/ide-preferences-surface.c
src/libide/gui/ide-preferences-window.ui
+src/libide/gui/ide-primary-workspace-actions.c
src/libide/gui/ide-primary-workspace.ui
src/libide/gui/ide-run-button.c
src/libide/gui/ide-run-button.ui
diff --git a/src/libide/gui/ide-primary-workspace-actions.c b/src/libide/gui/ide-primary-workspace-actions.c
index e90976f4e..669b12225 100644
--- a/src/libide/gui/ide-primary-workspace-actions.c
+++ b/src/libide/gui/ide-primary-workspace-actions.c
@@ -22,6 +22,7 @@
#include "config.h"
+#include <glib/gi18n.h>
#include <libide-foundry.h>
#include <libpeas/peas.h>
@@ -29,26 +30,53 @@
#include "ide-gui-private.h"
#include "ide-primary-workspace.h"
+typedef struct
+{
+ IdeNotification *notif;
+ gint n_active;
+} UpdateDependencies;
+
+static void
+update_dependencies_free (UpdateDependencies *ud)
+{
+ if (ud->notif != NULL)
+ {
+ ide_notification_withdraw (ud->notif);
+ ide_clear_and_destroy_object (&ud->notif);
+ }
+
+ g_slice_free (UpdateDependencies, ud);
+}
+
static void
update_dependencies_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
IdeDependencyUpdater *updater = (IdeDependencyUpdater *)object;
- g_autoptr(IdePrimaryWorkspace) self = user_data;
+ g_autoptr(IdeTask) task = user_data;
g_autoptr(GError) error = NULL;
+ IdePrimaryWorkspace *self;
+ UpdateDependencies *ud;
IdeContext *context;
g_assert (IDE_IS_DEPENDENCY_UPDATER (updater));
g_assert (G_IS_ASYNC_RESULT (result));
- g_assert (IDE_IS_PRIMARY_WORKSPACE (self));
+ g_assert (IDE_IS_TASK (task));
+ self = ide_task_get_source_object (task);
context = ide_widget_get_context (GTK_WIDGET (self));
if (!ide_dependency_updater_update_finish (updater, result, &error))
ide_context_warning (context, "%s", error->message);
ide_object_destroy (IDE_OBJECT (updater));
+
+ ud = ide_task_get_task_data (task);
+ ud->n_active--;
+
+ if (ud->n_active == 0)
+ ide_task_return_boolean (task, TRUE);
}
static void
@@ -58,21 +86,28 @@ ide_primary_workspace_actions_update_dependencies_cb (PeasExtensionSet *set,
gpointer user_data)
{
IdeDependencyUpdater *updater = (IdeDependencyUpdater *)exten;
- IdePrimaryWorkspace *self = user_data;
+ IdePrimaryWorkspace *self;
+ UpdateDependencies *ud;
IdeContext *context;
+ IdeTask *task = user_data;
g_assert (PEAS_IS_EXTENSION_SET (set));
g_assert (plugin_info != NULL);
g_assert (IDE_IS_DEPENDENCY_UPDATER (updater));
- g_assert (IDE_IS_PRIMARY_WORKSPACE (self));
+ g_assert (IDE_IS_TASK (task));
+
+ self = ide_task_get_source_object (task);
context = ide_widget_get_context (GTK_WIDGET (self));
ide_object_append (IDE_OBJECT (context), IDE_OBJECT (updater));
+ ud = ide_task_get_task_data (task);
+ ud->n_active++;
+
ide_dependency_updater_update_async (updater,
NULL,
update_dependencies_cb,
- g_object_ref (self));
+ g_object_ref (task));
}
static void
@@ -82,15 +117,41 @@ ide_primary_workspace_actions_update_dependencies (GSimpleAction *action,
{
IdePrimaryWorkspace *self = user_data;
g_autoptr(PeasExtensionSet) set = NULL;
+ g_autoptr(IdeNotification) notif = NULL;
+ g_autoptr(IdeTask) task = NULL;
+ UpdateDependencies *state;
+ IdeContext *context;
g_assert (IDE_IS_MAIN_THREAD ());
g_assert (G_IS_SIMPLE_ACTION (action));
g_assert (IDE_IS_PRIMARY_WORKSPACE (self));
+ context = ide_widget_get_context (GTK_WIDGET (self));
+
+ notif = ide_notification_new ();
+ ide_notification_set_title (notif, _("Updating Dependencies…"));
+ ide_notification_set_body (notif, _("Builder is updating your projects configured dependencies."));
+ ide_notification_set_icon_name (notif, "software-update-available-symbolic");
+ ide_notification_set_has_progress (notif, TRUE);
+ ide_notification_set_progress_is_imprecise (notif, TRUE);
+ ide_notification_attach (notif, IDE_OBJECT (context));
+
+ state = g_slice_new0 (UpdateDependencies);
+ state->n_active = 0;
+ state->notif = g_object_ref (notif);
+
+ task = ide_task_new (self, NULL, NULL, NULL);
+ ide_task_set_source_tag (task, ide_primary_workspace_actions_update_dependencies);
+ ide_task_set_task_data (task, state, update_dependencies_free);
+
set = peas_extension_set_new (peas_engine_get_default (),
IDE_TYPE_DEPENDENCY_UPDATER,
NULL);
- peas_extension_set_foreach (set, ide_primary_workspace_actions_update_dependencies_cb, self);
+ peas_extension_set_foreach (set,
+ ide_primary_workspace_actions_update_dependencies_cb,
+ task);
+ if (state->n_active == 0)
+ ide_task_return_boolean (task, TRUE);
}
static const GActionEntry actions[] = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]