diff --git a/Userland/Applications/CertificateSettings/CertificateStoreWidget.cpp b/Userland/Applications/CertificateSettings/CertificateStoreWidget.cpp index b19b45aa29..6feddc5ca4 100644 --- a/Userland/Applications/CertificateSettings/CertificateStoreWidget.cpp +++ b/Userland/Applications/CertificateSettings/CertificateStoreWidget.cpp @@ -92,7 +92,7 @@ ErrorOr CertificateStoreModel::add(Vector const& certificat ErrorOr CertificateStoreWidget::import_pem() { - auto fsac_result = FileSystemAccessClient::Client::the().open_file(window(), "Import"); + auto fsac_result = FileSystemAccessClient::Client::the().open_file(window(), { .window_title = "Import"sv }); if (fsac_result.is_error()) return {}; diff --git a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp index 7d3ddf5113..08651372c2 100644 --- a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp @@ -101,7 +101,12 @@ ErrorOr BackgroundSettingsWidget::create_frame() auto& button = *find_descendant_of_type_named("wallpaper_open_button"); button.on_click = [this](auto) { - auto response = FileSystemAccessClient::Client::the().open_file(window(), "Select Wallpaper"sv, "/res/wallpapers"sv, Core::File::OpenMode::Read, { { GUI::FileTypeFilter::image_files(), GUI::FileTypeFilter::all_files() } }); + FileSystemAccessClient::OpenFileOptions options { + .window_title = "Select Wallpaper"sv, + .path = "/res/wallpapers"sv, + .allowed_file_types = { { GUI::FileTypeFilter::image_files(), GUI::FileTypeFilter::all_files() } } + }; + auto response = FileSystemAccessClient::Client::the().open_file(window(), options); if (response.is_error()) return; m_wallpaper_view->selection().clear(); diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index 317a766f60..2fc808e63e 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -133,9 +133,12 @@ ErrorOr MainWidget::create_actions() m_open_action = GUI::CommonActions::make_open_action([this](auto&) { if (!request_close()) return; - auto response = FileSystemAccessClient::Client::the().open_file(window(), "Open", "/res/fonts"sv, Core::File::OpenMode::Read, - { { GUI::FileTypeFilter { "Bitmap Font Files", { { "font" } } }, - GUI::FileTypeFilter::all_files() } }); + FileSystemAccessClient::OpenFileOptions options { + .window_title = "Open"sv, + .path = "/res/fonts"sv, + .allowed_file_types = { { GUI::FileTypeFilter { "Bitmap Font Files", { { "font" } } }, GUI::FileTypeFilter::all_files() } }, + }; + auto response = FileSystemAccessClient::Client::the().open_file(window(), options); if (response.is_error()) return; auto file = response.release_value(); diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index d63d228d22..ebb84b5a6b 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -121,7 +121,7 @@ HexEditorWidget::HexEditorWidget() if (!request_close()) return; - auto response = FileSystemAccessClient::Client::the().open_file(window(), {}, Core::StandardPaths::home_directory(), Core::File::OpenMode::ReadWrite); + auto response = FileSystemAccessClient::Client::the().open_file(window(), { .requested_access = Core::File::OpenMode::ReadWrite }); if (response.is_error()) return; diff --git a/Userland/Applications/ImageViewer/main.cpp b/Userland/Applications/ImageViewer/main.cpp index 54c7f0e259..5867839440 100644 --- a/Userland/Applications/ImageViewer/main.cpp +++ b/Userland/Applications/ImageViewer/main.cpp @@ -121,7 +121,7 @@ ErrorOr serenity_main(Main::Arguments arguments) // Actions auto open_action = GUI::CommonActions::make_open_action( [&](auto&) { - auto result = FileSystemAccessClient::Client::the().open_file(window, "Open Image"); + auto result = FileSystemAccessClient::Client::the().open_file(window, { .window_title = "Open Image"sv }); if (result.is_error()) return; diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index b12423dcde..e8e3168df2 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -455,7 +455,7 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) }))); TRY(m_edit_menu->try_add_action(GUI::Action::create( "&Load Color Palette...", g_icon_bag.load_color_palette, [&](auto&) { - auto response = FileSystemAccessClient::Client::the().open_file(&window, "Load Color Palette"); + auto response = FileSystemAccessClient::Client::the().open_file(&window, { .window_title = "Load Color Palette"sv }); if (response.is_error()) return; diff --git a/Userland/Applications/ThemeEditor/MainWidget.cpp b/Userland/Applications/ThemeEditor/MainWidget.cpp index c1991bee9a..c2f55818b1 100644 --- a/Userland/Applications/ThemeEditor/MainWidget.cpp +++ b/Userland/Applications/ThemeEditor/MainWidget.cpp @@ -242,7 +242,7 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) { if (request_close() == GUI::Window::CloseRequestDecision::StayOpen) return; - auto response = FileSystemAccessClient::Client::the().open_file(&window, "Select Theme", "/res/themes"sv); + auto response = FileSystemAccessClient::Client::the().open_file(&window, { .window_title = "Select Theme"sv, .path = "/res/themes"sv }); if (response.is_error()) return; auto load_from_file_result = load_from_file(response.value().filename(), response.value().release_stream()); diff --git a/Userland/DevTools/GMLPlayground/MainWidget.cpp b/Userland/DevTools/GMLPlayground/MainWidget.cpp index 5b6724ed33..6b2f748cdd 100644 --- a/Userland/DevTools/GMLPlayground/MainWidget.cpp +++ b/Userland/DevTools/GMLPlayground/MainWidget.cpp @@ -161,11 +161,14 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) auto open_action = GUI::CommonActions::make_open_action([&](auto&) { if (request_close() == GUI::Window::CloseRequestDecision::StayOpen) return; - auto response = FileSystemAccessClient::Client::the().open_file(&window, {}, "/usr/src/serenity/Userland/Applications"sv, Core::File::OpenMode::Read, - Vector { + FileSystemAccessClient::OpenFileOptions options { + .path = "/usr/src/serenity/Userland/Applications"sv, + .allowed_file_types = Vector { GUI::FileTypeFilter { "GML Files", { { "gml" } } }, GUI::FileTypeFilter::all_files(), - }); + } + }; + auto response = FileSystemAccessClient::Client::the().open_file(&window, options); if (response.is_error()) return; diff --git a/Userland/Libraries/LibFileSystemAccessClient/Client.cpp b/Userland/Libraries/LibFileSystemAccessClient/Client.cpp index bed4bab1d0..02c8667bcf 100644 --- a/Userland/Libraries/LibFileSystemAccessClient/Client.cpp +++ b/Userland/Libraries/LibFileSystemAccessClient/Client.cpp @@ -63,10 +63,10 @@ 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, Optional> const& allowed_file_types) +Result Client::open_file(GUI::Window* parent_window, OpenFileOptions const& options) { auto const id = get_new_id(); - m_promises.set(id, RequestData { { Core::Promise::construct() }, parent_window, requested_access }); + m_promises.set(id, RequestData { { Core::Promise::construct() }, parent_window, options.requested_access }); auto parent_window_server_client_id = GUI::ConnectionToWindowServer::the().expose_client_id(); auto child_window_server_client_id = expose_window_server_client_id(); @@ -78,7 +78,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, allowed_file_types); + async_prompt_open_file(id, parent_window_server_client_id, parent_window_id, options.window_title, options.path, options.requested_access, options.allowed_file_types); return handle_promise(id); } diff --git a/Userland/Libraries/LibFileSystemAccessClient/Client.h b/Userland/Libraries/LibFileSystemAccessClient/Client.h index 3d9c5cba7f..caf769f4db 100644 --- a/Userland/Libraries/LibFileSystemAccessClient/Client.h +++ b/Userland/Libraries/LibFileSystemAccessClient/Client.h @@ -48,6 +48,13 @@ private: using Result = ErrorOr; +struct OpenFileOptions { + StringView window_title = {}; + DeprecatedString path = Core::StandardPaths::home_directory(); + Core::File::OpenMode requested_access = Core::File::OpenMode::Read; + Optional> allowed_file_types = {}; +}; + class Client final : public IPC::ConnectionToServer , public FileSystemAccessClientEndpoint { @@ -56,7 +63,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, Optional> const& = {}); + Result open_file(GUI::Window* parent_window, OpenFileOptions 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); void set_silence_errors(u32 flags) { m_silenced_errors = flags; }