another shutdown patch



Hi Dave,

This patch fixes a lot of the issues the older patch had. I've tested it
thoroughly and it works fine over here.

Any comments?

Thanks,

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	11 Nov 2002 21:14:11 -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)
 {
@@ -122,7 +132,7 @@
 	
 	if (!initialized) {
 		g_signal_new ("current_document_changed",
-			      ANJUTA_TYPE_DOCUMENT_MANAGER,
+			      G_TYPE_FROM_CLASS (gclass),
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (AnjutaDocumentManagerIface, 
 					       current_document_changed),
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	11 Nov 2002 21:14:11 -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	11 Nov 2002 21:14:11 -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	11 Nov 2002 21:14:11 -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	11 Nov 2002 21:14:13 -0000
@@ -145,8 +145,9 @@
 	gtk_label_set_text (GTK_LABEL (label), str);
 }
 
-static void
-remove_doc (AnjutaNotebookDocumentManager *docman, AnjutaDocument *document)
+void
+anjuta_notebook_document_manager_remove_doc (AnjutaNotebookDocumentManager *docman,
+					     AnjutaDocument *document)
 {
 	int index;
 	
@@ -163,11 +164,7 @@
 			g_list_remove (docman->documents, document);
 	}
 
-	if (!docman->documents) {
-		anjuta_document_manager_new_document (ANJUTA_DOCUMENT_MANAGER (docman),
-						      "text/plain",
-						      NULL);
-	}
+	g_signal_emit_by_name (docman, "document_removed", document);
 }
 
 static GtkResponseType
@@ -240,7 +237,14 @@
 			return; 
 	}
 
-	remove_doc (docman, document);
+	anjuta_notebook_document_manager_remove_doc (docman, document);
+
+	if (!docman->documents) {
+		anjuta_document_manager_new_document (ANJUTA_DOCUMENT_MANAGER (docman),
+						      "text/plain",
+						      NULL);
+	}
+
 }
 
 static void
@@ -272,7 +276,7 @@
 	if (docman->current_document && uri &&
 	    anjuta_bonobo_document_is_untitled (ANJUTA_BONOBO_DOCUMENT (docman->current_document)) &&
 	    !anjuta_bonobo_document_is_changed (ANJUTA_BONOBO_DOCUMENT (docman->current_document)))
-		remove_doc (docman, docman->current_document);
+		anjuta_notebook_document_manager_remove_doc (docman, docman->current_document);
 
 	/* Add the document to the list */
 	docman->documents = g_list_append (docman->documents,
@@ -337,6 +341,8 @@
 	if (!docman->current_document) {
 		set_current_document (docman, document);
 	}
+
+	g_signal_emit_by_name (docman, "document_added", document);
 }
 
 /* private routines */
@@ -382,6 +388,25 @@
 	
 	object_class->dispose = docman_dispose;
 	object_class->finalize = docman_finalize;
+
+	g_signal_new ("document_added",
+		      G_TYPE_FROM_CLASS (klass),
+		      G_SIGNAL_RUN_LAST,
+		      G_STRUCT_OFFSET (AnjutaNotebookDocumentManagerClass,
+				       document_added),
+		      NULL, NULL,
+		      g_cclosure_marshal_VOID__OBJECT,
+		      G_TYPE_NONE, 1,
+		      ANJUTA_TYPE_DOCUMENT);
+	g_signal_new ("document_removed",
+		      G_TYPE_FROM_CLASS (klass),
+		      G_SIGNAL_RUN_LAST,
+		      G_STRUCT_OFFSET (AnjutaNotebookDocumentManagerClass,
+				       document_removed),
+		      NULL, NULL,
+		      g_cclosure_marshal_VOID__OBJECT,
+		      G_TYPE_NONE, 1,
+		      ANJUTA_TYPE_DOCUMENT);
 }
 
 static void
@@ -976,6 +1001,7 @@
 
 		return NULL;
 	}
+	gnome_vfs_uri_unref (uri);
 
 	/* Only open the file if its not already opened. */
 	document = anjuta_document_manager_get_document_for_uri (anjuta_docman,
@@ -1021,8 +1047,34 @@
 			return;
 		}
 	}
-	
-	remove_doc (ANJUTA_NOTEBOOK_DOCUMENT_MANAGER (docman), document);
+
+	anjuta_notebook_document_manager_remove_doc (ANJUTA_NOTEBOOK_DOCUMENT_MANAGER (docman), document);
+
+	if (!ANJUTA_NOTEBOOK_DOCUMENT_MANAGER (docman)->documents) {
+		anjuta_document_manager_new_document (docman,
+						      "text/plain",
+						      NULL);
+	}
+}
+
+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
@@ -1125,6 +1177,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/anjuta-document-manager.h
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/document-manager/anjuta-document-manager.h,v
retrieving revision 1.11
diff -u -r1.11 anjuta-document-manager.h
--- plugins/document-manager/anjuta-document-manager.h	8 Jun 2002 23:12:14 -0000	1.11
+++ plugins/document-manager/anjuta-document-manager.h	11 Nov 2002 21:14:13 -0000
@@ -49,6 +49,11 @@
 
 struct _AnjutaNotebookDocumentManagerClass {
 	GtkNotebookClass parent_class;
+
+	void (* document_added)   (AnjutaNotebookDocumentManager *docman,
+				   AnjutaDocument *document);
+	void (* document_removed) (AnjutaNotebookDocumentManager *docman,
+				   AnjutaDocument *document);
 };
 
 /* Creation */
@@ -58,6 +63,8 @@
 
 GtkWidget      *      anjuta_notebook_document_manager_get_prefs_page      (void);
 
+void                  anjuta_notebook_document_manager_remove_doc          (AnjutaNotebookDocumentManager *docman,
+									    AnjutaDocument                *document);
 
 G_END_DECLS
 
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	11 Nov 2002 21:14:13 -0000
@@ -37,6 +37,7 @@
 	
 	AnjutaDocumentManager *docman;
 	AnjutaDocument *current_document;
+	GSList *docs;
 } DocumentTool;
 
 typedef struct {
@@ -181,6 +182,26 @@
 }
 
 static void
+document_added_cb (AnjutaNotebookDocumentManager *docman,
+		   AnjutaDocument *doc,
+		   AnjutaTool *tool)
+{
+	DocumentTool *doc_tool = (DocumentTool *)tool;
+
+	doc_tool->docs = g_slist_append (doc_tool->docs, doc);
+}
+
+static void
+document_removed_cb (AnjutaNotebookDocumentManager *docman,
+		     AnjutaDocument *doc,
+		     AnjutaTool *tool)
+{
+	DocumentTool *doc_tool = (DocumentTool *)tool;
+
+	doc_tool->docs = g_slist_remove (doc_tool->docs, doc);
+}
+
+static void
 shell_set (AnjutaTool *anjuta_tool)
 {
 	DocumentTool *tool = (DocumentTool*)anjuta_tool;
@@ -207,6 +228,14 @@
 			  "current_document_changed",
 			  G_CALLBACK (current_document_changed_cb),
 			  tool);
+	g_signal_connect (G_OBJECT (tool->docman),
+			  "document_added",
+			  G_CALLBACK (document_added_cb),
+			  tool);
+	g_signal_connect (G_OBJECT (tool->docman),
+			  "document_removed",
+			  G_CALLBACK (document_removed_cb),
+			  tool);
 
 	anjuta_document_manager_new_document (tool->docman,
 					      "text/plain",
@@ -232,15 +261,120 @@
 	g_object_unref (pixbuf);
 }
 
+static const char *
+get_doc_label (AnjutaNotebookDocumentManager *docman, 
+	       AnjutaDocument *document)
+{
+	GtkWidget *label;
+	const char *str;
+
+	g_return_val_if_fail (docman != NULL, NULL);
+	g_return_val_if_fail (ANJUTA_IS_DOCUMENT_MANAGER (docman), NULL);
+	g_return_val_if_fail (document != NULL, NULL);
+	g_return_val_if_fail (ANJUTA_IS_DOCUMENT (document), NULL);
+	
+	label = g_object_get_data (G_OBJECT (document), 
+				    "AnjutaNotebookDocumentManager::label");
+	str = gtk_label_get_text (GTK_LABEL (label));
+	
+	return str;
+}
+
+static GtkResponseType
+file_close_dialog (AnjutaNotebookDocumentManager *docman, 
+		   AnjutaDocument *current)
+{
+	char *filename;
+	GtkResponseType ret;
+	GtkWidget *dialog;
+	GtkWidget *button;
+
+	if (!anjuta_document_get_uri (ANJUTA_DOCUMENT (current))) {
+		char *label;
+
+		label = g_strdup (get_doc_label (docman, current));
+		filename = g_path_get_basename (label);
+	} else {
+		filename = g_strdup (anjuta_document_get_uri (ANJUTA_DOCUMENT (current)));
+	}
+
+	dialog = gtk_message_dialog_new (NULL,
+					 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+					 GTK_MESSAGE_QUESTION,
+					 GTK_BUTTONS_NONE,
+					 _("Do you want to save the changes you made to the document \"%s\"? \n\n"
+					   "Your changes will be lost if you don't save them."),
+					 filename);
+
+	/* Add "Don't save" button. */
+	button = gdl_button_new_with_stock_image (_("Do_n't save"), GTK_STOCK_NO);
+	g_return_val_if_fail (button != NULL, GTK_RESPONSE_CANCEL);
+	gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
+				      button,
+				      GTK_RESPONSE_NO);
+	gtk_widget_show (button);
+
+	gtk_dialog_add_button (GTK_DIALOG (dialog),
+			       GTK_STOCK_CANCEL,
+			       GTK_RESPONSE_CANCEL);
+
+	gtk_dialog_add_button (GTK_DIALOG (dialog),
+			       GTK_STOCK_SAVE,
+			       GTK_RESPONSE_YES);
+
+	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+
+	ret = gtk_dialog_run (GTK_DIALOG (dialog));
+
+	gtk_widget_destroy (dialog);
+
+	if (ret == GTK_RESPONSE_YES) {
+		anjuta_document_save (ANJUTA_DOCUMENT (current), NULL);
+	}
+
+	g_free (filename);
+
+	return ret;
+}
+
+static gboolean
+tool_shutdown (AnjutaTool *tool)
+{
+	DocumentTool *doc_tool = (DocumentTool *)tool;
+	GSList *docs, *l;
+	AnjutaDocument *doc;
+
+	docs = g_slist_copy (doc_tool->docs);
+	for (l = docs; l != NULL; 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 (doc_tool->docman), doc)
+			    == GTK_RESPONSE_CANCEL) {
+				g_slist_free (docs);
+				return FALSE;
+			}
+		}
+		anjuta_notebook_document_manager_remove_doc (ANJUTA_NOTEBOOK_DOCUMENT_MANAGER (doc_tool->docman), doc);
+	}
+	g_slist_free (docs);
+
+	return TRUE;
+}
+
 static void
 dispose (GObject *obj)
 {
 	DocumentTool *tool = (DocumentTool*)obj;
-	
+
 	if (tool->current_document) {
 		set_current_document (ANJUTA_TOOL (tool), NULL);
 	}
 
+	if (tool->docs) {
+		g_slist_free (tool->docs);
+		tool->docs = NULL;
+	}
+
 	if (tool->docman) {
 		anjuta_shell_remove_value (ANJUTA_TOOL (tool)->shell, 
 					   "DocumentManager:Manager",
@@ -258,6 +392,10 @@
 static void
 document_tool_instance_init (GObject *object)
 {
+	DocumentTool *doc_tool = (DocumentTool *)object;
+
+	doc_tool->docs = NULL;
+
 	if (!gnome_vfs_initialized ()) {
 		gnome_vfs_init ();
 	}
@@ -267,8 +405,9 @@
 document_tool_class_init (GObjectClass *klass)
 {
 	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	11 Nov 2002 21:14:13 -0000
@@ -58,8 +58,10 @@
 static void
 anjuta_window_delete (AnjutaWindow *window, gpointer data)
 {
+	if (!anjuta_tool_unload (window))
+		return;
+
 	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	11 Nov 2002 21:14:14 -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	11 Nov 2002 21:14:15 -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,49 @@
 	}
 
 	g_object_set_data (G_OBJECT (win), "InstalledTools", installed_tools);
+}
+
+gboolean
+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 FALSE;
+		}
+	}
+
+	/* 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);
+
+	return TRUE;
 }
 
 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	11 Nov 2002 21:14:15 -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);
+gboolean 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	11 Nov 2002 21:14:15 -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]