summaryrefslogtreecommitdiff
path: root/Applications/FileManager
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-23 10:57:42 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-23 11:10:52 +0100
commit3d20da9ee451460b6e233f5efdf5a13e11525f97 (patch)
tree524b72d0874304c68036dbbc0514b632a4a08c59 /Applications/FileManager
parent7ec758773cdd85755d91f52614f361e7e750c7e9 (diff)
downloadserenity-3d20da9ee451460b6e233f5efdf5a13e11525f97.zip
Userspace: Use Core::Object::add() when building interfaces
Diffstat (limited to 'Applications/FileManager')
-rw-r--r--Applications/FileManager/DirectoryView.cpp11
-rw-r--r--Applications/FileManager/DirectoryView.h2
-rw-r--r--Applications/FileManager/PropertiesDialog.cpp32
-rw-r--r--Applications/FileManager/main.cpp24
4 files changed, 34 insertions, 35 deletions
diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp
index c70fd8e215..fb2c6b998e 100644
--- a/Applications/FileManager/DirectoryView.cpp
+++ b/Applications/FileManager/DirectoryView.cpp
@@ -118,18 +118,17 @@ void DirectoryView::handle_activation(const GUI::ModelIndex& index)
}
};
-DirectoryView::DirectoryView(GUI::Widget* parent)
- : GUI::StackWidget(parent)
- , m_model(GUI::FileSystemModel::create())
+DirectoryView::DirectoryView()
+ : m_model(GUI::FileSystemModel::create())
{
set_active_widget(nullptr);
- m_item_view = GUI::ItemView::construct(this);
+ m_item_view = add<GUI::ItemView>();
m_item_view->set_model(model());
- m_columns_view = GUI::ColumnsView::construct(this);
+ m_columns_view = add<GUI::ColumnsView>();
m_columns_view->set_model(model());
- m_table_view = GUI::TableView::construct(this);
+ m_table_view = add<GUI::TableView>();
m_table_view->set_model(GUI::SortingProxyModel::create(m_model));
m_table_view->model()->set_key_column_and_sort_order(GUI::FileSystemModel::Column::Name, GUI::SortOrder::Ascending);
diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h
index 55c31a4084..5992b977f0 100644
--- a/Applications/FileManager/DirectoryView.h
+++ b/Applications/FileManager/DirectoryView.h
@@ -90,7 +90,7 @@ public:
GUI::FileSystemModel& model() { return *m_model; }
private:
- explicit DirectoryView(GUI::Widget* parent);
+ DirectoryView();
const GUI::FileSystemModel& model() const { return *m_model; }
void handle_activation(const GUI::ModelIndex&);
diff --git a/Applications/FileManager/PropertiesDialog.cpp b/Applications/FileManager/PropertiesDialog.cpp
index 83bda32aea..082a819422 100644
--- a/Applications/FileManager/PropertiesDialog.cpp
+++ b/Applications/FileManager/PropertiesDialog.cpp
@@ -52,9 +52,9 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
set_rect({ 0, 0, 360, 420 });
set_resizable(false);
- auto tab_widget = GUI::TabWidget::construct(main_widget);
+ auto tab_widget = main_widget->add<GUI::TabWidget>();
- auto general_tab = GUI::Widget::construct(tab_widget.ptr());
+ auto general_tab = tab_widget->add<GUI::Widget>();
general_tab->set_layout(make<GUI::VerticalBoxLayout>());
general_tab->layout()->set_margins({ 12, 8, 12, 8 });
general_tab->layout()->set_spacing(10);
@@ -62,19 +62,19 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
general_tab->layout()->add_spacer();
- auto file_container = GUI::Widget::construct(general_tab.ptr());
+ auto file_container = general_tab->add<GUI::Widget>();
file_container->set_layout(make<GUI::HorizontalBoxLayout>());
file_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
file_container->layout()->set_spacing(20);
file_container->set_preferred_size(0, 34);
- m_icon = GUI::Label::construct(file_container);
+ m_icon = file_container->add<GUI::Label>();
m_icon->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
m_icon->set_preferred_size(32, 32);
m_name = file_path.basename();
- m_name_box = GUI::TextBox::construct(file_container);
+ m_name_box = file_container->add<GUI::TextBox>();
m_name_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_name_box->set_preferred_size({ 0, 22 });
m_name_box->set_text(m_name);
@@ -132,7 +132,7 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
general_tab->layout()->add_spacer();
- auto button_widget = GUI::Widget::construct(main_widget.ptr());
+ auto button_widget = main_widget->add<GUI::Widget>();
button_widget->set_layout(make<GUI::HorizontalBoxLayout>());
button_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
button_widget->set_preferred_size(0, 24);
@@ -212,24 +212,24 @@ bool PropertiesDialog::apply_changes()
void PropertiesDialog::make_permission_checkboxes(NonnullRefPtr<GUI::Widget>& parent, PermissionMasks masks, String label_string, mode_t mode)
{
- auto widget = GUI::Widget::construct(parent.ptr());
+ auto widget = parent->add<GUI::Widget>();
widget->set_layout(make<GUI::HorizontalBoxLayout>());
widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
widget->set_preferred_size(0, 16);
widget->layout()->set_spacing(10);
- auto label = GUI::Label::construct(label_string, widget);
+ auto label = widget->add<GUI::Label>(label_string);
label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
- auto box_read = GUI::CheckBox::construct("Read", widget);
+ auto box_read = widget->add<GUI::CheckBox>("Read");
box_read->set_checked(mode & masks.read);
box_read->on_checked = [&, masks](bool checked) { permission_changed(masks.read, checked); };
- auto box_write = GUI::CheckBox::construct("Write", widget);
+ auto box_write = widget->add<GUI::CheckBox>("Write");
box_write->set_checked(mode & masks.write);
box_write->on_checked = [&, masks](bool checked) { permission_changed(masks.write, checked); };
- auto box_execute = GUI::CheckBox::construct("Execute", widget);
+ auto box_execute = widget->add<GUI::CheckBox>("Execute");
box_execute->set_checked(mode & masks.execute);
box_execute->on_checked = [&, masks](bool checked) { permission_changed(masks.execute, checked); };
}
@@ -241,17 +241,17 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>
property_labels.ensure_capacity(pairs.size());
for (auto pair : pairs) {
- auto label_container = GUI::Widget::construct(parent.ptr());
+ auto label_container = parent->add<GUI::Widget>();
label_container->set_layout(make<GUI::HorizontalBoxLayout>());
label_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
label_container->set_preferred_size(0, 14);
label_container->layout()->set_spacing(12);
- auto label_property = GUI::Label::construct(pair.property, label_container);
+ auto label_property = label_container->add<GUI::Label>(pair.property);
label_property->set_text_alignment(Gfx::TextAlignment::CenterLeft);
label_property->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
- GUI::Label::construct(pair.value, label_container)->set_text_alignment(Gfx::TextAlignment::CenterLeft);
+ label_container->add<GUI::Label>(pair.value)->set_text_alignment(Gfx::TextAlignment::CenterLeft);
max_width = max(max_width, label_property->font().width(pair.property));
property_labels.append(label_property);
@@ -263,7 +263,7 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>
NonnullRefPtr<GUI::Button> PropertiesDialog::make_button(String text, NonnullRefPtr<GUI::Widget>& parent)
{
- auto button = GUI::Button::construct(text, parent.ptr());
+ auto button = parent->add<GUI::Button>(text);
button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
button->set_preferred_size(70, 22);
return button;
@@ -273,7 +273,7 @@ void PropertiesDialog::make_divider(NonnullRefPtr<GUI::Widget>& parent)
{
parent->layout()->add_spacer();
- auto divider = GUI::Frame::construct(parent.ptr());
+ auto divider = parent->add<GUI::Frame>();
divider->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
divider->set_preferred_size({ 0, 2 });
divider->set_frame_shape(Gfx::FrameShape::HorizontalLine);
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp
index b2ad4e3cd7..f47c33150d 100644
--- a/Applications/FileManager/main.cpp
+++ b/Applications/FileManager/main.cpp
@@ -96,18 +96,18 @@ int main(int argc, char** argv)
widget->set_layout(make<GUI::VerticalBoxLayout>());
widget->layout()->set_spacing(0);
- auto main_toolbar = GUI::ToolBar::construct(widget);
- auto location_toolbar = GUI::ToolBar::construct(widget);
+ auto main_toolbar = widget->add<GUI::ToolBar>();
+ auto location_toolbar = widget->add<GUI::ToolBar>();
location_toolbar->layout()->set_margins({ 6, 3, 6, 3 });
location_toolbar->set_preferred_size(0, 25);
- auto location_label = GUI::Label::construct("Location: ", location_toolbar);
+ auto location_label = location_toolbar->add<GUI::Label>("Location: ");
location_label->size_to_fit();
- auto location_textbox = GUI::TextEditor::construct(GUI::TextEditor::SingleLine, location_toolbar);
+ auto location_textbox = location_toolbar->add<GUI::TextBox>();
- auto splitter = GUI::HorizontalSplitter::construct(widget);
- auto tree_view = GUI::TreeView::construct(splitter);
+ auto splitter = widget->add<GUI::HorizontalSplitter>();
+ auto tree_view = splitter->add<GUI::TreeView>();
auto directories_model = GUI::FileSystemModel::create("/", GUI::FileSystemModel::Mode::DirectoriesOnly);
tree_view->set_model(directories_model);
tree_view->set_column_hidden(GUI::FileSystemModel::Column::Icon, true);
@@ -120,11 +120,11 @@ int main(int argc, char** argv)
tree_view->set_column_hidden(GUI::FileSystemModel::Column::SymlinkTarget, true);
tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
tree_view->set_preferred_size(150, 0);
- auto directory_view = DirectoryView::construct(splitter);
+ auto directory_view = splitter->add<DirectoryView>();
- auto statusbar = GUI::StatusBar::construct(widget);
+ auto statusbar = widget->add<GUI::StatusBar>();
- auto progressbar = GUI::ProgressBar::construct(statusbar);
+ auto progressbar = statusbar->add<GUI::ProgressBar>();
progressbar->set_caption("Generating thumbnails: ");
progressbar->set_format(GUI::ProgressBar::Format::ValueSlashMax);
progressbar->set_visible(false);
@@ -171,7 +171,7 @@ int main(int argc, char** argv)
});
auto mkdir_action = GUI::Action::create("New directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) {
- auto input_box = GUI::InputBox::construct("Enter name:", "New directory", window);
+ auto input_box = window->add<GUI::InputBox>("Enter name:", "New directory");
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) {
auto new_dir_path = canonicalized_path(
String::format("%s/%s",
@@ -325,9 +325,9 @@ int main(int argc, char** argv)
RefPtr<PropertiesDialog> properties;
if (selected.is_empty()) {
- properties = PropertiesDialog::construct(model, path, true, window);
+ properties = window->add<PropertiesDialog>(model, path, true);
} else {
- properties = PropertiesDialog::construct(model, selected.first(), false, window);
+ properties = window->add<PropertiesDialog>(model, selected.first(), false);
}
properties->exec();