session & mime patch



Hi all,

I just committed a big patch that adds .anjuta mime type handling to
anjuta2. Anjuta2 will now be registered with nautilus as an application
which can open .anjuta files (anjuta project files). To enable this,
right click on a .anjuta file and select Open With->An Application...
Then choose anjuta2 and select to use the app by default for opening
.anjuta files. A mime icon will hopefully follow soon.

Anjuta2 can also open (multiple) source files specified on the command
line. These mime types are not yet registered though (will be soon).

The second part of the patch is for session handling. This part is not
finished yet. I need some more input on how to properly handling loading
& saving sessions from anjuta2 first.

Regards,

Jeroen
? anjuta2.anjuta
? session.patch
? autom4te.cache/output.0
? autom4te.cache/requests
? autom4te.cache/traces.0
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/anjuta2/ChangeLog,v
retrieving revision 1.251
diff -u -r1.251 ChangeLog
--- ChangeLog	28 Jan 2003 13:47:55 -0000	1.251
+++ ChangeLog	3 Feb 2003 12:23:02 -0000
@@ -1,3 +1,46 @@
+2003-02-03  Jeroen Zwartepoorte  <jeroen xs4all nl>
+
+	* data/Makefile.am: Add mime type files.
+	* data/anjuta2.applications: Use application/x-anjuta mime type.
+	* data/anjuta2.keys: .anjuta mime type handling.
+	* data/anjuta2.mime: Idem.
+	* libanjuta/Makefile.am: Add session files.
+	* libanjuta/anjuta-session.c: New session code.
+	* libanjuta/anjuta-session.h: Idem.
+	* libanjuta/anjuta-shell.c: (anjuta_shell_get_valist),
+	(anjuta_shell_base_init): Add session load & save signals.
+	* libanjuta/anjuta-shell.h: Idem.
+	* libanjuta/libanjuta.h: Add anjuta-session header.
+	* plugins/document-manager/anjuta-document-manager.c:
+	(anjuta_notebook_document_manager_remove_doc), (add_doc),
+	(anjuta_notebook_document_manager_get_current_document): Handle
+	document_removed signal slightly different.
+	* plugins/document-manager/anjuta-document-manager.h: Fix incorrect
+	macro names (s/DOCUMENT_MANAGER/NOTEBOOK_DOCUMENT_MANAGER).
+	* plugins/document-manager/anjuta-document.h: Idem:
+	s/DOCUMENT/BONOBO_DOCUMENT.
+	* plugins/document-manager/document-manager-tool.c: (idle_load_cb),
+	(session_load_cb), (session_save_cb), (shell_set), (get_doc_label),
+	(file_close_dialog), (tool_shutdown): Implement commandline file
+	loading, handle session signals properly and do some cleanup.
+	* plugins/project-manager/project-tool.c: (session_load_cb),
+	(session_save_cb), (shell_set): Implement commandline project
+	loading. Necessary to make the .anjuta mime type association
+	actually do anything.
+	* src/anjuta.c: (main): Add commandline arguments to shell so
+	plugins can access them (Shell::ProgramArgument variable).
+	* src/tools.c: (tool_from_file), (load_tool_file): Remove g_prints.
+	* src/window.c: (about_cmd), (anjuta_window_instance_init),
+	(anjuta_window_remove_value), (anjuta_window_dispose): Update copyright
+	to 2003. Add session handling.
+
+	This commit makes anjuta2 an application that can load .anjuta project
+	files form nautilus. Furthermore, the plugins can now access the
+	commandline arguments. The document-manager & project-manager use this
+	new functionality to load source files and project files upon startup.
+	Session handling is also partially implemented, although more work is
+	needed before it is really usable.
+
 2003-01-28  Jeroen Zwartepoorte  <jeroen xs4all nl>
 
 	* plugins/document-manager/anjuta-document-manager.xml: A little more
Index: data/Makefile.am
===================================================================
RCS file: /cvs/gnome/anjuta2/data/Makefile.am,v
retrieving revision 1.1
diff -u -r1.1 Makefile.am
--- data/Makefile.am	24 Jan 2003 12:47:49 -0000	1.1
+++ data/Makefile.am	3 Feb 2003 12:23:02 -0000
@@ -11,6 +11,9 @@
 app_DATA = anjuta2.applications
 appdir = $(datadir)/application-registry
 
+mimedir = $(datadir)/mime-info
+mime_DATA = anjuta2.keys anjuta2.mime
+
 bin_SCRIPTS=anjuta-clean.sh
 
 schemasdir = $(sysconfdir)/gconf/schemas
@@ -27,6 +30,7 @@
 	$(man_MANS) \
 	$(pixmap_DATA) \
 	$(desktop_in_files) \
+	$(mime_DATA) \
 	$(app_DATA) \
 	$(bin_SCRIPTS) \
 	$(schemas_in_files)
Index: data/anjuta2.applications
===================================================================
RCS file: /cvs/gnome/anjuta2/data/anjuta2.applications,v
retrieving revision 1.1
diff -u -r1.1 anjuta2.applications
--- data/anjuta2.applications	24 Jan 2003 12:47:49 -0000	1.1
+++ data/anjuta2.applications	3 Feb 2003 12:23:02 -0000
@@ -4,4 +4,4 @@
 	can_open_multiple_files=true
 	expects_uris=false
 	requires_terminal=false
-	mime_types=application/anjuta2
+	mime_types=application/x-anjuta
Index: libanjuta/Makefile.am
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/Makefile.am,v
retrieving revision 1.11
diff -u -r1.11 Makefile.am
--- libanjuta/Makefile.am	8 Jun 2002 23:12:04 -0000	1.11
+++ libanjuta/Makefile.am	3 Feb 2003 12:23:02 -0000
@@ -20,6 +20,7 @@
 	anjuta-shell.c \
 	anjuta-tool.c \
 	anjuta-utils.c \
+	anjuta-session.c \
 	glue-plugin.c \
 	glue-factory.c 
 
@@ -34,6 +35,7 @@
 	anjuta-utils.h \
 	anjuta-doc.h \
 	anjuta-marshal.h \
+	anjuta-session.h \
 	glue-plugin.c \
 	glue-factory.c
 
Index: libanjuta/anjuta-shell.c
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/anjuta-shell.c,v
retrieving revision 1.1
diff -u -r1.1 anjuta-shell.c
--- libanjuta/anjuta-shell.c	8 Jun 2002 23:12:04 -0000	1.1
+++ libanjuta/anjuta-shell.c	3 Feb 2003 12:23:03 -0000
@@ -211,7 +211,7 @@
 		anjuta_shell_get_value (shell, name, &value, &err);
 
 		if (err) {
-			g_print ("Could not get value: %s\n", err->message);
+			g_warning ("Could not get value: %s", err->message);
 			g_error_free (err);
 			break;
 		}
@@ -285,6 +285,23 @@
 			      anjuta_marshal_VOID__STRING,
 			      G_TYPE_NONE, 1,
 			      G_TYPE_STRING);
+
+		g_signal_new ("session_load",
+			      ANJUTA_TYPE_SHELL,
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (AnjutaShellIface, session_load),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0,
+			      NULL);
+		g_signal_new ("session_save",
+			      ANJUTA_TYPE_SHELL,
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (AnjutaShellIface, session_save),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0,
+			      NULL);
 	}
 }
 
Index: libanjuta/anjuta-shell.h
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/anjuta-shell.h,v
retrieving revision 1.1
diff -u -r1.1 anjuta-shell.h
--- libanjuta/anjuta-shell.h	8 Jun 2002 23:12:04 -0000	1.1
+++ libanjuta/anjuta-shell.h	3 Feb 2003 12:23:04 -0000
@@ -24,6 +24,8 @@
 	/* Signals */
 	void (*value_added) (AnjutaShell *shell, char *name, GValue *value);
 	void (*value_removed) (AnjutaShell *shell, char *name);
+	void (*session_load) (AnjutaShell *shell);
+	void (*session_save) (AnjutaShell *shell);
 
 	/* Virtual Table */
 	void (*add_widget)        (AnjutaShell  *shell,
Index: libanjuta/libanjuta.h
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/libanjuta.h,v
retrieving revision 1.7
diff -u -r1.7 libanjuta.h
--- libanjuta/libanjuta.h	8 Jun 2002 23:12:04 -0000	1.7
+++ libanjuta/libanjuta.h	3 Feb 2003 12:23:04 -0000
@@ -4,6 +4,7 @@
 #include "anjuta-utils.h"
 #include "anjuta-tool.h"
 #include "anjuta-doc.h"
+#include "anjuta-session.h"
 
 #define ANJUTA_WINDOW_LOC_TOP       GNOME_Development_Shell_LOC_TOP
 #define ANJUTA_WINDOW_LOC_BOTTOM    GNOME_Development_Shell_LOC_BOTTOM
Index: plugins/document-manager/anjuta-document-manager.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/document-manager/anjuta-document-manager.c,v
retrieving revision 1.26
diff -u -r1.26 anjuta-document-manager.c
--- plugins/document-manager/anjuta-document-manager.c	29 Dec 2002 19:41:50 -0000	1.26
+++ plugins/document-manager/anjuta-document-manager.c	3 Feb 2003 12:23:06 -0000
@@ -160,12 +160,12 @@
 		if (anjuta_bonobo_document_is_untitled (ANJUTA_BONOBO_DOCUMENT (document))) {
 			docman->priv->untitled_count--;
 		}
-		
+
+		g_signal_emit_by_name (docman, "document_removed", document);
+
 		docman->documents = 
 			g_list_remove (docman->documents, document);
 	}
-
-	g_signal_emit_by_name (docman, "document_removed", document);
 }
 
 static GtkResponseType
@@ -277,8 +277,10 @@
 	/* Remove untitled document first if it's the current active document. */
 	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)))
+	    !anjuta_bonobo_document_is_changed (ANJUTA_BONOBO_DOCUMENT (docman->current_document))) {
+		g_object_ref (G_OBJECT (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,
@@ -1175,8 +1177,6 @@
 static AnjutaDocument *
 anjuta_notebook_document_manager_get_current_document (AnjutaDocumentManager *docman)
 {
-	g_print ("getting current document\n");
-	
 	return ANJUTA_NOTEBOOK_DOCUMENT_MANAGER (docman)->current_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.12
diff -u -r1.12 anjuta-document-manager.h
--- plugins/document-manager/anjuta-document-manager.h	15 Nov 2002 09:25:19 -0000	1.12
+++ plugins/document-manager/anjuta-document-manager.h	3 Feb 2003 12:23:06 -0000
@@ -32,8 +32,8 @@
 #define ANJUTA_TYPE_NOTEBOOK_DOCUMENT_MANAGER        (anjuta_notebook_document_manager_get_type ())
 #define ANJUTA_NOTEBOOK_DOCUMENT_MANAGER(o)          (GTK_CHECK_CAST ((o), ANJUTA_TYPE_NOTEBOOK_DOCUMENT_MANAGER, AnjutaNotebookDocumentManager))
 #define ANJUTA_NOTEBOOK_DOCUMENT_MANAGER_CLASS(k)    (GTK_CHECK_CLASS_CAST((k), ANJUTA_TYPE_NOTEBOOK_DOCUMENT_MANAGER, AnjutaNotebookDocumentManagerClass))
-#define ANJUTA_IS_DOCUMENT_MANAGER(o)                (GTK_CHECK_TYPE ((o), ANJUTA_TYPE_NOTEBOOK_DOCUMENT_MANAGER))
-#define ANJUTA_IS_DOCUMENT_MANAGER_CLASS(k)          (GTK_CHECK_CLASS_TYPE ((k), ANJUTA_TYPE_NOTEBOOK_DOCUMENT_MANAGER))
+#define ANJUTA_IS_NOTEBOOK_DOCUMENT_MANAGER(o)       (GTK_CHECK_TYPE ((o), ANJUTA_TYPE_NOTEBOOK_DOCUMENT_MANAGER))
+#define ANJUTA_IS_NOTEBOOK_DOCUMENT_MANAGER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), ANJUTA_TYPE_NOTEBOOK_DOCUMENT_MANAGER))
 
 struct _AnjutaNotebookDocumentManager {
 	GtkNotebook parent;
Index: plugins/document-manager/anjuta-document.h
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/document-manager/anjuta-document.h,v
retrieving revision 1.30
diff -u -r1.30 anjuta-document.h
--- plugins/document-manager/anjuta-document.h	8 Jun 2002 23:12:14 -0000	1.30
+++ plugins/document-manager/anjuta-document.h	3 Feb 2003 12:23:06 -0000
@@ -28,8 +28,8 @@
 #define ANJUTA_TYPE_BONOBO_DOCUMENT        (anjuta_bonobo_document_get_type ())
 #define ANJUTA_BONOBO_DOCUMENT(o)          (GTK_CHECK_CAST ((o), ANJUTA_TYPE_BONOBO_DOCUMENT, AnjutaBonoboDocument))
 #define ANJUTA_BONOBO_DOCUMENT_CLASS(k)    (GTK_CHECK_CLASS_CAST((k), ANJUTA_TYPE_BONOBO_DOCUMENT, AnjutaBonoboDocumentClass))
-#define ANJUTA_IS_DOCUMENT(o)              (GTK_CHECK_TYPE ((o), ANJUTA_TYPE_BONOBO_DOCUMENT))
-#define ANJUTA_IS_DOCUMENT_CLASS(k)        (GTK_CHECK_CLASS_TYPE ((k), ANJUTA_TYPE_BONOBO_DOCUMENT))
+#define ANJUTA_IS_BONOBO_DOCUMENT(o)       (GTK_CHECK_TYPE ((o), ANJUTA_TYPE_BONOBO_DOCUMENT))
+#define ANJUTA_IS_BONOBO_DOCUMENT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), ANJUTA_TYPE_BONOBO_DOCUMENT))
 
 typedef struct _AnjutaBonoboDocument            AnjutaBonoboDocument;
 typedef struct _AnjutaBonoboDocumentClass       AnjutaBonoboDocumentClass;
Index: plugins/document-manager/document-manager-tool.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/document-manager/document-manager-tool.c,v
retrieving revision 1.19
diff -u -r1.19 document-manager-tool.c
--- plugins/document-manager/document-manager-tool.c	7 Jan 2003 05:07:04 -0000	1.19
+++ plugins/document-manager/document-manager-tool.c	3 Feb 2003 12:23:08 -0000
@@ -27,6 +27,7 @@
 #include <libanjuta/anjuta-document.h>
 #include <libanjuta/anjuta-document-manager.h>
 #include <libanjuta/anjuta-tool.h>
+#include <libanjuta/anjuta-session.h>
 #include <libanjuta/glue-plugin.h>
 #include <libanjuta/glue-factory.h>
 #include <bonobo/bonobo-file-selector-util.h>
@@ -44,6 +45,9 @@
 
 	gchar *default_path;
 	GSList *docs;
+
+	GSList *files;
+	int file_index;
 } DocumentTool;
 
 typedef struct {
@@ -219,6 +223,135 @@
 	doc_tool->docs = g_slist_remove (doc_tool->docs, doc);
 }
 
+static gboolean
+idle_load_cb (AnjutaTool *tool)
+{
+	DocumentTool *doc_tool = (DocumentTool *)tool;
+	int i = doc_tool->file_index;
+
+	if (g_slist_nth (doc_tool->files, i) != NULL) {
+		anjuta_document_manager_open (doc_tool->docman,
+					      g_slist_nth_data (doc_tool->files, i),
+					      NULL);
+		doc_tool->file_index++;
+	} else {
+		/* NOTE: program arguments are g_strdup so g_free is ok, but
+		 * session arguments are xmlNodeGetContents and should really
+		 * be xmlFree'ed. Just g_free them for now. */
+		g_slist_foreach (doc_tool->files, (GFunc)g_free, NULL);
+		g_slist_free (doc_tool->files);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static void
+session_load_cb (AnjutaShell *shell,
+		 AnjutaTool *tool)
+{
+	DocumentTool *doc_tool = (DocumentTool *)tool;
+	const char **args;
+	int i;
+	GSList *files = NULL;
+	AnjutaSession *session;
+	xmlNodePtr group, docs, doc;
+
+	/* If the user startup anjuta2 with the intention to display a source
+	 * file then don't load the previous session but only the files on the
+	 * commandline. */
+	anjuta_shell_get (tool->shell,
+			  "Shell::ProgramArguments",
+			  G_TYPE_POINTER,
+			  &args,
+			  NULL);
+	if (args) {
+		for (i = 0; args[i] != NULL; i++) {
+			if (args[i][0] == '-' ||
+			    g_str_has_suffix (args[i], ".anjuta"))
+				continue;
+			else
+				files = g_slist_append (files, g_strdup (args[i]));
+		}
+		if (g_slist_length (files) > 0) {
+			doc_tool->files = files;
+			doc_tool->file_index = 0;
+			g_idle_add ((GSourceFunc)idle_load_cb, tool);
+		}
+		return;
+	}
+
+	/* Load the source files from the previous session. */
+	anjuta_shell_get (tool->shell,
+			  "Shell::CurrentSession",
+			  G_TYPE_POINTER,
+			  &session,
+			  NULL);
+	group = anjuta_session_get_group (session, "document-manager");
+	if (group) {
+		/* Get <documents> node. */
+		for (docs = group->children; docs; docs = docs->next) {
+			if (docs->type == XML_ELEMENT_NODE)
+				if (!strcmp (docs->name, "documents"))
+					break;
+		}
+
+		if (docs) {
+			for (doc = docs->children; doc != NULL; doc = doc->next) {
+				if (doc->type == XML_ELEMENT_NODE) {
+					files = g_slist_append (files,
+								xmlNodeGetContent (doc));
+				}
+			}
+			doc_tool->files = files;
+			doc_tool->file_index = 0;
+			g_idle_add ((GSourceFunc)idle_load_cb, tool);
+		}
+	}
+}
+
+static void
+session_save_cb (AnjutaShell *shell,
+		 AnjutaTool *tool)
+{
+	DocumentTool *doc_tool = (DocumentTool *)tool;
+	AnjutaSession *session;
+	xmlNodePtr group, docs_node, child;
+	GSList *docs, *l;
+	AnjutaDocument *doc;
+
+	/* Get the <documents> session node. */
+	anjuta_shell_get (tool->shell,
+			  "Shell::CurrentSession",
+			  G_TYPE_POINTER,
+			  &session,
+			  NULL);
+	group = anjuta_session_get_group (session, "document-manager");
+	if (!group) {
+		group = anjuta_session_new_group (session, "document-manager");
+		docs_node = xmlNewChild (group, NULL, "documents", NULL);
+	} else {
+		/* Get <documents> node. */
+		for (docs_node = group->children; docs_node; docs_node = docs_node->next) {
+			if (docs_node->type == XML_ELEMENT_NODE)
+				if (!strcmp (docs_node->name, "documents"))
+					break;
+		}
+	}
+
+	/* Save session data & close documents. */
+	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_untitled (ANJUTA_BONOBO_DOCUMENT (doc)))
+			continue;
+
+		/* Create new <document> node with session info. */
+		child = xmlNewChild (docs_node, NULL, "document", anjuta_document_get_uri (doc));
+	}
+	g_slist_free (docs);
+}
+
 static void
 shell_set (AnjutaTool *anjuta_tool)
 {
@@ -227,7 +360,16 @@
 	GdkPixbuf *pixbuf;
 	GtkWidget *preferences;
 	GConfClient *gconf_client;
-	
+
+	g_signal_connect (G_OBJECT (anjuta_tool->shell),
+			  "session_load",
+			  G_CALLBACK (session_load_cb),
+			  tool);
+	g_signal_connect (G_OBJECT (anjuta_tool->shell),
+			  "session_save",
+			  G_CALLBACK (session_save_cb),
+			  tool);
+
 	anjuta_tool_merge_ui (anjuta_tool,
 			      "anjuta-document-manager",
 			      ANJUTA_DATADIR,
@@ -286,41 +428,34 @@
 }
 
 static const char *
-get_doc_label (AnjutaNotebookDocumentManager *docman, 
-	       AnjutaDocument *document)
+get_doc_label (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");
+	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)
+file_close_dialog (AnjutaDocument *current)
 {
 	char *filename;
 	GtkResponseType ret;
 	GtkWidget *dialog;
 	GtkWidget *button;
 
-	if (!anjuta_document_get_uri (ANJUTA_DOCUMENT (current))) {
+	if (!anjuta_document_get_uri (current)) {
 		char *label;
 
-		label = g_strdup (get_doc_label (docman, current));
+		label = g_strdup (get_doc_label (current));
 		filename = g_path_get_basename (label);
 		g_free (label);
 	} else {
-		filename = g_strdup (anjuta_document_get_uri (ANJUTA_DOCUMENT (current)));
+		filename = g_strdup (anjuta_document_get_uri (current));
 	}
 
 	dialog = gtk_message_dialog_new (NULL,
@@ -354,7 +489,7 @@
 	gtk_widget_destroy (dialog);
 
 	if (ret == GTK_RESPONSE_YES) {
-		anjuta_document_save (ANJUTA_DOCUMENT (current), NULL);
+		anjuta_document_save (current, NULL);
 	}
 
 	g_free (filename);
@@ -368,18 +503,21 @@
 	DocumentTool *doc_tool = (DocumentTool *)tool;
 	GSList *docs, *l;
 	AnjutaDocument *doc;
+	GtkResponseType resp;
 
+	/* Save/discard any modified files first. */
 	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) {
+			resp = file_close_dialog (doc);
+			if (resp == GTK_RESPONSE_NO) {
+				anjuta_notebook_document_manager_remove_doc (ANJUTA_NOTEBOOK_DOCUMENT_MANAGER (doc_tool->docman), doc);
+			} else if (resp == 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);
 
Index: plugins/project-manager/project-tool.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/project-manager/project-tool.c,v
retrieving revision 1.39
diff -u -r1.39 project-tool.c
--- plugins/project-manager/project-tool.c	28 Jan 2003 13:47:56 -0000	1.39
+++ plugins/project-manager/project-tool.c	3 Feb 2003 12:23:09 -0000
@@ -830,6 +830,39 @@
 }
 
 static void
+session_load_cb (AnjutaShell *shell,
+		 AnjutaTool *tool)
+{
+	ProjectTool *proj_tool = (ProjectTool *)tool;
+	const char **args;
+	int i;
+
+	/* If the user startup anjuta2 with the intention to display a source
+	 * file then don't load the previous session but only the files on the
+	 * commandline. */
+	anjuta_shell_get (tool->shell,
+			  "Shell::ProgramArguments",
+			  G_TYPE_POINTER,
+			  &args,
+			  NULL);
+	if (args) {
+		for (i = 0; args[i] != NULL; i++) {
+			if (g_str_has_suffix (args[i], ".anjuta")) {
+				set_build (proj_tool, args[i]);
+				break;
+			}
+		}
+	}
+}
+
+static void
+session_save_cb (AnjutaShell *shell,
+		 AnjutaTool *tool)
+{
+	ProjectTool *proj_tool = (ProjectTool *)tool;
+}
+
+static void
 shell_set (AnjutaTool *tool)
 {
 	GConfClient *client;
@@ -845,6 +878,15 @@
 			  ANJUTA_TYPE_PROJECT_MANAGER,
 			  proj_tool->manager,
 			  NULL);
+
+	g_signal_connect (G_OBJECT (tool->shell),
+			  "session_load",
+			  G_CALLBACK (session_load_cb),
+			  tool);
+	g_signal_connect (G_OBJECT (tool->shell),
+			  "session_save",
+			  G_CALLBACK (session_save_cb),
+			  tool);
 
 	anjuta_tool_merge_ui (tool, "anjuta-project-manager",
 			      DATADIR,
Index: src/anjuta.c
===================================================================
RCS file: /cvs/gnome/anjuta2/src/anjuta.c,v
retrieving revision 1.44
diff -u -r1.44 anjuta.c
--- src/anjuta.c	25 Jan 2003 10:36:52 -0000	1.44
+++ src/anjuta.c	3 Feb 2003 12:23:10 -0000
@@ -122,7 +122,7 @@
 	bindtextdomain (PACKAGE, GNOMELOCALEDIR);
 	bind_textdomain_codeset (PACKAGE, "UTF-8");
 	textdomain (PACKAGE);
-	
+
 	program = gnome_program_init (PACKAGE, VERSION, 
 				      LIBGNOMEUI_MODULE,
 				      argc, argv, 
@@ -132,15 +132,10 @@
 
 	g_object_get (G_OBJECT (program), "popt-context", &ctx, NULL);
 
-	if (dogfood_mode) {
-		anjuta_moniker_prefix = "anjuta-dogfood";
-	} else {
-		anjuta_moniker_prefix = "anjuta";
-	}
-	
 	gnome_vfs_init ();
 	bonobo_activate ();
-			    
+
+	g_object_get (G_OBJECT (program), "popt-context", &ctx, NULL);
 	startup_files = poptGetArgs (ctx);
 
 	gnome_window_icon_set_default_from_file (DATADIR "/pixmaps/anjuta2.png");
@@ -159,19 +154,20 @@
 
 	add_preference_pages ();
 
-#if 0
-	shell = BONOBO_OBJREF (main_window->shell);
-	load_files (shell, startup_files);
-#endif
-
 	gtk_widget_unref (splash);
 	gtk_widget_destroy (splash);
 
+	anjuta_shell_add (ANJUTA_SHELL (main_window),
+			  "Shell::ProgramArguments",
+			  G_TYPE_POINTER,
+			  startup_files, NULL);
+
+	g_signal_emit_by_name (main_window, "session_load", main_window);
+
 	/* GTK main loop */
 	gtk_main ();
 
 	anjuta_tools_finalize ();
 
-	/* Allīs great, return EXIT_SUCCESS */
-	return (EXIT_SUCCESS);
+	return EXIT_SUCCESS;
 }
Index: src/tools.c
===================================================================
RCS file: /cvs/gnome/anjuta2/src/tools.c,v
retrieving revision 1.23
diff -u -r1.23 tools.c
--- src/tools.c	15 Nov 2002 09:25:20 -0000	1.23
+++ src/tools.c	3 Feb 2003 12:23:11 -0000
@@ -353,7 +353,6 @@
 					   "Anjuta Plugin",
 					   "Location",
 					   &str)) {
-		g_print ("loading %s\n", str);
 		tool->id = str;
 	} else {
 		g_warning ("Couldn't find 'Location'");
@@ -435,8 +434,6 @@
 load_tool_file (const char *path)
 {
 	char *contents;
-	
-	g_print ("loading %s\n", path);
 
 	if (g_file_get_contents (path, &contents, NULL, NULL)) {
 		AnjutaPluginFile *file;
Index: src/window.c
===================================================================
RCS file: /cvs/gnome/anjuta2/src/window.c,v
retrieving revision 1.68
diff -u -r1.68 window.c
--- src/window.c	18 Jan 2003 21:50:26 -0000	1.68
+++ src/window.c	3 Feb 2003 12:23:12 -0000
@@ -30,8 +30,6 @@
 #include <gdl/gdl-dock.h>
 #include <gdl/gdl-dock-layout.h>
 #include <gdl/gdl-dock-placeholder.h>
-#include <libanjuta/anjuta-shell.h>
-#include <libanjuta/anjuta-utils.h>
 #include <libgnomeui/libgnomeui.h>
 #include <libgnome/gnome-macros.h>
 #include <libgnome/gnome-util.h>
@@ -201,14 +199,15 @@
 		about = gnome_about_new
 			(_("Anjuta"), 
 			 VERSION,
-			 _("Copyright Various Authors (C) 1998-2002"),
+			 _("Copyright Various Authors (C) 1998-2003"),
 			 _("A Gnome based IDE"), authors, NULL, NULL, NULL);
 		gtk_window_set_transient_for (GTK_WINDOW (about),
 					      GTK_WINDOW (window));
-		g_object_add_weak_pointer (G_OBJECT (about), &about);
+		g_object_add_weak_pointer (G_OBJECT (about), (gpointer *)&about);
 		gtk_widget_show (about);
-	} else
+	} else {
 		gdk_window_raise (GTK_WIDGET (about)->window);
+	}
 }
 
 static void
@@ -363,6 +362,7 @@
 {
 	BonoboUIContainer *ui_container;
 	GtkTargetEntry dragtypes[] = {{"text/uri-list", 0, 0}};
+	AnjutaSession *session;
 
 	ui_container = bonobo_window_get_ui_container (BONOBO_WINDOW (window));
 	
@@ -430,6 +430,15 @@
 	window->widgets = g_hash_table_new (g_str_hash, g_str_equal);
 	window->preference_pages = g_hash_table_new (g_str_hash, g_str_equal);
 
+	/* default session. */
+	session = anjuta_session_new ("default");
+	anjuta_shell_add (ANJUTA_SHELL (window),
+			  "Shell::CurrentSession",
+			  G_TYPE_POINTER,
+			  session,
+			  NULL);
+	g_object_set_data (G_OBJECT (window), "session", session);
+
 	gtk_widget_queue_draw (GTK_WIDGET(window));
 	gtk_widget_queue_resize (GTK_WIDGET(window));
 }
@@ -566,10 +575,10 @@
 		g_free (key);
 	}
 
-	if (g_hash_table_lookup_extended (window->widgets, name, 
+	if (g_hash_table_lookup_extended (window->values, name, 
 					  (gpointer*)&key, (gpointer*)&value)) {
+		g_hash_table_remove (window->values, name);
 		g_signal_emit_by_name (window, "value_removed", name);
-		
 		g_value_unset (value);
 		g_free (value);
 	}
@@ -662,7 +671,8 @@
 	AnjutaWindow *window;
 	GtkAllocation *alloc;
 	AnjutaWindowState *state;
-	
+	AnjutaSession *session;
+
 	g_assert (ANJUTA_IS_WINDOW (widget));
 	window = ANJUTA_WINDOW (widget);
 
@@ -681,6 +691,13 @@
 		/* free window state */
 		g_object_set_data (G_OBJECT (widget), "window_state", NULL);
 		g_free (state);
+	}
+
+	session = g_object_get_data (G_OBJECT (widget), "session");
+	if (session) {
+		anjuta_session_save (session);
+		g_object_set_data (G_OBJECT (widget), "session", NULL);
+		g_object_unref (session);
 	}
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]