[gnome-builder] gui: add private API to execute a command by identifier



commit c209ccae00887443eea090b7d6dc845e2c0e4c48
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 7 13:30:24 2019 -0700

    gui: add private API to execute a command by identifier

 src/libide/gui/ide-command-manager.c | 50 ++++++++++++++++++++++++++++++++++++
 src/libide/gui/ide-gui-private.h     |  3 +++
 2 files changed, 53 insertions(+)
---
diff --git a/src/libide/gui/ide-command-manager.c b/src/libide/gui/ide-command-manager.c
index 9f438bd63..225d376ef 100644
--- a/src/libide/gui/ide-command-manager.c
+++ b/src/libide/gui/ide-command-manager.c
@@ -371,3 +371,53 @@ ide_command_manager_get_command_by_id (IdeCommandManager *self,
 
   return g_steal_pointer (&state.command);
 }
+
+static void
+ide_command_manager_execute_cb (GObject      *object,
+                                GAsyncResult *result,
+                                gpointer      user_data)
+{
+  IdeCommand *command = (IdeCommand *)object;
+  g_autoptr(IdeCommandManager) self = user_data;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (IDE_IS_COMMAND (command));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (IDE_IS_COMMAND_MANAGER (self));
+
+  if (!ide_command_run_finish (command, result, &error))
+    ide_object_warning (self, "%s: %s", _("Command failed"), error->message);
+
+  ide_object_destroy (IDE_OBJECT (command));
+}
+
+void
+_ide_command_manager_execute (IdeCommandManager *self,
+                              IdeWorkspace      *workspace,
+                              const gchar       *command_id)
+{
+  g_autoptr(IdeCommand) command = NULL;
+
+  g_return_if_fail (IDE_IS_COMMAND_MANAGER (self));
+  g_return_if_fail (IDE_IS_WORKSPACE (workspace));
+
+  command = ide_command_manager_get_command_by_id (self, workspace, command_id);
+
+  if (command == NULL)
+    {
+      IdeContext *context = ide_workspace_get_context (workspace);
+
+      ide_context_warning (context,
+                           _("Failed to locate command ā€œ%sā€"),
+                           command_id);
+      return;
+    }
+
+  if (ide_object_is_root (IDE_OBJECT (command)))
+    ide_object_append (IDE_OBJECT (self), IDE_OBJECT (command));
+
+  ide_command_run_async (command,
+                         NULL,
+                         ide_command_manager_execute_cb,
+                         g_object_ref (self));
+}
diff --git a/src/libide/gui/ide-gui-private.h b/src/libide/gui/ide-gui-private.h
index 9567f139d..b7c3f90ec 100644
--- a/src/libide/gui/ide-gui-private.h
+++ b/src/libide/gui/ide-gui-private.h
@@ -44,6 +44,9 @@
 
 G_BEGIN_DECLS
 
+void      _ide_command_manager_execute          (IdeCommandManager   *self,
+                                                 IdeWorkspace        *workspace,
+                                                 const gchar         *command);
 gboolean  _ide_gtk_widget_action_is_stateful    (GtkWidget           *widget,
                                                  const gchar         *action_name);
 void      _ide_frame_init_actions               (IdeFrame            *self);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]