summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/FilePicker.cpp
diff options
context:
space:
mode:
authorDexesTTP <dexes.ttp@gmail.com>2021-04-26 18:18:57 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-26 18:57:57 +0200
commit91c210c39a013f57a12202e6d5fc18fad95eac3b (patch)
treeee39637d8b0a9d26c310a4ca609f063b94f0d437 /Userland/Libraries/LibGUI/FilePicker.cpp
parentfddcaafe5f73565acd4c3d70d20a7b56fa7ba0ad (diff)
downloadserenity-91c210c39a013f57a12202e6d5fc18fad95eac3b.zip
LibGUI: Make common locations configurable
Diffstat (limited to 'Userland/Libraries/LibGUI/FilePicker.cpp')
-rw-r--r--Userland/Libraries/LibGUI/FilePicker.cpp35
1 files changed, 12 insertions, 23 deletions
diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp
index 2735817522..1685dcacea 100644
--- a/Userland/Libraries/LibGUI/FilePicker.cpp
+++ b/Userland/Libraries/LibGUI/FilePicker.cpp
@@ -11,6 +11,7 @@
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
+#include <LibGUI/CommonLocationsProvider.h>
#include <LibGUI/FileIconProvider.h>
#include <LibGUI/FilePicker.h>
#include <LibGUI/FilePickerDialogGML.h>
@@ -207,14 +208,20 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& file_
}
};
- auto& common_locations_frame = *widget.find_descendant_of_type_named<GUI::Frame>("common_locations_frame");
+ auto& common_locations_frame = *widget.find_descendant_of_type_named<Frame>("common_locations_frame");
common_locations_frame.set_background_role(Gfx::ColorRole::Tray);
- auto add_common_location_button = [&](auto& name, String path) -> GUI::Button& {
+ m_model->on_complete = [&] {
+ for (auto location_button : m_common_location_buttons)
+ location_button.button.set_checked(m_model->root_path() == location_button.path);
+ };
+
+ for (auto& location : CommonLocationsProvider::common_locations()) {
+ String path = location.path;
auto& button = common_locations_frame.add<GUI::Button>();
button.set_button_style(Gfx::ButtonStyle::Tray);
button.set_foreground_role(Gfx::ColorRole::TrayText);
button.set_text_alignment(Gfx::TextAlignment::CenterLeft);
- button.set_text(move(name));
+ button.set_text(location.name);
button.set_icon(FileIconProvider::icon_for_path(path).bitmap_for_size(16));
button.set_fixed_height(22);
button.set_checkable(true);
@@ -222,26 +229,8 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& file_
button.on_click = [this, path] {
set_path(path);
};
- return button;
- };
-
- auto& root_button = add_common_location_button("Root", "/");
- auto& home_button = add_common_location_button("Home", Core::StandardPaths::home_directory());
- auto& desktop_button = add_common_location_button("Desktop", Core::StandardPaths::desktop_directory());
-
- m_model->on_complete = [&] {
- if (m_model->root_path() == Core::StandardPaths::home_directory()) {
- home_button.set_checked(true);
- } else if (m_model->root_path() == Core::StandardPaths::desktop_directory()) {
- desktop_button.set_checked(true);
- } else if (m_model->root_path() == "/") {
- root_button.set_checked(true);
- } else {
- home_button.set_checked(false);
- desktop_button.set_checked(false);
- root_button.set_checked(false);
- }
- };
+ m_common_location_buttons.append({ path, button });
+ }
set_path(path);
}