mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibGUI: Add shortcuts to common locations in GUI::FilePicker
This patch adds a handy set of buttons on the left hand side that can take you to common locations such as: - Your home directory - Your desktop directory - The root directory
This commit is contained in:
parent
346e0f4dac
commit
25de655d43
2 changed files with 86 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -43,6 +43,7 @@
|
|||
#include <LibGUI/TextBox.h>
|
||||
#include <LibGUI/ToolBar.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace GUI {
|
||||
|
@ -222,6 +223,22 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& file_
|
|||
on_file_return();
|
||||
}
|
||||
};
|
||||
|
||||
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& 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.on_click = [this, path] {
|
||||
set_path(path);
|
||||
};
|
||||
};
|
||||
add_common_location_button("Home", Core::StandardPaths::home_directory());
|
||||
add_common_location_button("Desktop", Core::StandardPaths::desktop_directory());
|
||||
add_common_location_button("Root", "/");
|
||||
}
|
||||
|
||||
FilePicker::~FilePicker()
|
||||
|
|
|
@ -1,6 +1,36 @@
|
|||
@GUI::Widget {
|
||||
fill_with_background_color: true
|
||||
|
||||
layout: @GUI::HorizontalBoxLayout {
|
||||
margins: [4, 4, 4, 4]
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
shrink_to_fit: true
|
||||
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4, 4, 4, 4]
|
||||
}
|
||||
|
||||
@GUI::Label {
|
||||
text: "Look in:"
|
||||
text_alignment: "CenterRight"
|
||||
fixed_height: 24
|
||||
}
|
||||
|
||||
@GUI::Frame {
|
||||
name: "common_locations_frame"
|
||||
fixed_width: 80
|
||||
fill_with_background_color: true
|
||||
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [2, 4, 2, 4]
|
||||
spacing: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4, 4, 4, 4]
|
||||
}
|
||||
|
@ -32,13 +62,14 @@
|
|||
|
||||
@GUI::Widget {
|
||||
fixed_height: 24
|
||||
|
||||
layout: @GUI::HorizontalBoxLayout {
|
||||
}
|
||||
|
||||
@GUI::Label {
|
||||
text: "File name:"
|
||||
text_alignment: "CenterLeft"
|
||||
fixed_width:80
|
||||
fixed_width: 80
|
||||
}
|
||||
|
||||
@GUI::TextBox {
|
||||
|
@ -55,6 +86,7 @@
|
|||
fixed_width: 75
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
fixed_height: 24
|
||||
|
||||
|
@ -71,4 +103,5 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue