[Planner Dev] Patch to close #143609



Hi guys!

Here goes the patch to close:

http://bugs.gnome.org/show_bug.cgi?id=143609

that closes all the bugs for undo system targeted to 0.12.

I will commit it in a few minutes.

Cheers

-- Alvaro
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/planner/ChangeLog,v
retrieving revision 1.173
diff -u -b -B -p -r1.173 ChangeLog
--- ChangeLog	25 Jun 2004 11:53:58 -0000	1.173
+++ ChangeLog	26 Jun 2004 04:21:39 -0000
@@ -1,3 +1,10 @@
+2004-06-26 Alvaro del Castillo  <acs barrapunto com>
+	
+	* libplanner/mrp-object.c: Fix in mrp_object_get_property API doc.
+	* src/planner-property-dialog.c: Implemented recovering properties
+	values for tasks and resources when you undo a remove custom
+	property operation. Fixes #143609.
+
 2004-06-25  Richard Hult  <richard imendio com>
 
 	* src/planner-ttable-row.c: (recalc_bounds),
Index: libplanner/mrp-object.c
===================================================================
RCS file: /cvs/gnome/planner/libplanner/mrp-object.c,v
retrieving revision 1.7
diff -u -b -B -p -r1.7 mrp-object.c
--- libplanner/mrp-object.c	7 Jun 2004 22:36:26 -0000	1.7
+++ libplanner/mrp-object.c	26 Jun 2004 04:21:42 -0000
@@ -219,8 +219,8 @@ mrp_object_set_property (MrpObject *obje
 /**
  * mrp_object_get_property:
  * @object: an #MrpObject
- * @property: the property to set
- * @value: the value to set
+ * @property: the property to get
+ * @value: the value to get
  * 
  * Gets a custom property. This is mostly for language bindings. C programmers
  * should use mrp_object_get instead.
Index: src/planner-property-dialog.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-property-dialog.c,v
retrieving revision 1.4
diff -u -b -B -p -r1.4 planner-property-dialog.c
--- src/planner-property-dialog.c	21 Jun 2004 10:21:29 -0000	1.4
+++ src/planner-property-dialog.c	26 Jun 2004 04:21:44 -0000
@@ -74,14 +74,17 @@ typedef struct {
 typedef struct {
 	PlannerCmd       base;
 	
-	PlannerWindow	*window;
 	MrpProject      *project;
 	gchar	 	*name; 
+	MrpProperty	*property;
 	MrpPropertyType	 type;
 	gchar	 	*label_text;
 	gchar	 	*description;
 	GType		 owner;
 	gboolean	 user_defined;   
+
+	GHashTable      *tasks;
+	GHashTable      *resources;	
 } PropertyCmdRemove;
 
 typedef struct {
@@ -626,12 +629,9 @@ property_cmd_add_undo (PlannerCmd *cmd_b
 		
 	cmd = (PropertyCmdAdd*) cmd_base;
 
-	/* FIXME: why is the NULL check here? */
-	if (cmd->name != NULL) {
 		mrp_project_remove_property (cmd->project, 
 				  	     cmd->owner,
 				  	     cmd->name);
-	}	
 }
 
 
@@ -695,6 +695,31 @@ property_cmd_remove_do (PlannerCmd *cmd_
 		return FALSE;
 	}
 
+	/* First we need to save the value of the property */
+	if (cmd->owner == MRP_TYPE_TASK && g_hash_table_size (cmd->tasks) == 0) {
+		GList *l, *tasks = mrp_project_get_all_tasks (cmd->project);
+
+		/* ref tasks */
+		for (l = tasks; l; l = l->next) {
+			GValue *value = g_new0 (GValue, 1);
+			g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (cmd->property));
+			mrp_object_get_property (l->data, cmd->property, value);
+			g_hash_table_insert (cmd->tasks, g_object_ref (l->data), value);
+		}
+		
+	}	
+	else if (cmd->owner == MRP_TYPE_RESOURCE && g_hash_table_size (cmd->resources) == 0) {
+		GList *l, *resources = mrp_project_get_resources (cmd->project);
+
+		for (l = resources; l; l = l->next) {
+			GValue *value = g_new0 (GValue, 1);
+			g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (cmd->property));
+			mrp_object_get_property (l->data, cmd->property, value); 
+			g_hash_table_insert (cmd->resources, g_object_ref (l->data), value);
+		}
+		
+	}
+
 	mrp_project_remove_property (cmd->project,
 				     cmd->owner,
 				     cmd->name);
@@ -703,16 +728,29 @@ property_cmd_remove_do (PlannerCmd *cmd_
 }
 
 static void
+property_hash_recover  (gpointer key,
+			gpointer value,
+			gpointer user_data)
+{
+	PropertyCmdRemove *cmd = (PropertyCmdRemove*) user_data;
+
+	g_assert (MRP_IS_TASK (key) || MRP_IS_RESOURCE (key));
+	g_assert (G_IS_VALUE (value));
+
+	mrp_object_set_property (key, cmd->property, value);
+
+}
+
+static void
 property_cmd_remove_undo (PlannerCmd *cmd_base)
 {
 	PropertyCmdRemove *cmd;
-	MrpProperty       *property;
 	
 	cmd = (PropertyCmdRemove*) cmd_base;
 
-	/* FIXME: why is this check here? */
-	if (cmd->name != NULL) {
-		property = mrp_property_new (cmd->name, 
+	mrp_property_unref (cmd->property);
+
+	cmd->property = mrp_property_new (cmd->name, 
 					     cmd->type,
 					     cmd->label_text,
 					     cmd->description,
@@ -720,9 +758,20 @@ property_cmd_remove_undo (PlannerCmd *cm
 		
 		mrp_project_add_property (cmd->project, 
 					  cmd->owner,
-					  property,
+				  cmd->property,
 					  cmd->user_defined);
-	}	
+
+	g_hash_table_foreach (cmd->tasks, property_hash_recover, cmd);
+	g_hash_table_foreach (cmd->resources, property_hash_recover, cmd);	
+}
+
+static void
+property_hash_free  (gpointer key,
+		     gpointer value,
+		     gpointer user_data) 
+{
+	g_object_unref (key);
+	g_value_unset ((GValue *) value);	
 }
 
 static void
@@ -732,9 +781,18 @@ property_cmd_remove_free (PlannerCmd *cm
 
 	cmd = (PropertyCmdRemove*) cmd_base;
 
+	mrp_property_unref (cmd->property);
+
+	g_hash_table_foreach (cmd->tasks, property_hash_free, NULL);
+	g_hash_table_destroy (cmd->tasks);
+	g_hash_table_foreach (cmd->resources, property_hash_free, NULL);
+	g_hash_table_destroy (cmd->resources);
+
 	g_free (cmd->name);
 	g_free (cmd->label_text);
 	g_free (cmd->description);
+
+	g_object_unref (cmd->project);
 }
 
 static PlannerCmd *
@@ -755,8 +813,7 @@ property_cmd_remove (PlannerWindow *wind
 
 	cmd = (PropertyCmdRemove *) cmd_base;
 	
-	cmd->window = window;
-	cmd->project = project;
+	cmd->project = g_object_ref (project);
 	cmd->owner = owner;
 	cmd->name = g_strdup (name);
 
@@ -764,10 +821,14 @@ property_cmd_remove (PlannerWindow *wind
 					     name,
 					     owner);
 					     
+	cmd->property = mrp_property_ref (property);
 	cmd->type = mrp_property_get_property_type (property);
 	cmd->description = g_strdup (mrp_property_get_description (property));
 	cmd->label_text = g_strdup ( mrp_property_get_label (property));
 	cmd->user_defined = mrp_property_get_user_defined (property);
+
+	cmd->tasks = g_hash_table_new (NULL, NULL);
+	cmd->resources = g_hash_table_new (NULL, NULL);
 
 	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (window),
 					   cmd_base);

Attachment: signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente



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