[geany/geany] a6bbea: Add new function document_show_message()

Matthew Brush git-noreply at xxxxx
Sat May 24 12:47:57 UTC 2014


Branch:      refs/heads/master
Author:      Matthew Brush <matt at geany.org>
Committer:   Thomas Martitz <kugel at rockbox.org>
Date:        Sat, 24 May 2014 12:47:57 UTC
Commit:      a6bbea53c8a7f9e1d278c00eebbc6aa483fee416
             https://github.com/geany/geany/commit/a6bbea53c8a7f9e1d278c00eebbc6aa483fee416

Log Message:
-----------
Add new function document_show_message()


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

Modified: src/document.c
115 lines changed, 114 insertions(+), 1 deletions(-)
===================================================================
@@ -38,6 +38,7 @@
 #include "filetypesprivate.h"
 #include "geany.h" /* FIXME: why is this needed for DOC_FILENAME()? should come from documentprivate.h/document.h */
 #include "geanyobject.h"
+#include "geanywraplabel.h" /* for document_show_message() using GtkInfoBar */
 #include "highlighting.h"
 #include "main.h"
 #include "msgwindow.h"
@@ -74,7 +75,6 @@
 /*#define USE_GIO_FILEMON 1*/
 #include <gio/gio.h>
 
-
 GeanyFilePrefs file_prefs;
 
 
@@ -2989,6 +2989,119 @@ gboolean document_close_all(void)
 }
 
 
+
+/* *
+ * Shows a message related to a document.
+ *
+ * Use this whenever the user needs to see a document-related message,
+ * for example when the file was externally modified or deleted.
+ *
+ * Any of the buttons can be @c NULL.  If not @c NULL, @a btn_1's
+ * @a response_1 response will be the default for the @c GtkInfoBar or
+ * @c GtkDialog.
+ *
+ * @param doc @c GeanyDocument.
+ * @param msgtype The type of message.
+ * @param response_cb A callback function called when there's a response.
+ * @param btn_1 The first action area button.
+ * @param response_1 The response for @a btn_1.
+ * @param btn_2 The second action area button.
+ * @param response_2 The response for @a btn_2.
+ * @param btn_3 The third action area button.
+ * @param response_3 The response for @a btn_3.
+ * @param extra_text Text to show below the main message.
+ * @param format The text format for the main message.
+ * @param ... Used with @a format as in @c printf.
+ *
+ * @since 1.25
+ * */
+static GtkWidget* document_show_message(GeanyDocument *doc, GtkMessageType msgtype,
+	void (*response_cb)(GtkWidget *info_bar, gint response_id, GeanyDocument *doc),
+	const gchar *btn_1, GtkResponseType response_1,
+	const gchar *btn_2, GtkResponseType response_2,
+	const gchar *btn_3, GtkResponseType response_3,
+	const gchar *extra_text, const gchar *format, ...)
+{
+	va_list args;
+	gchar *text, *markup;
+	GtkWidget *hbox, *vbox, *icon, *label, *extra_label, *content_area;
+	GtkWidget *info_widget, *ok_button, *cancel_button, *parent;
+	parent = gtk_notebook_get_nth_page(GTK_NOTEBOOK(main_widgets.notebook),
+                                       document_get_notebook_page(doc));
+
+	va_start(args, format);
+	text = g_strdup_vprintf(format, args);
+	va_end(args);
+
+	markup = g_strdup_printf("<span size=\"larger\">%s</span>", text);
+	g_free(text);
+
+	info_widget = gtk_info_bar_new();
+	/* must be done now else Gtk-WARNING: widget not within a GtkWindow */
+	gtk_box_pack_start(GTK_BOX(parent), info_widget, FALSE, TRUE, 0);
+
+	gtk_info_bar_set_message_type(GTK_INFO_BAR(info_widget), msgtype);
+
+	if (btn_1)
+		gtk_info_bar_add_button(GTK_INFO_BAR(info_widget), btn_1, response_1);
+	if (btn_2)
+		gtk_info_bar_add_button(GTK_INFO_BAR(info_widget), btn_2, response_2);
+	if (btn_3)
+		gtk_info_bar_add_button(GTK_INFO_BAR(info_widget), btn_3, response_3);
+
+	content_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(info_widget));
+
+	label = geany_wrap_label_new(NULL);
+
+	gtk_label_set_markup(GTK_LABEL(label), markup);
+	g_free(markup);
+
+	g_signal_connect(info_widget, "response", G_CALLBACK(response_cb), doc);
+	g_signal_connect_after(info_widget, "response", G_CALLBACK(gtk_widget_destroy), NULL);
+
+	hbox = gtk_hbox_new(FALSE, 12);
+	gtk_container_add(GTK_CONTAINER(content_area), hbox);
+
+	switch (msgtype)
+	{
+		case GTK_MESSAGE_INFO:
+			icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
+			break;
+		case GTK_MESSAGE_WARNING:
+			icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
+			break;
+		case GTK_MESSAGE_QUESTION:
+			icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
+			break;
+		case GTK_MESSAGE_ERROR:
+			icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
+			break;
+		default:
+			icon = NULL;
+			break;
+	}
+
+	if (icon)
+		gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, TRUE, 0);
+
+	if (extra_text)
+	{
+		vbox = gtk_vbox_new(FALSE, 6);
+		extra_label = geany_wrap_label_new(extra_text);
+		gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
+		gtk_box_pack_start(GTK_BOX(vbox), extra_label, TRUE, TRUE, 0);
+		gtk_container_add(GTK_CONTAINER(hbox), vbox);
+	}
+	else
+		gtk_container_add(GTK_CONTAINER(hbox), label);
+
+	gtk_box_reorder_child(GTK_BOX(parent), info_widget, 0);
+
+	gtk_widget_show_all(info_widget);
+
+	return info_widget;
+}
+
 static void monitor_reload_file(GeanyDocument *doc)
 {
 	gchar *base_name = g_path_get_basename(doc->file_name);



--------------
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