[Planner Dev] More undo work in tasks: Indent, Unident, Up and Down



Hi guys!

Here goes another patch more complete that the last one that implements
not only indent tasks, but also unindent, up and down.

I am trying to send the patches ASAP to the list in order people can
test them. This patch is against last planner cvs.

Cheers

-- Alvaro
? cost.diff
? indent-move-undo.diff
? indent-undo.diff
? task-tree-remove-undo1.diff
? task-tree-remove-undo2.diff
? task-tree-remove-undo3.diff
? task-tree-remove-undo4.diff
? task-tree-remove-undo5.diff
? dotnet/Makefile
? dotnet/Makefile.in
? dotnet/libplanner/Makefile
? dotnet/libplanner/Makefile.in
? dotnet/samples/Makefile
? dotnet/samples/Makefile.in
? src/tasks-undo.diff
? tests/task-undo.tgz
? tests/tasks-undo
? tests/tasks-undo.tgz
Index: libplanner/mrp-task.c
===================================================================
RCS file: /cvs/gnome/planner/libplanner/mrp-task.c,v
retrieving revision 1.3
diff -u -b -B -p -r1.3 mrp-task.c
--- libplanner/mrp-task.c	6 Apr 2004 20:38:23 -0000	1.3
+++ libplanner/mrp-task.c	8 Apr 2004 05:56:13 -0000
@@ -1595,7 +1595,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.16
diff -u -b -B -p -r1.16 planner-task-tree.c
--- src/planner-task-tree.c	6 Apr 2004 20:25:22 -0000	1.16
+++ src/planner-task-tree.c	8 Apr 2004 05:56:20 -0000
@@ -4,7 +4,7 @@
  * Copyright (C) 2002-2003 CodeFactory AB
  * Copyright (C) 2002-2003 Richard Hult <richard imendio com>
  * Copyright (C) 2002 Mikael Hallendal <micke imendio com>
- * Copyright (C) 2002 Alvaro del Castillo <acs barrapunto com>
+ * Copyright (C) 2002-2004 Alvaro del Castillo <acs barrapunto com>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -715,6 +715,211 @@ 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;
+	MrpTask    *sibling;
+	MrpTask    *sibling_old;
+	gboolean    before;
+	gboolean    before_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,
+					      cmd->sibling,
+					      cmd->parent,
+					      cmd->before,
+					      &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,
+					      cmd->sibling_old,
+					      cmd->parent_old,
+					      cmd->before_old,
+					      &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);
+	if (cmd->parent != NULL) {
+		g_object_unref (cmd->parent);
+	}
+	g_object_unref (cmd->parent_old);
+	if (cmd->sibling != NULL) {
+		g_object_unref (cmd->sibling);
+	}
+	if (cmd->sibling_old != NULL) {
+		g_object_unref (cmd->sibling_old);
+	}
+
+	g_free (cmd);
+}
+
+
+static PlannerCmd *
+task_cmd_task_move (PlannerTaskTree *tree,
+		    MrpTask         *task,
+		    MrpTask         *sibling,
+		    MrpTask         *parent,
+		    gboolean         before)
+{
+	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);
+
+	if (parent != NULL) {
+		cmd->parent = g_object_ref (parent);
+	} else {
+		cmd->parent_old = NULL;
+	}
+	cmd->parent_old = g_object_ref (mrp_task_get_parent (task));
+
+	if (sibling != NULL) {
+		cmd->sibling = g_object_ref (sibling);
+	} else {
+		cmd->sibling = NULL;
+	}
+	cmd->sibling_old = mrp_task_get_next_sibling (task);
+	if (cmd->sibling_old != NULL) { 
+		cmd->sibling_old = g_object_ref (cmd->sibling_old);
+	}
+
+	cmd->before = before;
+	/* do Up task -> undo Down task*/
+	if (sibling != NULL && before) { 
+		cmd->before_old = FALSE;
+	} 
+	/* do Down task -> undo Up task */
+	else {
+		cmd->before_old = TRUE;	
+	}
+			
+	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)
@@ -1349,6 +1554,7 @@ task_tree_start_edited (GtkCellRendererT
 			gchar               *new_text,
 			gpointer             data)
 {
+	PlannerTaskTree         *tree = data;
 	PlannerCellRendererDate *date;
 	GtkTreeView             *view;
 	GtkTreeModel            *model;
@@ -1357,8 +1563,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);
@@ -1373,7 +1577,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);
 }
@@ -1394,8 +1600,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);
@@ -2441,8 +2645,6 @@ planner_task_tree_indent_task (PlannerTa
 	GtkWidget         *dialog;
 	GtkTreeSelection  *selection;
 
-	/* FIXME: undo */
-
 	project = tree->priv->project;
 
 	model = PLANNER_GANTT_MODEL (gtk_tree_view_get_model (GTK_TREE_VIEW (tree)));
@@ -2475,17 +2677,21 @@ 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, NULL, new_parent, FALSE); 
+
+		/* 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,
@@ -2526,8 +2732,6 @@ planner_task_tree_unindent_task (Planner
 	GtkTreePath       *path;
 	GtkTreeSelection  *selection;
 
-	/* FIXME: undo */
-
 	project = tree->priv->project;
 
 	model = PLANNER_GANTT_MODEL (gtk_tree_view_get_model (GTK_TREE_VIEW (tree)));
@@ -2564,14 +2768,19 @@ planner_task_tree_unindent_task (Planner
 	unindent_tasks = g_list_reverse (unindent_tasks);
 
 	for (l = unindent_tasks; l; l = l->next) {
+		TaskCmdTaskMove *cmd;
+
 		task = l->data;
 
-		mrp_project_move_task (project,
+		cmd = (TaskCmdTaskMove *) 
+			task_cmd_task_move (tree, task, NULL, new_parent, FALSE);
+
+		/* mrp_project_move_task (project,
 				       task,
 				       NULL,
 				       new_parent,
 				       FALSE,
-				       NULL);
+				       NULL); */
 	}
 
 	path = planner_gantt_model_get_path_from_task (PLANNER_GANTT_MODEL (model), 
@@ -2598,8 +2807,6 @@ planner_task_tree_move_task_up (PlannerT
 	GList	    	 *list;
 	guint	    	  position;
 
-	/* FIXME: undo */
-	
 	project = tree->priv->project;
 
 	task_tree_block_selection_changed (tree);
@@ -2620,12 +2827,15 @@ planner_task_tree_move_task_up (PlannerT
 	if (position == 0) {
 		/* Task on the top of the list */
 	} else {
+		TaskCmdTaskMove *cmd;
 		sibling = mrp_task_get_nth_child (parent, 
 						  position - 1);
 		
 		/* Move task from 'position' to 'position-1' */
-		mrp_project_move_task (project, task, sibling, 
-				       parent, TRUE, NULL);
+		cmd = (TaskCmdTaskMove *) 
+		   task_cmd_task_move (tree, task, sibling, parent, TRUE);
+		/* mrp_project_move_task (project, task, sibling, 
+		   parent, TRUE, NULL); */
 		path = planner_gantt_model_get_path_from_task (
 			PLANNER_GANTT_MODEL (model), task);
 		gtk_tree_selection_select_path (selection, path);
@@ -2646,8 +2856,6 @@ planner_task_tree_move_task_down (Planne
 	GList		 *list;
 	guint		  position;
 
-	/* FIXME: undo */
-
 	project = tree->priv->project;
 
 	task_tree_block_selection_changed (tree);
@@ -2667,10 +2875,14 @@ planner_task_tree_move_task_down (Planne
 		if (position == (mrp_task_get_n_children (parent) - 1) ) {
 			/* The task is in the bottom of the list */
 		} else {
+			TaskCmdTaskMove *cmd;
 			sibling = mrp_task_get_nth_child (parent, position + 1);
+
 			/* Moving task from 'position' to 'position + 1' */
-			mrp_project_move_task (project, task, sibling, 
-					       parent, FALSE, NULL);
+			cmd = (TaskCmdTaskMove *) 
+				task_cmd_task_move (tree, task, sibling, parent, FALSE);
+			/* mrp_project_move_task (project, task, sibling, 
+			   parent, FALSE, NULL);*/
 
 			path = planner_gantt_model_get_path_from_task (PLANNER_GANTT_MODEL (model), task);
 			gtk_tree_selection_select_path (selection, path);


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