LibGUI: Use MultiView in FilePicker

This allows the user to switch between different view modes.

Fixes #1283.
This commit is contained in:
Andreas Kling 2020-02-24 20:50:21 +01:00
parent 1b2b35cc40
commit a5d7ea24e9
Notes: sideshowbarker 2024-07-19 09:04:52 +09:00
2 changed files with 18 additions and 5 deletions

View file

@ -34,6 +34,7 @@
#include <LibGUI/InputBox.h>
#include <LibGUI/Label.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/MultiView.h>
#include <LibGUI/SortingProxyModel.h>
#include <LibGUI/TextBox.h>
#include <LibGUI/ToolBar.h>
@ -98,15 +99,16 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
auto toolbar = upper_container->add<ToolBar>();
toolbar->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
toolbar->set_preferred_size(85, 0);
toolbar->set_preferred_size(165, 0);
toolbar->set_has_frame(false);
auto location_textbox = upper_container->add<TextBox>();
location_textbox->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
location_textbox->set_preferred_size(0, 20);
m_view = vertical_container->add<TableView>();
m_view = vertical_container->add<MultiView>();
m_view->set_model(SortingProxyModel::create(*m_model));
m_view->set_model_column(FileSystemModel::Column::Name);
m_view->set_column_hidden(FileSystemModel::Column::Owner, true);
m_view->set_column_hidden(FileSystemModel::Column::Group, true);
m_view->set_column_hidden(FileSystemModel::Column::Permissions, true);
@ -146,8 +148,19 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
}
}
});
toolbar->add_action(*mkdir_action);
toolbar->add_separator();
toolbar->add_action(m_view->view_as_icons_action());
toolbar->add_action(m_view->view_as_table_action());
// FIXME: Enable this once GUI::ColumnsView doesn't crash when used here.
#if 0
toolbar->add_action(m_view->view_as_columns_action());
#endif
auto lower_container = vertical_container->add<Widget>();
lower_container->set_layout(make<VerticalBoxLayout>());
lower_container->layout()->set_spacing(4);
@ -172,7 +185,8 @@ FilePicker::FilePicker(Mode mode, const StringView& file_name, const StringView&
on_file_return();
};
m_view->on_selection = [this](auto& index) {
m_view->on_selection_change = [this] {
auto index = m_view->selection().first();
auto& filter_model = (SortingProxyModel&)*m_view->model();
auto local_index = filter_model.map_to_target(index);
const FileSystemModel::Node& node = m_model->node(local_index);

View file

@ -28,7 +28,6 @@
#include <AK/Optional.h>
#include <LibCore/UserInfo.h>
#include <LibGUI/Dialog.h>
#include <LibGUI/TableView.h>
namespace GUI {
@ -67,7 +66,7 @@ private:
}
}
RefPtr<TableView> m_view;
RefPtr<MultiView> m_view;
NonnullRefPtr<FileSystemModel> m_model;
FileSystemPath m_selected_file;