[anjuta/newproject: 176/189] Make properties dialog more general



commit d278bfb498b067e47a094738299991db75059c2f
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Wed Apr 21 22:28:31 2010 +0200

    Make properties dialog more general

 plugins/am-project/Makefile.am                     |    2 +-
 plugins/am-project/am-project.ui                   |  411 --------------------
 plugins/project-manager/Makefile.am                |    2 +-
 plugins/project-manager/dialogs.c                  |  248 ++++++-------
 plugins/project-manager/dialogs.h                  |    5 +-
 plugins/project-manager/plugin.c                   |  132 +------
 plugins/project-manager/plugin.h                   |    3 -
 .../{create_dialogs.ui => pm_dialogs.ui}           |   85 ++++
 plugins/project-manager/project-util.c             |    2 +-
 plugins/project-manager/project.c                  |   83 +++--
 plugins/project-manager/project.h                  |    6 +-
 11 files changed, 258 insertions(+), 721 deletions(-)
---
diff --git a/plugins/am-project/Makefile.am b/plugins/am-project/Makefile.am
index d1fc213..d2e2dd9 100644
--- a/plugins/am-project/Makefile.am
+++ b/plugins/am-project/Makefile.am
@@ -4,7 +4,7 @@ plugin_ui_DATA =
 
 # Plugin glade file
 plugin_gladedir = $(anjuta_glade_dir)
-plugin_glade_DATA = am-project.ui
+plugin_glade_DATA =
 
 # Plugin icon file
 plugin_pixmapsdir = $(anjuta_image_dir)
diff --git a/plugins/project-manager/Makefile.am b/plugins/project-manager/Makefile.am
index 825b2bd..2a387cb 100644
--- a/plugins/project-manager/Makefile.am
+++ b/plugins/project-manager/Makefile.am
@@ -4,7 +4,7 @@ project_ui_DATA = anjuta-project-manager.xml
 
 # Plugin glade file
 project_gladedir = $(anjuta_glade_dir)
-project_glade_DATA = create_dialogs.ui
+project_glade_DATA = pm_dialogs.ui
 
 # Plugin Icon file
 project_pixmapsdir = $(anjuta_image_dir)
diff --git a/plugins/project-manager/dialogs.c b/plugins/project-manager/dialogs.c
index 11cb30c..59a2ff6 100644
--- a/plugins/project-manager/dialogs.c
+++ b/plugins/project-manager/dialogs.c
@@ -31,7 +31,7 @@
 #include <libanjuta/anjuta-debug.h>
 #include <libanjuta/anjuta-utils.h>
 
-#define GLADE_FILE  PACKAGE_DATA_DIR "/glade/am-project.ui"
+#define GLADE_FILE  PACKAGE_DATA_DIR "/glade/create_dialogs.ui"
 
 /* Types
   *---------------------------------------------------------------------------*/
@@ -56,24 +56,6 @@ enum {
 /* Private functions
  *---------------------------------------------------------------------------*/
 
-static AnjutaProjectNodeInfo *
-project_get_type_info (IAnjutaProject *project, AnjutaProjectNodeType type)
-{
-	GList *item;
-	AnjutaProjectNodeInfo *info = NULL;
-
-	g_message ("get node info list %p", ianjuta_project_get_node_info (project, NULL));
-	for (item = ianjuta_project_get_node_info (project, NULL); item != NULL; item = g_list_next (item))
-	{
-		info = (AnjutaProjectNodeInfo *)item->data;
-
-		g_message ("check node name %s type %x look for %x", info->name, info->type, type);
-		if (info->type == type) break;
-	}
-
-	return info;
-}
-
 static void
 on_project_widget_destroy (GtkWidget *wid, ConfigureProjectDialog *dlg)
 {
@@ -192,162 +174,158 @@ add_label (const gchar *display_name, const gchar *value, GtkWidget *table, gint
 	*position = *position + 1;
 }
 
-/* Public functions
- *---------------------------------------------------------------------------*/
-
-GtkWidget *
-pm_configure_project_dialog (IAnjutaProject *project, AnjutaProjectNode *node, GError **error)
+static GtkWidget *
+create_properties_table (IAnjutaProject *project, AnjutaProjectNode *node)
 {
-	GtkBuilder *bxml = gtk_builder_new ();
+	GtkBuilder *bxml;
 	ConfigureProjectDialog *dlg;
-	GtkWidget *table;
-	gint pos;
-	gchar *name;
-	AnjutaProjectProperty *prop;
-
-	bxml = anjuta_util_builder_new (GLADE_FILE, NULL);
-	if (!bxml) return NULL;
-
-	dlg = g_new0 (ConfigureProjectDialog, 1);
-	anjuta_util_builder_get_objects (bxml,
-	    							"general_properties_table", &table,
-	                                NULL);
-	dlg->top_level = table;
-	g_object_ref (table);
-	g_signal_connect (table, "destroy", G_CALLBACK (on_project_widget_destroy), dlg);
-
-	pos = 0;
-	name = g_file_get_parse_name (anjuta_project_node_get_file (node));
-	add_label (_("Path:"), name, table, &pos);
-	g_free (name);
-
-	for (prop = anjuta_project_node_first_valid_property (node); prop != NULL; prop = anjuta_project_property_next (prop))
-	{
-		add_entry (project, NULL, prop, table, &pos);
-	}
-	
-	/*add_entry (project, NULL, _("Name:"), AMP_PROPERTY_NAME, table, 1);
-	add_entry (project, NULL, _("Version:"), AMP_PROPERTY_VERSION, table, 2);
-	add_entry (project, NULL, _("Bug report URL:"), AMP_PROPERTY_BUG_REPORT, table, 3);
-	add_entry (project, NULL, _("Package name:"), AMP_PROPERTY_TARNAME, table, 4);
-	add_entry (project, NULL, _("URL:"), AMP_PROPERTY_URL, table, 5);*/
-	
-	gtk_widget_show_all (table);
-	g_object_unref (bxml);
-
-	return table;
-}
-
-GtkWidget *
-pm_configure_group_dialog (IAnjutaProject *project, AnjutaProjectNode *group, GError **error)
-{
-	GtkBuilder *bxml = gtk_builder_new ();
 	GtkWidget *properties;
 	GtkWidget *main_table;
-	gint main_pos;
 	GtkWidget *extra_table;
+	GtkWidget *extra_expand;
+	gint main_pos;
 	gint extra_pos;
-	ConfigureProjectDialog *dlg;
-	gchar *name;
-	AnjutaProjectProperty *prop;
+	gchar *path;
+	GList *item;
+	AnjutaProjectNodeType type;
+	AnjutaProjectNodeInfo* node_info;
+	gboolean single;
+	AnjutaProjectProperty *valid_prop;
+
 
 	bxml = anjuta_util_builder_new (GLADE_FILE, NULL);
 	if (!bxml) return NULL;
 
 	dlg = g_new0 (ConfigureProjectDialog, 1);
 	anjuta_util_builder_get_objects (bxml,
-	                                "properties", &properties,
-	    							"main_table", &main_table,
-	    							"extra_table", &extra_table,
-	                                NULL);
+									"properties", &properties,
+									"main_table", &main_table,
+									"extra_table", &extra_table,
+									"extra_expand", &extra_expand,
+									NULL);
 	dlg->top_level = properties;
 	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 (anjuta_project_node_get_file (group));
-	add_label (_("Name:"), name, main_table, &main_pos);
-	g_free (name);
 
-	for (prop = anjuta_project_node_first_valid_property (group); prop != NULL; prop = anjuta_project_property_next (prop))
+	/* Always display node name */
+	path = g_file_get_path (anjuta_project_node_get_file (node));
+	add_label (_("Full Name:"), path, main_table, &main_pos);
+	g_free (path);
+
+	/* Display node type only if several types are possible */
+	node_info = NULL;
+	single = TRUE;
+	type = anjuta_project_node_get_type (node);
+	for (item = ianjuta_project_get_node_info (project, NULL); item != NULL; item = g_list_next (item))
 	{
-		AnjutaProjectProperty *item;
+		AnjutaProjectNodeInfo* info = (AnjutaProjectNodeInfo *)item->data;
 
-		item = anjuta_project_node_get_property (group, prop);
-		if (item != NULL)
+		if (info->type == type)
 		{
-			add_entry (project, group, item, main_table, &main_pos);
+			node_info = info;
 		}
-		else
+		else if ((info->type & ANJUTA_PROJECT_TYPE_MASK) == (type & ANJUTA_PROJECT_TYPE_MASK))
+		{
+			single = FALSE;
+		}
+		if (!single && (node_info != NULL))
 		{
-			add_entry (project, group, prop, extra_table, &extra_pos);
+			add_label (_("Type:"), anjuta_project_node_info_name (node_info), main_table, &main_pos);
+			break;
 		}
 	}
-	
-	gtk_widget_show_all (properties);
-	g_object_unref (bxml);
-	
-	return properties;
-}
-
-GtkWidget *
-pm_configure_target_dialog (IAnjutaProject *project, AnjutaProjectNode *target, GError **error)
-{
-	GtkBuilder *bxml = gtk_builder_new ();
-	GtkWidget *properties;
-	GtkWidget *main_table;
-	gint main_pos;
-	GtkWidget *extra_table;
-	gint extra_pos;
-	ConfigureProjectDialog *dlg;
-	AnjutaProjectNodeInfo* info;
-	const gchar *name;
-	AnjutaProjectProperty *prop;
-
-	bxml = anjuta_util_builder_new (GLADE_FILE, NULL);
-	if (!bxml) return NULL;
 
-	dlg = g_new0 (ConfigureProjectDialog, 1);
-	anjuta_util_builder_get_objects (bxml,
-	                                "properties", &properties,
-	    							"main_table", &main_table,
-	    							"extra_table", &extra_table,
-	                                NULL);
-	dlg->top_level = properties;
-	g_object_ref (properties);
-	g_signal_connect (properties, "destroy", G_CALLBACK (on_project_widget_destroy), dlg);
-
-	main_pos = 0;
-	extra_pos = 0;
-	name = anjuta_project_node_get_name (target);
-	add_label (_("Name:"), name, main_table, &main_pos);
-	info = project_get_type_info (project, anjuta_project_node_get_type (target));;
-	add_label (_("Type:"), anjuta_project_node_info_name (info), main_table, &main_pos);
-
-	for (prop = anjuta_project_node_first_valid_property (target); prop != NULL; prop = anjuta_project_property_next (prop))
+	/* Display other node properties */
+	single = FALSE;
+	for (valid_prop = anjuta_project_node_first_valid_property (node); valid_prop != NULL; valid_prop = anjuta_project_property_next (valid_prop))
 	{
-		AnjutaProjectProperty *item;
+		AnjutaProjectProperty *prop;
 
-		item = anjuta_project_node_get_property (target, prop);
-		if (item != NULL)
+		prop = anjuta_project_node_get_property (node, valid_prop);
+		if (prop != NULL)
 		{
-			add_entry (project, target, item, main_table, &main_pos);
+			/* This property has been set, display it in the main part */
+			add_entry (project, node, prop, main_table, &main_pos);
 		}
 		else
 		{
-			add_entry (project, target, prop, extra_table, &extra_pos);
+			/* This property has not been set, hide it by default */
+			add_entry (project, node, valid_prop, extra_table, &extra_pos);
+			single = TRUE;
 		}
 	}
-	
+
 	gtk_widget_show_all (properties);
+	
+	/* Hide expander if it is empty */
+	if (!single) gtk_widget_hide (extra_expand);
+	
 	g_object_unref (bxml);
 	
 	return properties;
 }
 
-GtkWidget *
-pm_configure_source_dialog (IAnjutaProject *project, AnjutaProjectNode *source, GError **error)
+static void
+on_properties_dialog_response (GtkDialog *win,
+							   gint id,
+							   GtkWidget **dialog)
 {
-	return NULL;
+	gtk_widget_destroy (*dialog);
+	*dialog = NULL;
 }
+
+/* Public functions
+ *---------------------------------------------------------------------------*/
+
+gboolean
+pm_project_create_properties_dialog (IAnjutaProject *project, GtkWidget **dialog, GtkWindow *parent, AnjutaProjectNode *node)
+{
+	const char *title;
+	GtkWidget *properties;
+
+	g_return_val_if_fail (node != NULL, FALSE);
+	g_return_val_if_fail (*dialog == NULL, FALSE);
+	
+	switch (anjuta_project_node_get_type (node))
+	{
+	case ANJUTA_PROJECT_ROOT:
+		title = _("Project properties");
+		break;
+	case ANJUTA_PROJECT_GROUP:
+		title = _("Group properties");
+		break;
+	case ANJUTA_PROJECT_TARGET:
+		title = _("Target properties");
+		break;
+	case ANJUTA_PROJECT_SOURCE:
+		title = _("Source properties");
+		break;
+	default:
+		return FALSE;
+	}
+
+	properties = create_properties_table (project, node);
+
+	if (properties)
+	{
+		*dialog = gtk_dialog_new_with_buttons (title,
+							   parent,
+							   GTK_DIALOG_DESTROY_WITH_PARENT,
+							   GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, NULL);
+
+		g_signal_connect (*dialog, "response",
+						G_CALLBACK (on_properties_dialog_response),
+						dialog);
+
+		gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG(*dialog))),
+				properties);
+		gtk_window_set_default_size (GTK_WINDOW (*dialog), 450, -1);
+		gtk_widget_show (*dialog);
+	}
+
+	return *dialog != NULL;
+}
+
diff --git a/plugins/project-manager/dialogs.h b/plugins/project-manager/dialogs.h
index c66029a..f2e13a3 100644
--- a/plugins/project-manager/dialogs.h
+++ b/plugins/project-manager/dialogs.h
@@ -27,10 +27,7 @@
 
 G_BEGIN_DECLS
 
-GtkWidget *pm_configure_project_dialog (IAnjutaProject *project, AnjutaProjectNode *node, GError **error);
-GtkWidget *pm_configure_group_dialog (IAnjutaProject *project, AnjutaProjectNode *group, GError **error);
-GtkWidget *pm_configure_target_dialog (IAnjutaProject *project, AnjutaProjectNode *target, GError **error);
-GtkWidget *pm_configure_source_dialog (IAnjutaProject *project, AnjutaProjectNode *target, GError **error);
+gboolean pm_project_create_properties_dialog (IAnjutaProject *project, GtkWidget **dialog, GtkWindow *parent, AnjutaProjectNode *node);
 
 G_END_DECLS
 
diff --git a/plugins/project-manager/plugin.c b/plugins/project-manager/plugin.c
index 51f011a..44edb67 100644
--- a/plugins/project-manager/plugin.c
+++ b/plugins/project-manager/plugin.c
@@ -366,129 +366,6 @@ update_operation_begin (ProjectManagerPlugin *plugin)
 										  NULL);
 }
 
-/* Properties dialogs functions
- *---------------------------------------------------------------------------*/
-
-static void
-on_properties_dialog_response (GtkDialog *win,
-							   gint id,
-							   GtkWidget **dialog)
-{
-	gtk_widget_destroy (*dialog);
-	*dialog = NULL;
-}
-
-static void
-project_manager_create_properties_dialog (ProjectManagerPlugin *plugin,
-    									  GtkWidget **dialog,
-    								      const gchar *title,
-    									  GtkWidget *properties)
-{
-	*dialog = gtk_dialog_new_with_buttons (title,
-							   GTK_WINDOW (ANJUTA_PLUGIN(plugin)->shell),
-							   GTK_DIALOG_DESTROY_WITH_PARENT,
-							   GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, NULL);
-
-	g_signal_connect (*dialog, "response",
-					  G_CALLBACK (on_properties_dialog_response),
-					  dialog);
-
-	gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG(*dialog))),
-			   properties);
-	gtk_window_set_default_size (GTK_WINDOW (*dialog), 450, -1);
-	gtk_widget_show (*dialog);
-}
-
-/* Display properties dialog. These dialogs are not modal, so a pointer on each
- * dialog is kept with in node data to be able to destroy them if the node is
- * removed. It is useful to put the dialog at the top if the same target is
- * selected while the corresponding dialog already exist instead of creating
- * two times the same dialog.
- * The project properties dialog is display if the node iterator is NULL. */
-
-static void
-project_manager_show_node_properties_dialog (ProjectManagerPlugin *plugin,
-    									GbfTreeData *data)
-{
-	if (data == NULL) return;
-
-	if (data->is_shortcut) data = data->shortcut;
-	
-	if (data->properties_dialog != NULL)
-	{
-		/* Show already existing dialog */
-		gtk_window_present (GTK_WINDOW (data->properties_dialog));
-	}
-	else
-	{
-		GtkWidget *properties = NULL;
-		const char *title;
-		AnjutaProjectNode *node;
-
-		switch (data->type)
-		{
-		case GBF_TREE_NODE_GROUP:
-			title = _("Group properties");
-			node = anjuta_pm_project_get_node (plugin->project, data);
-			if (node != NULL)
-			{
-				properties = anjuta_pm_project_configure (plugin->project, node);
-
-				if (properties == NULL)
-				{
-					anjuta_util_dialog_info (GTK_WINDOW (ANJUTA_PLUGIN(plugin)->shell),
-								 _("No properties available for this group"));
-				}
-			}
-			break;
-		case GBF_TREE_NODE_TARGET:
-			title = _("Target properties");
-			node = anjuta_pm_project_get_node (plugin->project, data);
-			if (node != NULL)
-			{
-				properties = anjuta_pm_project_configure (plugin->project, node);
-
-				if (properties == NULL)
-				{
-					anjuta_util_dialog_info (GTK_WINDOW (ANJUTA_PLUGIN(plugin)->shell),
-							 _("No properties available for this target"));
-				}
-			}
-			break;
-		default:
-			break;
-		}
-
-		if (properties)
-		{
-			project_manager_create_properties_dialog(plugin,
-			    &data->properties_dialog,
-		    	title,
-		    	properties);
-		}
-	}
-}
-
-static void
-project_manager_show_project_properties_dialog (ProjectManagerPlugin *plugin)
-{
-	/* Project configuration dialog */
-	
-	if (plugin->properties_dialog != NULL)
-	{
-		/* Show already existing dialog */
-		gtk_window_present (GTK_WINDOW (plugin->properties_dialog));
-	}
-	else
-	{
-		project_manager_create_properties_dialog(plugin,
-		    &plugin->properties_dialog,
-		    _("Project properties"),
-			anjuta_pm_project_configure (plugin->project, NULL));
-	}
-}
-
-
 /* GUI callbacks
  *---------------------------------------------------------------------------*/
 
@@ -527,7 +404,7 @@ on_refresh (GtkAction *action, ProjectManagerPlugin *plugin)
 static void
 on_properties (GtkAction *action, ProjectManagerPlugin *plugin)
 {
-	project_manager_show_project_properties_dialog (plugin); 
+	anjuta_pm_project_show_properties_dialog (plugin->project, NULL);
 }
 
 static void
@@ -640,7 +517,7 @@ on_popup_properties (GtkAction *action, ProjectManagerPlugin *plugin)
 		{
 			GbfTreeData *data = (GbfTreeData *)(item->data);
 
-			project_manager_show_node_properties_dialog (plugin, data);
+			anjuta_pm_project_show_properties_dialog (plugin->project, data);
 		}
 		g_list_free (selected);
 	}
@@ -1530,10 +1407,6 @@ project_manager_unload_gbf (ProjectManagerPlugin *pm_plugin)
 				g_list_free (to_remove);
 		}
 		
-		/* Remove project properties dialogs */
-		if (pm_plugin->properties_dialog != NULL) gtk_widget_destroy (pm_plugin->properties_dialog);
-		pm_plugin->properties_dialog = NULL;
-		
 		/* Release project */
 		anjuta_pm_project_unload (pm_plugin->project, NULL);
 		update_ui (pm_plugin);
@@ -1689,7 +1562,6 @@ project_manager_plugin_activate_plugin (AnjutaPlugin *plugin)
 	
 	pm_plugin->scrolledwindow = scrolled_window;
 	pm_plugin->view = view;
-	pm_plugin->properties_dialog = NULL;
 	
 	/* Action groups */
 	pm_plugin->pm_action_group = 
diff --git a/plugins/project-manager/plugin.h b/plugins/project-manager/plugin.h
index 67d0521..1422735 100644
--- a/plugins/project-manager/plugin.h
+++ b/plugins/project-manager/plugin.h
@@ -75,9 +75,6 @@ struct _ProjectManagerPlugin{
 	/* Idle callback id */
 	guint close_project_idle;
 	
-	/* project properties dialog */
-	GtkWidget *properties_dialog;
-
 	/* project is loading */
 	gboolean busy;
 };
diff --git a/plugins/project-manager/create_dialogs.ui b/plugins/project-manager/pm_dialogs.ui
similarity index 93%
rename from plugins/project-manager/create_dialogs.ui
rename to plugins/project-manager/pm_dialogs.ui
index fe00719..0074090 100644
--- a/plugins/project-manager/create_dialogs.ui
+++ b/plugins/project-manager/pm_dialogs.ui
@@ -828,4 +828,89 @@
       <action-widget response="-5">ok_package_button</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkVBox" id="properties">
+    <property name="visible">True</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkTable" id="main_table">
+        <property name="visible">True</property>
+        <property name="n_rows">3</property>
+        <property name="n_columns">2</property>
+        <property name="column_spacing">12</property>
+        <property name="row_spacing">6</property>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">False</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkExpander" id="extra_expand">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkTable" id="extra_table">
+            <property name="visible">True</property>
+            <property name="n_rows">3</property>
+            <property name="n_columns">2</property>
+            <property name="column_spacing">12</property>
+            <property name="row_spacing">6</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+        </child>
+        <child type="label">
+          <object class="GtkLabel" id="label13">
+            <property name="visible">True</property>
+            <property name="yalign">1</property>
+            <property name="label" translatable="yes">More options:</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">False</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+    <child>
+      <placeholder/>
+    </child>
+  </object>
 </interface>
diff --git a/plugins/project-manager/project-util.c b/plugins/project-manager/project-util.c
index d29399f..4b0b239 100644
--- a/plugins/project-manager/project-util.c
+++ b/plugins/project-manager/project-util.c
@@ -38,7 +38,7 @@
 
 #define ICON_SIZE 16
 
-#define GLADE_FILE PACKAGE_DATA_DIR  "/glade/create_dialogs.ui"
+#define GLADE_FILE PACKAGE_DATA_DIR  "/glade/pm_dialogs.ui"
 
 enum {
     COLUMN_FILE,
diff --git a/plugins/project-manager/project.c b/plugins/project-manager/project.c
index 6e98242..a876c5a 100644
--- a/plugins/project-manager/project.c
+++ b/plugins/project-manager/project.c
@@ -490,6 +490,10 @@ anjuta_pm_project_unload (AnjutaPmProject *project, GError **error)
 	g_object_unref (project->project);
 	project->project = NULL;
 
+	/* Remove project properties dialogs */
+	if (project->properties_dialog != NULL) gtk_widget_destroy (project->properties_dialog);
+	project->properties_dialog = NULL;
+	
 	return TRUE;
 }
 
@@ -501,40 +505,6 @@ anjuta_pm_project_refresh (AnjutaPmProject *project, GError **error)
 	return TRUE;
 }
 
-GtkWidget *
-anjuta_pm_project_configure (AnjutaPmProject *project, AnjutaProjectNode *node)
-{
-	GtkWidget *properties;
-	
-	if (node == NULL)
-	{
-		properties = pm_configure_project_dialog (project->project, node, NULL);
-	}
-	else
-	{
-		switch (anjuta_project_node_get_type (node))
-		{
-		case ANJUTA_PROJECT_ROOT:
-			properties = pm_configure_project_dialog (project->project, node, NULL);
-			break;
-		case ANJUTA_PROJECT_GROUP:
-			properties = pm_configure_group_dialog (project->project, node, NULL);
-			break;
-		case ANJUTA_PROJECT_TARGET:
-			properties = pm_configure_target_dialog (project->project, node, NULL);
-			break;
-		case ANJUTA_PROJECT_SOURCE:
-			properties = pm_configure_source_dialog (project->project, node, NULL);
-			break;
-		default:
-			properties = NULL;
-			break;
-		}
-	}
-	
-	return properties;
-}
-
 IAnjutaProjectCapabilities
 anjuta_pm_project_get_capabilities (AnjutaPmProject *project)
 {
@@ -688,6 +658,49 @@ anjuta_pm_project_get_node_from_file (AnjutaPmProject *project, AnjutaProjectNod
 	return NULL;
 }
 
+/* Display properties dialog. These dialogs are not modal, so a pointer on each
+ * dialog is kept with in node data to be able to destroy them if the node is
+ * removed. It is useful to put the dialog at the top if the same target is
+ * selected while the corresponding dialog already exist instead of creating
+ * two times the same dialog.
+ * The project properties dialog is display if the node iterator is NULL. */
+
+gboolean
+anjuta_pm_project_show_properties_dialog (AnjutaPmProject *project, GbfTreeData *data)
+{
+	GtkWidget **dialog;
+	AnjutaProjectNode *node;
+	
+	if (data == NULL)
+	{
+		/* Show project properties dialog */
+		dialog = &project->properties_dialog;
+		node = project->root;
+	}
+	else
+	{
+		/* Show node properties dialog */
+		dialog = &data->properties_dialog;
+		node = anjuta_pm_project_get_node (project, data);
+	}
+	
+	if (*dialog != NULL)
+	{
+		/* Show already existing dialog */
+		gtk_window_present (GTK_WINDOW (*dialog));
+	}
+	else
+	{
+		pm_project_create_properties_dialog (
+			project->project,
+			dialog,
+			GTK_WINDOW (project->plugin->shell),
+			node);
+	}
+
+	return TRUE;
+}
+
 /* Implement GObject
  *---------------------------------------------------------------------------*/
 
@@ -699,6 +712,8 @@ anjuta_pm_project_init (AnjutaPmProject *project)
 	project->model = gbf_project_model_new (NULL);
 	project->plugin = NULL;
 
+	project->properties_dialog = NULL;
+	
 	project->job_queue = NULL;
 	project->work_queue = NULL;
 	project->done_queue = NULL;
diff --git a/plugins/project-manager/project.h b/plugins/project-manager/project.h
index c30f4f6..6d05aab 100644
--- a/plugins/project-manager/project.h
+++ b/plugins/project-manager/project.h
@@ -61,6 +61,9 @@ struct _AnjutaPmProject
 
 	AnjutaProjectNode *root;
 	
+	/* project properties dialog */
+	GtkWidget *properties_dialog;
+	
 	/* Thread queue */
 	GQueue *job_queue;
 	GAsyncQueue *work_queue;
@@ -80,7 +83,6 @@ gboolean anjuta_pm_project_load (AnjutaPmProject *project, GFile *file, GError *
 gboolean anjuta_pm_project_unload (AnjutaPmProject *project, GError **error);
 gboolean anjuta_pm_project_refresh (AnjutaPmProject *project, GError **error);
 
-GtkWidget *anjuta_pm_project_configure (AnjutaPmProject *project, AnjutaProjectNode *node);
 IAnjutaProjectCapabilities anjuta_pm_project_get_capabilities (AnjutaPmProject *project);
 GList *anjuta_pm_project_get_node_info (AnjutaPmProject *project);
 
@@ -101,6 +103,8 @@ GbfProjectModel *anjuta_pm_project_get_model (AnjutaPmProject *project);
 AnjutaProjectNode *anjuta_pm_project_get_node (AnjutaPmProject *project, GbfTreeData *data);
 AnjutaProjectNode *anjuta_pm_project_get_node_from_file (AnjutaPmProject *project, AnjutaProjectNodeType type, GFile *file);
 
+gboolean anjuta_pm_project_show_properties_dialog (AnjutaPmProject *project, GbfTreeData *data);
+
 G_END_DECLS
 
 #endif /* _PROJECT_H_ */



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