[gedit/wip/gtkapp-actions] GeditApp: simplify add_actions()
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/gtkapp-actions] GeditApp: simplify add_actions()
- Date: Fri, 3 Aug 2012 17:23:14 +0000 (UTC)
commit b80ce67cf282eb5167201579e8a3aa0163b78aa6
Author: SÃbastien Wilmet <swilmet gnome org>
Date: Fri Aug 3 19:13:57 2012 +0200
GeditApp: simplify add_actions()
gedit/gedit-app.c | 108 +++++++++++++++-------------------------------------
1 files changed, 31 insertions(+), 77 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 1db81c0..d603773 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -759,16 +759,18 @@ load_print_settings (GeditApp *app)
static void
activate_new_window_action (GSimpleAction *action,
GVariant *parameter,
- GeditApp *app)
+ gpointer user_data)
{
- create_new_window (app);
+ create_new_window (GEDIT_APP (user_data));
}
static void
activate_new_document_action (GSimpleAction *action,
GVariant *parameter,
- GeditApp *app)
+ gpointer user_data)
{
+ GeditApp *app = GEDIT_APP (user_data);
+
g_return_if_fail (app->priv->active_window != NULL);
gedit_debug_message (DEBUG_APP, "Create tab");
@@ -778,8 +780,9 @@ activate_new_document_action (GSimpleAction *action,
static void
activate_set_encoding_action (GSimpleAction *action,
GVariant *parameter,
- GeditApp *app)
+ gpointer user_data)
{
+ GeditApp *app = GEDIT_APP (user_data);
const gchar *encoding_charset = g_variant_get_string (parameter, NULL);
app->priv->encoding = gedit_encoding_get_from_charset (encoding_charset);
@@ -793,8 +796,9 @@ activate_set_encoding_action (GSimpleAction *action,
static void
activate_set_geometry_action (GSimpleAction *action,
GVariant *parameter,
- GeditApp *app)
+ gpointer user_data)
{
+ GeditApp *app = GEDIT_APP (user_data);
const gchar *geometry;
geometry = g_variant_get_string (parameter, NULL);
@@ -806,8 +810,10 @@ activate_set_geometry_action (GSimpleAction *action,
static void
activate_set_document_positions_action (GSimpleAction *action,
GVariant *parameter,
- GeditApp *app)
+ gpointer user_data)
{
+ GeditApp *app = GEDIT_APP (user_data);
+
g_variant_get (parameter, "(ii)",
&app->priv->line_position,
&app->priv->column_position);
@@ -816,8 +822,9 @@ activate_set_document_positions_action (GSimpleAction *action,
static void
activate_open_files_action (GSimpleAction *action,
GVariant *parameter,
- GeditApp *app)
+ gpointer user_data)
{
+ GeditApp *app = GEDIT_APP (user_data);
const gchar **uri_list = NULL;
const gchar **cur_uri = NULL;
GSList *file_list = NULL;
@@ -858,9 +865,11 @@ activate_open_files_action (GSimpleAction *action,
static void
activate_read_stdin_action (GSimpleAction *action,
GVariant *parameter,
- GeditApp *app)
+ gpointer user_data)
{
#ifdef G_OS_UNIX
+ GeditApp *app = GEDIT_APP (user_data);
+
/* It would nice, but it doesn't work for a remote instance.
* Most probably not handled in GApplication.
*/
@@ -881,75 +890,20 @@ activate_read_stdin_action (GSimpleAction *action,
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);
-
- /* Open files */
- action = g_simple_action_new ("open-files", G_VARIANT_TYPE_STRING_ARRAY);
- g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
-
- g_signal_connect (action,
- "activate",
- G_CALLBACK (activate_open_files_action),
- app);
-
- /* Read stdin */
- action = g_simple_action_new ("read-stdin", G_VARIANT_TYPE_HANDLE);
- g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
-
- g_signal_connect (action,
- "activate",
- G_CALLBACK (activate_read_stdin_action),
- app);
+ const GActionEntry entries[] = {
+ { "new-window", activate_new_window_action },
+ { "new-document", activate_new_document_action },
+ { "set-encoding", activate_set_encoding_action, "s" },
+ { "set-geometry", activate_set_geometry_action, "s" },
+ { "set-document-positions", activate_set_document_positions_action, "(ii)" },
+ { "open-files", activate_open_files_action, "as" },
+ { "read-stdin", activate_read_stdin_action, "h" },
+ };
+
+ g_action_map_add_action_entries (G_ACTION_MAP (app),
+ entries,
+ G_N_ELEMENTS (entries),
+ app);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]