[Planner Dev] Fixes to UNDO/REDO for task/resource property label edits not working right.




Attached is the small patch to fix my UNDO/REDO code
for the labels on the custom properties.

I was using the property pointer which obviously gets
destroyed when you UNDO back to nothing so its not
the right thing to use on the REDO.

This closes bugzilla,

http://bugzilla.gnome.org/show_bug.cgi?id=141967

Rgds,
Lincoln.
Index: src/planner-property-dialog.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-property-dialog.c,v
retrieving revision 1.3
diff -u -B -b -p -r1.3 planner-property-dialog.c
--- a/src/planner-property-dialog.c	2 Jun 2004 20:25:18 -0000	1.3
+++ b/src/planner-property-dialog.c	20 Jun 2004 03:29:04 -0000
@@ -89,7 +89,9 @@ typedef struct {
 	PlannerCmd        base;
 
 	PlannerWindow	  *window;
-	MrpProperty	 *property;
+	MrpProject	 *project;
+	GType		 owner;
+	gchar		 *name;
 	gchar            *old_text;
 	gchar  	     	 *new_text;
 } ProjectPropertyCmdLabelEdited;
@@ -168,6 +170,8 @@ static void	project_property_cmd_remove_
 
 static PlannerCmd *project_property_cmd_label_edited 	(PlannerWindow *window,
 							MrpProperty	*property,
+							MrpProject	*project,
+							GType		owner,
 							const gchar 	*new_text);
 static gboolean	project_property_cmd_label_edited_do 	(PlannerCmd *cmd_base);
 static void	project_property_cmd_label_edited_undo 	(PlannerCmd *cmd_base);
@@ -475,9 +479,13 @@ property_dialog_label_edited (GtkCellRen
 			    COL_PROPERTY, &property,
 			    -1);
 
+	if (strcmp (new_text, mrp_property_get_label (property)) != 0 ) { /* Only do if different Labels */
 	cmd = (ProjectPropertyCmdLabelEdited*) project_property_cmd_label_edited (priv->main_window, 
 										property, 
+										priv->project,
+										priv->owner,
 										new_text);
+	}
 
 	gtk_tree_path_free (path);
 }
@@ -876,7 +884,7 @@ project_property_cmd_remove 	(PlannerWin
 	MrpProperty     *property;
 
 	cmd_base = planner_cmd_new (ProjectPropertyCmdRemove,
-				   _("Add property"),
+				   _("Remove property"),
 				   project_property_cmd_remove_do,
 				   project_property_cmd_remove_undo,
 				   project_property_cmd_remove_free);
@@ -909,14 +917,19 @@ static gboolean
 project_property_cmd_label_edited_do (PlannerCmd *cmd_base)
 {
 	ProjectPropertyCmdLabelEdited *cmd;
+	MrpProperty		*property;
 
 	cmd = (ProjectPropertyCmdLabelEdited*) cmd_base;
 	
-	if (!cmd->property) {
+	property = mrp_project_get_property (cmd->project,
+					     cmd->name,
+					     cmd->owner);
+					     
+	if (!property) {
 		return FALSE;
 	}
 	
-	mrp_property_set_label (cmd->property, cmd->new_text);
+	mrp_property_set_label (property, cmd->new_text);
 		
 	return TRUE;
 }
@@ -926,12 +939,18 @@ static void
 project_property_cmd_label_edited_undo (PlannerCmd *cmd_base)
 {
 	ProjectPropertyCmdLabelEdited *cmd;
+	MrpProperty		*property;
 		
 	cmd = (ProjectPropertyCmdLabelEdited*) cmd_base;
 
-	if (cmd->property != NULL) {
+	property = mrp_project_get_property (cmd->project,
+					     cmd->name,
+					     cmd->owner);
 
-	mrp_property_set_label (cmd->property, cmd->old_text);	
+
+	if (property != NULL) {
+
+	mrp_property_set_label (property, cmd->old_text);	
 	
 	}
 }
@@ -945,20 +964,23 @@ project_property_cmd_label_edited_free (
 
 	g_free (cmd->old_text);
 	g_free (cmd->new_text);
-	cmd->property = NULL;  
+	g_free (cmd->name);
+	cmd->project = NULL; 
 	cmd->window = NULL;
 }
 
 static PlannerCmd *
 project_property_cmd_label_edited 	(PlannerWindow *window,
 					MrpProperty	*property,
+					MrpProject	*project,
+					GType		owner,
 					const gchar 	*new_text)
 {
 	PlannerCmd      *cmd_base;
 	ProjectPropertyCmdLabelEdited  *cmd;
 
 	cmd_base = planner_cmd_new (ProjectPropertyCmdLabelEdited,
-				   _("Add property"),
+				   _("Property label edited"),
 				   project_property_cmd_label_edited_do,
 				   project_property_cmd_label_edited_undo,
 				   project_property_cmd_label_edited_free);
@@ -966,12 +988,20 @@ project_property_cmd_label_edited 	(Plan
 	cmd = (ProjectPropertyCmdLabelEdited *) cmd_base;
 
 	cmd->window = window;
-	cmd->property = property;
 	cmd->new_text = g_strdup (new_text);
 		
-	/* Now remember also the old data so we can undo the label edit */
+	/* Now remember also the old data so we can undo the label edit 
+	   Though it seems safe to DO the label change with the property pointer
+	   its not safe to UNDO it after the property has been deleted as 
+	   we've lost that pointer. So we actually must just remember 
+	   the project, name and owner too and do a mrp_project_get_property()
+	   to get the current property pointer.
+	*/
 
-	cmd->old_text = g_strdup ( mrp_property_get_label (property));
+	cmd->old_text = g_strdup (mrp_property_get_label (property));
+	cmd->project = project;
+	cmd->name = g_strdup (mrp_property_get_name (property));
+	cmd->owner = owner;
 	
 	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (window),
 					   cmd_base);


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