Index: src/Makefile.am =================================================================== RCS file: /cvs/gnome/gnumeric/src/Makefile.am,v retrieving revision 1.265 diff -u -p -r1.265 Makefile.am --- src/Makefile.am 2002/02/16 07:15:52 1.265 +++ src/Makefile.am 2002/02/22 23:22:13 @@ -35,6 +41,8 @@ GNUMERIC_BASE = \ auto-format.h \ auto-correct.c \ auto-correct.h \ + auto-save.c \ + auto-save.h \ cell.h \ cell.c \ cell-draw.c \ Index: src/gui-file.c =================================================================== RCS file: /cvs/gnome/gnumeric/src/gui-file.c,v retrieving revision 1.28 diff -u -p -r1.28 gui-file.c --- src/gui-file.c 2002/02/15 05:50:57 1.28 +++ src/gui-file.c 2002/02/22 23:22:14 @@ -125,7 +125,7 @@ gui_file_import (WorkbookControlGUI *wbc file_name = gtk_file_selection_get_filename (fsel); if (fo != NULL) { (void) wb_view_open_custom (wb_control_view (WORKBOOK_CONTROL (wbcg)), - WORKBOOK_CONTROL (wbcg), fo, file_name, TRUE); + WORKBOOK_CONTROL (wbcg), NULL, fo, file_name, TRUE); } gtk_object_destroy (GTK_OBJECT (fsel)); g_list_free (importers); Index: src/main.c =================================================================== RCS file: /cvs/gnome/gnumeric/src/main.c,v retrieving revision 1.157 diff -u -p -r1.157 main.c --- src/main.c 2002/02/15 05:51:07 1.157 +++ src/main.c 2002/02/22 23:22:14 @@ -34,6 +34,7 @@ #include "eval.h" #include "sheet-autofill.h" #include "xml-io.h" +#include "auto-save.h" #include #include @@ -284,6 +285,9 @@ main (int argc, char *argv []) } warn_about_ancient_gnumerics (gnumeric_binary, wbc); + + /* recover from a previously-crashed gnumeric */ + auto_save_check_recover(wb_control_view(wbc), wbc); gtk_main (); } Index: src/workbook-view.c =================================================================== RCS file: /cvs/gnome/gnumeric/src/workbook-view.c,v retrieving revision 1.82 diff -u -p -r1.82 workbook-view.c --- src/workbook-view.c 2002/02/15 05:51:28 1.82 +++ src/workbook-view.c 2002/02/22 23:22:14 @@ -590,13 +585,15 @@ gboolean wb_view_open (WorkbookView *wbv, WorkbookControl *wbc, gchar const *file_name, gboolean display_errors) { - return wb_view_open_custom (wbv, wbc, NULL, file_name, display_errors); + return wb_view_open_custom (wbv, wbc, NULL, NULL, file_name, display_errors); } /** * wb_view_open_custom: * @wbv : Workbook View * @wbc : Workbook Control + * @new_wbc : A place to store the WorkbookControl created by a + * successful load. May be NULL. * @fo : GnumFileOpener object * @file_name : File name * @@ -606,17 +603,24 @@ wb_view_open (WorkbookView *wbv, Workboo */ gboolean wb_view_open_custom (WorkbookView *wbv, WorkbookControl *wbc, + WorkbookControl **new_wbc, GnumFileOpener const *fo, gchar const *file_name, gboolean display_errors) { Workbook *new_wb = NULL; WorkbookView *new_wbv = NULL; + WorkbookControl *ignore; g_return_val_if_fail (IS_WORKBOOK_VIEW (wbv), FALSE); g_return_val_if_fail (IS_WORKBOOK_CONTROL (wbc), FALSE); g_return_val_if_fail (fo == NULL || IS_GNUM_FILE_OPENER (fo), FALSE); g_return_val_if_fail (file_name != NULL, FALSE); + if (new_wbc==NULL) + new_wbc = &ignore; /* we can assume new_wbc is non-null now */ + else + *new_wbc=NULL; /* default value in case of error */ + if (g_file_test (file_name, G_FILE_TEST_IS_REGULAR)) { IOContext *io_context = gnumeric_io_context_new (COMMAND_CONTEXT (wbc)); wb_control_menu_state_sensitivity (wbc, FALSE); @@ -684,8 +688,9 @@ wb_view_open_custom (WorkbookView *wbv, workbook_unref (old_wb); workbook_control_set_view (wbc, new_wbv, NULL); workbook_control_init_state (wbc); + *new_wbc = wbc; } else - (void) wb_control_wrapper_new (wbc, new_wbv, NULL); + *new_wbc = wb_control_wrapper_new (wbc, new_wbv, NULL); workbook_recalc (new_wb); Index: src/workbook-view.h =================================================================== RCS file: /cvs/gnome/gnumeric/src/workbook-view.h,v retrieving revision 1.29 diff -u -p -r1.29 workbook-view.h --- src/workbook-view.h 2002/02/15 05:51:29 1.29 +++ src/workbook-view.h 2002/02/22 23:22:14 @@ -82,6 +83,7 @@ gboolean wb_view_open (WorkbookVi char const *file_name, gboolean display_errors); gboolean wb_view_open_custom (WorkbookView *wbv, WorkbookControl *wbc, + WorkbookControl **new_wbc, GnumFileOpener const *fo, char const *file_name, gboolean display_errors); Index: src/workbook.c =================================================================== RCS file: /cvs/gnome/gnumeric/src/workbook.c,v retrieving revision 1.527 diff -u -p -r1.527 workbook.c --- src/workbook.c 2002/02/21 00:40:37 1.527 +++ src/workbook.c 2002/02/22 23:22:14 @@ -116,6 +116,9 @@ workbook_finalize (GObject *wb_object) wb->priv->during_destruction = TRUE; + /* remove autosave timer & free last_autosave_filename */ + auto_save_destroy(wb); + if (wb->file_saver != NULL) { g_object_weak_unref (G_OBJECT (wb->file_saver), (GWeakNotify) cb_saver_finalize, wb); @@ -224,6 +227,8 @@ workbook_set_dirty (Workbook *wb, gboole wb->summary_info->modified = is_dirty; g_hash_table_foreach (wb->sheet_hash_private, cb_sheet_mark_dirty, GINT_TO_POINTER (is_dirty)); + if (!is_dirty) + auto_save_reset(wb); } static void @@ -429,6 +434,12 @@ workbook_new (void) wb->priv->workbook_views = NULL; wb->priv->persist_file = NULL; #endif + + /* Start up autosave timer. */ + wb->last_autosave_filename = NULL; + wb->autosave_timer_id = 0; + auto_save_reset(wb); + return wb; } @@ -438,7 +449,7 @@ workbook_new (void) * @number: returns the number stripped off in *number * * Gets a name in the form of "Sheet (10)", "Stuff" or "Dummy ((((," - * and returns the real name of the sheet "Sheet","Stuff","Dymmy ((((," + * and returns the real name of the sheet "Sheet","Stuff","Dummy ((((," * without the copy number. **/ static void Index: src/workbook.h =================================================================== RCS file: /cvs/gnome/gnumeric/src/workbook.h,v retrieving revision 1.100 diff -u -p -r1.100 workbook.h --- src/workbook.h 2002/02/21 00:40:37 1.100 +++ src/workbook.h 2002/02/22 23:22:14 @@ -30,6 +30,10 @@ struct _Workbook { FileFormatLevel file_format_level; GnumFileSaver *file_saver; + /* Auto-save support */ + gchar *last_autosave_filename; + guint autosave_timer_id; /* zero if no timer */ + /* Undo support */ GSList *undo_commands; GSList *redo_commands;