[gnome-builder/wip/chergert/headerbar] util: add helper to get current context for a widget
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/headerbar] util: add helper to get current context for a widget
- Date: Wed, 22 Jun 2016 01:08:56 +0000 (UTC)
commit 4bfa3b66037da1801e1416077d665dc1ac856018
Author: Christian Hergert <chergert redhat com>
Date: Tue Jun 21 18:07:50 2016 -0700
util: add helper to get current context for a widget
This is the combination of a get_workbench() + get_context().
libide/util/ide-gtk.c | 30 ++++++++++++++++++++++++++----
libide/util/ide-gtk.h | 1 +
2 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/libide/util/ide-gtk.c b/libide/util/ide-gtk.c
index eec79e4..eb79211 100644
--- a/libide/util/ide-gtk.c
+++ b/libide/util/ide-gtk.c
@@ -113,15 +113,17 @@ ide_widget_notify_context (GtkWidget *toplevel,
GtkWidget *widget)
{
IdeWidgetContextHandler handler;
- IdeContext *context = NULL;
+ g_autoptr(IdeContext) context = NULL;
handler = g_object_get_data (G_OBJECT (widget), "IDE_CONTEXT_HANDLER");
- if (!handler)
+ if (handler == NULL)
return;
- g_object_get (toplevel, "context", &context, NULL);
+ g_object_get (toplevel,
+ "context", &context,
+ NULL);
+
handler (widget, context);
- g_clear_object (&context);
}
static void
@@ -415,3 +417,23 @@ ide_widget_add_style_class (GtkWidget *widget,
gtk_style_context_add_class (gtk_widget_get_style_context (widget), class_name);
}
+
+/**
+ * ide_widget_get_context: (skip)
+ *
+ * Returns: (nullable) (transfer none): An #IdeContext or %NULL.
+ */
+IdeContext *
+ide_widget_get_context (GtkWidget *widget)
+{
+ IdeWorkbench *workbench;
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+ workbench = ide_widget_get_workbench (widget);
+
+ if (workbench == NULL)
+ return NULL;
+
+ return ide_workbench_get_context (workbench);
+}
diff --git a/libide/util/ide-gtk.h b/libide/util/ide-gtk.h
index bcf75fa..869020f 100644
--- a/libide/util/ide-gtk.h
+++ b/libide/util/ide-gtk.h
@@ -40,6 +40,7 @@ gboolean ide_widget_action_with_string (GtkWidget *widget,
const gchar *param);
void ide_widget_set_context_handler (gpointer widget,
IdeWidgetContextHandler handler);
+IdeContext *ide_widget_get_context (GtkWidget *widget);
void ide_widget_hide_with_fade (GtkWidget *widget);
void ide_widget_show_with_fade (GtkWidget *widget);
void ide_widget_add_style_class (GtkWidget *widget,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]