*** empty log message ***
[anjuta-git-plugin.git] / src / anjuta.c
blob027abeb61a392a7b466a2d6efcbb3fe0b597d1a7
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta.c
4 * Copyright (C) 2000 Naba Kumar <naba@gnome.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <libanjuta/anjuta-shell.h>
22 #include <libanjuta/anjuta-debug.h>
23 #include <libanjuta/anjuta-utils.h>
24 #include <libanjuta/plugins.h>
25 #include <libanjuta/interfaces/ianjuta-profile.h>
27 #include "anjuta.h"
29 #define ANJUTA_SESSION_SKIP_LAST "anjuta.session.skip.last"
31 static gboolean
32 on_anjuta_delete_event (AnjutaApp *app, GdkEvent *event, gpointer data)
34 gchar *session_dir;
35 DEBUG_PRINT ("AnjutaApp delete event");
37 /* FIXME: Check for unsaved data */
39 /* Save current session as default session */
40 session_dir = g_build_filename (g_get_home_dir (), ".anjuta",
41 "session", NULL);
42 anjuta_shell_session_save (ANJUTA_SHELL (app), session_dir, NULL);
43 g_free (session_dir);
45 /* Shutdown */
46 if (g_object_get_data (G_OBJECT (app), "__proper_shutdown"))
48 gtk_widget_hide (GTK_WIDGET (app));
49 anjuta_plugins_unload_all (ANJUTA_SHELL (app));
51 return FALSE;
54 static void
55 on_anjuta_destroy (GtkWidget * w, gpointer data)
57 DEBUG_PRINT ("AnjutaApp destroy event");
59 gtk_widget_hide (w);
60 gtk_main_quit ();
63 /* Saves the current anjuta session */
64 static gint
65 on_anjuta_session_save_yourself (GnomeClient * client, gint phase,
66 GnomeSaveStyle s_style, gint shutdown,
67 GnomeInteractStyle i_style, gint fast,
68 gpointer app)
70 gchar *argv[] = { "rm", "-rf", NULL};
71 const gchar *prefix;
73 DEBUG_PRINT ("Going to save session ...");
75 prefix = gnome_client_get_config_prefix (client);
76 argv[2] = gnome_config_get_real_path (prefix);
77 gnome_client_set_discard_command (client, 3, argv);
79 argv[0] = "anjuta";
80 gnome_client_set_restart_command(client, 1, argv);
81 gnome_client_set_restart_style (client, GNOME_RESTART_IF_RUNNING);
84 * We want to be somewhere at last to start, otherwise bonobo-activation
85 * and gnome-vfs gets screwed up at start up
87 gnome_client_set_priority (client, 80);
89 /* Save current session */
90 anjuta_shell_session_save (ANJUTA_SHELL (app), argv[2], NULL);
91 g_free (argv[2]);
93 return TRUE;
96 static gint
97 on_anjuta_session_die (GnomeClient * client, gpointer data)
99 gtk_main_quit();
100 return FALSE;
103 AnjutaApp*
104 anjuta_new (gchar *prog_name, GList *prog_args, gboolean no_splash,
105 const gchar *im_file,
106 gboolean proper_shutdown, const gchar *geometry)
108 gchar *session_dir;
109 AnjutaApp *app;
110 AnjutaStatus *status;
111 GnomeClient *client;
112 GnomeClientFlags flags;
113 IAnjutaProfile *profile;
115 /* Initialize application */
116 app = ANJUTA_APP (anjuta_app_new ());
117 status = anjuta_shell_get_status (ANJUTA_SHELL (app), NULL);
118 anjuta_status_progress_add_ticks (status, 1);
120 if (im_file)
121 anjuta_status_progress_set_splash (status, im_file, 100);
122 if (no_splash)
123 anjuta_status_progress_disable_splash (status, no_splash);
125 if (proper_shutdown)
127 g_object_set_data (G_OBJECT (app), "__proper_shutdown", "1");
129 g_signal_connect (G_OBJECT (app), "delete_event",
130 G_CALLBACK (on_anjuta_delete_event), NULL);
131 g_signal_connect (G_OBJECT (app), "destroy",
132 G_CALLBACK (on_anjuta_destroy), NULL);
134 /* Load plugins */
135 profile = anjuta_shell_get_interface (ANJUTA_SHELL(app),
136 IAnjutaProfile, NULL);
137 if (!profile)
139 g_warning ("No profile could be loaded");
140 exit(1);
142 ianjuta_profile_load (profile, NULL);
144 /* Session management */
145 client = gnome_master_client();
146 gtk_signal_connect(GTK_OBJECT(client), "save_yourself",
147 GTK_SIGNAL_FUNC(on_anjuta_session_save_yourself),
148 app);
149 gtk_signal_connect(GTK_OBJECT(client), "die",
150 GTK_SIGNAL_FUNC(on_anjuta_session_die), app);
152 flags = gnome_client_get_flags(client);
154 if (flags & GNOME_CLIENT_RESTORED)
156 /* Load the last session */
157 const gchar *prefix;
158 prefix = gnome_client_get_config_prefix (client);
159 session_dir = gnome_config_get_real_path (prefix);
161 else if (prog_args || geometry)
163 AnjutaSession *session;
165 /* Reset default session */
166 session_dir = g_build_filename (g_get_home_dir (), ".anjuta",
167 "session", NULL);
168 session = anjuta_session_new (session_dir);
169 anjuta_session_clear (session);
170 if (geometry)
171 anjuta_session_set_string (session, "Anjuta", "Geometry",
172 geometry);
173 if (prog_args)
174 anjuta_session_set_string_list (session, "File Loader", "Files",
175 prog_args);
177 else
179 AnjutaSession *session;
181 /* Load default session */
182 session_dir = g_build_filename (g_get_home_dir (), ".anjuta",
183 "session", NULL);
184 /* If preferences is not set to load last session, clear it */
185 if (anjuta_preferences_get_int (app->preferences,
186 ANJUTA_SESSION_SKIP_LAST))
188 /* Reset default session */
189 session_dir = g_build_filename (g_get_home_dir (), ".anjuta",
190 "session", NULL);
191 session = anjuta_session_new (session_dir);
192 anjuta_session_clear (session);
196 /* Restore session */
197 anjuta_shell_session_load (ANJUTA_SHELL (app), session_dir, NULL);
198 g_free (session_dir);
199 anjuta_status_progress_tick (status, NULL, _("Loaded Session ..."));
200 return app;