Re: [Planner Dev] Planner enhancement ** Link button patch against 0.11 CVS.



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Richard,

	OK - have gone through and cleaned up my code to have
/*
*
*/

style of comments.

I've also gone through manually and fixed up my edits.
I was using Kwrite and it was dropping whitespace at
end of lines.

I don't seem to be able to make Cervisia ignore whitespace
in its diffs. It has an options field but doesn't pass
to the diff. I'm using its...

~ Advanced -> Create patch against repository

function. The attached diff is a lot cleaner now and
only includes what I've specifically changed.

When I looked at what I did - it was really all cut+paste
of existing code. The only extra bits were some logic for
counting when >=2 things were clicked and thats two or so
lines so not worth changing copyright just yet.

I'll have to think more on the shift-click/ctrl-click
modifiers once I learn more on coding. As it stands my
Link button is a useful feature and I'll enhance it later
once I've had feedback from users and learn more on how to
add sub-submenus (?) under the Action menu.

Rgds,
Lincoln.

Richard Hult wrote:
| tis 2004-02-10 klockan 16.50 skrev lincoln phipps openmutual net:
|
| Hi!
|
|
|>My first attempt at any GNOME coding - a cut+past job if
|>ever there was !. I'm using Cervisia to manage CVS and
|>do the diff but never used it before in anger so please
|>feedback if using it wrong. Also whats the copyright
|>release procedure  for Planner ?
|
|
| Cool! The patch looks like it's a good start, but it would be great if
| you could adjust the coding style in a few places so if follows:
|
| for () {  <-- brace on the same line
|   <-- code on the next line
|
| }
|
| No C++ comments, only /* ... */
|
| Is it possible specify which options to use for producing diffs with
| Cervisia? It would be easier to review if you could use "diff -ubBp"
| (one of the options tell diff to not care about white-space changes
| only).
|
| About copyright, you should add yourself to the files where you write
| more than a few lines that aren't just copy/paste.
|
|
|>The following patch adds a Link button to the menus and
|>GUI.
|>
|>If you ctrl-click tasks in Task or Gantt view and then
|>click the Link button it puts a FS link between these.
|>Multiple items cause it to cascade links as it walks
|>through the task list.
|
|
| Nice!
|
|
|>I want to add shift-click and ctrl-click to modify the
|>MRP_RELATION_XX behaviour but don't know anything
|>about GNOME gui stuff to trap this message type.
|
|
| Hmm, I don't think using modifiers when clicking toolbar buttons is very
| common. Maybe we could put the less common cases in a menu and have
| shortcut keys for those?
|
| Thanks,
| Richard
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFAKagJVo/F3CLIt9cRAlIqAJ9lUZNg+vk1tuMt2dMJvZWmdtNDkgCdH3jd
guUr5NJ3TqlepsTHPdqzt64=
=+Lsr
-----END PGP SIGNATURE-----
? data/images/24_link_tasks.png
Index: data/images/Makefile.am
===================================================================
RCS file: /cvs/gnome/planner/data/images/Makefile.am,v
retrieving revision 1.2
diff -u -r1.2 Makefile.am
--- data/images/Makefile.am	23 Jan 2004 00:48:19 -0000	1.2
+++ data/images/Makefile.am	11 Feb 2004 03:10:21 -0000
@@ -10,6 +10,7 @@
 	24_insert_task.png		\
 	24_remove_task.png		\
 	24_unlink_task.png		\
+	24_link_tasks.png		\
 	24_indent_task.png		\
 	24_unindent_task.png		\
 	24_insert_resource.png		\
Index: data/ui/gantt-view.ui
===================================================================
RCS file: /cvs/gnome/planner/data/ui/gantt-view.ui,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 gantt-view.ui
--- data/ui/gantt-view.ui	1 Dec 2003 17:36:55 -0000	1.1.1.1
+++ data/ui/gantt-view.ui	11 Feb 2004 03:10:21 -0000
@@ -4,7 +4,8 @@
     <cmd name="RemoveTask"          _label="_Remove Task"             pixtype="stock" pixname="planner-stock-remove-task" sensitive="0"/>
     <cmd name="InsertTasks"         _label="In_sert Tasks..."         pixtype="stock" pixname="planner-stock-insert-task"/>
     <cmd name="EditTask"            _label="_Edit Task Properties..." sensitive="0"/>
-    <cmd name="UnlinkTask"          _label="Un_link Task"              pixtype="stock" pixname="planner-stock-unlink-task"/>
+    <cmd name="UnlinkTask"          _label="_Unlink Task"              pixtype="stock" pixname="planner-stock-unlink-task"/>
+    <cmd name="LinkTasks"          _label="_Link Tasks"              pixtype="stock" pixname="planner-stock-link-tasks"/>
     <cmd name="ResetConstraint"     _label="Reset _Constraint" sensitive="0"/>
     <cmd name="ResetAllConstraints" _label="Reset _All Constraints"/>
     <cmd name="SelectAll"           _label="Select _All"              _tip="Select all tasks"/>
@@ -44,6 +45,7 @@
         <menuitem name="InsertTasks"         verb=""/>
 	<menuitem name="RemoveTask"          verb=""/>
         <menuitem name="UnlinkTask"          verb=""/>
+	<menuitem name="LinkTasks"          verb=""/>
         <separator/>
         <menuitem name="IndentTask"          verb=""/>
         <menuitem name="UnindentTask"        verb=""/>
@@ -63,6 +65,7 @@
     <toolitem name="InsertTask"   verb="" _label="Insert"/>
     <toolitem name="RemoveTask"   verb="" _label="Remove"/>
     <toolitem name="UnlinkTask"   verb="" _label="Unlink"/>
+        <toolitem name="LinkTasks"   verb="" _label="Link"/>
     <toolitem name="IndentTask"   verb="" _label="Indent"/>
     <toolitem name="UnindentTask" verb="" _label="Unindent"/>
     <separator/>
Index: data/ui/task-view.ui
===================================================================
RCS file: /cvs/gnome/planner/data/ui/task-view.ui,v
retrieving revision 1.2
diff -u -r1.2 task-view.ui
--- data/ui/task-view.ui	16 Dec 2003 15:50:21 -0000	1.2
+++ data/ui/task-view.ui	11 Feb 2004 03:10:21 -0000
@@ -4,7 +4,8 @@
     <cmd name="InsertTasks"         _label="In_sert Tasks..."           pixtype="stock" pixname="planner-stock-insert-task"/>
     <cmd name="RemoveTask"          _label="_Remove Task"               pixtype="stock" pixname="planner-stock-remove-task"    sensitive="0"/>
     <cmd name="EditTask"            _label="_Edit Task Properties..."                                                     sensitive="0"/>
-    <cmd name="UnlinkTask"          _label="Un_link Task"               pixtype="stock" pixname="planner-stock-unlink-task"/>
+    <cmd name="UnlinkTask"          _label="_Unlink Task"               pixtype="stock" pixname="planner-stock-unlink-task"/>
+        <cmd name="LinkTasks"          _label="_Link Tasks"               pixtype="stock" pixname="planner-stock-link-tasks"/>
     <cmd name="SelectAll"           _label="Select _All"                 _tip="Select all tasks"/>
     <cmd name="ResetConstraint"     _label="Reset _Constraint"                                                            sensitive="0"/>
     <cmd name="ResetAllConstraints" _label="Reset _All Constraints"/>
@@ -37,6 +38,7 @@
         <menuitem name="InsertTasks"         verb=""/>
 	<menuitem name="RemoveTask"          verb=""/>
         <menuitem name="UnlinkTask"          verb=""/>
+	<menuitem name="LinkTasks"          verb=""/>
         <separator/>
         <menuitem name="IndentTask"          verb=""/>
         <menuitem name="UnindentTask"        verb=""/>
@@ -58,6 +60,7 @@
     <toolitem name="InsertTask"   verb="" _label="Insert"/>
     <toolitem name="RemoveTask"   verb="" _label="Remove"/>
     <toolitem name="UnlinkTask"   verb="" _label="Unlink"/>
+    <toolitem name="LinkTasks"   verb="" _label="Link"/>
     <toolitem name="IndentTask"   verb="" _label="Indent"/>
     <toolitem name="UnindentTask" verb="" _label="Unindent"/>
     <toolitem name="MoveTaskUp"	  verb="" _label="Move up"/>
Index: src/planner-application.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-application.c,v
retrieving revision 1.4
diff -u -r1.4 planner-application.c
--- src/planner-application.c	11 Dec 2003 10:52:46 -0000	1.4
+++ src/planner-application.c	11 Feb 2004 03:10:23 -0000
@@ -71,6 +71,13 @@
 		0, /*keyval*/
 		GETTEXT_PACKAGE
 	},
+		{
+		"planner-stock-link-tasks",
+		N_("Link"),
+		0, /*GdkModifierType*/
+		0, /*keyval*/
+		GETTEXT_PACKAGE
+	},
 	{
 		"planner-stock-indent-task",
 		N_("Indent"),
Index: src/planner-gantt-view.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-gantt-view.c,v
retrieving revision 1.5
diff -u -r1.5 planner-gantt-view.c
--- src/planner-gantt-view.c	16 Dec 2003 22:07:08 -0000	1.5
+++ src/planner-gantt-view.c	11 Feb 2004 03:10:25 -0000
@@ -80,6 +80,9 @@
 static void       gantt_view_unlink_task_cb               (BonoboUIComponent            *component,
 							   gpointer                      data,
 							   const char                   *cname);
+static void       gantt_view_link_tasks_cb               (BonoboUIComponent            *component,
+							   gpointer                      data,
+							   const char                   *cname);
 static void       gantt_view_indent_task_cb               (BonoboUIComponent            *component,
 							   gpointer                      data,
 							   const char                   *cname);
@@ -156,6 +159,7 @@
 	BONOBO_UI_VERB ("EditTask",		gantt_view_edit_task_cb),
 	BONOBO_UI_VERB ("SelectAll",		gantt_view_select_all_cb),
 	BONOBO_UI_VERB ("UnlinkTask",		gantt_view_unlink_task_cb),
+	BONOBO_UI_VERB ("LinkTasks",		gantt_view_link_tasks_cb),
 	BONOBO_UI_VERB ("IndentTask",		gantt_view_indent_task_cb),
 	BONOBO_UI_VERB ("UnindentTask",		gantt_view_unindent_task_cb),
 	BONOBO_UI_VERB ("MoveTaskUp",           gantt_view_move_task_up_cb),
@@ -242,6 +246,13 @@
 			      "planner-stock-unlink-task",
 			      icon_set);
 
+	pixbuf = gdk_pixbuf_new_from_file (IMAGEDIR "/24_link_tasks.png", NULL);
+	icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
+	g_object_unref (pixbuf);
+	gtk_icon_factory_add (icon_factory,
+			      "planner-stock-link-tasks",
+			      icon_set);
+
 	pixbuf = gdk_pixbuf_new_from_file (IMAGEDIR "/24_indent_task.png", NULL);
 	icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
 	g_object_unref (pixbuf);
@@ -654,6 +665,21 @@
 }
 
 static void
+gantt_view_link_tasks_cb (BonoboUIComponent *component,
+			   gpointer           data,
+			   const char        *cname)
+{
+	PlannerView *view;
+
+	view = PLANNER_VIEW (data);
+/* TODO: need to get a way of easily modifying the options to tweak the link relationships between the tasks
+*	from the most common option of FS i.e. finish to start. Maybe project-wide flag, maybe menu option
+*	or maybe click-modifiers i.e. Shift+click or Control+click.
+*/
+	planner_task_tree_link_tasks (PLANNER_TASK_TREE (view->priv->tree), MRP_RELATION_FS);
+}
+
+static void
 gantt_view_indent_task_cb (BonoboUIComponent *component, 
 			   gpointer           data, 
 			   const char        *cname)
@@ -929,6 +955,8 @@
 	GList      *list, *l;
 	gchar      *value;
 	gchar      *rel_value = "0";
+	gchar      *link_value = "0";
+	gint        count_value = 0;
 
 	g_return_if_fail (PLANNER_IS_VIEW (view));
 	
@@ -946,8 +974,14 @@
 			break;
 		}
 	}
-	
+
+
+	for (l = list; l; l = l->next) {
+		count_value = count_value + (count_value + 1);
+	}
+
 	value = (list != NULL) ? "1" : "0";
+	link_value = (count_value >= 2) ? "1" : "0";
 
 	bonobo_ui_component_freeze (view->ui_component, NULL);
 
@@ -966,6 +1000,10 @@
 				      "sensitive", rel_value,
 				      NULL);
 
+      	bonobo_ui_component_set_prop (view->ui_component, 
+				      "/commands/LinkTasks",
+				      "sensitive", link_value, 
+				      NULL);
 
 	bonobo_ui_component_set_prop (view->ui_component, 
 				      "/commands/IndentTask",
Index: src/planner-task-tree.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-tree.c,v
retrieving revision 1.9
diff -u -r1.9 planner-task-tree.c
--- src/planner-task-tree.c	25 Jan 2004 12:11:22 -0000	1.9
+++ src/planner-task-tree.c	11 Feb 2004 03:10:27 -0000
@@ -36,6 +36,7 @@
 #include <gtk/gtkstock.h>
 #include <gtk/gtkmessagedialog.h>
 #include <libgnome/gnome-i18n.h>
+#include <libgnomecanvas/gnome-canvas.h>
 #include "planner-format.h"
 #include "planner-marshal.h"
 #include "planner-cell-renderer-date.h"
@@ -143,6 +144,9 @@
 static void        task_tree_popup_unlink_task_cb      (gpointer              callback_data,
 							guint                 action,
 							GtkWidget            *widget);
+static void        task_tree_popup_link_tasks_cb      (gpointer              callback_data,
+							guint                 action,
+							GtkWidget            *widget);
 static void        task_tree_block_selection_changed   (PlannerTaskTree      *tree);
 static void        task_tree_unblock_selection_changed (PlannerTaskTree      *tree);
 static void        task_tree_selection_changed_cb      (GtkTreeSelection     *selection,
@@ -179,6 +183,7 @@
 	POPUP_SUBTASK,
 	POPUP_REMOVE,
 	POPUP_UNLINK,
+	POPUP_LINK,
 	POPUP_EDIT
 };
 
@@ -200,6 +205,9 @@
 	{ N_("/_Unlink task"),       NULL, GIF_CB (task_tree_popup_unlink_task_cb),
 	  POPUP_UNLINK,  "<Item>",   NULL
 	},
+	{ N_("/_Link tasks"),       NULL, GIF_CB (task_tree_popup_link_tasks_cb),
+	  POPUP_LINK,  "<Item>",   NULL
+	},
 	{ "/sep2",                   NULL, 0,
 	  POPUP_NONE,    "<Separator>"
 	},
@@ -517,6 +525,13 @@
 			      "planner-stock-unlink-task",
 			      icon_set);
 
+	pixbuf = gdk_pixbuf_new_from_file (IMAGEDIR "/24_link_tasks.png", NULL);
+	icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
+	g_object_unref (pixbuf);
+	gtk_icon_factory_add (icon_factory,
+			      "planner-stock-link-tasks",
+			      icon_set);
+
 	pixbuf = gdk_pixbuf_new_from_file (IMAGEDIR "/24_indent_task.png", NULL);
 	icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
 	g_object_unref (pixbuf);
@@ -605,6 +620,14 @@
 }
 
 static void
+task_tree_popup_link_tasks_cb (gpointer   callback_data,
+				guint      action,
+				GtkWidget *widget)
+{
+	planner_task_tree_link_tasks (callback_data, MRP_RELATION_FS);
+}
+
+static void
 task_tree_block_selection_changed (PlannerTaskTree *tree)
 {
 	GtkTreeSelection *selection;
@@ -751,6 +774,8 @@
 			gtk_widget_set_sensitive (
 				gtk_item_factory_get_widget_by_action (factory, POPUP_UNLINK), TRUE);
 			gtk_widget_set_sensitive (
+				gtk_item_factory_get_widget_by_action (factory, POPUP_LINK), TRUE);
+			gtk_widget_set_sensitive (
 				gtk_item_factory_get_widget_by_action (factory, POPUP_EDIT), TRUE);
 			
 			gtk_tree_path_free (path);
@@ -764,6 +789,8 @@
 			gtk_widget_set_sensitive (
 				gtk_item_factory_get_widget_by_action (factory, POPUP_UNLINK), FALSE);
 			gtk_widget_set_sensitive (
+				gtk_item_factory_get_widget_by_action (factory, POPUP_LINK), FALSE);
+			gtk_widget_set_sensitive (
 				gtk_item_factory_get_widget_by_action (factory, POPUP_EDIT), FALSE);
 		}
 		
@@ -2066,6 +2093,57 @@
 		g_list_free (relations);
 	}
 	
+	g_list_free (list);
+}
+
+void
+planner_task_tree_link_tasks (PlannerTaskTree *tree, MrpRelationType relationship)
+{
+	MrpTask     *task;
+	MrpTask     *target_task;
+	GList       *list, *l;
+	gint        count_value = 0;
+
+	/* FIXME: undo */
+
+	list = planner_task_tree_get_selected_tasks (tree);
+	if (list == NULL) {
+		return;
+	}
+	/* The next step is simply to fool make (gcc) into not warning on premature use of task
+	*  Without assigning target_task to something gcc complains that it may be used before
+	*  it was assigned a value. Ergo assign it to something. Its because the if() logic in
+	* the for() loop is what upsets the compiler warning.
+	*/
+	l = list;
+	target_task = l->data;
+
+	for (l = list; l; l = l->next) {
+		if (count_value == 0) {
+			target_task = l->data; /* this is the 1st item. We can't link tasks yet */
+		}
+		if (count_value >= 1) {
+			task = target_task;  /* remember the previous item */
+			target_task = l->data; /* now have two items - link them up !! */
+			GError *error = NULL;
+				if (!mrp_task_add_predecessor (target_task,
+							       task,
+							       relationship,
+							       0,
+							       &error)) {
+					GtkWidget *dialog;
+					dialog = gtk_message_dialog_new (NULL,
+									 GTK_DIALOG_DESTROY_WITH_PARENT,
+									 GTK_MESSAGE_ERROR,
+									 GTK_BUTTONS_OK,
+									 "%s", error->message);
+					gtk_dialog_run (GTK_DIALOG (dialog));
+					gtk_widget_destroy (dialog);
+					g_error_free (error);
+				}
+		}
+	count_value = count_value + 1; /* Step on the count of items. This is only used to detect 0,1 many */
+	}
 	g_list_free (list);
 }
 
Index: src/planner-task-tree.h
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-tree.h,v
retrieving revision 1.3
diff -u -r1.3 planner-task-tree.h
--- src/planner-task-tree.h	16 Dec 2003 15:50:22 -0000	1.3
+++ src/planner-task-tree.h	11 Feb 2004 03:10:28 -0000
@@ -66,6 +66,7 @@
 void       planner_task_tree_insert_tasks           (PlannerTaskTree   *tree);
 void       planner_task_tree_select_all             (PlannerTaskTree   *tree);
 void       planner_task_tree_unlink_task            (PlannerTaskTree   *tree);
+void       planner_task_tree_link_tasks             (PlannerTaskTree   *tree, MrpRelationType relationship);
 void       planner_task_tree_indent_task            (PlannerTaskTree   *tree);
 void       planner_task_tree_unindent_task          (PlannerTaskTree   *tree);
 void       planner_task_tree_reset_constraint       (PlannerTaskTree   *tree);
Index: src/planner-task-view.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-view.c,v
retrieving revision 1.4
diff -u -r1.4 planner-task-view.c
--- src/planner-task-view.c	16 Dec 2003 22:07:08 -0000	1.4
+++ src/planner-task-view.c	11 Feb 2004 03:10:28 -0000
@@ -86,6 +86,9 @@
 static void   task_view_unlink_task_cb           (BonoboUIComponent            *component,
 						  gpointer                      data,
 						  const char                   *cname);
+static void   task_view_link_tasks_cb           (BonoboUIComponent            *component,
+						  gpointer                      data,
+						  const char                   *cname);
 static void   task_view_indent_task_cb           (BonoboUIComponent            *component,
 						  gpointer                      data,
 						  const char                   *cname);
@@ -133,6 +136,7 @@
 	BONOBO_UI_VERB ("EditTask",		task_view_edit_task_cb),
 	BONOBO_UI_VERB ("SelectAll",		task_view_select_all_cb),
 	BONOBO_UI_VERB ("UnlinkTask",		task_view_unlink_task_cb),
+	BONOBO_UI_VERB ("LinkTasks",		task_view_link_tasks_cb),
 	BONOBO_UI_VERB ("IndentTask",		task_view_indent_task_cb),
 	BONOBO_UI_VERB ("UnindentTask",		task_view_unindent_task_cb),
 	BONOBO_UI_VERB ("MoveTaskUp",		task_view_move_task_up_cb),
@@ -383,6 +387,18 @@
 }
 
 static void
+task_view_link_tasks_cb (BonoboUIComponent *component,
+			  gpointer           data,
+			  const char        *cname)
+{
+	PlannerView *view;
+
+	view = PLANNER_VIEW (data);
+
+	planner_task_tree_link_tasks (PLANNER_TASK_TREE (view->priv->tree), MRP_RELATION_FS);
+}
+
+static void
 task_view_indent_task_cb (BonoboUIComponent *component, 
 			  gpointer           data, 
 			  const char        *cname)
@@ -571,7 +587,9 @@
 	GList      *list, *l;
 	gchar      *value;
 	gchar      *rel_value = "0";
-	
+	gchar	   *link_value = "0";
+	gint	    count_value = 0;
+
 	if (!view->activated) {
 		return;
 	}
@@ -587,7 +605,12 @@
 		}
 	}
 
+	for (l = list; l; l = l->next) {
+			count_value = count_value + 1;
+	}
+
 	value = (list != NULL) ? "1" : "0";
+	link_value = (count_value >= 2) ? "1" : "0";
 
 	bonobo_ui_component_freeze (view->ui_component, NULL);
 
@@ -604,6 +627,11 @@
 	bonobo_ui_component_set_prop (view->ui_component, 
 				      "/commands/UnlinkTask",
 				      "sensitive", rel_value, 
+				      NULL);
+
+      	bonobo_ui_component_set_prop (view->ui_component, 
+				      "/commands/LinkTasks",
+				      "sensitive", link_value, 
 				      NULL);
 
 	bonobo_ui_component_set_prop (view->ui_component, 

PNG image



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