[Planner Dev] Patch for undo adding/removing predecessors form task dialog



Hi guys!

Here goes a new patch to undo adding/removing predecessors from the task
dialog. The code is the same we use in planner-task-tree to do the same
operation, so I have moved the code from planner-task-tree to
planner-task-dialog and share between them.

The problems with phantoms arrows in the gantt view appear so we will
need debugging time and solve the open bug with a patch:

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

I feel they are related.

This bug isn't in 0.12 release bugs. I think we need to solve it before
releasing 0.12 because strange things happens in the gantt chart using
the undo/redo system so the user will stop to use it.

Cheers

-- Alvaro
Index: src/planner-task-dialog.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-dialog.c,v
retrieving revision 1.14
diff -u -b -B -p -r1.14 planner-task-dialog.c
--- src/planner-task-dialog.c	7 Jun 2004 06:30:57 -0000	1.14
+++ src/planner-task-dialog.c	8 Jun 2004 04:49:19 -0000
@@ -754,6 +754,155 @@ task_cmd_assign_units (PlannerWindow *ma
 	return cmd_base;
 }
 
+/* link and unlink shared with planner-task-tree.c */
+static gboolean
+task_cmd_link_do (PlannerCmd *cmd_base)
+{
+	TaskCmdLink *cmd;
+	GError      *error = NULL;
+	MrpRelation *relation;
+	gboolean     retval;
+
+	cmd = (TaskCmdLink *) cmd_base;
+
+	relation = mrp_task_add_predecessor (cmd->after,
+					     cmd->before,
+					     cmd->relationship,
+					     cmd->lag,
+					     &error);
+	if (!error) {
+		retval = TRUE;
+	} else {
+		cmd->error = error;
+		retval = FALSE;		
+	} 
+
+	return retval;
+}
+
+static void
+task_cmd_link_undo (PlannerCmd *cmd_base)
+{
+	TaskCmdLink *cmd;
+	
+	cmd = (TaskCmdLink*) cmd_base;
+	
+	mrp_task_remove_predecessor (cmd->after, cmd->before);
+}
+
+static void
+task_cmd_link_free (PlannerCmd *cmd_base)
+{
+	TaskCmdLink *cmd;
+
+	cmd = (TaskCmdLink *) cmd_base;
+
+	g_object_unref (cmd->project);
+	g_object_unref (cmd->before);
+	g_object_unref (cmd->after);
+}
+
+
+PlannerCmd *
+planner_task_cmd_link (PlannerWindow   *main_window,
+		       MrpTask         *before,
+		       MrpTask         *after,
+		       MrpRelationType  relationship,
+		       glong            lag,
+		       GError         **error)
+{
+	PlannerCmd          *cmd_base;
+	TaskCmdLink         *cmd;
+
+	cmd = g_new0 (TaskCmdLink, 1);
+
+	cmd_base = (PlannerCmd*) cmd;
+	cmd_base->label = g_strdup (_("Link task"));
+	cmd_base->do_func = task_cmd_link_do;
+	cmd_base->undo_func = task_cmd_link_undo;
+	cmd_base->free_func = task_cmd_link_free;
+
+	cmd->project = g_object_ref (planner_window_get_project (main_window));
+
+	cmd->before = g_object_ref (before);
+	cmd->after = g_object_ref (after);
+	cmd->relationship = relationship;
+	cmd->lag = lag;
+			
+	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager 
+					   (main_window),
+					   cmd_base);
+
+	if (cmd->error) {
+		g_propagate_error (error, cmd->error);
+		return NULL;
+	}
+
+	return cmd_base;	
+}
+
+static gboolean
+task_cmd_unlink_do (PlannerCmd *cmd_base)
+{
+	TaskCmdLink *cmd;
+	
+	cmd = (TaskCmdLink*) cmd_base;
+
+	if (g_getenv ("PLANNER_DEBUG_UNDO_TASK")) {
+		g_message ("Removing the link ...");
+	}
+	
+	mrp_task_remove_predecessor (cmd->after, cmd->before);
+
+	return TRUE;
+}
+
+static void
+task_cmd_unlink_undo (PlannerCmd *cmd_base)
+{
+	TaskCmdLink *cmd;
+	GError      *error;
+	MrpRelation *relation;
+
+	cmd = (TaskCmdLink *) cmd_base;
+
+	relation = mrp_task_add_predecessor (cmd->after,
+					     cmd->before,
+					     cmd->relationship,
+					     cmd->lag,
+					     &error);
+	g_assert (relation);
+}
+
+PlannerCmd *
+planner_task_cmd_unlink (PlannerWindow   *main_window,
+			 MrpRelation     *relation)
+{
+	PlannerCmd          *cmd_base;
+	TaskCmdLink         *cmd;
+
+	cmd = g_new0 (TaskCmdLink, 1);
+
+	cmd_base = (PlannerCmd*) cmd;
+	cmd_base->label = g_strdup (_("Unlink task"));
+	cmd_base->do_func = task_cmd_unlink_do;
+	cmd_base->undo_func = task_cmd_unlink_undo;
+	cmd_base->free_func = task_cmd_link_free;
+	
+	cmd->project = g_object_ref (planner_window_get_project (main_window));
+
+	cmd->before = g_object_ref (mrp_relation_get_predecessor (relation));
+	cmd->after = g_object_ref (mrp_relation_get_successor (relation));
+	cmd->relationship = mrp_relation_get_relation_type (relation);
+	cmd->lag = mrp_relation_get_lag (relation);
+			
+	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager 
+					   (main_window),
+					   cmd_base);
+	return cmd_base;
+}
+
+
 static void
 task_dialog_close_clicked_cb (GtkWidget *w, DialogData *data)
 {
@@ -1518,7 +1667,8 @@ task_dialog_task_child_added_or_removed_
 }
 
 static GtkWidget *  
-task_dialog_predecessor_dialog_new (MrpTask *task)
+task_dialog_predecessor_dialog_new (MrpTask       *task,
+				    PlannerWindow *main_window)
 {
 	MrpProject *project;
 	GladeXML   *glade;
@@ -1533,8 +1683,9 @@ task_dialog_predecessor_dialog_new (MrpT
 			       NULL);
 
 	dialog = glade_xml_get_widget (glade, "add_predecessor_dialog");
-	g_object_set_data (G_OBJECT (dialog), "task_main", task);
 	
+	g_object_set_data (G_OBJECT (dialog), "task_main", task);
+	g_object_set_data (G_OBJECT (dialog), "main_window", main_window);
 	w = glade_xml_get_widget (glade, "predecessor_combo");
 	g_object_set_data (G_OBJECT (dialog), "predecessor_combo", w);
 	
@@ -1575,6 +1726,8 @@ static void  
 task_dialog_new_pred_ok_clicked_cb (GtkWidget *button, 
 				    GtkWidget *dialog)
 {
+	PlannerWindow *main_window;
+	PlannerCmd    *cmd;
 	GtkWidget   *w;
 	GError      *error = NULL;
 	MrpTask     *task_main;
@@ -1584,6 +1737,8 @@ task_dialog_new_pred_ok_clicked_cb (GtkW
 	gint         pred_type; 
 	gchar       *str;
 	
+	main_window = g_object_get_data (G_OBJECT (dialog), "main_window");
+
 	task_main = g_object_get_data (G_OBJECT (dialog), "task_main");
 	mrp_object_get (task_main, "project", &project, NULL);
 
@@ -1606,11 +1761,10 @@ task_dialog_new_pred_ok_clicked_cb (GtkW
 	
 	mrp_object_get (MRP_OBJECT (new_task_pred), "name", &str, NULL);
 
-	if (!mrp_task_add_predecessor (task_main,
-				       new_task_pred,
-				       pred_type,
-				       lag,
-				       &error)) {
+	cmd = planner_task_cmd_link (main_window, new_task_pred, task_main,
+				     pred_type, lag, &error);
+	
+	if (!cmd) {
 		GtkWidget *err_dialog;
 		
 		err_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
@@ -1642,7 +1796,7 @@ task_dialog_add_predecessor_cb (GtkWidge
 {
 	GtkWidget *dialog;
 	
-	dialog = task_dialog_predecessor_dialog_new (data->task);
+	dialog = task_dialog_predecessor_dialog_new (data->task, data->main_window);
 	gtk_widget_show (dialog);
 }
 
@@ -1652,6 +1806,7 @@ task_dialog_remove_predecessor_cb (GtkWi
 {
 	GtkTreeView        *tree;
 	MrpTask            *predecessor;
+	MrpRelation             *relation;
 	PlannerPredecessorModel *model;
 	GtkTreeSelection   *selection;
 	GtkTreeIter         iter;
@@ -1665,7 +1820,9 @@ task_dialog_remove_predecessor_cb (GtkWi
         }
 	
 	predecessor = MRP_TASK (planner_list_model_get_object (PLANNER_LIST_MODEL (model), &iter));
-	mrp_task_remove_predecessor (data->task, predecessor);
+	/* mrp_task_remove_predecessor (data->task, predecessor); */
+	relation = mrp_task_get_relation (data->task, predecessor);
+	planner_task_cmd_unlink (data->main_window, relation);
 }
 
 static void  
Index: src/planner-task-dialog.h
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-dialog.h,v
retrieving revision 1.3
diff -u -b -B -p -r1.3 planner-task-dialog.h
--- src/planner-task-dialog.h	27 Apr 2004 18:58:02 -0000	1.3
+++ src/planner-task-dialog.h	8 Jun 2004 04:49:19 -0000
@@ -38,6 +38,28 @@ GtkWidget * planner_task_dialog_new (Pla
 				     MrpTask               *task,
 				     PlannerTaskDialogPage  page);
 
+/* Undo operation shared with planner-task-tree.c */
+typedef struct {
+	PlannerCmd        base;
+
+	MrpProject       *project;
+	MrpTask          *before;
+	MrpTask          *after;
+	MrpRelationType   relationship;
+	glong             lag;
+	GError           *error;
+} TaskCmdLink;
+
+PlannerCmd * planner_task_cmd_link   (PlannerWindow   *main_window,
+				      MrpTask         *before,
+				      MrpTask         *after,
+				      MrpRelationType  relationship,
+				      glong            lag,
+				      GError         **error);
+
+PlannerCmd * planner_task_cmd_unlink (PlannerWindow   *main_window,
+				      MrpRelation     *relation);
+
 
 #endif /* __PLANNER_TASK_DIALOG_H__ */
 
Index: src/planner-task-tree.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-tree.c,v
retrieving revision 1.27
diff -u -b -B -p -r1.27 planner-task-tree.c
--- src/planner-task-tree.c	4 Jun 2004 05:10:20 -0000	1.27
+++ src/planner-task-tree.c	8 Jun 2004 04:49:26 -0000
@@ -1043,166 +1043,6 @@ task_cmd_move (PlannerTaskTree *tree,
 typedef struct {
 	PlannerCmd        base;
 
-	MrpProject       *project;
-	MrpTask          *before;
-	MrpTask          *after;
-	MrpRelationType   relationship;
-	glong             lag;
-	GError           *error;
-} TaskCmdLink;
-
-static gboolean
-task_cmd_link_do (PlannerCmd *cmd_base)
-{
-	TaskCmdLink *cmd;
-	GError      *error = NULL;
-	MrpRelation *relation;
-	gboolean     retval;
-
-	cmd = (TaskCmdLink *) cmd_base;
-
-	relation = mrp_task_add_predecessor (cmd->after,
-					     cmd->before,
-					     cmd->relationship,
-					     cmd->lag,
-					     &error);
-	if (!error) {
-		retval = TRUE;
-	} else {
-		cmd->error = error;
-		retval = FALSE;		
-	} 
-
-	return retval;
-}
-
-static void
-task_cmd_link_undo (PlannerCmd *cmd_base)
-{
-	TaskCmdLink *cmd;
-	
-	cmd = (TaskCmdLink*) cmd_base;
-	
-	mrp_task_remove_predecessor (cmd->after, cmd->before);
-}
-
-static void
-task_cmd_link_free (PlannerCmd *cmd_base)
-{
-	TaskCmdLink *cmd;
-
-	cmd = (TaskCmdLink *) cmd_base;
-
-	g_object_unref (cmd->project);
-	g_object_unref (cmd->before);
-	g_object_unref (cmd->after);
-}
-
-
-PlannerCmd *
-planner_task_tree_task_cmd_link (PlannerTaskTree *tree,
-				 MrpTask         *before,
-				 MrpTask         *after,
-				 MrpRelationType  relationship,
-				 glong            lag,
-				 GError         **error)
-{
-	PlannerTaskTreePriv *priv = tree->priv;
-	PlannerCmd          *cmd_base;
-	TaskCmdLink         *cmd;
-
-	cmd = g_new0 (TaskCmdLink, 1);
-
-	cmd_base = (PlannerCmd*) cmd;
-	cmd_base->label = g_strdup (_("Link task"));
-	cmd_base->do_func = task_cmd_link_do;
-	cmd_base->undo_func = task_cmd_link_undo;
-	cmd_base->free_func = task_cmd_link_free;
-
-	cmd->project = g_object_ref (tree->priv->project);
-
-	cmd->before = g_object_ref (before);
-	cmd->after = g_object_ref (after);
-	cmd->relationship = relationship;
-	cmd->lag = lag;
-			
-	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager 
-					   (priv->main_window),
-					   cmd_base);
-
-	if (cmd->error) {
-		g_propagate_error (error, cmd->error);
-		return NULL;
-	}
-
-	return cmd_base;	
-}
-
-static gboolean
-task_cmd_unlink_do (PlannerCmd *cmd_base)
-{
-	TaskCmdLink *cmd;
-	
-	cmd = (TaskCmdLink*) cmd_base;
-
-	if (g_getenv ("PLANNER_DEBUG_UNDO_TASK")) {
-		g_message ("Removing the link ...");
-	}
-	
-	mrp_task_remove_predecessor (cmd->after, cmd->before);
-
-	return TRUE;
-}
-
-static void
-task_cmd_unlink_undo (PlannerCmd *cmd_base)
-{
-	TaskCmdLink *cmd;
-	GError      *error;
-	MrpRelation *relation;
-
-	cmd = (TaskCmdLink *) cmd_base;
-
-	relation = mrp_task_add_predecessor (cmd->after,
-					     cmd->before,
-					     cmd->relationship,
-					     cmd->lag,
-					     &error);
-	g_assert (relation);
-}
-
-static PlannerCmd *
-task_cmd_unlink (PlannerTaskTree *tree,
-		 MrpRelation     *relation)
-{
-	PlannerTaskTreePriv *priv = tree->priv;
-	PlannerCmd          *cmd_base;
-	TaskCmdLink         *cmd;
-
-	cmd = g_new0 (TaskCmdLink, 1);
-
-	cmd_base = (PlannerCmd*) cmd;
-	cmd_base->label = g_strdup (_("Unlink task"));
-	cmd_base->do_func = task_cmd_unlink_do;
-	cmd_base->undo_func = task_cmd_unlink_undo;
-	cmd_base->free_func = task_cmd_link_free;
-	
-	cmd->project = g_object_ref (tree->priv->project);
-
-	cmd->before = g_object_ref (mrp_relation_get_predecessor (relation));
-	cmd->after = g_object_ref (mrp_relation_get_successor (relation));
-	cmd->relationship = mrp_relation_get_relation_type (relation);
-	cmd->lag = mrp_relation_get_lag (relation);
-			
-	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager 
-					   (priv->main_window),
-					   cmd_base);
-	return cmd_base;
-}
-
-typedef struct {
-	PlannerCmd   base;
-
 	MrpTask      *task;
 	MrpProperty  *property;  
 	GValue       *value;
@@ -3018,7 +2858,7 @@ planner_task_tree_unlink_task (PlannerTa
 			/* mrp_task_remove_predecessor (
 			   task, mrp_relation_get_predecessor (relation)); */
 
-			task_cmd_unlink (tree, relation); 
+			planner_task_cmd_unlink (tree->priv->main_window, relation); 
 		}
 
 		g_list_free (relations);
@@ -3030,7 +2870,7 @@ planner_task_tree_unlink_task (PlannerTa
 			/* mrp_task_remove_predecessor (
 			   mrp_relation_get_successor (relation), task); */
 
-			task_cmd_unlink (tree, relation);
+			planner_task_cmd_unlink (tree->priv->main_window, relation);
 		}
 
 		g_list_free (relations);
@@ -3062,7 +2902,7 @@ planner_task_tree_link_tasks (PlannerTas
 
 		task = l->data;
 
-		cmd = planner_task_tree_task_cmd_link (tree, task, target_task, 
+		cmd = planner_task_cmd_link (tree->priv->main_window, task, target_task, 
 						       relationship, 0, &error);
 
 		/* cmd = mrp_task_add_predecessor (target_task,

Attachment: signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente



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