summary refs log tree commit diff stats
path: root/src/fe-gtk/gtkutil.c
diff options
context:
space:
mode:
authorBerke Viktor <bviktor@hexchat.org>2012-07-21 21:42:48 +0200
committerBerke Viktor <bviktor@hexchat.org>2012-07-21 21:42:48 +0200
commitbc651b0222a41edcbc40b6a26bdc8ecfe4a7f503 (patch)
treec58bf43ab4f13081ab1b25304b6870cef325e7db /src/fe-gtk/gtkutil.c
parent2b3e1f46e36ee0726dcf9d55593cadab9d42fcb1 (diff)
Add extension filter for file dialogs, specify filters and starting folder for loading plugins
Diffstat (limited to 'src/fe-gtk/gtkutil.c')
-rw-r--r--src/fe-gtk/gtkutil.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/fe-gtk/gtkutil.c b/src/fe-gtk/gtkutil.c
index 165f8d4e..e8b47074 100644
--- a/src/fe-gtk/gtkutil.c
+++ b/src/fe-gtk/gtkutil.c
@@ -370,12 +370,15 @@ win32_read_thread (GIOChannel *source, GIOCondition cond, struct file_req *freq)
 #endif	/* native file dialogs */
 
 void
-gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter,
+gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, char *extensions,
 						int flags)
 {
 	struct file_req *freq;
 	GtkWidget *dialog;
+	GtkFileFilter *filefilter;
 	extern char *get_xdir_fs (void);
+	char *token;
+	char *tokenbuffer;
 
 #if 0	/* native file dialogs */
 #ifdef WIN32
@@ -473,6 +476,23 @@ gtkutil_file_req (const char *title, void *callback, void *userdata, char *filte
 			gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), filter);
 	}
 
+	if (flags & FRF_EXTENSIONS && extensions != NULL)
+	{
+		filefilter = gtk_file_filter_new ();
+		tokenbuffer = g_strdup (extensions);
+		token = strtok (tokenbuffer, ";");
+
+		while (token != NULL)
+		{
+			gtk_file_filter_add_pattern (filefilter, token);
+			token = strtok (NULL, ";");
+		}
+
+		g_free (tokenbuffer);
+		gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filefilter);
+		g_free (filefilter);
+	}
+
 	freq = malloc (sizeof (struct file_req));
 	freq->dialog = dialog;
 	freq->flags = flags;