[gnumeric] preparatory redistribution of code for #623559



commit 4f5181caf8fe2ef8e3955b7bfa1eb2bb6f2380cc
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sun Jul 4 21:29:32 2010 -0600

    preparatory redistribution of code for #623559
    
    2010-07-04  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/commands.c (cmd_objects_move): move most code into
    	  sheet_object_move_undo and sheet_object_move_do
    	* src/sheet-object.h (sheet_object_move_undo): new
    	(sheet_object_move_do): new
    	* src/sheet-object.c (sheet_object_move_undo): new
    	(sheet_object_move_do): new

 ChangeLog          |    9 ++++++
 src/commands.c     |   58 ++++++++++------------------------------
 src/sheet-object.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/sheet-object.h |    3 ++
 4 files changed, 100 insertions(+), 43 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7a846bf..3ae5045 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2010-07-04  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/commands.c (cmd_objects_move): move most code into
+	  sheet_object_move_undo and sheet_object_move_do
+	* src/sheet-object.h (sheet_object_move_undo): new
+	(sheet_object_move_do): new
+	* src/sheet-object.c (sheet_object_move_undo): new
+	(sheet_object_move_do): new
+
+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
diff --git a/src/commands.c b/src/commands.c
index b733c5c..6c48e53 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -4448,56 +4448,28 @@ cmd_objects_move (WorkbookControl *wbc, GSList *objects, GSList *anchors,
 {
 	GOUndo *undo = NULL;
 	GOUndo *redo = NULL;
-	GSList *objs = objects, *anchs = anchors;
+	gboolean result;
 
 	g_return_val_if_fail (IS_WORKBOOK_CONTROL (wbc), TRUE);
-	g_return_val_if_fail (NULL != objects, TRUE);
-	g_return_val_if_fail (NULL != anchors, TRUE);
-	g_return_val_if_fail (g_slist_length (objects) == g_slist_length (anchors), TRUE);
-
-	/*
-	 * There is no need to move the object around, because this has
-	 * already happened.
-	 */
 
-	for (; objs && anchs; objs = objs->next, anchs = anchs->next) {
-		SheetObject *obj = objs->data;
-		SheetObjectAnchor *anch = anchs->data;
-		SheetObjectAnchor *tmp;
+	undo = sheet_object_move_undo (objects, objects_created);
+	redo = sheet_object_move_do (objects, anchors, objects_created);
 
-		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);
+	if (undo == NULL || redo == NULL) {
+		if (undo) g_object_unref (undo);
+		if (redo) g_object_unref (redo);
+		return TRUE;
 	}
+
+	result = cmd_generic (wbc, name, undo, redo);
+	
+	if (result)
+		return TRUE;
+
 	g_slist_free (objects);
-	g_slist_free (anchors);
+	go_slist_free_custom (anchors, g_free);
 
-	return cmd_generic (wbc, name, undo, redo);
+	return FALSE;
 }
 
 /******************************************************************/
diff --git a/src/sheet-object.c b/src/sheet-object.c
index 062066e..397ba79 100644
--- a/src/sheet-object.c
+++ b/src/sheet-object.c
@@ -1463,6 +1463,79 @@ sheet_object_write_object (SheetObject const *so, char const *format,
 	gnm_pop_C_locale (locale);
 }
 
+GOUndo *
+sheet_object_move_undo (GSList *objects, gboolean objects_created)
+{
+	GOUndo *undo = NULL;
+	GSList *objs = objects;
+
+	g_return_val_if_fail (NULL != objects, NULL);
+
+	for (; objs; objs = objs->next) {
+		SheetObject *obj = objs->data;
+		SheetObjectAnchor *tmp;
+
+		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));
+		}
+		
+		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));
+	}
+	return undo;
+}
+
+GOUndo *
+sheet_object_move_do (GSList *objects, GSList *anchors, 
+		      gboolean objects_created)
+{
+	GOUndo *undo = NULL;
+	GSList *objs = objects, *anchs = anchors;
+
+	g_return_val_if_fail (NULL != objects, NULL);
+	g_return_val_if_fail (NULL != anchors, NULL);
+	g_return_val_if_fail (g_slist_length (objects) 
+			      == g_slist_length (anchors), NULL);
+
+	for (; objs && anchs; objs = objs->next, anchs = anchs->next) {
+		SheetObject *obj = objs->data;
+		SheetObjectAnchor *anch = anchs->data;
+		SheetObjectAnchor *tmp;
+
+		if (objects_created) {
+			undo = go_undo_combine 
+				(undo,
+				 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 = *anch;
+		undo = go_undo_combine 
+			(go_undo_binary_new 
+			 (g_object_ref (obj), tmp, 
+			  (GOUndoBinaryFunc) sheet_object_set_anchor,
+			  (GFreeFunc) g_object_unref,
+			  (GFreeFunc) g_free), undo);
+	}
+	return undo;
+}
+
+
 /*****************************************************************************/
 
 void
diff --git a/src/sheet-object.h b/src/sheet-object.h
index 147c2a3..8e3efb6 100644
--- a/src/sheet-object.h
+++ b/src/sheet-object.h
@@ -104,6 +104,9 @@ void	sheet_objects_relocate   (GnmExprRelocateInfo const *rinfo,
 				  gboolean update, GOUndo **pundo);
 void    sheet_objects_clear      (Sheet const *sheet, GnmRange const *r,
 				  GType t, GOUndo **pundo);
+GOUndo *sheet_object_move_undo   (GSList *objects, gboolean objects_created);
+GOUndo *sheet_object_move_do     (GSList *objects, GSList *anchors, 
+				  gboolean objects_created);
 GSList *sheet_objects_get        (Sheet const *sheet, GnmRange const *r,
 				  GType t);
 void    sheet_objects_dup	 (Sheet const *src, Sheet *dst, GnmRange *range);



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