[Planner Dev] Patch to fix Resource Usage menus and some of the odd display behaviors.




The attached patch fixes..

Edit menu in resource usage view is strange...
http://bugzilla.gnome.org/show_bug.cgi?id=138149 as originally reported.

Zoom to extremes possible on Resource Usage (TTable) view.
http://bugzilla.gnome.org/show_bug.cgi?id=141116 (found during testing)

Tree expansion state gets out of sync in Resource Usage v...
http://bugzilla.gnome.org/show_bug.cgi?id=141117 (found during testing)

Plus adds selections and multi-dialog support to the selections
in the Resource Usage view.

Warning: it doesn't fix...
Certain Undo/redo causes Resource Usage to have duplicate..
http://bugzilla.gnome.org/show_bug.cgi?id=141120
or
Resource usage should keep tasks in WBS order.
http://bugzilla.gnome.org/show_bug.cgi?id=141637

and those two bugs should keep Resource Usage as a beta
feature only and not production. I tried but just couldn't
get the tree and model to stay in sync so leaving those for
someone else :)

Use usual patch command e.g.

patch -p1 <../planner-ttable-menuv0.6.diff

(use p1 to strip a bit of the leading path off). Fixes bundled together
as they are all interrelated in the ttable ui/tree/view/model
files.

Rgds,
Lincoln.
Index: data/ui/time-table-view.ui
===================================================================
RCS file: /cvs/gnome/planner/data/ui/time-table-view.ui,v
retrieving revision 1.2
diff -u -b -B -p -r1.2 time-table-view.ui
--- a/data/ui/time-table-view.ui	6 Apr 2004 20:54:12 -0000	1.2
+++ b/data/ui/time-table-view.ui	3 May 2004 04:39:43 -0000
@@ -1,8 +1,16 @@
 <Root>
   <commands>
+    <cmd name="EditTaskGeneral"     _label="Edit Task _General Page"  sensitive="0"/>
+    <cmd name="EditTaskResources"   _label="Edit Task Res_ources Page"   sensitive="0"/>
+    <cmd name="EditTaskPredecessors" _label="Edit Task _Predecessors Page"   sensitive="0"/>
+    <cmd name="EditTaskNotes"          _label="Edit Task _Notes Page"   sensitive="0"/>
+    <cmd name="EditResource"    _label="Edit _Resource Properties..." pixtype="stock" pixname="gtk-properties"   sensitive="0"/> 
     <cmd name="ZoomIn"              _label="Zoom in"                   pixtype="stock" pixname="gtk-zoom-in"/>
     <cmd name="ZoomOut"             _label="Zoom out"                  pixtype="stock" pixname="gtk-zoom-out"/>
     <cmd name="ZoomToFit"           _label="Zoom to fit"               pixtype="stock" pixname="gtk-zoom-fit"/>
+    <cmd name="SelectAll"           _label="Select _All"              _tip="Select all tasks"/>
+    <cmd name="ExpandAll"           _label="E_xpand All"              _tip="Expand all Resources"/>
+    <cmd name="CollapseAll"         _label="Collapse All"             _tip="Collapse all Resources"/>
   </commands>
 
   <menu>
@@ -10,17 +18,6 @@
       <placeholder name="Selection placeholder">
         <menuitem name="SelectAll"         verb=""   accel="*Control*a"/>
       </placeholder>
-      <placeholder name="View specific placeholder">
-        <menuitem name="InsertTask"         verb=""/>
-        <menuitem name="InsertTasks"        verb=""/>
-        <separator/>
-        <menuitem name="UnindentTask"        verb=""/>
-        <separator/>
-        <menuitem name="ResetConstraint"     verb=""/>
-        <menuitem name="ResetAllConstraints" verb=""/>
-        <separator/>
-        <menuitem name="EditTask"            verb=""   accel="*Shift**Control*e"/>
-      </placeholder>
     </submenu>
 
     <submenu    name="View">
@@ -28,8 +25,23 @@
         <menuitem name="ZoomIn"            verb=""/>
         <menuitem name="ZoomOut"           verb=""/>
         <menuitem name="ZoomToFit"         verb=""/>
+	<separator/>
+	<menuitem name="ExpandAll"           verb=""/>
+        <menuitem name="CollapseAll"         verb=""/>
       </placeholder>
     </submenu>
+    
+    <submenu    name="Actions">
+      <placeholder name="Actions specific actions placeholder">
+          <menuitem name="EditTaskGeneral"       verb=""   accel="*Shift**Control*g"/>
+          <menuitem name="EditTaskResources"     verb=""   accel="*Shift**Control*o"/>
+          <menuitem name="EditTaskPredecessors"  verb=""   accel="*Shift**Control*p"/>
+          <menuitem name="EditTaskNotes"         verb=""   accel="*Shift**Control*n"/>
+	<separator/>
+       <menuitem name="EditResource"        verb=""   accel="*Shift**Control*e"/>
+      </placeholder>
+    </submenu>
+    
   </menu>
 
   <dockitem name="Toolbar">
Index: src/planner-ttable-model.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-ttable-model.c,v
retrieving revision 1.4
diff -u -b -B -p -r1.4 planner-ttable-model.c
--- a/src/planner-ttable-model.c	22 Jan 2004 23:24:28 -0000	1.4
+++ b/src/planner-ttable-model.c	3 May 2004 04:39:45 -0000
@@ -65,6 +65,13 @@ static void	ttable_model_resource_added_
 static void	ttable_model_resource_removed_cb		(MrpProject	*project,
 								 MrpResource	*resource,
 								 PlannerTtableModel	*model);
+static void	ttable_model_task_added_cb			(MrpProject		*project,
+								 MrpTask		*task,
+								 PlannerTtableModel	*model);
+static void	ttable_model_task_removed_cb			(MrpProject		*project,
+								 MrpTask		*task,
+								 PlannerTtableModel	*model);	 
+
 /*
 static void	ttable_model_assignment_removed_cb		(MrpAssignment	*assign,
 								 GParamSpec	*spec,
@@ -200,6 +207,24 @@ ttable_model_class_init	(PlannerTtableMo
 			      G_TYPE_NONE,
 			      1, MRP_TYPE_TASK);
 	
+	signals[ASSIGNMENT_ADDED] =
+		g_signal_new ("assignment-added",
+			      G_TYPE_FROM_CLASS (klass),
+			      G_SIGNAL_RUN_LAST,
+			      0,
+			      NULL, NULL,
+			      planner_marshal_VOID__OBJECT,
+			      G_TYPE_NONE,
+			      1, MRP_TYPE_ASSIGNMENT);
+	signals[ASSIGNMENT_REMOVED] =
+		g_signal_new ("assignment-removed",
+			      G_TYPE_FROM_CLASS (klass),
+			      G_SIGNAL_RUN_LAST,
+			      0,
+			      NULL, NULL,
+			      planner_marshal_VOID__OBJECT,
+			      G_TYPE_NONE,
+			      1, MRP_TYPE_ASSIGNMENT);	
 }
 
 static int
@@ -572,6 +597,16 @@ planner_ttable_model_new (MrpProject *pr
 			G_CALLBACK(ttable_model_resource_removed_cb),
 			model,
 			0);
+	g_signal_connect_object(project,
+			"task_inserted", /* This is whats used in mrp-project.c */
+			G_CALLBACK(ttable_model_task_added_cb),
+			model,
+			0);
+	g_signal_connect_object(project,
+			"task_removed",
+			G_CALLBACK(ttable_model_task_removed_cb),
+			model,
+			0);
 	priv->in_new=FALSE;
 	return model;
 }
@@ -820,6 +855,26 @@ ttable_model_resource_removed_cb (MrpPro
 	gtk_tree_path_free (path);
 }
 
+static void
+ttable_model_task_added_cb 	(MrpProject         *project,
+				MrpTask             *task,
+				PlannerTtableModel  *model)
+{
+	
+	g_signal_emit (model, signals[TASK_ADDED] ,0, task);
+
+}
+
+static void
+ttable_model_task_removed_cb 	(MrpProject         *project,
+				 MrpTask            *task,
+				 PlannerTtableModel *model)
+{
+	
+	g_signal_emit (model, signals[TASK_REMOVED] ,0, task);
+
+}
+
 /*
 static void
 ttable_model_assignment_removed_cb		(MrpAssignment	*assign,
Index: src/planner-ttable-tree.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-ttable-tree.c,v
retrieving revision 1.5
diff -u -b -B -p -r1.5 planner-ttable-tree.c
--- a/src/planner-ttable-tree.c	27 Apr 2004 18:58:02 -0000	1.5
+++ b/src/planner-ttable-tree.c	3 May 2004 04:39:46 -0000
@@ -42,6 +42,9 @@
 #include "planner-ttable-tree.h"
 #include "planner-ttable-model.h"
 
+#define WARN_ITEM_DIALOGS 10
+#define MAX_ITEM_DIALOGS 25
+
 enum {
 	SELECTION_CHANGED,
 	EXPAND_ALL,
@@ -64,7 +67,10 @@ static void	 ttable_tree_finalize				(GO
 static void	 ttable_tree_popup_edit_resource_cb		(gpointer		 callback_data,
 								 guint			 action,
 								 GtkWidget		*widget);
-static void	 ttable_tree_popup_edit_task_cb			(gpointer		 callback_data,
+static void	 ttable_tree_popup_edit_task_page_general_cb	(gpointer		 callback_data,
+								 guint			 action,
+								 GtkWidget		*widget);
+static void	 ttable_tree_popup_edit_task_page_resources_cb	(gpointer		 callback_data,
 								 guint			 action,
 								 GtkWidget		*widget);
 static void	 ttable_tree_popup_expand_all_cb		(gpointer		 callback_data,
@@ -90,13 +96,15 @@ enum {
 	POPUP_NONE,
 	POPUP_REDIT,
 	POPUP_TEDIT,
+	POPUP_AEDIT,
 	POPUP_EXPAND,
 	POPUP_COLLAPSE
 };
 
 static GtkItemFactoryEntry popup_menu_items[] = {
-	{ N_("/_Edit resource..."),	NULL,	GIF_CB (ttable_tree_popup_edit_resource_cb),	POPUP_REDIT,	"<Item>",	NULL	},
-	{ N_("/_Edit task..."),		NULL,	GIF_CB (ttable_tree_popup_edit_task_cb),	POPUP_TEDIT,	"<Item>",	NULL	},
+	{ N_("/Edit _resource..."),	NULL,	GIF_CB (ttable_tree_popup_edit_resource_cb),	POPUP_REDIT,	"<Item>",	NULL	},
+	{ N_("/Edit _task..."),		NULL,	GIF_CB (ttable_tree_popup_edit_task_page_general_cb),	POPUP_TEDIT,	"<Item>",	NULL	},
+	{ N_("/Edit task _assignment..."),	NULL,	GIF_CB (ttable_tree_popup_edit_task_page_resources_cb),	POPUP_AEDIT,	"<Item>",	NULL	},
 	{ "/sep1",			NULL,	0,						POPUP_NONE,	"<Separator>" },
 	{ N_("/_Expand all resources"),	NULL,	GIF_CB (ttable_tree_popup_expand_all_cb),	POPUP_EXPAND,	"<Item>",	NULL	},
 	{ N_("/_Collapse all resources"), NULL,	GIF_CB (ttable_tree_popup_collapse_all_cb),	POPUP_COLLAPSE,	"<Item>",	NULL	},
@@ -207,6 +215,7 @@ planner_ttable_tree_set_model (PlannerTt
 	gtk_tree_view_set_model (GTK_TREE_VIEW (tree),
 				 GTK_TREE_MODEL (model));
 	gtk_tree_view_expand_all (GTK_TREE_VIEW (tree));
+	
 }
 
 static void
@@ -346,15 +355,23 @@ ttable_tree_popup_edit_resource_cb	(gpoi
 					 guint		 action,
 					 GtkWidget	*widget)
 {
-	planner_ttable_tree_edit_resource(callback_data);
+	planner_ttable_tree_edit_resource (callback_data);
+}
+
+static void
+ttable_tree_popup_edit_task_page_general_cb (gpointer	 callback_data,
+					 guint		 action,
+					 GtkWidget	*widget)
+{
+	planner_ttable_tree_edit_task (callback_data, PLANNER_TASK_DIALOG_PAGE_GENERAL);
 }
 
 static void
-ttable_tree_popup_edit_task_cb		(gpointer	 callback_data,
+ttable_tree_popup_edit_task_page_resources_cb (gpointer	 callback_data,
 					 guint		 action,
 					 GtkWidget	*widget)
 {
-	planner_ttable_tree_edit_task(callback_data);
+	planner_ttable_tree_edit_task (callback_data, PLANNER_TASK_DIALOG_PAGE_RESOURCES);
 }
 
 static void
@@ -394,61 +411,192 @@ planner_ttable_tree_edit_resource	(Plann
 	MrpResource		*resource;
 	MrpAssignment		*assignment;
 	GtkWidget		*dialog;
-	GList			*list;
+	GList			*list, *l;
+	GHashTable		*resource_hash;
+	gint			i;
+	gint			result;
+	gboolean		proceed;
 
 	g_return_if_fail(PLANNER_IS_TTABLE_TREE(tree));
 
 	priv = tree->priv;
 
 	list = planner_ttable_tree_get_selected_items(tree);
-	if (list==NULL)
+	if (list==NULL) {
 		return;
+	}
+
+	/* Count how many things are actually resources in our selection so we give a sensible warning */
+
+	resource_hash = g_hash_table_new (g_str_hash, g_str_equal);
 
-	if (MRP_IS_RESOURCE(list->data)) {
-		resource = MRP_RESOURCE(list->data);
+ 	for (l = list; l ; l = l->next) {
+		if (MRP_IS_RESOURCE(l->data)) {
+			resource = MRP_RESOURCE(l->data);
 	} else {
-		assignment = MRP_ASSIGNMENT(list->data);
-		resource = mrp_assignment_get_resource(assignment);
+			assignment = MRP_ASSIGNMENT(l->data);
+			resource = mrp_assignment_get_resource (assignment);
+	}
+		g_hash_table_insert (resource_hash, g_strdup (mrp_resource_get_name (resource)), g_strdup(""));
 	}
 
+
+	/* We do it his way because the hash table doesn't count duplicate selected resources. */
+	i = g_hash_table_size (resource_hash);
+	g_hash_table_destroy (resource_hash);
+	
+	proceed = TRUE;
+
+	if (i >= WARN_ITEM_DIALOGS ) {
+		/* FIXME: Use ngettext when we've left the stone ages
+		 * (i.e. GNOME 2.0). Also this whole thing with several dialogs
+		 * is just a workaround for now, should replace it with a
+		 * multitask editing dialog for setting a property to the same
+		 * value for all selected tasks. We also need to improve the way
+		 * data is input generally in the views.
+		 */
+	 
+		dialog = gtk_message_dialog_new (NULL,
+						 GTK_DIALOG_DESTROY_WITH_PARENT,
+						 GTK_MESSAGE_QUESTION,
+						 GTK_BUTTONS_YES_NO,
+						 _("You are about to open an edit dialog each for %i resources. "
+						   "Are you sure that you want to do that?"),
+						  i );
+		
+		result = gtk_dialog_run (GTK_DIALOG (dialog));
+		gtk_widget_destroy (dialog);
+		
+		switch (result) {
+		case GTK_RESPONSE_YES:
+			proceed= TRUE;
+			break;
+		default:
+			proceed = FALSE;
+			break;
+		}
+	}
+	
+	
+	if (proceed) {
+		resource = NULL;
+		assignment = NULL;
+		resource_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+ 		for (l = list, i= 0; l && i <= MAX_ITEM_DIALOGS ; l = l->next) {
+			if (MRP_IS_RESOURCE(l->data)) {
+				resource = MRP_RESOURCE(l->data);
+			} else {
+				assignment = MRP_ASSIGNMENT(l->data);
+				resource = mrp_assignment_get_resource (assignment);
+			}
 	dialog = planner_resource_dialog_new (priv->main_window, resource);
 	gtk_widget_show (dialog);
-	g_list_free(list);
+			/* Next two lines used as a simple no-duplicate item counter */
+			g_hash_table_insert (resource_hash, g_strdup (mrp_resource_get_name (resource)), g_strdup(""));
+			i = g_hash_table_size (resource_hash);
+		}
+		g_hash_table_destroy (resource_hash);
+ 	}
+
+	g_list_free (list);
 }
 
+
 void
-planner_ttable_tree_edit_task	(PlannerTtableTree	*tree)
+planner_ttable_tree_edit_task	(PlannerTtableTree	*tree, PlannerTaskDialogPage page)
 {
 	PlannerTtableTreePriv	*priv;
 	MrpAssignment		*assignment;
 	MrpTask			*task;
 	GtkWidget		*dialog;
 	GList			*list, *l;
+	GHashTable		*task_hash;
+	gint			i;
+	gint			result;
+	gboolean		proceed;
 
 	g_return_if_fail(PLANNER_IS_TTABLE_TREE(tree));
 
 	priv = tree->priv;
 
 	list = planner_ttable_tree_get_selected_items(tree);
-	if (list==NULL)
+	
+	if (list==NULL) {
 		return;
+	}
 
-	assignment = NULL;
-	l = list;
-	while (l != NULL && assignment == NULL) {
-		if (MRP_IS_ASSIGNMENT(l->data)) {
-			assignment = MRP_ASSIGNMENT(l->data);
-		} else {
-			l = l->next;
+	/* Count how many things are actually assignment (i.e. tasks) in our selection so we give a sensible warning */
+
+	task_hash = g_hash_table_new (g_str_hash, g_str_equal);
+					     
+ 	for (l = list; l ; l = l->next) {
+ 		if (MRP_IS_ASSIGNMENT (l->data)) {
+ 			assignment = MRP_ASSIGNMENT (l->data);
+ 				if (assignment != NULL) {
+ 					task = mrp_assignment_get_task (assignment);
+ 					g_hash_table_insert (task_hash, g_strdup (mrp_task_get_name (task)), g_strdup(""));
+ 				}
 		}
 	}
-	if (assignment == NULL)
-		return;
-	task = mrp_assignment_get_task(assignment);
 
-	dialog = planner_task_dialog_new (priv->main_window, task,
-					  PLANNER_TASK_DIALOG_PAGE_GENERAL);
+	/* TODO: What about tasks with same named ? Um. Maybe we should hash on ID or something */
+	i = g_hash_table_size (task_hash);
+	g_hash_table_destroy (task_hash);
+	
+	proceed = TRUE;
+ 
+	if (i >= WARN_ITEM_DIALOGS ) {
+		/* FIXME: Use ngettext when we've left the stone ages
+		 * (i.e. GNOME 2.0). Also this whole thing with several dialogs
+		 * is just a workaround for now, should replace it with a
+		 * multitask editing dialog for setting a property to the same
+		 * value for all selected tasks. We also need to improve the way
+		 * data is input generally in the views.
+		 */
+	 
+		dialog = gtk_message_dialog_new (NULL,
+						 GTK_DIALOG_DESTROY_WITH_PARENT,
+						 GTK_MESSAGE_QUESTION,
+						 GTK_BUTTONS_YES_NO,
+						 _("You are about to open an edit dialog each for up to %i tasks. "
+						   "Are you sure that you want to do that?"),
+						 (i<MAX_ITEM_DIALOGS) ? i : MAX_ITEM_DIALOGS );
+		
+		result = gtk_dialog_run (GTK_DIALOG (dialog));
+		gtk_widget_destroy (dialog);
+		
+		switch (result) {
+		case GTK_RESPONSE_YES:
+			proceed= TRUE;
+			break;
+		default:
+			proceed = FALSE;
+			break;
+		}
+	}
+	
+	/* Based on the user reply we would either proceed or not */
+ 	if (proceed) {
+		assignment = NULL;
+		task = NULL;
+		task_hash = g_hash_table_new (g_str_hash, g_str_equal);
+		
+ 		for (l = list, i = 0; l && i <= MAX_ITEM_DIALOGS; l = l->next, i++) {
+ 			if (MRP_IS_ASSIGNMENT (l->data)) {
+ 				assignment = MRP_ASSIGNMENT (l->data);
+ 				if (assignment != NULL) {
+ 					task = mrp_assignment_get_task (assignment);
+ 					dialog = planner_task_dialog_new (priv->main_window, task, page);
 	gtk_widget_show (dialog);
+					g_hash_table_insert (task_hash, g_strdup (mrp_task_get_name (task)), g_strdup(""));
+					i = g_hash_table_size (task_hash);
+ 				}
+ 			}
+ 		}
+		g_hash_table_destroy (task_hash);
+ 	}
+	
 	g_list_free (list);
 }
 
@@ -516,6 +664,10 @@ ttable_tree_tree_view_button_press_event
 	PlannerTtableTreePriv	*priv;
 	PlannerTtableModel		*model;
 	GtkItemFactory		*factory;
+	GtkTreeIter          	iter;
+	GList			*list, *l;
+	gboolean		res_value;
+	gboolean		task_value;
 
 	tv = GTK_TREE_VIEW(tree);
 	priv = tree->priv;
@@ -524,27 +676,47 @@ ttable_tree_tree_view_button_press_event
 
 	if (event->button == 3) {
 		gtk_widget_grab_focus (GTK_WIDGET (tree));
-		gtk_widget_set_sensitive (
-				gtk_item_factory_get_widget_by_action (factory, POPUP_EXPAND), TRUE);
-		gtk_widget_set_sensitive (
-				gtk_item_factory_get_widget_by_action (factory, POPUP_COLLAPSE), TRUE);
+
 
 		if (gtk_tree_view_get_path_at_pos (tv, event->x, event->y, &path, NULL, NULL, NULL)) {
+			gtk_tree_model_get_iter (gtk_tree_view_get_model (tree_view), &iter, path);
+			if (!gtk_tree_selection_iter_is_selected (gtk_tree_view_get_selection (tree_view), &iter)) {
 			gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (tv));
 			gtk_tree_selection_select_path (gtk_tree_view_get_selection (tv), path);
-			if (planner_ttable_model_path_is_assignment(model,path)) {
+			}
+			
+			list = planner_ttable_tree_get_selected_items (tree);
+			res_value = FALSE;
+			task_value = FALSE;
+			
+			for (l=list; l ; l=l->next) {
+				res_value = MRP_IS_RESOURCE (l->data) ? TRUE : res_value ;
+				task_value = MRP_IS_ASSIGNMENT (l->data) ? TRUE : task_value ;
+			}
+			g_list_free (list);
+			
+			res_value = (task_value) ? TRUE : res_value;
+			
+			/* TODO: GtkItemFactory used around here is deprecated. */
+				gtk_widget_set_sensitive (
+						gtk_item_factory_get_widget_by_action (factory, POPUP_REDIT), res_value);
 				gtk_widget_set_sensitive (
-						gtk_item_factory_get_widget_by_action (factory, POPUP_REDIT), TRUE);
+						gtk_item_factory_get_widget_by_action (factory, POPUP_TEDIT), task_value);
 				gtk_widget_set_sensitive (
-						gtk_item_factory_get_widget_by_action (factory, POPUP_TEDIT), TRUE);
+						gtk_item_factory_get_widget_by_action (factory, POPUP_AEDIT), task_value);
+
 			} else {
+			gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (tv));
+		
 				gtk_widget_set_sensitive (
-						gtk_item_factory_get_widget_by_action (factory, POPUP_REDIT), TRUE);
+						gtk_item_factory_get_widget_by_action (factory, POPUP_REDIT), FALSE);
 				gtk_widget_set_sensitive (
 						gtk_item_factory_get_widget_by_action (factory, POPUP_TEDIT), FALSE);
+				gtk_widget_set_sensitive (
+					gtk_item_factory_get_widget_by_action (factory, POPUP_AEDIT), FALSE);
+
 			}
-			gtk_tree_path_free (path);
-		}
+		
 		gtk_item_factory_popup (factory, event->x_root, event->y_root,
 				event->button, event->time);
 		return TRUE;
Index: src/planner-ttable-tree.h
===================================================================
RCS file: /cvs/gnome/planner/src/planner-ttable-tree.h,v
retrieving revision 1.4
diff -u -b -B -p -r1.4 planner-ttable-tree.h
--- a/src/planner-ttable-tree.h	12 Dec 2003 20:21:44 -0000	1.4
+++ b/src/planner-ttable-tree.h	3 May 2004 04:39:46 -0000
@@ -26,6 +26,7 @@
 #include <libplanner/mrp-project.h>
 #include "planner-ttable-model.h"
 #include "planner-window.h"
+#include "planner-task-dialog.h"
 
 #define PLANNER_TYPE_TTABLE_TREE               (planner_ttable_tree_get_type ())
 #define PLANNER_TTABLE_TREE(obj)               (GTK_CHECK_CAST ((obj), PLANNER_TYPE_TTABLE_TREE, PlannerTtableTree))
@@ -52,7 +53,8 @@ GtkWidget	*planner_ttable_tree_new      
 		                                	 PlannerTtableModel *model);
 void		 planner_ttable_tree_set_model          (PlannerTtableTree  *tree,
 							 PlannerTtableModel *model);
-void		 planner_ttable_tree_edit_task          (PlannerTtableTree  *tree);
+void		 planner_ttable_tree_edit_task          (PlannerTtableTree  *tree, 
+							PlannerTaskDialogPage page);
 void		 planner_ttable_tree_edit_resource      (PlannerTtableTree  *tree);
 GList*		 planner_ttable_tree_get_selected_items (PlannerTtableTree  *tree);
 void		 planner_ttable_tree_expand_all         (PlannerTtableTree  *tree);
Index: src/planner-ttable-view.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-ttable-view.c,v
retrieving revision 1.7
diff -u -b -B -p -r1.7 planner-ttable-view.c
--- a/src/planner-ttable-view.c	27 Feb 2004 17:40:38 -0000	1.7
+++ b/src/planner-ttable-view.c	3 May 2004 04:39:46 -0000
@@ -53,10 +53,43 @@ static void		ttable_view_zoom_in_cb		(Bo
 static void		ttable_view_zoom_to_fit_cb	(BonoboUIComponent	*component,
 							 gpointer		 data,
 							 const char		*cname);
+static void		ttable_view_expand_all_cb	(BonoboUIComponent	*component,
+							 gpointer		 data,
+							 const char		*cname);
+static void		ttable_view_collapse_all_cb	(BonoboUIComponent	*component,
+							 gpointer		 data,
+							 const char		*cname);
+static void		ttable_view_select_all_cb	(BonoboUIComponent	*component,
+							 gpointer		 data,
+							 const char		*cname);
+static void		ttable_view_edit_task_page_general_cb	(BonoboUIComponent	*component,
+							 	gpointer		 data,
+								 const char		*cname);
+static void		ttable_view_edit_task_page_resources_cb	(BonoboUIComponent	*component,
+							 	gpointer		 data,
+							 	const char		*cname);
+static void		ttable_view_edit_task_page_predecessors_cb	(BonoboUIComponent	*component,
+							 	gpointer		 data,
+							 	const char		*cname);
+static void		ttable_view_edit_task_page_notes_cb	(BonoboUIComponent	*component,
+								gpointer		 data,
+								const char		*cname);
+static void   		ttable_view_edit_resource_cb         (BonoboUIComponent   *component,
+						       gpointer             data, 
+						       const char          *cname);
+								
 static BonoboUIVerb verbs[] = {
 	BONOBO_UI_VERB ("ZoomOut",	ttable_view_zoom_out_cb),
 	BONOBO_UI_VERB ("ZoomIn",	ttable_view_zoom_in_cb),
 	BONOBO_UI_VERB ("ZoomToFit",	ttable_view_zoom_to_fit_cb),
+	BONOBO_UI_VERB ("ExpandAll",	ttable_view_expand_all_cb),
+	BONOBO_UI_VERB ("CollapseAll",	ttable_view_collapse_all_cb),
+	BONOBO_UI_VERB ("SelectAll",	ttable_view_select_all_cb),
+	BONOBO_UI_VERB ("EditTaskGeneral",	ttable_view_edit_task_page_general_cb),
+	BONOBO_UI_VERB ("EditTaskResources",	ttable_view_edit_task_page_resources_cb),
+	BONOBO_UI_VERB ("EditTaskPredecessors",	ttable_view_edit_task_page_predecessors_cb),
+	BONOBO_UI_VERB ("EditTaskNotes",	ttable_view_edit_task_page_notes_cb),
+	BONOBO_UI_VERB ("EditResource",	ttable_view_edit_resource_cb),	
 	BONOBO_UI_VERB_END
 };
 
@@ -70,6 +103,14 @@ static void        ttable_view_project_l
 						      PlannerView                  *view);
 static void        ttable_view_tree_view_realize_cb  (GtkWidget                    *w,
 						      gpointer                      data);
+static void        ttable_view_selection_changed_cb  (PlannerTtableTree            *tree,
+						      PlannerView                  *view);
+static void	   ttable_view_expand_all_model_cb   (PlannerTtableModel 	   *model, 
+						     MrpTask 			   *task, 
+						     PlannerView		   *view);
+static void	   ttable_view_collapse_all_model_cb   (PlannerTtableModel 	   *model, 
+						     MrpTask 			   *task, 
+						     PlannerView		   *view);
 static void        ttable_view_row_expanded          (GtkTreeView                  *tree_view,
 						      GtkTreeIter                  *iter,
 						      GtkTreePath                  *path,
@@ -82,9 +123,13 @@ static void        ttable_view_expand_al
 						      PlannerTtableChart           *chart);
 static void        ttable_view_collapse_all          (PlannerTtableTree            *tree,
 						      PlannerTtableChart           *chart);
+static void        ttable_view_select_all            (PlannerTtableTree            *tree);
 static void        ttable_view_ttable_status_updated (PlannerTtableChart           *chart,
 						      const gchar                  *message,
 						      PlannerView                  *view);
+static void	   ttable_view_update_ui 	     (PlannerView *view);
+static void	   ttable_view_update_zoom_sensitivity (PlannerView *view);
+
 void               activate                          (PlannerView                  *view);
 void               deactivate                        (PlannerView                  *view);
 void               init                              (PlannerView                  *view,
@@ -107,12 +152,15 @@ activate (PlannerView *view)
 {      
 	PlannerViewPriv	*priv;
 
-	priv=view->priv;
+	priv = view->priv;
 	planner_view_activate_helper(view,
 				DATADIR
 				"/planner/ui/time-table-view.ui",
 				"timetableview",
 				verbs);
+
+	ttable_view_selection_changed_cb ((PlannerTtableTree *) (view->priv->tree), view);
+	ttable_view_update_zoom_sensitivity (view);
 }
 
 G_MODULE_EXPORT void
@@ -237,6 +285,7 @@ ttable_view_zoom_out_cb (BonoboUICompone
 	view = PLANNER_VIEW (data);
 
 	planner_ttable_chart_zoom_out (view->priv->chart);
+	ttable_view_update_zoom_sensitivity (view);
 }
 
 static void
@@ -249,6 +298,7 @@ ttable_view_zoom_in_cb (BonoboUIComponen
 	view = PLANNER_VIEW (data);
 	
 	planner_ttable_chart_zoom_in (view->priv->chart);
+	ttable_view_update_zoom_sensitivity (view);
 }
 
 static void
@@ -259,6 +309,121 @@ ttable_view_zoom_to_fit_cb	(BonoboUIComp
 	PlannerView		*view;
 	view = PLANNER_VIEW(data);
 	planner_ttable_chart_zoom_to_fit(view->priv->chart);
+	ttable_view_update_zoom_sensitivity (view);
+}
+
+static void
+ttable_view_expand_all_cb (BonoboUIComponent	*component,
+			  gpointer		 data,
+			  const char		*cname)
+{
+	PlannerView		*view;
+	
+	view = PLANNER_VIEW(data);
+
+	ttable_view_expand_all ( (PlannerTtableTree *) view->priv->tree, view->priv->chart);
+}
+
+/* This is used when tasks are changed via UNDO/REDO (especially the UNDO).
+*/
+
+static void
+ttable_view_expand_all_model_cb (PlannerTtableModel *model, MrpTask *task, PlannerView	*view)
+{
+	ttable_view_expand_all ( (PlannerTtableTree *) view->priv->tree, view->priv->chart);
+}
+
+/* This is used when tasks are changed via UNDO/REDO */
+
+static void
+ttable_view_collapse_all_model_cb (PlannerTtableModel *model, MrpTask *task, PlannerView	*view)
+{
+	ttable_view_collapse_all ( (PlannerTtableTree *) view->priv->tree, view->priv->chart);
+}
+
+
+static void
+ttable_view_collapse_all_cb	(BonoboUIComponent	*component,
+				 gpointer		 data,
+				 const char		*cname)
+{
+	PlannerView		*view;
+	
+	view = PLANNER_VIEW(data);
+
+	ttable_view_collapse_all ( (PlannerTtableTree *) view->priv->tree, view->priv->chart);
+}
+
+static void
+ttable_view_select_all_cb	(BonoboUIComponent	*component,
+				 gpointer		 data,
+				 const char		*cname)
+{
+	PlannerView		*view;
+	
+	view = PLANNER_VIEW(data);
+
+	ttable_view_select_all ( (PlannerTtableTree *) view->priv->tree);
+}
+
+static void
+ttable_view_edit_task_page_general_cb (BonoboUIComponent *component, 
+			 gpointer           data, 
+			 const char        *cname)
+{
+	PlannerView *view;
+
+	view = PLANNER_VIEW (data);
+
+	planner_ttable_tree_edit_task ((PlannerTtableTree *) (view->priv->tree), PLANNER_TASK_DIALOG_PAGE_GENERAL);
+}
+
+static void
+ttable_view_edit_task_page_resources_cb (BonoboUIComponent *component, 
+			 gpointer           data, 
+			 const char        *cname)
+{
+	PlannerView *view;
+
+	view = PLANNER_VIEW (data);
+
+	planner_ttable_tree_edit_task ((PlannerTtableTree *) (view->priv->tree), PLANNER_TASK_DIALOG_PAGE_RESOURCES);
+}
+
+static void
+ttable_view_edit_task_page_predecessors_cb (BonoboUIComponent *component, 
+			 gpointer           data, 
+			 const char        *cname)
+{
+	PlannerView *view;
+
+	view = PLANNER_VIEW (data);
+
+	planner_ttable_tree_edit_task ((PlannerTtableTree *) (view->priv->tree), PLANNER_TASK_DIALOG_PAGE_PREDECESSORS);
+}
+
+static void
+ttable_view_edit_task_page_notes_cb (BonoboUIComponent *component, 
+			 gpointer           data, 
+			 const char        *cname)
+{
+	PlannerView *view;
+
+	view = PLANNER_VIEW (data);
+
+	planner_ttable_tree_edit_task ((PlannerTtableTree *) (view->priv->tree), PLANNER_TASK_DIALOG_PAGE_NOTES);
+}
+
+static void
+ttable_view_edit_resource_cb (BonoboUIComponent *component, 
+			 gpointer           data, 
+			 const char        *cname)
+{
+	PlannerView *view;
+
+	view = PLANNER_VIEW (data);
+
+	planner_ttable_tree_edit_resource ((PlannerTtableTree *) (view->priv->tree));
 }
 
 static void
@@ -324,6 +489,8 @@ ttable_view_create_widget	(PlannerView		
 	
 	GtkAdjustment    *hadj, *vadj;
 
+	GtkTreeSelection *selection;
+		
 	project = planner_window_get_project (view->main_window);
 	priv = view->priv;
 	priv->project = project;
@@ -371,8 +538,27 @@ ttable_view_create_widget	(PlannerView		
 	g_signal_connect (chart, "status_updated",G_CALLBACK(ttable_view_ttable_status_updated),view);
 	g_signal_connect_after (tree, "size_request",G_CALLBACK(ttable_view_tree_view_size_request_cb),NULL);
 	g_signal_connect_after (tree, "scroll_event",G_CALLBACK(ttable_view_tree_view_scroll_event_cb),view);
-	gtk_tree_view_expand_all(GTK_TREE_VIEW(tree));
-	planner_ttable_chart_expand_all(PLANNER_TTABLE_CHART(chart));
+	g_signal_connect (model,"task_added",G_CALLBACK(ttable_view_expand_all_model_cb),view);
+	g_signal_connect (model,"task_removed",G_CALLBACK(ttable_view_collapse_all_model_cb),view);
+	/* FIXME: Must do a collapse as doesn't work to expand when you add a resource (via undo)
+	*  It may be some race but it looks OK when collapsing all. If you don't you're left with
+	*  some resources expanded, and some not but the chart is expanded so things look messy.
+	*/ 
+	g_signal_connect (model,"resource_added",G_CALLBACK(ttable_view_collapse_all_model_cb),view);  
+	g_signal_connect (model,"resource_removed",G_CALLBACK(ttable_view_collapse_all_model_cb),view);
+	g_signal_connect (model,"assignment_added",G_CALLBACK(ttable_view_expand_all_model_cb),view);  
+	g_signal_connect (model,"assignment_removed",G_CALLBACK(ttable_view_collapse_all_model_cb),view);
+	
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
+	gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+
+	g_signal_connect (selection, 
+			  "changed",
+			  G_CALLBACK (ttable_view_selection_changed_cb),
+			  view);  /* This works fine */
+		  
+	ttable_view_expand_all (PLANNER_TTABLE_TREE(tree), PLANNER_TTABLE_CHART(chart));
+
 	g_object_unref(model);
 	return hpaned;
 }
@@ -495,6 +681,108 @@ ttable_view_collapse_all	(PlannerTtableT
 					  chart);
 }
 
+static void
+ttable_view_select_all (PlannerTtableTree *tree)
+{
+	GtkTreeSelection *selection;
+
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
+
+	gtk_tree_selection_select_all (selection);
+	
+}
+
+static void 
+ttable_view_selection_changed_cb (PlannerTtableTree *tree, PlannerView *view)
+{
+	g_return_if_fail (PLANNER_IS_VIEW (view));
+	
+	ttable_view_update_ui (view);
+}
+
+
+static void
+ttable_view_update_ui (PlannerView *view)
+{
+	GList      *list ,*l;
+	gboolean   res_value;
+	gboolean   task_value;
+
+	if (!view->activated) {
+		return;
+	}
+	
+	list = planner_ttable_tree_get_selected_items ((PlannerTtableTree *) (view->priv->tree));
+
+/* We can have either a selection of MRP_IS_RESOURCE or MRP_IS_ASSIGNMENT or both */
+
+	res_value = FALSE;
+	task_value = FALSE;
+	
+	for (l=list; l ; l=l->next) {
+		res_value = MRP_IS_RESOURCE (l->data) ? TRUE : res_value ;
+		task_value = MRP_IS_ASSIGNMENT (l->data) ? TRUE : task_value ;
+	}
+
+/* If we have a task assignment we can look at a resource too */
+	res_value = (task_value) ? TRUE : res_value;
+
+	bonobo_ui_component_freeze (view->ui_component, NULL);
+
+	bonobo_ui_component_set_prop (view->ui_component, 
+				      "/commands/EditTaskGeneral",
+				      "sensitive", task_value ? "1" : "0", 
+				      NULL);
+
+	bonobo_ui_component_set_prop (view->ui_component, 
+				      "/commands/EditTaskResources",
+				      "sensitive", task_value ? "1" : "0",
+				      NULL);
+
+	bonobo_ui_component_set_prop (view->ui_component, 
+				      "/commands/EditTaskPredecessors",
+				      "sensitive", task_value ? "1" : "0", 
+				      NULL);
+
+	bonobo_ui_component_set_prop (view->ui_component, 
+				      "/commands/EditTaskNotes",
+				      "sensitive", task_value ? "1" : "0",
+				      NULL);
+				      
+	bonobo_ui_component_set_prop (view->ui_component, 
+				      "/commands/EditResource",
+				      "sensitive", res_value ? "1" : "0",
+				      NULL);
+				      
+	bonobo_ui_component_thaw (view->ui_component, NULL);
+
+	g_list_free (list);
+}
+
+static void
+ttable_view_update_zoom_sensitivity (PlannerView *view)
+{
+	gboolean in, out;
+
+	planner_ttable_chart_can_zoom (view->priv->chart,
+				 &in,
+				 &out);
+
+	bonobo_ui_component_freeze (view->ui_component, NULL);
+	
+	bonobo_ui_component_set_prop (view->ui_component, 
+				      "/commands/ZoomIn",
+				      "sensitive", in ? "1" : "0", 
+				      NULL);
+
+	bonobo_ui_component_set_prop (view->ui_component, 
+				      "/commands/ZoomOut",
+				      "sensitive", out ? "1" : "0", 
+				      NULL);
+	
+	bonobo_ui_component_thaw (view->ui_component, NULL);
+}
+
 /*
 TODO:
 planner_ttable_print_data_new


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