[anjuta] am-project: bgo #681073 - Anjuta crashes when switching git branches of the current project on the c



commit cd7999fd2d924e29641c97c0f343083067148c80
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Wed Oct 17 22:31:14 2012 +0200

    am-project: bgo #681073 - Anjuta crashes when switching git branches of the current project on the commandline

 plugins/am-project/am-project.c  |   74 ++++++++++++++------------------------
 plugins/am-project/amp-group.c   |   22 ++++++++++--
 plugins/am-project/amp-module.c  |   16 ++++----
 plugins/am-project/amp-node.c    |   24 ++++++++++++
 plugins/am-project/amp-node.h    |    4 ++
 plugins/am-project/amp-package.c |   31 ++++++++++++----
 plugins/am-project/amp-target.c  |   25 +++++++++----
 7 files changed, 122 insertions(+), 74 deletions(-)
---
diff --git a/plugins/am-project/am-project.c b/plugins/am-project/am-project.c
index 48589a5..793220f 100644
--- a/plugins/am-project/am-project.c
+++ b/plugins/am-project/am-project.c
@@ -241,6 +241,20 @@ static AmpNodeInfo AmpNodeInformations[] = {
 	NULL}
 };
 
+/* Types
+ *---------------------------------------------------------------------------*/
+
+static void iproject_iface_init(IAnjutaProjectIface* iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (AmpProject,
+                                amp_project,
+                                AMP_TYPE_ROOT_NODE,
+                                0,
+                                G_IMPLEMENT_INTERFACE_DYNAMIC (IANJUTA_TYPE_PROJECT,
+                                                               iproject_iface_init));
+
+
+
 /* Properties
  *---------------------------------------------------------------------------*/
 
@@ -1605,45 +1619,6 @@ amp_project_update_node (AnjutaProjectNode *key, AnjutaProjectNode *value, GHash
 	}
 }
 
-static AnjutaProjectNode *
-amp_project_duplicate_node (AnjutaProjectNode *old_node)
-{
-	AnjutaProjectNode *new_node;
-
-	/* Create new node */
-	new_node = g_object_new (G_TYPE_FROM_INSTANCE (old_node), NULL);
-	if (old_node->file != NULL) new_node->file = g_file_dup (old_node->file);
-	if (old_node->name != NULL) new_node->name = g_strdup (old_node->name);
-	if (anjuta_project_node_get_node_type (old_node) == ANJUTA_PROJECT_TARGET)
-	{
-		amp_target_node_set_type (AMP_TARGET_NODE (new_node), anjuta_project_node_get_full_type (old_node));
-	}
-	if (anjuta_project_node_get_node_type (old_node) == ANJUTA_PROJECT_PACKAGE)
-	{
-		// FIXME: We should probably copy the version number too because it will not
-		// be updated when the node is reloaded. So later when updating the old_node,
-		// the value will be overwritten with the new node empty value.
-		amp_package_node_add_token (AMP_PACKAGE_NODE (new_node), amp_package_node_get_token (AMP_PACKAGE_NODE (old_node)));
-	}
-	if (anjuta_project_node_get_node_type (old_node) == ANJUTA_PROJECT_GROUP)
-	{
-
-		amp_group_node_add_token (AMP_GROUP_NODE (new_node), amp_group_node_get_first_token (AMP_GROUP_NODE (old_node), AM_GROUP_TOKEN_CONFIGURE), AM_GROUP_TOKEN_CONFIGURE);
-		amp_group_node_add_token (AMP_GROUP_NODE (new_node), amp_group_node_get_first_token (AMP_GROUP_NODE (old_node), AM_GROUP_TOKEN_SUBDIRS), AM_GROUP_TOKEN_SUBDIRS);
-		amp_group_node_add_token (AMP_GROUP_NODE (new_node), amp_group_node_get_first_token (AMP_GROUP_NODE (old_node), AM_GROUP_TOKEN_DIST_SUBDIRS), AM_GROUP_TOKEN_DIST_SUBDIRS);
-
-	}
-	if (anjuta_project_node_parent (old_node) == NULL)
-	{
-		// FIXME: It would be better to write a duplicate function to avoid this code
-		((AmpProject *)new_node)->lang_manager = (((AmpProject *)old_node)->lang_manager != NULL) ? g_object_ref (((AmpProject *)old_node)->lang_manager) : NULL;
-	}
-	/* Keep old parent, Needed for source node to find project root node */
-	new_node->parent = old_node->parent;
-
-	return new_node;
-}
-
 /* Public functions
  *---------------------------------------------------------------------------*/
 
@@ -2123,7 +2098,7 @@ amp_load_setup (PmJob *job)
 {
 	//anjuta_project_node_check (job->node);
 	pm_job_set_parent (job, anjuta_project_node_parent (job->node));
-	job->proxy = amp_project_duplicate_node (job->node);
+	job->proxy = ANJUTA_PROJECT_NODE (amp_node_copy (AMP_NODE (job->node)));
 
 	return TRUE;
 }
@@ -2565,6 +2540,17 @@ amp_project_update (AmpNode *node, AmpNode *new_node)
 	return TRUE;
 }
 
+static AmpNode *
+amp_project_copy (AmpNode *old_node)
+{
+	AmpNode *new_node;
+
+	new_node = AMP_NODE_CLASS (amp_project_parent_class)->copy (old_node);
+	((AmpProject *)new_node)->lang_manager = (((AmpProject *)old_node)->lang_manager != NULL) ? g_object_ref (((AmpProject *)old_node)->lang_manager) : NULL;
+
+	return new_node;
+}
+
 
 /* GObject implementation
  *---------------------------------------------------------------------------*/
@@ -2640,6 +2626,7 @@ amp_project_class_init (AmpProjectClass *klass)
 	node_class->load = amp_project_load;
 	node_class->save = amp_project_save;
 	node_class->update = amp_project_update;
+	node_class->copy = amp_project_copy;
 }
 
 static void
@@ -2647,13 +2634,6 @@ amp_project_class_finalize (AmpProjectClass *klass)
 {
 }
 
-G_DEFINE_DYNAMIC_TYPE_EXTENDED (AmpProject,
-                                amp_project,
-                                AMP_TYPE_ROOT_NODE,
-                                0,
-                                G_IMPLEMENT_INTERFACE_DYNAMIC (IANJUTA_TYPE_PROJECT,
-                                                               iproject_iface_init));
-
 void
 amp_project_register (GTypeModule *module)
 {
diff --git a/plugins/am-project/amp-group.c b/plugins/am-project/amp-group.c
index 6d1bcf8..028061d 100644
--- a/plugins/am-project/amp-group.c
+++ b/plugins/am-project/amp-group.c
@@ -43,6 +43,11 @@
 #include <string.h>
 #include <ctype.h>
 
+/* Types
+ *---------------------------------------------------------------------------*/
+
+G_DEFINE_DYNAMIC_TYPE (AmpGroupNode, amp_group_node, AMP_TYPE_NODE);
+
 
 /* Helper functions
  *---------------------------------------------------------------------------*/
@@ -714,6 +719,19 @@ amp_group_node_update (AmpNode *node, AmpNode *new_node)
 	return TRUE;
 }
 
+static AmpNode *
+amp_group_node_copy (AmpNode *old_node)
+{
+	AmpNode *new_node;
+	
+	new_node = AMP_NODE_CLASS (amp_group_node_parent_class)->copy (old_node);
+	amp_group_node_add_token (AMP_GROUP_NODE (new_node), amp_group_node_get_first_token (AMP_GROUP_NODE (old_node), AM_GROUP_TOKEN_CONFIGURE), AM_GROUP_TOKEN_CONFIGURE);
+	amp_group_node_add_token (AMP_GROUP_NODE (new_node), amp_group_node_get_first_token (AMP_GROUP_NODE (old_node), AM_GROUP_TOKEN_SUBDIRS), AM_GROUP_TOKEN_SUBDIRS);
+	amp_group_node_add_token (AMP_GROUP_NODE (new_node), amp_group_node_get_first_token (AMP_GROUP_NODE (old_node), AM_GROUP_TOKEN_DIST_SUBDIRS), AM_GROUP_TOKEN_DIST_SUBDIRS);
+
+	return new_node;
+}
+
 static gboolean
 amp_group_node_write (AmpNode *node, AmpNode *parent, AmpProject *project, GError **error)
 {
@@ -731,9 +749,6 @@ amp_group_node_erase (AmpNode *node, AmpNode *parent, AmpProject *project, GErro
 /* GObjet implementation
  *---------------------------------------------------------------------------*/
 
-
-G_DEFINE_DYNAMIC_TYPE (AmpGroupNode, amp_group_node, AMP_TYPE_NODE);
-
 static void
 amp_group_node_init (AmpGroupNode *node)
 {
@@ -797,6 +812,7 @@ amp_group_node_class_init (AmpGroupNodeClass *klass)
 	node_class->load = amp_group_node_load;
 	node_class->save = amp_group_node_save;
 	node_class->update = amp_group_node_update;
+	node_class->copy = amp_group_node_copy;
 	node_class->write = amp_group_node_write;
 	node_class->erase = amp_group_node_erase;
 }
diff --git a/plugins/am-project/amp-module.c b/plugins/am-project/amp-module.c
index 879f3b2..d0c953b 100644
--- a/plugins/am-project/amp-module.c
+++ b/plugins/am-project/amp-module.c
@@ -51,6 +51,14 @@ struct _AmpModuleNode {
 	AnjutaToken *module;
 };
 
+typedef struct _AmpModuleNodeClass AmpModuleNodeClass;
+
+struct _AmpModuleNodeClass {
+	AmpNodeClass parent_class;
+};
+
+G_DEFINE_DYNAMIC_TYPE (AmpModuleNode, amp_module_node, AMP_TYPE_NODE);
+
 
 /* Module objects
  *---------------------------------------------------------------------------*/
@@ -271,14 +279,6 @@ amp_module_node_erase (AmpNode *node, AmpNode *amp_parent, AmpProject *project,
 /* GObjet implementation
  *---------------------------------------------------------------------------*/
 
-typedef struct _AmpModuleNodeClass AmpModuleNodeClass;
-
-struct _AmpModuleNodeClass {
-	AmpNodeClass parent_class;
-};
-
-G_DEFINE_DYNAMIC_TYPE (AmpModuleNode, amp_module_node, AMP_TYPE_NODE);
-
 static void
 amp_module_node_init (AmpModuleNode *node)
 {
diff --git a/plugins/am-project/amp-node.c b/plugins/am-project/amp-node.c
index 67af6ac..cce36b0 100644
--- a/plugins/am-project/amp-node.c
+++ b/plugins/am-project/amp-node.c
@@ -214,6 +214,14 @@ amp_node_update (AmpNode *node,
   return AMP_NODE_GET_CLASS (node)->update (node, new_node);
 }
 
+AmpNode*
+amp_node_copy (AmpNode *node)
+{
+  g_return_val_if_fail (AMP_IS_NODE (node), FALSE);
+
+  return AMP_NODE_GET_CLASS (node)->copy (node);
+}
+
 gboolean
 amp_node_write (AmpNode *node,
                 AmpNode *parent,
@@ -265,6 +273,21 @@ amp_node_real_update (AmpNode *node,
 	return FALSE;
 }
 
+static AmpNode*
+amp_node_real_copy (AmpNode *old_node)
+{
+	AnjutaProjectNode *new_node;
+
+	/* Create new node */
+	new_node = g_object_new (G_TYPE_FROM_INSTANCE (old_node), NULL);
+	if (old_node->parent.file != NULL) new_node->file = g_file_dup (old_node->parent.file);
+	if (old_node->parent.name != NULL) new_node->name = g_strdup (old_node->parent.name);
+	/* Keep old parent, Needed for source node to find project root node */
+	new_node->parent = old_node->parent.parent;
+
+	return AMP_NODE (new_node);	
+}
+
 static gboolean
 amp_node_real_write (AmpNode *node,
                      AmpNode *parent,
@@ -319,6 +342,7 @@ amp_node_class_init (AmpNodeClass *klass)
 	klass->load = amp_node_real_load;
 	klass->save = amp_node_real_save;
 	klass->update = amp_node_real_update;
+	klass->copy = amp_node_real_copy;
 	klass->write = amp_node_real_write;
 	klass->erase = amp_node_real_erase;
 }
diff --git a/plugins/am-project/amp-node.h b/plugins/am-project/amp-node.h
index fddc3cc..ab282cc 100644
--- a/plugins/am-project/amp-node.h
+++ b/plugins/am-project/amp-node.h
@@ -73,6 +73,8 @@ struct _AmpNodeClass
 	gboolean					(*update)				(AmpNode *node,
 											                AmpNode *parent);
 
+	AmpNode*				    (*copy)				    (AmpNode *node);
+
 	gboolean					(*erase)				(AmpNode *node,
 											                AmpNode *parent,
 											                AmpProject *project,
@@ -115,6 +117,8 @@ gboolean						amp_node_save					(AmpNode *node,
 gboolean						amp_node_update					(AmpNode *node,
 											                      AmpNode *new_node);
 
+AmpNode*						amp_node_copy					(AmpNode *node);
+
 gboolean						amp_node_write					(AmpNode *node,
 											                       AmpNode *parent,
 											                       AmpProject *project,
diff --git a/plugins/am-project/amp-package.c b/plugins/am-project/amp-package.c
index c7873f1..1534c58 100644
--- a/plugins/am-project/amp-package.c
+++ b/plugins/am-project/amp-package.c
@@ -53,6 +53,14 @@ struct _AmpPackageNode {
 	AnjutaToken *token;
 };
 
+typedef struct _AmpPackageNodeClass AmpPackageNodeClass;
+
+struct _AmpPackageNodeClass {
+	AmpNodeClass parent_class;
+};
+
+G_DEFINE_DYNAMIC_TYPE (AmpPackageNode, amp_package_node, AMP_TYPE_NODE);
+
 
 /* Package objects
  *---------------------------------------------------------------------------*/
@@ -180,6 +188,20 @@ amp_package_node_update (AmpNode *node, AmpNode *new_node)
 	return TRUE;
 }
 
+static AmpNode *
+amp_package_node_copy (AmpNode *old_node)
+{
+	AmpNode *new_node;
+	
+	new_node = AMP_NODE_CLASS (amp_package_node_parent_class)->copy (old_node);
+	// FIXME: We should probably copy the version number too because it will not
+	// be updated when the node is reloaded. So later when updating the old_node,
+	// the value will be overwritten with the new node empty value.
+	amp_package_node_add_token (AMP_PACKAGE_NODE (new_node), amp_package_node_get_token (AMP_PACKAGE_NODE (old_node)));
+
+	return new_node;
+}
+
 static gboolean
 amp_package_node_write (AmpNode *node, AmpNode *parent, AmpProject *project, GError **error)
 {
@@ -196,14 +218,6 @@ amp_package_node_erase (AmpNode *node, AmpNode *parent, AmpProject *project, GEr
 /* GObjet implementation
  *---------------------------------------------------------------------------*/
 
-typedef struct _AmpPackageNodeClass AmpPackageNodeClass;
-
-struct _AmpPackageNodeClass {
-	AmpNodeClass parent_class;
-};
-
-G_DEFINE_DYNAMIC_TYPE (AmpPackageNode, amp_package_node, AMP_TYPE_NODE);
-
 static void
 amp_package_node_init (AmpPackageNode *node)
 {
@@ -234,6 +248,7 @@ amp_package_node_class_init (AmpPackageNodeClass *klass)
 	node_class = AMP_NODE_CLASS (klass);
 	node_class->load = amp_package_node_load;
 	node_class->update = amp_package_node_update;
+	node_class->copy = amp_package_node_copy;
 	node_class->erase = amp_package_node_erase;
 	node_class->write = amp_package_node_write;
 }
diff --git a/plugins/am-project/amp-target.c b/plugins/am-project/amp-target.c
index 189d6f0..06277e6 100644
--- a/plugins/am-project/amp-target.c
+++ b/plugins/am-project/amp-target.c
@@ -53,8 +53,13 @@ struct _AmpTargetNode {
 	GList* tokens;
 };
 
+typedef struct _AmpTargetNodeClass AmpTargetNodeClass;
 
+struct _AmpTargetNodeClass {
+	AmpNodeClass parent_class;
+};
 
+G_DEFINE_DYNAMIC_TYPE (AmpTargetNode, amp_target_node, AMP_TYPE_NODE);
 
 
 
@@ -434,6 +439,17 @@ amp_target_node_update (AmpNode *node, AmpNode *new_node)
 	return TRUE;
 }
 
+static AmpNode *
+amp_target_node_copy (AmpNode *old_node)
+{
+	AmpNode *new_node;
+	
+	new_node = AMP_NODE_CLASS (amp_target_node_parent_class)->copy (old_node);
+	amp_target_node_set_type (AMP_TARGET_NODE (new_node), anjuta_project_node_get_full_type (ANJUTA_PROJECT_NODE (old_node)));
+
+	return new_node;
+}
+
 static gboolean
 amp_target_node_write (AmpNode *node, AmpNode *parent, AmpProject *project, GError **error)
 {
@@ -502,14 +518,6 @@ amp_target_node_erase (AmpNode *target, AmpNode *parent, AmpProject *project, GE
 /* GObjet implementation
  *---------------------------------------------------------------------------*/
 
-typedef struct _AmpTargetNodeClass AmpTargetNodeClass;
-
-struct _AmpTargetNodeClass {
-	AmpNodeClass parent_class;
-};
-
-G_DEFINE_DYNAMIC_TYPE (AmpTargetNode, amp_target_node, AMP_TYPE_NODE);
-
 static void
 amp_target_node_init (AmpTargetNode *node)
 {
@@ -543,6 +551,7 @@ amp_target_node_class_init (AmpTargetNodeClass *klass)
 
 	node_class = AMP_NODE_CLASS (klass);
 	node_class->update = amp_target_node_update;
+	node_class->copy = amp_target_node_copy;
 	node_class->write = amp_target_node_write;
 	node_class->erase = amp_target_node_erase;
 }



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