[gnumeric] Doc: track document state instead of tracking dirtiness directly.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Doc: track document state instead of tracking dirtiness directly.
- Date: Sat, 27 Feb 2021 02:40:40 +0000 (UTC)
commit b9bb5d2e8395cb639d939d538955fba7a6bee92f
Author: Morten Welinder <terra gnome org>
Date: Fri Feb 26 21:39:43 2021 -0500
Doc: track document state instead of tracking dirtiness directly.
NEWS | 1 +
configure.ac | 2 +-
src/commands.c | 9 +++------
src/gnm-command-impl.h | 2 +-
src/sheet.c | 2 +-
src/workbook-view.c | 8 +++++++-
src/workbook.c | 16 ++++++++++++----
src/workbook.h | 2 ++
8 files changed, 28 insertions(+), 14 deletions(-)
---
diff --git a/NEWS b/NEWS
index c388a213d..90f33462e 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,7 @@ Morten:
* Dead kitten in css.
* Improve the drawing of filter combos.
* Allow theming of grid color.
+ * Fix dirty-tracking. [#554]
--------------------------------------------------------------------------
Gnumeric 1.12.48
diff --git a/configure.ac b/configure.ac
index 35f627ab3..2e84aa28e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,7 +166,7 @@ PKG_PROG_PKG_CONFIG(0.18)
dnl *****************************
libspreadsheet_reqs="
- libgoffice-${GOFFICE_API_VER} >= 0.10.48
+ libgoffice-${GOFFICE_API_VER} >= 0.10.49
libgsf-1 >= 1.14.33
libxml-2.0 >= 2.4.12
"
diff --git a/src/commands.c b/src/commands.c
index 299cf857a..b4d67ca4c 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -398,8 +398,7 @@ command_undo (WorkbookControl *wbc)
update_after_action (cmd->sheet, wbc);
- if (!cmd->workbook_modified_before_do)
- go_doc_set_dirty (GO_DOC (wb), FALSE);
+ go_doc_set_state (GO_DOC (wb), cmd->state_before_do);
/*
* A few commands clear the undo queue. For those, we do not
@@ -449,8 +448,7 @@ command_redo (WorkbookControl *wbc)
g_object_ref (cmd);
- cmd->workbook_modified_before_do =
- go_doc_is_dirty (wb_control_get_doc (wbc));
+ cmd->state_before_do = go_doc_get_state (wb_control_get_doc (wbc));
/* TRUE indicates a failure to redo. Leave the command where it is */
if (!klass->redo_cmd (cmd, wbc)) {
@@ -720,8 +718,7 @@ gnm_command_push_undo (WorkbookControl *wbc, GObject *obj)
g_return_val_if_fail (wbc != NULL, TRUE);
cmd = GNM_COMMAND (obj);
- cmd->workbook_modified_before_do =
- go_doc_is_dirty (wb_control_get_doc (wbc));
+ cmd->state_before_do = go_doc_get_state (wb_control_get_doc (wbc));
g_return_val_if_fail (cmd != NULL, TRUE);
diff --git a/src/gnm-command-impl.h b/src/gnm-command-impl.h
index fbdbbab21..da1d1a0b0 100644
--- a/src/gnm-command-impl.h
+++ b/src/gnm-command-impl.h
@@ -40,7 +40,7 @@ typedef struct {
char const *cmd_descriptor;
/* State of workbook before the commands was undo. */
- gboolean workbook_modified_before_do;
+ guint64 state_before_do;
} GnmCommand;
typedef gboolean (* UndoCmd) (GnmCommand *self, WorkbookControl *wbc);
diff --git a/src/sheet.c b/src/sheet.c
index 02152f2c2..399645591 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -5169,7 +5169,7 @@ sheet_mark_dirty (Sheet *sheet)
g_return_if_fail (IS_SHEET (sheet));
if (sheet->workbook)
- go_doc_set_dirty (GO_DOC (sheet->workbook), TRUE);
+ workbook_mark_dirty (sheet->workbook);
}
/****************************************************************************/
diff --git a/src/workbook-view.c b/src/workbook-view.c
index a998d6d95..8801c4494 100644
--- a/src/workbook-view.c
+++ b/src/workbook-view.c
@@ -1215,6 +1215,8 @@ workbook_view_save_as (WorkbookView *wbv, GOFileSaver *fs, char const *uri,
if (go_doc_set_uri (GO_DOC (wb), uri)) {
GDateTime *modtime;
+ go_doc_set_saved_state (GO_DOC (wb),
+ go_doc_get_state (GO_DOC (wb)));
go_doc_set_dirty (GO_DOC (wb), FALSE);
/* See 634792. */
go_doc_set_pristine (GO_DOC (wb), FALSE);
@@ -1286,6 +1288,8 @@ workbook_view_save (WorkbookView *wbv, GOCmdContext *context)
if (gnm_debug_flag ("modtime"))
g_printerr ("Modtime set\n");
g_date_time_unref (modtime);
+ go_doc_set_saved_state (GO_DOC (wb),
+ go_doc_get_state (GO_DOC (wb)));
go_doc_set_dirty (GO_DOC (wb), FALSE);
}
if (has_error || has_warning)
@@ -1399,7 +1403,9 @@ workbook_view_new_from_input (GsfInput *input,
workbook_queue_volatile_recalc (new_wb);
workbook_recalc (new_wb);
workbook_update_graphs (new_wb);
- go_doc_set_dirty (GO_DOC (new_wb), FALSE);
+ go_doc_set_saved_state
+ (GO_DOC (new_wb),
+ go_doc_get_state (GO_DOC (new_wb)));
if (uri && workbook_get_file_exporter (new_wb))
workbook_set_last_export_uri
(new_wb, uri);
diff --git a/src/workbook.c b/src/workbook.c
index 8cc57de15..4df508225 100644
--- a/src/workbook.c
+++ b/src/workbook.c
@@ -463,11 +463,19 @@ workbook_new_with_sheets (int sheet_count)
gnm_sheet_suggest_size (&cols, &rows);
while (sheet_count-- > 0)
workbook_sheet_add (wb, -1, cols, rows);
- go_doc_set_dirty (GO_DOC (wb), FALSE);
+ // Restore to pristine state
+ go_doc_set_state (GO_DOC (wb), go_doc_get_saved_state (GO_DOC (wb)));
go_doc_set_pristine (GO_DOC (wb), TRUE);
return wb;
}
+void
+workbook_mark_dirty (Workbook *wb)
+{
+ go_doc_bump_state (GO_DOC (wb));
+}
+
+
/**
* workbook_set_saveinfo:
* @wb: the workbook to modify
@@ -1031,7 +1039,7 @@ workbook_sheet_attach_at_pos (Workbook *wb, Sheet *new_sheet, int pos)
/* Do not signal until after adding the views [#314208] */
post_sheet_index_change (wb);
- go_doc_set_dirty (GO_DOC (wb), TRUE);
+ workbook_mark_dirty (wb);
}
/**
@@ -1159,7 +1167,7 @@ workbook_sheet_delete (Sheet *sheet)
g_object_unref (sheet);
if (!wb->during_destruction)
- go_doc_set_dirty (GO_DOC (wb), TRUE);
+ workbook_mark_dirty (wb);
g_signal_emit (G_OBJECT (wb), signals[SHEET_DELETED], 0);
if (!wb->during_destruction)
@@ -1204,7 +1212,7 @@ workbook_sheet_move (Sheet *sheet, int direction)
post_sheet_index_change (wb);
- go_doc_set_dirty (GO_DOC (wb), TRUE);
+ workbook_mark_dirty (wb);
}
/**
diff --git a/src/workbook.h b/src/workbook.h
index 8fa683e9c..c62d6da23 100644
--- a/src/workbook.h
+++ b/src/workbook.h
@@ -16,6 +16,8 @@ GType workbook_get_type (void);
Workbook *workbook_new (void);
Workbook *workbook_new_with_sheets (int sheet_count);
+void workbook_mark_dirty (Workbook *wb);
+
/* Sheet support routines */
GPtrArray *workbook_sheets (Workbook const *wb);
int workbook_sheet_count (Workbook const *wb);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]