Re: [Planner Dev] New patch: undo for editing custom task properties





Acs,
	I see this is just altering the values.  This is really
cool as the patch I'm working on handles the add/remove and re-label
of the custom property itself (i..e the actuall column) but I hadn't
done anything on the values (except for the custom project property
values (i.e. in the Project dialog).

I'll build/test the two patches (this and mine) together
as I'll probably look at what you've done to restore a whole
project worth of properties when a property (column) is deleted
i.e. every task gets its custom property value deleted.

Lincoln.

Alvaro del Castillo wrote:
Hi guys!

With a code very similar to the undo editing custom properties in
resources, I have implemented also the undo editing custom properties
for tasks.

In the two cases it isn't implemented the editing if the custom property
is a DATE, something that the custom property dialog doesn't allow
currently, so right now it isn't a problem but will be if we let the
user create custom properties that are dates.

In the task tree only remains the reset constraint to be undoable. And
then, I will focus in the task editor dialog, very similar work to the
resource editor dialog in which I have worked in the past.

I will test next days the last patch I sent for the bug:

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

Cheers



------------------------------------------------------------------------

Index: src/planner-task-tree.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-tree.c,v
retrieving revision 1.24
diff -u -b -B -p -r1.24 planner-task-tree.c
--- src/planner-task-tree.c	9 May 2004 08:02:14 -0000	1.24
+++ src/planner-task-tree.c	13 May 2004 05:28:11 -0000
@@ -75,7 +75,7 @@ struct _PlannerTaskTreePriv {
 };
typedef struct {
-	GtkTreeView *tree;
+	PlannerTaskTree *tree;
 	MrpProperty *property;
 } ColPropertyData;
@@ -1128,6 +1138,98 @@ task_cmd_unlink (PlannerTaskTree *tree,
 	return cmd_base;
 }
+typedef struct {
+	PlannerCmd   base;
+
+	MrpTask      *task;
+ MrpProperty *property; + GValue *value;
+	GValue       *old_value;
+} TaskCmdEditCustomProperty;
+
+static gboolean
+task_cmd_edit_custom_property_do (PlannerCmd *cmd_base)
+{
+	TaskCmdEditCustomProperty *cmd;
+	cmd = (TaskCmdEditCustomProperty*) cmd_base;
+
+	mrp_object_set_property (MRP_OBJECT (cmd->task),
+				 cmd->property,
+				 cmd->value);
+
+	return TRUE;
+}
+
+static void
+task_cmd_edit_custom_property_undo (PlannerCmd *cmd_base)
+{
+	TaskCmdEditCustomProperty *cmd;
+
+	cmd = (TaskCmdEditCustomProperty*) cmd_base;
+
+	/* FIXME: delay in the UI when setting the property */
+	mrp_object_set_property (MRP_OBJECT (cmd->task),
+				 cmd->property,
+				 cmd->old_value);
+
+}
+
+static void
+task_cmd_edit_custom_property_free (PlannerCmd *cmd_base)
+{
+	TaskCmdEditCustomProperty *cmd;
+
+	cmd = (TaskCmdEditCustomProperty*) cmd_base;
+
+	g_value_unset (cmd->value);
+	g_value_unset (cmd->old_value);
+
+	g_object_unref (cmd->task);
+}
+
+static PlannerCmd *
+task_cmd_edit_custom_property (PlannerTaskTree  *tree,
+			       MrpTask          *task,
+			       MrpProperty      *property,
+			       const GValue     *value)
+{
+	PlannerCmd                *cmd_base;
+	PlannerTaskTreePriv       *priv = tree->priv;
+	TaskCmdEditCustomProperty *cmd;
+
+	cmd = g_new0 (TaskCmdEditCustomProperty, 1);
+
+	cmd_base = (PlannerCmd*) cmd;
+
+	cmd_base->label = g_strdup (_("Edit task custom property"));
+	cmd_base->do_func = task_cmd_edit_custom_property_do;
+	cmd_base->undo_func = task_cmd_edit_custom_property_undo;
+	cmd_base->free_func = task_cmd_edit_custom_property_free;
+
+	cmd->property = property;
+	cmd->task = g_object_ref (task);
+
+	cmd->value = g_new0 (GValue, 1);
+	g_value_init (cmd->value, G_VALUE_TYPE (value));
+	g_value_copy (value, cmd->value);
+
+	cmd->old_value = g_new0 (GValue, 1);
+	g_value_init (cmd->old_value, G_VALUE_TYPE (value));
+
+	mrp_object_get_property (MRP_OBJECT (cmd->task),
+				 cmd->property,
+				 cmd->old_value);
+
+ /* FIXME: if old and new value are the same, do nothing + How we can compare values?
+	*/
+
+	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (priv->main_window),
+					   cmd_base);
+
+	return cmd_base;
+}
+
GType
 planner_task_tree_get_type (void)
@@ -2028,31 +2130,16 @@ task_tree_property_data_func (GtkTreeVie
 	g_free (svalue);
 }
-static void -task_tree_property_value_edited (GtkCellRendererText *cell, - gchar *path_str,
+static GValue
+task_view_custom_property_set_value (MrpProperty         *property,
gchar *new_text, - ColPropertyData *data) + GtkCellRendererText *cell) {
-	GtkTreePath             *path;
-	GtkTreeIter              iter;
-	GtkTreeModel            *model;
-	MrpProperty             *property;
-	MrpPropertyType          type;
-	MrpTask                 *task;
 	PlannerCellRendererDate *date;	
+	GValue                   value = { 0 };
+	MrpPropertyType          type;
 	gfloat                   fvalue;
- /* FIXME: undo */
-	
-	model = gtk_tree_view_get_model (data->tree);
-	property = data->property;
-
-	path = gtk_tree_path_new_from_string (path_str);
-	gtk_tree_model_get_iter (model, &iter, path);
-
-	task = planner_gantt_model_get_task (PLANNER_GANTT_MODEL (model), &iter);
-
 	/* FIXME: implement mrp_object_set_property like
* g_object_set_property that takes a GValue. */
@@ -2060,47 +2147,43 @@ task_tree_property_value_edited (GtkCell
switch (type) {
 	case MRP_PROPERTY_TYPE_STRING:
-		mrp_object_set (MRP_OBJECT (task),
- mrp_property_get_name (property), - new_text,
-				NULL);
+		g_value_init (&value, G_TYPE_STRING);
+		g_value_set_string (&value, new_text);
+
 		break;
 	case MRP_PROPERTY_TYPE_INT:
-		mrp_object_set (MRP_OBJECT (task),
- mrp_property_get_name (property), - atoi (new_text),
-				NULL);
+		g_value_init (&value, G_TYPE_INT);
+		g_value_set_int (&value, atoi (new_text));
+
 		break;
 	case MRP_PROPERTY_TYPE_FLOAT:
 		fvalue = g_ascii_strtod (new_text, NULL);
-		mrp_object_set (MRP_OBJECT (task),
- mrp_property_get_name (property), - fvalue,
-				NULL);
+		g_value_init (&value, G_TYPE_FLOAT);
+		g_value_set_float (&value, fvalue);
+
 		break;
case MRP_PROPERTY_TYPE_DURATION:
 		/* FIXME: support reading units etc... */
-		mrp_object_set (MRP_OBJECT (task),
- mrp_property_get_name (property), - atoi (new_text) *8*60*60,
-				NULL);
+		g_value_init (&value, G_TYPE_INT);
+		g_value_set_int (&value, atoi (new_text) *8*60*60);
+
 		break;
 		
case MRP_PROPERTY_TYPE_DATE:
 		date = PLANNER_CELL_RENDERER_DATE (cell);
-		mrp_object_set (MRP_OBJECT (task),
+		/* FIXME: Currently custom properties can't be dates. Why? */
+		/* mrp_object_set (MRP_OBJECT (task),
mrp_property_get_name (property), &(date->time),
-				NULL);
+				NULL);*/
 		break;
 	case MRP_PROPERTY_TYPE_COST:
 		fvalue = g_ascii_strtod (new_text, NULL);
-		mrp_object_set (MRP_OBJECT (task),
- mrp_property_get_name (property), - fvalue,
-				NULL);
+		g_value_init (&value, G_TYPE_FLOAT);
+		g_value_set_float (&value, fvalue);
+
 		break;	
 				
 	default:
@@ -2108,6 +2191,37 @@ task_tree_property_value_edited (GtkCell
 		break;
 	}
+ return value;
+}
+
+static void +task_tree_property_value_edited (GtkCellRendererText *cell, + gchar *path_str, + gchar *new_text, + ColPropertyData *data)
+{
+	PlannerCmd              *cmd;
+	GtkTreePath             *path;
+	GtkTreeIter              iter;
+	GtkTreeModel            *model;
+	MrpProperty             *property;
+	MrpTask                 *task;
+	GValue                   value = { 0 };
+	
+	model = gtk_tree_view_get_model (GTK_TREE_VIEW (data->tree));
+	property = data->property;	
+
+	path = gtk_tree_path_new_from_string (path_str);
+	gtk_tree_model_get_iter (model, &iter, path);
+
+	task = planner_gantt_model_get_task (PLANNER_GANTT_MODEL (model), &iter);
+
+	value = task_view_custom_property_set_value (property, new_text, cell);
+
+	cmd = task_cmd_edit_custom_property (data->tree, task, property, &value);
+
+	g_value_unset (&value);
+
 	gtk_tree_path_free (path);
 }
@@ -2168,7 +2282,7 @@ task_tree_property_added (MrpProject g_hash_table_insert (priv->property_to_column, property, col);
 	
 	data->property = property;
-	data->tree = tree;
+	data->tree = task_tree;
gtk_tree_view_column_pack_start (col, cell, TRUE);

------------------------------------------------------------------------

_______________________________________________
Planner-dev mailing list
Planner-dev lists imendio com
http://lists.imendio.com/mailman/listinfo/planner-dev



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