Commit e3ba4c02 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg
Browse files

Partial row/col ins/del undo capabilites

Begining support for paste_from_cut.

2000-01-06  Jody Goldberg <jgoldberg@home.com>

	* *.[ch] : rename struct expr_relocate_info -> ExprRelocateInfo.

	* src/sheet.c (sheet_save_row_col_sizes) : New routine to support undo.
	(sheet_save_row_col_sizes) : Ditto.
	(col_row_info_init) : Init hard_size.

	* src/commands.c (cmd_ins_del_row_col_undo) : Restore the row/col size
	  info.
	(cmd_ins_del_row_col_redo) : Save the info.
parent 18324d41
2000-01-06 Jody Goldberg <jgoldberg@home.com>
* *.[ch] : rename struct expr_relocate_info -> ExprRelocateInfo.
* src/sheet.c (sheet_save_row_col_sizes) : New routine to support undo.
(sheet_save_row_col_sizes) : Ditto.
(col_row_info_init) : Init hard_size.
* src/commands.c (cmd_ins_del_row_col_undo) : Restore the row/col size
info.
(cmd_ins_del_row_col_redo) : Save the info.
2000-01-05 Morten Welinder <terra@diku.dk>
* src/commands.c (cmd_set_text_undo) : Free the old string.
......
2000-01-06 Jody Goldberg <jgoldberg@home.com>
* *.[ch] : rename struct expr_relocate_info -> ExprRelocateInfo.
* src/sheet.c (sheet_save_row_col_sizes) : New routine to support undo.
(sheet_save_row_col_sizes) : Ditto.
(col_row_info_init) : Init hard_size.
* src/commands.c (cmd_ins_del_row_col_undo) : Restore the row/col size
info.
(cmd_ins_del_row_col_redo) : Save the info.
2000-01-05 Morten Welinder <terra@diku.dk>
* src/commands.c (cmd_set_text_undo) : Free the old string.
......
......@@ -922,8 +922,8 @@ cell_relocate (Cell *cell, gboolean const check_bounds)
* location. All the move is doing is a bounds check.
*/
if (check_bounds) {
struct expr_relocate_info rinfo;
EvalPosition pos;
ExprRelocateInfo rinfo;
EvalPosition pos;
ExprTree *expr = cell->parsed_node;
rinfo.origin.start.col =
......
......@@ -21,6 +21,7 @@
*
* Feel free to lend a hand. There are several distinct stages to
* wrapping each command.
*
* 1) Find the appropriate place(s) in the catch all calls to activations
* of this logical function. Be careful. This should only be called by
* user initiated actions, not internal commands.
......@@ -39,6 +40,12 @@
*
* That way undo redo just become applications of the old or the new styles.
*
* FIXME : fine tune the use of these commands so that they actually
* execute the operation. Redo must be capable of applying the
* command, so lets avoid duplicating logic. SetText is a good
* example of the WRONG way to do it. I use that as an after thought
* and hence treat formating differenting.
*
* TODO : Add user preference for undo buffer size limit (# of commands ?)
* TODO : Possibly clear lists on save.
*
......@@ -248,19 +255,32 @@ command_list_release (GSList *cmd_list)
*
* @wb : The workbook the command operated on.
* @cmd : The new command to add.
* @trouble : A flag indicating whether there was a problem with the
* command.
*
* returns : @trouble.
*/
static void
command_push_undo (Workbook *wb, GtkObject *cmd)
static gboolean
command_push_undo (Workbook *wb, GtkObject *cmd, gboolean const trouble)
{
g_return_if_fail (wb != NULL);
g_return_if_fail (cmd != NULL);
/* TODO : trouble should be a variable not an argument.
* We should call redo on the command object and use
* the result as the value for trouble.
*/
if (!trouble) {
g_return_val_if_fail (wb != NULL, TRUE);
g_return_val_if_fail (cmd != NULL, TRUE);
command_list_release (wb->redo_commands);
wb->redo_commands = NULL;
command_list_release (wb->redo_commands);
wb->redo_commands = NULL;
wb->undo_commands = g_slist_prepend (wb->undo_commands, cmd);
wb->undo_commands = g_slist_prepend (wb->undo_commands, cmd);
undo_redo_menu_labels (wb);
undo_redo_menu_labels (wb);
} else
gtk_object_unref (cmd);
return trouble;
}
/******************************************************************/
......@@ -370,9 +390,7 @@ cmd_set_text (CommandContext *context,
if (*pad) g_free (text);
/* Register the command object */
command_push_undo (sheet->workbook, obj);
return FALSE;
return command_push_undo (sheet->workbook, obj, FALSE);
}
/******************************************************************/
......@@ -387,8 +405,10 @@ typedef struct
Sheet *sheet;
gboolean is_insert;
gboolean is_cols;
int index;
int count;
int index;
int count;
double *sizes;
} CmdInsDelRowCol;
GNUMERIC_MAKE_COMMAND (CmdInsDelRowCol, cmd_ins_del_row_col);
......@@ -397,23 +417,28 @@ static gboolean
cmd_ins_del_row_col_undo (GnumericCommand *cmd, CommandContext *context)
{
CmdInsDelRowCol *me = CMD_INS_DEL_ROW_COL(cmd);
int index;
g_return_val_if_fail (me != NULL, TRUE);
/* TODO : 1) Restore the values of the deleted cells */
/* TODO : 2) Restore the styles in the cleared range */
/* TODO : 3) Restore the sizes of the deleted rows/cols */
if (!me->is_insert) {
index = me->index;
if (me->is_cols)
sheet_insert_cols (context, me->sheet, me->index, me->count);
else
sheet_insert_rows (context, me->sheet, me->index, me->count);
} else {
index = (me->is_cols) ? SHEET_MAX_COLS : SHEET_MAX_ROWS - me->count;
if (me->is_cols)
sheet_delete_cols (context, me->sheet, me->index, me->count);
else
sheet_delete_rows (context, me->sheet, me->index, me->count);
}
sheet_restore_row_col_sizes (me->sheet, me->is_cols, index, me->count,
me->sizes);
me->sizes = NULL;
return FALSE;
}
......@@ -424,16 +449,22 @@ cmd_ins_del_row_col_redo (GnumericCommand *cmd, CommandContext *context)
CmdInsDelRowCol *me = CMD_INS_DEL_ROW_COL(cmd);
g_return_val_if_fail (me != NULL, TRUE);
g_return_val_if_fail (me->sizes == NULL, TRUE);
/* TODO : 1) Save the values of the deleted cells */
/* TODO : 2) Save the styles in the cleared range */
/* TODO : 3) Save the sizes of the deleted rows/cols */
if (me->is_insert) {
int const index = (me->is_cols) ? SHEET_MAX_COLS : SHEET_MAX_ROWS -
me->count;
me->sizes = sheet_save_row_col_sizes (me->sheet, me->is_cols,
index, me->count);
if (me->is_cols)
sheet_insert_cols (context, me->sheet, me->index, me->count);
else
sheet_insert_rows (context, me->sheet, me->index, me->count);
} else {
me->sizes = sheet_save_row_col_sizes (me->sheet, me->is_cols,
me->index, me->count);
if (me->is_cols)
sheet_delete_cols (context, me->sheet, me->index, me->count);
else
......@@ -445,10 +476,10 @@ cmd_ins_del_row_col_redo (GnumericCommand *cmd, CommandContext *context)
static void
cmd_ins_del_row_col_destroy (GtkObject *cmd)
{
#if 0
CmdInsDelRowCol *me = CMD_INS_DEL_ROW_COL(cmd);
#endif
/* FIXME : Fill in */
if (me->sizes)
g_free (me->sizes);
gnumeric_command_destroy (cmd);
}
......@@ -460,6 +491,7 @@ cmd_ins_del_row_col (CommandContext *context,
{
GtkObject *obj;
CmdInsDelRowCol *me;
gboolean trouble;
g_return_val_if_fail (sheet != NULL, TRUE);
......@@ -472,13 +504,14 @@ cmd_ins_del_row_col (CommandContext *context,
me->is_insert = is_insert;
me->index = index;
me->count = count;
me->sizes = NULL;
me->parent.cmd_descriptor = descriptor;
/* Register the command object */
command_push_undo (sheet->workbook, obj);
trouble = cmd_ins_del_row_col_redo (GNUMERIC_COMMAND(me), context);
return cmd_ins_del_row_col_redo (GNUMERIC_COMMAND(me), context);
/* Register the command object */
return command_push_undo (sheet->workbook, obj, trouble);
}
gboolean
......@@ -675,13 +708,34 @@ cmd_paste_cut_destroy (GtkObject *cmd)
gnumeric_command_destroy (cmd);
}
#if 0
gboolean
cmd_paste_cut (CommandContext *context,
cmd_paste_cut (CommandContext *context, ExprRelocateInfo const * const info)
{
return FALSE;
GtkObject *obj;
CmdPasteCut *me;
gboolean trouble;
/* FIXME : improve on this */
char *descriptor = g_strdup_printf (_("Moving cells") );
g_return_val_if_fail (info != NULL, TRUE);
obj = gtk_type_new (CMD_PASTE_CUT_TYPE);
me = CMD_PASTE_CUT (obj);
/* Store the specs for the object */
me->parent.cmd_descriptor = descriptor;
trouble = cmd_paste_cut_redo (GNUMERIC_COMMAND(me), context);
/* Register the command object */
/* NOTE : if the destination workbook is different from the source workbook
* should we have undo elements in both menus ?? It seems poor form to
* hit undo in 1 window and effect another ...
*/
return command_push_undo (info->target_sheet->workbook, obj, trouble);
}
#endif
/******************************************************************/
......
#ifndef GNUMERIC_COMMAND_H
#define GNUMERIC_COMMAND_H
#include "gnumeric.h"
#include "command-context.h"
void command_undo (CommandContext *context, Workbook *wb);
......@@ -23,4 +24,7 @@ gboolean cmd_delete_cols (CommandContext *context,
gboolean cmd_delete_rows (CommandContext *context,
Sheet *sheet, int start_row, int count);
gboolean cmd_paste_cut (CommandContext *context,
ExprRelocateInfo const * const info);
#endif /* GNUMERIC_COMMAND_CONTEXT_H */
......@@ -1417,7 +1417,7 @@ enum CellRefRelocate {
static enum CellRefRelocate
cellref_relocate (CellRef * const ref,
const EvalPosition * const pos,
const struct expr_relocate_info * const rinfo)
const ExprRelocateInfo * const rinfo)
{
/* For row or column refs
* Ref From To
......@@ -1519,7 +1519,7 @@ cellref_relocate (CellRef * const ref,
ExprTree *
expr_relocate (const ExprTree *expr,
const EvalPosition *pos,
const struct expr_relocate_info *rinfo)
const ExprRelocateInfo *rinfo)
{
g_return_val_if_fail (expr != NULL, NULL);
......
......@@ -172,7 +172,7 @@ ExprTree *expr_tree_array_formula (int const x, int const y, int const rows,
void expr_tree_ref (ExprTree *tree);
void expr_tree_unref (ExprTree *tree);
struct expr_relocate_info {
struct _ExprRelocateInfo {
Range origin; /* References to cells in origin_sheet!range */
Sheet *origin_sheet; /* should to adjusted */
......@@ -182,7 +182,7 @@ struct expr_relocate_info {
ExprTree *expr_relocate (const ExprTree *expr,
const EvalPosition *pos,
const struct expr_relocate_info *info);
const ExprRelocateInfo *info);
int expr_tree_get_const_int (ExprTree const *const expr);
char const * expr_tree_get_const_str (ExprTree const *const expr);
......
......@@ -10,9 +10,10 @@ typedef struct _Workbook Workbook;
typedef struct _Sheet Sheet;
typedef struct _Cell Cell;
typedef struct _ExprTree ExprTree;
typedef struct _ArrayRef ArrayRef;
typedef struct _ExprName ExprName;
typedef struct _ExprTree ExprTree;
typedef struct _ArrayRef ArrayRef;
typedef struct _ExprName ExprName;
typedef struct _ExprRelocateInfo ExprRelocateInfo;
typedef struct _CellRegion CellRegion;
typedef GList CellList;
......
......@@ -648,7 +648,7 @@ sheet_selection_cut (CommandContext *context, Sheet *sheet)
}
static void
sheet_selection_move (struct expr_relocate_info *rinfo)
sheet_selection_move (ExprRelocateInfo *rinfo)
{
Sheet * const sheet = rinfo->target_sheet;
Range r = rinfo->origin;
......@@ -686,7 +686,7 @@ sheet_selection_paste (CommandContext *context, Sheet *sheet,
/* If contents are null this was a cut */
if (content == NULL && area != NULL) {
struct expr_relocate_info rinfo;
ExprRelocateInfo rinfo;
Sheet * src_sheet = application_clipboard_sheet_get ();
Range const *sel = selection_first_range (sheet, FALSE);
......
......@@ -523,7 +523,7 @@ autofill_cell (Cell *cell, int idx, FillItem *fi)
{
ExprTree * func;
EvalPosition pos;
struct expr_relocate_info rinfo;
ExprRelocateInfo rinfo;
/* FIXME : Find out how to handle this */
rinfo.target_sheet = rinfo.origin_sheet = 0;
......
......@@ -839,7 +839,7 @@ sheet_style_insert_colrow (Sheet *sheet, int pos, int count,
}
void
sheet_style_relocate (const struct expr_relocate_info *rinfo)
sheet_style_relocate (const ExprRelocateInfo *rinfo)
{
GList *stored_regions = NULL;
GList *l, *next;
......
......@@ -87,6 +87,7 @@ col_row_info_init (ColRowInfo *cri, double points)
cri->margin_a = 0;
cri->margin_b = 0;
cri->hard_size = FALSE;
cri->spans = NULL;
}
......@@ -749,7 +750,8 @@ sheet_col_set_internal_width (Sheet *sheet, ColRowInfo *ci, double width)
}
void
sheet_row_set_height_units (Sheet *sheet, int row, double height, gboolean height_set_by_user)
sheet_row_set_height_units (Sheet *sheet, int row, double height,
gboolean set_by_user)
{
ColRowInfo *ri;
......@@ -764,14 +766,15 @@ sheet_row_set_height_units (Sheet *sheet, int row, double height, gboolean heigh
sheet_row_add (sheet, ri);
}
if (height_set_by_user)
if (set_by_user)
ri->hard_size = TRUE;
sheet_row_set_internal_height (sheet, ri, height);
}
void
sheet_col_set_width_units (Sheet *sheet, int col, double width)
sheet_col_set_width_units (Sheet *sheet, int col, double width,
gboolean set_by_user)
{
ColRowInfo *ci;
......@@ -786,6 +789,8 @@ sheet_col_set_width_units (Sheet *sheet, int col, double width)
sheet_col_add (sheet, ci);
}
if (set_by_user)
ci->hard_size = TRUE;
sheet_col_set_internal_width (sheet, ci, width);
}
......@@ -3311,7 +3316,7 @@ void
sheet_insert_cols (CommandContext *context, Sheet *sheet,
int col, int count)
{
struct expr_relocate_info reloc_info;
ExprRelocateInfo reloc_info;
GList *deps;
int i;
......@@ -3380,7 +3385,7 @@ void
sheet_delete_cols (CommandContext *context, Sheet *sheet,
int col, int count)
{
struct expr_relocate_info reloc_info;
ExprRelocateInfo reloc_info;
GList *deps;
int i;
......@@ -3450,7 +3455,7 @@ void
sheet_insert_rows (CommandContext *context, Sheet *sheet,
int row, int count)
{
struct expr_relocate_info reloc_info;
ExprRelocateInfo reloc_info;
GList *deps;
int i;
......@@ -3520,7 +3525,7 @@ void
sheet_delete_rows (CommandContext *context, Sheet *sheet,
int row, int count)
{
struct expr_relocate_info reloc_info;
ExprRelocateInfo reloc_info;
GList *deps;
int i;
......@@ -3586,7 +3591,7 @@ sheet_delete_rows (CommandContext *context, Sheet *sheet,
*/
void
sheet_move_range (CommandContext *context,
struct expr_relocate_info const * rinfo)
ExprRelocateInfo const * rinfo)
{
GList *deps, *cells = NULL;
Cell *cell;
......@@ -3690,7 +3695,7 @@ void
sheet_shift_rows (CommandContext *context, Sheet *sheet,
int col, int start_row, int end_row, int count)
{
struct expr_relocate_info rinfo;
ExprRelocateInfo rinfo;
rinfo.origin.start.col = col;
rinfo.origin.start.row = start_row;
rinfo.origin.end.col = SHEET_MAX_COLS-1;
......@@ -3719,7 +3724,7 @@ void
sheet_shift_cols (CommandContext *context, Sheet *sheet,
int start_col, int end_col, int row, int count)
{
struct expr_relocate_info rinfo;
ExprRelocateInfo rinfo;
rinfo.origin.start.col = start_col;
rinfo.origin.start.row = row;
rinfo.origin.end.col = end_col;
......@@ -3730,3 +3735,49 @@ sheet_shift_cols (CommandContext *context, Sheet *sheet,
sheet_move_range (context, &rinfo);
}
double *
sheet_save_row_col_sizes (Sheet *sheet, gboolean const is_cols,
int index, int count)
{
int i;
double *res = NULL;
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (count > 0, NULL);
res = g_new (double, count);
for (i = 0 ; i < count ; ++i) {
ColRowInfo *info = sheet_col_get_info (sheet, index + i);
res[i] = info->units;
if (info->hard_size)
res[i] *= -1.;
}
return res;
}
void
sheet_restore_row_col_sizes (Sheet *sheet, gboolean const is_cols,
int index, int count, double *sizes)
{
int i;
g_return_if_fail (sizes != NULL);
g_return_if_fail (sheet != NULL);
g_return_if_fail (count > 0);
for (i = 0 ; i < count ; ++i) {
gboolean hard_size = FALSE;
if (sizes[i] < 0.) {
hard_size = TRUE;
sizes[i] *= -1.;
}
if (is_cols)
sheet_col_set_width_units (sheet, index+i, sizes[i], hard_size);
else
sheet_row_set_height_units (sheet, index+i, sizes[i], hard_size);
}
g_free (sizes);
}
......@@ -207,6 +207,12 @@ int sheet_find_boundary_horizontal (Sheet *sheet, int start_col, int row,
int sheet_find_boundary_vertical (Sheet *sheet, int col, int start_row,
int count, gboolean jump_to_boundaries);
/* Save and restore the sizes of a set of rows or columns */
double * sheet_save_row_col_sizes (Sheet *sheet, gboolean const is_cols,
int index, int count);
void sheet_restore_row_col_sizes (Sheet *sheet, gboolean const is_cols,
int index, int count, double *);
/* Duplicates the information of a col/row */
ColRowInfo *sheet_duplicate_colrow (ColRowInfo *original);
......@@ -243,7 +249,8 @@ void sheet_col_set_width (Sheet *sheet,
int col, int width);
void sheet_col_info_set_width (Sheet *sheet,
ColRowInfo *ci, int width);
void sheet_col_set_width_units (Sheet *sheet, int col, double width);
void sheet_col_set_width_units (Sheet *sheet, int col, double width,
gboolean set_by_user);
void sheet_col_set_internal_width (Sheet *sheet, ColRowInfo *ci,
double width);
......@@ -254,7 +261,7 @@ void sheet_row_set_height_units (Sheet *sheet, int row, double height,
gboolean height_set_by_user);
void sheet_row_info_set_height (Sheet *sheet,
ColRowInfo *ri, int height,
gboolean height_set_by_user);
gboolean set_by_user);
void sheet_row_set_internal_height (Sheet *sheet, ColRowInfo *ri, double height);
int sheet_col_size_fit (Sheet *sheet, int col);
......@@ -267,7 +274,6 @@ void sheet_row_set_selection (Sheet *sheet,
void sheet_set_selection (Sheet *sheet, SheetSelection const *ss);
/* sheet-style.c */
struct expr_relocate_info;
MStyle *sheet_style_compute (Sheet const *sheet,
int col, int row);
void sheet_style_attach (Sheet *sheet, Range range,
......@@ -279,7 +285,7 @@ void sheet_style_insert_colrow (Sheet *sheet, int pos, int coun
gboolean is_col);
void sheet_style_delete_colrow (Sheet *sheet, int pos, int count,
gboolean is_col);
void sheet_style_relocate (const struct expr_relocate_info *rinfo);
void sheet_style_relocate (const ExprRelocateInfo *rinfo);
void sheet_selection_apply_style (Sheet *sheet, MStyle *style);
MStyle *sheet_selection_get_unique_style (Sheet *sheet,
MStyleBorder **borders);
......@@ -326,7 +332,7 @@ gboolean sheet_is_pristine (Sheet *sheet);
/* Sheet information manipulation */
void sheet_move_range (CommandContext *context,
struct expr_relocate_info const * rinfo);
ExprRelocateInfo const * rinfo);
Sheet *sheet_lookup_by_name (Workbook *wb, const char *name);
......
......@@ -97,7 +97,7 @@ workbook_cmd_format_column_width (GtkWidget *widget, Workbook *wb)
int col;
for (col = ss->user.start.col; col <= ss->user.end.col; col++)
sheet_col_set_width_units (sheet, col, value);
sheet_col_set_width_units (sheet, col, value, TRUE);
}
sheet_set_dirty (sheet, TRUE);
}
......
......@@ -162,9 +162,8 @@ gboolean workbook_can_detach_sheet (Workbook *wb, Sheet *sheet);
GList *workbook_sheets (Workbook *wb);
char *workbook_selection_to_string (Workbook *wb, Sheet *base_sheet);
struct expr_relocate_info;
void workbook_expr_relocate (Workbook *wb,
struct expr_relocate_info const *info);
ExprRelocateInfo const *info);
/*
* Does any pending recalculations
*/
......
......@@ -2424,7 +2424,7 @@ sheet_action_delete_sheet (GtkWidget *widget, Sheet *current_sheet)
* to infinity (and beyond)
*/
{
struct expr_relocate_info rinfo;
ExprRelocateInfo rinfo;
rinfo.origin.start.col = 0;
rinfo.origin.start.row = 0;
rinfo.origin.end.col = SHEET_MAX_COLS-1;
......@@ -2851,7 +2851,7 @@ workbook_foreach (WorkbookCallback cback, gpointer data)
*/
void
workbook_expr_relocate (Workbook *wb, struct expr_relocate_info const *info)
workbook_expr_relocate (Workbook *wb, ExprRelocateInfo const *info)
{
GList *cells, *l;
EvalPosition pos;
......
......@@ -162,9 +162,8 @@ gboolean workbook_can_detach_sheet (Workbook *wb, Sheet *sheet);
GList *workbook_sheets (Workbook *wb);
char *workbook_selection_to_string (Workbook *wb, Sheet *base_sheet);
struct expr_relocate_info;
void workbook_expr_relocate (Workbook *wb,
struct expr_relocate_info const *info);
ExprRelocateInfo const *info);
/*
* Does any pending recalculations
*/
......
......@@ -1837,7 +1837,7 @@ xml_read_cols_info (parse_xml_context_t *ctxt, Sheet *sheet, xmlNodePtr tree)
if (!info)
continue;