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 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)
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
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>
29 #define ANJUTA_SESSION_SKIP_LAST "anjuta.session.skip.last"
32 on_anjuta_delete_event (AnjutaApp
*app
, GdkEvent
*event
, gpointer data
)
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",
42 anjuta_shell_session_save (ANJUTA_SHELL (app
), session_dir
, NULL
);
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
));
55 on_anjuta_destroy (GtkWidget
* w
, gpointer data
)
57 DEBUG_PRINT ("AnjutaApp destroy event");
63 /* Saves the current anjuta session */
65 on_anjuta_session_save_yourself (GnomeClient
* client
, gint phase
,
66 GnomeSaveStyle s_style
, gint shutdown
,
67 GnomeInteractStyle i_style
, gint fast
,
70 gchar
*argv
[] = { "rm", "-rf", NULL
};
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
);
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
);
97 on_anjuta_session_die (GnomeClient
* client
, gpointer data
)
104 anjuta_new (gchar
*prog_name
, GList
*prog_args
, gboolean no_splash
,
105 const gchar
*im_file
,
106 gboolean proper_shutdown
, const gchar
*geometry
)
110 AnjutaStatus
*status
;
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);
121 anjuta_status_progress_set_splash (status
, im_file
, 100);
123 anjuta_status_progress_disable_splash (status
, no_splash
);
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
);
135 profile
= anjuta_shell_get_interface (ANJUTA_SHELL(app
),
136 IAnjutaProfile
, NULL
);
139 g_warning ("No profile could be loaded");
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
),
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 */
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",
168 session
= anjuta_session_new (session_dir
);
169 anjuta_session_clear (session
);
171 anjuta_session_set_string (session
, "Anjuta", "Geometry",
174 anjuta_session_set_string_list (session
, "File Loader", "Files",
179 AnjutaSession
*session
;
181 /* Load default session */
182 session_dir
= g_build_filename (g_get_home_dir (), ".anjuta",
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",
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 ..."));