From a40c38c441c4ee4293f402621f2e2709333ad855 Mon Sep 17 00:00:00 2001 From: Morten Welinder Date: Tue, 24 Apr 2018 08:18:56 -0400 Subject: [PATCH] Paste: fix undo That broke with respect to colrow sizes. Things are actually much simpler with the clipboard handling those. --- ChangeLog | 5 +++++ src/clipboard.c | 2 -- src/colrow.c | 4 ++-- src/commands.c | 39 ++++++--------------------------------- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index cbd6c6145..0b79669a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-04-24 Morten Welinder + + * src/commands.c (cmd_paste_copy_impl): Simplify now that + clipboard handles colrow sizes. + 2018-04-21 Morten Welinder * src/sheet-object-image.c (gnm_soi_write_image): If the format diff --git a/src/clipboard.c b/src/clipboard.c index 860a2619c..97c44f67b 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -455,8 +455,6 @@ clipboard_paste_region (GnmCellRegion const *cr, src_cols = cr->cols; src_rows = cr->rows; - - /* If the source is a single cell or a single merge */ /* Treat a target of a single merge specially, don't split the merge */ if ((src_cols == 1 && src_rows == 1) || diff --git a/src/colrow.c b/src/colrow.c index ad31c5f36..e7a0283f2 100644 --- a/src/colrow.c +++ b/src/colrow.c @@ -853,8 +853,8 @@ cb_autofit_row (GnmColRowIter const *iter, gpointer data_) * @ignore_strings: Don't consider cells with string values. * @min_current: Don't shrink below current size. * @min_default: Don't shrink below default size. - * @indices: indices appropriate for colrow_restore_state_group. - * @sizes: old sizes appropriate for colrow_restore_state_group. + * @indices: (nullable): indices appropriate for colrow_restore_state_group. + * @sizes: (nullable): old sizes appropriate for colrow_restore_state_group. * * This function autofits columns or rows in @range as specified by * @is_cols. Only cells in @range are considered for the sizing diff --git a/src/commands.c b/src/commands.c index a46eeac6c..2b2ffe4d7 100644 --- a/src/commands.c +++ b/src/commands.c @@ -2907,10 +2907,6 @@ typedef struct { GnmPasteTarget dst; gboolean has_been_through_cycle; gboolean only_objects; - ColRowStateGroup *saved_sizes_rows; - ColRowStateGroup *saved_sizes_cols; - ColRowIndexList *saved_list_rows; - ColRowIndexList *saved_list_cols; gboolean single_merge_to_single_merge; } CmdPasteCopy; @@ -2987,7 +2983,6 @@ cmd_paste_copy_impl (GnmCommand *cmd, WorkbookControl *wbc, CmdPasteCopy *me = CMD_PASTE_COPY (cmd); GnmCellRegion *contents; GSList *old_objects; - GnmPasteTarget actual_dst; g_return_val_if_fail (me != NULL, TRUE); g_return_val_if_fail (me->contents != NULL, TRUE); @@ -3003,8 +2998,9 @@ cmd_paste_copy_impl (GnmCommand *cmd, WorkbookControl *wbc, if (me->has_been_through_cycle) me->dst.paste_flags = PASTE_CONTENTS | (me->dst.paste_flags & PASTE_ALL_SHEET); - actual_dst = me->dst; - if (clipboard_paste_region (me->contents, &actual_dst, GO_CMD_CONTEXT (wbc))) { + + if (clipboard_paste_region (me->contents, &me->dst, + GO_CMD_CONTEXT (wbc))) { /* There was a problem, avoid leaking */ cellregion_unref (contents); g_slist_free (old_objects); @@ -3015,26 +3011,13 @@ cmd_paste_copy_impl (GnmCommand *cmd, WorkbookControl *wbc, g_slist_foreach (me->pasted_objects, (GFunc)g_object_ref, NULL); g_slist_free (old_objects); - if (is_undo) { - colrow_restore_state_group (me->dst.sheet, FALSE, - me->saved_list_rows, me->saved_sizes_rows); - colrow_state_group_destroy (me->saved_sizes_rows); - me->saved_sizes_rows = NULL; - colrow_index_list_destroy (me->saved_list_rows); - me->saved_list_rows = NULL; - colrow_restore_state_group (me->dst.sheet, TRUE, - me->saved_list_cols, me->saved_sizes_cols); - colrow_state_group_destroy (me->saved_sizes_cols); - me->saved_sizes_cols = NULL; - colrow_index_list_destroy (me->saved_list_cols); - me->saved_list_cols = NULL; - } else { + if (!is_undo && !me->has_been_through_cycle) { colrow_autofit (me->dst.sheet, &me->dst.range, FALSE, FALSE, TRUE, FALSE, - &me->saved_list_rows, &me->saved_sizes_rows); + NULL, NULL); colrow_autofit (me->dst.sheet, &me->dst.range, TRUE, TRUE, TRUE, FALSE, - &me->saved_list_cols, &me->saved_sizes_cols); + NULL, NULL); } /* @@ -3082,12 +3065,6 @@ cmd_paste_copy_finalize (GObject *cmd) { CmdPasteCopy *me = CMD_PASTE_COPY (cmd); - me->saved_sizes_rows = colrow_state_group_destroy (me->saved_sizes_rows); - colrow_index_list_destroy (me->saved_list_rows); - me->saved_list_rows = NULL; - me->saved_sizes_cols = colrow_state_group_destroy (me->saved_sizes_cols); - colrow_index_list_destroy (me->saved_list_cols); - me->saved_list_cols = NULL; if (me->contents) { cellregion_unref (me->contents); me->contents = NULL; @@ -3129,10 +3106,6 @@ cmd_paste_copy (WorkbookControl *wbc, me->contents = cr; me->has_been_through_cycle = FALSE; me->only_objects = (cr->cols < 1 || cr->rows < 1); - me->saved_sizes_rows = NULL; - me->saved_sizes_cols = NULL; - me->saved_list_rows = NULL; - me->saved_list_cols = NULL; me->pasted_objects = NULL; me->orig_contents_objects = go_slist_map (cr->objects, (GOMapFunc)sheet_object_dup); -- 2.11.4.GIT