[gedit/wip/gtkapp: 183/197] More crazy stuff to handle the command line
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/gtkapp: 183/197] More crazy stuff to handle the command line
- Date: Mon, 5 Nov 2012 15:29:38 +0000 (UTC)
commit 59ab2e13df7db378a77c3fc74745bd603682aa03
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue Jul 31 15:22:58 2012 +0200
More crazy stuff to handle the command line
gedit/gedit-app.c | 227 +++++++++++++++++++++++++++++------------------------
1 files changed, 124 insertions(+), 103 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index c5ec757..ef9c90b 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -105,6 +105,7 @@ static gboolean wait = FALSE;
static gboolean background = FALSE;
static gboolean standalone = FALSE;
static gchar **remaining_args = NULL;
+static const GeditEncoding *encoding = NULL;
static const GOptionEntry options[] =
{
@@ -199,6 +200,10 @@ 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);
}
@@ -365,21 +370,6 @@ gedit_app_startup (GApplication *application)
}
static void
-gedit_app_activate (GApplication *application)
-{
- GeditWindow *window;
-
- gedit_debug_message (DEBUG_APP, "Create main window");
- window = gedit_app_create_window (GEDIT_APP (application), NULL);
- gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (window));
-
- gedit_debug_message (DEBUG_APP, "Show window");
- gtk_widget_show (GTK_WIDGET (window));
-
- g_message ("activate");
-}
-
-static void
get_line_column_position (const gchar *arg,
gint *line,
gint *column)
@@ -404,6 +394,93 @@ get_line_column_position (const gchar *arg,
g_strfreev (split);
}
+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)
+ {
+ 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 (!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)
@@ -415,6 +492,24 @@ gedit_app_command_line (GApplication *application,
gint argc;
gint i;
+ /* reset values */
+ g_free (encoding_charset);
+ g_strfreev (remaining_args);
+ g_free (geometry);
+
+ help = FALSE;
+ 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;
+
args = g_application_command_line_get_arguments (command_line, &argc);
/* We have to make an extra copy of the array, since g_option_context_parse()
@@ -447,44 +542,6 @@ gedit_app_command_line (GApplication *application,
}
else
{
- GSList *file_list = NULL;
- gint line_position = 0;
- gint column_position = 0;
- const GeditEncoding *encoding = NULL;
- GeditWindow *window;
- gboolean doc_created = FALSE;
-
- if (remaining_args)
- {
- 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);
- }
-
/* Parse encoding */
if (encoding_charset)
{
@@ -500,59 +557,10 @@ gedit_app_command_line (GApplication *application,
g_free (encoding_charset);
}
- gedit_debug_message (DEBUG_APP, "Create main window");
- window = gedit_app_create_window (GEDIT_APP (application), NULL);
-
- gedit_debug_message (DEBUG_APP, "Show window");
- gtk_widget_show (GTK_WIDGET (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 (!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);
+ gedit_app_activate (application);
}
g_option_context_free (context);
- g_free (encoding_charset);
- g_strfreev (remaining_args);
- g_free (geometry);
-
- /* reset values for the next call */
- help = FALSE;
- 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;
return 0;
}
@@ -630,6 +638,19 @@ gedit_app_local_command_line (GApplication *application,
g_strfreev (remaining_args);
g_free (geometry);
+ help = FALSE;
+ 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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]