mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 09:37:44 +00:00
LibGUI: Make common locations configurable
This commit is contained in:
parent
fddcaafe5f
commit
91c210c39a
6 changed files with 132 additions and 23 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue