[anjuta] build-basic-autotools: Fix selection of build directory



commit 4bb40c6e9440c793dcf496f4d511a2ee6fb7c7ad
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Wed Jan 23 22:12:56 2013 +0100

    build-basic-autotools: Fix selection of build directory

 plugins/build-basic-autotools/build-options.c      |   64 ++++++++------------
 plugins/build-basic-autotools/build.c              |   24 +++----
 plugins/build-basic-autotools/configuration-list.c |   24 +++-----
 plugins/build-basic-autotools/configuration-list.h |    3 +-
 plugins/build-basic-autotools/plugin.c             |    5 +-
 5 files changed, 49 insertions(+), 71 deletions(-)
---
diff --git a/plugins/build-basic-autotools/build-options.c b/plugins/build-basic-autotools/build-options.c
index 588861b..cee9629 100644
--- a/plugins/build-basic-autotools/build-options.c
+++ b/plugins/build-basic-autotools/build-options.c
@@ -69,8 +69,8 @@ typedef struct _BuildMissingDirectory BuildMissingDirectory;
 
 struct _BuildMissingDirectory
 {
-	gsize exist;
-	gchar uri[1];
+	GFile *exist;
+	GFile *created;
 };
 
 
@@ -139,17 +139,12 @@ build_gtk_file_chooser_create_directory_get_quark (void)
 
 /* Remove created directory */
 static void
-on_build_missing_directory_destroyed (BuildMissingDirectory* dir)
+on_build_missing_directory_destroyed (BuildMissingDirectory* pack)
 {
 	/* Remove previously created directories */
 	GFile* created_dir;
-	GFile* existing_dir;
 
-	created_dir = g_file_new_for_uri (dir->uri);
-	dir->uri[dir->exist] = '\0';
-	existing_dir = g_file_new_for_uri (dir->uri);
-
-	for (;!g_file_equal (created_dir, existing_dir);)
+	for (created_dir = pack->created; !g_file_equal (created_dir, pack->exist);)
 	{
 		GFile *parent_dir;
 
@@ -159,37 +154,30 @@ on_build_missing_directory_destroyed (BuildMissingDirectory* dir)
 		created_dir = parent_dir;
 	}
 	g_object_unref (created_dir);
-	g_object_unref (existing_dir);
-	g_free (dir);
+	g_object_unref (pack->exist);
+	g_free (pack);
 }
 
 /* If the folder is missing created it before setting it */
 
 static gboolean
-build_gtk_file_chooser_create_and_set_uri (GtkFileChooser *chooser, const gchar *uri)
+build_gtk_file_chooser_create_and_set_file (GtkFileChooser *chooser, GFile *dir)
 {
-	GFile *dir;
 	GError *error = NULL;
 	GFile *parent;
 
-	dir = g_file_new_for_uri (uri);
 	parent = build_make_directories (dir, NULL, &error);
 	if (parent != NULL)
 	{
-		BuildMissingDirectory* dir;
-		gchar *last;
-		gsize len;
-
-		len = strlen (uri);
-		dir = (BuildMissingDirectory *)g_new (char, sizeof (BuildMissingDirectory) + len);
+		BuildMissingDirectory* pack;
 
-		memcpy (dir->uri, uri, len + 1);
-		last = g_file_get_uri (parent);
-		dir->exist = strlen (last);
+		pack = g_new (BuildMissingDirectory, 1);
+		pack->exist = parent;
+		pack->created = g_object_ref (dir);
 
 		g_object_set_qdata_full (G_OBJECT (chooser),
 								 GTK_FILE_CHOOSER_CREATE_DIRECTORY_QUARK,
-								 dir,
+								 pack,
 								 (GDestroyNotify)on_build_missing_directory_destroyed);
 	}
 	else
@@ -199,35 +187,33 @@ build_gtk_file_chooser_create_and_set_uri (GtkFileChooser *chooser, const gchar
 							NULL);
 		g_error_free (error);
 	}
-	g_object_unref (dir);
 
-	return gtk_file_chooser_set_current_folder_uri (chooser, uri);
+	return gtk_file_chooser_set_file (chooser, dir, NULL);
 }
 
 /* Do not delete the automatically created folder */
 static void
 build_gtk_file_chooser_keep_folder (GtkFileChooser *chooser, const char *uri)
 {
-	BuildMissingDirectory* dir;
+	BuildMissingDirectory* pack;
 
-	dir = g_object_steal_qdata (G_OBJECT (chooser), GTK_FILE_CHOOSER_CREATE_DIRECTORY_QUARK);
-	if (dir != NULL)
+	pack = g_object_steal_qdata (G_OBJECT (chooser), GTK_FILE_CHOOSER_CREATE_DIRECTORY_QUARK);
+	if (pack != NULL)
 	{
-		GFile *created_dir;
 		GFile *needed_dir;
 
 		needed_dir = g_file_new_for_uri (uri);
-		created_dir = g_file_new_for_uri (dir->uri);
-		if (!g_file_equal (created_dir, needed_dir))
+		if (!g_file_equal (pack->created, needed_dir))
 		{
 			/* Need to delete created directory */
-			on_build_missing_directory_destroyed (dir);
+			on_build_missing_directory_destroyed (pack);
 		}
 		else
 		{
-			g_free (dir);
+			g_object_unref (pack->exist);
+			g_object_unref (pack->created);
+			g_free (pack);
 		}
-		g_object_unref (created_dir);
 		g_object_unref (needed_dir);
 	}
 }
@@ -261,7 +247,6 @@ on_select_configuration (GtkComboBox *widget, gpointer user_data)
 	else
 	{
 		BuildConfiguration *cfg;
-		gchar *uri;
 
 		gtk_widget_set_sensitive (dlg->ok, TRUE);
 
@@ -271,13 +256,14 @@ on_select_configuration (GtkComboBox *widget, gpointer user_data)
 		{
 			const gchar *args;
 			GList *item;
+			GFile *file;
 
 			args = build_configuration_get_args (cfg);
 			gtk_entry_set_text (GTK_ENTRY (dlg->args), args == NULL ? "" : args);
 
-			uri = build_configuration_list_get_build_uri (dlg->config_list, cfg);
-			build_gtk_file_chooser_create_and_set_uri (GTK_FILE_CHOOSER (dlg->build_dir_chooser), uri);
-			g_free (uri);
+			file = build_configuration_list_get_build_file (dlg->config_list, cfg);
+			build_gtk_file_chooser_create_and_set_file (GTK_FILE_CHOOSER (dlg->build_dir_chooser), file);
+			g_object_unref (file);
 
 			anjuta_environment_editor_reset (ANJUTA_ENVIRONMENT_EDITOR (dlg->env_editor));
 			for (item = build_configuration_get_variables (cfg); item != NULL; item = g_list_next (item))
diff --git a/plugins/build-basic-autotools/build.c b/plugins/build-basic-autotools/build.c
index eab1772..cba379d 100644
--- a/plugins/build-basic-autotools/build.c
+++ b/plugins/build-basic-autotools/build.c
@@ -900,15 +900,18 @@ build_project_configured (GObject *sender,
 		BuildContext *context = (BuildContext *)handle;
 		BasicAutotoolsPlugin *plugin = (BasicAutotoolsPlugin *)(context == NULL ? (void *)sender : (void *)build_context_get_plugin (context));
 		GValue *value;
+		GFile *file;
 		gchar *uri;
 
 		/* FIXME: check if build directory correspond, configuration could have changed */
 		value = g_new0 (GValue, 1);
 		g_value_init (value, G_TYPE_STRING);
 
-		uri = build_configuration_list_get_build_uri (plugin->configurations, build_configuration_list_get_selected (plugin->configurations));
+		file = build_configuration_list_get_build_file (plugin->configurations, build_configuration_list_get_selected (plugin->configurations));
+		uri = g_file_get_uri (file);
 		g_value_set_string (value, uri);
 		g_free (uri);
+		g_object_unref (file);
 
 		anjuta_shell_add_value (ANJUTA_PLUGIN (plugin)->shell, IANJUTA_BUILDER_ROOT_URI, value, NULL);
 
@@ -1130,13 +1133,10 @@ build_configure_dialog (BasicAutotoolsPlugin *plugin, BuildFunc func, GFile *fil
 	{
 		BuildConfiguration *config;
 		GFile *build_file;
-		gchar *build_uri;
 		const gchar *args;
 
 		config = build_configuration_list_get_selected (plugin->configurations);
-		build_uri = build_configuration_list_get_build_uri (plugin->configurations, config);
-		build_file = g_file_new_for_uri (build_uri);
-		g_free (build_uri);
+		build_file = build_configuration_list_get_build_file (plugin->configurations, config);
 
 		args = build_configuration_get_args (config);
 
@@ -1201,22 +1201,18 @@ build_get_uri_configuration (BasicAutotoolsPlugin *plugin, const gchar *uri)
 {
 	BuildConfiguration *cfg;
 	BuildConfiguration *uri_cfg = NULL;
-	gsize uri_len = 0;
+	GFile *file = g_file_new_for_uri (uri);
 
 	/* Check all configurations as other configuration directories are
 	 * normally child of default configuration directory */
 	for (cfg = build_configuration_list_get_first (plugin->configurations); cfg != NULL; cfg = build_configuration_next (cfg))
 	{
-		const gchar *root = build_configuration_list_get_build_uri  (plugin->configurations, cfg);
-		gsize len = root != NULL ? strlen (root) : 0;
+		GFile *root = build_configuration_list_get_build_file  (plugin->configurations, cfg);
 
-		if ((len > uri_len) && (strncmp (uri, root, len) == 0))
-		{
-			uri_cfg = cfg;
-			uri_len = len;
-		}
+		if ((root != NULL) && g_file_has_prefix (file, root)) uri_cfg = cfg;
 	}
+	g_object_unref (file);
 
-	return uri_len == 0 ? NULL : build_configuration_get_name (uri_cfg);
+	return uri_cfg != NULL ? build_configuration_get_name (uri_cfg) : NULL;
 }
 
diff --git a/plugins/build-basic-autotools/configuration-list.c b/plugins/build-basic-autotools/configuration-list.c
index 6a2c68f..5d4a9aa 100644
--- a/plugins/build-basic-autotools/configuration-list.c
+++ b/plugins/build-basic-autotools/configuration-list.c
@@ -416,29 +416,21 @@ build_configuration_list_set_build_uri (BuildConfigurationList *list, BuildConfi
 	return ok;
 }
 
-gchar *
-build_configuration_list_get_build_uri (BuildConfigurationList *list, BuildConfiguration *cfg)
+GFile*
+build_configuration_list_get_build_file (BuildConfigurationList *list, BuildConfiguration *cfg)
 {
+	GFile *build;
+
+	build = g_file_new_for_uri (list->project_root_uri);
 	if ((list->project_root_uri != NULL) && (cfg->build_uri != NULL))
 	{
 		GFile *root;
-		GFile *build;
-		gchar *uri;
-
-		root = g_file_new_for_uri (list->project_root_uri);
+		root = build;
 		build = g_file_resolve_relative_path (root, cfg->build_uri);
-
-		uri = g_file_get_uri (build);
-
 		g_object_unref (root);
-		g_object_unref (build);
-
-		return uri;
-	}
-	else
-	{
-		return g_strdup (list->project_root_uri);
 	}
+
+	return build;
 }
 
 const gchar *
diff --git a/plugins/build-basic-autotools/configuration-list.h b/plugins/build-basic-autotools/configuration-list.h
index a138a55..29b51ed 100644
--- a/plugins/build-basic-autotools/configuration-list.h
+++ b/plugins/build-basic-autotools/configuration-list.h
@@ -22,6 +22,7 @@
 #define CONFIGURATION_LIST_H
 
 #include <glib.h>
+#include <gio/gio.h>
 
 typedef struct _BuildConfiguration BuildConfiguration;
 typedef struct _BuildConfigurationList BuildConfigurationList;
@@ -44,7 +45,7 @@ void build_configuration_list_set_project_uri (BuildConfigurationList *list, con
 const gchar *build_configuration_get_translated_name (BuildConfiguration *cfg);
 const gchar *build_configuration_get_name (BuildConfiguration *cfg);
 gboolean build_configuration_list_set_build_uri (BuildConfigurationList *list, BuildConfiguration *cfg, const gchar *build_uri);
-gchar *build_configuration_list_get_build_uri (BuildConfigurationList *list, BuildConfiguration *cfg);
+GFile *build_configuration_list_get_build_file (BuildConfigurationList *list, BuildConfiguration *cfg);
 const gchar *build_configuration_get_relative_build_uri (BuildConfiguration *cfg);
 void build_configuration_set_args (BuildConfiguration *cfg, const gchar *args);
 const gchar *build_configuration_get_args (BuildConfiguration *cfg);
diff --git a/plugins/build-basic-autotools/plugin.c b/plugins/build-basic-autotools/plugin.c
index 96bac38..f979eab 100644
--- a/plugins/build-basic-autotools/plugin.c
+++ b/plugins/build-basic-autotools/plugin.c
@@ -1543,6 +1543,7 @@ on_select_configuration (GtkRadioMenuItem *item, gpointer user_data)
 		BasicAutotoolsPlugin *plugin = ANJUTA_PLUGIN_BASIC_AUTOTOOLS (user_data);
 		gchar *name;
 		GValue *value;
+		GFile *file;
 		gchar *uri;
 
 		name = g_object_get_data (G_OBJECT (item), "untranslated_name");
@@ -1552,9 +1553,11 @@ on_select_configuration (GtkRadioMenuItem *item, gpointer user_data)
 		value = g_new0 (GValue, 1);
 		g_value_init (value, G_TYPE_STRING);
 
-		uri = build_configuration_list_get_build_uri (plugin->configurations, build_configuration_list_get_selected (plugin->configurations));
+		file = build_configuration_list_get_build_file (plugin->configurations, build_configuration_list_get_selected (plugin->configurations));
+		uri = g_file_get_uri (file);
 		g_value_set_string (value, uri);
 		g_free (uri);
+		g_object_unref (file);
 
 		anjuta_shell_add_value (ANJUTA_PLUGIN (plugin)->shell, IANJUTA_BUILDER_ROOT_URI, value, NULL);
 	}



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