Re: [Planner Dev] Giving some live to the Resource Usage View. Patch included.



Hi!

El mié, 05-04-2006 a las 08:57 -0400, Kurt Maute escribió: 
> On Tue, 2006-04-04 at 10:37 +0200, Alvaro del Castillo wrote:
> > Hi!
> 
> > Here goes the new patch with some cleanup as a bonus! ;-)
> 
> I tried this out and looks like it works well.  The only thing that
> looks like its missing is to provide the same functionality in the usage
> graph itself.  

The same functionality as the gantt canvas? Yes, for the moment you can
only:

1. Select a task in the canvas with a single left click
2. Edit the task properties with a single right click

> Looks like you started looking into that with your
> g_print ("Second mouse button pressed\n") message?

I have played a bit with that but this message and this second mouse
button should be cleaned in this first version. 

3. I want to make also that if you are in the canvas in the resource
usage bar, when you left click in it you should get the resource enable
and when you right click, you should get the resource edit dialog.

About adding more interactivity to the canvas as it is in the gantt
canvas I am not sure we want the user to do more things from this view
and also, the work to implement all the canvas gantt features would need
more time (basically it is cut & paste code at the right place changing
a bit some concepts).

I will be happy having the 1, 2 and 3 implemented in a first round. And
here goes an updated patch to do the three items (the second patch I
sent missed an important line and doesn't work).

Cheers

-- Alvaro
Index: src/planner-gantt-row.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-gantt-row.c,v
retrieving revision 1.27
diff -u -b -B -p -r1.27 planner-gantt-row.c
Index: src/planner-usage-chart.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-usage-chart.c,v
retrieving revision 1.1
diff -u -b -B -p -r1.1 planner-usage-chart.c
--- src/planner-usage-chart.c	16 Apr 2005 14:19:59 -0000	1.1
+++ src/planner-usage-chart.c	6 Apr 2006 18:00:03 -0000
@@ -81,6 +81,7 @@ struct _PlannerUsageChartPriv {
 
         GtkTreeModel    *model;
         TreeNode        *tree;
+	PlannerUsageTree *view;
 
         GnomeCanvasItem *background;
         gdouble          zoom;
@@ -1045,6 +1046,15 @@ planner_usage_chart_set_model (PlannerUs
         g_object_notify (G_OBJECT (chart), "model");
 }
 
+GtkTreeModel *
+planner_usage_chart_get_model (PlannerUsageChart *chart)
+{
+	g_return_val_if_fail (PLANNER_IS_USAGE_CHART (chart), NULL);
+
+	return chart->priv->model;
+}
+
+
 static void
 usage_chart_build_tree (PlannerUsageChart * chart)
 {
@@ -1532,3 +1542,21 @@ planner_usage_chart_setup_root_task (Pla
 			  chart);
 }
 
+PlannerUsageTree *  
+planner_usage_chart_get_view (PlannerUsageChart *chart) 
+{
+	g_return_val_if_fail (PLANNER_IS_USAGE_CHART (chart), NULL);	
+
+	return chart->priv->view;
+}
+
+void          
+planner_usage_chart_set_view (PlannerUsageChart *chart,
+			      PlannerUsageTree  *view) 
+{
+	g_return_if_fail (PLANNER_IS_USAGE_TREE (view));
+	
+	g_print ("View for Usage configured\n");
+
+	chart->priv->view = view;
+}
Index: src/planner-usage-chart.h
===================================================================
RCS file: /cvs/gnome/planner/src/planner-usage-chart.h,v
retrieving revision 1.1
diff -u -b -B -p -r1.1 planner-usage-chart.h
--- src/planner-usage-chart.h	16 Apr 2005 14:19:59 -0000	1.1
+++ src/planner-usage-chart.h	6 Apr 2006 18:00:03 -0000
@@ -27,6 +27,7 @@
 #include <gtk/gtkvbox.h>
 #include <gtk/gtktreemodel.h>
 #include <libgnomecanvas/gnome-canvas.h>
+#include "planner-usage-tree.h"
 
 #define PLANNER_TYPE_USAGE_CHART             (planner_usage_chart_get_type ())
 #define PLANNER_USAGE_CHART(obj)             (GTK_CHECK_CAST ((obj), PLANNER_TYPE_USAGE_CHART, PlannerUsageChart))
@@ -58,6 +59,10 @@ GtkWidget *   planner_usage_chart_new_wi
 GtkTreeModel *planner_usage_chart_get_model        (PlannerUsageChart *chart);
 void          planner_usage_chart_set_model        (PlannerUsageChart *chart,
 						     GtkTreeModel       *model);
+PlannerUsageTree *  
+              planner_usage_chart_get_view         (PlannerUsageChart *chart);
+void          planner_usage_chart_set_view         (PlannerUsageChart *chart,
+						    PlannerUsageTree  *view);
 void          planner_usage_chart_expand_row       (PlannerUsageChart *chart,
 						     GtkTreePath        *path);
 void          planner_usage_chart_collapse_row     (PlannerUsageChart *chart,
Index: src/planner-usage-model.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-usage-model.c,v
retrieving revision 1.1
diff -u -b -B -p -r1.1 planner-usage-model.c
--- src/planner-usage-model.c	16 Apr 2005 14:19:59 -0000	1.1
+++ src/planner-usage-model.c	6 Apr 2006 18:00:04 -0000
@@ -321,6 +320,21 @@ planner_usage_model_get_path_from_resour
 
         return usage_model_get_path_from_node (PLANNER_USAGE_MODEL (model),
                                                 node);
+}
+
+GtkTreePath *       
+planner_usage_model_get_path_from_assignment (PlannerUsageModel *model,
+					      MrpAssignment     *assignment) 
+{
+        GNode *node;
+	
+        g_return_val_if_fail (PLANNER_IS_USAGE_MODEL (model), NULL);
+        g_return_val_if_fail (MRP_IS_ASSIGNMENT (assignment), NULL);
+	
+        node = g_hash_table_lookup (model->priv->assign2node, assignment);
+	
+        return usage_model_get_path_from_node (PLANNER_USAGE_MODEL (model),
+					       node);
 }
 
 static GtkTreePath *
Index: src/planner-usage-model.h
===================================================================
RCS file: /cvs/gnome/planner/src/planner-usage-model.h,v
retrieving revision 1.1
diff -u -b -B -p -r1.1 planner-usage-model.h
--- src/planner-usage-model.h	16 Apr 2005 14:19:59 -0000	1.1
+++ src/planner-usage-model.h	6 Apr 2006 18:00:04 -0000
@@ -60,6 +60,9 @@ GType               planner_usage_model_
 PlannerUsageModel *planner_usage_model_new                    (MrpProject         *project);
 GtkTreePath *       planner_usage_model_get_path_from_resource (PlannerUsageModel *model,
 								 MrpResource        *resource);
+GtkTreePath *       planner_usage_model_get_path_from_assignment 
+                                                               (PlannerUsageModel *model,
+								MrpAssignment     *assignment);
 MrpProject *        planner_usage_model_get_project            (PlannerUsageModel *model);
 MrpAssignment *     planner_usage_model_get_assignment         (PlannerUsageModel *model,
 								 GtkTreeIter        *iter);
Index: src/planner-usage-row.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-usage-row.c,v
retrieving revision 1.1
diff -u -b -B -p -r1.1 planner-usage-row.c
--- src/planner-usage-row.c	16 Apr 2005 14:19:59 -0000	1.1
+++ src/planner-usage-row.c	6 Apr 2006 18:00:04 -0000
@@ -39,6 +39,8 @@
 #include "planner-canvas-line.h"
 #include "eel-canvas-rect.h"
 #include "planner-scale-utils.h"
+#include "planner-usage-chart.h"
+#include "planner-usage-model.h"
 
 /* The padding between the gantt bar and the text. */
 #define TEXT_PADDING 10.0
@@ -144,6 +146,8 @@ static void     usage_row_bounds        
 							 double                 *y1,
 							 double                 *x2,
 							 double                 *y2);
+static gboolean usage_row_event                       (GnomeCanvasItem          *item,
+						       GdkEvent                 *event);
 static void     usage_row_ensure_layout               (PlannerUsageRow       *row);
 static void     usage_row_update_resources            (PlannerUsageRow       *row);
 static void     usage_row_geometry_changed             (PlannerUsageRow       *row);
@@ -225,6 +229,8 @@ usage_row_class_init (PlannerUsageRowCla
         gobject_class->set_property = usage_row_set_property;
         gobject_class->get_property = usage_row_get_property;
 
+	item_class->event = usage_row_event;
+
         signals[GEOMETRY_CHANGED] =
                 g_signal_new ("geometry-changed",
                               G_TYPE_FROM_CLASS (class),
@@ -1557,4 +1563,75 @@ usage_row_geometry_changed (PlannerUsage
         y2 = y1 + row->priv->height;
 
         g_signal_emit (row, signals[GEOMETRY_CHANGED], 0, x1, y1, x2, y2);
+}
+
+static gboolean
+usage_row_event (GnomeCanvasItem *item, GdkEvent *event)
+{
+	PlannerUsageRow     *row;
+	PlannerUsageRowPriv *priv;
+	PlannerUsageChart   *chart;
+	GtkTreePath         *path;
+	GtkTreeSelection    *selection;
+	PlannerUsageTree    *tree;
+	GtkTreeView         *tree_view;
+	GtkTreeIter          iter;
+	GtkWidget           *canvas_widget;
+
+	row = PLANNER_USAGE_ROW (item);
+	priv = row->priv;
+	canvas_widget = GTK_WIDGET (item->canvas);
+	
+	switch (event->type) {
+	case GDK_BUTTON_PRESS:
+		chart = g_object_get_data (G_OBJECT (item->canvas), "chart");
+
+		if (priv->assignment != NULL) {
+			path = planner_usage_model_get_path_from_assignment
+				(PLANNER_USAGE_MODEL (planner_usage_chart_get_model (chart)),
+				 priv->assignment);
+		}
+		else if (priv->resource != NULL) {
+			path = planner_usage_model_get_path_from_resource
+				(PLANNER_USAGE_MODEL (planner_usage_chart_get_model (chart)),
+				 priv->resource);
+		}
+		else {
+			break;
+		}
+
+		tree = planner_usage_chart_get_view (chart);
+		tree_view = GTK_TREE_VIEW (tree);
+		selection = gtk_tree_view_get_selection (tree_view);
+		
+		gtk_tree_model_get_iter (gtk_tree_view_get_model (tree_view), 
+					 &iter, path);
+		
+		if (!gtk_tree_selection_iter_is_selected (selection, &iter)) {
+			gtk_tree_selection_unselect_all (selection);
+			gtk_tree_selection_select_path (selection, path);
+		}
+
+		if (event->button.button == 3) {
+			if (priv->assignment != NULL) {
+				planner_usage_tree_edit_task (tree);
+			}
+			else if (priv->resource != NULL) {
+				planner_usage_tree_edit_resource (tree);
+			}			
+		}
+
+		break;
+
+	default:
+		break;
+	}
+	
+			
+
+	if (TRUE) {
+		return TRUE;
+	}
+
+	return FALSE;
 }
Index: src/planner-usage-tree.h
===================================================================
RCS file: /cvs/gnome/planner/src/planner-usage-tree.h,v
retrieving revision 1.1
diff -u -b -B -p -r1.1 planner-usage-tree.h
--- src/planner-usage-tree.h	16 Apr 2005 14:19:59 -0000	1.1
+++ src/planner-usage-tree.h	6 Apr 2006 18:00:04 -0000
@@ -27,6 +27,7 @@
 #include <libplanner/mrp-project.h>
 #include "planner-usage-model.h"
 #include "planner-window.h"
+#include "planner-task-dialog.h"
 
 #define PLANNER_TYPE_USAGE_TREE               (planner_usage_tree_get_type ())
 #define PLANNER_USAGE_TREE(obj)               (GTK_CHECK_CAST ((obj), PLANNER_TYPE_USAGE_TREE, PlannerUsageTree))
Index: src/planner-usage-view.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-usage-view.c,v
retrieving revision 1.4
diff -u -b -B -p -r1.4 planner-usage-view.c
--- src/planner-usage-view.c	23 Apr 2005 10:33:10 -0000	1.4
+++ src/planner-usage-view.c	6 Apr 2006 18:00:04 -0000
@@ -405,6 +405,10 @@ usage_view_create_widget (PlannerView *v
 
         chart = planner_usage_chart_new_with_model (GTK_TREE_MODEL (model));
         priv->chart = PLANNER_USAGE_CHART (chart);
+
+	planner_usage_chart_set_view (PLANNER_USAGE_CHART (priv->chart), 
+				      PLANNER_USAGE_TREE  (priv->tree));
+
         sw = gtk_scrolled_window_new (hadj, vadj);
         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                         GTK_POLICY_ALWAYS,


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