[Planner Dev] Patch for undo cost resource in resource dialog



Hi guys!

Here goes another patch for the missing undo for cost field. And I hope
that now is completly implemented undo for the resource dialog.

Also in this patch goes some corrections for signals handling. Take a
look at the Changelog.

Cheers

-- Alvaro
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/planner/ChangeLog,v
retrieving revision 1.115
diff -u -b -B -p -r1.115 ChangeLog
--- ChangeLog	1 May 2004 18:08:14 -0000	1.115
+++ ChangeLog	2 May 2004 07:50:00 -0000
@@ -1,5 +1,16 @@
 2004-05-01 Alvaro del Castillo  <acs barrapunto com>
 
+	* src/planner-resource-dialog.c: implemented undo for resource cost 
+	in the resource editor dialog.
+	* src/planner-resource-dialog.c:
+	(resource_dialog_close_clicked_cb)
+	(resource_dialog_resource_removed_cb)
+	Disconnect signal for resource removed so we don't try to destroy
+	a widget that doesn't exist
+	
+
+2004-05-01 Alvaro del Castillo  <acs barrapunto com>
+
 	* src/planner-resource-dialog.c: implemented undo for resource calendar 
 	in the resource editor dialog.
 
Index: src/planner-resource-dialog.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-resource-dialog.c,v
retrieving revision 1.10
diff -u -b -B -p -r1.10 planner-resource-dialog.c
--- src/planner-resource-dialog.c	1 May 2004 18:08:14 -0000	1.10
+++ src/planner-resource-dialog.c	2 May 2004 07:50:06 -0000
@@ -129,6 +129,12 @@ static void     resource_dialog_resource
 								MrpProperty   *property,
 								GValue        *value,
 								GtkWidget     *dialog);
+static gboolean resource_dialog_resource_cost_focus_in_cb      (GtkWidget     *w,
+								GdkEventFocus *event,
+								DialogData    *data);
+static gboolean resource_dialog_resource_cost_focus_out_cb     (GtkWidget     *w,
+								GdkEventFocus *event,
+								DialogData    *data);
 static void     resource_dialog_resource_calendar_changed_cb   (MrpResource   *resource,
 								GParamSpec    *pspec,
 								GtkWidget     *dialog);
@@ -193,6 +199,15 @@ typedef struct {
 	PlannerCmd   base;
 
 	MrpResource *resource;
+	gchar       *property;
+	gfloat       cost;
+	gfloat       old_cost;
+} ResourceCmdEditCost;
+
+typedef struct {
+	PlannerCmd   base;
+
+	MrpResource *resource;
 	MrpCalendar *calendar;
 	MrpCalendar *old_calendar;
 } ResourceCmdCalendar;
@@ -427,6 +442,9 @@ static void
 resource_dialog_close_clicked_cb (GtkWidget  *w,
 				  DialogData *data)
 {
+	g_signal_handlers_disconnect_by_func (data->resource,
+					      resource_dialog_resource_removed_cb,
+					      data);
 	gtk_widget_destroy (data->dialog);
 }
 
@@ -434,6 +452,9 @@ static void
 resource_dialog_resource_removed_cb (GtkWidget  *w,
 				     DialogData *data)
 {
+	g_signal_handlers_disconnect_by_func (data->resource,
+					      resource_dialog_resource_removed_cb,
+					      data);
 	gtk_widget_destroy (data->dialog);
 }
 
@@ -523,11 +544,6 @@ resource_cmd_note_do (PlannerCmd *cmd_ba
 
 	cmd = (ResourceCmdEditNote*) cmd_base;
 
-	if (g_getenv ("PLANNER_DEBUG_UNDO_RESOURCE")) {
-		g_message ("Doing the note change ... focus out: %s, focus in: %s", 
-			   cmd->note, cmd->old_note);
-	}
-
 	g_object_set (cmd->resource, "note", cmd->note, NULL);
 }
 
@@ -538,11 +554,6 @@ resource_cmd_note_undo (PlannerCmd *cmd_
 
 	cmd = (ResourceCmdEditNote*) cmd_base;
 
-	if (g_getenv ("PLANNER_DEBUG_UNDO_RESOURCE")) {
-		g_message ("Undoing the note change to \"%s\" from the new \"%s\"", 
-			   cmd->old_note, cmd->note);
-	}
-
 	g_object_set (cmd->resource, "note", cmd->old_note, NULL);
 }
 
@@ -564,7 +575,6 @@ resource_cmd_note_free (PlannerCmd *cmd_
 
 static PlannerCmd *
 resource_cmd_edit_note (DialogData  *data,
-			const gchar *property,
 			const gchar *focus_in_note)
 {
 	PlannerCmd          *cmd_base;
@@ -587,7 +597,7 @@ resource_cmd_edit_note (DialogData  *dat
 	cmd_base->undo_func = resource_cmd_note_undo;
 	cmd_base->free_func = resource_cmd_note_free;
 
-	cmd->property = g_strdup (property);
+	cmd->property = g_strdup ("note");
 	cmd->resource = g_object_ref (data->resource);
 
 	cmd->old_note = g_strdup (focus_in_note);
@@ -600,6 +610,80 @@ resource_cmd_edit_note (DialogData  *dat
 }
 
 static void
+resource_cmd_cost_do (PlannerCmd *cmd_base)
+{
+	ResourceCmdEditCost *cmd;
+
+	cmd = (ResourceCmdEditCost*) cmd_base;
+
+	mrp_object_set (cmd->resource, "cost", cmd->cost, NULL);
+}
+
+static void
+resource_cmd_cost_undo (PlannerCmd *cmd_base)
+{
+	ResourceCmdEditCost *cmd;
+
+	cmd = (ResourceCmdEditCost*) cmd_base;
+
+	mrp_object_set (cmd->resource, "cost", cmd->old_cost, NULL);
+}
+
+static void
+resource_cmd_cost_free (PlannerCmd *cmd_base)
+{
+	ResourceCmdEditCost *cmd;
+
+	cmd = (ResourceCmdEditCost*) cmd_base;
+
+	g_object_unref (cmd->resource);
+
+	g_free (cmd);
+}
+
+static PlannerCmd *
+resource_cmd_edit_cost (DialogData  *data,
+			const gchar *focus_in_cost)
+{
+	PlannerCmd          *cmd_base;
+	ResourceCmdEditCost *cmd;
+	gfloat               cost, old_cost;
+	gchar               *end_ptr;
+
+	mrp_object_get (data->resource, "cost", &cost, NULL);
+
+	old_cost = g_strtod (focus_in_cost, &end_ptr);
+
+	if (end_ptr == focus_in_cost) {
+		return NULL;
+	}
+
+	if (cost == old_cost) {
+		return NULL;
+	}
+	
+	cmd = g_new0 (ResourceCmdEditCost, 1);
+
+	cmd_base = (PlannerCmd*) cmd;
+
+	cmd_base->label = g_strdup (_("Edit resource cost from dialog"));
+	cmd_base->do_func = resource_cmd_cost_do;
+	cmd_base->undo_func = resource_cmd_cost_undo;
+	cmd_base->free_func = resource_cmd_cost_free;
+
+	cmd->property = g_strdup ("cost");
+	cmd->resource = g_object_ref (data->resource);
+
+	cmd->old_cost = old_cost;
+	cmd->cost = cost;
+
+	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (data->main_window),
+					   cmd_base);
+
+	return cmd_base;
+}
+
+static void
 resource_cmd_edit_property_do (PlannerCmd *cmd_base)
 {
 	ResourceCmdEditProperty *cmd;
@@ -1012,7 +1096,6 @@ resource_dialog_group_changed_cb (GtkWid
 					 data->dialog);
 
 	cmd = resource_cmd_edit_property (data->main_window, data->resource, "group", &value);
-	/* g_object_set (data->resource, "group", group, NULL); */
 
 	g_signal_handlers_unblock_by_func (data->resource,
 					   resource_dialog_resource_group_changed_cb, 
@@ -1037,8 +1120,6 @@ resource_dialog_email_changed_cb (GtkWid
 					 resource_dialog_resource_email_changed_cb, 
 					 data->dialog);
 
-	/* FIXME: activate undo support when clear how to group several keystrokes */
-	/* cmd = resource_cmd_edit_property (data->main_window, data->resource, "email", &value); */
 	g_object_set (data->resource, "email", email, NULL);
 
 	g_signal_handlers_unblock_by_func (data->resource,
@@ -1113,9 +1194,38 @@ resource_dialog_resource_email_changed_c
 	g_free (email);
 }
 
+static gboolean
+resource_dialog_resource_cost_focus_out_cb (GtkWidget     *w,
+					    GdkEventFocus *event,
+					    DialogData    *data)
+{
+	gchar        *focus_in_cost;
+	PlannerCmd   *cmd;
+
+	focus_in_cost = g_object_get_data (G_OBJECT (data->resource),"focus_in_cost");
+	
+	cmd = resource_cmd_edit_cost (data, focus_in_cost);
+
+	g_free (focus_in_cost);
+	
+	return FALSE;
+}
+
+static gboolean
+resource_dialog_resource_cost_focus_in_cb (GtkWidget     *w,
+					   GdkEventFocus *event,
+					   DialogData    *data)
+{
+	gchar  *cost;
+	   
+	cost = g_strdup (gtk_entry_get_text (GTK_ENTRY (w)));
+	
+	g_object_set_data (G_OBJECT (data->resource), 
+			   "focus_in_cost", (gpointer) cost);
+
+	return FALSE;
+}
 
-/* FIXME: we need generic methods to handle custom properties
-   as we do in resource view */
 static void  
 resource_dialog_cost_changed_cb (GtkWidget  *w,
 				 DialogData *data) 
@@ -1123,7 +1233,6 @@ resource_dialog_cost_changed_cb (GtkWidg
 	const gchar *cost;
 	gfloat       fvalue;
 	GValue       value = { 0 };
-	/* PlannerCmd  *cmd; */
 	gchar       *nptr = NULL;
 
 	cost = gtk_entry_get_text (GTK_ENTRY (w));
@@ -1140,8 +1249,6 @@ resource_dialog_cost_changed_cb (GtkWidg
 					 resource_dialog_resource_cost_changed_cb, 
 					 data->dialog);
 
-	/* FIXME: we need custom properties undo support and group several keystrokes */
-	/* cmd = resource_cmd_edit_property (data->main_window, data->resource, "cost", &value); */
 	mrp_object_set (data->resource, "cost", fvalue, NULL);
 
 	g_signal_handlers_unblock_by_func (data->resource,
@@ -1234,7 +1341,7 @@ resource_dialog_note_focus_out_cb (GtkWi
 
 	focus_in_note = g_object_get_data (G_OBJECT (data->resource),"focus_in_note");
 	
-	cmd = resource_cmd_edit_note (data, "note", focus_in_note);
+	cmd = resource_cmd_edit_note (data, focus_in_note);
 
 	if (g_getenv ("PLANNER_DEBUG_UNDO_RESOURCE")) {
 		gchar *note;
@@ -1381,7 +1488,7 @@ resource_dialog_note_stamp_clicked_cb (G
 
 	g_object_set (data->resource, "note", note, NULL);
 
-	cmd = resource_cmd_edit_note (data, "note", note_old);
+	cmd = resource_cmd_edit_note (data, note_old);
 
 	g_free (note_old);
 }
@@ -1607,6 +1714,10 @@ static void
 resource_dialog_parent_destroy_cb (GtkWidget *parent,
 				   GtkWidget *dialog)
 {
+	if (g_getenv ("PLANNER_DEBUG_UNDO_RESOURCE")) {
+		g_message ("Destroying the resource dialog widget ...");
+	}
+
 	gtk_widget_destroy (dialog);
 }
 
@@ -1850,6 +1961,17 @@ planner_resource_dialog_new (PlannerWind
 			  "changed",
 			  G_CALLBACK (resource_dialog_cost_changed_cb),
 			  data);
+
+	g_signal_connect (data->cost_entry,
+			  "focus_out_event",
+			  G_CALLBACK (resource_dialog_resource_cost_focus_out_cb),
+			  data);
+
+	g_signal_connect (data->cost_entry,
+			  "focus_in_event",
+			  G_CALLBACK (resource_dialog_resource_cost_focus_in_cb),
+			  data);
+	
 
 	g_free (name);
 	g_free (short_name);
Index: src/planner-resource-view.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-resource-view.c,v
retrieving revision 1.17
diff -u -b -B -p -r1.17 planner-resource-view.c


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