summaryrefslogtreecommitdiff
path: root/gtkutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'gtkutil.c')
-rw-r--r--gtkutil.c86
1 files changed, 31 insertions, 55 deletions
diff --git a/gtkutil.c b/gtkutil.c
index b5ec30c..cbcf2f4 100644
--- a/gtkutil.c
+++ b/gtkutil.c
@@ -46,8 +46,6 @@ static GtkWidget *dialog;
static int dial_done=FALSE;
static int selected=FALSE;
-static char saved_path[PATH_MAX+1];
-
/* ---------------------------------------- PRIVATE FUNCTIONS
*/
@@ -66,25 +64,6 @@ static gint DestroyCB(GtkWidget *w, GdkEvent *ev, gpointer data)
}
-static gint NoDestroyCB(GtkWidget *w, GdkEvent *ev, gpointer data)
-{
- dial_done=TRUE;
- selected=(int)data;
- return TRUE;
-}
-
-
-static void FselCallback(GtkWidget *w, gpointer data)
-{
- dial_done=TRUE;
- selected=(int)data;
-
- if (selected)
- strcpy(saved_path,
- gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog)));
-}
-
-
/* ---------------------------------------- EXPORTED FUNCTIONS
*/
void DialogParent(GtkWidget *w)
@@ -190,43 +169,40 @@ int DialogYesNo(const char *format, ...)
}
-int DialogFSelect(const char *title, char path[])
+int DialogFSelect(const char *title, const char *filter_name,
+ const char *filter, char path[])
{
- dialog=gtk_file_selection_new(title);
-
- if (path[0])
- gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog),path);
-
- gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION(dialog)->ok_button),
- "clicked",
- GTK_SIGNAL_FUNC (FselCallback),
- (gpointer)1);
+ GtkWidget *fsel;
+ int ret=FALSE;
- gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION(dialog)->cancel_button),
- "clicked",
- GTK_SIGNAL_FUNC (FselCallback),
- (gpointer)0);
-
- gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
- GTK_SIGNAL_FUNC(NoDestroyCB), (gpointer)0);
-
- gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent));
- gtk_window_set_modal(GTK_WINDOW(dialog),TRUE);
- gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ON_PARENT);
+ fsel=gtk_file_chooser_dialog_new(title,
+ GTK_WINDOW(parent),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
- gtk_widget_show(dialog);
-
- dial_done=FALSE;
-
- while(!dial_done)
- gtk_main_iteration();
-
- if (selected)
- strcpy(path,saved_path);
-
- gtk_widget_destroy(dialog);
-
- return selected;
+ if (path[0])
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(fsel),path);
+
+ if (filter_name && filter)
+ {
+ GtkFileFilter *f=gtk_file_filter_new();
+ gtk_file_filter_set_name(GTK_FILE_FILTER(f),filter_name);
+ gtk_file_filter_add_pattern(GTK_FILE_FILTER(f),filter);
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fsel),
+ GTK_FILE_FILTER(f));
+ }
+
+ if (gtk_dialog_run(GTK_DIALOG(fsel))==GTK_RESPONSE_ACCEPT)
+ {
+ strcpy(path,gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fsel)));
+ ret=TRUE;
+ }
+
+ gtk_widget_destroy(fsel);
+
+ return ret;
}