[Planner Dev] New patch for undo: Focus in - focus out undo



Hi guys!

Here goes the work I have done it the train in my last trip. It is a
second round in all the undo stuff and the more visible feature now is
that you can undo changes in resource dialog fields. For example, you
can change the name for a resource and then undo this change. The trick
here is that undo is to the stage the field was when you focus in the
field and do the changes.

Cheers

-- Alvaro
? extremadura-train.diff
? undo-focus.diff
Index: gtk-doc.make
===================================================================
RCS file: /cvs/gnome/planner/gtk-doc.make,v
retrieving revision 1.3
diff -u -b -B -p -r1.3 gtk-doc.make
--- gtk-doc.make	16 Mar 2004 20:39:02 -0000	1.3
+++ gtk-doc.make	18 Apr 2004 10:45:13 -0000
@@ -39,7 +39,7 @@ SCANOBJ_FILES = 		 \
 	$(DOC_MODULE).prerequisites \
 	$(DOC_MODULE).signals
 
-CLEANFILES = $(SCANOBJ_FILES) $(DOC_MODULE)-unused.txt $(DOC_STAMPS)
+CLEANFILES = $(SCANOBJ_FILES) $(DOC_MODULE)-scan.o $(DOC_MODULE)-unused.txt $(DOC_STAMPS)
 
 if ENABLE_GTK_DOC
 all-local: html-build.stamp
@@ -99,32 +99,29 @@ html-build.stamp: sgml.stamp $(DOC_MAIN_
 	@echo '-- Fixing Crossreferences' 
 	cd $(srcdir) && gtkdoc-fixxref --module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS)
 	touch html-build.stamp
-else
-all-local:
 endif
 
 ##############
 
 clean-local:
 	rm -f *~ *.bak
-	rm -rf .libs
 
 maintainer-clean-local: clean
 	cd $(srcdir) && rm -rf xml html $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
 
 install-data-local:
-	installfiles=`echo $(srcdir)/html/*`; \
+	$(mkinstalldirs) $(DESTDIR)$(TARGET_DIR)
+	(installfiles=`echo $(srcdir)/html/*`; \
 	if test "$$installfiles" = '$(srcdir)/html/*'; \
 	then echo '-- Nothing to install' ; \
 	else \
-	  $(mkinstalldirs) $(DESTDIR)$(TARGET_DIR); \
 	  for i in $$installfiles; do \
 	    echo '-- Installing '$$i ; \
 	    $(INSTALL_DATA) $$i $(DESTDIR)$(TARGET_DIR); \
 	  done; \
 	  echo '-- Installing $(srcdir)/html/index.sgml' ; \
 	  $(INSTALL_DATA) $(srcdir)/html/index.sgml $(DESTDIR)$(TARGET_DIR) || :; \
-	fi
+	fi)
 
 uninstall-local:
 	rm -f $(DESTDIR)$(TARGET_DIR)/*
Index: src/planner-group-dialog.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-group-dialog.c,v
retrieving revision 1.9
diff -u -b -B -p -r1.9 planner-group-dialog.c
--- src/planner-group-dialog.c	27 Mar 2004 08:18:23 -0000	1.9
+++ src/planner-group-dialog.c	18 Apr 2004 10:45:17 -0000
@@ -3,7 +3,7 @@
  * Copyright (C) 2002 CodeFactory AB
  * Copyright (C) 2002 Richard Hult <richard imendio com>
  * Copyright (C) 2002 Mikael Hallendal <micke imendio com>
- * Copyright (C) 2002 Alvaro del Castillo <acs barrapunto com>
+ * Copyright (C) 2002-2004 Alvaro del Castillo <acs barrapunto com>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -479,7 +479,6 @@ group_cmd_default_do (PlannerCmd *cmd_ba
 
 	cmd = (GroupCmdDefault*) cmd_base;
 
-	mrp_object_get (cmd->project, "default-group", &cmd->old_group, NULL);
 	mrp_object_set (cmd->project, "default-group", cmd->group, NULL);
 }
 
@@ -498,10 +497,12 @@ group_cmd_default_free (PlannerCmd *cmd_
 	GroupCmdDefault *cmd;
 	
 	cmd = (GroupCmdDefault*) cmd_base;
-	/* We haven't ref this objects ... we must? */
-	cmd->project = NULL;
-	cmd->group = NULL;
-	cmd->old_group = NULL;
+
+	g_object_unref (cmd->group);
+	g_object_unref (cmd->old_group);
+	g_free (cmd_base->label);
+
+	g_free (cmd);
 }
 
 static PlannerCmd *
@@ -522,7 +523,8 @@ group_cmd_default (PlannerView *view,
 
 	cmd->project = planner_window_get_project (view->main_window);
 
-	cmd->group = group;	
+	cmd->group = g_object_ref (group);
+	mrp_object_get (cmd->project, "default-group", &cmd->old_group, NULL);
 
 	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (view->main_window),
 					   cmd_base);
@@ -649,6 +651,10 @@ group_cmd_edit_property (PlannerView  *v
 	g_object_get_property (G_OBJECT (cmd->group),
 			       cmd->property,
 			       cmd->old_value);
+
+	/* FIXME: if old and new value are the same, do nothing 
+	   How we can compare values?
+	 */
 
 	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (view->main_window),
 					   cmd_base);
Index: src/planner-resource-dialog.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-resource-dialog.c,v
retrieving revision 1.6
diff -u -b -B -p -r1.6 planner-resource-dialog.c
--- src/planner-resource-dialog.c	10 Apr 2004 11:37:41 -0000	1.6
+++ src/planner-resource-dialog.c	18 Apr 2004 10:45:20 -0000
@@ -3,7 +3,7 @@
  * Copyright (C) 2001-2002 CodeFactory AB
  * Copyright (C) 2001-2002 Richard Hult <richard imendio com>
  * Copyright (C) 2001-2002 Mikael Hallendal <micke imendio com>
- * Copyright (C) 2001-2002 Alvaro del Castillo <acs barrapunto com>
+ * Copyright (C) 2001-2004 Alvaro del Castillo <acs barrapunto com>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -86,11 +86,23 @@ static void  resource_dialog_name_change
 static void  resource_dialog_resource_name_changed_cb       (MrpResource  *resource,  
 							     GParamSpec   *pspec, 
 							     GtkWidget    *dialog);
+static void  resource_dialog_name_focus_in_cb               (GtkWidget     *w,
+							     GdkEventFocus *event,
+							     DialogData    *data);
+static void  resource_dialog_name_focus_out_cb              (GtkWidget     *w,
+							     GdkEventFocus *event,
+							     DialogData    *data);
 static void  resource_dialog_short_name_changed_cb          (GtkWidget    *w,
 							     DialogData   *data);
 static void  resource_dialog_resource_short_name_changed_cb (MrpResource  *resource,  
 							     GParamSpec   *pspec, 
 							     GtkWidget    *dialog);
+static void  resource_dialog_short_name_focus_in_cb         (GtkWidget     *w,
+							     GdkEventFocus *event,
+							     DialogData    *data);
+static void  resource_dialog_short_name_focus_out_cb        (GtkWidget     *w,
+							     GdkEventFocus *event,
+							     DialogData    *data);
 static void  resource_dialog_type_changed_cb                (GtkWidget    *w,
 							     DialogData   *data);
 static void  resource_dialog_resource_type_changed_cb       (MrpResource  *resource,  
@@ -106,6 +118,12 @@ static void  resource_dialog_email_chang
 static void  resource_dialog_resource_email_changed_cb      (MrpResource  *resource,  
 							     GParamSpec   *pspec, 
 							     GtkWidget    *dialog);
+static void  resource_dialog_email_focus_in_cb              (GtkWidget     *w,
+							     GdkEventFocus *event,
+							     DialogData    *data);
+static void  resource_dialog_email_focus_out_cb             (GtkWidget     *w,
+							     GdkEventFocus *event,
+							     DialogData    *data);
 static void  resource_dialog_resource_cost_changed_cb       (MrpResource  *resource,  
 							     MrpProperty  *property,
 							     GValue       *value,
@@ -149,7 +167,7 @@ typedef struct {
 	PlannerCmd   base;
 
 	MrpResource *resource;
-	const gchar *property;  
+	gchar       *property;  
 	GValue      *value;
 	GValue      *old_value;
 } ResourceCmdEditProperty;
@@ -410,6 +428,24 @@ resource_cmd_edit_property_undo (Planner
 			       cmd->old_value);
 }
 
+static void
+resource_cmd_edit_property_free (PlannerCmd *cmd_base)
+{
+	ResourceCmdEditProperty *cmd;
+
+	cmd = (ResourceCmdEditProperty*) cmd_base;
+
+	g_free (cmd_base->label);
+
+	g_value_unset (cmd->value);
+	g_value_unset (cmd->old_value);
+
+	g_free (cmd->property);
+	g_object_unref (cmd->resource);
+
+	g_free (cmd);
+}
+
 static PlannerCmd *
 resource_cmd_edit_property (PlannerWindow *main_window,
 			    MrpResource   *resource,
@@ -426,10 +462,10 @@ resource_cmd_edit_property (PlannerWindo
 	cmd_base->label = g_strdup (_("Edit resource property from dialog"));
 	cmd_base->do_func = resource_cmd_edit_property_do;
 	cmd_base->undo_func = resource_cmd_edit_property_undo;
-	cmd_base->free_func = NULL; /* FIXME */
+	cmd_base->free_func = resource_cmd_edit_property_free;
 
-	cmd->property = property;
-	cmd->resource = resource;
+	cmd->property = g_strdup (property);
+	cmd->resource = g_object_ref (resource);
 
 	cmd->value = g_new0 (GValue, 1);
 	g_value_init (cmd->value, G_VALUE_TYPE (value));
@@ -448,7 +484,46 @@ resource_cmd_edit_property (PlannerWindo
 	return cmd_base;
 }
 
+/* 
+   In text entries we return to the value that exists when focus in.
+   The new value is already stored in the object
+*/
+static PlannerCmd *
+resource_cmd_edit_property_focus (PlannerWindow *main_window,
+				  MrpResource   *resource,
+				  const gchar   *property,
+				  const GValue  *focus_in_value)
+{
+	PlannerCmd              *cmd_base;
+	ResourceCmdEditProperty *cmd;
+
+	cmd = g_new0 (ResourceCmdEditProperty, 1);
+
+	cmd_base = (PlannerCmd*) cmd;
+
+	cmd_base->label = g_strdup (_("Edit resource property from dialog"));
+	cmd_base->do_func = resource_cmd_edit_property_do;
+	cmd_base->undo_func = resource_cmd_edit_property_undo;
+	cmd_base->free_func = resource_cmd_edit_property_free;
+
+	cmd->property = g_strdup (property);
+	cmd->resource = g_object_ref (resource);
+
+	cmd->value = g_new0 (GValue, 1);
+	g_value_init (cmd->value, G_VALUE_TYPE (focus_in_value));
+	g_object_get_property (G_OBJECT (cmd->resource),
+			       cmd->property,
+			       cmd->value);
 
+	cmd->old_value = g_new0 (GValue, 1);
+	g_value_init (cmd->old_value, G_VALUE_TYPE (focus_in_value));
+	g_value_copy (focus_in_value, cmd->old_value);
+
+	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (main_window),
+					   cmd_base);
+
+	return cmd_base;
+}
 
 static void  
 resource_dialog_resource_name_changed_cb (MrpResource *resource,  
@@ -484,20 +559,15 @@ resource_dialog_name_changed_cb (GtkWidg
 				 DialogData *data)
 {
 	const gchar  *name;
-	GValue        value = { 0 };
-	/* PlannerCmd   *cmd; */
 
-	name = gtk_entry_get_text (GTK_ENTRY (w));
+	g_assert (MRP_IS_RESOURCE (data->resource));
 
-	g_value_init (&value, G_TYPE_STRING);
-	g_value_set_string (&value, name);
+	name = gtk_entry_get_text (GTK_ENTRY (w));
 
 	g_signal_handlers_block_by_func (data->resource,
 					 resource_dialog_resource_name_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, "name", &value); */
 	g_object_set (data->resource, "name", name, NULL);
 
 	resource_dialog_update_title (data);
@@ -505,8 +575,41 @@ resource_dialog_name_changed_cb (GtkWidg
 	g_signal_handlers_unblock_by_func (data->resource,
 					   resource_dialog_resource_name_changed_cb,
 					   data->dialog);
+}
 
-	g_value_unset (&value);
+static void
+resource_dialog_name_focus_out_cb (GtkWidget     *w,
+				   GdkEventFocus *event,
+				   DialogData    *data)
+{
+	gchar        *focus_in_name;
+	GValue        value = { 0 };
+	PlannerCmd   *cmd;
+
+	g_assert (MRP_IS_RESOURCE (data->resource));
+
+	focus_in_name = g_object_get_data (G_OBJECT (data->resource),"focus_in_name");
+	
+	g_value_init (&value, G_TYPE_STRING);
+	g_value_set_string (&value, g_strdup (focus_in_name));
+
+	cmd = resource_cmd_edit_property_focus (data->main_window, 
+						data->resource, "name", &value);
+
+	g_free (focus_in_name);
+}
+
+static void
+resource_dialog_name_focus_in_cb (GtkWidget     *w,
+				  GdkEventFocus *event,
+				  DialogData    *data)
+{
+	gchar  *name;
+	   
+	name = g_strdup (gtk_entry_get_text (GTK_ENTRY (w)));
+	
+	g_object_set_data (G_OBJECT (data->resource), 
+			   "focus_in_name", (gpointer) name);
 }
 
 static void  
@@ -556,6 +659,42 @@ resource_dialog_resource_short_name_chan
 }
 
 static void  
+resource_dialog_short_name_focus_out_cb (GtkWidget     *w,
+					 GdkEventFocus *event,
+					 DialogData    *data)
+{
+	gchar        *focus_in_short_name;
+	GValue        value = { 0 };
+	PlannerCmd   *cmd;
+
+	g_assert (MRP_IS_RESOURCE (data->resource));
+
+	focus_in_short_name = g_object_get_data (G_OBJECT (data->resource),
+						 "focus_in_short_name");
+	
+	g_value_init (&value, G_TYPE_STRING);
+	g_value_set_string (&value, g_strdup (focus_in_short_name));
+
+	cmd = resource_cmd_edit_property_focus (data->main_window, 
+						data->resource, "short_name", &value);
+
+	g_free (focus_in_short_name);
+}
+
+static void
+resource_dialog_short_name_focus_in_cb (GtkWidget     *w,
+					GdkEventFocus *event,
+					DialogData    *data)
+{
+	gchar  *name;
+	   
+	name = g_strdup (gtk_entry_get_text (GTK_ENTRY (w)));
+	
+	g_object_set_data (G_OBJECT (data->resource), 
+			   "focus_in_short_name", (gpointer) name);
+}
+
+static void  
 resource_dialog_resource_type_changed_cb (MrpResource *resource,  
 					  GParamSpec  *pspec, 
 					  GtkWidget   *dialog)
@@ -608,7 +747,6 @@ resource_dialog_type_changed_cb (GtkWidg
 					 resource_dialog_resource_type_changed_cb, 
 					 data->dialog);
 
-	/* g_object_set (data->resource, "type", type, NULL); */
 	cmd = resource_cmd_edit_property (data->main_window, data->resource, "type", &value);
 
 	g_signal_handlers_unblock_by_func (data->resource,
@@ -709,6 +847,41 @@ resource_dialog_email_changed_cb (GtkWid
 }
 
 static void  
+resource_dialog_email_focus_out_cb (GtkWidget     *w,
+				    GdkEventFocus *event,
+				    DialogData    *data)
+{
+	gchar        *focus_in_email;
+	GValue        value = { 0 };
+	PlannerCmd   *cmd;
+
+	g_assert (MRP_IS_RESOURCE (data->resource));
+
+	focus_in_email = g_object_get_data (G_OBJECT (data->resource),"focus_in_email");
+	
+	g_value_init (&value, G_TYPE_STRING);
+	g_value_set_string (&value, g_strdup (focus_in_email));
+
+	cmd = resource_cmd_edit_property_focus (data->main_window, 
+						data->resource, "email", &value);
+
+	g_free (focus_in_email);
+}
+
+static void
+resource_dialog_email_focus_in_cb (GtkWidget     *w,
+				   GdkEventFocus *event,
+				   DialogData    *data)
+{
+	gchar  *email;
+	   
+	email = g_strdup (gtk_entry_get_text (GTK_ENTRY (w)));
+	
+	g_object_set_data (G_OBJECT (data->resource), 
+			   "focus_in_email", (gpointer) email);
+}
+
+static void  
 resource_dialog_resource_email_changed_cb (MrpResource *resource,  
 					   GParamSpec  *pspec, 
 					   GtkWidget   *dialog)
@@ -735,6 +908,9 @@ resource_dialog_resource_email_changed_c
 	g_free (email);
 }
 
+
+/* 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) 
@@ -1290,6 +1466,16 @@ planner_resource_dialog_new (PlannerWind
 			  G_CALLBACK (resource_dialog_name_changed_cb),
 			  data);
 
+	g_signal_connect (data->name_entry,
+			  "focus_out_event",
+			  G_CALLBACK (resource_dialog_name_focus_out_cb),
+			  data);
+
+	g_signal_connect (data->name_entry,
+			  "focus_in_event",
+			  G_CALLBACK (resource_dialog_name_focus_in_cb),
+			  data);
+
 	gtk_entry_set_text (GTK_ENTRY (data->short_name_entry), short_name);
 
 	g_signal_connect (data->short_name_entry,
@@ -1297,6 +1483,16 @@ planner_resource_dialog_new (PlannerWind
 			  G_CALLBACK (resource_dialog_short_name_changed_cb),
 			  data);
 			  
+	g_signal_connect (data->short_name_entry,
+			  "focus_out_event",
+			  G_CALLBACK (resource_dialog_short_name_focus_out_cb),
+			  data);
+
+	g_signal_connect (data->short_name_entry,
+			  "focus_in_event",
+			  G_CALLBACK (resource_dialog_short_name_focus_in_cb),
+			  data);
+			  
 	resource_dialog_setup_option_menu (data->type_menu,
 					   NULL,
 					   NULL,
@@ -1347,7 +1543,18 @@ planner_resource_dialog_new (PlannerWind
 			  G_CALLBACK (resource_dialog_email_changed_cb),
 			  data);
 
-	gtk_entry_set_text (GTK_ENTRY (data->cost_entry), planner_format_float (cost, 2, FALSE)); 
+	g_signal_connect (data->email_entry,
+			  "focus_out_event",
+			  G_CALLBACK (resource_dialog_email_focus_out_cb),
+			  data);
+
+	g_signal_connect (data->email_entry,
+			  "focus_in_event",
+			  G_CALLBACK (resource_dialog_email_focus_in_cb),
+			  data);
+
+	gtk_entry_set_text (GTK_ENTRY (data->cost_entry), 
+			    planner_format_float (cost, 2, FALSE)); 
 
 	g_signal_connect (data->cost_entry,
 			  "changed",
Index: src/planner-resource-view.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-resource-view.c,v
retrieving revision 1.16
diff -u -b -B -p -r1.16 planner-resource-view.c
--- src/planner-resource-view.c	15 Apr 2004 22:11:35 -0000	1.16
+++ src/planner-resource-view.c	18 Apr 2004 10:45:25 -0000
@@ -287,7 +287,7 @@ typedef struct {
 	PlannerCmd   base;
 
 	MrpResource *resource;
-	const gchar *property;  
+	gchar       *property;  
 	GValue      *value;
 	GValue      *old_value;
 } ResourceCmdEditProperty;
@@ -757,7 +757,7 @@ resource_cmd_insert_do (PlannerCmd *cmd_
 	ResourceCmdInsert *cmd;
 
 	cmd = (ResourceCmdInsert*) cmd_base;
-	g_assert (MRP_IS_RESOURCE (cmd->resource));
+
 	mrp_project_add_resource (cmd->project, cmd->resource);
 }
 
@@ -770,9 +770,6 @@ resource_cmd_insert_undo (PlannerCmd *cm
 
 	mrp_project_remove_resource (cmd->project,
 				     cmd->resource);
-	
-	/* Don't clean the resource before the cmd free */
-	/* cmd->resource = NULL; */
 }
 
 static void
@@ -889,9 +886,11 @@ resource_cmd_remove_do (PlannerCmd *cmd_
 	assignments = mrp_resource_get_assignments (cmd->resource);
 
 	for (l = assignments; l; l = l->next) {
-		cmd->assignments = g_list_prepend (cmd->assignments, l->data);
+		cmd->assignments = g_list_append (cmd->assignments, 
+						  g_object_ref (l->data));
 	}
 
+
 	mrp_project_remove_resource (cmd->project, cmd->resource);
 }
 
@@ -903,8 +902,6 @@ resource_cmd_remove_undo (PlannerCmd *cm
 	
 	cmd = (ResourceCmdRemove*) cmd_base;
 
-	g_assert (MRP_IS_RESOURCE (cmd->resource));
-
 	mrp_project_add_resource (cmd->project, cmd->resource);
 
 	for (l = cmd->assignments; l; l = l->next) {
@@ -917,6 +914,7 @@ resource_cmd_remove_undo (PlannerCmd *cm
 		mrp_resource_assign (cmd->resource, task, units);
 	}
 
+	g_list_foreach (cmd->assignments, (GFunc) g_object_unref, NULL);
 	g_list_free (cmd->assignments);
 	cmd->assignments = NULL;
 }
@@ -931,9 +929,8 @@ resource_cmd_remove_free (PlannerCmd *cm
 
 	g_object_unref (cmd->resource);
 
-	cmd->assignments = NULL;
-	cmd->resource    = NULL;
-	cmd->project     = NULL;
+	g_free (cmd_base->label);
+	g_free (cmd);
 }
 
 static PlannerCmd *
@@ -1316,6 +1313,23 @@ resource_cmd_edit_property_undo (Planner
 			       cmd->old_value);
 }
 
+static void
+resource_cmd_edit_property_free (PlannerCmd *cmd_base)
+{
+	ResourceCmdEditProperty *cmd;
+
+	cmd = (ResourceCmdEditProperty*) cmd_base;
+
+	g_value_unset (cmd->value);
+	g_value_unset (cmd->old_value);
+
+	g_object_unref (cmd->resource);
+	g_free (cmd->property);
+
+	g_free (cmd_base->label);
+	g_free (cmd);
+}
+
 static PlannerCmd *
 resource_cmd_edit_property (PlannerView  *view,
 			    MrpResource  *resource,
@@ -1332,10 +1346,10 @@ resource_cmd_edit_property (PlannerView 
 	cmd_base->label = g_strdup (_("Edit resource property"));
 	cmd_base->do_func = resource_cmd_edit_property_do;
 	cmd_base->undo_func = resource_cmd_edit_property_undo;
-	cmd_base->free_func = NULL; /* FIXME */
+	cmd_base->free_func = resource_cmd_edit_property_free;
 
-	cmd->property = property;
-	cmd->resource = resource;
+	cmd->property = g_strdup (property);
+	cmd->resource = g_object_ref (resource);
 
 	cmd->value = g_new0 (GValue, 1);
 	g_value_init (cmd->value, G_VALUE_TYPE (value));
@@ -1348,6 +1362,10 @@ resource_cmd_edit_property (PlannerView 
 			       cmd->property,
 			       cmd->old_value);
 
+	/* FIXME: if old and new value are the same, do nothing 
+	   How we can compare values?
+	*/
+
 	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (view->main_window),
 					   cmd_base);
 
@@ -1372,12 +1390,29 @@ resource_cmd_edit_custom_property_undo (
 
 	cmd = (ResourceCmdEditCustomProperty*) cmd_base;
 
+	/* FIXME: delay in the UI when setting the property */
 	mrp_object_set_property (MRP_OBJECT (cmd->resource),
 				 cmd->property,
 				 cmd->old_value);
 
 }
 
+static void
+resource_cmd_edit_custom_property_free (PlannerCmd *cmd_base)
+{
+	ResourceCmdEditCustomProperty *cmd;
+
+	cmd = (ResourceCmdEditCustomProperty*) cmd_base;
+
+	g_free (cmd_base->label);
+
+	g_value_unset (cmd->value);
+	g_value_unset (cmd->old_value);
+
+	g_object_unref (cmd->resource);
+	g_free (cmd);
+}
+
 static PlannerCmd *
 resource_cmd_edit_custom_property (PlannerView  *view,
 				   MrpResource  *resource,
@@ -1394,10 +1429,10 @@ resource_cmd_edit_custom_property (Plann
 	cmd_base->label = g_strdup (_("Edit resource custom property"));
 	cmd_base->do_func = resource_cmd_edit_custom_property_do;
 	cmd_base->undo_func = resource_cmd_edit_custom_property_undo;
-	cmd_base->free_func = NULL; /* FIXME */
+	cmd_base->free_func = resource_cmd_edit_custom_property_free;
 
 	cmd->property = property;
-	cmd->resource = resource;
+	cmd->resource = g_object_ref (resource);
 
 	cmd->value = g_new0 (GValue, 1);
 	g_value_init (cmd->value, G_VALUE_TYPE (value));
@@ -1409,6 +1444,10 @@ resource_cmd_edit_custom_property (Plann
 	mrp_object_get_property (MRP_OBJECT (cmd->resource),
 				 cmd->property,
 				 cmd->old_value);
+
+	/* FIXME: if old and new value are the same, do nothing 
+	   How we can compare values?
+	*/
 
 	planner_cmd_manager_insert_and_do (planner_window_get_cmd_manager (view->main_window),
 					   cmd_base);
Index: src/planner-task-tree.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-tree.c,v
retrieving revision 1.20
diff -u -b -B -p -r1.20 planner-task-tree.c
--- src/planner-task-tree.c	17 Apr 2004 09:45:08 -0000	1.20
+++ src/planner-task-tree.c	18 Apr 2004 10:45:31 -0000
@@ -318,6 +318,22 @@ task_cmd_edit_property_undo (PlannerCmd 
 			       cmd->old_value);
 }
 
+static void
+task_cmd_edit_property_free (PlannerCmd *cmd_base)
+{
+	TaskCmdEditProperty *cmd;
+	
+	cmd = (TaskCmdEditProperty*) cmd_base;
+
+	g_free (cmd_base->label);
+	g_free (cmd->property);
+	g_value_unset (cmd->value);
+	g_value_unset (cmd->old_value);
+	g_free (cmd);
+
+	
+}
+
 static PlannerCmd *
 task_cmd_edit_property (PlannerTaskTree *tree,
 			MrpTask         *task,
@@ -337,7 +353,7 @@ task_cmd_edit_property (PlannerTaskTree 
 
 	cmd_base->do_func = task_cmd_edit_property_do;
 	cmd_base->undo_func = task_cmd_edit_property_undo;
-	cmd_base->free_func = NULL; /* FIXME: task_cmd_edit_free */
+	cmd_base->free_func = task_cmd_edit_property_free;
 
 	cmd->tree = tree;
 	cmd->project = task_tree_get_project (tree);
@@ -803,7 +819,7 @@ typedef struct {
 	MrpTask    *sibling;
 	gboolean    before;
 	gboolean    before_old;
-	gboolean    first_time;
+	gboolean    success;
 } TaskCmdTaskMove;
 
 static void
@@ -811,7 +827,6 @@ task_cmd_task_move_do (PlannerCmd *cmd_b
 {
 	TaskCmdTaskMove *cmd;
 	GError          *error;
-	gboolean         success;
 
 	cmd = (TaskCmdTaskMove*) cmd_base;
 
@@ -829,22 +844,12 @@ task_cmd_task_move_do (PlannerCmd *cmd_b
 		}
 	}
 
-	/* Already done the move */
-	if (cmd->first_time) {
-		cmd->first_time = FALSE;
-		return;
-	}
-
-	success = mrp_project_move_task (cmd->project,
+	cmd->success = mrp_project_move_task (cmd->project,
 					 cmd->task,
 					 cmd->sibling,
 					 cmd->parent,
 					 cmd->before,
 					 &error);
-
-	if (g_getenv ("PLANNER_DEBUG_UNDO_TASK")) {
-		g_assert (success);
-	}
 }
 
 static void
@@ -852,10 +857,14 @@ task_cmd_task_move_undo (PlannerCmd *cmd
 {
 	TaskCmdTaskMove *cmd;
 	GError          *error;
-	gboolean         success;
 
 	cmd = (TaskCmdTaskMove*) cmd_base;
 
+	if (!cmd->success) {
+		return;
+	}
+	
+
 	if (g_getenv ("PLANNER_DEBUG_UNDO_TASK")) {
 		if (cmd->before_old) {
 			g_message ("UNDO: Moving %s (parent %s) before %s",
@@ -870,16 +879,14 @@ task_cmd_task_move_undo (PlannerCmd *cmd
 		}
 	}
 
-	success = mrp_project_move_task (cmd->project,
+	cmd->success = mrp_project_move_task (cmd->project,
 					 cmd->task,
 					 cmd->sibling,
 					 cmd->parent_old,
 					 cmd->before_old,
 					 &error);
 
-	if (g_getenv ("PLANNER_DEBUG_UNDO_TASK")) {
-		g_assert (success);
-	}		
+	g_assert (cmd->success);
 }
 
 static void
@@ -936,7 +943,6 @@ task_cmd_task_move (PlannerTaskTree *tre
 	cmd = g_new0 (TaskCmdTaskMove, 1);
 
 	cmd_base = (PlannerCmd*) cmd;
-	cmd->first_time = TRUE;
 	cmd_base->label = g_strdup (_("Move task"));
 	cmd_base->do_func = task_cmd_task_move_do;
 	cmd_base->undo_func = task_cmd_task_move_undo;


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