Use Zenity to add Linux support

This commit is contained in:
UnknownShadow200 2022-01-19 20:52:36 +11:00
parent a2e6cedf42
commit 8b88d3e575

View File

@ -10,6 +10,7 @@
#include <X11/Xutil.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XInput2.h>
#include <stdio.h>
#ifdef X_HAVE_UTF8_STRING
#define CC_BUILD_XIM
@ -967,7 +968,43 @@ static void ShowDialogCore(const char* title, const char* msg) {
}
cc_result Window_OpenFileDialog(const char* const* filters, OpenFileDialogCallback callback) {
return ERR_NOT_SUPPORTED;
cc_string path; char pathBuffer[1024];
char result[4096] = { 0 };
int len, i;
FILE* fp;
String_InitArray_NT(path, pathBuffer);
String_AppendConst(&path, "zenity --file-selection --file-filter='All supported files (");
for (i = 0; filters[i]; i++)
{
if (i) String_Append(&path, ',');
String_Format1(&path, "*%c", filters[i]);
}
String_AppendConst(&path, ") |");
for (i = 0; filters[i]; i++)
{
String_Format1(&path, " *%c", filters[i]);
}
String_AppendConst(&path, "'");
path.buffer[path.length] = '\0';
/* TODO this doesn't detect when Zenity doesn't exist */
fp = popen(path.buffer, "r");
if (!fp) return 0;
/* result is normally just one string */
while (fgets(result, sizeof(result), fp)) { }
len = String_Length(result);
if (len) {
String_InitArray(path, pathBuffer);
String_AppendUtf8(&path, result, len);
callback(&path);
}
pclose(fp);
return 0;
}
static GC fb_gc;