Blob Blame History Raw
From b0e10edb322665f5a357d9264bfbc4d759b265ea Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 15 Apr 2016 13:08:54 -0400
Subject: [PATCH] gedit-document: fix close after save functionality

Right now if a document is modified when a user tries
to close the buffer, we pop up a dialog asking if they
would like to save before closing.  If the user says
yes, we proceed to save the document but then fail to
close it.

This is because we try to close the tab before marking
the now saved document as unmodified. The close operation
then fails.

This commit changes the code to set the document unmodified,
earlier, in time for the close tab operation to succeed.
---
 gedit/gedit-document.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index cc59ea1..92c0393 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -1187,76 +1187,76 @@ saved_query_info_cb (GFile         *location,
 	if (info != NULL)
 	{
 		if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
 		{
 			content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
 		}
 
 		if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
 		{
 			g_file_info_get_modification_time (info, &doc->priv->mtime);
 			doc->priv->mtime_set = TRUE;
 		}
 	}
 
 	gedit_document_set_content_type (doc, content_type);
 
 	if (info != NULL)
 	{
 		/* content_type (owned by info) is no longer needed. */
 		g_object_unref (info);
 	}
 
 	g_get_current_time (&doc->priv->time_of_last_save_or_load);
 
 	doc->priv->externally_modified = FALSE;
 	doc->priv->deleted = FALSE;
 	doc->priv->create = FALSE;
 
 	set_readonly (doc, FALSE);
 
-	gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), FALSE);
-
 	save_encoding_metadata (doc);
 
 	/* Async operation finished. */
 	g_object_unref (doc);
 }
 
 static void
 gedit_document_saved_real (GeditDocument *doc)
 {
 	GFile *location = gtk_source_file_get_location (doc->priv->file);
 
 	/* Keep the doc alive during the async operation. */
 	g_object_ref (doc);
 
+	gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), FALSE);
+
 	g_file_query_info_async (location,
 				 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
 				 G_FILE_ATTRIBUTE_TIME_MODIFIED,
 				 G_FILE_QUERY_INFO_NONE,
 				 G_PRIORITY_DEFAULT,
 				 NULL,
 				 (GAsyncReadyCallback) saved_query_info_cb,
 				 doc);
 }
 
 gboolean
 gedit_document_is_untouched (GeditDocument *doc)
 {
 	GFile *location;
 
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE);
 
 	location = gtk_source_file_get_location (doc->priv->file);
 
 	return location == NULL && !gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc));
 }
 
 gboolean
 gedit_document_is_untitled (GeditDocument *doc)
 {
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE);
 
 	return gtk_source_file_get_location (doc->priv->file) == NULL;
 }
 
-- 
2.8.1