1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2000 Naba Kumar <naba@gnome.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <libanjuta/anjuta-debug.h>
34 #include <libxml/parser.h>
42 /* Command line options */
43 static gboolean no_splash
= 0;
44 static gboolean no_client
= 0;
45 static gboolean no_session
= 0;
46 static gboolean no_files
= 0;
47 static gboolean proper_shutdown
= 0;
48 static gchar
*anjuta_geometry
= NULL
;
49 static gchar
**anjuta_filenames
= NULL
;
52 show_version_cb (const char *option_name
,
57 g_print ("%s\n", PACKAGE_STRING
);
63 static const GOptionEntry anjuta_options
[] = {
65 "geometry", 'g', 0, G_OPTION_ARG_STRING
,
67 N_("Specify the size and location of the main window"),
68 /* This is the format you can specify the size andposition
69 * of the window on command line */
70 N_("WIDTHxHEIGHT+XOFF+YOFF")
73 "no-splash", 's', 0, G_OPTION_ARG_NONE
,
75 N_("Do not show the splash screen"),
79 "no-client", 'c', 0, G_OPTION_ARG_NONE
,
81 N_("Start a new instance and do not open the file in an existing instance"),
85 "no-session", 'n', 0, G_OPTION_ARG_NONE
,
87 N_("Do not open last session on startup"),
91 "no-files", 'f', 0, G_OPTION_ARG_NONE
,
93 N_("Do not open last project and files on startup"),
97 "proper-shutdown", 'p', 0, G_OPTION_ARG_NONE
,
99 N_("Shut down Anjuta properly, releasing all resources (for debugging)"),
103 "version", 'v', G_OPTION_FLAG_NO_ARG
, G_OPTION_ARG_CALLBACK
,
105 ("Display program version"),
109 G_OPTION_REMAINING
, 0, 0, G_OPTION_ARG_FILENAME_ARRAY
,
118 free_files (GFile
** files
, gint n_files
)
121 for (i
= 0; i
< n_files
; i
++)
123 g_object_unref (files
[i
]);
129 main (int argc
, char *argv
[])
131 GOptionContext
*context
;
132 GError
* error
= NULL
;
134 GFile
** files
= NULL
;
138 context
= g_option_context_new (_("- Integrated Development Environment"));
140 setlocale (LC_ALL
, "");
141 bindtextdomain (GETTEXT_PACKAGE
, PACKAGE_LOCALE_DIR
);
142 bind_textdomain_codeset(GETTEXT_PACKAGE
, "UTF-8");
143 textdomain (GETTEXT_PACKAGE
);
144 g_option_context_add_main_entries (context
, anjuta_options
, GETTEXT_PACKAGE
);
146 g_option_context_add_main_entries (context
, anjuta_options
, NULL
);
149 g_option_context_add_group (context
, gtk_get_option_group (TRUE
));
151 /* Initialize gnome program */
152 if (!g_option_context_parse (context
, &argc
, &argv
, &error
))
154 g_debug ("Option parsing failed: %s", error
->message
);
159 gtk_init (&argc
, &argv
);
160 /* Initialize threads */
163 /* Init debug helpers */
164 anjuta_debug_init ();
166 /* Convert all file names to URI */
167 /* So an already existing instance of Anjuta having another current
168 * directory can still open the files */
169 if (anjuta_filenames
)
171 files
= g_new0 (GFile
*, 1);
173 for (filename
= anjuta_filenames
; *filename
!= NULL
; filename
++)
175 GFile
* file
= g_file_new_for_commandline_arg(*filename
);
176 files
= g_realloc (files
, (n_files
+ 1) * sizeof (GFile
*));
177 files
[n_files
++] = file
;
181 g_set_application_name (_("Anjuta"));
182 anjuta
= anjuta_new ();
184 if (no_client
) g_application_set_flags (G_APPLICATION (anjuta
), G_APPLICATION_NON_UNIQUE
);
186 g_application_register (G_APPLICATION (anjuta
), NULL
, NULL
);
189 if (g_application_get_is_remote (G_APPLICATION (anjuta
)))
191 if (g_application_get_is_remote (G_APPLICATION (anjuta
)) && !no_client
)
196 g_application_open (G_APPLICATION (anjuta
), files
, n_files
, "");
197 free_files (files
, n_files
);
202 AnjutaApp
*app
= create_window (files
, n_files
,
203 no_splash
, no_session
, no_files
,
204 proper_shutdown
, anjuta_geometry
);
205 gtk_window_set_application (GTK_WINDOW (app
), GTK_APPLICATION (anjuta
));
206 gtk_widget_show (GTK_WIDGET (app
));
208 free_files (files
, n_files
);
211 status
= g_application_run (G_APPLICATION (anjuta
), argc
, argv
);
212 g_object_unref (anjuta
);
214 /* xmlCleanupParser must be called only one time in the application */
215 if (proper_shutdown
) xmlCleanupParser ();