Improve Linux file dialog support

Adds support for multi selection, filtering and initial folder for both zenity and kdialog. kdialog is also preferred over zenity when KDE is detected.
This commit is contained in:
2023-02-03 22:00:50 +02:00
parent d8a9b699ad
commit 0ac5db45d1
4 changed files with 62 additions and 12 deletions

View File

@@ -50,11 +50,16 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(FileSystemBase);
/// </summary>
/// <param name="parentWindow">The parent window or null.</param>
/// <param name="initialDirectory">The initial directory.</param>
/// <param name="filter">The custom filter.</param>
/// <param name="filter">The file filter string as null-terminated pairs of name and list of extensions. Multiple file extensions must be separated with semicolon.</param>
/// <param name="multiSelect">True if allow multiple files to be selected, otherwise use single-file mode.</param>
/// <param name="title">The dialog title.</param>
/// <param name="filenames">The output names of the files picked by the user.</param>
/// <returns>True if failed, otherwise false.</returns>
/// <remarks>
/// Example file filters:
/// "All Files\0*.*"
/// "All Files\0*.*\0Image Files\0*.png;*.jpg"
/// </remarks>
API_FUNCTION() static bool ShowOpenFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, API_PARAM(Out) Array<String, HeapAllocation>& filenames);
/// <summary>
@@ -62,11 +67,16 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(FileSystemBase);
/// </summary>
/// <param name="parentWindow">The parent window.</param>
/// <param name="initialDirectory">The initial directory.</param>
/// <param name="filter">The filter.</param>
/// <param name="filter">The file filter string as null-terminated pairs of name and list of extensions. Multiple file extensions must be separated with semicolon.</param>
/// <param name="multiSelect">True if allow multiple files to be selected, otherwise use single-file mode.</param>
/// <param name="title">The title.</param>
/// <param name="filenames">The output names of the files picked by the user.</param>
/// <returns>True if failed, otherwise false.</returns>
/// <remarks>
/// Example file filters:
/// "All Files\0*.*"
/// "All Files\0*.*\0Image Files\0*.png;*.jpg"
/// </remarks>
API_FUNCTION() static bool ShowSaveFileDialog(Window* parentWindow, const StringView& initialDirectory, const StringView& filter, bool multiSelect, const StringView& title, API_PARAM(Out) Array<String, HeapAllocation>& filenames);
/// <summary>

View File

@@ -528,4 +528,17 @@ String StringUtils::ToString(double value)
return String::Format(TEXT("{}"), value);
}
String StringUtils::GetZZString(const Char* str)
{
const Char* end = str;
while (*end != '\0')
{
end++;
if (*end == '\0')
end++;
}
const int len = end - str;
return String(str, len);
}
#undef STRING_UTILS_ITOSTR_BUFFER_SIZE