[anjuta/newproject] Read and display list properties



commit b37667d88a13aef3c40e211f7fb53f9170e2638f
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Sun Feb 14 17:07:08 2010 +0100

    Read and display list properties

 libanjuta/anjuta-project.c         |   52 ++++++++++++++-
 libanjuta/anjuta-project.h         |    4 +-
 plugins/am-project/am-dialogs.c    |  131 ++++++++++++++++++++++++++---------
 plugins/am-project/am-project.c    |   15 +++--
 plugins/am-project/am-properties.c |   29 +++++---
 plugins/am-project/am-properties.h |    2 +-
 6 files changed, 180 insertions(+), 53 deletions(-)
---
diff --git a/libanjuta/anjuta-project.c b/libanjuta/anjuta-project.c
index de6532d..a7e10fd 100644
--- a/libanjuta/anjuta-project.c
+++ b/libanjuta/anjuta-project.c
@@ -109,12 +109,62 @@ anjuta_project_property_lookup (AnjutaProjectPropertyList *list, AnjutaProjectPr
 	return info;
 }
 
+AnjutaProjectPropertyItem *
+anjuta_project_property_override (AnjutaProjectPropertyList *list, AnjutaProjectPropertyItem *prop)
+{
+	AnjutaProjectPropertyItem *item;
+	
+	for (item = list; item != NULL; item = g_list_next (item))
+	{
+		AnjutaProjectPropertyInfo *info;
+	
+		info = (AnjutaProjectPropertyInfo *)list->data;
+		
+		if (info->override == NULL)
+		{
+			item = NULL;
+			break;
+		}
+		else if (info->override == prop)
+		{
+			break;
+		}
+	}
+
+	return item;
+}
+
+AnjutaProjectPropertyItem *
+anjuta_project_property_next_item (AnjutaProjectPropertyItem *item)
+{
+	AnjutaProjectPropertyItem *prop = ((AnjutaProjectPropertyInfo *)item->data)->override;
+
+	for (item = g_list_next (item); item != NULL; item = g_list_next (item))
+	{
+		AnjutaProjectPropertyInfo *info;
+	
+		info = (AnjutaProjectPropertyInfo *)item->data;
+		
+		if (info->override == NULL)
+		{
+			item = NULL;
+			break;
+		}
+		else if (info->override == prop)
+		{
+			break;
+		}
+	}
+
+	return item;
+}
+
 AnjutaProjectPropertyList *
 anjuta_project_property_insert (AnjutaProjectPropertyList *list, AnjutaProjectPropertyItem *prop, AnjutaProjectPropertyInfo *info)
 {
 	GList *next;
 	
-	info->name = ((AnjutaProjectPropertyInfo *)prop->data)->name;
+	if (info->name == NULL) info->name = ((AnjutaProjectPropertyInfo *)prop->data)->name;
 	info->type = ((AnjutaProjectPropertyInfo *)prop->data)->type;
 	info->override = prop;
 
diff --git a/libanjuta/anjuta-project.h b/libanjuta/anjuta-project.h
index f1579b0..3967036 100644
--- a/libanjuta/anjuta-project.h
+++ b/libanjuta/anjuta-project.h
@@ -73,7 +73,7 @@ typedef enum
 {
 	ANJUTA_PROJECT_PROPERTY_STRING = 1,
 	ANJUTA_PROJECT_PROPERTY_BOOLEAN,
-	ANJUTA_PROJECT_PROPERTY_MAP
+	ANJUTA_PROJECT_PROPERTY_LIST
 } AnjutaProjectPropertyType;
 
 typedef struct
@@ -124,6 +124,8 @@ typedef void (*AnjutaProjectNodeFunc) (AnjutaProjectNode *node, gpointer data);
 
 AnjutaProjectPropertyItem *anjuta_project_property_first (AnjutaProjectPropertyList *list);
 AnjutaProjectPropertyItem *anjuta_project_property_next (AnjutaProjectPropertyItem *list);
+AnjutaProjectPropertyItem *anjuta_project_property_override (AnjutaProjectPropertyList *list, AnjutaProjectPropertyItem *prop);
+AnjutaProjectPropertyItem *anjuta_project_property_next_item (AnjutaProjectPropertyItem *item);
 AnjutaProjectPropertyInfo *anjuta_project_property_get_info (AnjutaProjectPropertyItem *list);
 AnjutaProjectPropertyInfo *anjuta_project_property_lookup (AnjutaProjectPropertyList *list, AnjutaProjectPropertyItem *prop);
 AnjutaProjectPropertyList *anjuta_project_property_insert (AnjutaProjectPropertyList *list, AnjutaProjectPropertyItem *prop, AnjutaProjectPropertyInfo *info);
diff --git a/plugins/am-project/am-dialogs.c b/plugins/am-project/am-dialogs.c
index f950fef..4082c17 100644
--- a/plugins/am-project/am-dialogs.c
+++ b/plugins/am-project/am-dialogs.c
@@ -43,6 +43,12 @@ typedef struct _AmpConfigureProjectDialog
 	GtkWidget *top_level;
 } AmpConfigureProjectDialog;
 
+enum {
+	NAME_COLUMN,
+	VALUE_COLUMN,
+	LIST_COLUMNS_NB
+};
+
 
 /* Helper functions
  *---------------------------------------------------------------------------*/
@@ -58,15 +64,30 @@ on_project_widget_destroy (GtkWidget *wid, AmpConfigureProjectDialog *dlg)
 }
 
 static void
-add_entry (AmpProject *project, AnjutaProjectNode *node, AnjutaProjectPropertyInfo *info, GtkWidget *table, gint position)
+add_entry (AmpProject *project, AnjutaProjectNode *node, AnjutaProjectPropertyItem *prop, GtkWidget *table, gint *position)
 {
 	GtkWidget *label;
 	GtkWidget *entry = NULL;
-
-	label = gtk_label_new (_(info->name));
+	GtkWidget *view;
+	static GType column_type[LIST_COLUMNS_NB] = {
+		G_TYPE_STRING, G_TYPE_STRING};
+	GtkCellRenderer *renderer;
+	GtkTreeViewColumn *column;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	AnjutaProjectPropertyInfo *info = anjuta_project_property_get_info (prop);
+
+	if (info->override)
+	{
+		label = gtk_label_new (_(((AnjutaProjectPropertyInfo *)info->override->data)->name));
+	}
+	else
+	{
+		label = gtk_label_new (_(info->name));
+	}
 	gtk_misc_set_alignment (GTK_MISC (label), 0, -1);
 	gtk_widget_show (label);
-	gtk_table_attach (GTK_TABLE (table), label, 0, 1, position, position+1,
+	gtk_table_attach (GTK_TABLE (table), label, 0, 1, *position, *position+1,
 			  GTK_FILL, GTK_FILL, 5, 3);
 
 	switch (info->type)
@@ -79,31 +100,79 @@ add_entry (AmpProject *project, AnjutaProjectNode *node, AnjutaProjectPropertyIn
 		entry = gtk_check_button_new ();
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (entry), (info->value != NULL) && (*info->value == '1'));
 		break;
+	case ANJUTA_PROJECT_PROPERTY_LIST:
+			model = GTK_TREE_MODEL (gtk_list_store_newv (LIST_COLUMNS_NB, column_type));
+
+			while ((info->override != NULL) && (prop != NULL))
+			{
+				info = anjuta_project_property_get_info (prop);
+
+				gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+				gtk_list_store_set (GTK_LIST_STORE (model), &iter, NAME_COLUMN, info->name, VALUE_COLUMN, info->value, -1);
+
+				prop = anjuta_project_property_next_item (prop);
+			}
+			
+			gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+			gtk_list_store_set (GTK_LIST_STORE (model), &iter, NAME_COLUMN, "", VALUE_COLUMN, "", -1);
+			
+			entry = gtk_frame_new (NULL);
+			gtk_frame_set_shadow_type (GTK_FRAME (entry), GTK_SHADOW_IN);
+			
+			view = gtk_tree_view_new_with_model (model);
+			gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)),
+											GTK_SELECTION_SINGLE);
+			gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (view), TRUE);
+			g_object_unref (G_OBJECT (model));
+
+			renderer = gtk_cell_renderer_text_new ();
+			column = gtk_tree_view_column_new_with_attributes (_("Name"),
+			    renderer,
+			    "text",
+			    NAME_COLUMN,
+			    NULL);
+			gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+			gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
+			column = gtk_tree_view_column_new_with_attributes (_("Value"),
+			    renderer,
+			    "text",
+			    VALUE_COLUMN,
+			    NULL);
+			gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
+			gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
+
+			gtk_container_add (GTK_CONTAINER (entry), view);
+			
+			break;
 	default:
 		return;
 	}		
 	gtk_misc_set_alignment (GTK_MISC (entry), 0, -1);
 	gtk_widget_show (entry);
-	gtk_table_attach (GTK_TABLE (table), entry, 1, 2, position, position+1,
+	gtk_table_attach (GTK_TABLE (table), entry, 1, 2, *position, *position+1,
 			  GTK_FILL | GTK_EXPAND, GTK_FILL, 5, 3);
+	
+	*position = *position + 1;
 }
 
 static void
-add_label (const gchar *display_name, const gchar *value, GtkWidget *table, gint position)
+add_label (const gchar *display_name, const gchar *value, GtkWidget *table, gint *position)
 {
 	GtkWidget *label;
 	
 	label = gtk_label_new (display_name);
 	gtk_misc_set_alignment (GTK_MISC (label), 0, -1);
 	gtk_widget_show (label);
-	gtk_table_attach (GTK_TABLE (table), label, 0, 1, position, position+1,
+	gtk_table_attach (GTK_TABLE (table), label, 0, 1, *position, *position+1,
 			  GTK_FILL, GTK_FILL, 5, 3);
 
 	label = gtk_label_new (value);
 	gtk_misc_set_alignment (GTK_MISC (label), 0, -1);
 	gtk_widget_show (label);
-	gtk_table_attach (GTK_TABLE (table), label, 1, 2, position, position+1,
+	gtk_table_attach (GTK_TABLE (table), label, 1, 2, *position, *position+1,
 			  GTK_FILL | GTK_EXPAND, GTK_FILL, 5, 3);
+
+	*position = *position + 1;
 }
 
 /* Public functions
@@ -133,19 +202,15 @@ amp_configure_project_dialog (AmpProject *project, GError **error)
 	g_object_ref (top_level);
 	g_signal_connect (top_level, "destroy", G_CALLBACK (on_project_widget_destroy), dlg);
 
+	pos = 0;
 	name = g_file_get_parse_name (amp_project_get_file (project));
-	add_label (_("Path:"), name, table, 0);
+	add_label (_("Path:"), name, table, &pos);
 	g_free (name);
 
-	pos = 1;
 	list = amp_project_get_property_list (project);
 	for (prop = anjuta_project_property_first (list); prop != NULL; prop = anjuta_project_property_next (prop))
 	{
-		AnjutaProjectPropertyInfo *info;
-
-		info = anjuta_project_property_lookup (list, prop);
-		if (info == NULL) info = anjuta_project_property_get_info (prop);
-		add_entry (project, NULL, info, table, pos++);
+		add_entry (project, NULL, prop, table, &pos);
 	}
 	
 	/*add_entry (project, NULL, _("Name:"), AMP_PROPERTY_NAME, table, 1);
@@ -187,26 +252,25 @@ amp_configure_group_dialog (AmpProject *project, AmpGroup *group, GError **error
 	g_object_ref (properties);
 	g_signal_connect (properties, "destroy", G_CALLBACK (on_project_widget_destroy), dlg);
 
+	main_pos = 0;
+	extra_pos = 0;
 	name = g_file_get_parse_name (amp_group_get_directory (group));
-	add_label (_("Name:"), name, main_table, 0);
+	add_label (_("Name:"), name, main_table, &main_pos);
 	g_free (name);
 
-	main_pos = 1;
-	extra_pos = 0;
 	list = ANJUTA_PROJECT_NODE_DATA ((AnjutaProjectNode *)group)->properties;
 	for (prop = anjuta_project_property_first (list); prop != NULL; prop = anjuta_project_property_next (prop))
 	{
-		AnjutaProjectPropertyInfo *info;
+		AnjutaProjectPropertyItem *item;
 
-		info = anjuta_project_property_lookup (list, prop);
-		if (info != NULL)
+		item = anjuta_project_property_override (list, prop);
+		if (item != NULL)
 		{
-			add_entry (project, (AnjutaProjectNode *)group, info, main_table, main_pos++);
+			add_entry (project, (AnjutaProjectNode *)group, item, main_table, &main_pos);
 		}
 		else
 		{
-			info = anjuta_project_property_get_info (prop);
-			add_entry (project, (AnjutaProjectNode *)group, info, extra_table, extra_pos++);
+			add_entry (project, (AnjutaProjectNode *)group, prop, extra_table, &extra_pos);
 		}
 	}
 	
@@ -244,27 +308,26 @@ amp_configure_target_dialog (AmpProject *project, AmpTarget *target, GError **er
 	g_object_ref (properties);
 	g_signal_connect (properties, "destroy", G_CALLBACK (on_project_widget_destroy), dlg);
 
+	main_pos = 0;
+	extra_pos = 0;
 	name = amp_target_get_name (target);
-	add_label (_("Name:"), name, main_table, 0);
+	add_label (_("Name:"), name, main_table, &main_pos);
 	type = anjuta_project_target_get_type (target);
-	add_label (_("Type:"), anjuta_project_target_type_name (type), main_table, 1);
+	add_label (_("Type:"), anjuta_project_target_type_name (type), main_table, &main_pos);
 
-	main_pos = 2;
-	extra_pos = 0;
 	list = ANJUTA_PROJECT_NODE_DATA ((AnjutaProjectNode *)target)->properties;
 	for (prop = anjuta_project_property_first (list); prop != NULL; prop = anjuta_project_property_next (prop))
 	{
-		AnjutaProjectPropertyInfo *info;
+		AnjutaProjectPropertyItem *item;
 
-		info = anjuta_project_property_lookup (list, prop);
-		if (info != NULL)
+		item = anjuta_project_property_override (list, prop);
+		if (item != NULL)
 		{
-			add_entry (project, (AnjutaProjectNode *)target, info, main_table, main_pos++);
+			add_entry (project, (AnjutaProjectNode *)target, item, main_table, &main_pos);
 		}
 		else
 		{
-			info = anjuta_project_property_get_info (prop);
-			add_entry (project, (AnjutaProjectNode *)target, info, extra_table, extra_pos++);
+			add_entry (project, (AnjutaProjectNode *)target, prop, extra_table, &extra_pos);
 		}
 	}
 	
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index 5eacc17..f66e5b9 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -1014,7 +1014,7 @@ amp_project_load_properties (AmpProject *project, AnjutaToken *macro, AnjutaToke
 			prop = anjuta_project_property_lookup (project->properties, list);
 			if (prop == NULL)
 			{
-				prop = (AnjutaProjectPropertyInfo *)amp_property_new (info->token_type, info->position, NULL, macro);
+				prop = (AnjutaProjectPropertyInfo *)amp_property_new (NULL, info->token_type, info->position, NULL, macro);
 				
 				project->properties = anjuta_project_property_insert (project->properties, list, prop);
 			}
@@ -1501,7 +1501,7 @@ project_load_target_properties (AmpProject *project, AnjutaToken *name, AnjutaTo
 
 		/* Create property */
 		value = anjuta_token_evaluate (list);
-		prop = amp_property_new (type, 0, value, list);
+		prop = amp_property_new (NULL, type, 0, value, list);
 
 		if (parent == NULL)
 		{
@@ -1532,18 +1532,23 @@ project_load_target_properties (AmpProject *project, AnjutaToken *name, AnjutaTo
 }
 
 static AnjutaToken*
-project_load_group_properties (AmpProject *project, AnjutaTokenType type, AnjutaToken *list, AnjutaProjectGroup *parent)
+project_load_group_properties (AmpProject *project, AnjutaToken *token, AnjutaTokenType type, AnjutaToken *list, AnjutaProjectGroup *parent)
 {
 	AmpGroupData *group = AMP_GROUP_DATA (parent);
 	gchar *value;
+	gchar *name;
 	AnjutaProjectPropertyInfo *prop;
 		
 	/* Create property */
+	name = anjuta_token_evaluate (token);
 	value = anjuta_token_evaluate (list);
-	prop = amp_property_new (type, 0, value, list);
+
+	g_message ("group_name %s", name);
+	prop = amp_property_new (name, type, 0, value, list);
 
 	amp_node_property_add (parent, prop);
 	g_free (value);
+	g_free (name);
 
 	return NULL;
 }
@@ -1706,7 +1711,7 @@ amp_project_set_am_variable (AmpProject* project, AmpGroup* group, AnjutaTokenTy
 	case AM_TOKEN__OBJCFLAGS:
 	case AM_TOKEN__LFLAGS:
 	case AM_TOKEN__YFLAGS:
-		project_load_group_properties (project, variable, list, group);
+		project_load_group_properties (project, name, variable, list, group);
 		break;
 	case AM_TOKEN_TARGET_LDFLAGS:
 	case AM_TOKEN_TARGET_CPPFLAGS:
diff --git a/plugins/am-project/am-properties.c b/plugins/am-project/am-properties.c
index 7219e65..23c7110 100644
--- a/plugins/am-project/am-properties.c
+++ b/plugins/am-project/am-properties.c
@@ -61,7 +61,7 @@ static AmpPropertyInfo AmpGroupProperties[] = {
 	{{N_("Objective C compiler flags:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, AM_TOKEN__OBJCFLAGS, 0, NULL},
 	{{N_("Lex/Flex flags:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, AM_TOKEN__LFLAGS, 0, NULL},
 	{{N_("Yacc/Bison flags:"), ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL},AM_TOKEN__YFLAGS, 0, NULL},
-	{{N_("Install directories:"), ANJUTA_PROJECT_PROPERTY_MAP, NULL, NULL}, AM_TOKEN_DIR, 0, NULL},
+	{{N_("Install directories:"), ANJUTA_PROJECT_PROPERTY_LIST, NULL, NULL}, AM_TOKEN_DIR, 0, NULL},
 	{{NULL, ANJUTA_PROJECT_PROPERTY_STRING, NULL, NULL}, 0, 0, NULL}};
 
 static GList* AmpGroupPropertyList = NULL;
@@ -127,11 +127,12 @@ amp_create_property_list (GList **list, AmpPropertyInfo *info)
  *---------------------------------------------------------------------------*/
 
 AnjutaProjectPropertyInfo *
-amp_property_new (AnjutaTokenType type, gint position, const gchar *value, AnjutaToken *token)
+amp_property_new (const gchar *name, AnjutaTokenType type, gint position, const gchar *value, AnjutaToken *token)
 {
 	AmpPropertyInfo *prop;
 
 	prop = g_slice_new0(AmpPropertyInfo);
+	if (name != NULL) prop->base.name = g_strdup (name);
 	prop->base.value = g_strdup (value);
 	prop->token = token;
 	prop->token_type = type;
@@ -145,6 +146,10 @@ amp_property_free (AnjutaProjectPropertyInfo *prop)
 {
 	if (prop->override != NULL)
 	{
+		if ((prop->name != NULL) && (prop->name != ((AmpPropertyInfo *)(prop->override->data))->base.name))
+		{
+			g_free (prop->name);
+		}
 		if ((prop->value != NULL) && (prop->value != ((AmpPropertyInfo *)(prop->override->data))->base.value))
 		{
 			g_free (prop->value);
@@ -174,7 +179,7 @@ amp_node_property_set (AnjutaProjectNode *node, gint token_type, gint position,
 			prop = anjuta_project_property_lookup (*properties, list);
 			if (prop == NULL)
 			{
-				prop = (AnjutaProjectPropertyInfo *)amp_property_new (token_type, position, NULL, token);
+				prop = (AnjutaProjectPropertyInfo *)amp_property_new (NULL, token_type, position, NULL, token);
 				
 				*properties = anjuta_project_property_insert (*properties, list, prop);
 			}
@@ -195,21 +200,23 @@ amp_node_property_add (AnjutaProjectNode *node, AmpPropertyInfo *prop)
 	AnjutaProjectPropertyItem *list;
 	gboolean set = FALSE;
 
-	g_message ("properties %p", *properties);
 	for (list = anjuta_project_property_first (*properties); list != NULL; list = anjuta_project_property_next (list))
 	{
 		AmpPropertyInfo *info = (AmpPropertyInfo *)anjuta_project_property_get_info (list);
 
 		if ((info->token_type == prop->token_type) && (info->position == prop->position))
 		{
-			AnjutaProjectPropertyInfo *old_prop;
-
-			old_prop = anjuta_project_property_lookup (*properties, list);
-			if (old_prop != NULL)
+			if (info->base.type != ANJUTA_PROJECT_PROPERTY_LIST)
 			{
-				*properties = anjuta_project_property_remove (*properties, list);
-				g_message ("remove properties %p", *properties);
-				amp_property_free (old_prop);
+				/* Replace property */
+				AnjutaProjectPropertyInfo *old_prop;
+
+				old_prop = anjuta_project_property_lookup (*properties, list);
+				if (old_prop != NULL)
+				{
+					*properties = anjuta_project_property_remove (*properties, list);
+					amp_property_free (old_prop);
+				}
 			}
 			*properties = anjuta_project_property_insert (*properties, list, (AnjutaProjectPropertyInfo *)prop);
 			set = TRUE;
diff --git a/plugins/am-project/am-properties.h b/plugins/am-project/am-properties.h
index d017e49..a0b31e4 100644
--- a/plugins/am-project/am-properties.h
+++ b/plugins/am-project/am-properties.h
@@ -28,7 +28,7 @@
 
 G_BEGIN_DECLS
 
-AnjutaProjectPropertyInfo *amp_property_new (AnjutaTokenType type, gint position, const gchar *value, AnjutaToken *token);
+AnjutaProjectPropertyInfo *amp_property_new (const gchar *name, AnjutaTokenType type, gint position, const gchar *value, AnjutaToken *token);
 void amp_property_free (AnjutaProjectPropertyInfo *prop);
 
 gboolean amp_node_property_set (AnjutaProjectNode *target, gint token_type, gint position, const gchar *value, AnjutaToken *token);



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