Commit a0d1b58e authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte

GladeWindow: move actions to GtkApplication

parent f787130c
......@@ -75,11 +75,13 @@
#define CONFIG_INTRO_GROUP "Intro"
#define CONFIG_INTRO_DONE "intro-done"
#define GLADE_WINDOW_ACTIVE_VIEW(w) ((GladeDesignView *) gtk_stack_get_visible_child (w->priv->view_stack))
#define GLADE_WINDOW_ACTIVE_VIEW(w) ((GladeDesignView *) gtk_stack_get_visible_child (w->priv->view_stack))
#define GLADE_WINDOW_GET_ACTION(w,a) ((w && ((GladeWindow *)w)->priv->application) ? g_action_map_lookup_action (G_ACTION_MAP (((GladeWindow *)w)->priv->application), a) : NULL)
struct _GladeWindowPrivate
{
GladeApp *app;
GtkApplication *application;
GtkStack *stack;
GtkStack *view_stack;
......@@ -129,7 +131,7 @@ struct _GladeWindowPrivate
static void check_reload_project (GladeWindow *window, GladeProject *project);
G_DEFINE_TYPE_WITH_PRIVATE (GladeWindow, glade_window, GTK_TYPE_APPLICATION_WINDOW)
G_DEFINE_TYPE_WITH_PRIVATE (GladeWindow, glade_window, GTK_TYPE_WINDOW)
static void
refresh_title (GladeWindow *window)
......@@ -403,11 +405,13 @@ project_targets_changed_cb (GladeProject *project, GladeWindow *window)
refresh_stack_title_for_project (window, project);
}
static void
static inline void
actions_set_enabled (GladeWindow *window, const gchar *name, gboolean enabled)
{
GAction *action = g_action_map_lookup_action (G_ACTION_MAP (window), name);
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
GAction *action;
if ((action = GLADE_WINDOW_GET_ACTION (window, name)))
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
}
static void
......@@ -1538,7 +1542,9 @@ drag_data_received (GtkWidget *widget,
static gboolean
delete_event (GtkWindow *w, GdkEvent *event, GladeWindow *window)
{
g_action_group_activate_action (G_ACTION_GROUP (window), "quit", NULL);
GladeWindowPrivate *priv = window->priv;
g_action_group_activate_action (G_ACTION_GROUP (priv->application), "quit", NULL);
/* return TRUE to stop other handlers */
return TRUE;
......@@ -2077,6 +2083,8 @@ on_quit_action_activate (GSimpleAction *action,
glade_window_config_save (window);
g_list_free (projects);
g_application_quit (G_APPLICATION (window->priv->application));
}
static void
......@@ -2144,9 +2152,10 @@ glade_window_init (GladeWindow *window)
static void
glade_window_action_handler (GladeWindow *window, const gchar *name)
{
GladeWindowPrivate *priv = window->priv;
GAction *action;
if ((action = g_action_map_lookup_action (G_ACTION_MAP (window), name)))
if ((action = GLADE_WINDOW_GET_ACTION (window, name)))
g_action_activate (action, NULL);
}
......@@ -2216,16 +2225,17 @@ on_intro_show_node (GladeIntro *intro,
if (!g_strcmp0 (node, "new-project"))
{
/* Create two new project to make the project switcher visible */
g_action_group_activate_action (G_ACTION_GROUP (window), "new", NULL);
g_action_group_activate_action (G_ACTION_GROUP (window), "new", NULL);
g_action_group_activate_action (G_ACTION_GROUP (priv->application), "new", NULL);
g_action_group_activate_action (G_ACTION_GROUP (priv->application), "new", NULL);
}
else if (!g_strcmp0 (node, "add-project"))
{
GAction *new_action = g_action_map_lookup_action (G_ACTION_MAP (window), "new");
GAction *new_action;
g_signal_connect (new_action, "activate",
G_CALLBACK (on_user_new_action_activate),
window);
if ((new_action = GLADE_WINDOW_GET_ACTION (window, "new")))
g_signal_connect (new_action, "activate",
G_CALLBACK (on_user_new_action_activate),
window);
}
else if (!g_strcmp0 (node, "add-window"))
{
......@@ -2342,7 +2352,7 @@ glade_window_populate_intro (GladeWindow *window)
}
static void
glade_window_constructed (GObject *object)
on_application_notify (GObject *gobject, GParamSpec *pspec)
{
static GActionEntry actions[] = {
{ "open", on_open_action_activate, NULL, NULL, NULL },
......@@ -2372,6 +2382,23 @@ glade_window_constructed (GObject *object)
{ "margin_edit", on_pointer_margin_edit_action_activate, NULL, NULL, NULL },
{ "align_edit", on_pointer_align_edit_action_activate, NULL, NULL, NULL },
};
GladeWindowPrivate * priv = GLADE_WINDOW (gobject)->priv;
priv->application = gtk_window_get_application (GTK_WINDOW (gobject));
g_action_map_add_action_entries (G_ACTION_MAP (priv->application),
actions,
G_N_ELEMENTS (actions),
gobject);
gtk_widget_insert_action_group (GTK_WIDGET (gobject), "app",
G_ACTION_GROUP (priv->application));
project_actions_set_enabled (GLADE_WINDOW (gobject), FALSE);
}
static void
glade_window_constructed (GObject *object)
{
GladeWindow *window = GLADE_WINDOW (object);
GladeWindowPrivate *priv = window->priv;
gchar *version;
......@@ -2379,6 +2406,8 @@ glade_window_constructed (GObject *object)
/* Chain up... */
G_OBJECT_CLASS (glade_window_parent_class)->constructed (object);
g_signal_connect (object, "notify::application", G_CALLBACK (on_application_notify), NULL);
/* Init Glade version */
version = g_strdup_printf ("%d.%d.%d", GLADE_MAJOR_VERSION, GLADE_MINOR_VERSION, GLADE_MICRO_VERSION);
gtk_label_set_text (priv->version_label, version);
......@@ -2387,10 +2416,6 @@ glade_window_constructed (GObject *object)
/* recent files */
priv->recent_manager = gtk_recent_manager_get_default ();
/* Setup Actions */
g_action_map_add_action_entries (G_ACTION_MAP (window), actions, G_N_ELEMENTS (actions), window);
gtk_widget_insert_action_group (GTK_WIDGET (window), "app", G_ACTION_GROUP(window));
/* status bar */
priv->statusbar_context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (priv->statusbar), "general");
priv->statusbar_menu_context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (priv->statusbar), "menu");
......@@ -2430,7 +2455,6 @@ glade_window_constructed (GObject *object)
glade_window_populate_intro (window);
refresh_title (window);
project_actions_set_enabled (window, FALSE);
}
#define DEFINE_ACTION_SIGNAL(klass, name, handler,...) \
......
......@@ -38,13 +38,13 @@ typedef struct _GladeWindowClass GladeWindowClass;
struct _GladeWindow
{
GtkApplicationWindow parent_instance;
GtkWindow parent_instance;
GladeWindowPrivate *priv;
};
struct _GladeWindowClass
{
GtkApplicationWindowClass parent_class;
GtkWindowClass parent_class;
};
GType glade_window_get_type (void) G_GNUC_CONST;
......
......@@ -166,7 +166,7 @@ Author: Juan Pablo Ugarte
<property name="show_numbers">True</property>
<signal name="item-activated" handler="on_open_recent_action_item_activated" swapped="no"/>
</object>
<template class="GladeWindow" parent="GtkApplicationWindow">
<template class="GladeWindow" parent="GtkWindow">
<property name="can_focus">False</property>
<child>
<object class="GtkStack" id="stack">
......
......@@ -77,20 +77,11 @@ startup (GApplication *application)
}
static void
on_quit_activate (GAction *action,
GVariant *parameter,
GApplication *application)
{
g_application_quit (application);
}
static void
activate (GApplication *application)
{
GladeWindow *window;
GAction *quit;
if (version != FALSE)
{
......@@ -110,10 +101,6 @@ activate (GApplication *application)
gtk_widget_show (GTK_WIDGET (window));
glade_window_registration_notify_user (window);
quit = g_action_map_lookup_action (G_ACTION_MAP (window), "quit");
g_signal_connect (quit, "activate", G_CALLBACK (on_quit_activate), application);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment