[anjuta] anjuta: Allow to abort loading of a session
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] anjuta: Allow to abort loading of a session
- Date: Sat, 10 Nov 2012 10:07:32 +0000 (UTC)
commit f757bd46336556558e9b6898f69392a2939f1410
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Thu Nov 1 09:39:29 2012 +0100
anjuta: Allow to abort loading of a session
This is useful to make the code loading files more general. The old code
was checking which file is a project file because such file triggers the
loading of a new session. In case there was a project session only the project
session was loaded.
The new code load all files in the same way. But if a project file is loaded
it aborts the current session and the project session is loaded instead.
libanjuta/anjuta-shell.c | 73 +++++++++++++++++++++-------
plugins/file-loader/plugin.c | 19 +++----
src/anjuta-application.c | 108 ++----------------------------------------
3 files changed, 68 insertions(+), 132 deletions(-)
---
diff --git a/libanjuta/anjuta-shell.c b/libanjuta/anjuta-shell.c
index 4fc5187..4cf287d 100644
--- a/libanjuta/anjuta-shell.c
+++ b/libanjuta/anjuta-shell.c
@@ -913,31 +913,68 @@ anjuta_shell_session_load (AnjutaShell *shell, const gchar *session_directory,
GError **error)
{
AnjutaSession *session;
-
+ AnjutaSession *child;
+
g_return_if_fail (ANJUTA_IS_SHELL (shell));
g_return_if_fail (session_directory != NULL);
+
+ /* It is possible that loading a session triggers the load on another
+ * session. It happens when restoring an user session includes a project.
+ * The project session is loaded while the user session is still loading. */
+ session = anjuta_session_new (session_directory);
- /* Do not allow multiple session loadings at once. Could be a trouble */
- if (g_object_get_data (G_OBJECT (shell), "__session_loading"))
+ child = g_object_get_data (G_OBJECT (shell), "__session_loading");
+ g_object_set_data (G_OBJECT (shell), "__session_loading", session);
+ if (child != NULL)
{
- /* DEBUG_PRINT ("%s", "A session load is requested in the middle of another!!"); */
+ /* There is already a session loading.
+ * Replace it with our own session. The previous session will be
+ * aborted and our session will be loaded afterward. */
+ g_object_unref (G_OBJECT (child));
+
return;
}
- g_object_set_data (G_OBJECT (shell), "__session_loading", "1");
-
- session = anjuta_session_new (session_directory);
- g_signal_emit_by_name (G_OBJECT (shell), "load_session",
- ANJUTA_SESSION_PHASE_START, session);
- g_signal_emit_by_name (G_OBJECT (shell), "load_session",
- ANJUTA_SESSION_PHASE_FIRST, session);
- g_signal_emit_by_name (G_OBJECT (shell), "load_session",
- ANJUTA_SESSION_PHASE_NORMAL, session);
- g_signal_emit_by_name (G_OBJECT (shell), "load_session",
- ANJUTA_SESSION_PHASE_LAST, session);
- g_signal_emit_by_name (G_OBJECT (shell), "load_session",
- ANJUTA_SESSION_PHASE_END, session);
- g_object_unref (session);
+ /* This is the top session. This code emits all signals and check after
+ * each phase that the session is still the same. If it is not the case
+ * the session is aborted and the new session is loaded. */
+ for (;;)
+ {
+ if (child != NULL)
+ {
+ /* Abort previous session */
+ g_signal_emit_by_name (G_OBJECT (shell), "load_session",
+ ANJUTA_SESSION_PHASE_END, session);
+ g_object_unref (session);
+ /* Reread session in case PHASE_END has triggered another session */
+ session = g_object_get_data (G_OBJECT (shell), "__session_loading");
+ }
+ g_object_ref (session);
+
+ g_signal_emit_by_name (G_OBJECT (shell), "load_session",
+ ANJUTA_SESSION_PHASE_START, session);
+ child = g_object_get_data (G_OBJECT (shell), "__session_loading");
+ if (child != session) continue;
+ g_signal_emit_by_name (G_OBJECT (shell), "load_session",
+ ANJUTA_SESSION_PHASE_FIRST, session);
+ child = g_object_get_data (G_OBJECT (shell), "__session_loading");
+ if (child != session) continue;
+ g_signal_emit_by_name (G_OBJECT (shell), "load_session",
+ ANJUTA_SESSION_PHASE_NORMAL, session);
+ child = g_object_get_data (G_OBJECT (shell), "__session_loading");
+ if (child != session) continue;
+ g_signal_emit_by_name (G_OBJECT (shell), "load_session",
+ ANJUTA_SESSION_PHASE_LAST, session);
+ child = g_object_get_data (G_OBJECT (shell), "__session_loading");
+ if (child != session) continue;
+ g_signal_emit_by_name (G_OBJECT (shell), "load_session",
+ ANJUTA_SESSION_PHASE_END, session);
+ child = g_object_get_data (G_OBJECT (shell), "__session_loading");
+ g_object_unref (session);
+ if (child == session) break;
+ session = child;
+ child = NULL;
+ }
g_object_set_data (G_OBJECT (shell), "__session_loading", NULL);
}
diff --git a/plugins/file-loader/plugin.c b/plugins/file-loader/plugin.c
index 4a2a9d2..8374554 100644
--- a/plugins/file-loader/plugin.c
+++ b/plugins/file-loader/plugin.c
@@ -1172,21 +1172,18 @@ on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase,
if (uri)
{
- if (!anjuta_util_is_project_file (uri))
- {
- gchar *fragment = NULL;
- GFile* file = anjuta_session_get_file_from_relative_uri (session, uri, &fragment);
- GObject *loader = ianjuta_file_loader_load (IANJUTA_FILE_LOADER (plugin),
+ gchar *fragment = NULL;
+ GFile* file = anjuta_session_get_file_from_relative_uri (session, uri, &fragment);
+ GObject *loader = ianjuta_file_loader_load (IANJUTA_FILE_LOADER (plugin),
file, FALSE, NULL);
- if (fragment != NULL)
+ if (fragment != NULL)
+ {
+ if (IANJUTA_IS_DOCUMENT_MANAGER (loader))
{
- if (IANJUTA_IS_DOCUMENT_MANAGER (loader))
- {
- ianjuta_document_manager_goto_file_line (IANJUTA_DOCUMENT_MANAGER (loader), file, atoi(fragment), NULL);
- }
+ ianjuta_document_manager_goto_file_line (IANJUTA_DOCUMENT_MANAGER (loader), file, atoi(fragment), NULL);
}
- g_object_unref (file);
}
+ g_object_unref (file);
}
g_free (uri);
}
diff --git a/src/anjuta-application.c b/src/anjuta-application.c
index bb7b029..f562c3e 100644
--- a/src/anjuta-application.c
+++ b/src/anjuta-application.c
@@ -211,41 +211,6 @@ on_profile_descoped (AnjutaProfileManager *profile_manager,
g_free (session_dir);
}
-/* This extracts the project URI saved in the session so that it could be
- * loaded sequencially. Returned string must be freed.
- */
-static GFile*
-extract_project_from_session (const gchar* session_dir)
-{
- AnjutaSession *session;
- GList *node, *files;
- GFile *project = NULL;
-
- session = anjuta_session_new (session_dir);
-
- files = anjuta_session_get_string_list (session, "File Loader", "Files");
-
- /* Find project file */
- node = files;
- for (node = files; node != NULL; node = g_list_next (node))
- {
- gchar *uri = node->data;
- if (uri)
- {
- if (anjuta_util_is_project_file (uri))
- {
- if (project != NULL) g_object_unref (project);
- project = anjuta_session_get_file_from_relative_uri (session, uri, NULL);
- }
- g_free (uri);
- }
- }
- g_list_free (files);
- g_object_unref (session);
-
- return project;
-}
-
static AnjutaWindow*
anjuta_application_create_window (AnjutaApplication *app,
GFile **files, int n_files, gboolean no_splash,
@@ -259,8 +224,6 @@ anjuta_application_create_window (AnjutaApplication *app,
AnjutaProfile *profile;
GFile *session_profile;
gchar *remembered_plugins;
- GFile *project = NULL;
- GFile *template = NULL;
gchar *profile_name = NULL;
gchar *im_file = NULL;
GError *error = NULL;
@@ -355,9 +318,6 @@ anjuta_application_create_window (AnjutaApplication *app,
/* Reset default session */
session_dir = USER_SESSION_PATH_NEW;
- project = extract_project_from_session (session_dir);
- template = NULL;
-
session = anjuta_session_new (session_dir);
anjuta_session_clear (session);
if (geometry)
@@ -370,21 +330,7 @@ anjuta_application_create_window (AnjutaApplication *app,
gchar* file = g_file_get_path (files[i]);
if (!file)
continue;
- if (anjuta_util_is_project_file (file))
- {
- /* Pick up the first project file for loading later */
- project = files[i];
- g_object_ref (project);
- }
- else if (anjuta_util_is_template_file (file))
- {
- template = files[i];
- g_object_ref (template);
- }
- else
- {
- files_load = g_list_prepend (files_load, g_file_get_uri (files[i]));
- }
+ files_load = g_list_prepend (files_load, g_file_get_uri (files[i]));
}
if (files_load)
{
@@ -426,26 +372,12 @@ anjuta_application_create_window (AnjutaApplication *app,
anjuta_session_sync (session);
g_object_unref (session);
}
- /* Otherwise, load session normally */
- else
- {
- project = extract_project_from_session (session_dir);
- }
g_free (session_dir);
}
/* Prepare for session save and load on profile change */
g_signal_connect (profile_manager, "profile-scoped",
G_CALLBACK (on_profile_scoped), win);
- /* Load project file */
- if ((project != NULL) && (template == NULL))
- {
- IAnjutaFileLoader *loader;
- loader = anjuta_shell_get_interface (ANJUTA_SHELL (win),
- IAnjutaFileLoader, NULL);
- ianjuta_file_loader_load (loader, project, FALSE, NULL);
- g_object_unref (project);
- }
anjuta_profile_manager_thaw (profile_manager, &error);
if (error)
@@ -460,16 +392,6 @@ anjuta_application_create_window (AnjutaApplication *app,
anjuta_status_progress_tick (status, NULL, _("Loaded Sessionâ"));
anjuta_status_disable_splash (status, TRUE);
- /* Load template file */
- if (template != NULL)
- {
- IAnjutaFileLoader *loader;
- loader = anjuta_shell_get_interface (ANJUTA_SHELL (win),
- IAnjutaFileLoader, NULL);
- ianjuta_file_loader_load (loader, template, FALSE, NULL);
- g_object_unref (template);
- }
-
return win;
}
@@ -596,7 +518,7 @@ anjuta_application_local_command_line (GApplication *application,
files[n_files++] = file;
}
}
-
+
if (no_client) g_application_set_flags (application, G_APPLICATION_NON_UNIQUE);
g_application_register (G_APPLICATION (application), NULL, NULL);
@@ -616,11 +538,11 @@ anjuta_application_local_command_line (GApplication *application,
anjuta_geometry);
gtk_window_set_application (GTK_WINDOW (win), GTK_APPLICATION (application));
gtk_widget_show (GTK_WIDGET (win));
-
+
free_files (files, n_files);
}
-
+
g_option_context_free (context);
return TRUE;
@@ -640,27 +562,7 @@ anjuta_application_open (GApplication *application,
if (!loader)
return;
-
- /* Identify non-project files and set them for loading in session */
- for (i = 0; i < n_files; i++)
- {
- gchar* file = g_file_get_path (files[i]);
- if (!file)
- continue;
- if (anjuta_util_is_project_file (file))
- {
- AnjutaWindow* new_win = anjuta_application_create_window (ANJUTA_APPLICATION (application),
- files, n_files,
- TRUE, TRUE, FALSE, NULL);
- gtk_application_add_window (GTK_APPLICATION (application),
- GTK_WINDOW (new_win));
- gtk_widget_show (GTK_WIDGET (new_win));
- g_free (file);
- return;
- }
- g_free (file);
- }
-
+
for (i = 0; i < n_files; i++)
{
ianjuta_file_loader_load(loader, files[i], FALSE, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]