Re: [Planner Dev] Patch for planner Bugzilla 138595 Task up and down should work on selections.




Ha ha... guess what ? - just noticed that there was
no g_list_free(list) at the end of either the planner_task_tree_move_task_up()
or planner_task_tree_move_task_down() so those have potentially
been leaking since MrProject.

Attached is version 2 with the required g_list_free(list); !!

Rgds,
Lincoln.

lincoln phipps openmutual net wrote:


http://bugzilla.gnome.org/show_bug.cgi?id=138595
(Task up and down should work on selections.)

Attached is a standalone patch that allows you to select a
range of tasks and do a move up and move down within gantt
and task view.  A very handy feature when rearranging your
schedule :)

Before only individual tasks could be moved which meant
that shifting your task schedule design could be tedious.

It handles all sane selections including ctrl-clicking a
discountinuous list of tasks (which would be a weird
thing to do in practice but it works anyway).

Rgds,
Lincoln.



Index: src/planner-task-tree.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-tree.c,v
retrieving revision 1.14
diff -u -b -B -p -r1.14 planner-task-tree.c
--- src/planner-task-tree.c	28 Mar 2004 23:03:49 -0000	1.14
+++ src/planner-task-tree.c	6 Apr 2004 01:29:20 -0000
@@ -2163,9 +2163,11 @@ planner_task_tree_move_task_up (PlannerT
 	GtkTreeModel	 *model;
 	GtkTreePath	 *path;
 	MrpProject  	 *project;
-	MrpTask	    	 *task, *parent, *sibling;
-	GList	    	 *list;
+	MrpTask	    	 *task, *parent, *sibling, *temptask;
+	GList	    	 *list, *l, *m;
 	guint	    	  position;
+	gboolean	  proceed, skip;
+	gint		  count;
 
 	/* FIXME: undo */
 	
@@ -2180,15 +2182,33 @@ planner_task_tree_move_task_up (PlannerT
 		return;
 	} 
 
-	task = list->data;
+	proceed = TRUE;  /* seed this */
+	count = 0 ;
+
+	for (l = list; l; l = l->next) {
+		count++;
+		task = l->data;
 	position = mrp_task_get_position (task);
 	parent = mrp_task_get_parent (task);
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
 	model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
 	
-	if (position == 0) {
-		/* Task on the top of the list */
-	} else {
+		/* We now check if the parent is selected as well me. as If it is then 
+		* we skip checks on our position and skip moving because its just not relevant ! 
+		*/
+		skip = FALSE;
+		for (m = list; m; m = m->next) {
+			temptask = m->data;
+			if (temptask == parent ) {
+				skip = TRUE; 
+			}
+		}
+		
+		if (position == 0 && count ==1) {
+			/* We should stop everything if at top of list and first task else just stop moving this one task */
+			proceed = FALSE;
+		} 
+		if (skip == FALSE && position != 0 && proceed) {
 		sibling = mrp_task_get_nth_child (parent, 
 						  position - 1);
 		
@@ -2199,8 +2219,10 @@ planner_task_tree_move_task_up (PlannerT
 			PLANNER_GANTT_MODEL (model), task);
 		gtk_tree_selection_select_path (selection, path);
 	}
+	}
 
 	task_tree_unblock_selection_changed (tree);
+	g_list_free (list);
 }
 
 void 
@@ -2210,9 +2232,11 @@ planner_task_tree_move_task_down (Planne
 	GtkTreeModel	 *model;
 	GtkTreePath	 *path;
 	MrpProject 	 *project;
-	MrpTask	   	 *task, *parent, *sibling;
-	GList		 *list;
+	MrpTask	   	 *task, *parent, *sibling, *temptask;
+	GList		 *list, *l , *m;
 	guint		  position;
+	gboolean	  proceed, skip;
+	gint		  count;
 
 	/* FIXME: undo */
 
@@ -2225,16 +2249,38 @@ planner_task_tree_move_task_down (Planne
 	if (list == NULL) {
 		/* Nothing selected */
 		return;
-	} else {
-		task = list->data;
+	} 	
+
+	list = g_list_reverse (list);  /* swap the selection around */
+
+	proceed = TRUE;  /* seed this */
+	count = 0 ;
+
+	for (l = list; l; l = l->next) {
+		count++;
+		task = l->data;
 		position = mrp_task_get_position (task);
 		parent = mrp_task_get_parent (task);
 		selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
 		model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
 
-		if (position == (mrp_task_get_n_children (parent) - 1) ) {
-			/* The task is in the bottom of the list */
-		} else {
+		/* We now check if the parent is selected as well me. If it is then we skip checks on our position AS its not relevant  */
+		skip = FALSE;
+		for (m = list; m; m = m->next) {
+				temptask = m->data;
+				if (temptask == parent ) {
+					skip = TRUE; 
+				}
+		}
+	
+		if (position == (mrp_task_get_n_children (mrp_project_get_root_task (project)) - 1) && count ==1) {
+			/* We should stop everything if at bottom of project and first attempt at moving stuff else just stop moving this one task */
+			proceed = FALSE;
+		} else if ((skip == FALSE) && (position == (mrp_task_get_n_children (parent) - 1)) && (count ==1)) {
+			/* If the parent task is selected then we don't care if we are at the bottom of our particular position */ 
+			proceed = FALSE;
+		} 
+		if (skip == FALSE && position <= (mrp_task_get_n_children (parent) - 1) && proceed) {
 			sibling = mrp_task_get_nth_child (parent, position + 1);
 			/* Moving task from 'position' to 'position + 1' */
 			mrp_project_move_task (project, task, sibling, 
@@ -2246,6 +2292,7 @@ planner_task_tree_move_task_down (Planne
 	}
 
 	task_tree_unblock_selection_changed (tree);
+	g_list_free (list);
 }
 
 void


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