diff options
author | Tom <tomut@yahoo.com> | 2020-07-15 19:52:02 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-16 16:10:21 +0200 |
commit | 6568765e8f89563fa76407ce5e369ec1eb09c125 (patch) | |
tree | ab185f89d668de23ed608a8b11ae5491df3b4d16 | |
parent | 98440889641fcd7d049921146984ca5ec3b957b3 (diff) | |
download | serenity-6568765e8f89563fa76407ce5e369ec1eb09c125.zip |
LibGUI: Add parent window argument to FilePicker functions
Since FilePicker almost always should be modal, add the parent
window as mandatory first argument.
-rw-r--r-- | Applications/DisplaySettings/DisplaySettings.cpp | 2 | ||||
-rw-r--r-- | Applications/DisplaySettings/main.cpp | 1 | ||||
-rw-r--r-- | Applications/FontEditor/main.cpp | 4 | ||||
-rw-r--r-- | Applications/HexEditor/HexEditorWidget.cpp | 4 | ||||
-rw-r--r-- | Applications/KeyboardMapper/main.cpp | 4 | ||||
-rw-r--r-- | Applications/Piano/SamplerWidget.cpp | 2 | ||||
-rw-r--r-- | Applications/Piano/main.cpp | 2 | ||||
-rw-r--r-- | Applications/PixelPaint/main.cpp | 2 | ||||
-rw-r--r-- | Applications/QuickShow/main.cpp | 2 | ||||
-rw-r--r-- | Applications/SoundPlayer/main.cpp | 2 | ||||
-rw-r--r-- | Applications/TextEditor/TextEditorWidget.cpp | 4 | ||||
-rw-r--r-- | DevTools/HackStudio/main.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/FilePicker.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibGUI/FilePicker.h | 10 |
14 files changed, 27 insertions, 26 deletions
diff --git a/Applications/DisplaySettings/DisplaySettings.cpp b/Applications/DisplaySettings/DisplaySettings.cpp index a77a9a66b5..5c26f7156c 100644 --- a/Applications/DisplaySettings/DisplaySettings.cpp +++ b/Applications/DisplaySettings/DisplaySettings.cpp @@ -152,7 +152,7 @@ void DisplaySettingsWidget::create_frame() button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); button.set_preferred_size(22, 22); button.on_click = [this](auto) { - Optional<String> open_path = GUI::FilePicker::get_open_filepath("Select wallpaper from file system."); + Optional<String> open_path = GUI::FilePicker::get_open_filepath(root_widget()->window(), "Select wallpaper from file system."); if (!open_path.has_value()) return; diff --git a/Applications/DisplaySettings/main.cpp b/Applications/DisplaySettings/main.cpp index f125f1afdc..aa6a2c34ad 100644 --- a/Applications/DisplaySettings/main.cpp +++ b/Applications/DisplaySettings/main.cpp @@ -54,6 +54,7 @@ int main(int argc, char** argv) auto instance = DisplaySettingsWidget::construct(); auto window = GUI::Window::construct(); + dbg() << "main window: " << window; window->set_title("Display settings"); window->move_to(100, 100); window->resize(360, 390); diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp index 7f8aa9ac3e..b764050c43 100644 --- a/Applications/FontEditor/main.cpp +++ b/Applications/FontEditor/main.cpp @@ -92,7 +92,7 @@ int main(int argc, char** argv) auto& app_menu = menubar->add_menu("Font Editor"); app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { - Optional<String> open_path = GUI::FilePicker::get_open_filepath(); + Optional<String> open_path = GUI::FilePicker::get_open_filepath(window); if (!open_path.has_value()) return; @@ -112,7 +112,7 @@ int main(int argc, char** argv) app_menu.add_action(GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](auto&) { FontEditorWidget* editor = static_cast<FontEditorWidget*>(window->main_widget()); LexicalPath lexical_path(editor->path()); - Optional<String> save_path = GUI::FilePicker::get_save_filepath(lexical_path.title(), lexical_path.extension()); + Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, lexical_path.title(), lexical_path.extension()); if (!save_path.has_value()) return; diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index eabb7cea67..922ec6481c 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/Applications/HexEditor/HexEditorWidget.cpp @@ -95,7 +95,7 @@ HexEditorWidget::HexEditorWidget() }); m_open_action = GUI::CommonActions::make_open_action([this](auto&) { - Optional<String> open_path = GUI::FilePicker::get_open_filepath(); + Optional<String> open_path = GUI::FilePicker::get_open_filepath(window()); if (!open_path.has_value()) return; @@ -118,7 +118,7 @@ HexEditorWidget::HexEditorWidget() }); m_save_as_action = GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [this](const GUI::Action&) { - Optional<String> save_path = GUI::FilePicker::get_save_filepath(m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "bin" : m_extension); + Optional<String> save_path = GUI::FilePicker::get_save_filepath(window(), m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "bin" : m_extension); if (!save_path.has_value()) return; diff --git a/Applications/KeyboardMapper/main.cpp b/Applications/KeyboardMapper/main.cpp index 77a9070d3d..67e265725d 100644 --- a/Applications/KeyboardMapper/main.cpp +++ b/Applications/KeyboardMapper/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char** argv) // Actions auto open_action = GUI::CommonActions::make_open_action( [&](auto&) { - Optional<String> path = GUI::FilePicker::get_open_filepath("Open"); + Optional<String> path = GUI::FilePicker::get_open_filepath(window, "Open"); if (path.has_value()) { keyboard_mapper_widget->load_from_file(path.value()); } @@ -78,7 +78,7 @@ int main(int argc, char** argv) auto save_as_action = GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](auto&) { String m_name = "Unnamed"; - Optional<String> save_path = GUI::FilePicker::get_save_filepath(m_name, "json"); + Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, m_name, "json"); if (!save_path.has_value()) return; diff --git a/Applications/Piano/SamplerWidget.cpp b/Applications/Piano/SamplerWidget.cpp index e08026453e..bc522754e8 100644 --- a/Applications/Piano/SamplerWidget.cpp +++ b/Applications/Piano/SamplerWidget.cpp @@ -108,7 +108,7 @@ SamplerWidget::SamplerWidget(TrackManager& track_manager) m_open_button->set_focusable(false); m_open_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png")); m_open_button->on_click = [this](auto) { - Optional<String> open_path = GUI::FilePicker::get_open_filepath(); + Optional<String> open_path = GUI::FilePicker::get_open_filepath(window()); if (!open_path.has_value()) return; String error_string = m_track_manager.current_track().set_recorded_sample(open_path.value()); diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp index 0a9782bf37..53ce80d80d 100644 --- a/Applications/Piano/main.cpp +++ b/Applications/Piano/main.cpp @@ -96,7 +96,7 @@ int main(int argc, char** argv) auto& app_menu = menubar->add_menu("Piano"); app_menu.add_action(GUI::Action::create("Export", { Mod_Ctrl, Key_E }, [&](const GUI::Action&) { - save_path = GUI::FilePicker::get_save_filepath("Untitled", "wav"); + save_path = GUI::FilePicker::get_save_filepath(window, "Untitled", "wav"); if (!save_path.has_value()) return; wav_writer.set_file(save_path.value()); diff --git a/Applications/PixelPaint/main.cpp b/Applications/PixelPaint/main.cpp index b51ea389c7..542ffbd336 100644 --- a/Applications/PixelPaint/main.cpp +++ b/Applications/PixelPaint/main.cpp @@ -100,7 +100,7 @@ int main(int argc, char** argv) auto& app_menu = menubar->add_menu("PixelPaint"); app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { - Optional<String> open_path = GUI::FilePicker::get_open_filepath(); + Optional<String> open_path = GUI::FilePicker::get_open_filepath(window); if (!open_path.has_value()) return; diff --git a/Applications/QuickShow/main.cpp b/Applications/QuickShow/main.cpp index cbcc46c0cc..99f28540ea 100644 --- a/Applications/QuickShow/main.cpp +++ b/Applications/QuickShow/main.cpp @@ -126,7 +126,7 @@ int main(int argc, char** argv) // Actions auto open_action = GUI::CommonActions::make_open_action( [&](auto&) { - Optional<String> path = GUI::FilePicker::get_open_filepath("Open image..."); + Optional<String> path = GUI::FilePicker::get_open_filepath(window, "Open image..."); if (path.has_value()) { widget.load_from_file(path.value()); } diff --git a/Applications/SoundPlayer/main.cpp b/Applications/SoundPlayer/main.cpp index 938b259ab5..c90fff2794 100644 --- a/Applications/SoundPlayer/main.cpp +++ b/Applications/SoundPlayer/main.cpp @@ -79,7 +79,7 @@ int main(int argc, char** argv) }); app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { - Optional<String> path = GUI::FilePicker::get_open_filepath("Open wav file..."); + Optional<String> path = GUI::FilePicker::get_open_filepath(window, "Open wav file..."); if (path.has_value()) { player.open_file(path.value()); } diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index a1538c4e8f..c368b73017 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -304,7 +304,7 @@ TextEditorWidget::TextEditorWidget() }); m_open_action = GUI::CommonActions::make_open_action([this](auto&) { - Optional<String> open_path = GUI::FilePicker::get_open_filepath(); + Optional<String> open_path = GUI::FilePicker::get_open_filepath(window()); if (!open_path.has_value()) return; @@ -321,7 +321,7 @@ TextEditorWidget::TextEditorWidget() }); m_save_as_action = GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [this](const GUI::Action&) { - Optional<String> save_path = GUI::FilePicker::get_save_filepath(m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "txt" : m_extension); + Optional<String> save_path = GUI::FilePicker::get_save_filepath(window(), m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "txt" : m_extension); if (!save_path.has_value()) return; diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index 5ed3f1717d..a5ad71be9a 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -222,7 +222,7 @@ int main(int argc, char** argv) }); auto add_existing_file_action = GUI::Action::create("Add existing file to project...", Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), [&](auto&) { - auto result = GUI::FilePicker::get_open_filepath("Add existing file to project"); + auto result = GUI::FilePicker::get_open_filepath(g_window, "Add existing file to project"); if (!result.has_value()) return; auto& filename = result.value(); @@ -425,7 +425,7 @@ int main(int argc, char** argv) }); auto open_action = GUI::Action::create("Open project...", { Mod_Ctrl | Mod_Shift, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), [&](auto&) { - auto open_path = GUI::FilePicker::get_open_filepath("Open project"); + auto open_path = GUI::FilePicker::get_open_filepath(g_window, "Open project"); if (!open_path.has_value()) return; open_project(open_path.value()); diff --git a/Libraries/LibGUI/FilePicker.cpp b/Libraries/LibGUI/FilePicker.cpp index a8ebf4595c..3877df01d8 100644 --- a/Libraries/LibGUI/FilePicker.cpp +++ b/Libraries/LibGUI/FilePicker.cpp @@ -42,9 +42,9 @@ namespace GUI { -Optional<String> FilePicker::get_open_filepath(const String& window_title, Options options) +Optional<String> FilePicker::get_open_filepath(Window* parent_window, const String& window_title, Options options) { - auto picker = FilePicker::construct(Mode::Open, options); + auto picker = FilePicker::construct(parent_window, Mode::Open, options); if (!window_title.is_null()) picker->set_title(window_title); @@ -60,9 +60,9 @@ Optional<String> FilePicker::get_open_filepath(const String& window_title, Optio return {}; } -Optional<String> FilePicker::get_save_filepath(const String& title, const String& extension, Options options) +Optional<String> FilePicker::get_save_filepath(Window* parent_window, const String& title, const String& extension, Options options) { - auto picker = FilePicker::construct(Mode::Save, options, String::format("%s.%s", title.characters(), extension.characters())); + auto picker = FilePicker::construct(parent_window, Mode::Save, options, String::format("%s.%s", title.characters(), extension.characters())); if (picker->exec() == Dialog::ExecOK) { String file_path = picker->selected_file().string(); @@ -75,7 +75,7 @@ Optional<String> FilePicker::get_save_filepath(const String& title, const String return {}; } -FilePicker::FilePicker(Mode mode, Options options, const StringView& file_name, const StringView& path, Window* parent_window) +FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const StringView& file_name, const StringView& path) : Dialog(parent_window) , m_model(FileSystemModel::create()) , m_mode(mode) diff --git a/Libraries/LibGUI/FilePicker.h b/Libraries/LibGUI/FilePicker.h index 7d45819df3..a681ef3c83 100644 --- a/Libraries/LibGUI/FilePicker.h +++ b/Libraries/LibGUI/FilePicker.h @@ -49,12 +49,12 @@ public: DisablePreview = (1 << 0) }; - static Optional<String> get_open_filepath(Options options) + static Optional<String> get_open_filepath(Window* parent_window, Options options) { - return get_open_filepath({}, options); + return get_open_filepath(parent_window, {}, options); } - static Optional<String> get_open_filepath(const String& window_title = {}, Options options = Options::None); - static Optional<String> get_save_filepath(const String& title, const String& extension, Options options = Options::None); + static Optional<String> get_open_filepath(Window* parent_window, const String& window_title = {}, Options options = Options::None); + static Optional<String> get_save_filepath(Window* parent_window, const String& title, const String& extension, Options options = Options::None); static bool file_exists(const StringView& path); virtual ~FilePicker() override; @@ -69,7 +69,7 @@ private: virtual void on_model_update(unsigned) override; - FilePicker(Mode type = Mode::Open, Options = Options::None, const StringView& file_name = "Untitled", const StringView& path = Core::StandardPaths::home_directory(), Window* parent_window = nullptr); + FilePicker(Window* parent_window, Mode type = Mode::Open, Options = Options::None, const StringView& file_name = "Untitled", const StringView& path = Core::StandardPaths::home_directory()); static String ok_button_name(Mode mode) { |