SF.net SVN: geany: [1468] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Sat Apr 21 12:25:18 UTC 2007


Revision: 1468
          http://svn.sourceforge.net/geany/?rev=1468&view=rev
Author:   ntrel
Date:     2007-04-21 05:25:17 -0700 (Sat, 21 Apr 2007)

Log Message:
-----------
Restore the current project when restarting Geany.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/keyfile.c
    trunk/src/main.c
    trunk/src/project.c
    trunk/src/project.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-04-20 16:43:11 UTC (rev 1467)
+++ trunk/ChangeLog	2007-04-21 12:25:17 UTC (rev 1468)
@@ -1,3 +1,9 @@
+2007-04-21  Nick Treleaven  <nick.treleaven at btinternet.com>
+
+ * src/project.c, src/project.h, src/keyfile.c, src/main.c:
+   Restore the current project when restarting Geany.
+
+
 2007-04-20  Nick Treleaven  <nick.treleaven at btinternet.com>
 
  * doc/geany.docbook:

Modified: trunk/src/keyfile.c
===================================================================
--- trunk/src/keyfile.c	2007-04-20 16:43:11 UTC (rev 1467)
+++ trunk/src/keyfile.c	2007-04-21 12:25:17 UTC (rev 1468)
@@ -47,6 +47,7 @@
 #include "main.h"
 #include "msgwindow.h"
 #include "search.h"
+#include "project.h"
 
 
 static gchar *scribble_text = NULL;
@@ -282,8 +283,8 @@
 
 	g_key_file_set_string(config, "search", "fif_extra_options", search_prefs.fif_extra_options ? search_prefs.fif_extra_options : "");
 
+	project_save_prefs(config);	// save project filename, etc.
 	save_recent_files(config);
-
 	save_session_files(config);
 
 	// write the file
@@ -539,6 +540,7 @@
 
 	search_prefs.fif_extra_options = utils_get_setting_string(config, "search", "fif_extra_options", "");
 
+	project_load_prefs(config);
 	load_file_lists(config);
 
 	g_key_file_free(config);

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2007-04-20 16:43:11 UTC (rev 1467)
+++ trunk/src/main.c	2007-04-21 12:25:17 UTC (rev 1468)
@@ -551,6 +551,22 @@
 }
 
 
+static void load_project_file()
+{
+	gchar *locale_filename;
+
+	g_return_if_fail(project_prefs.session_file != NULL);
+
+	locale_filename = utils_get_locale_from_utf8(project_prefs.session_file);
+
+	if (*locale_filename)
+		project_load_file(locale_filename);
+
+	g_free(locale_filename);
+	g_free(project_prefs.session_file);	// no longer needed
+}
+
+
 gint main(gint argc, gchar **argv)
 {
 	gint idx;
@@ -672,6 +688,9 @@
 	{
 		if (app->pref_main_load_session && cl_options.load_session)
 		{
+			load_project_file();
+
+			// load session files
 			if (! configuration_open_files())
 			{
 				ui_update_popup_copy_items(-1);

Modified: trunk/src/project.c
===================================================================
--- trunk/src/project.c	2007-04-20 16:43:11 UTC (rev 1467)
+++ trunk/src/project.c	2007-04-21 12:25:17 UTC (rev 1468)
@@ -35,11 +35,15 @@
 #include "utils.h"
 #include "ui_utils.h"
 #include "msgwindow.h"
+#include "main.h"
 #ifdef G_OS_WIN32
 # include "win32.h"
 #endif
 
 
+ProjectPrefs project_prefs = {NULL};
+
+
 static gboolean entries_modified;
 
 // simple struct to keep references to the elements of the properties dialog
@@ -751,15 +755,17 @@
 		gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
 
 		// try to load the config
-		if (load_config(filename))
+		if (project_load_file(filename))
 		{
 			gtk_widget_destroy(GTK_WIDGET(dialog));
-			msgwin_status_add(_("Project \"%s\" opened."), app->project->name);
 		}
 		else
 		{
-			SHOW_ERR(_("Project file could not be loaded."));
+			gchar *utf8_filename = utils_get_utf8_from_locale(filename);
+
+			SHOW_ERR(_("Project file \"%s\" could not be loaded."), utf8_filename);
 			gtk_widget_grab_focus(GTK_WIDGET(dialog));
+			g_free(utf8_filename);
 		}
 		g_free(filename);
 	}
@@ -769,6 +775,26 @@
 #endif
 
 
+gboolean project_load_file(const gchar *locale_file_name)
+{
+	g_return_val_if_fail(locale_file_name != NULL, FALSE);
+
+	if (load_config(locale_file_name))
+	{
+		msgwin_status_add(_("Project \"%s\" opened."), app->project->name);
+		return TRUE;
+	}
+	else
+	{
+		gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name);
+
+		msgwin_status_add(_("Project file \"%s\" could not be loaded."), utf8_filename);
+		g_free(utf8_filename);
+	}
+	return FALSE;
+}
+
+
 /* Reads the given filename and creates a new project with the data found in the file.
  * At this point there should not be an already opened project in Geany otherwise it will just
  * return.
@@ -781,8 +807,6 @@
 	// there should not be an open project
 	g_return_val_if_fail(app->project == NULL && filename != NULL, FALSE);
 
-	p = app->project = g_new0(GeanyProject, 1);
-
 	config = g_key_file_new();
 	if (! g_key_file_load_from_file(config, filename, G_KEY_FILE_KEEP_COMMENTS, NULL))
 	{
@@ -790,6 +814,8 @@
 		return FALSE;
 	}
 
+	p = app->project = g_new0(GeanyProject, 1);
+
 	p->name = utils_get_setting_string(config, "project", "name", GEANY_STRING_UNTITLED);
 	p->description = utils_get_setting_string(config, "project", "description", "");
 	p->file_name = utils_get_utf8_from_locale(filename);
@@ -853,3 +879,26 @@
 }
 
 
+void project_save_prefs(GKeyFile *config)
+{
+	GeanyProject *project = app->project;
+
+	if (cl_options.load_session)
+	{
+		gchar *utf8_filename = (project == NULL) ? "" : project->file_name;
+
+		g_key_file_set_string(config, "project", "session_file", utf8_filename);
+	}
+}
+
+
+void project_load_prefs(GKeyFile *config)
+{
+	if (cl_options.load_session)
+	{
+		g_return_if_fail(project_prefs.session_file == NULL);
+		project_prefs.session_file = utils_get_setting_string(config, "project",
+			"session_file", "");
+	}
+}
+

Modified: trunk/src/project.h
===================================================================
--- trunk/src/project.h	2007-04-20 16:43:11 UTC (rev 1467)
+++ trunk/src/project.h	2007-04-21 12:25:17 UTC (rev 1468)
@@ -41,7 +41,14 @@
 	gchar **file_patterns;	// array of filename extension patterns
 };
 
+typedef struct
+{
+	gchar *session_file;
+} ProjectPrefs;
 
+extern ProjectPrefs project_prefs;
+
+
 void project_new();
 
 void project_open();
@@ -51,6 +58,13 @@
 void project_properties();
 
 
+gboolean project_load_file(const gchar *locale_file_name);
+
 const gchar *project_get_make_dir();
 
+
+void project_save_prefs(GKeyFile *config);
+
+void project_load_prefs(GKeyFile *config);
+
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list