From 9155106cea10e2bda520fc20564384a6ba9a336a Mon Sep 17 00:00:00 2001 From: Jayson R. King Date: Sat, 30 Jul 2011 22:14:54 -0500 Subject: [PATCH] fix bug 2730: Undo allows an altered document to be closed without warning about saving --- src/undo.c | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/undo.c b/src/undo.c index a878849..7384327 100644 --- a/src/undo.c +++ b/src/undo.c @@ -114,9 +114,8 @@ static void undo_clear_redo_info(void) } /*takes command, offsets and a string, and builds a UndoInfo object, which -we stuff into the undo_list. Note that you can't set ->seq this way. -Also (FIXME) we have no use for the buffer passed to us*/ -static void undo_append_undo_info(GtkTextBuffer *buffer, gint command, gint start, gint end, gchar *str) +we stuff into the undo_list. Note that you can't set ->seq this way.*/ +static void undo_append_undo_info(gint command, gint start, gint end, gchar *str) { UndoInfo *ui = g_malloc(sizeof(UndoInfo)); @@ -211,7 +210,7 @@ static void undo_create_undo_info(GtkTextBuffer *buffer, gint command, gint star gtk_widget_set_sensitive(redo_menu_item, FALSE); return; } - undo_append_undo_info(buffer, ui_tmp->command, ui_tmp->start, ui_tmp->end, g_strdup(undo_gstr->str)); + undo_append_undo_info(ui_tmp->command, ui_tmp->start, ui_tmp->end, g_strdup(undo_gstr->str)); undo_gstr = g_string_erase(undo_gstr, 0, -1); } @@ -224,7 +223,7 @@ static void undo_create_undo_info(GtkTextBuffer *buffer, gint command, gint star undo_gstr = g_string_erase(undo_gstr, 0, -1); g_string_append(undo_gstr, str); } else - undo_append_undo_info(buffer, command, start, end, g_strdup(str)); + undo_append_undo_info(command, start, end, g_strdup(str)); DV(g_print("undo_create_undo_info: ui_tmp->command: %d", ui_tmp->command)); undo_clear_redo_info(); prev_keyval = keyval; @@ -295,9 +294,14 @@ static void cb_modified_changed(void) /*I'm this is only called by init, and when we save. We call it from the save call back, so that we can properly handle the asterisk in the titlebar and warn that the document is altered after a save, but -retain the undo history. The leads to (FIXME) bug 2730*/ +retain the undo history.*/ void undo_reset_step_modif(void) { + if (undo_gstr->len) { /* fix bug 2730 */ +DV(g_print("undo_reset_step_modif: ui_tmp->command %d", ui_tmp->command)); + undo_append_undo_info(ui_tmp->command, ui_tmp->start, ui_tmp->end, g_strdup(undo_gstr->str)); + undo_gstr = g_string_erase(undo_gstr, 0, -1); + } step_modif = g_trash_stack_height(&undo_stack); DV(g_print("undo_reset_step_modif: Reseted step_modif by %d\n", step_modif)); } @@ -340,7 +344,6 @@ void undo_init(GtkWidget *textview, GtkTextBuffer *buffer, GtkWidget *menubar) undo_clear_undo_info(); if (redo_stack != NULL) undo_clear_redo_info(); - undo_reset_step_modif(); DV(g_print("undo_init: list reseted\n")); /*This is retarded*/ @@ -365,6 +368,7 @@ DV(g_print("undo_init: list reseted\n")); /*Not sure why we do this here, and not in the insert callback*/ ui_tmp->command = INS; undo_gstr = g_string_erase(undo_gstr, 0, -1); + undo_reset_step_modif(); } /*Straight forward. When performing the undo/redo, we don't want our @@ -432,7 +436,7 @@ void undo_undo(GtkTextBuffer *buffer) if (undo_gstr->len) { DV(g_print("undo_undo_real: ui_tmp->command %d", ui_tmp->command)); - undo_append_undo_info(buffer, ui_tmp->command, ui_tmp->start, ui_tmp->end, g_strdup(undo_gstr->str)); + undo_append_undo_info(ui_tmp->command, ui_tmp->start, ui_tmp->end, g_strdup(undo_gstr->str)); undo_gstr = g_string_erase(undo_gstr, 0, -1); } if ((g_trash_stack_peek(&undo_stack)) != NULL) { -- 1.6.0.6