Do not report incorrect value for GeanyDocument:changed when quitting

Fix document_account_for_unsaved() so it does not alter the `changed`
flag on documents, in order for plugins to have a reliable value there
at all times.

Patch by @chrontec with small additional tidying up.

Closes #1857.
This commit is contained in:
Jason Cumbie 2018-05-13 08:48:32 -07:00 committed by Colomban Wendling
parent 5c428b912b
commit 5f38675114
2 changed files with 20 additions and 30 deletions

View File

@ -704,7 +704,8 @@ static gboolean remove_page(guint page_num)
g_return_val_if_fail(doc != NULL, FALSE); g_return_val_if_fail(doc != NULL, FALSE);
if (doc->changed && ! dialogs_show_unsaved_file(doc)) /* if we're closing all, document_account_for_unsaved() has been called already, no need to ask again. */
if (! main_status.closing_all && doc->changed && ! dialogs_show_unsaved_file(doc))
return FALSE; return FALSE;
/* tell any plugins that the document is about to be closed */ /* tell any plugins that the document is about to be closed */
@ -3368,12 +3369,10 @@ GeanyDocument *document_clone(GeanyDocument *old_doc)
} }
/* @note If successful, this should always be followed up with a call to /* @return TRUE if all files were saved or had their changes discarded. */
* document_close_all().
* @return TRUE if all files were saved or had their changes discarded. */
gboolean document_account_for_unsaved(void) gboolean document_account_for_unsaved(void)
{ {
guint i, p, page_count; guint p, page_count;
page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
/* iterate over documents in tabs order */ /* iterate over documents in tabs order */
@ -3387,27 +3386,15 @@ gboolean document_account_for_unsaved(void)
return FALSE; return FALSE;
} }
} }
/* all documents should now be accounted for, so ignore any changes */
foreach_document (i)
{
documents[i]->changed = FALSE;
}
return TRUE; return TRUE;
} }
static void force_close_all(void) static void force_close_all(void)
{ {
guint i, len = documents_array->len; guint i;
/* check all documents have been accounted for */
for (i = 0; i < len; i++)
{
if (documents[i]->is_valid)
{
g_return_if_fail(!documents[i]->changed);
}
}
main_status.closing_all = TRUE; main_status.closing_all = TRUE;
foreach_document(i) foreach_document(i)

View File

@ -1262,16 +1262,20 @@ static void queue_free(GQueue *queue)
} }
static void do_main_quit(void) static gboolean do_main_quit(void)
{ {
geany_debug("Quitting...");
configuration_save(); configuration_save();
if (app->project != NULL) if (app->project != NULL)
project_close(FALSE); /* save project session files */ {
if (!project_close(FALSE)) /* save project session files */
return FALSE;
}
document_close_all(); if (!document_close_all())
return FALSE;
geany_debug("Quitting...");
main_status.quitting = TRUE; main_status.quitting = TRUE;
@ -1364,6 +1368,8 @@ static void do_main_quit(void)
ui_finalize_builder(); ui_finalize_builder();
gtk_main_quit(); gtk_main_quit();
return TRUE;
} }
@ -1389,18 +1395,15 @@ gboolean main_quit(void)
if (! check_no_unsaved()) if (! check_no_unsaved())
{ {
if (document_account_for_unsaved()) if (do_main_quit())
{
do_main_quit();
return TRUE; return TRUE;
} }
}
else else
if (! prefs.confirm_exit || if (! prefs.confirm_exit ||
dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL, dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
_("Do you really want to quit?"))) _("Do you really want to quit?")))
{ {
do_main_quit(); if (do_main_quit())
return TRUE; return TRUE;
} }