1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

ThemeEditor: Open the FilePicker at the location in the path input

The kernel panic no longer occurs, so we can do this now. :^)
This commit is contained in:
Sam Atkins 2022-04-28 17:17:37 +01:00 committed by Andreas Kling
parent e05d5df6aa
commit 91230ff28d

View file

@ -256,11 +256,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
path_input.set_text(startup_preview_palette.path(Gfx::PathRole::TitleButtonIcons));
path_picker_button.on_click = [&](auto) {
// FIXME: Open at the path_input location. Right now that's panicking the kernel though! :^(
auto role = path_combo_box.model()->index(path_combo_box.selected_index()).data(GUI::ModelRole::Custom).to_path_role();
bool open_folder = (role == Gfx::PathRole::TitleButtonIcons);
auto window_title = String::formatted(open_folder ? "Select {} folder" : "Select {} file", path_combo_box.text());
auto result = GUI::FilePicker::get_open_filepath(window, window_title, "/res/icons", open_folder);
auto target_path = path_input.text();
if (Core::File::exists(target_path)) {
if (!Core::File::is_directory(target_path))
target_path = LexicalPath::dirname(target_path);
} else {
target_path = "/res/icons";
}
auto result = GUI::FilePicker::get_open_filepath(window, window_title, target_path, open_folder);
if (!result.has_value())
return;
path_input.set_text(*result);