[gnome-builder/wip/gtk4-port: 859/1774] libide/commands: add param parameter to commands
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 859/1774] libide/commands: add param parameter to commands
- Date: Mon, 11 Jul 2022 22:31:26 +0000 (UTC)
commit d2bb4eb38ce51e6a8de4e5d3e725098fcca01697
Author: Christian Hergert <chergert redhat com>
Date: Tue May 3 12:50:37 2022 -0700
libide/commands: add param parameter to commands
This will make it a bit easier to merge actions/commands as we go forward.
src/libide/commands/ide-command-manager.c | 8 +++++++-
src/libide/commands/ide-command-manager.h | 3 ++-
src/libide/commands/ide-command.c | 5 ++++-
src/libide/commands/ide-command.h | 2 ++
src/libide/gui/ide-workspace-actions.c | 18 ++++++++++++++----
5 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/commands/ide-command-manager.c b/src/libide/commands/ide-command-manager.c
index 4025c7add..012cd5c97 100644
--- a/src/libide/commands/ide-command-manager.c
+++ b/src/libide/commands/ide-command-manager.c
@@ -509,14 +509,19 @@ ide_command_manager_execute_cb (GObject *object,
void
ide_command_manager_execute (IdeCommandManager *self,
GtkWidget *widget,
- const char *command_id)
+ const char *command_id,
+ GVariant *params)
{
g_autoptr(IdeCommand) command = NULL;
+ g_autoptr(GVariant) freeme = NULL;
g_return_if_fail (IDE_IS_COMMAND_MANAGER (self));
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (command_id != NULL);
+ if (g_variant_is_floating (params))
+ freeme = g_variant_ref_sink (params);
+
if (!(command = ide_command_manager_get_command_by_id (self, widget, command_id)))
{
ide_object_warning (IDE_OBJECT (self),
@@ -529,6 +534,7 @@ ide_command_manager_execute (IdeCommandManager *self,
ide_object_append (IDE_OBJECT (self), IDE_OBJECT (command));
ide_command_run_async (command,
+ params,
NULL,
ide_command_manager_execute_cb,
g_object_ref (self));
diff --git a/src/libide/commands/ide-command-manager.h b/src/libide/commands/ide-command-manager.h
index 647b2d862..788e5570e 100644
--- a/src/libide/commands/ide-command-manager.h
+++ b/src/libide/commands/ide-command-manager.h
@@ -46,7 +46,8 @@ IdeCommand *ide_command_manager_get_command_by_id (IdeCommandManager *
IDE_AVAILABLE_IN_ALL
void ide_command_manager_execute (IdeCommandManager *self,
GtkWidget *widget,
- const char *command_id);
+ const char *command_id,
+ GVariant *params);
IDE_AVAILABLE_IN_ALL
void ide_command_manager_load_shortcuts (IdeCommandManager *self,
GtkNative *native);
diff --git a/src/libide/commands/ide-command.c b/src/libide/commands/ide-command.c
index ac5511e6d..259fe84ec 100644
--- a/src/libide/commands/ide-command.c
+++ b/src/libide/commands/ide-command.c
@@ -28,6 +28,7 @@ G_DEFINE_INTERFACE (IdeCommand, ide_command, IDE_TYPE_OBJECT)
static void
ide_command_real_run_async (IdeCommand *self,
+ GVariant *params,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -66,6 +67,7 @@ ide_command_default_init (IdeCommandInterface *iface)
/**
* ide_command_run_async:
* @self: an #IdeCommand
+ * @params: (nullable): a #GVariant or %NULL
* @cancellable: (nullable): a #GCancellable
* @callback: a #GAsyncReadyCallback to execute upon completion
* @user_data: closure data for @callback
@@ -76,6 +78,7 @@ ide_command_default_init (IdeCommandInterface *iface)
*/
void
ide_command_run_async (IdeCommand *self,
+ GVariant *params,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -83,7 +86,7 @@ ide_command_run_async (IdeCommand *self,
g_return_if_fail (IDE_IS_COMMAND (self));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
- IDE_COMMAND_GET_IFACE (self)->run_async (self, cancellable, callback, user_data);
+ IDE_COMMAND_GET_IFACE (self)->run_async (self, params, cancellable, callback, user_data);
}
/**
diff --git a/src/libide/commands/ide-command.h b/src/libide/commands/ide-command.h
index 6898685cd..91ce8dbc6 100644
--- a/src/libide/commands/ide-command.h
+++ b/src/libide/commands/ide-command.h
@@ -40,6 +40,7 @@ struct _IdeCommandInterface
char *(*get_title) (IdeCommand *self);
char *(*get_subtitle) (IdeCommand *self);
void (*run_async) (IdeCommand *self,
+ GVariant *params,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
@@ -60,6 +61,7 @@ IDE_AVAILABLE_IN_ALL
char *ide_command_get_subtitle (IdeCommand *self);
IDE_AVAILABLE_IN_ALL
void ide_command_run_async (IdeCommand *self,
+ GVariant *params,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
diff --git a/src/libide/gui/ide-workspace-actions.c b/src/libide/gui/ide-workspace-actions.c
index 63cae07ac..f7773c8a7 100644
--- a/src/libide/gui/ide-workspace-actions.c
+++ b/src/libide/gui/ide-workspace-actions.c
@@ -47,19 +47,29 @@ ide_workspace_actions_command (GSimpleAction *action,
{
IdeCommandManager *command_manager;
IdeWorkspace *self = user_data;
- const gchar *command;
IdeContext *context;
+ g_autoptr(GVariant) str = NULL;
+ g_autoptr(GVariant) maybe = NULL;
+ g_autoptr(GVariant) params = NULL;
g_assert (G_IS_SIMPLE_ACTION (action));
g_assert (param != NULL);
- g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE_STRING));
+ g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE ("(smv)")));
g_assert (IDE_IS_WORKSPACE (self));
- command = g_variant_get_string (param, NULL);
context = ide_widget_get_context (GTK_WIDGET (self));
command_manager = ide_command_manager_from_context (context);
- ide_command_manager_execute (command_manager, GTK_WIDGET (self), command);
+ str = g_variant_get_child_value (param, 0);
+ maybe = g_variant_get_child_value (param, 1);
+
+ if (maybe != NULL && g_variant_n_children (maybe) == 1)
+ params = g_variant_get_child_value (maybe, 0);
+
+ ide_command_manager_execute (command_manager,
+ GTK_WIDGET (self),
+ g_variant_get_string (str, NULL),
+ params);
}
static const GActionEntry actions[] = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]