1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 04:37:44 +00:00

FileSystemAccessServer: Implement FileTypeFilter to open_file()

This is the same functionality as in FilePicker. It allows the
specification of what file types are allowed.
This commit is contained in:
huttongrabiel 2023-03-17 11:53:43 -07:00 committed by Sam Atkins
parent 106ad6bb13
commit 6a5c561a41
5 changed files with 10 additions and 7 deletions

View file

@ -74,7 +74,7 @@ Result Client::request_file(GUI::Window* parent_window, DeprecatedString const&
return handle_promise(id);
}
Result Client::open_file(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::File::OpenMode requested_access)
Result Client::open_file(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::File::OpenMode requested_access, Optional<Vector<GUI::FileTypeFilter>> const& allowed_file_types)
{
auto const id = get_new_id();
m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
@ -89,7 +89,7 @@ Result Client::open_file(GUI::Window* parent_window, DeprecatedString const& win
GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
});
async_prompt_open_file(id, parent_window_server_client_id, parent_window_id, window_title, path, requested_access);
async_prompt_open_file(id, parent_window_server_client_id, parent_window_id, window_title, path, requested_access, allowed_file_types);
return handle_promise(id);
}

View file

@ -14,6 +14,7 @@
#include <LibCore/File.h>
#include <LibCore/Promise.h>
#include <LibCore/StandardPaths.h>
#include <LibGUI/FileTypeFilter.h>
#include <LibGUI/Window.h>
#include <LibIPC/ConnectionToServer.h>
@ -47,7 +48,7 @@ class Client final
public:
Result request_file_read_only_approved(GUI::Window* parent_window, DeprecatedString const& path);
Result request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::File::OpenMode requested_access);
Result open_file(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::File::OpenMode requested_access = Core::File::OpenMode::Read);
Result open_file(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::File::OpenMode requested_access = Core::File::OpenMode::Read, Optional<Vector<GUI::FileTypeFilter>> const& = {});
Result save_file(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::File::OpenMode requested_access = Core::File::OpenMode::Write | Core::File::OpenMode::Truncate);
static Client& the();