From 4b2fcdb0199182c43f007096a29ba59c9c8d6d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 17 Jul 2014 13:24:03 +0200 Subject: Implement modification detection --- editor.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'editor.c') diff --git a/editor.c b/editor.c index d29bc9e..c0ac388 100644 --- a/editor.c +++ b/editor.c @@ -85,6 +85,7 @@ struct Editor { Piece begin, end; /* sentinel nodes which always exists but don't hold any data */ Action *redo, *undo; /* two stacks holding all actions performed to the file */ Action *current_action; /* action holding all file changes until a snapshot is performed */ + Action *saved_action; /* the last action at the time of the save operation */ size_t size; /* current file content size in bytes */ const char *filename; /* filename of which data was loaded */ struct stat info; /* stat as proped on load time */ @@ -411,7 +412,10 @@ int editor_save(Editor *ed, const char *filename) { } if (close(fd) == -1) return -1; - return rename(tmpname, filename); + if (rename(tmpname, filename) == -1) + return -1; + ed->saved_action = ed->undo; + editor_snapshot(ed); err: close(fd); return -1; @@ -591,6 +595,5 @@ void editor_free(Editor *ed) { } bool editor_modified(Editor *ed) { - // TODO: not correct after save - return ed->undo != NULL; + return ed->saved_action != ed->undo; } -- cgit v1.2.3