From ba119029ddc71e533d2abaed969e099e5efe37fe Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Wed, 14 Jul 2021 12:04:46 +0200 Subject: [PATCH] LibGUI: Allow to specify FilePicker window position --- Userland/Libraries/LibGUI/FilePicker.cpp | 12 ++++++------ Userland/Libraries/LibGUI/FilePicker.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index cb9f7b9b94..5babccfca7 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -30,9 +30,9 @@ namespace GUI { -Optional FilePicker::get_open_filepath(Window* parent_window, const String& window_title, const StringView& path, bool folder) +Optional FilePicker::get_open_filepath(Window* parent_window, const String& window_title, const StringView& path, bool folder, ScreenPosition screen_position) { - auto picker = FilePicker::construct(parent_window, folder ? Mode::OpenFolder : Mode::Open, "", path); + auto picker = FilePicker::construct(parent_window, folder ? Mode::OpenFolder : Mode::Open, "", path, screen_position); if (!window_title.is_null()) picker->set_title(window_title); @@ -48,9 +48,9 @@ Optional FilePicker::get_open_filepath(Window* parent_window, const Stri return {}; } -Optional FilePicker::get_save_filepath(Window* parent_window, const String& title, const String& extension, const StringView& path) +Optional FilePicker::get_save_filepath(Window* parent_window, const String& title, const String& extension, const StringView& path, ScreenPosition screen_position) { - auto picker = FilePicker::construct(parent_window, Mode::Save, String::formatted("{}.{}", title, extension), path); + auto picker = FilePicker::construct(parent_window, Mode::Save, String::formatted("{}.{}", title, extension), path, screen_position); if (picker->exec() == Dialog::ExecOK) { String file_path = picker->selected_file(); @@ -63,8 +63,8 @@ Optional FilePicker::get_save_filepath(Window* parent_window, const Stri return {}; } -FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filename, const StringView& path) - : Dialog(parent_window) +FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filename, const StringView& path, ScreenPosition screen_position) + : Dialog(parent_window, screen_position) , m_model(FileSystemModel::create(path)) , m_mode(mode) { diff --git a/Userland/Libraries/LibGUI/FilePicker.h b/Userland/Libraries/LibGUI/FilePicker.h index 44858dfcda..4d0a6eb74d 100644 --- a/Userland/Libraries/LibGUI/FilePicker.h +++ b/Userland/Libraries/LibGUI/FilePicker.h @@ -28,8 +28,8 @@ public: Save }; - static Optional get_open_filepath(Window* parent_window, const String& window_title = {}, const StringView& path = Core::StandardPaths::home_directory(), bool folder = false); - static Optional get_save_filepath(Window* parent_window, const String& title, const String& extension, const StringView& path = Core::StandardPaths::home_directory()); + static Optional get_open_filepath(Window* parent_window, const String& window_title = {}, const StringView& path = Core::StandardPaths::home_directory(), bool folder = false, ScreenPosition screen_position = Dialog::ScreenPosition::CenterWithinParent); + static Optional get_save_filepath(Window* parent_window, const String& title, const String& extension, const StringView& path = Core::StandardPaths::home_directory(), ScreenPosition screen_position = Dialog::ScreenPosition::CenterWithinParent); virtual ~FilePicker() override; @@ -43,7 +43,7 @@ private: // ^GUI::ModelClient virtual void model_did_update(unsigned) override; - FilePicker(Window* parent_window, Mode type = Mode::Open, const StringView& filename = "Untitled", const StringView& path = Core::StandardPaths::home_directory()); + FilePicker(Window* parent_window, Mode type = Mode::Open, const StringView& filename = "Untitled", const StringView& path = Core::StandardPaths::home_directory(), ScreenPosition screen_position = Dialog::ScreenPosition::CenterWithinParent); static String ok_button_name(Mode mode) {