diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-09-11 15:56:52 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-09-11 15:56:52 +0200 |
commit | 62a26977c793acde24ffad1f81647c0a4f68ed09 (patch) | |
tree | 17d073431872027c39b9ad7eab8b373b7ef564db /src/libui_sdl/libui/unix | |
parent | 08ed0f3229da2a6feb8bc3080b8e871c79c8d392 (diff) |
libui: primp file picker dialogs
* support for filters, for Windows (tested) and GTK (theoretical)
* add extra parameter for setting the start directory, but not supported yet
Diffstat (limited to 'src/libui_sdl/libui/unix')
-rw-r--r-- | src/libui_sdl/libui/unix/stddialogs.c | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/src/libui_sdl/libui/unix/stddialogs.c b/src/libui_sdl/libui/unix/stddialogs.c index 93302f7..edce773 100644 --- a/src/libui_sdl/libui/unix/stddialogs.c +++ b/src/libui_sdl/libui/unix/stddialogs.c @@ -6,7 +6,7 @@ #define windowWindow(w) (GTK_WINDOW(uiControlHandle(uiControl(w)))) -static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm) +static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm, char* filter, char* initpath) { GtkWidget *fcd; GtkFileChooser *fc; @@ -18,6 +18,52 @@ static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gcha confirm, GTK_RESPONSE_ACCEPT, NULL); fc = GTK_FILE_CHOOSER(fcd); + + // filters + { + gchar _filter[256]; + gchar* fp = &_filter[0]; int s = 0; + gchar* fname; + for (int i = 0; i < 255; i++) + { + if (filter[i] == '|' || filter[i] == '\0') + { + _filter[i] = '\0'; + if (s & 1) + { + GtkFileFilter* filter = gtk_file_filter_new(); + gtk_file_filter_set_name(filter, fname); + + for (gchar* j = fp; ; j++) + { + if (*j == ';') + { + gtk_file_filter_add_pattern(filter, fp); + fp = j+1; + } + else if (*j == '\0') + { + gtk_file_filter_add_pattern(filter, fp); + break; + } + } + + gtk_file_chooser_add_filter(fc, filter); + } + else + { + fname = fp; + } + fp = &_filter[i+1]; + s++; + if (s >= 8) break; + if (filter[i] == '\0') break; + } + else + _filter[i] = filter[i]; + } + } + gtk_file_chooser_set_local_only(fc, FALSE); gtk_file_chooser_set_select_multiple(fc, FALSE); gtk_file_chooser_set_show_hidden(fc, TRUE); @@ -33,14 +79,14 @@ static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gcha return filename; } -char *uiOpenFile(uiWindow *parent) +char *uiOpenFile(uiWindow *parent, char* filter, char* initpath) { - return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open"); + return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", filter, initpath); } -char *uiSaveFile(uiWindow *parent) +char *uiSaveFile(uiWindow *parent, char* filter, char* initpath) { - return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save"); + return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save", filter, initpath); } static void msgbox(GtkWindow *parent, const char *title, const char *description, GtkMessageType type, GtkButtonsType buttons) |