[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[PATCH] partial undo implementation
- From: Martin Sheppard <shepp camtech net au>
- To: gnumeric-list gnome org
- Subject: [PATCH] partial undo implementation
- Date: Wed, 29 Dec 1999 10:33:07 +1000
Hi,
This patch partially implements the undo function in gnumeric. It traps any
changes to a cell in the cell_modified function, makes a copy of the old
cell, and adds it to a list of changes that can be undone. Then by
executing undo, these can be undone one by one. The main problem at the
moment is that many operations make multiple changes to cells in one go. We
would like these to all be undone together, but at the moment this doesn't
happen. The other problem is that it doesn't cater for higher level changes
to the spreadsheet like inserting and deleting rows, changing column widths
and changing styles.
The patch is not really ready to be incorporated into gnumeric, but it may
be useful for any work that is carried out on undo functionality in the
future.
Cheers,
Martin.
diff -rup gnumeric-0.45-clean/src/cell.c gnumeric-0.45-undo/src/cell.c
---
gnumeric-0.45-clean/src/cell.c Sat Nov 20 08:29:00 1999
+++
gnumeric-0.45-undo/src/cell.c Wed Dec 29 09:46:35 1999
@@ -18,6 +18,7 @@
#include "cursors.h"
#include "utils.h"
#include
"gnumeric-util.h"
+#include "workbook.h"
static int
redraws_frozen = 0;
static int redraws_deep_frozen
= 0;
@@ -41,11 +42,21 @@ cell_modified (Cell *cell)
/* Cells from the
clipboard do not have a sheet attached */
if (sheet)
sheet->modified =
TRUE;
+
+ /* if cell->text is NULL then cell isn't initialised properly yet
*/
+ if (cell->text && sheet && sheet->workbook) {
+ UndoInfo *undo =
g_new (UndoInfo, 1);
+ undo->next = sheet->workbook->undolist;
+
undo->newcell = cell;
+ undo->oldcell = cell_copy(cell);
+ undo->oldstyle
= cell_get_mstyle(undo->oldcell);
+ sheet->workbook->undolist = undo;
+ }
}
/* Empty a cell's value, entered_text, and parsed_node. */
-static
void
+void
cell_cleanout (Cell *cell)
{
if (cell->parsed_node){
@@
-345,7 +356,7 @@ cell_set_rendered_text (Cell *cell, cons
g_return_if_fail (cell != NULL);
g_return_if_fail (rendered_text !=
NULL);
- cell_modified (cell);
+ /* cell_modified (cell);*/
oldtext =
cell->text;
cell->text = string_get (rendered_text);
@@ -715,7 +726,7 @@
cell_destroy (Cell *cell)
g_hash_table_remove (cell_hash_queue, cell);
}
- cell_modified (cell);
+ /* cell_modified (cell);*/
cell_cleanout
(cell);
if (cell->render_color)
diff -rup
gnumeric-0.45-clean/src/sheet.c gnumeric-0.45-undo/src/sheet.c
---
gnumeric-0.45-clean/src/sheet.c Sat Dec 4 12:30:11 1999
+++
gnumeric-0.45-undo/src/sheet.c Wed Dec 29 09:46:35 1999
@@ -2039,7 +2039,16
@@ sheet_cell_new (Sheet *sheet, int col, i
cell = g_new0 (Cell, 1);
+ if (sheet && sheet->workbook) {
+ UndoInfo *undo = g_new (UndoInfo,
1);
+ undo->next = sheet->workbook->undolist;
+ undo->newcell = cell;
+
undo->oldcell = NULL;
+ sheet->workbook->undolist = undo;
+ }
+
sheet_cell_add (sheet, cell, col, row);
+
return cell;
}
diff -rup
gnumeric-0.45-clean/src/workbook.c gnumeric-0.45-undo/src/workbook.c
---
gnumeric-0.45-clean/src/workbook.c Sat Dec 4 12:30:11 1999
+++
gnumeric-0.45-undo/src/workbook.c Wed Dec 29 09:48:10 1999
@@ -540,8
+540,39 @@ quit_cmd (void)
}
static void
+do_undo (Workbook *wb)
+{
+
UndoInfo *undoinfo = wb->undolist;
+ Cell *newcell, *oldcell;
+
+ if
(undoinfo == NULL) return;
+ wb->undolist = undoinfo->next;
+
+ oldcell =
undoinfo->oldcell;
+ newcell = undoinfo->newcell;
+
+ if (oldcell == NULL)
{
+ sheet_cell_remove(newcell->sheet, newcell);
+ } else {
+ /*
+ *
need to dispose of all resources used by newcell here
+ * to avoid memory
leak.
+ */
+
+ *newcell = *oldcell;
+ cell_set_mstyle(newcell,
undoinfo->oldstyle);
+ g_free(undoinfo);
+ cell_queue_redraw(newcell);
+
cell_content_changed(newcell);
+ }
+}
+
+static void
undo_cmd (GtkWidget
*widget, Workbook *wb)
{
+ do_undo(wb);
+ workbook_recalc(wb);
+
#if 0
/* Disable until they are read for prime time */
workbook_undo (wb);
@@
-2041,6 +2072,7 @@ workbook_new (void)
wb = gtk_type_new
(workbook_get_type ());
wb->toplevel = gnome_app_new ("Gnumeric",
"Gnumeric");
wb->table = gtk_table_new (0, 0, 0);
+ wb->undolist =
NULL;
gtk_window_set_policy (GTK_WINDOW (wb->toplevel), 1, 1, 0);
sx
= MAX (gdk_screen_width () - 64, 400);
@@ -2075,7 +2107,7 @@ workbook_new
(void)
wb->menu_item_paste_special = workbook_menu_edit[6].widget;
/*
Disable undo/redo for now */
- gtk_widget_set_sensitive
(wb->menu_item_undo, FALSE);
+ /* gtk_widget_set_sensitive
(wb->menu_item_undo, FALSE);*/
gtk_widget_set_sensitive
(wb->menu_item_redo, FALSE);
/* Disable paste & paste special, they
will be enabled when
diff -rup gnumeric-0.45-clean/src/workbook.h
gnumeric-0.45-undo/src/workbook.h
--- gnumeric-0.45-clean/src/workbook.h
Sat Dec 4 12:30:11 1999
+++ gnumeric-0.45-undo/src/workbook.h Wed Dec 29
09:46:35 1999
@@ -35,6 +35,17 @@ typedef struct _WorkbookPrivate Workbook
/* This must be included after the fwd declarations */
#include "expr.h"
+#include "cell.h"
+
+typedef struct _UndoInfo{
+ Cell *oldcell;
+ MStyle
*oldstyle;
+ Cell *newcell;
+ struct _UndoInfo *next;
+}
UndoInfo;
+
+//typedef struct _UndoIndo UndoInfo;
+
struct _Workbook {
#ifdef ENABLE_BONOBO
/* The base object for the Workbook */
@@ -112,6
+123,8 @@ struct _Workbook {
void *corba_server;
WorkbookPrivate *priv;
+
+ UndoInfo *undolist;
};
typedef struct {
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]