[gnumeric] Fix undo text for sheet object duplication. [#623557]



commit 50346573f0c8a5634bf778f6b0429ca215e52594
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sun Jul 4 20:41:09 2010 -0600

    Fix undo text for sheet object duplication. [#623557]
    
    2010-07-04  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/sheet-control-gui.c (scg_objects_drag_commit): simplify slightly
    	(scg_drag_receive_same_process): pass the correct argument to
    	  scg_objects_drag_commit
    	* src/sheet-object.c (sheet_object_set_sheet): don't complain if the oject
    	  is already set to this sheet.
    	* src/commands.c (CMD_OBJECTS_MOVE): delete
    	(cmd_objects_move_*): delete
    	(cmd_objects_move): rewrite using GOUndo

 ChangeLog               |   11 +++++
 NEWS                    |    1 +
 src/commands.c          |  107 +++++++++++++++++------------------------------
 src/sheet-control-gui.c |   12 +++--
 src/sheet-object.c      |    4 ++
 5 files changed, 62 insertions(+), 73 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7926480..7a846bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2010-07-04  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/sheet-control-gui.c (scg_objects_drag_commit): simplify slightly
+	(scg_drag_receive_same_process): pass the correct argument to 
+	  scg_objects_drag_commit
+	* src/sheet-object.c (sheet_object_set_sheet): don't complain if the oject
+	  is already set to this sheet.
+	* src/commands.c (CMD_OBJECTS_MOVE): delete
+	(cmd_objects_move_*): delete
+	(cmd_objects_move): rewrite using GOUndo
+
+2010-07-04  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* src/sheet-control-gui.c (scg_objects_drag_commit): don't be cheesy, ie.
 	  use ngettext.
 
diff --git a/NEWS b/NEWS
index 98aad9c..4b16f06 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Andreas:
 	* Improve function syntax tooltips. [#623317]
 	* Add weekend specifier to WORKDAY and NETWORKDAYS. [#172458]
 	* Fix ngettext usage.
+	* Fix undo text for sheet object duplication. [#623557]
 
 Morten:
 	* Ask user to locate solver binaries when plain search fails.
diff --git a/src/commands.c b/src/commands.c
index 0168df6..b733c5c 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -4442,67 +4442,13 @@ cmd_objects_delete (WorkbookControl *wbc, GSList *objects,
 
 /******************************************************************/
 
-#define CMD_OBJECTS_MOVE_TYPE (cmd_objects_move_get_type ())
-#define CMD_OBJECTS_MOVE(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), CMD_OBJECTS_MOVE_TYPE, CmdObjectsMove))
-
-typedef struct {
-	GnmCommand cmd;
-	GSList *objects;
-	GSList *anchors;
-	gboolean objects_created, first_time;
-} CmdObjectsMove;
-
-MAKE_GNM_COMMAND (CmdObjectsMove, cmd_objects_move, NULL)
-
-static gboolean
-cmd_objects_move_redo (GnmCommand *cmd,
-		       G_GNUC_UNUSED WorkbookControl *wbc)
-{
-	CmdObjectsMove *me = CMD_OBJECTS_MOVE (cmd);
-	GSList *objs = me->objects, *anchs = me->anchors;
-
-	for (; objs && anchs; objs = objs->next, anchs = anchs->next) {
-		SheetObject *obj = objs->data;
-		SheetObjectAnchor *anch = anchs->data;
-		SheetObjectAnchor tmp;
-
-		/* If these were newly created objects remove them on undo and
-		 * re-insert on subsequent redos */
-		if (me->objects_created && !me->first_time) {
-			if (NULL != sheet_object_get_sheet (obj))
-				sheet_object_clear_sheet (obj);
-			else
-				sheet_object_set_sheet (obj, cmd->sheet);
-		}
-		tmp = *sheet_object_get_anchor (obj);
-		sheet_object_set_anchor	(obj, anch);
-		*anch = tmp;
-	}
-	me->first_time = FALSE;
-
-	return FALSE;
-}
-
-static gboolean
-cmd_objects_move_undo (GnmCommand *cmd, WorkbookControl *wbc)
-{
-	return cmd_objects_move_redo (cmd, wbc);
-}
-
-static void
-cmd_objects_move_finalize (GObject *cmd)
-{
-	CmdObjectsMove *me = CMD_OBJECTS_MOVE (cmd);
-	go_slist_free_custom (me->objects, g_object_unref);
-	go_slist_free_custom (me->anchors, g_free);
-	gnm_command_finalize (cmd);
-}
-
 gboolean
 cmd_objects_move (WorkbookControl *wbc, GSList *objects, GSList *anchors,
 		  gboolean objects_created, char const *name)
 {
-	CmdObjectsMove *me;
+	GOUndo *undo = NULL;
+	GOUndo *redo = NULL;
+	GSList *objs = objects, *anchs = anchors;
 
 	g_return_val_if_fail (IS_WORKBOOK_CONTROL (wbc), TRUE);
 	g_return_val_if_fail (NULL != objects, TRUE);
@@ -4514,19 +4460,44 @@ cmd_objects_move (WorkbookControl *wbc, GSList *objects, GSList *anchors,
 	 * already happened.
 	 */
 
-	me = g_object_new (CMD_OBJECTS_MOVE_TYPE, NULL);
-
-	me->first_time = TRUE;
-	me->objects_created  = objects_created;
-	me->objects = objects;
-	g_slist_foreach (me->objects, (GFunc) g_object_ref, NULL);
-	me->anchors = anchors;
-
-	me->cmd.sheet = sheet_object_get_sheet (objects->data);
-	me->cmd.size = 1;
-	me->cmd.cmd_descriptor = g_strdup (name);
+	for (; objs && anchs; objs = objs->next, anchs = anchs->next) {
+		SheetObject *obj = objs->data;
+		SheetObjectAnchor *anch = anchs->data;
+		SheetObjectAnchor *tmp;
 
-	return gnm_command_push_undo (wbc, G_OBJECT (me));
+		if (objects_created) {
+			undo = go_undo_combine 
+				(undo, 
+				 go_undo_unary_new 
+				 (g_object_ref (obj), 
+				  (GOUndoUnaryFunc) sheet_object_clear_sheet,
+				  (GFreeFunc) g_object_unref));
+			redo = go_undo_combine 
+				(redo,
+				 go_undo_binary_new (g_object_ref (obj), 
+						     sheet_object_get_sheet (obj),
+						     (GOUndoBinaryFunc) sheet_object_set_sheet,
+						     (GFreeFunc) g_object_unref,
+						     NULL));
+		}
+		
+		tmp = g_new (SheetObjectAnchor, 1);
+		*tmp = *sheet_object_get_anchor (obj);
+		undo = go_undo_combine 
+			(undo, go_undo_binary_new (g_object_ref (obj), tmp, 
+						   (GOUndoBinaryFunc) sheet_object_set_anchor,
+						   (GFreeFunc) g_object_unref,
+						   (GFreeFunc) g_free));
+		redo = go_undo_combine 
+			(go_undo_binary_new (g_object_ref (obj), anch, 
+					     (GOUndoBinaryFunc) sheet_object_set_anchor,
+					     (GFreeFunc) g_object_unref,
+					     (GFreeFunc) g_free), redo);
+	}
+	g_slist_free (objects);
+	g_slist_free (anchors);
+
+	return cmd_generic (wbc, name, undo, redo);
 }
 
 /******************************************************************/
diff --git a/src/sheet-control-gui.c b/src/sheet-control-gui.c
index c53f717..04ca30d 100644
--- a/src/sheet-control-gui.c
+++ b/src/sheet-control-gui.c
@@ -2477,6 +2477,7 @@ scg_objects_drag_commit (SheetControlGUI *scg, int drag_type,
 	CollectObjectsData data;
 	int n;
 	char *text;
+	char const *format;
 
 	data.objects = data.anchors = NULL;
 	data.scg = scg;
@@ -2487,19 +2488,20 @@ scg_objects_drag_commit (SheetControlGUI *scg, int drag_type,
 	if (created_objects) {
 		if (drag_type == 8)
 			/* xgettext : %d gives the number of objects. This is input to ngettext. */
-			text = g_strdup_printf (ngettext ("Duplicate %d Object", "Duplicate %d Objects", n), n); 
+			format = ngettext ("Duplicate %d Object", "Duplicate %d Objects", n); 
 		else
 			/* xgettext : %d gives the number of objects. This is input to ngettext. */
-			text = g_strdup_printf (ngettext ("Insert %d Object", "Insert %d Objects", n), n); 			
+			format = ngettext ("Insert %d Object", "Insert %d Objects", n); 			
 	} else {
 		if (drag_type == 8)
 			/* xgettext : %d gives the number of objects. This is input to ngettext. */
-			text = g_strdup_printf (ngettext ("Move %d Object", "Move %d Objects", n), n); 
+			format = ngettext ("Move %d Object", "Move %d Objects", n); 
 		else
 			/* xgettext : %d gives the number of objects. This is input to ngettext. */
-			text = g_strdup_printf (ngettext ("Resize %d Object", "Resize %d Objects", n), n); 			
+			format = ngettext ("Resize %d Object", "Resize %d Objects", n); 			
 	}
 	
+	text = g_strdup_printf (format, n);
 	cmd_objects_move (WORKBOOK_CONTROL (scg_wbcg (scg)),
 		data.objects, data.anchors, created_objects, text);
 	g_free (text);
@@ -3553,7 +3555,7 @@ scg_drag_receive_same_process (SheetControlGUI *scg, GtkWidget *source_widget,
 				       (mask & GDK_SHIFT_MASK) != 0);
 		pane->drag.origin_x = pane->drag.last_x;
 		pane->drag.origin_y = pane->drag.last_y;
-		scg_objects_drag_commit	(scg, 8, FALSE);
+		scg_objects_drag_commit	(scg, 8, make_dup);
 
 		if (make_dup) {
 			GSList *ptr, *objs = go_hash_keys (scg->selected_objects);
diff --git a/src/sheet-object.c b/src/sheet-object.c
index 92e1137..062066e 100644
--- a/src/sheet-object.c
+++ b/src/sheet-object.c
@@ -455,6 +455,10 @@ sheet_object_set_sheet (SheetObject *so, Sheet *sheet)
 {
 	g_return_val_if_fail (IS_SHEET_OBJECT (so), TRUE);
 	g_return_val_if_fail (IS_SHEET (sheet), TRUE);
+	
+	if (sheet == so->sheet)
+		return FALSE;
+
 	g_return_val_if_fail (so->sheet == NULL, TRUE);
 	g_return_val_if_fail (g_slist_find (sheet->sheet_objects, so) == NULL, TRUE);
 



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