Hi guys! This morning I have solved the conflicts in the undo code for the last patch applied from lincoln to move tasks and the undo code for indent tasks and move tasks seem to work correctly. I have test in some deep the code but you know, hacking and testing the same person isn't a good thing. So here goes another patch against the last CVS. I hope this patch will work until I apply it to the CVS, but I don't know all the patches that now are in the queue :) Cheers -- Alvaro
Index: src/planner-task-tree.c =================================================================== RCS file: /cvs/gnome/planner/src/planner-task-tree.c,v retrieving revision 1.17 diff -u -b -B -p -r1.17 planner-task-tree.c --- src/planner-task-tree.c 8 Apr 2004 15:25:55 -0000 1.17 +++ src/planner-task-tree.c 9 Apr 2004 06:17:23 -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,237 @@ 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 (cmd->task, "constraint", + cmd->constraint, NULL); +} + +static void +task_cmd_constraint_undo (PlannerCmd *cmd_base) +{ + TaskCmdConstraint *cmd; + + cmd = (TaskCmdConstraint*) cmd_base; + + g_object_set (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 (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; + 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; + + if (g_getenv ("PLANNER_DEBUG_UNDO_TASK")) { + if (cmd->before) { + g_message ("DO: Moving %s (parent %s) before %s", + mrp_task_get_name (cmd->task), + mrp_task_get_name (cmd->parent), + mrp_task_get_name (cmd->sibling)); + } else { + g_message ("DO: Moving %s (parent %s) after %s", + mrp_task_get_name (cmd->task), + mrp_task_get_name (cmd->parent), + mrp_task_get_name (cmd->sibling)); + } + } + + 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; + + if (!cmd->success) { + return; + } + + + if (g_getenv ("PLANNER_DEBUG_UNDO_TASK")) { + if (cmd->before_old) { + g_message ("UNDO: Moving %s (parent %s) before %s", + mrp_task_get_name (cmd->task), + mrp_task_get_name (cmd->parent_old), + mrp_task_get_name (cmd->sibling)); + } else { + g_message ("UNDO: Moving %s (parent %s) after %s", + mrp_task_get_name (cmd->task), + mrp_task_get_name (cmd->parent_old), + mrp_task_get_name (cmd->sibling)); + } + } + + cmd->success = mrp_project_move_task (cmd->project, + cmd->task, + cmd->sibling, + cmd->parent_old, + cmd->before_old, + &error); + + g_assert (cmd->success); +} + +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); + } + 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->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 +1580,7 @@ task_tree_start_edited (GtkCellRendererT gchar *new_text, gpointer data) { + PlannerTaskTree *tree = data; PlannerCellRendererDate *date; GtkTreeView *view; GtkTreeModel *model; @@ -1357,8 +1589,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 +1603,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 +1626,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); @@ -1404,14 +1634,14 @@ task_tree_start_show_popup (PlannerCellR COL_TASK, &task, -1); - g_object_get (G_OBJECT (task), + g_object_get (task, "constraint", &constraint, NULL); cell->type = constraint->type; if (cell->type == MRP_CONSTRAINT_ASAP) { - g_object_get (G_OBJECT (task), + g_object_get (task, "start", &start, NULL); @@ -2442,8 +2672,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))); @@ -2476,17 +2704,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, @@ -2527,8 +2759,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))); @@ -2567,12 +2797,14 @@ planner_task_tree_unindent_task (Planner for (l = unindent_tasks; l; l = l->next) { task = l->data; - mrp_project_move_task (project, + 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), @@ -2602,8 +2834,6 @@ planner_task_tree_move_task_up (PlannerT gint count; MrpTask *anchor_task; - /* FIXME: undo */ - project = tree->priv->project; list = planner_task_tree_get_selected_tasks (tree); @@ -2655,12 +2885,12 @@ planner_task_tree_move_task_up (PlannerT */ proceed = FALSE; } - if (!skip && position != 0 && proceed) { /* Move task from position to position - 1. */ sibling = mrp_task_get_nth_child (parent, position - 1); - mrp_project_move_task (project, task, sibling, - parent, TRUE, NULL); + task_cmd_task_move (tree, task, sibling, parent, TRUE); + /* mrp_project_move_task (project, task, sibling, + parent, TRUE, NULL);*/ } } @@ -2699,8 +2929,6 @@ planner_task_tree_move_task_down (Planne gint count; MrpTask *anchor_task; - /* FIXME: undo */ - project = tree->priv->project; list = planner_task_tree_get_selected_tasks (tree); @@ -2767,8 +2995,11 @@ planner_task_tree_move_task_down (Planne if (!skip && position <= mrp_task_get_n_children (parent) - 1 && proceed) { /* Move task from position to position + 1. */ sibling = mrp_task_get_nth_child (parent, position + 1); - mrp_project_move_task (project, task, sibling, - parent, FALSE, NULL); + + /* Moving task from 'position' to 'position + 1' */ + task_cmd_task_move (tree, task, sibling, parent, FALSE); + /* mrp_project_move_task (project, task, sibling, + parent, FALSE, NULL); */ } }
Attachment:
signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente