diff --git a/ChangeLog b/ChangeLog index 0b827291..a39f6635 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * src/templates.c, src/document.c, src/filetypes.c: Added new file template for filetype HTML. + * src/document.c, src/dialogs.c: + Don't quit when an error occurs while saving changed files. 2006-09-05 Nick Treleaven diff --git a/src/dialogs.c b/src/dialogs.c index 394a6ac1..3ef39ff8 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -313,10 +313,13 @@ gboolean dialogs_show_unsaved_file(gint idx) case GTK_RESPONSE_YES: { if (doc_list[idx].file_name == NULL) + { dialogs_show_save_as(); + ret = TRUE; + } else - document_save_file(idx, FALSE); - ret = TRUE; + // document_save_file() returns the status if the file could be saved + ret = document_save_file(idx, FALSE); break; } case GTK_RESPONSE_NO: ret = TRUE; break; diff --git a/src/document.c b/src/document.c index ca149939..12316a28 100644 --- a/src/document.c +++ b/src/document.c @@ -676,22 +676,23 @@ gint document_reload_file(gint idx, const gchar *forced_enc) /* This saves the file. - * When force is set then it is always saved, even if it is unchanged(useful when using Save As) */ -void document_save_file(gint idx, gboolean force) + * When force is set then it is always saved, even if it is unchanged(useful when using Save As) + * It returns whether the file could be saved or not. */ +gboolean document_save_file(gint idx, gboolean force) { gchar *data; FILE *fp; gint bytes_written, len; gchar *locale_filename = NULL; - if (idx == -1) return; - if (! force && ! doc_list[idx].changed) return; + if (idx == -1) return FALSE; + if (! force && ! doc_list[idx].changed) return FALSE; if (doc_list[idx].file_name == NULL) { msgwin_status_add(_("Error saving file.")); utils_beep(); - return; + return FALSE; } // replaces tabs by spaces @@ -739,7 +740,7 @@ void document_save_file(gint idx, gboolean force) geany_debug("encoding error: %s)", conv_error->message); g_error_free(conv_error); g_free(data); - return; + return FALSE; } else { @@ -760,7 +761,7 @@ void document_save_file(gint idx, gboolean force) msgwin_status_add(_("Error saving file (%s)."), strerror(errno)); utils_beep(); g_free(data); - return; + return FALSE; } bytes_written = fwrite(data, sizeof (gchar), len, fp); fclose (fp); @@ -771,7 +772,7 @@ void document_save_file(gint idx, gboolean force) { msgwin_status_add(_("Error saving file.")); utils_beep(); - return; + return FALSE; } // ignore the following things if we are quitting @@ -803,6 +804,7 @@ void document_save_file(gint idx, gboolean force) #endif } + return TRUE; } diff --git a/src/document.h b/src/document.h index 6ff495ba..83cead00 100644 --- a/src/document.h +++ b/src/document.h @@ -138,8 +138,9 @@ int document_reload_file(gint idx, const gchar *forced_enc); /* This saves the file. - * When force is set then it is always saved, even if it is unchanged(useful when using Save As) */ -void document_save_file(gint, gboolean force); + * When force is set then it is always saved, even if it is unchanged(useful when using Save As) + * It returns whether the file could be saved or not. */ +gboolean document_save_file(gint idx, gboolean force); /* special search function, used from the find entry in the toolbar */ void document_find_next(gint, const gchar*, gint, gboolean, gboolean);