[gtk+/wip/action-helper: 4/5] GtkActionHelper: add 'application' mode
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/action-helper: 4/5] GtkActionHelper: add 'application' mode
- Date: Sun, 17 Jun 2012 02:47:10 +0000 (UTC)
commit 039187304236ed94d9ae0acf08f9e49b97851062
Author: Ryan Lortie <desrt desrt ca>
Date: Sat Jun 16 22:44:07 2012 -0400
GtkActionHelper: add 'application' mode
For the sake of Mac OS.
gtk/gtkactionhelper.c | 109 +++++++++++++++++++++++++++++++++++++------------
gtk/gtkactionhelper.h | 4 ++
2 files changed, 87 insertions(+), 26 deletions(-)
---
diff --git a/gtk/gtkactionhelper.c b/gtk/gtkactionhelper.c
index 60f8d58..abd755a 100644
--- a/gtk/gtkactionhelper.c
+++ b/gtk/gtkactionhelper.c
@@ -234,7 +234,8 @@ struct _GtkActionHelper
{
GObject parent_instance;
- GtkActionable *widget;
+ GtkApplication *application;
+ GtkWidget *widget;
GtkActionHelperGroup *group;
@@ -271,36 +272,39 @@ gtk_action_helper_report_change (GtkActionHelper *helper,
{
helper->reporting++;
- switch (prop_id)
+ if (!helper->application)
{
- case PROP_ENABLED:
- gtk_widget_set_sensitive (GTK_WIDGET (helper->widget), helper->enabled);
- break;
+ switch (prop_id)
+ {
+ case PROP_ENABLED:
+ gtk_widget_set_sensitive (GTK_WIDGET (helper->widget), helper->enabled);
+ break;
- case PROP_ACTIVE:
- {
- GParamSpec *pspec;
+ case PROP_ACTIVE:
+ {
+ GParamSpec *pspec;
- pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (helper->widget), "active");
+ pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (helper->widget), "active");
- if (pspec && G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_BOOLEAN)
- g_object_set (G_OBJECT (helper->widget), "active", helper->active, NULL);
- }
- break;
+ if (pspec && G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_BOOLEAN)
+ g_object_set (G_OBJECT (helper->widget), "active", helper->active, NULL);
+ }
+ break;
- case PROP_ROLE:
- {
- GParamSpec *pspec;
+ case PROP_ROLE:
+ {
+ GParamSpec *pspec;
- pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (helper->widget), "action-role");
+ pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (helper->widget), "action-role");
- if (pspec && G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_UINT)
- g_object_set (G_OBJECT (helper->widget), "action-role", helper->role, NULL);
- }
- break;
+ if (pspec && G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_UINT)
+ g_object_set (G_OBJECT (helper->widget), "action-role", helper->role, NULL);
+ }
+ break;
- default:
- g_assert_not_reached ();
+ default:
+ g_assert_not_reached ();
+ }
}
g_object_notify_by_pspec (G_OBJECT (helper), gtk_action_helper_pspecs[prop_id]);
@@ -527,6 +531,17 @@ gtk_action_helper_finalize (GObject *object)
g_signal_handlers_disconnect_by_func (helper->widget, gtk_action_helper_actions_changed, helper);
+ if (helper->application)
+ {
+ g_object_unref (helper->application);
+
+ if (helper->widget)
+ {
+ g_signal_handlers_disconnect_by_data (helper->widget, helper);
+ g_object_unref (helper->widget);
+ }
+ }
+
g_free (helper->action_group_name);
g_free (helper->action_name);
@@ -585,13 +600,53 @@ gtk_action_helper_new (GtkActionable *widget)
g_return_val_if_fail (GTK_IS_ACTIONABLE (widget), NULL);
helper = g_object_new (GTK_TYPE_ACTION_HELPER, NULL);
- helper->widget = widget;
+ helper->widget = GTK_WIDGET (widget);
g_signal_connect (widget, "actions-changed", G_CALLBACK (gtk_action_helper_actions_changed), helper);
return helper;
}
+static void
+gtk_action_helper_active_window_changed (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ GtkActionHelper *helper = user_data;
+
+ if (helper->widget)
+ {
+ g_signal_handlers_disconnect_by_func (helper->widget, gtk_action_helper_actions_changed, helper);
+ g_object_unref (helper->widget);
+ }
+
+ helper->widget = GTK_WIDGET (gtk_application_get_active_window (helper->application));
+
+ if (helper->widget)
+ {
+ g_signal_connect (helper->widget, "actions-changed", G_CALLBACK (gtk_action_helper_actions_changed), helper);
+ g_object_ref (helper->widget);
+ }
+
+ gtk_action_helper_actions_changed (helper->widget, NULL, helper);
+}
+
+GtkActionHelper *
+gtk_action_helper_new_with_application (GtkApplication *application)
+{
+ GtkActionHelper *helper;
+
+ g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
+
+ helper = g_object_new (GTK_TYPE_ACTION_HELPER, NULL);
+ helper->application = g_object_ref (application);
+
+ g_signal_connect (application, "notify::active-window", G_CALLBACK (gtk_action_helper_active_window_changed), helper);
+ gtk_action_helper_active_window_changed (NULL, NULL, helper);
+
+ return helper;
+}
+
void
gtk_action_helper_set_action_name (GtkActionHelper *helper,
const gchar *action_name)
@@ -626,7 +681,8 @@ gtk_action_helper_set_action_name (GtkActionHelper *helper,
gtk_action_helper_actions_changed (NULL, NULL, helper);
- g_object_notify (G_OBJECT (helper->widget), "action-name");
+ if (!helper->application)
+ g_object_notify (G_OBJECT (helper->widget), "action-name");
}
void
@@ -687,7 +743,8 @@ gtk_action_helper_set_action_target_value (GtkActionHelper *helper,
if (helper->active != was_active)
gtk_action_helper_report_change (helper, PROP_ACTIVE);
- g_object_notify (G_OBJECT (helper->widget), "action-target");
+ if (!helper->application)
+ g_object_notify (G_OBJECT (helper->widget), "action-target");
}
const gchar *
diff --git a/gtk/gtkactionhelper.h b/gtk/gtkactionhelper.h
index fe23ef7..bc54357 100644
--- a/gtk/gtkactionhelper.h
+++ b/gtk/gtkactionhelper.h
@@ -20,6 +20,7 @@
#ifndef __GTK_ACTION_HELPER_H__
#define __GTK_ACTION_HELPER_H__
+#include <gtk/gtkapplication.h>
#include <gtk/gtkactionable.h>
#define GTK_TYPE_ACTION_HELPER (gtk_action_helper_get_type ())
@@ -44,6 +45,9 @@ G_GNUC_INTERNAL
GtkActionHelper * gtk_action_helper_new (GtkActionable *widget);
G_GNUC_INTERNAL
+GtkActionHelper * gtk_action_helper_new_with_application (GtkApplication *application);
+
+G_GNUC_INTERNAL
void gtk_action_helper_set_action_name (GtkActionHelper *helper,
const gchar *action_name);
G_GNUC_INTERNAL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]