[gedit/wip/gtkapp-actions: 6/10] GeditApp: add some actions and activate them in main()
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/gtkapp-actions: 6/10] GeditApp: add some actions and activate them in main()
- Date: Fri, 3 Aug 2012 08:04:41 +0000 (UTC)
commit 4963cd57f1d0764c593b7918fa9064663d6095d6
Author: SÃbastien Wilmet <swilmet gnome org>
Date: Fri Aug 3 07:43:37 2012 +0200
GeditApp: add some actions and activate them in main()
With actions, the code in GeditApp is simplified, there will be more
functions, but they are smaller.
Moreover, if one day we want to make GeditApp reusable (in a lib for
example), it will be easier like that. It doesn't depend on the command
line.
gedit/gedit-app.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
gedit/gedit.c | 51 ++++++++++++++++++++---
2 files changed, 165 insertions(+), 7 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 491070b..2c25dd2 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -94,11 +94,15 @@ struct _GeditAppPrivate
GtkPageSetup *page_setup;
GtkPrintSettings *print_settings;
-
+
GObject *settings;
GSettings *window_settings;
PeasExtensionSet *extensions;
+
+ const GeditEncoding *encoding;
+ gint line_position;
+ gint column_position;
};
static GeditApp *app_instance = NULL;
@@ -760,6 +764,119 @@ load_print_settings (GeditApp *app)
}
static void
+activate_new_window_action (GSimpleAction *action,
+ GVariant *parameter,
+ GeditApp *app)
+{
+ create_new_window (app);
+}
+
+static void
+activate_new_document_action (GSimpleAction *action,
+ GVariant *parameter,
+ GeditApp *app)
+{
+ g_return_if_fail (app->priv->active_window != NULL);
+
+ gedit_debug_message (DEBUG_APP, "Create tab");
+ gedit_window_create_tab (app->priv->active_window, TRUE);
+}
+
+static void
+activate_set_encoding_action (GSimpleAction *action,
+ GVariant *parameter,
+ GeditApp *app)
+{
+ const gchar *encoding_charset = g_variant_get_string (parameter, NULL);
+
+ app->priv->encoding = gedit_encoding_get_from_charset (encoding_charset);
+
+ if (app->priv->encoding == NULL)
+ {
+ g_warning (_("%s: invalid encoding."), encoding_charset);
+ }
+}
+
+static void
+activate_set_geometry_action (GSimpleAction *action,
+ GVariant *parameter,
+ GeditApp *app)
+{
+ const gchar *geometry;
+
+ geometry = g_variant_get_string (parameter, NULL);
+
+ gtk_window_parse_geometry (GTK_WINDOW (app->priv->active_window),
+ geometry);
+}
+
+static void
+activate_set_document_positions_action (GSimpleAction *action,
+ GVariant *parameter,
+ GeditApp *app)
+{
+ g_variant_get (parameter, "(ii)",
+ &app->priv->line_position,
+ &app->priv->column_position);
+}
+
+static void
+add_actions (GeditApp *app)
+{
+ GSimpleAction *action;
+ GVariantType *type;
+
+ /* New window */
+ action = g_simple_action_new ("new-window", NULL);
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
+
+ g_signal_connect (action,
+ "activate",
+ G_CALLBACK (activate_new_window_action),
+ app);
+
+ /* New document */
+ action = g_simple_action_new ("new-document", NULL);
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
+
+ g_signal_connect (action,
+ "activate",
+ G_CALLBACK (activate_new_document_action),
+ app);
+
+ /* Set encoding */
+ action = g_simple_action_new ("set-encoding", G_VARIANT_TYPE_STRING);
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
+
+ g_signal_connect (action,
+ "activate",
+ G_CALLBACK (activate_set_encoding_action),
+ app);
+
+ /* Set geometry */
+ action = g_simple_action_new ("set-geometry", G_VARIANT_TYPE_STRING);
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
+
+ g_signal_connect (action,
+ "activate",
+ G_CALLBACK (activate_set_geometry_action),
+ app);
+
+ /* Set document positions (line and column) */
+
+ type = g_variant_type_new ("(ii)");
+ action = g_simple_action_new ("set-document-positions", type);
+ g_variant_type_free (type);
+
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
+
+ g_signal_connect (action,
+ "activate",
+ G_CALLBACK (activate_set_document_positions_action),
+ app);
+}
+
+static void
gedit_app_init (GeditApp *app)
{
app->priv = GEDIT_APP_GET_PRIVATE (app);
@@ -770,6 +887,8 @@ gedit_app_init (GeditApp *app)
/* initial lockdown state */
app->priv->lockdown = gedit_settings_get_lockdown (GEDIT_SETTINGS (app->priv->settings));
+
+ add_actions (app);
}
/* FIXME: lets kill this method */
diff --git a/gedit/gedit.c b/gedit/gedit.c
index 87add02..feb697b 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -218,8 +218,8 @@ parse_command_line (int argc, char **argv)
int
main (int argc, char *argv[])
{
- GeditApp *app;
- gint status;
+ GeditApp *app = NULL;
+ GError *error = NULL;
g_type_init ();
@@ -229,12 +229,51 @@ main (int argc, char *argv[])
parse_command_line (argc, argv);
app = gedit_app_get_default ();
- status = g_application_run (G_APPLICATION (app), argc, argv);
- /* Cleanup */
- g_object_unref (app);
+ if (standalone)
+ {
+ GApplicationFlags old_flags;
+
+ old_flags = g_application_get_flags (G_APPLICATION (app));
+ g_application_set_flags (G_APPLICATION (app),
+ old_flags | G_APPLICATION_NON_UNIQUE);
+ }
+
+ if (!g_application_register (G_APPLICATION (app), NULL, &error))
+ {
+ g_error ("Failed to register the application: %s", error->message);
+ return EXIT_FAILURE;
+ }
+
+ if (encoding_charset != NULL)
+ {
+ g_action_group_activate_action (G_ACTION_GROUP (app),
+ "set-encoding",
+ g_variant_new_string (encoding_charset));
+ }
+
+ if (new_window)
+ {
+ g_action_group_activate_action (G_ACTION_GROUP (app),
+ "new-window",
+ NULL);
+ }
+
+ if (geometry != NULL)
+ {
+ g_action_group_activate_action (G_ACTION_GROUP (app),
+ "set-geometry",
+ g_variant_new_string (geometry));
+ }
+
+ if (new_document)
+ {
+ g_action_group_activate_action (G_ACTION_GROUP (app),
+ "new-document",
+ NULL);
+ }
- return status;
+ return g_application_run (G_APPLICATION (app), 0, NULL);
}
/* ex:set ts=8 noet: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]