[geany/geany] b487d8: infobars: Do not show reload and resave messages more than once since only the

Thomas Martitz git-noreply at xxxxx
Sat May 24 13:05:14 UTC 2014


Branch:      refs/heads/master
Author:      Thomas Martitz <kugel at rockbox.org>
Committer:   Thomas Martitz <kugel at rockbox.org>
Date:        Sat, 24 May 2014 13:05:14 UTC
Commit:      b487d8dea3c2c3d448431ae91e06470b43d7d6bc
             https://github.com/geany/geany/commit/b487d8dea3c2c3d448431ae91e06470b43d7d6bc

Log Message:
-----------
infobars: Do not show reload and resave messages more than once since only the
last one (respectively) is significant to the user.


Modified Paths:
--------------
    src/document.c
    src/documentprivate.h

Modified: src/document.c
52 lines changed, 36 insertions(+), 16 deletions(-)
===================================================================
@@ -3148,6 +3148,8 @@ static void on_monitor_reload_file_response(GtkWidget *bar, gint response_id, Ge
 
 	if (response_id == GTK_RESPONSE_ACCEPT)
 		document_reload_file(doc, doc->encoding);
+
+	doc->priv->info_bars[MSG_TYPE_RELOAD] = NULL;
 }
 
 
@@ -3155,16 +3157,22 @@ static void monitor_reload_file(GeanyDocument *doc)
 {
 	gchar *base_name = g_path_get_basename(doc->file_name);
 
-	document_show_message(doc, GTK_MESSAGE_QUESTION, on_monitor_reload_file_response,
-		_("_Reload"), GTK_RESPONSE_ACCEPT,
-		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-		NULL, GTK_RESPONSE_NONE,
-		_("Do you want to reload it?"),
-		_("The file '%s' on the disk is more recent than the current buffer."),
-		base_name);
+	/* show this message only once */
+	if (doc->priv->info_bars[MSG_TYPE_RELOAD] == NULL)
+	{
+		GtkWidget *bar;
 
-	protect_document(doc);
+		bar = document_show_message(doc, GTK_MESSAGE_QUESTION, on_monitor_reload_file_response,
+				_("_Reload"), GTK_RESPONSE_ACCEPT,
+				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+				NULL, GTK_RESPONSE_NONE,
+				_("Do you want to reload it?"),
+				_("The file '%s' on the disk is more recent than the current buffer."),
+				base_name);
 
+		protect_document(doc);
+		doc->priv->info_bars[MSG_TYPE_RELOAD] = bar;
+	}
 	g_free(base_name);
 }
 
@@ -3186,20 +3194,31 @@ static void on_monitor_resave_missing_file_response(GtkWidget *bar,
 		/* don't prompt more than once */
 		SETPTR(doc->real_path, NULL);
 	}
+
+	doc->priv->info_bars[MSG_TYPE_RESAVE] = NULL;
 }
 
 
 static void monitor_resave_missing_file(GeanyDocument *doc)
 {
-	document_show_message(doc, GTK_MESSAGE_WARNING, on_monitor_resave_missing_file_response,
-		GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
-		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-		NULL, GTK_RESPONSE_NONE,
-		_("Try to resave the file?"),
-		_("File \"%s\" was not found on disk!"),
-		doc->file_name);
+	GtkWidget *bar;
 
-	protect_document(doc);
+	if (doc->priv->info_bars[MSG_TYPE_RESAVE] == NULL)
+	{
+		GtkWidget *bar;
+
+		bar = document_show_message(doc, GTK_MESSAGE_WARNING,
+				on_monitor_resave_missing_file_response,
+				GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+				NULL, GTK_RESPONSE_NONE,
+				_("Try to resave the file?"),
+				_("File \"%s\" was not found on disk!"),
+				doc->file_name);
+
+		protect_document(doc);
+		doc->priv->info_bars[MSG_TYPE_RESAVE] = bar;
+	}
 }
 
 
@@ -3253,6 +3272,7 @@ gboolean document_check_disk_status(GeanyDocument *doc, gboolean force)
 	}
 	else if (doc->priv->mtime < st.st_mtime)
 	{
+		/* make sure the user is not prompted again after he cancelled the "reload file?" message */
 		doc->priv->mtime = st.st_mtime;
 		monitor_reload_file(doc);
 		/* doc may be closed now */


Modified: src/documentprivate.h
9 lines changed, 9 insertions(+), 0 deletions(-)
===================================================================
@@ -53,6 +53,13 @@ typedef struct FileEncoding
 }
 FileEncoding;
 
+enum
+{
+	MSG_TYPE_RELOAD,
+	MSG_TYPE_RESAVE,
+
+	NUM_MSG_TYPES
+};
 
 /* Private GeanyDocument fields */
 typedef struct GeanyDocumentPrivate
@@ -89,6 +96,8 @@ typedef struct GeanyDocumentPrivate
 	/* Whether it's temoporarily protected (read-only and saving is prevented). Does
 	 * not imply doc->readonly as writable files can be protected */
 	gint			 protected;
+	/* Save pointer to info bars allowing to cancel them programatically (to avoid multiple ones) */
+	GtkWidget		*info_bars[NUM_MSG_TYPES];
 }
 GeanyDocumentPrivate;
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list