diff options
Diffstat (limited to 'src/libui_sdl/libui')
-rw-r--r-- | src/libui_sdl/libui/darwin/stddialogs.m | 4 | ||||
-rw-r--r-- | src/libui_sdl/libui/ui.h | 4 | ||||
-rw-r--r-- | src/libui_sdl/libui/unix/stddialogs.c | 56 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/stddialogs.cpp | 44 |
4 files changed, 94 insertions, 14 deletions
diff --git a/src/libui_sdl/libui/darwin/stddialogs.m b/src/libui_sdl/libui/darwin/stddialogs.m index 57ce959..42cb94c 100644 --- a/src/libui_sdl/libui/darwin/stddialogs.m +++ b/src/libui_sdl/libui/darwin/stddialogs.m @@ -32,7 +32,7 @@ static char *runSavePanel(NSWindow *parent, NSSavePanel *s) return filename; } -char *uiOpenFile(uiWindow *parent) +char *uiOpenFile(uiWindow *parent, char* filter, char* initpath) { NSOpenPanel *o; @@ -46,7 +46,7 @@ char *uiOpenFile(uiWindow *parent) return runSavePanel(windowWindow(parent), o); } -char *uiSaveFile(uiWindow *parent) +char *uiSaveFile(uiWindow *parent, char* filter, char* initpath) { NSSavePanel *s; diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h index 5a2069e..27574a5 100644 --- a/src/libui_sdl/libui/ui.h +++ b/src/libui_sdl/libui/ui.h @@ -265,8 +265,8 @@ _UI_EXTERN uiMenuItem *uiMenuAppendAboutItem(uiMenu *m); _UI_EXTERN void uiMenuAppendSeparator(uiMenu *m); _UI_EXTERN uiMenu *uiNewMenu(const char *name); -_UI_EXTERN char *uiOpenFile(uiWindow *parent); -_UI_EXTERN char *uiSaveFile(uiWindow *parent); +_UI_EXTERN char *uiOpenFile(uiWindow *parent, char* filter, char* initpath); +_UI_EXTERN char *uiSaveFile(uiWindow *parent, char* filter, char* initpath); _UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description); _UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description); 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) diff --git a/src/libui_sdl/libui/windows/stddialogs.cpp b/src/libui_sdl/libui/windows/stddialogs.cpp index 89d26ba..dbd58fe 100644 --- a/src/libui_sdl/libui/windows/stddialogs.cpp +++ b/src/libui_sdl/libui/windows/stddialogs.cpp @@ -16,7 +16,7 @@ #define windowHWND(w) ((HWND) uiControlHandle(uiControl(w))) -char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd) +char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, char* filter, char* initpath, FILEOPENDIALOGOPTIONS optsadd) { IFileDialog *d = NULL; FILEOPENDIALOGOPTIONS opts; @@ -46,6 +46,38 @@ char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOP logHRESULT(L"error setting options", hr); goto out; } + + // filters + { + COMDLG_FILTERSPEC filterspec[8]; + wchar_t _filter[256]; + wchar_t* fp = &_filter[0]; int s = 0; + wchar_t* fname; + for (int i = 0; i < 255; i++) + { + if (filter[i] == '|' || filter[i] == '\0') + { + _filter[i] = '\0'; + if (s & 1) + { + filterspec[s>>1].pszName = fname; + filterspec[s>>1].pszSpec = fp; + } + else + { + fname = fp; + } + fp = &_filter[i+1]; + s++; + if (s >= 8) break; + if (filter[i] == '\0') break; + } + else + _filter[i] = filter[i]; + } + d->SetFileTypes(s>>1, filterspec); + } + hr = d->Show(parent); if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) // cancelled; return NULL like we have ready @@ -76,26 +108,28 @@ out: return name; } -char *uiOpenFile(uiWindow *parent) +char *uiOpenFile(uiWindow *parent, char* filter, char* initpath) { char *res; disableAllWindowsExcept(parent); res = commonItemDialog(windowHWND(parent), CLSID_FileOpenDialog, IID_IFileOpenDialog, - FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); + filter, initpath, + FOS_NOCHANGEDIR | FOS_FORCEFILESYSTEM | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); enableAllWindowsExcept(parent); return res; } -char *uiSaveFile(uiWindow *parent) +char *uiSaveFile(uiWindow *parent, char* filter, char* initpath) { char *res; disableAllWindowsExcept(parent); res = commonItemDialog(windowHWND(parent), CLSID_FileSaveDialog, IID_IFileSaveDialog, - FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_ALLNONSTORAGEITEMS | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); + filter, initpath, + FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_FORCEFILESYSTEM | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_NODEREFERENCELINKS | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); enableAllWindowsExcept(parent); return res; } |