FullscreenUI: Use native file selector on Flatpak
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
#include "gpu_device.h"
|
||||
#include "image.h"
|
||||
#include "imgui_animated.h"
|
||||
#include "imgui_manager.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/easing.h"
|
||||
@ -2072,7 +2073,7 @@ void ImGuiFullscreen::PopulateFileSelectorItems()
|
||||
if (s_file_selector_filters.empty() ||
|
||||
std::none_of(s_file_selector_filters.begin(), s_file_selector_filters.end(),
|
||||
[&fd](const std::string& filter) {
|
||||
return StringUtil::WildcardMatch(fd.FileName.c_str(), filter.c_str());
|
||||
return StringUtil::WildcardMatch(fd.FileName.c_str(), filter.c_str(), false);
|
||||
}))
|
||||
{
|
||||
continue;
|
||||
@ -2102,6 +2103,16 @@ bool ImGuiFullscreen::IsFileSelectorOpen()
|
||||
void ImGuiFullscreen::OpenFileSelector(std::string_view title, bool select_directory, FileSelectorCallback callback,
|
||||
FileSelectorFilters filters, std::string initial_directory)
|
||||
{
|
||||
if (initial_directory.empty() || !FileSystem::DirectoryExists(initial_directory.c_str()))
|
||||
initial_directory = FileSystem::GetWorkingDirectory();
|
||||
|
||||
if (Host::ShouldPreferHostFileSelector())
|
||||
{
|
||||
Host::OpenHostFileSelectorAsync(ImGuiManager::StripIconCharacters(title), select_directory, std::move(callback),
|
||||
std::move(filters), initial_directory);
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_file_selector_open)
|
||||
CloseFileSelector();
|
||||
|
||||
@ -2111,8 +2122,6 @@ void ImGuiFullscreen::OpenFileSelector(std::string_view title, bool select_direc
|
||||
s_file_selector_callback = std::move(callback);
|
||||
s_file_selector_filters = std::move(filters);
|
||||
|
||||
if (initial_directory.empty() || !FileSystem::DirectoryExists(initial_directory.c_str()))
|
||||
initial_directory = FileSystem::GetWorkingDirectory();
|
||||
SetFileSelectorDirectory(std::move(initial_directory));
|
||||
QueueResetFocus();
|
||||
}
|
||||
|
||||
@ -314,3 +314,16 @@ void GetChoiceDialogHelpText(SmallStringBase& dest);
|
||||
void GetFileSelectorHelpText(SmallStringBase& dest);
|
||||
void GetInputDialogHelpText(SmallStringBase& dest);
|
||||
} // namespace ImGuiFullscreen
|
||||
|
||||
// Host UI triggers from Big Picture mode.
|
||||
namespace Host {
|
||||
/// Returns true if native file dialogs should be preferred over Big Picture.
|
||||
bool ShouldPreferHostFileSelector();
|
||||
|
||||
/// Opens a file selector dialog.
|
||||
using FileSelectorCallback = std::function<void(const std::string& path)>;
|
||||
using FileSelectorFilters = std::vector<std::string>;
|
||||
void OpenHostFileSelectorAsync(std::string_view title, bool select_directory, FileSelectorCallback callback,
|
||||
FileSelectorFilters filters = FileSelectorFilters(),
|
||||
std::string_view initial_directory = std::string_view());
|
||||
} // namespace Host
|
||||
|
||||
@ -1123,3 +1123,25 @@ void ImGuiManager::SetSoftwareCursorPosition(u32 index, float pos_x, float pos_y
|
||||
sc.pos.first = pos_x;
|
||||
sc.pos.second = pos_y;
|
||||
}
|
||||
|
||||
std::string ImGuiManager::StripIconCharacters(std::string_view str)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(str.length());
|
||||
|
||||
for (size_t offset = 0; offset < str.length();)
|
||||
{
|
||||
char32_t utf;
|
||||
offset += StringUtil::DecodeUTF8(str, offset, &utf);
|
||||
|
||||
// icon if outside BMP/SMP/TIP, or inside private use area
|
||||
if (utf > 0x32FFF || (utf >= 0xE000 && utf <= 0xF8FF))
|
||||
continue;
|
||||
|
||||
StringUtil::EncodeAndAppendUTF8(result, utf);
|
||||
}
|
||||
|
||||
StringUtil::StripWhitespace(&result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -106,6 +106,9 @@ void SetSoftwareCursorPosition(u32 index, float pos_x, float pos_y);
|
||||
|
||||
/// Adds software cursors to ImGui render list.
|
||||
void RenderSoftwareCursors();
|
||||
|
||||
/// Strips icon characters from a string.
|
||||
std::string StripIconCharacters(std::string_view str);
|
||||
} // namespace ImGuiManager
|
||||
|
||||
namespace Host {
|
||||
|
||||
Reference in New Issue
Block a user