anjuta2 shutdown patch
- From: Jeroen Zwartepoorte <jeroen xs4all nl>
- To: dave ximian com
- Cc: gnome-devtools list <gnome-devtools gnome org>
- Subject: anjuta2 shutdown patch
- Date: 10 Nov 2002 00:01:44 +0100
Hi Dave,
Here's a patch that makes anjuta2 properly shutdown the plugins before
exiting (it just exited before this without any cleanup). I've added a
gboolean shutdown() method to anjuta-tool.h. Plugins can save anything
they want in there (documents, projects, sessions). If a plugin returns
FALSE, the shutdown will be aborted (a user pressed the Cancel button in
a "Do you want to [Discard] [Save] [Cancel] the document").
There's also some preliminary code in the document-manager for
saving/discarding modified document upon exit, but in order to properly
do this, i need a list of open documents (and that requires modifying
the document-manager interface (which has a bug etc.))
For now, it will ask the user if he wants to discard or save the
document (Cancel is ignored).
OK to commit?
Jeroen
? anjuta2.schemas
? autom4te-2.53.cache
? shutdown.patch
? tools.patch
? libanjuta/anjuta-marshal.c
? libanjuta/anjuta-marshal.h
? libanjuta/libanjuta-1.0.pc
? plugins/terminal/Makefile
? plugins/terminal/Makefile.in
Index: libanjuta/anjuta-document-manager.c
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/anjuta-document-manager.c,v
retrieving revision 1.1
diff -u -r1.1 anjuta-document-manager.c
--- libanjuta/anjuta-document-manager.c 8 Jun 2002 23:12:04 -0000 1.1
+++ libanjuta/anjuta-document-manager.c 9 Nov 2002 22:56:03 -0000
@@ -46,6 +46,16 @@
}
void
+anjuta_document_manager_close_all (AnjutaDocumentManager *docman,
+ GError *error)
+{
+ g_return_if_fail (docman != NULL);
+ g_return_if_fail (ANJUTA_IS_DOCUMENT_MANAGER (docman));
+
+ ANJUTA_DOCUMENT_MANAGER_GET_IFACE (docman)->close_all (docman, error);
+}
+
+void
anjuta_document_manager_save_all (AnjutaDocumentManager *docman,
GError *error)
{
Index: libanjuta/anjuta-document-manager.h
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/anjuta-document-manager.h,v
retrieving revision 1.1
diff -u -r1.1 anjuta-document-manager.h
--- libanjuta/anjuta-document-manager.h 8 Jun 2002 23:12:04 -0000 1.1
+++ libanjuta/anjuta-document-manager.h 9 Nov 2002 22:56:03 -0000
@@ -32,6 +32,8 @@
void (*close) (AnjutaDocumentManager *docman,
AnjutaDocument *document,
GError *error);
+ void (*close_all) (AnjutaDocumentManager *docman,
+ GError *error);
void (*save_all) (AnjutaDocumentManager *docman,
GError *error);
int (*num_documents) (AnjutaDocumentManager *docman);
@@ -55,6 +57,8 @@
GError *error);
void anjuta_document_manager_close (AnjutaDocumentManager *docman,
AnjutaDocument *document,
+ GError *error);
+void anjuta_document_manager_close_all (AnjutaDocumentManager *docman,
GError *error);
void anjuta_document_manager_save_all (AnjutaDocumentManager *docman,
GError *error);
Index: libanjuta/anjuta-tool.c
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/anjuta-tool.c,v
retrieving revision 1.10
diff -u -r1.10 anjuta-tool.c
--- libanjuta/anjuta-tool.c 8 Jun 2002 23:12:04 -0000 1.10
+++ libanjuta/anjuta-tool.c 9 Nov 2002 22:56:03 -0000
@@ -158,6 +158,8 @@
object_class->get_property = anjuta_tool_get_property;
object_class->set_property = anjuta_tool_set_property;
+ class->shutdown = NULL;
+
g_object_class_install_property
(object_class,
PROP_SHELL,
Index: libanjuta/anjuta-tool.h
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/anjuta-tool.h,v
retrieving revision 1.9
diff -u -r1.9 anjuta-tool.h
--- libanjuta/anjuta-tool.h 8 Jun 2002 23:12:04 -0000 1.9
+++ libanjuta/anjuta-tool.h 9 Nov 2002 22:56:03 -0000
@@ -62,6 +62,7 @@
GObjectClass parent_class;
void (*shell_set) (AnjutaTool *tool);
+ gboolean (*shutdown) (AnjutaTool *tool);
};
GType anjuta_tool_get_type (void);
Index: plugins/document-manager/anjuta-document-manager.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/document-manager/anjuta-document-manager.c,v
retrieving revision 1.24
diff -u -r1.24 anjuta-document-manager.c
--- plugins/document-manager/anjuta-document-manager.c 14 Jul 2002 17:08:38 -0000 1.24
+++ plugins/document-manager/anjuta-document-manager.c 9 Nov 2002 22:56:05 -0000
@@ -1026,6 +1026,26 @@
}
static void
+anjuta_notebook_document_manager_close_all (AnjutaDocumentManager *docman,
+ GError *error)
+{
+ GList *l;
+ AnjutaDocument *doc;
+
+ for (l = ANJUTA_NOTEBOOK_DOCUMENT_MANAGER (docman)->documents; l; l = l->next) {
+ doc = ANJUTA_DOCUMENT (l->data);
+
+ if (anjuta_bonobo_document_is_changed (ANJUTA_BONOBO_DOCUMENT (doc))) {
+ if (file_close_dialog (ANJUTA_NOTEBOOK_DOCUMENT_MANAGER (docman), doc)
+ == GTK_RESPONSE_CANCEL) {
+ return;
+ }
+ }
+ anjuta_notebook_document_manager_close (docman, doc, error);
+ }
+}
+
+static void
anjuta_notebook_document_manager_save_all (AnjutaDocumentManager *docman,
GError *error)
{
@@ -1125,6 +1145,7 @@
iface->new_document = anjuta_notebook_document_manager_new_document;
iface->open = anjuta_notebook_document_manager_open;
iface->close = anjuta_notebook_document_manager_close;
+ iface->close_all = anjuta_notebook_document_manager_close_all;
iface->save_all = anjuta_notebook_document_manager_save_all;
iface->num_documents = anjuta_notebook_document_manager_num_documents;
iface->get_nth_document = anjuta_notebook_document_manager_get_nth_document;
Index: plugins/document-manager/document-manager-tool.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/document-manager/document-manager-tool.c,v
retrieving revision 1.17
diff -u -r1.17 document-manager-tool.c
--- plugins/document-manager/document-manager-tool.c 8 Jun 2002 23:12:14 -0000 1.17
+++ plugins/document-manager/document-manager-tool.c 9 Nov 2002 22:56:05 -0000
@@ -232,11 +232,21 @@
g_object_unref (pixbuf);
}
+static gboolean
+tool_shutdown (AnjutaTool *tool)
+{
+ DocumentTool *doc_tool = (DocumentTool *)tool;
+
+ anjuta_document_manager_close_all (doc_tool->docman, NULL);
+
+ return TRUE;
+}
+
static void
dispose (GObject *obj)
{
DocumentTool *tool = (DocumentTool*)obj;
-
+
if (tool->current_document) {
set_current_document (ANJUTA_TOOL (tool), NULL);
}
@@ -269,6 +279,7 @@
AnjutaToolClass *tool_class = ANJUTA_TOOL_CLASS (klass);
tool_class->shell_set = shell_set;
+ tool_class->shutdown = tool_shutdown;
klass->dispose = dispose;
}
Index: src/anjuta-windows.c
===================================================================
RCS file: /cvs/gnome/anjuta2/src/anjuta-windows.c,v
retrieving revision 1.14
diff -u -r1.14 anjuta-windows.c
--- src/anjuta-windows.c 8 Jun 2002 23:12:30 -0000 1.14
+++ src/anjuta-windows.c 9 Nov 2002 22:56:05 -0000
@@ -58,8 +58,8 @@
static void
anjuta_window_delete (AnjutaWindow *window, gpointer data)
{
+ anjuta_tool_unload (window);
gtk_object_destroy (GTK_OBJECT (window));
-
gtk_main_quit ();
}
Index: src/anjuta.c
===================================================================
RCS file: /cvs/gnome/anjuta2/src/anjuta.c,v
retrieving revision 1.42
diff -u -r1.42 anjuta.c
--- src/anjuta.c 9 Jun 2002 00:30:21 -0000 1.42
+++ src/anjuta.c 9 Nov 2002 22:56:06 -0000
@@ -169,6 +169,8 @@
/* GTK main loop */
gtk_main ();
+ anjuta_tools_finalize ();
+
/* All�s great, return EXIT_SUCCESS */
return (EXIT_SUCCESS);
}
Index: src/tools.c
===================================================================
RCS file: /cvs/gnome/anjuta2/src/tools.c,v
retrieving revision 1.21
diff -u -r1.21 tools.c
--- src/tools.c 11 Jun 2002 20:07:13 -0000 1.21
+++ src/tools.c 9 Nov 2002 22:56:07 -0000
@@ -747,7 +747,7 @@
g_strfreev (pathv);
}
- plugin_dirs = g_list_prepend (NULL, PLUGIN_DIR);
+ plugin_dirs = g_list_prepend (plugin_dirs, g_strdup (PLUGIN_DIR));
glue_factory_add_path (glue_factory, PLUGIN_DIR);
plugin_dirs = g_list_reverse (plugin_dirs);
@@ -758,6 +758,32 @@
load_tool_sets ();
}
+static gboolean
+free_tool_set (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ ToolSet *tool_set = (ToolSet *)value;
+
+ g_free (tool_set->name);
+ g_hash_table_destroy (tool_set->tools);
+ g_free (tool_set);
+
+ return TRUE;
+}
+
+void
+anjuta_tools_finalize (void)
+{
+ unload_available_tools ();
+ g_object_unref (gconf_client);
+ g_list_foreach (plugin_dirs, (GFunc)g_free, NULL);
+ g_list_free (plugin_dirs);
+ g_hash_table_foreach_remove (tool_sets, free_tool_set, NULL);
+ g_hash_table_destroy (tool_sets);
+ g_object_unref (glue_factory);
+}
+
static gboolean
should_load (AvailableTool *tool, ToolSet *set)
{
@@ -868,6 +894,47 @@
}
g_object_set_data (G_OBJECT (win), "InstalledTools", installed_tools);
+}
+
+void
+anjuta_tool_unload (AnjutaWindow *window)
+{
+ GHashTable *installed_tools;
+ GSList *l;
+
+ installed_tools = g_object_get_data (G_OBJECT (window), "InstalledTools");
+
+ /* reverse available_tools when unloading, so that plugins are
+ * unloaded in the right order */
+ available_tools = g_slist_reverse (available_tools);
+
+ /* Shutdown all plugins. If a plugin doesn't want to exit, abort the
+ * shutdown process. */
+ for (l = available_tools; l != NULL; l = l->next) {
+ AvailableTool *tool = l->data;
+ GObject *tool_obj = g_hash_table_lookup (installed_tools,
+ tool);
+ if (tool_obj) {
+ AnjutaTool *anjuta_tool = ANJUTA_TOOL (tool_obj);
+ if (ANJUTA_TOOL_GET_CLASS (anjuta_tool)->shutdown)
+ if (!ANJUTA_TOOL_GET_CLASS (anjuta_tool)->shutdown (anjuta_tool))
+ return;
+ }
+ }
+
+ /* Remove plugins. */
+ for (l = available_tools; l != NULL; l = l->next) {
+ AvailableTool *tool = l->data;
+ GObject *tool_obj = g_hash_table_lookup (installed_tools,
+ tool);
+ if (tool_obj) {
+ g_object_unref (tool_obj);
+ /* FIXME: Unload the class if possible */
+ g_hash_table_remove (installed_tools, tool);
+ }
+ }
+
+ g_hash_table_destroy (installed_tools);
}
static AvailableTool *
Index: src/tools.h
===================================================================
RCS file: /cvs/gnome/anjuta2/src/tools.h,v
retrieving revision 1.8
diff -u -r1.8 tools.h
--- src/tools.h 8 Jun 2002 23:12:31 -0000 1.8
+++ src/tools.h 9 Nov 2002 22:56:07 -0000
@@ -5,9 +5,11 @@
#include "window.h"
void anjuta_tools_init (void);
+void anjuta_tools_finalize (void);
void anjuta_tool_set_load (AnjutaWindow *win,
ESplash *splash,
const char *name);
+void anjuta_tool_unload (AnjutaWindow *window);
GtkWidget *anjuta_tools_get_preferences (void);
Index: src/window.c
===================================================================
RCS file: /cvs/gnome/anjuta2/src/window.c,v
retrieving revision 1.65
diff -u -r1.65 window.c
--- src/window.c 21 Sep 2002 14:02:08 -0000 1.65
+++ src/window.c 9 Nov 2002 22:56:07 -0000
@@ -167,6 +167,7 @@
static void
tmp_exit (GtkWidget *w, AnjutaWindow *window)
{
+ anjuta_tool_unload (window);
gtk_object_destroy (GTK_OBJECT (window));
gtk_main_quit ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]