[gedit/wip/gtkapp-actions: 2/10] GeditApp: remove command line options handling
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/gtkapp-actions: 2/10] GeditApp: remove command line options handling
- Date: Fri, 3 Aug 2012 08:04:21 +0000 (UTC)
commit e386ecd6af1740c3be741dab32f0f37dc9e53963
Author: SÃbastien Wilmet <swilmet gnome org>
Date: Fri Aug 3 07:21:19 2012 +0200
GeditApp: remove command line options handling
gedit/gedit-app.c | 368 -----------------------------------------------------
1 files changed, 0 insertions(+), 368 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 6b6516e..4326805 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -103,110 +103,11 @@ struct _GeditAppPrivate
static GeditApp *app_instance = NULL;
-static gboolean version = FALSE;
-static gboolean list_encodings = FALSE;
-static gchar *encoding_charset = NULL;
-static gboolean new_window = FALSE;
-static gboolean new_document = FALSE;
-static gchar *geometry = NULL;
-static gboolean wait = FALSE;
-static gboolean background = FALSE;
-static gboolean standalone = FALSE;
-static gchar **remaining_args = NULL;
-static const GeditEncoding *encoding = NULL;
-static GInputStream *stdin_stream = NULL;
-
-static const GOptionEntry options[] =
-{
- /* Version */
- {
- "version", 'V', 0, G_OPTION_ARG_NONE, &version,
- N_("Show the application's version"), NULL
- },
-
- /* List available encodings */
- {
- "list-encodings", '\0', 0, G_OPTION_ARG_NONE, &list_encodings,
- N_("Display list of possible values for the encoding option"),
- NULL
- },
-
- /* Encoding */
- {
- "encoding", '\0', 0, G_OPTION_ARG_STRING,
- &encoding_charset,
- N_("Set the character encoding to be used to open the files listed on the command line"),
- N_("ENCODING")
- },
-
- /* Open a new window */
- {
- "new-window", '\0', 0, G_OPTION_ARG_NONE,
- &new_window,
- N_("Create a new top-level window in an existing instance of gedit"),
- NULL
- },
-
- /* Create a new empty document */
- {
- "new-document", '\0', 0, G_OPTION_ARG_NONE,
- &new_document,
- N_("Create a new document in an existing instance of gedit"),
- NULL
- },
-
- /* Window geometry */
- {
- "geometry", 'g', 0, G_OPTION_ARG_STRING,
- &geometry,
- N_("Set the size and position of the window (WIDTHxHEIGHT+X+Y)"),
- N_("GEOMETRY")
- },
-
- /* Wait for closing documents */
- {
- "wait", 'w', 0, G_OPTION_ARG_NONE,
- &wait,
- N_("Open files and block process until files are closed"),
- NULL
- },
-
- /* Run in the background */
- {
- "background", 'b', 0, G_OPTION_ARG_NONE,
- &background,
- N_("Run gedit in the background"),
- NULL
- },
-
- /* New instance */
- {
- "standalone", 's', 0, G_OPTION_ARG_NONE,
- &standalone,
- N_("Run gedit in standalone mode"),
- NULL
- },
-
- /* collects file arguments */
- {
- G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY,
- &remaining_args,
- NULL,
- N_("[FILE...] [+LINE[:COLUMN]]")
- },
-
- {NULL}
-};
-
G_DEFINE_ABSTRACT_TYPE(GeditApp, gedit_app, GTK_TYPE_APPLICATION)
static void
gedit_app_finalize (GObject *object)
{
- g_free (encoding_charset);
- g_strfreev (remaining_args);
- g_free (geometry);
-
G_OBJECT_CLASS (gedit_app_parent_class)->finalize (object);
}
@@ -482,273 +383,7 @@ static void
gedit_app_activate (GApplication *application)
{
GeditApp *app = GEDIT_APP (application);
- GSList *file_list = NULL;
- gint line_position = 0;
- gint column_position = 0;
- GeditWindow *window;
- gboolean doc_created = FALSE;
-
- /* XXX: have it global and move this to the command line parsing? */
- if (remaining_args)
- {
- gint i;
-
- for (i = 0; remaining_args[i]; i++)
- {
- if (*remaining_args[i] == '+')
- {
- if (*(remaining_args[i] + 1) == '\0')
- {
- /* goto the last line of the document */
- line_position = G_MAXINT;
- column_position = 0;
- }
- else
- {
- get_line_column_position (remaining_args[i] + 1,
- &line_position,
- &column_position);
- }
- }
- else
- {
- GFile *file;
-
- file = g_file_new_for_commandline_arg (remaining_args[i]);
- file_list = g_slist_prepend (file_list, file);
- }
- }
-
- file_list = g_slist_reverse (file_list);
- }
-
- if (app->priv->active_window == NULL || new_window)
- {
- gedit_debug_message (DEBUG_APP, "Create main window");
- window = gedit_app_create_window (app, NULL);
-
- gedit_debug_message (DEBUG_APP, "Show window");
- gtk_widget_show (GTK_WIDGET (window));
- }
- else
- {
- window = app->priv->active_window;
- }
-
- if (geometry)
- {
- gtk_window_parse_geometry (GTK_WINDOW (window),
- geometry);
- }
-
- if (file_list != NULL)
- {
- GSList *loaded;
-
- gedit_debug_message (DEBUG_APP, "Load files");
- loaded = _gedit_cmd_load_files_from_prompt (window,
- file_list,
- encoding,
- line_position,
- column_position);
-
- doc_created = loaded != NULL;
- g_slist_free (loaded);
- }
-
- if (stdin_stream)
- {
- doc_created = gedit_window_create_tab_from_stream (window,
- stdin_stream,
- encoding,
- line_position,
- column_position,
- TRUE) != NULL;
- }
-
- if (!doc_created || new_document)
- {
- gedit_debug_message (DEBUG_APP, "Create tab");
- gedit_window_create_tab (window, TRUE);
- }
-
- g_slist_free_full (file_list, g_object_unref);
-}
-
-static gint
-gedit_app_command_line (GApplication *application,
- GApplicationCommandLine *command_line)
-{
- GOptionContext *context;
- GError *error = NULL;
- gint argc;
- gchar **argv;
- gchar **argv_tofree;
-
- /* reset values */
- g_free (encoding_charset);
- g_strfreev (remaining_args);
- g_free (geometry);
-
- version = FALSE;
- list_encodings = FALSE;
- encoding_charset = NULL;
- new_window = FALSE;
- new_document = FALSE;
- geometry = NULL;
- wait = FALSE;
- background = FALSE;
- standalone = FALSE;
- remaining_args = NULL;
- encoding = NULL;
-
- argv = g_application_command_line_get_arguments (command_line, &argc);
-
- gint i;
-
- /* We have to make an extra copy of the array, since g_option_context_parse()
- * assumes that it can remove strings from the array without freeing them.
- */
- argv_tofree = g_new (gchar*, argc + 1);
- for (i = 0; i <= argc; i++)
- {
- argv[i] = argv[i];
- }
-
- /* Setup command line options */
- context = g_option_context_new (_("- Edit text files"));
- g_option_context_set_help_enabled (context, FALSE);
- g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
- g_option_context_add_group (context, gtk_get_option_group (TRUE));
-
-#ifdef ENABLE_INTROSPECTION
- g_option_context_add_group (context, g_irepository_get_option_group ());
-#endif
-
- if (!g_option_context_parse (context, &argc, &argv, &error))
- {
- g_application_command_line_print (command_line,
- _("%s\nRun '%s --help' to see a full list of available command line options.\n"),
- error->message, argv[0]);
-
- g_error_free (error);
- g_application_command_line_set_exit_status (command_line, 1);
- }
- else
- {
- /* Parse encoding */
- if (encoding_charset)
- {
- encoding = gedit_encoding_get_from_charset (encoding_charset);
-
- if (encoding == NULL)
- {
- g_application_command_line_print (command_line,
- _("%s: invalid encoding."),
- encoding_charset);
- }
-
- g_free (encoding_charset);
- }
-
- stdin_stream = g_application_command_line_get_stdin (command_line);
-
- gedit_app_activate (application);
- }
-
- g_option_context_free (context);
- g_free (argv_tofree);
-
- return 0;
-}
-
-static gboolean
-gedit_app_local_command_line (GApplication *application,
- gchar ***arguments,
- gint *exit_status)
-{
- GOptionContext *context;
- GError *error = NULL;
- gint argc;
- gchar **argv;
- gint i;
-
- /* We have to make an extra copy of the array, since g_option_context_parse()
- * assumes that it can remove strings from the array without freeing them.
- */
- argc = g_strv_length (*arguments);
- argv = g_new (gchar*, argc + 1);
- for (i = 0; i <= argc; i++)
- {
- argv[i] = (*arguments)[i];
- }
-
- *exit_status = 0;
-
- /* Setup command line options */
- context = g_option_context_new (_("- Edit text files"));
- g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
- g_option_context_add_group (context, gtk_get_option_group (TRUE));
-
-#ifdef ENABLE_INTROSPECTION
- g_option_context_add_group (context, g_irepository_get_option_group ());
-#endif
-
- if (!g_option_context_parse (context, &argc, &argv, &error))
- {
- g_error (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
- error->message, argv[0]);
-
- g_error_free (error);
- *exit_status = 1;
- }
- else if (version)
- {
- g_print ("%s - Version %s\n", g_get_application_name (), VERSION);
-
- return TRUE;
- }
- else if (list_encodings)
- {
- gint i = 0;
- const GeditEncoding *enc;
-
- while ((enc = gedit_encoding_get_from_index (i)) != NULL)
- {
- g_print ("%s\n", gedit_encoding_get_charset (enc));
-
- ++i;
- }
-
- return TRUE;
- }
- else if (standalone)
- {
- GApplicationFlags old_flags;
-
- old_flags = g_application_get_flags (application);
- g_application_set_flags (application, old_flags | G_APPLICATION_NON_UNIQUE);
- }
- g_option_context_free (context);
- g_free (encoding_charset);
- g_strfreev (remaining_args);
- g_free (geometry);
- g_free (argv);
-
- version = FALSE;
- list_encodings = FALSE;
- encoding_charset = NULL;
- new_window = FALSE;
- new_document = FALSE;
- geometry = NULL;
- wait = FALSE;
- background = FALSE;
- standalone = FALSE;
- remaining_args = NULL;
- encoding = NULL;
-
- return G_APPLICATION_CLASS (gedit_app_parent_class)->local_command_line (application, arguments, exit_status);
}
static gboolean
@@ -1057,8 +692,6 @@ gedit_app_class_init (GeditAppClass *klass)
app_class->startup = gedit_app_startup;
app_class->activate = gedit_app_activate;
- app_class->command_line = gedit_app_command_line;
- app_class->local_command_line = gedit_app_local_command_line;
app_class->shutdown = gedit_app_shutdown;
klass->last_window_destroyed = gedit_app_last_window_destroyed_impl;
@@ -1187,7 +820,6 @@ gedit_app_get_default (void)
return GEDIT_APP (g_object_new (type,
"application-id", "org.gnome.Gedit",
- "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
NULL));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]