Commit 0e537e1c authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Limit size of undo/redo stack.


2000-11-20  Morten Welinder  <terra@diku.dk>

	* gnumeric.spec.in (gal): Require 0.2.99.

	* configure.in (gal): Require 0.2.99 (and fix check).

	* src/workbook-control-gui.c (workbook_control_gui_ctor_class):
 	Set undo_redo.truncate.
	(wbcg_undo_redo_truncate): New function.

	* src/commands.c (command_push_undo): truncate undo information.
	(truncate_undo_info): New function.
	(cmd_format): Properly size undo information.
parent 360ffac2
2000-11-20 Morten Welinder <terra@diku.dk>
* gnumeric.spec.in (gal): Require 0.2.99.
* configure.in (gal): Require 0.2.99 (and fix check).
* src/workbook-control-gui.c (workbook_control_gui_ctor_class):
Set undo_redo.truncate.
(wbcg_undo_redo_truncate): New function.
* src/commands.c (command_push_undo): truncate undo information.
(truncate_undo_info): New function.
(cmd_format): Properly size undo information.
2000-11-20 Jody Goldberg <jgoldberg@home.com>
* src/colrow.c (col_row_get_index_list) : Take away my crack pipe.
......
......@@ -6,6 +6,9 @@ Jody:
Jon Kåre:
* Improve XL export of non-builtin functions.
Morten:
* Semi-smart undo/redo list truncation.
--------------------------------------------------------------------------
Gnumeric 0.59
......
2000-11-20 Morten Welinder <terra@diku.dk>
* gnumeric.spec.in (gal): Require 0.2.99.
* configure.in (gal): Require 0.2.99 (and fix check).
* src/workbook-control-gui.c (workbook_control_gui_ctor_class):
Set undo_redo.truncate.
(wbcg_undo_redo_truncate): New function.
* src/commands.c (command_push_undo): truncate undo information.
(truncate_undo_info): New function.
(cmd_format): Properly size undo information.
2000-11-20 Jody Goldberg <jgoldberg@home.com>
* src/colrow.c (col_row_get_index_list) : Take away my crack pipe.
......
2000-11-20 Morten Welinder <terra@diku.dk>
* gnumeric.spec.in (gal): Require 0.2.99.
* configure.in (gal): Require 0.2.99 (and fix check).
* src/workbook-control-gui.c (workbook_control_gui_ctor_class):
Set undo_redo.truncate.
(wbcg_undo_redo_truncate): New function.
* src/commands.c (command_push_undo): truncate undo information.
(truncate_undo_info): New function.
(cmd_format): Properly size undo information.
2000-11-20 Jody Goldberg <jgoldberg@home.com>
* src/colrow.c (col_row_get_index_list) : Take away my crack pipe.
......
2000-11-20 Morten Welinder <terra@diku.dk>
* gnumeric.spec.in (gal): Require 0.2.99.
* configure.in (gal): Require 0.2.99 (and fix check).
* src/workbook-control-gui.c (workbook_control_gui_ctor_class):
Set undo_redo.truncate.
(wbcg_undo_redo_truncate): New function.
* src/commands.c (command_push_undo): truncate undo information.
(truncate_undo_info): New function.
(cmd_format): Properly size undo information.
2000-11-20 Jody Goldberg <jgoldberg@home.com>
* src/colrow.c (col_row_get_index_list) : Take away my crack pipe.
......
2000-11-20 Morten Welinder <terra@diku.dk>
* gnumeric.spec.in (gal): Require 0.2.99.
* configure.in (gal): Require 0.2.99 (and fix check).
* src/workbook-control-gui.c (workbook_control_gui_ctor_class):
Set undo_redo.truncate.
(wbcg_undo_redo_truncate): New function.
* src/commands.c (command_push_undo): truncate undo information.
(truncate_undo_info): New function.
(cmd_format): Properly size undo information.
2000-11-20 Jody Goldberg <jgoldberg@home.com>
* src/colrow.c (col_row_get_index_list) : Take away my crack pipe.
......
......@@ -23,7 +23,7 @@ You need:
gtk+ >= 1.2.7 (gnome-libs 1.3 is not supported)
gnome-libs >= 1.0.57 (gnome-libs 2.0 is not supported)
libglade >= 0.14
gal >= 0.2.2.0
gal >= 0.2.99.0
gnome-print >= 0.25 (Be careful, newer version may not compile)
gnome-xml >= 1.8.7 (gnome-xml 2.x not supported yet)
......
......@@ -342,14 +342,14 @@ fi
dnl ******************************
dnl Gnome App Lib checking
dnl ******************************
AC_MSG_CHECKING(for Gnome App libraries (GAL) >= 0.2.2.0)
AC_MSG_CHECKING(for Gnome App libraries (GAL) >= 0.2.99.0)
if gnome-config --libs gal > /dev/null 2>&1; then
vers=`gnome-config --modversion gal | sed -e "s/gal-//" -e 's/cvs$//' -e 's/pre$//' | \
awk 'BEGIN { FS = "."; } { print $1*1000000 + $2*10000 + $3*100 + $4; }'`
if test "$vers" -ge 20200; then
awk 'BEGIN { FS = "."; } { printf "%d", $1*1000000 + $2*10000 + $3*100 + $4; }'`
if test "$vers" -ge 29900; then
AC_MSG_RESULT(found)
else
AC_MSG_ERROR(You need at least GNOME Application libs 0.2.2.0 for this version of Gnumeric)
AC_MSG_ERROR(You need at least GNOME Application libs 0.2.99.0 for this version of Gnumeric)
fi
else
AC_MSG_ERROR(Did not find GnomeAppLib (GAL) installed)
......
......@@ -20,7 +20,7 @@ Requires: gnome-print >= 0.25
Requires: libglade >= 0.14
Requires: libxml >= 1.8.5
Requires: libole2 >= 0.1.7
Requires: gal >= 0.2.2
Requires: gal >= 0.2.99
%description
GNOME (GNU Network Object Model Environment) is a user-friendly set of
......
......@@ -93,6 +93,7 @@ typedef struct
{
GtkObject parent;
char const *cmd_descriptor; /* A string to put in the menu */
int size; /* See truncate_undo_info. */
} GnumericCommand;
typedef gboolean (* UndoCmd)(GnumericCommand *this, WorkbookControl *wbc);
......@@ -127,22 +128,22 @@ gnumeric_command_destroy (GtkObject *obj)
(*gtk_object_dtor) (obj);
}
#define GNUMERIC_MAKE_COMMAND(type, func) \
static gboolean \
func ## _undo (GnumericCommand *me, WorkbookControl *wbc); \
static gboolean \
func ## _redo (GnumericCommand *me, WorkbookControl *wbc); \
static void \
func ## _destroy (GtkObject *object); \
static void \
func ## _class_init (GnumericCommandClass * const parent) \
{ \
parent->undo_cmd = (UndoCmd)& func ## _undo; \
parent->redo_cmd = (RedoCmd)& func ## _redo; \
if (gtk_object_dtor == NULL) \
gtk_object_dtor = parent->parent_class.destroy; \
parent->parent_class.destroy = & func ## _destroy; \
} \
#define GNUMERIC_MAKE_COMMAND(type, func) \
static gboolean \
func ## _undo (GnumericCommand *me, WorkbookControl *wbc); \
static gboolean \
func ## _redo (GnumericCommand *me, WorkbookControl *wbc); \
static void \
func ## _destroy (GtkObject *object); \
static void \
func ## _class_init (GnumericCommandClass * const parent) \
{ \
parent->undo_cmd = (UndoCmd)& func ## _undo; \
parent->redo_cmd = (RedoCmd)& func ## _redo; \
if (gtk_object_dtor == NULL) \
gtk_object_dtor = parent->parent_class.destroy; \
parent->parent_class.destroy = & func ## _destroy; \
} \
static GNUMERIC_MAKE_TYPE_WITH_CLASS(func, #type, type, GnumericCommandClass, func ## _class_init, NULL, \
gnumeric_command_get_type())
......@@ -287,6 +288,65 @@ command_list_release (GSList *cmd_list)
}
}
/*
* Each undo item has a certain size. The size of typing a value into
* a cell is the unit size. A large autoformat could have a size of
* hundreds or even thousands.
*
* We wish to have the same undo behaviour across platforms, so please
* don't use sizeof in computing the undo size.
*/
/*
* Truncate the undo list if it is too big.
*
* Returns -1 if no truncation was done, or else the number of elements
* left.
*/
static int
truncate_undo_info (WorkbookControl *wbc)
{
int size_left = 100; /* FIXME? */
int ok_count;
GSList *l, *prev;
Workbook *wb = wb_control_workbook (wbc);
for (l = wb->undo_commands, prev = NULL, ok_count = 0;
l;
prev = l, l = l->next, ok_count++) {
int min_leave;
GnumericCommand *cmd = GNUMERIC_COMMAND (l->data);
int size = cmd->size;
if (size < 1) {
/*
* We could g_assert, but that would cause data loss.
* Instead, just continue.
*/
g_warning ("Faulty undo_size_func, please report.");
size = 1;
}
/* Keep at least one undo item. */
if (size > size_left && ok_count >= 1) {
/* Current item is too big; truncate list here. */
command_list_release (l);
prev->next = NULL;
return ok_count;
}
/*
* In order to allow a series of useful small items behind
* a big item, leave at least 10% of current item's size.
*/
min_leave = size / 10;
size_left = MAX (size_left - size, min_leave);
}
return -1;
}
/**
* command_push_undo : An internal utility to tack a new command
* onto the undo list.
......@@ -316,16 +376,22 @@ command_push_undo (WorkbookControl *wbc, GtkObject *obj)
trouble = klass->redo_cmd (cmd, wbc);
if (!trouble) {
int undo_trunc;
command_list_release (wb->redo_commands);
wb->redo_commands = NULL;
wb->undo_commands = g_slist_prepend (wb->undo_commands, cmd);
undo_trunc = truncate_undo_info (wbc);
WORKBOOK_FOREACH_CONTROL (wb, view, control,
{
wb_control_undo_redo_push (control,
cmd->cmd_descriptor, TRUE);
if (undo_trunc >= 0)
wb_control_undo_redo_truncate (control, undo_trunc, TRUE);
wb_control_undo_redo_clear (control, FALSE);
});
undo_redo_menu_labels (wb);
} else
......@@ -449,6 +515,8 @@ cmd_set_text (WorkbookControl *wbc,
} else
text = corrected_text;
me->parent.size = 1;
me->parent.cmd_descriptor =
g_strdup_printf (_("Typing \"%s%s\" in %s"), text, pad,
cell_pos_name(pos));
......@@ -635,6 +703,8 @@ cmd_area_set_text (WorkbookControl *wbc, EvalPos const *pos,
} else
text = (gchar *) new_text;
me->parent.size = 1;
me->parent.cmd_descriptor =
g_strdup_printf (_("Typing \"%s%s\""), text, pad);
......@@ -825,6 +895,8 @@ cmd_ins_del_row_col (WorkbookControl *wbc,
me->sizes = NULL;
me->contents = NULL;
me->parent.size = 1;
me->parent.cmd_descriptor = descriptor;
/* Register the command object */
......@@ -1018,6 +1090,8 @@ cmd_clear_selection (WorkbookControl *wbc, Sheet *sheet, int clear_flags)
if (clear_flags & CLEAR_COMMENTS)
g_warning ("Deleted comments cannot be restored yet");
me->parent.size = 1;
/* TODO : Something more descriptive ? maybe the range name */
me->parent.cmd_descriptor = g_strdup (_("Clear"));
......@@ -1181,6 +1255,8 @@ cmd_format (WorkbookControl *wbc, Sheet *sheet,
me->selection = selection_get_ranges (sheet, FALSE); /* TRUE ? */
me->new_style = style;
me->parent.size = 1;
me->old_styles = NULL;
for (l = me->selection; l; l = l->next) {
CmdFormatOldStyle *os;
......@@ -1197,6 +1273,7 @@ cmd_format (WorkbookControl *wbc, Sheet *sheet,
os->styles = sheet_get_styles_in_range (sheet, &range);
os->pos = range.start;
me->parent.size += g_list_length (os->styles);
me->old_styles = g_slist_append (me->old_styles, os);
}
......@@ -1279,6 +1356,8 @@ cmd_rename_sheet (WorkbookControl *wbc, const char *old_name, const char *new_na
me->old_name = g_strdup (old_name);
me->new_name = g_strdup (new_name);
me->parent.size = 1;
me->parent.cmd_descriptor =
g_strdup_printf (_("Rename sheet '%s' '%s'"), old_name, new_name);
......@@ -1420,6 +1499,8 @@ cmd_set_date_time (WorkbookControl *wbc,
me->is_date = is_date;
me->contents = NULL;
me->parent.size = 1;
me->parent.cmd_descriptor =
g_strdup_printf (is_date
? _("Setting current date in %s")
......@@ -1519,6 +1600,8 @@ cmd_resize_row_col (WorkbookControl *wbc, Sheet *sheet,
me->saved_sizes = NULL;
me->new_size = new_size;
me->parent.size = 1;
me->parent.cmd_descriptor = is_cols
? g_strdup (_("Setting width of columns"))
: g_strdup (_("Setting height of rows"));
......@@ -1614,6 +1697,8 @@ cmd_sort (WorkbookControl *wbc, SortData *data)
me->perm = NULL;
me->inv = NULL;
me->parent.size = 1;
me->parent.cmd_descriptor =
g_strdup_printf (_("Sorting %s"), range_name(me->data->range));
......@@ -1695,6 +1780,8 @@ cmd_hide_selection_rows_cols (WorkbookControl *wbc, Sheet *sheet,
me->visible = visible;
me->elements = col_row_get_visiblity_toggle (sheet, is_cols, visible);
me->parent.size = 1;
me->parent.cmd_descriptor = g_strdup (is_cols
? (visible ? _("Unhide columns") : _("Hide columns"))
: (visible ? _("Unhide rows") : _("Hide rows")));
......@@ -1879,6 +1966,8 @@ cmd_paste_cut (WorkbookControl *wbc, ExprRelocateInfo const *info,
me->reloc_storage = NULL;
me->move_selection = move_selection;
me->parent.size = 1;
me->parent.cmd_descriptor = descriptor;
/* NOTE : if the destination workbook is different from the source workbook
......@@ -2007,6 +2096,8 @@ cmd_paste_copy (WorkbookControl *wbc,
}
}
me->parent.size = 1;
me->parent.cmd_descriptor = g_strdup_printf (_("Pasting into %s"), range_name(&pt->range));
/* Register the command object */
......@@ -2138,6 +2229,8 @@ cmd_autofill (WorkbookControl *wbc, Sheet *sheet,
me->end_col = end_col;
me->end_row = end_row;
me->parent.size = 1;
me->parent.cmd_descriptor = g_strdup (_("Autofill"));
/* Register the command object */
......@@ -2294,6 +2387,8 @@ cmd_autoformat (WorkbookControl *wbc, Sheet *sheet, FormatTemplate *ft)
me->old_styles = g_slist_append (me->old_styles, os);
}
me->parent.size = 1;
me->parent.cmd_descriptor = g_strdup (_("Autoformat"));
/* Register the command object */
......
......@@ -661,6 +661,12 @@ wbcg_undo_redo_clear (WorkbookControl *wbc, gboolean is_undo)
gtk_combo_stack_clear (ur_stack (wbc, is_undo));
}
static void
wbcg_undo_redo_truncate (WorkbookControl *wbc, int n, gboolean is_undo)
{
gtk_combo_stack_truncate (ur_stack (wbc, is_undo), n);
}
static void
wbcg_undo_redo_pop (WorkbookControl *wbc, gboolean is_undo)
{
......@@ -3074,10 +3080,11 @@ workbook_control_gui_ctor_class (GtkObjectClass *object_class)
wbc_class->sheet.move = wbcg_sheet_move;
wbc_class->sheet.remove_all = wbcg_sheet_remove_all;
wbc_class->undo_redo.clear = wbcg_undo_redo_clear;
wbc_class->undo_redo.pop = wbcg_undo_redo_pop;
wbc_class->undo_redo.push = wbcg_undo_redo_push;
wbc_class->undo_redo.labels = wbcg_undo_redo_labels;
wbc_class->undo_redo.clear = wbcg_undo_redo_clear;
wbc_class->undo_redo.truncate = wbcg_undo_redo_truncate;
wbc_class->undo_redo.pop = wbcg_undo_redo_pop;
wbc_class->undo_redo.push = wbcg_undo_redo_push;
wbc_class->undo_redo.labels = wbcg_undo_redo_labels;
wbc_class->paste.special_enable = wbcg_paste_special_enable;
wbc_class->paste.from_selection = wbcg_paste_from_selection;
......
......@@ -34,6 +34,7 @@ typedef struct {
} sheet;
struct {
void (*clear) (WorkbookControl *wbc, gboolean is_undo);
void (*truncate)(WorkbookControl *wbc, int n, gboolean is_undo);
void (*pop) (WorkbookControl *wbc, gboolean is_undo);
void (*push) (WorkbookControl *wbc,
char const *text, gboolean is_undo);
......
......@@ -84,6 +84,8 @@ WBC_VIRTUAL_FULL (sheet_remove_all, sheet.remove_all,
WBC_VIRTUAL_FULL (undo_redo_clear, undo_redo.clear,
(WorkbookControl *wbc, gboolean is_undo), (wbc, is_undo))
WBC_VIRTUAL_FULL (undo_redo_truncate, undo_redo.truncate,
(WorkbookControl *wbc, int n, gboolean is_undo), (wbc, n, is_undo))
WBC_VIRTUAL_FULL (undo_redo_pop, undo_redo.pop,
(WorkbookControl *wbc, gboolean is_undo), (wbc, is_undo))
WBC_VIRTUAL_FULL (undo_redo_push, undo_redo.push,
......
......@@ -35,6 +35,7 @@ void wb_control_sheet_move (WorkbookControl *wbc, Sheet *sheet,
void wb_control_sheet_remove_all (WorkbookControl *wbc);
void wb_control_undo_redo_clear (WorkbookControl *wbc, gboolean is_undo);
void wb_control_undo_redo_truncate (WorkbookControl *wbc, int n, gboolean is_undo);
void wb_control_undo_redo_pop (WorkbookControl *wbc, gboolean is_undo);
void wb_control_undo_redo_push (WorkbookControl *wbc,
char const *text, gboolean is_undo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment