[Planner Dev] New patch to undo constraints and indent tasks



Hi guys!

Here goes a patch to undo task constraints and task indenting. I am sure
the task indent have some bug but I can reproduce it right now :(

This holidays I plan to continue with the undo system.

Cheers

-- Alvaro
Index: libplanner/mrp-task.c
===================================================================
RCS file: /cvs/gnome/planner/libplanner/mrp-task.c,v
retrieving revision 1.2
diff -u -b -B -p -r1.2 mrp-task.c
--- libplanner/mrp-task.c	17 Feb 2004 20:00:17 -0000	1.2
+++ libplanner/mrp-task.c	7 Apr 2004 18:20:23 -0000
@@ -1569,7 +1569,7 @@ mrp_task_get_cost (MrpTask *task)
 		resource = mrp_assignment_get_resource (l->data);
 
 		mrp_object_get (resource, "cost", &cost, NULL);
-		total += mrp_assignment_get_units (l->data) * priv->work * cost / (3600.0 * 100);
+		total += priv->work * cost / 3600.0;
 	}
 
 	return total;
Index: src/planner-task-tree.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-tree.c,v
retrieving revision 1.15
diff -u -b -B -p -r1.15 planner-task-tree.c
--- src/planner-task-tree.c	4 Apr 2004 15:12:34 -0000	1.15
+++ src/planner-task-tree.c	7 Apr 2004 18:20:39 -0000
@@ -713,6 +713,173 @@ task_cmd_remove (PlannerTaskTree *tree,
 	return cmd_base;
 }
 
+typedef struct {
+	PlannerCmd     base;
+
+	MrpTask       *task;
+	MrpConstraint *constraint;
+	MrpConstraint *constraint_old;
+} TaskCmdConstraint;
+
+static void
+task_cmd_constraint_do (PlannerCmd *cmd_base)
+{
+	TaskCmdConstraint *cmd;
+
+	cmd = (TaskCmdConstraint*) cmd_base;
+
+	g_object_set (G_OBJECT (cmd->task), "constraint", 
+		      cmd->constraint, NULL);
+}
+
+static void
+task_cmd_constraint_undo (PlannerCmd *cmd_base)
+{
+	TaskCmdConstraint *cmd;
+
+	cmd = (TaskCmdConstraint*) cmd_base;
+
+	g_object_set (G_OBJECT (cmd->task), "constraint", 
+		      cmd->constraint_old, NULL);
+	
+}
+
+static void
+task_cmd_constraint_free (PlannerCmd *cmd_base)
+{
+	TaskCmdConstraint *cmd;
+
+	cmd = (TaskCmdConstraint*) cmd_base;
+
+	g_object_unref (cmd->task);
+	g_free (cmd->constraint);
+	g_free (cmd->constraint_old);
+
+	g_free (cmd);
+}
+
+
+static PlannerCmd *
+task_cmd_constraint (PlannerTaskTree *tree,
+		     MrpTask         *task,
+		     MrpConstraint    constraint)
+{
+	PlannerTaskTreePriv *priv = tree->priv;
+	PlannerCmd          *cmd_base;
+	TaskCmdConstraint   *cmd;
+
+	cmd = g_new0 (TaskCmdConstraint, 1);
+
+	cmd_base = (PlannerCmd*) cmd;
+	cmd_base->label = g_strdup (_("Constraint task"));
+	cmd_base->do_func = task_cmd_constraint_do;
+	cmd_base->undo_func = task_cmd_constraint_undo;
+	cmd_base->free_func = task_cmd_constraint_free;
+	
+	cmd->task = g_object_ref (task);
+
+	cmd->constraint = g_new0 (MrpConstraint, 1);
+	cmd->constraint->time = constraint.time;
+	cmd->constraint->type = constraint.type;
+
+	g_object_get (G_OBJECT (task), "constraint", 
+		      &cmd->constraint_old, NULL);
+
+	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (priv->main_window),
+					   cmd_base);
+
+	return cmd_base;
+}
+
+typedef struct {
+	PlannerCmd     base;
+
+	MrpProject *project;
+	MrpTask    *task;
+	MrpTask    *parent;
+	MrpTask    *parent_old;
+	gboolean    success;
+} TaskCmdTaskMove;
+
+static void
+task_cmd_task_move_do (PlannerCmd *cmd_base)
+{
+	TaskCmdTaskMove *cmd;
+	GError          *error;
+
+	cmd = (TaskCmdTaskMove*) cmd_base;
+
+	cmd->success = mrp_project_move_task (cmd->project,
+					      cmd->task,
+					      NULL,
+					      cmd->parent,
+					      FALSE,
+					      &error);
+}
+
+static void
+task_cmd_task_move_undo (PlannerCmd *cmd_base)
+{
+	TaskCmdTaskMove *cmd;
+	GError          *error;
+
+	cmd = (TaskCmdTaskMove*) cmd_base;
+
+	cmd->success = mrp_project_move_task (cmd->project,
+					      cmd->task,
+					      NULL,
+					      cmd->parent_old,
+					      FALSE,
+					      &error);
+}
+
+static void
+task_cmd_task_move_free (PlannerCmd *cmd_base)
+{
+	TaskCmdTaskMove *cmd;
+
+	cmd = (TaskCmdTaskMove*) cmd_base;
+
+	g_object_unref (cmd->project);
+	g_object_unref (cmd->task);
+	g_object_unref (cmd->parent);
+	g_object_unref (cmd->parent_old);
+
+	g_free (cmd);
+}
+
+
+static PlannerCmd *
+task_cmd_task_move (PlannerTaskTree *tree,
+		    MrpTask         *task,
+		    MrpTask         *parent)
+{
+	PlannerTaskTreePriv *priv = tree->priv;
+	PlannerCmd          *cmd_base;
+	TaskCmdTaskMove     *cmd;
+
+	cmd = g_new0 (TaskCmdTaskMove, 1);
+
+	cmd_base = (PlannerCmd*) cmd;
+	cmd_base->label = g_strdup (_("Move task"));
+	cmd_base->do_func = task_cmd_task_move_do;
+	cmd_base->undo_func = task_cmd_task_move_undo;
+	cmd_base->free_func = task_cmd_task_move_free;
+	
+	cmd->project = g_object_ref (tree->priv->project);
+	cmd->task = g_object_ref (task);
+
+	cmd->parent = g_object_ref (parent);
+	cmd->parent_old = g_object_ref (mrp_task_get_parent (task));
+
+	cmd->success = FALSE;
+
+	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)
@@ -1300,6 +1467,7 @@ task_tree_start_edited (GtkCellRendererT
 			gchar               *new_text,
 			gpointer             data)
 {
+	PlannerTaskTree         *tree = data;
 	PlannerCellRendererDate *date;
 	GtkTreeView             *view;
 	GtkTreeModel            *model;
@@ -1308,8 +1476,6 @@ task_tree_start_edited (GtkCellRendererT
 	MrpTask                 *task;
 	MrpConstraint            constraint;
 
-	/* FIXME: undo */
-	
 	view = GTK_TREE_VIEW (data);
 	model = gtk_tree_view_get_model (view);
 	date = PLANNER_CELL_RENDERER_DATE (cell);
@@ -1324,7 +1490,9 @@ task_tree_start_edited (GtkCellRendererT
 	constraint.time = date->time;
 	constraint.type = date->type;
 	
-	g_object_set (task, "constraint", &constraint, NULL);
+	task_cmd_constraint (tree, task, constraint);
+	
+	/* g_object_set (task, "constraint", &constraint, NULL); */
 
 	gtk_tree_path_free (path);
 }
@@ -1345,8 +1513,6 @@ task_tree_start_show_popup (PlannerCellR
 	mrptime        start;
 	MrpConstraint *constraint;
 
-	/* FIXME: undo */
-	
 	model = gtk_tree_view_get_model (tree_view);
 	
 	path = gtk_tree_path_new_from_string (path_string);
@@ -2419,17 +2585,20 @@ planner_task_tree_indent_task (PlannerTa
 	indent_tasks = g_list_reverse (indent_tasks);
 
 	for (l = indent_tasks; l; l = l->next) {
-		gboolean success;
+		TaskCmdTaskMove *cmd;
 		
 		task = l->data;
 
-		success = mrp_project_move_task (project,
+		cmd = (TaskCmdTaskMove *) task_cmd_task_move (tree, task, new_parent); 
+
+		/* cmd = mrp_project_move_task (project,
 						 task,
 						 NULL,
 						 new_parent,
 						 FALSE,
-						 &error);
-		if (!success) {
+					     &error); */
+
+		if (!cmd->success) {
 			dialog = gtk_message_dialog_new (GTK_WINDOW (tree->priv->main_window),
 							 GTK_DIALOG_DESTROY_WITH_PARENT,
 							 GTK_MESSAGE_ERROR,


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