[anjuta] libanjuta: Add a function to create a new main window in the same process
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] libanjuta: Add a function to create a new main window in the same process
- Date: Sat, 10 Nov 2012 10:07:42 +0000 (UTC)
commit 4aa22b3bf694e13575ea782d1a96cd441369b11d
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Sun Nov 4 19:56:25 2012 +0100
libanjuta: Add a function to create a new main window in the same process
This is useful to have one Anjuta process with several windows following the
trend supported by GtkApplication.
The command line options -n, -f, -s, -g have been broken by this patch.
libanjuta/anjuta-shell.c | 14 ++
libanjuta/anjuta-shell.h | 4 +
plugins/project-manager/plugin.c | 13 +-
src/anjuta-application.c | 344 +++++++++++++++-----------------------
src/anjuta-application.h | 2 +
src/anjuta-window.c | 54 ++++++-
6 files changed, 215 insertions(+), 216 deletions(-)
---
diff --git a/libanjuta/anjuta-shell.c b/libanjuta/anjuta-shell.c
index 4cf287d..a4a7a55 100644
--- a/libanjuta/anjuta-shell.c
+++ b/libanjuta/anjuta-shell.c
@@ -490,6 +490,20 @@ void anjuta_shell_unmaximize (AnjutaShell *shell,
}
/**
+ * anjuta_shell_create_window:
+ * @shell: A #AnjutaShell interface
+ * @error: Error propagation object.
+ *
+ * Create a new main window in the same process.
+ */
+AnjutaShell*
+anjuta_shell_create_window (AnjutaShell *shell,
+ GError **error)
+{
+ return ANJUTA_SHELL_GET_IFACE (shell)->create_window (shell, error);
+}
+
+/**
* anjuta_shell_add_value:
* @shell: A #AnjutaShell interface
* @name: Name of the value
diff --git a/libanjuta/anjuta-shell.h b/libanjuta/anjuta-shell.h
index ad5e609..a93eb66 100644
--- a/libanjuta/anjuta-shell.h
+++ b/libanjuta/anjuta-shell.h
@@ -140,6 +140,8 @@ struct _AnjutaShellIface {
GObject* (*get_object) (AnjutaShell *shell,
const char *iface_name,
GError **error);
+ AnjutaShell * (*create_window) (AnjutaShell *shell,
+ GError **error);
};
GQuark anjuta_shell_error_quark (void);
@@ -207,6 +209,8 @@ void anjuta_shell_maximize_widget (AnjutaShell *shell,
GError **error);
void anjuta_shell_unmaximize (AnjutaShell *shell,
GError **error);
+AnjutaShell* anjuta_shell_create_window (AnjutaShell* shell,
+ GError **error);
void anjuta_shell_add_value (AnjutaShell *shell,
const char *name,
const GValue *value,
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index 058e8b0..7df33e4 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -2343,13 +2343,12 @@ ifile_open (IAnjutaFile *ifile, GFile* file, GError **e)
/* If there is already a project loaded, load in separate anjuta window */
if (plugin->project_root_uri)
{
- gchar *uri = g_file_get_uri (file);
- gchar *quoted_uri = g_shell_quote (uri);
- gchar *cmd = g_strconcat ("anjuta --no-splash --no-client ", quoted_uri, NULL);
- g_free (quoted_uri);
- anjuta_util_execute_shell (NULL, cmd);
- g_free (cmd);
- g_free (uri);
+ AnjutaShell *shell;
+ IAnjutaFileLoader* loader;
+
+ shell = anjuta_shell_create_window (ANJUTA_PLUGIN (ifile)->shell, NULL);
+ loader = anjuta_shell_get_interface(shell, IAnjutaFileLoader, NULL);
+ ianjuta_file_loader_load(loader, file, FALSE, NULL);
return;
}
diff --git a/src/anjuta-application.c b/src/anjuta-application.c
index c7c423c..f0e7c06 100644
--- a/src/anjuta-application.c
+++ b/src/anjuta-application.c
@@ -34,8 +34,6 @@
#include "anjuta-application.h"
#define ANJUTA_REMEMBERED_PLUGINS "remembered-plugins"
-#define ANJUTA_SESSION_SKIP_LAST "session-skip-last"
-#define ANJUTA_SESSION_SKIP_LAST_FILES "session-skip-last-files"
#define USER_SESSION_PATH_NEW (anjuta_util_get_user_cache_file_path ("session/", NULL))
#define DEFAULT_PROFILE "file://"PACKAGE_DATA_DIR"/profiles/default.profile"
@@ -196,191 +194,6 @@ on_profile_descoped (AnjutaProfileManager *profile_manager,
g_free (session_dir);
}
-static AnjutaWindow*
-anjuta_application_create_window (AnjutaApplication *app,
- GFile **files, int n_files, gboolean no_splash,
- gboolean no_session, gboolean no_files,
- const gchar *geometry)
-{
- AnjutaPluginManager *plugin_manager;
- AnjutaProfileManager *profile_manager;
- AnjutaWindow *win;
- AnjutaStatus *status;
- AnjutaProfile *profile;
- GFile *session_profile;
- gchar *remembered_plugins;
- gchar *profile_name = NULL;
- GError *error = NULL;
-
- /* Initialize application */
- win = ANJUTA_WINDOW (anjuta_window_new ());
- status = anjuta_shell_get_status (ANJUTA_SHELL (win), NULL);
- anjuta_status_progress_add_ticks (status, 1);
-
- gtk_window_set_role (GTK_WINDOW (win), "anjuta-app");
- gtk_window_set_auto_startup_notification(TRUE);
- gtk_window_set_default_icon_name ("anjuta");
- gtk_window_set_auto_startup_notification(FALSE);
-
- if (app->priv->no_splash)
- {
- anjuta_status_disable_splash (status, TRUE);
- }
- else
- {
- gchar *im_file = NULL;
- im_file = anjuta_res_get_pixmap_file (ANJUTA_PIXMAP_SPLASH_SCREEN);
- if (im_file)
- {
- anjuta_status_set_splash (status, im_file, 100);
- g_free (im_file);
- }
- }
-
- g_signal_connect (G_OBJECT (win), "delete_event",
- G_CALLBACK (on_anjuta_delete_event), app);
-
- /* Setup application framework */
- plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_SHELL (win),
- NULL);
- profile_manager = anjuta_shell_get_profile_manager (ANJUTA_SHELL (win),
- NULL);
-
- /* Restore remembered plugins */
- remembered_plugins =
- g_settings_get_string (win->settings, ANJUTA_REMEMBERED_PLUGINS);
- if (remembered_plugins)
- anjuta_plugin_manager_set_remembered_plugins (plugin_manager,
- remembered_plugins);
- g_free (remembered_plugins);
-
- /* Prepare profile */
- profile = anjuta_profile_new (USER_PROFILE_NAME, plugin_manager);
- session_profile = g_file_new_for_uri (DEFAULT_PROFILE);
- anjuta_profile_add_plugins_from_xml (profile, session_profile,
- TRUE, &error);
- if (error)
- {
- anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
- g_error_free (error);
- error = NULL;
- }
- g_object_unref (session_profile);
-
- /* Load user session profile */
- profile_name = g_path_get_basename (DEFAULT_PROFILE);
- session_profile = anjuta_util_get_user_cache_file (profile_name, NULL);
- if (g_file_query_exists (session_profile, NULL))
- {
- anjuta_profile_add_plugins_from_xml (profile, session_profile,
- FALSE, &error);
- if (error)
- {
- anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
- g_error_free (error);
- error = NULL;
- }
- }
- anjuta_profile_set_sync_file (profile, session_profile);
- g_object_unref (session_profile);
- g_free (profile_name);
-
- /* Load profile */
- anjuta_profile_manager_freeze (profile_manager);
- anjuta_profile_manager_push (profile_manager, profile, &error);
- if (error)
- {
- anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
- g_error_free (error);
- error = NULL;
- }
-
- if (files || geometry)
- {
- gchar *session_dir;
- AnjutaSession *session;
- gint i;
- GList *files_load = NULL;
-
- /* Reset default session */
- session_dir = USER_SESSION_PATH_NEW;
-
- session = anjuta_session_new (session_dir);
- anjuta_session_clear (session);
- if (geometry)
- anjuta_session_set_string (session, "Anjuta", "Geometry",
- geometry);
-
- /* 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;
- files_load = g_list_prepend (files_load, g_file_get_uri (files[i]));
- }
- if (files_load)
- {
- anjuta_session_set_string_list (session, "File Loader", "Files",
- files_load);
- g_list_foreach (files_load, (GFunc)g_free, NULL);
- g_list_free (files_load);
- }
- anjuta_session_sync (session);
- g_object_unref (session);
- g_free (session_dir);
- }
- else
- {
- gchar *session_dir;
- AnjutaSession *session;
-
- /* Load user session */
- session_dir = USER_SESSION_PATH_NEW;
-
- /* If preferences is set to not load last session, clear it */
- if (no_session ||
- g_settings_get_boolean (win->settings,
- ANJUTA_SESSION_SKIP_LAST))
- {
- /* Reset default session */
- session = anjuta_session_new (session_dir);
- anjuta_session_clear (session);
- g_object_unref (session);
- }
- /* If preferences is set to not load last project, clear it */
- else if (no_files ||
- g_settings_get_boolean (win->settings,
- ANJUTA_SESSION_SKIP_LAST_FILES))
- {
- session = anjuta_session_new (session_dir);
- anjuta_session_set_string_list (session, "File Loader",
- "Files", NULL);
- anjuta_session_sync (session);
- g_object_unref (session);
- }
- 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);
- anjuta_profile_manager_thaw (profile_manager, &error);
-
- if (error)
- {
- anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
- g_error_free (error);
- error = NULL;
- }
- g_signal_connect (profile_manager, "profile-descoped",
- G_CALLBACK (on_profile_descoped), win);
-
- anjuta_status_progress_tick (status, NULL, _("Loaded Sessionâ"));
- anjuta_status_disable_splash (status, TRUE);
-
- return win;
-}
/* GApplication implementation
@@ -508,22 +321,7 @@ anjuta_application_local_command_line (GApplication *application,
}
}
- if (g_application_get_is_remote (application))
- {
- if (files)
- {
- g_application_open (application, (GFile **)files->pdata, files->len, "");
- }
- }
- else
- {
- AnjutaWindow *win = anjuta_application_create_window (ANJUTA_APPLICATION (application),
- (GFile **)files->pdata, files->len,
- no_splash, no_session, no_files,
- geometry);
- gtk_window_set_application (GTK_WINDOW (win), GTK_APPLICATION (application));
- gtk_widget_show (GTK_WIDGET (win));
- }
+ g_application_open (application, (GFile **)files->pdata, files->len, NULL);
g_ptr_array_foreach (files, (GFunc)g_object_unref, NULL);
g_ptr_array_free (files, TRUE);
@@ -536,12 +334,25 @@ anjuta_application_open (GApplication *application,
gint n_files,
const gchar* hint)
{
- int i;
- GList* windows = gtk_application_get_windows (GTK_APPLICATION (application));
- AnjutaWindow *win = ANJUTA_WINDOW (windows->data);
- IAnjutaFileLoader* loader =
- anjuta_shell_get_interface(ANJUTA_SHELL(win), IAnjutaFileLoader, NULL);
+ GList *windows;
+ AnjutaShell *win;
+ IAnjutaFileLoader* loader = NULL;
+ gint i;
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (application));
+ if (windows == NULL)
+ {
+ win = ANJUTA_SHELL (anjuta_application_create_window (ANJUTA_APPLICATION (application)));
+ }
+ else
+ {
+ win = ANJUTA_SHELL (windows->data);
+ }
+ if (win != NULL)
+ {
+ loader = anjuta_shell_get_interface(win, IAnjutaFileLoader, NULL);
+ }
if (!loader)
return;
@@ -607,3 +418,120 @@ anjuta_application_get_proper_shutdown (AnjutaApplication *app)
{
return app->priv->proper_shutdown;
}
+
+AnjutaWindow*
+anjuta_application_create_window (AnjutaApplication *app)
+{
+ AnjutaPluginManager *plugin_manager;
+ AnjutaProfileManager *profile_manager;
+ AnjutaWindow *win;
+ AnjutaStatus *status;
+ AnjutaProfile *profile;
+ GFile *session_profile;
+ gchar *remembered_plugins;
+ gchar *profile_name = NULL;
+ GError *error = NULL;
+
+ /* Initialize application */
+ win = ANJUTA_WINDOW (anjuta_window_new ());
+ gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (win));
+ status = anjuta_shell_get_status (ANJUTA_SHELL (win), NULL);
+ anjuta_status_progress_add_ticks (status, 1);
+
+ gtk_window_set_role (GTK_WINDOW (win), "anjuta-app");
+ gtk_window_set_auto_startup_notification(TRUE);
+ gtk_window_set_default_icon_name ("anjuta");
+ gtk_window_set_auto_startup_notification(FALSE);
+
+ if (app->priv->no_splash)
+ {
+ anjuta_status_disable_splash (status, TRUE);
+ }
+ else
+ {
+ gchar *im_file = NULL;
+ im_file = anjuta_res_get_pixmap_file (ANJUTA_PIXMAP_SPLASH_SCREEN);
+ if (im_file)
+ {
+ anjuta_status_set_splash (status, im_file, 100);
+ g_free (im_file);
+ }
+ }
+
+ g_signal_connect (G_OBJECT (win), "delete_event",
+ G_CALLBACK (on_anjuta_delete_event), app);
+
+ /* Setup application framework */
+ plugin_manager = anjuta_shell_get_plugin_manager (ANJUTA_SHELL (win),
+ NULL);
+ profile_manager = anjuta_shell_get_profile_manager (ANJUTA_SHELL (win),
+ NULL);
+
+ /* Restore remembered plugins */
+ remembered_plugins =
+ g_settings_get_string (win->settings, ANJUTA_REMEMBERED_PLUGINS);
+ if (remembered_plugins)
+ anjuta_plugin_manager_set_remembered_plugins (plugin_manager,
+ remembered_plugins);
+ g_free (remembered_plugins);
+
+ /* Prepare profile */
+ profile = anjuta_profile_new (USER_PROFILE_NAME, plugin_manager);
+ session_profile = g_file_new_for_uri (DEFAULT_PROFILE);
+ anjuta_profile_add_plugins_from_xml (profile, session_profile,
+ TRUE, &error);
+ if (error)
+ {
+ anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ g_object_unref (session_profile);
+
+ /* Load user session profile */
+ profile_name = g_path_get_basename (DEFAULT_PROFILE);
+ session_profile = anjuta_util_get_user_cache_file (profile_name, NULL);
+ if (g_file_query_exists (session_profile, NULL))
+ {
+ anjuta_profile_add_plugins_from_xml (profile, session_profile,
+ FALSE, &error);
+ if (error)
+ {
+ anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ }
+ anjuta_profile_set_sync_file (profile, session_profile);
+ g_object_unref (session_profile);
+ g_free (profile_name);
+
+ /* Load profile */
+ anjuta_profile_manager_freeze (profile_manager);
+ anjuta_profile_manager_push (profile_manager, profile, &error);
+ if (error)
+ {
+ anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+
+ /* Prepare for session save and load on profile change */
+ g_signal_connect (profile_manager, "profile-scoped",
+ G_CALLBACK (on_profile_scoped), win);
+ anjuta_profile_manager_thaw (profile_manager, &error);
+
+ if (error)
+ {
+ anjuta_util_dialog_error (GTK_WINDOW (win), "%s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ g_signal_connect (profile_manager, "profile-descoped",
+ G_CALLBACK (on_profile_descoped), win);
+
+ anjuta_status_progress_tick (status, NULL, _("Loaded Sessionâ"));
+ anjuta_status_disable_splash (status, TRUE);
+
+ return win;
+}
diff --git a/src/anjuta-application.h b/src/anjuta-application.h
index c324e60..8dde69d 100644
--- a/src/anjuta-application.h
+++ b/src/anjuta-application.h
@@ -52,4 +52,6 @@ AnjutaApplication *anjuta_application_new (void);
gboolean anjuta_application_get_proper_shutdown (AnjutaApplication *app);
+AnjutaWindow* anjuta_application_create_window (AnjutaApplication *app);
+
#endif
diff --git a/src/anjuta-window.c b/src/anjuta-window.c
index 898b7a2..4cdeff6 100644
--- a/src/anjuta-window.c
+++ b/src/anjuta-window.c
@@ -43,6 +43,7 @@
#include "anjuta-window.h"
#include "anjuta-actions.h"
+#include "anjuta-application.h"
#include "about.h"
#define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta.xml"
@@ -256,6 +257,22 @@ anjuta_window_unmaximize (AnjutaShell *shell,
win->maximized = FALSE;
}
+static AnjutaShell *
+anjuta_window_create_window (AnjutaShell *shell,
+ GError **error)
+{
+ AnjutaWindow *win = NULL;
+ AnjutaApplication *app;
+
+ /* AnjutaWindow assertions */
+ g_return_val_if_fail (ANJUTA_IS_WINDOW (shell), NULL);
+
+ app = ANJUTA_APPLICATION (gtk_window_get_application (GTK_WINDOW (shell)));
+ win = anjuta_application_create_window (ANJUTA_APPLICATION (app));
+
+ return ANJUTA_SHELL (win);
+}
+
static void
on_toolbar_style_changed (GSettings* settings,
const gchar* key,
@@ -419,6 +436,35 @@ static void
on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase,
AnjutaSession *session, AnjutaWindow *win)
{
+ if (phase == ANJUTA_SESSION_PHASE_START)
+ {
+ AnjutaApplication *app;
+
+ app = ANJUTA_APPLICATION (gtk_window_get_application (GTK_WINDOW (win)));
+ if (app != NULL)
+ {
+ if (anjuta_application_get_no_session (app) ||
+ g_settings_get_boolean (win->settings, ANJUTA_SESSION_SKIP_LAST))
+ {
+ /* Clear session */
+ anjuta_session_clear (session);
+ }
+ else if (anjuta_application_get_no_files (app) ||
+ g_settings_get_boolean (win->settings, ANJUTA_SESSION_SKIP_LAST_FILES))
+ {
+ /* Clear files from session */
+ anjuta_session_set_string_list (session, "File Loader",
+ "Files", NULL);
+ }
+ if (anjuta_application_get_geometry (app))
+ {
+ /* Set new geometry */
+ anjuta_session_set_string (session, "Anjuta", "Geometry",
+ anjuta_application_get_geometry (app));
+ }
+ }
+ }
+
/* We load layout at last so that all plugins would have loaded by now */
if (phase == ANJUTA_SESSION_PHASE_LAST)
{
@@ -447,7 +493,12 @@ on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase,
{
gtk_window_maximize (GTK_WINDOW (shell));
}
-
+ else
+ {
+ gtk_window_unmaximize (GTK_WINDOW (shell));
+ }
+ gtk_widget_show (GTK_WIDGET (win));
+
/* Restore layout */
layout_file = g_build_filename (anjuta_session_get_session_directory (session),
"dock-layout.xml", NULL);
@@ -1379,6 +1430,7 @@ anjuta_shell_iface_init (AnjutaShellIface *iface)
iface->show_dockable_widget = anjuta_window_show_dockable_widget;
iface->maximize_widget = anjuta_window_maximize_widget;
iface->unmaximize = anjuta_window_unmaximize;
+ iface->create_window = anjuta_window_create_window;
iface->add_value = anjuta_window_add_value;
iface->get_value = anjuta_window_get_value;
iface->remove_value = anjuta_window_remove_value;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]