SF.net SVN: geany: [1984] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Sun Oct 28 17:02:36 UTC 2007


Revision: 1984
          http://geany.svn.sourceforge.net/geany/?rev=1984&view=rev
Author:   eht16
Date:     2007-10-28 10:02:36 -0700 (Sun, 28 Oct 2007)

Log Message:
-----------
Add support for relative project base path.
Improve and synchronize base path tooltips in project new and properties dialogs.
Fix minor GUI annoyances in project dialogs.	    

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/doc/geany.txt
    trunk/src/build.c
    trunk/src/project.c
    trunk/src/project.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-10-26 16:09:00 UTC (rev 1983)
+++ trunk/ChangeLog	2007-10-28 17:02:36 UTC (rev 1984)
@@ -1,3 +1,12 @@
+2007-10-28  Enrico Tröger  <enrico.troeger at uvena.de>
+
+ * doc/geany.txt, src/build.c, src/project.c, src/project.h:
+   Add support for relative project base path.
+   Improve and synchronize base path tooltips in project new and
+   properties dialogs.
+   Fix minor GUI annoyances in project dialogs.
+
+
 2007-10-26  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
 
  * plugins/svndiff.c, plugins/export.c, plugins/demoplugin.c,

Modified: trunk/doc/geany.txt
===================================================================
--- trunk/doc/geany.txt	2007-10-26 16:09:00 UTC (rev 1983)
+++ trunk/doc/geany.txt	2007-10-28 17:02:36 UTC (rev 1984)
@@ -1171,13 +1171,15 @@
 used elsewhere by Geany.
 
 The *Base path* field is used as the directory to run the Make and Make
-custom commands in.
+custom commands in. It is also used as working directory for the project
+specific *Run command*.
+The specified path can be absolute or relative to the project's file name.
 
 
 Run command
 ```````````
 
-The Run command overrides the default run command. You can set this
+The *Run command* overrides the default run command. You can set this
 to the executable or main script file for the project, and append
 any command-line arguments.
 

Modified: trunk/src/build.c
===================================================================
--- trunk/src/build.c	2007-10-26 16:09:00 UTC (rev 1983)
+++ trunk/src/build.c	2007-10-28 17:02:36 UTC (rev 1984)
@@ -300,7 +300,7 @@
 static GPid build_make_file(gint idx, gint build_opts)
 {
 	GString *cmdstr;
-	const gchar *dir = NULL;
+	gchar *dir = NULL;
 	GPid pid;
 
 	if (idx < 0 || doc_list[idx].file_name == NULL) return (GPid) 1;
@@ -331,6 +331,7 @@
 	}
 
 	pid = build_spawn_cmd(idx, cmdstr->str, dir);	// if dir is NULL, idx filename is used
+	g_free(dir);
 	g_string_free(cmdstr, TRUE);
 	return pid;
 }
@@ -636,9 +637,14 @@
 		return NULL;
 	}
 
-	working_dir = (have_project) ?
-		utils_get_locale_from_utf8(project->base_path) :
-		g_path_get_dirname(locale_filename);
+	if (have_project)
+	{
+		gchar *project_base_path = project_get_make_dir();
+		working_dir = utils_get_locale_from_utf8(project_base_path);
+		g_free(project_base_path);
+	}
+	else
+		working_dir = g_path_get_dirname(locale_filename);
 
 	if (chdir(working_dir) != 0)
 	{

Modified: trunk/src/project.c
===================================================================
--- trunk/src/project.c	2007-10-26 16:09:00 UTC (rev 1983)
+++ trunk/src/project.c	2007-10-28 17:02:36 UTC (rev 1984)
@@ -28,6 +28,7 @@
 #include "geany.h"
 
 #include <string.h>
+#include <unistd.h>
 
 #include "project.h"
 #include "dialogs.h"
@@ -46,7 +47,7 @@
 
 static struct
 {
-	gchar *project_file_path;
+	gchar *project_file_path; // in UTF-8
 } local_prefs = {NULL};
 
 
@@ -153,7 +154,8 @@
 	e->base_path = gtk_entry_new();
 	gtk_tooltips_set_tip(tooltips, e->base_path,
 		_("Base directory of all files that make up the project. "
-		"This can be a new path, or an existing directory tree."), NULL);
+		"This can be a new path, or an existing directory tree absolute "
+		"or relative to the project filename."), NULL);
 	bbox = ui_path_box_new(_("Choose Project Base Path"),
 		GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path));
 
@@ -219,6 +221,7 @@
 #else
 	GtkWidget *dialog;
 	GtkFileFilter *filter;
+	gchar *locale_path;
 #endif
 	if (! close_open_project()) return;
 
@@ -256,7 +259,13 @@
 	gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
 	gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
 
-	gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir);
+	locale_path = utils_get_locale_from_utf8(dir);
+	if (g_file_test(locale_path, G_FILE_TEST_EXISTS) &&
+		g_file_test(locale_path, G_FILE_TEST_IS_DIR))
+	{
+		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path);
+	}
+	g_free(locale_path);
 
 	gtk_widget_show_all(dialog);
 	run_open_dialog(GTK_DIALOG(dialog));
@@ -374,8 +383,9 @@
 
 	e->base_path = gtk_entry_new();
 	gtk_tooltips_set_tip(tooltips, e->base_path,
-		_("Directory to run Make All from. "
-		"Leave blank to use the default command."), NULL);
+		_("Base directory of all files that make up the project. "
+		"This can be a new path, or an existing directory tree absolute "
+		"or relative to the project filename."), NULL);
 	bbox = ui_path_box_new(_("Choose Project Base Path"),
 		GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path));
 	gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 3, 4,
@@ -505,6 +515,7 @@
 static gboolean update_config(const PropertyDialogElements *e)
 {
 	const gchar *name, *file_name, *base_path;
+	gchar *locale_filename;
 	gint name_len;
 	gboolean new_project = FALSE;
 	GeanyProject *p;
@@ -534,10 +545,27 @@
 		return FALSE;
 	}
 
+	// finally test whether the given project file can be written
+	locale_filename = utils_get_locale_from_utf8(file_name);
+	if (utils_write_file(file_name, "") != 0)
+	{
+		SHOW_ERR(_("Project file could not be written."));
+		gtk_widget_grab_focus(e->file_name);
+		return FALSE;
+	}
+
 	base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path));
 	if (NZV(base_path))
 	{	// check whether the given directory actually exists
 		gchar *locale_path = utils_get_locale_from_utf8(base_path);
+
+		if (! g_path_is_absolute(locale_path))
+		{	// relative base path, so add base dir of project file name
+			gchar *dir = g_path_get_dirname(locale_filename);
+			setptr(locale_path, g_strconcat(dir, G_DIR_SEPARATOR_S, locale_path, NULL));
+			g_free(dir);
+		}
+
 		if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR))
 		{
 			if (dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL,
@@ -556,15 +584,8 @@
 		}
 		g_free(locale_path);
 	}
+	g_free(locale_filename);
 
-	// finally test whether the given project file can be written
-	if (utils_write_file(file_name, "") != 0)
-	{
-		SHOW_ERR(_("Project file could not be written."));
-		gtk_widget_grab_focus(e->file_name);
-		return FALSE;
-	}
-
 	if (app->project == NULL)
 	{
 		app->project = g_new0(GeanyProject, 1);
@@ -579,7 +600,7 @@
 	p->file_name = g_strdup(file_name);
 
 	if (p->base_path != NULL) g_free(p->base_path);
-	p->base_path = g_strdup(base_path);
+	p->base_path = g_strdup(NZV(base_path) ? base_path : "./"); // use "." if base_path is empty
 
 	if (! new_project)	// save properties specific fields
 	{
@@ -629,6 +650,18 @@
 	{
 		if (g_file_test(locale_filename, G_FILE_TEST_EXISTS))
 			gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), utf8_filename);
+		else // if the file doesn't yet exist, use at least the current directory
+		{
+			gchar *locale_dir = g_path_get_dirname(locale_filename);
+			gchar *name = g_path_get_basename(utf8_filename);
+
+			if (g_file_test(locale_dir, G_FILE_TEST_EXISTS))
+				gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_dir);
+			gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), name);
+
+			g_free(name);
+			g_free(locale_dir);
+		}
 	}
 	else
 	if (gtk_file_chooser_get_action(GTK_FILE_CHOOSER(dialog)) != GTK_FILE_CHOOSER_ACTION_OPEN)
@@ -849,10 +882,27 @@
 }
 
 
-const gchar *project_get_make_dir()
+/* Constructs the project's base path which is used for "Make all" and "Execute".
+ * The result is an absolute string in UTF-8 encoding which is either the same as
+ * base path if it is absolute or it is built out of project file name's dir and base_path.
+ * If there is no project or project's base_path is invalid, NULL will be returned.
+ * The returned string should be freed when no longer needed. */
+gchar *project_get_make_dir()
 {
 	if (app->project != NULL && NZV(app->project->base_path))
-		return app->project->base_path;
+	{
+		if (g_path_is_absolute(app->project->base_path))
+			return g_strdup(app->project->base_path);
+		else
+		{	// build base_path out of project file name's dir and base_path
+			gchar *path;
+			gchar *dir = g_path_get_dirname(app->project->file_name);
+
+			path = g_strconcat(dir, G_DIR_SEPARATOR_S, app->project->base_path, NULL);
+			g_free(dir);
+			return path;
+		}
+	}
 	else
 		return NULL;
 }
@@ -911,8 +961,7 @@
 	const gchar *str;
 
 	str = gtk_entry_get_text(GTK_ENTRY(path_entry));
-	g_free(local_prefs.project_file_path);
-	local_prefs.project_file_path = g_strdup(str);
+	setptr(local_prefs.project_file_path, g_strdup(str));
 }
 
 

Modified: trunk/src/project.h
===================================================================
--- trunk/src/project.h	2007-10-26 16:09:00 UTC (rev 1983)
+++ trunk/src/project.h	2007-10-28 17:02:36 UTC (rev 1984)
@@ -34,7 +34,7 @@
 
 	gchar *file_name; 		// where the project file is stored (in UTF-8)
 
-	gchar *base_path;		// base path of the project directory (in UTF-8)
+	gchar *base_path;		// base path of the project directory (in UTF-8, maybe relative)
 	gchar *run_cmd; 		// project run command (in UTF-8)
 	// ...					// fields for build process(run arguments and so on) should be added
 
@@ -60,7 +60,7 @@
 
 gboolean project_load_file(const gchar *locale_file_name);
 
-const gchar *project_get_make_dir();
+gchar *project_get_make_dir();
 
 
 void project_save_prefs(GKeyFile *config);


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