From 33d9b592cd5a8a13168fb53eba8f9e5ef5e07fd7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 6 Apr 2021 19:30:37 +0200 Subject: [PATCH] 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. :^) --- Userland/Libraries/LibGUI/FilePicker.cpp | 29 +++++++++++++++---- .../Libraries/LibGUI/FilePickerDialog.gml | 2 +- 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("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(); 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 {