Merge remote-tracking branch 'origin/master' into dotnet7
This commit is contained in:
@@ -30,7 +30,6 @@ bool LinuxFileSystem::ShowOpenFileDialog(Window* parentWindow, const StringView&
|
||||
const StringAsANSI<> initialDirectoryAnsi(*initialDirectory, initialDirectory.Length());
|
||||
const StringAsANSI<> titleAnsi(*title, title.Length());
|
||||
const char* initDir = initialDirectory.HasChars() ? initialDirectoryAnsi.Get() : ".";
|
||||
char cmd[2048];
|
||||
String xdgCurrentDesktop;
|
||||
StringBuilder fileFilter;
|
||||
Array<String> fileFilterEntries;
|
||||
@@ -39,6 +38,7 @@ bool LinuxFileSystem::ShowOpenFileDialog(Window* parentWindow, const StringView&
|
||||
|
||||
const bool zenitySupported = FileSystem::FileExists(TEXT("/usr/bin/zenity"));
|
||||
const bool kdialogSupported = FileSystem::FileExists(TEXT("/usr/bin/kdialog"));
|
||||
char cmd[2048];
|
||||
if (zenitySupported && (xdgCurrentDesktop != TEXT("KDE") || !kdialogSupported)) // Prefer kdialog when running on KDE
|
||||
{
|
||||
for (int32 i = 1; i < fileFilterEntries.Count(); i += 2)
|
||||
@@ -87,6 +87,51 @@ bool LinuxFileSystem::ShowOpenFileDialog(Window* parentWindow, const StringView&
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxFileSystem::ShowBrowseFolderDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& title, String& path)
|
||||
{
|
||||
const StringAsANSI<> titleAnsi(*title, title.Length());
|
||||
String xdgCurrentDesktop;
|
||||
Platform::GetEnvironmentVariable(TEXT("XDG_CURRENT_DESKTOP"), xdgCurrentDesktop);
|
||||
|
||||
// TODO: support initialDirectory
|
||||
|
||||
const bool zenitySupported = FileSystem::FileExists(TEXT("/usr/bin/zenity"));
|
||||
const bool kdialogSupported = FileSystem::FileExists(TEXT("/usr/bin/kdialog"));
|
||||
char cmd[2048];
|
||||
if (zenitySupported && (xdgCurrentDesktop != TEXT("KDE") || !kdialogSupported)) // Prefer kdialog when running on KDE
|
||||
{
|
||||
sprintf(cmd, "/usr/bin/zenity --modal --file-selection --directory --title=\"%s\" ", titleAnsi.Get());
|
||||
}
|
||||
else if (kdialogSupported)
|
||||
{
|
||||
sprintf(cmd, "/usr/bin/kdialog --getexistingdirectory --title \"%s\" ", titleAnsi.Get());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(Error, "Missing file picker (install zenity or kdialog).");
|
||||
return true;
|
||||
}
|
||||
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++;
|
||||
path = String(start, (int32)(c - start));
|
||||
if (path.HasChars())
|
||||
break;
|
||||
c++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxFileSystem::ShowFileExplorer(const StringView& path)
|
||||
{
|
||||
const StringAsANSI<> pathAnsi(*path, path.Length());
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
|
||||
// [FileSystemBase]
|
||||
static bool ShowOpenFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, Array<String, HeapAllocation>& filenames);
|
||||
static bool ShowBrowseFolderDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& title, String& path);
|
||||
static bool ShowFileExplorer(const StringView& path);
|
||||
static bool CreateDirectory(const StringView& path);
|
||||
static bool DeleteDirectory(const String& path, bool deleteContents = true);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define LINUXINPUT_MAX_GAMEPAD_EVENTS_PER_FRAME 32
|
||||
#define TRIGGER_THRESHOLD 1000
|
||||
|
||||
class LinuxGamepad : public Gamepad
|
||||
class FLAXENGINE_API LinuxGamepad : public Gamepad
|
||||
{
|
||||
public:
|
||||
int fd;
|
||||
|
||||
@@ -2759,6 +2759,30 @@ Window* LinuxPlatform::CreateWindow(const CreateWindowSettings& settings)
|
||||
return New<LinuxWindow>(settings);
|
||||
}
|
||||
|
||||
extern char **environ;
|
||||
|
||||
void LinuxPlatform::GetEnvironmentVariables(Dictionary<String, String, HeapAllocation>& result)
|
||||
{
|
||||
char **s = environ;
|
||||
for (; *s; s++)
|
||||
{
|
||||
char* var = *s;
|
||||
int32 split = -1;
|
||||
for (int32 i = 0; var[i]; i++)
|
||||
{
|
||||
if (var[i] == '=')
|
||||
{
|
||||
split = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (split == -1)
|
||||
result[String(var)] = String::Empty;
|
||||
else
|
||||
result[String(var, split)] = String(var + split + 1);
|
||||
}
|
||||
}
|
||||
|
||||
bool LinuxPlatform::GetEnvironmentVariable(const String& name, String& value)
|
||||
{
|
||||
char* env = getenv(StringAsANSI<>(*name).Get());
|
||||
|
||||
@@ -131,6 +131,7 @@ public:
|
||||
static String GetWorkingDirectory();
|
||||
static bool SetWorkingDirectory(const String& path);
|
||||
static Window* CreateWindow(const CreateWindowSettings& settings);
|
||||
static void GetEnvironmentVariables(Dictionary<String, String, HeapAllocation>& result);
|
||||
static bool GetEnvironmentVariable(const String& name, String& value);
|
||||
static bool SetEnvironmentVariable(const String& name, const String& value);
|
||||
static int32 StartProcess(const StringView& filename, const StringView& args, const StringView& workingDir, bool hiddenWindow = false, bool waitForEnd = false);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/// <summary>
|
||||
/// Thread object for Linux platform.
|
||||
/// </summary>
|
||||
class LinuxThread : public UnixThread
|
||||
class FLAXENGINE_API LinuxThread : public UnixThread
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/// <summary>
|
||||
/// Implementation of the window class for Linux platform.
|
||||
/// </summary>
|
||||
class LinuxWindow : public WindowBase
|
||||
class FLAXENGINE_API LinuxWindow : public WindowBase
|
||||
{
|
||||
friend LinuxPlatform;
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user