mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
LibFileSystemAccessClient: Add functions returning FSAC::File
This patch reimplements the now deprecated try_open_file(),
try_request_file() and try_request_file_read_only_approved() functions,
with the difference that the new ones return a FSAC::File object
(currently a wrapper with a Core::Stream and a filename) instead of a
Core::File.
Implemented in a similar manner to 6dd716adf2
.
This commit is contained in:
parent
2cbe2dd3c0
commit
86f6586c6e
2 changed files with 73 additions and 0 deletions
|
@ -48,6 +48,31 @@ DeprecatedResult Client::try_request_file_read_only_approved_deprecated(GUI::Win
|
||||||
return handle_promise<DeprecatedResult>(id);
|
return handle_promise<DeprecatedResult>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result Client::request_file_read_only_approved(GUI::Window* parent_window, DeprecatedString const& path)
|
||||||
|
{
|
||||||
|
auto const id = get_new_id();
|
||||||
|
m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
|
||||||
|
|
||||||
|
auto parent_window_server_client_id = GUI::ConnectionToWindowServer::the().expose_client_id();
|
||||||
|
auto child_window_server_client_id = expose_window_server_client_id();
|
||||||
|
auto parent_window_id = parent_window->window_id();
|
||||||
|
|
||||||
|
GUI::ConnectionToWindowServer::the().add_window_stealing_for_client(child_window_server_client_id, parent_window_id);
|
||||||
|
|
||||||
|
ScopeGuard guard([parent_window_id, child_window_server_client_id] {
|
||||||
|
GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (path.starts_with('/')) {
|
||||||
|
async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, path);
|
||||||
|
} else {
|
||||||
|
auto full_path = LexicalPath::join(Core::File::current_working_directory(), path).string();
|
||||||
|
async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, full_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle_promise<Result>(id);
|
||||||
|
}
|
||||||
|
|
||||||
static Core::Stream::OpenMode to_stream_open_mode(Core::OpenMode open_mode)
|
static Core::Stream::OpenMode to_stream_open_mode(Core::OpenMode open_mode)
|
||||||
{
|
{
|
||||||
Core::Stream::OpenMode result {};
|
Core::Stream::OpenMode result {};
|
||||||
|
@ -96,6 +121,31 @@ DeprecatedResult Client::try_request_file_deprecated(GUI::Window* parent_window,
|
||||||
return handle_promise<DeprecatedResult>(id);
|
return handle_promise<DeprecatedResult>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result Client::request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::Stream::OpenMode mode)
|
||||||
|
{
|
||||||
|
auto const id = get_new_id();
|
||||||
|
m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
|
||||||
|
|
||||||
|
auto parent_window_server_client_id = GUI::ConnectionToWindowServer::the().expose_client_id();
|
||||||
|
auto child_window_server_client_id = expose_window_server_client_id();
|
||||||
|
auto parent_window_id = parent_window->window_id();
|
||||||
|
|
||||||
|
GUI::ConnectionToWindowServer::the().add_window_stealing_for_client(child_window_server_client_id, parent_window_id);
|
||||||
|
|
||||||
|
ScopeGuard guard([parent_window_id, child_window_server_client_id] {
|
||||||
|
GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (path.starts_with('/')) {
|
||||||
|
async_request_file(id, parent_window_server_client_id, parent_window_id, path, mode);
|
||||||
|
} else {
|
||||||
|
auto full_path = LexicalPath::join(Core::File::current_working_directory(), path).string();
|
||||||
|
async_request_file(id, parent_window_server_client_id, parent_window_id, full_path, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle_promise<Result>(id);
|
||||||
|
}
|
||||||
|
|
||||||
DeprecatedResult Client::try_open_file_deprecated(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::OpenMode deprecated_requested_access)
|
DeprecatedResult Client::try_open_file_deprecated(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::OpenMode deprecated_requested_access)
|
||||||
{
|
{
|
||||||
auto const id = get_new_id();
|
auto const id = get_new_id();
|
||||||
|
@ -118,6 +168,26 @@ DeprecatedResult Client::try_open_file_deprecated(GUI::Window* parent_window, De
|
||||||
return handle_promise<DeprecatedResult>(id);
|
return handle_promise<DeprecatedResult>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result Client::open_file(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::Stream::OpenMode requested_access)
|
||||||
|
{
|
||||||
|
auto const id = get_new_id();
|
||||||
|
m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
|
||||||
|
|
||||||
|
auto parent_window_server_client_id = GUI::ConnectionToWindowServer::the().expose_client_id();
|
||||||
|
auto child_window_server_client_id = expose_window_server_client_id();
|
||||||
|
auto parent_window_id = parent_window->window_id();
|
||||||
|
|
||||||
|
GUI::ConnectionToWindowServer::the().add_window_stealing_for_client(child_window_server_client_id, parent_window_id);
|
||||||
|
|
||||||
|
ScopeGuard guard([parent_window_id, child_window_server_client_id] {
|
||||||
|
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);
|
||||||
|
|
||||||
|
return handle_promise<Result>(id);
|
||||||
|
}
|
||||||
|
|
||||||
DeprecatedResult Client::try_save_file_deprecated(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode deprecated_requested_access)
|
DeprecatedResult Client::try_save_file_deprecated(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode deprecated_requested_access)
|
||||||
{
|
{
|
||||||
auto const id = get_new_id();
|
auto const id = get_new_id();
|
||||||
|
|
|
@ -51,6 +51,9 @@ public:
|
||||||
DeprecatedResult try_open_file_deprecated(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::OpenMode requested_access = Core::OpenMode::ReadOnly);
|
DeprecatedResult try_open_file_deprecated(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::OpenMode requested_access = Core::OpenMode::ReadOnly);
|
||||||
DeprecatedResult try_save_file_deprecated(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode requested_access = Core::OpenMode::WriteOnly | Core::OpenMode::Truncate);
|
DeprecatedResult try_save_file_deprecated(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode requested_access = Core::OpenMode::WriteOnly | Core::OpenMode::Truncate);
|
||||||
|
|
||||||
|
Result request_file_read_only_approved(GUI::Window* parent_window, DeprecatedString const& path);
|
||||||
|
Result request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::Stream::OpenMode requested_access);
|
||||||
|
Result open_file(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::Stream::OpenMode requested_access = Core::Stream::OpenMode::Read);
|
||||||
Result save_file(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::Stream::OpenMode requested_access = Core::Stream::OpenMode::Write | Core::Stream::OpenMode::Truncate);
|
Result save_file(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::Stream::OpenMode requested_access = Core::Stream::OpenMode::Write | Core::Stream::OpenMode::Truncate);
|
||||||
|
|
||||||
static Client& the();
|
static Client& the();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue