[gnome-builder/wip/chergert/perspective] gtk: add helper to activate an action
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/perspective] gtk: add helper to activate an action
- Date: Wed, 25 Nov 2015 01:21:12 +0000 (UTC)
commit b5c425698c007402723ad052bb0e13437a223c79
Author: Christian Hergert <christian hergert me>
Date: Tue Nov 24 17:14:01 2015 -0800
gtk: add helper to activate an action
libide/ide-source-view.c | 100 +++++-----------------------------------------
libide/ide-source-view.h | 4 --
libide/ide-workbench.c | 14 ++++++
libide/util/ide-gtk.c | 38 +++++++++++++++++
libide/util/ide-gtk.h | 4 ++
5 files changed, 67 insertions(+), 93 deletions(-)
---
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 50b83dd..dfb2e7e 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -42,6 +42,7 @@
#include "ide-file-settings.h"
#include "ide-fixit.h"
#include "ide-gdk.h"
+#include "ide-gtk.h"
#include "ide-highlighter.h"
#include "ide-internal.h"
#include "ide-indenter.h"
@@ -421,53 +422,6 @@ ide_source_view_get_indenter (IdeSourceView *self)
}
static void
-activate_action (GtkWidget *widget,
- const gchar *prefix,
- const gchar *action_name,
- GVariant *parameter)
-{
- GApplication *app;
- GtkWidget *toplevel;
- GActionGroup *group = NULL;
-
- g_return_if_fail (GTK_IS_WIDGET (widget));
- g_return_if_fail (prefix);
- g_return_if_fail (action_name);
-
- app = g_application_get_default ();
- toplevel = gtk_widget_get_toplevel (widget);
-
- while ((group == NULL) && (widget != NULL))
- {
- group = gtk_widget_get_action_group (widget, prefix);
- widget = gtk_widget_get_parent (widget);
- }
-
- if (!group && g_str_equal (prefix, "win") && G_IS_ACTION_GROUP (toplevel))
- group = G_ACTION_GROUP (toplevel);
-
- if (!group && g_str_equal (prefix, "app") && G_IS_ACTION_GROUP (app))
- group = G_ACTION_GROUP (app);
-
- if (group)
- {
- if (g_action_group_has_action (group, action_name))
- {
- g_action_group_activate_action (group, action_name, parameter);
- return;
- }
- }
-
- if (parameter && g_variant_is_floating (parameter))
- {
- parameter = g_variant_ref_sink (parameter);
- g_variant_unref (parameter);
- }
-
- g_warning ("Failed to resolve action %s.%s", prefix, action_name);
-}
-
-static void
ide_source_view_block_handlers (IdeSourceView *self)
{
IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
@@ -2363,37 +2317,6 @@ ide_source_view_real_style_updated (GtkWidget *widget)
}
static void
-ide_source_view_real_action (IdeSourceView *self,
- const gchar *prefix,
- const gchar *action_name,
- const gchar *param)
-{
- GVariant *variant = NULL;
-
- IDE_ENTRY;
-
- g_return_if_fail (IDE_IS_SOURCE_VIEW (self));
-
- if (*param != 0)
- {
- g_autoptr(GError) error = NULL;
-
- variant = g_variant_parse (NULL, param, NULL, NULL, &error);
-
- if (variant == NULL)
- {
- g_warning ("can't parse keybinding parameters \"%s\": %s",
- param, error->message);
- return;
- }
- }
-
- activate_action (GTK_WIDGET (self), prefix, action_name, variant);
-
- IDE_EXIT;
-}
-
-static void
ide_source_view_real_append_to_count (IdeSourceView *self,
gint digit)
{
@@ -5330,7 +5253,6 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
text_view_class->insert_at_cursor = ide_source_view_real_insert_at_cursor;
text_view_class->populate_popup = ide_source_view_real_populate_popup;
- klass->action = ide_source_view_real_action;
klass->append_to_count = ide_source_view_real_append_to_count;
klass->begin_macro = ide_source_view_real_begin_macro;
klass->capture_modifier = ide_source_view_real_capture_modifier;
@@ -5541,16 +5463,16 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
g_object_class_install_properties (object_class, LAST_PROP, properties);
signals [ACTION] =
- g_signal_new ("action",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (IdeSourceViewClass, action),
- NULL, NULL, NULL,
- G_TYPE_NONE,
- 3,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING);
+ g_signal_new_class_handler ("action",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_CALLBACK (ide_widget_action_with_string),
+ NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 3,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
signals [APPEND_TO_COUNT] =
g_signal_new ("append-to-count",
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index 84d30e6..8a1c8eb 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -201,10 +201,6 @@ struct _IdeSourceViewClass
{
GtkSourceViewClass parent_class;
- void (*action) (IdeSourceView *self,
- const gchar *prefix,
- const gchar *action_name,
- const gchar *param);
void (*append_to_count) (IdeSourceView *self,
gint digit);
void (*auto_indent) (IdeSourceView *self);
diff --git a/libide/ide-workbench.c b/libide/ide-workbench.c
index ea9d634..7b674b5 100644
--- a/libide/ide-workbench.c
+++ b/libide/ide-workbench.c
@@ -19,6 +19,7 @@
#define G_LOG_DOMAIN "ide-workbench"
#include "ide-debug.h"
+#include "ide-gtk.h"
#include "ide-macros.h"
#include "ide-window-settings.h"
#include "ide-workbench.h"
@@ -37,6 +38,7 @@ enum {
};
enum {
+ ACTION,
SET_PERSPECTIVE,
LAST_SIGNAL
};
@@ -220,6 +222,18 @@ ide_workbench_class_init (IdeWorkbenchClass *klass)
g_object_class_install_properties (object_class, LAST_PROP, properties);
+ signals [ACTION] =
+ g_signal_new_class_handler ("action",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+ G_CALLBACK (ide_widget_action_with_string),
+ NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 3,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+
/**
* IdeWorkbench::set-perspective:
* @self: An #IdeWorkbench
diff --git a/libide/util/ide-gtk.c b/libide/util/ide-gtk.c
index cf87ae4..ccdfd00 100644
--- a/libide/util/ide-gtk.c
+++ b/libide/util/ide-gtk.c
@@ -18,6 +18,7 @@
#include "egg-animation.h"
+#include "ide-debug.h"
#include "ide-gtk.h"
gboolean
@@ -64,6 +65,43 @@ ide_widget_action (GtkWidget *widget,
return FALSE;
}
+gboolean
+ide_widget_action_with_string (GtkWidget *widget,
+ const gchar *group,
+ const gchar *name,
+ const gchar *param)
+{
+ GVariant *variant = NULL;
+ gboolean ret;
+
+ IDE_ENTRY;
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+ g_return_val_if_fail (group != NULL, FALSE);
+ g_return_val_if_fail (name != NULL, FALSE);
+
+ if (param == NULL)
+ param = "";
+
+ if (*param != 0)
+ {
+ g_autoptr(GError) error = NULL;
+
+ variant = g_variant_parse (NULL, param, NULL, NULL, &error);
+
+ if (variant == NULL)
+ {
+ g_warning ("can't parse keybinding parameters \"%s\": %s",
+ param, error->message);
+ IDE_RETURN (FALSE);
+ }
+ }
+
+ ret = ide_widget_action (widget, group, name, variant);
+
+ IDE_RETURN (ret);
+}
+
static void
ide_widget_notify_context (GtkWidget *toplevel,
GParamSpec *pspec,
diff --git a/libide/util/ide-gtk.h b/libide/util/ide-gtk.h
index 866fbe6..5f35c33 100644
--- a/libide/util/ide-gtk.h
+++ b/libide/util/ide-gtk.h
@@ -33,6 +33,10 @@ gboolean ide_widget_action (GtkWidget *widget,
const gchar *group,
const gchar *name,
GVariant *param);
+gboolean ide_widget_action_with_string (GtkWidget *widget,
+ const gchar *group,
+ const gchar *name,
+ const gchar *param);
void ide_widget_set_context_handler (gpointer widget,
IdeWidgetContextHandler handler);
void ide_widget_hide_with_fade (GtkWidget *widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]