[gnumeric] Fix additional undo entry for sheet object duplication. [#623559]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Fix additional undo entry for sheet object duplication. [#623559]
- Date: Mon, 5 Jul 2010 04:26:28 +0000 (UTC)
commit f8497ed88b371396d2032aa4244a19431bd8dacc
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Sun Jul 4 22:26:23 2010 -0600
Fix additional undo entry for sheet object duplication. [#623559]
2010-07-04 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/commands.c (cmd_objects_move): simplify
* src/sheet-control-gui.h (scg_objects_drag_commit): add arguments
* src/sheet-control-gui.c (scg_objects_drag_commit): add arguments
to return GOUndo items and change all callers
(scg_objects_drag_commit_get_undo_text): new (code from
scg_objects_drag_commit)
(scg_drag_receive_same_process): combine the undos before committing
ChangeLog | 10 ++++++
NEWS | 1 +
src/commands.c | 13 +-------
src/gnm-pane.c | 6 ++-
src/sheet-control-gui.c | 76 ++++++++++++++++++++++++++++++++++------------
src/sheet-control-gui.h | 4 ++-
6 files changed, 76 insertions(+), 34 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3ae5045..6c601e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2010-07-04 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * src/commands.c (cmd_objects_move): simplify
+ * src/sheet-control-gui.h (scg_objects_drag_commit): add arguments
+ * src/sheet-control-gui.c (scg_objects_drag_commit): add arguments
+ to return GOUndo items and change all callers
+ (scg_objects_drag_commit_get_undo_text): new (code from
+ scg_objects_drag_commit)
+ (scg_drag_receive_same_process): combine the undos before committing
+
+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
diff --git a/NEWS b/NEWS
index 4b16f06..eeb6b70 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Andreas:
* Add weekend specifier to WORKDAY and NETWORKDAYS. [#172458]
* Fix ngettext usage.
* Fix undo text for sheet object duplication. [#623557]
+ * Fix additional undo entry for sheet object duplication. [#623559]
Morten:
* Ask user to locate solver binaries when plain search fails.
diff --git a/src/commands.c b/src/commands.c
index 6c48e53..7200698 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -4448,28 +4448,19 @@ cmd_objects_move (WorkbookControl *wbc, GSList *objects, GSList *anchors,
{
GOUndo *undo = NULL;
GOUndo *redo = NULL;
- gboolean result;
+ gboolean result = TRUE;
g_return_val_if_fail (IS_WORKBOOK_CONTROL (wbc), TRUE);
undo = sheet_object_move_undo (objects, objects_created);
redo = sheet_object_move_do (objects, anchors, objects_created);
- 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);
go_slist_free_custom (anchors, g_free);
- return FALSE;
+ return result;
}
/******************************************************************/
diff --git a/src/gnm-pane.c b/src/gnm-pane.c
index 699fa90..5df4bf8 100644
--- a/src/gnm-pane.c
+++ b/src/gnm-pane.c
@@ -2639,12 +2639,14 @@ control_point_button_released (GocItem *item, int button, G_GNUC_UNUSED double x
; /* ignore fake event generated by the dnd code */
else if (pane->drag.had_motion)
scg_objects_drag_commit (scg, idx,
- pane->drag.created_objects);
+ pane->drag.created_objects,
+ NULL, NULL, NULL);
else if (pane->drag.created_objects && idx == 7) {
double w, h;
sheet_object_default_size (so, &w, &h);
scg_objects_drag (scg, NULL, NULL, &w, &h, 7, FALSE, FALSE, FALSE);
- scg_objects_drag_commit (scg, 7, TRUE);
+ scg_objects_drag_commit (scg, 7, TRUE,
+ NULL, NULL, NULL);
}
gnm_pane_clear_obj_size_tip (pane);
return TRUE;
diff --git a/src/sheet-control-gui.c b/src/sheet-control-gui.c
index 04ca30d..26634e5 100644
--- a/src/sheet-control-gui.c
+++ b/src/sheet-control-gui.c
@@ -2470,20 +2470,11 @@ cb_collect_objects_to_commit (SheetObject *so, double *coords, CollectObjectsDat
}
}
-void
-scg_objects_drag_commit (SheetControlGUI *scg, int drag_type,
- gboolean created_objects)
+static char *
+scg_objects_drag_commit_get_undo_text (int drag_type, int n,
+ gboolean created_objects)
{
- CollectObjectsData data;
- int n;
- char *text;
char const *format;
-
- data.objects = data.anchors = NULL;
- data.scg = scg;
- g_hash_table_foreach (scg->selected_objects,
- (GHFunc) cb_collect_objects_to_commit, &data);
- n = g_slist_length (data.objects);
if (created_objects) {
if (drag_type == 8)
@@ -2501,10 +2492,42 @@ scg_objects_drag_commit (SheetControlGUI *scg, int drag_type,
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);
+ return g_strdup_printf (format, n);
+
+}
+
+void
+scg_objects_drag_commit (SheetControlGUI *scg, int drag_type,
+ gboolean created_objects,
+ GOUndo **pundo, GOUndo **predo, gchar **undo_title)
+{
+ CollectObjectsData data;
+ char *text = NULL;
+ GOUndo *undo = NULL;
+ GOUndo *redo = NULL;
+
+ data.objects = data.anchors = NULL;
+ data.scg = scg;
+ g_hash_table_foreach (scg->selected_objects,
+ (GHFunc) cb_collect_objects_to_commit, &data);
+
+ undo = sheet_object_move_undo (data.objects, created_objects);
+ redo = sheet_object_move_do (data.objects, data.anchors, created_objects);
+ text = scg_objects_drag_commit_get_undo_text
+ (drag_type, g_slist_length (data.objects), created_objects);
+
+ if (pundo && predo) {
+ *pundo = undo;
+ *predo = redo;
+ if (undo_title)
+ *undo_title = text;
+ } else {
+ cmd_generic (WORKBOOK_CONTROL (scg_wbcg (scg)),
+ text, undo, redo);
+ g_free (text);
+ }
+ g_slist_free (data.objects);
+ go_slist_free_custom (data.anchors, g_free);
}
void
@@ -2514,7 +2537,7 @@ scg_objects_nudge (SheetControlGUI *scg, GnmPane *pane,
/* no nudging if we are creating an object */
if (!scg->wbcg->new_object) {
scg_objects_drag (scg, pane, NULL, &dx, &dy, drag_type, symmetric, snap_to_grid, FALSE);
- scg_objects_drag_commit (scg, drag_type, FALSE);
+ scg_objects_drag_commit (scg, drag_type, FALSE, NULL, NULL, NULL);
}
}
@@ -3353,7 +3376,7 @@ scg_image_create (SheetControlGUI *scg, SheetObjectAnchor *anchor,
scg_object_select (scg, so);
sheet_object_default_size (so, &w, &h);
scg_objects_drag (scg, NULL, NULL, &w, &h, 7, FALSE, FALSE, FALSE);
- scg_objects_drag_commit (scg, 7, TRUE);
+ scg_objects_drag_commit (scg, 7, TRUE, NULL, NULL, NULL);
}
void
@@ -3536,6 +3559,9 @@ scg_drag_receive_same_process (SheetControlGUI *scg, GtkWidget *source_widget,
int xx = x, yy = y;
int origin_x = 0, origin_y = 0;
gboolean make_dup;
+ GOUndo *undo = NULL;
+ GOUndo *redo = NULL;
+ gchar *title = NULL;
window = gtk_widget_get_parent_window (GTK_WIDGET (pane));
gdk_window_get_pointer (window, NULL, NULL, &mask);
@@ -3555,10 +3581,13 @@ 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, make_dup);
+ scg_objects_drag_commit (scg, 8, make_dup, &undo, &redo, &title);
if (make_dup) {
GSList *ptr, *objs = go_hash_keys (scg->selected_objects);
+ GOUndo *nudge_undo = NULL;
+ GOUndo *nudge_redo = NULL;
+ double dx, dy;
for (ptr = objs ; ptr != NULL ; ptr = ptr->next) {
SheetObject *dup_obj = sheet_object_dup (ptr->data);
@@ -3570,8 +3599,15 @@ scg_drag_receive_same_process (SheetControlGUI *scg, GtkWidget *source_widget,
}
}
g_slist_free (objs);
- scg_objects_nudge (scg, pane, 8, x - origin_x, y - origin_y, FALSE, FALSE);
+ dx = x - origin_x;
+ dy = y - origin_y;
+ scg_objects_drag (scg, pane, NULL, &dx, &dy, 8, FALSE, FALSE, FALSE);
+ scg_objects_drag_commit (scg, 8, FALSE, &nudge_undo, &nudge_redo, NULL);
+ undo = go_undo_combine (undo, nudge_undo);
+ redo = go_undo_combine (nudge_redo, redo);
}
+ cmd_generic (WORKBOOK_CONTROL (scg_wbcg (scg)), title, undo, redo);
+ g_free (title);
} else {
GnmCellRegion *content;
GSList *objects;
diff --git a/src/sheet-control-gui.h b/src/sheet-control-gui.h
index 19a29b4..e1d2ef1 100644
--- a/src/sheet-control-gui.h
+++ b/src/sheet-control-gui.h
@@ -32,7 +32,9 @@ void scg_objects_drag (SheetControlGUI *scg, GnmPane *gcanvas,
int drag_type, gboolean symmetric, gboolean snap_to_grid,
gboolean is_mouse_move);
void scg_objects_drag_commit (SheetControlGUI *scg, int drag_type,
- gboolean created_objects);
+ gboolean created_objects,
+ GOUndo **pundo, GOUndo **predo,
+ gchar **undo_title);
void scg_objects_nudge (SheetControlGUI *scg, GnmPane *gcanvas,
int drag_type, double dx, double dy,
gboolean symmetric,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]