Add ShowOpenFileDialog on Linux

This commit is contained in:
mafiesto4
2021-01-10 22:40:07 +01:00
parent 7bbf089e9f
commit 0dc9d3a59a
2 changed files with 29 additions and 0 deletions

View File

@@ -20,6 +20,33 @@
const DateTime UnixEpoch(1970, 1, 1);
bool LinuxFileSystem::ShowOpenFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, Array<String, HeapAllocation>& filenames)
{
const StringAsANSI<> titleAnsi(*title, title.Length());
char cmd[2048];
// TODO: multiSelect support
// TODO: filter support
sprintf(cmd, "/usr/bin/zenity --modal --file-selection --title=\"%s\" ", titleAnsi.Get());
FILE* f = popen(cmd, "r");
char buf[2048];
fgets(buf, ARRAY_COUNT(buf), f);
int result = pclose(f);
if (result != 0)
{
return true;
}
const char* c = buf;
while (*c)
{
const char* start = c;
while (*c != '\n')
c++;
filenames.Add(String(start, (int32)(c - start)));
c++;
}
return false;
}
bool LinuxFileSystem::CreateDirectory(const StringView& path)
{
const StringAsANSI<> pathAnsi(*path, path.Length());

View File

@@ -13,6 +13,8 @@ class FLAXENGINE_API LinuxFileSystem : public FileSystemBase
{
public:
// [FileSystemBase]
static bool ShowOpenFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, Array<String, HeapAllocation>& filenames);
static bool CreateDirectory(const StringView& path);
static bool DeleteDirectory(const String& path, bool deleteContents = true);
static bool DirectoryExists(const StringView& path);