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



Hi!

El lun, 03-04-2006 a las 22:02 +0200, Richard Hult escribió:
> Welcome back Alvaro :)
> 
> Alvaro del Castillo skrev:
> 
> > If Kurt and Richard find the patch useful and in good shape I will
> > commit it to the CVS.
> 
> Great, it sounds useful :) It would be easier to review the patch if you 
> use unified format though (e.g. diff -uBp).
> 

Yes Richard, sorry about that. My new development environment hasn't the
correct .cvsrc file.

Here goes the new patch with some cleanup as a bonus! ;-)

Cheers

-- Alvaro

> /Richard
> 
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	4 Apr 2006 08:33:31 -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,19 @@ 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));
+	
+	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	4 Apr 2006 08:33:31 -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	4 Apr 2006 08:33:31 -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	4 Apr 2006 08:33:31 -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	4 Apr 2006 08:33:31 -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,67 @@ 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:
+		if (priv->assignment == NULL) {
+			break;
+		}
+		chart = g_object_get_data (G_OBJECT (item->canvas), "chart");
+		tree = planner_usage_chart_get_view (chart);
+		path = planner_usage_model_get_path_from_assignment
+			(PLANNER_USAGE_MODEL (planner_usage_chart_get_model (chart)),
+			 priv->assignment);
+		
+		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) {
+			planner_usage_tree_edit_task (tree);
+		}
+		break;
+
+	case GDK_2BUTTON_PRESS:
+		if (event->button.button == 3) {
+			g_print ("Second mouse button pressed\n");
+		}
+
+	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	4 Apr 2006 08:33:31 -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))


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