summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-04-06 19:30:37 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-06 21:07:04 +0200
commit33d9b592cd5a8a13168fb53eba8f9e5ef5e07fd7 (patch)
tree22d01049271e3637df63c6c818f2da251eb8c7cc /Userland/Libraries/LibGUI
parent25de655d438b4e275e2a8f776ec5576a2201dc78 (diff)
downloadserenity-33d9b592cd5a8a13168fb53eba8f9e5ef5e07fd7.zip
LibGUI: Make FilePicker's common location buttons checkable
We now use the checked state of these buttons to indicate that you are in that specific folder. The checked state is updated automagically no matter how you navigate the file system. :^)
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/FilePicker.cpp29
-rw-r--r--Userland/Libraries/LibGUI/FilePickerDialog.gml2
2 files changed, 24 insertions, 7 deletions
diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp
index ce7183b39e..022dfcd772 100644
--- a/Userland/Libraries/LibGUI/FilePicker.cpp
+++ b/Userland/Libraries/LibGUI/FilePicker.cpp
@@ -120,8 +120,6 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& file_
m_view->set_column_visible(FileSystemModel::Column::Inode, true);
m_view->set_column_visible(FileSystemModel::Column::SymlinkTarget, true);
- set_path(path);
-
m_model->register_client(*this);
m_location_textbox->on_return_pressed = [this] {
@@ -225,20 +223,39 @@ 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 add_common_location_button = [&](auto& name, String path) {
+ auto add_common_location_button = [&](auto& name, String path) -> GUI::Button& {
auto& button = common_locations_frame.add<GUI::Button>();
button.set_button_style(Gfx::ButtonStyle::CoolBar);
button.set_text_alignment(Gfx::TextAlignment::CenterLeft);
button.set_text(move(name));
button.set_icon(FileIconProvider::icon_for_path(path).bitmap_for_size(16));
button.set_fixed_height(22);
+ button.set_checkable(true);
+ button.set_exclusive(true);
button.on_click = [this, path] {
set_path(path);
};
+ return button;
};
- add_common_location_button("Home", Core::StandardPaths::home_directory());
- add_common_location_button("Desktop", Core::StandardPaths::desktop_directory());
- 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());
+ auto& root_button = add_common_location_button("Root", "/");
+
+ 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);
+ }
+ };
+
+ set_path(path);
}
FilePicker::~FilePicker()
diff --git a/Userland/Libraries/LibGUI/FilePickerDialog.gml b/Userland/Libraries/LibGUI/FilePickerDialog.gml
index 48492e128b..3a0bfd6ac8 100644
--- a/Userland/Libraries/LibGUI/FilePickerDialog.gml
+++ b/Userland/Libraries/LibGUI/FilePickerDialog.gml
@@ -20,7 +20,7 @@
@GUI::Frame {
name: "common_locations_frame"
- fixed_width: 80
+ fixed_width: 90
fill_with_background_color: true
layout: @GUI::VerticalBoxLayout {