Don't quit when an error occurs while saving changed files.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@792 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2006-09-05 18:33:48 +00:00
parent d7951f66d0
commit 5a05227d87
4 changed files with 20 additions and 12 deletions

View File

@ -2,6 +2,8 @@
* src/templates.c, src/document.c, src/filetypes.c: * src/templates.c, src/document.c, src/filetypes.c:
Added new file template for filetype HTML. 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 <nick.treleaven@btinternet.com> 2006-09-05 Nick Treleaven <nick.treleaven@btinternet.com>

View File

@ -313,10 +313,13 @@ gboolean dialogs_show_unsaved_file(gint idx)
case GTK_RESPONSE_YES: case GTK_RESPONSE_YES:
{ {
if (doc_list[idx].file_name == NULL) if (doc_list[idx].file_name == NULL)
{
dialogs_show_save_as(); dialogs_show_save_as();
ret = TRUE;
}
else else
document_save_file(idx, FALSE); // document_save_file() returns the status if the file could be saved
ret = TRUE; ret = document_save_file(idx, FALSE);
break; break;
} }
case GTK_RESPONSE_NO: ret = TRUE; break; case GTK_RESPONSE_NO: ret = TRUE; break;

View File

@ -676,22 +676,23 @@ gint document_reload_file(gint idx, const gchar *forced_enc)
/* This saves the file. /* This saves the file.
* When force is set then it is always saved, even if it is unchanged(useful when using Save As) */ * 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) * It returns whether the file could be saved or not. */
gboolean document_save_file(gint idx, gboolean force)
{ {
gchar *data; gchar *data;
FILE *fp; FILE *fp;
gint bytes_written, len; gint bytes_written, len;
gchar *locale_filename = NULL; gchar *locale_filename = NULL;
if (idx == -1) return; if (idx == -1) return FALSE;
if (! force && ! doc_list[idx].changed) return; if (! force && ! doc_list[idx].changed) return FALSE;
if (doc_list[idx].file_name == NULL) if (doc_list[idx].file_name == NULL)
{ {
msgwin_status_add(_("Error saving file.")); msgwin_status_add(_("Error saving file."));
utils_beep(); utils_beep();
return; return FALSE;
} }
// replaces tabs by spaces // replaces tabs by spaces
@ -739,7 +740,7 @@ void document_save_file(gint idx, gboolean force)
geany_debug("encoding error: %s)", conv_error->message); geany_debug("encoding error: %s)", conv_error->message);
g_error_free(conv_error); g_error_free(conv_error);
g_free(data); g_free(data);
return; return FALSE;
} }
else else
{ {
@ -760,7 +761,7 @@ void document_save_file(gint idx, gboolean force)
msgwin_status_add(_("Error saving file (%s)."), strerror(errno)); msgwin_status_add(_("Error saving file (%s)."), strerror(errno));
utils_beep(); utils_beep();
g_free(data); g_free(data);
return; return FALSE;
} }
bytes_written = fwrite(data, sizeof (gchar), len, fp); bytes_written = fwrite(data, sizeof (gchar), len, fp);
fclose (fp); fclose (fp);
@ -771,7 +772,7 @@ void document_save_file(gint idx, gboolean force)
{ {
msgwin_status_add(_("Error saving file.")); msgwin_status_add(_("Error saving file."));
utils_beep(); utils_beep();
return; return FALSE;
} }
// ignore the following things if we are quitting // ignore the following things if we are quitting
@ -803,6 +804,7 @@ void document_save_file(gint idx, gboolean force)
#endif #endif
} }
return TRUE;
} }

View File

@ -138,8 +138,9 @@ int document_reload_file(gint idx, const gchar *forced_enc);
/* This saves the file. /* This saves the file.
* When force is set then it is always saved, even if it is unchanged(useful when using Save As) */ * 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); * 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 */ /* special search function, used from the find entry in the toolbar */
void document_find_next(gint, const gchar*, gint, gboolean, gboolean); void document_find_next(gint, const gchar*, gint, gboolean, gboolean);