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

FileManager+LibGUI: Add a simple location textbox.

The widget layout here is a bit off and needs work.
This commit is contained in:
Andreas Kling 2019-03-03 00:34:40 +01:00
parent 63cdc3d2d5
commit d94abc4f81
5 changed files with 23 additions and 13 deletions

View file

@ -3,6 +3,7 @@
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GStatusBar.h>
#include <LibGUI/GTextBox.h>
#include <LibGUI/GToolBar.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GAction.h>
@ -33,10 +34,17 @@ int main(int argc, char** argv)
auto* widget = new GWidget;
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
auto* toolbar = new GToolBar(widget);
auto* main_toolbar = new GToolBar(widget);
auto* location_toolbar = new GToolBar(widget);
auto* location_textbox = new GTextBox(location_toolbar);
auto* directory_table_view = new DirectoryTableView(widget);
auto* statusbar = new GStatusBar(widget);
location_textbox->on_return_pressed = [directory_table_view] (GTextBox& textbox) {
directory_table_view->open(textbox.text());
};
auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/parentdirectory16.rgb", { 16, 16 }), [directory_table_view] (const GAction&) {
directory_table_view->open_parent_directory();
});
@ -77,13 +85,14 @@ int main(int argc, char** argv)
app.set_menubar(move(menubar));
toolbar->add_action(open_parent_directory_action.copy_ref());
toolbar->add_action(mkdir_action.copy_ref());
toolbar->add_action(copy_action.copy_ref());
toolbar->add_action(delete_action.copy_ref());
main_toolbar->add_action(open_parent_directory_action.copy_ref());
main_toolbar->add_action(mkdir_action.copy_ref());
main_toolbar->add_action(copy_action.copy_ref());
main_toolbar->add_action(delete_action.copy_ref());
directory_table_view->on_path_change = [window] (const String& new_path) {
directory_table_view->on_path_change = [window, location_textbox] (const String& new_path) {
window->set_title(String::format("FileManager: %s", new_path.characters()));
location_textbox->set_text(new_path);
};
directory_table_view->on_status_message = [statusbar] (String message) {

View file

@ -66,7 +66,6 @@ void GBoxLayout::run(GWidget& widget)
dbgprintf("GBoxLayout: automatic_size=%s\n", automatic_size.to_string().characters());
#endif
// FIXME: We should also respect the bottom and right margins.
int current_x = margins().left();
int current_y = margins().top();
@ -77,7 +76,7 @@ void GBoxLayout::run(GWidget& widget)
ASSERT_NOT_REACHED();
}
ASSERT(entry.widget);
rect.set_size(automatic_size);
rect.set_size({ automatic_size.width() - margins().left() - margins().right(), automatic_size.height() - margins().top() - margins().bottom() });
if (entry.widget->size_policy(Orientation::Vertical) == SizePolicy::Fixed)
rect.set_height(entry.widget->preferred_size().height());
if (entry.widget->size_policy(Orientation::Horizontal) == SizePolicy::Fixed)

View file

@ -15,9 +15,11 @@ GTextBox::~GTextBox()
{
}
void GTextBox::set_text(String&& text)
void GTextBox::set_text(const String& text)
{
m_text = move(text);
if (m_text == text)
return;
m_text = text;
m_cursor_position = m_text.length();
update();
}

View file

@ -9,7 +9,7 @@ public:
virtual ~GTextBox() override;
String text() const { return m_text; }
void set_text(String&&);
void set_text(const String&);
Function<void(GTextBox&)> on_return_pressed;
Function<void(GTextBox&)> on_change;

View file

@ -8,10 +8,10 @@ GToolBar::GToolBar(GWidget* parent)
: GWidget(parent)
{
set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
set_preferred_size({ 0, 29 });
set_preferred_size({ 0, 30 });
set_layout(make<GBoxLayout>(Orientation::Horizontal));
layout()->set_spacing(0);
layout()->set_margins({1, 1, 1, 1});
layout()->set_margins({ 2, 2, 2, 2 });
}
GToolBar::~GToolBar()