mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:27:34 +00:00
LibCore: Make Core::Object::add<ChildType> return a ChildType&
Since the returned object is now owned by the callee object, we can simply vend a ChildType&. This allows us to use "." instead of "->" at the call site, which is quite nice. :^)
This commit is contained in:
parent
fb09b6a8ce
commit
028c011760
46 changed files with 1035 additions and 1039 deletions
|
@ -68,60 +68,60 @@ int main(int argc, char** argv)
|
|||
outer_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
outer_widget.layout()->set_margins({ 8, 8, 8, 8 });
|
||||
|
||||
auto inner_widget = outer_widget.add<GUI::Widget>();
|
||||
inner_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
inner_widget->layout()->set_spacing(8);
|
||||
auto& inner_widget = outer_widget.add<GUI::Widget>();
|
||||
inner_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
inner_widget.layout()->set_spacing(8);
|
||||
|
||||
auto left_outer_container = inner_widget->add<GUI::Widget>();
|
||||
left_outer_container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
auto& left_outer_container = inner_widget.add<GUI::Widget>();
|
||||
left_outer_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
auto left_inner_container = left_outer_container->add<GUI::Widget>();
|
||||
left_inner_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
left_inner_container->layout()->set_spacing(8);
|
||||
left_inner_container->set_preferred_size(0, 50);
|
||||
left_inner_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
auto& left_inner_container = left_outer_container.add<GUI::Widget>();
|
||||
left_inner_container.set_layout<GUI::VerticalBoxLayout>();
|
||||
left_inner_container.layout()->set_spacing(8);
|
||||
left_inner_container.set_preferred_size(0, 50);
|
||||
left_inner_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
|
||||
auto label = left_inner_container->add<GUI::Label>();
|
||||
label->set_text_alignment(Gfx::TextAlignment::CenterRight);
|
||||
label->set_font(Gfx::Font::default_bold_font());
|
||||
label->set_text("SerenityOS");
|
||||
label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
label->set_preferred_size(0, 11);
|
||||
auto& label = left_inner_container.add<GUI::Label>();
|
||||
label.set_text_alignment(Gfx::TextAlignment::CenterRight);
|
||||
label.set_font(Gfx::Font::default_bold_font());
|
||||
label.set_text("SerenityOS");
|
||||
label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
label.set_preferred_size(0, 11);
|
||||
|
||||
utsname uts;
|
||||
int rc = uname(&uts);
|
||||
ASSERT(rc == 0);
|
||||
|
||||
auto version_label = left_inner_container->add<GUI::Label>();
|
||||
version_label->set_text_alignment(Gfx::TextAlignment::CenterRight);
|
||||
version_label->set_text(String::format("Version %s", uts.release));
|
||||
version_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
version_label->set_preferred_size(0, 11);
|
||||
auto& version_label = left_inner_container.add<GUI::Label>();
|
||||
version_label.set_text_alignment(Gfx::TextAlignment::CenterRight);
|
||||
version_label.set_text(String::format("Version %s", uts.release));
|
||||
version_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
version_label.set_preferred_size(0, 11);
|
||||
|
||||
auto git_info_label = left_inner_container->add<GUI::Label>();
|
||||
git_info_label->set_text_alignment(Gfx::TextAlignment::CenterRight);
|
||||
git_info_label->set_text(String::format("%s@%s", GIT_BRANCH, GIT_COMMIT));
|
||||
git_info_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
git_info_label->set_preferred_size(0, 11);
|
||||
auto& git_info_label = left_inner_container.add<GUI::Label>();
|
||||
git_info_label.set_text_alignment(Gfx::TextAlignment::CenterRight);
|
||||
git_info_label.set_text(String::format("%s@%s", GIT_BRANCH, GIT_COMMIT));
|
||||
git_info_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
git_info_label.set_preferred_size(0, 11);
|
||||
|
||||
auto right_container = inner_widget->add<GUI::Widget>();
|
||||
right_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
auto& right_container = inner_widget.add<GUI::Widget>();
|
||||
right_container.set_layout<GUI::VerticalBoxLayout>();
|
||||
|
||||
auto icon_label = right_container->add<GUI::Label>();
|
||||
icon_label->set_icon(Gfx::Bitmap::load_from_file("/res/icons/buggie.png"));
|
||||
icon_label->set_tooltip("Buggie");
|
||||
icon_label->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
icon_label->set_preferred_size(icon_label->icon()->size());
|
||||
auto& icon_label = right_container.add<GUI::Label>();
|
||||
icon_label.set_icon(Gfx::Bitmap::load_from_file("/res/icons/buggie.png"));
|
||||
icon_label.set_tooltip("Buggie");
|
||||
icon_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
icon_label.set_preferred_size(icon_label.icon()->size());
|
||||
|
||||
auto quit_button = outer_widget.add<GUI::Button>();
|
||||
quit_button->set_text("Okay");
|
||||
quit_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
quit_button->set_preferred_size(100, 20);
|
||||
quit_button->on_click = [] {
|
||||
auto& quit_button = outer_widget.add<GUI::Button>();
|
||||
quit_button.set_text("Okay");
|
||||
quit_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
quit_button.set_preferred_size(100, 20);
|
||||
quit_button.on_click = [] {
|
||||
GUI::Application::the().quit(0);
|
||||
};
|
||||
|
||||
quit_button->set_focus(true);
|
||||
quit_button.set_focus(true);
|
||||
window->show();
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
InspectorWidget::InspectorWidget()
|
||||
{
|
||||
set_layout<GUI::VerticalBoxLayout>();
|
||||
auto splitter = add<GUI::VerticalSplitter>();
|
||||
m_dom_tree_view = splitter->add<GUI::TreeView>();
|
||||
auto& splitter = add<GUI::VerticalSplitter>();
|
||||
m_dom_tree_view = splitter.add<GUI::TreeView>();
|
||||
m_dom_tree_view->on_selection = [this](auto& index) {
|
||||
auto* node = static_cast<Node*>(index.internal_data());
|
||||
node->document().set_inspected_node(node);
|
||||
|
@ -55,12 +55,12 @@ InspectorWidget::InspectorWidget()
|
|||
}
|
||||
};
|
||||
|
||||
auto tab_widget = splitter->add<GUI::TabWidget>();
|
||||
auto& tab_widget = splitter.add<GUI::TabWidget>();
|
||||
|
||||
m_style_table_view = tab_widget->add_tab<GUI::TableView>("Styles");
|
||||
m_style_table_view = tab_widget.add_tab<GUI::TableView>("Styles");
|
||||
m_style_table_view->set_size_columns_to_fit_content(true);
|
||||
|
||||
m_computed_style_table_view = tab_widget->add_tab<GUI::TableView>("Computed");
|
||||
m_computed_style_table_view = tab_widget.add_tab<GUI::TableView>("Computed");
|
||||
m_computed_style_table_view->set_size_columns_to_fit_content(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,8 @@ int main(int argc, char** argv)
|
|||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
widget.layout()->set_spacing(0);
|
||||
|
||||
auto toolbar = widget.add<GUI::ToolBar>();
|
||||
auto html_widget = widget.add<HtmlView>();
|
||||
auto& toolbar = widget.add<GUI::ToolBar>();
|
||||
auto& html_widget = widget.add<HtmlView>();
|
||||
|
||||
History<URL> history;
|
||||
|
||||
|
@ -99,70 +99,70 @@ int main(int argc, char** argv)
|
|||
history.go_back();
|
||||
update_actions();
|
||||
TemporaryChange<bool> change(should_push_loads_to_history, false);
|
||||
html_widget->load(history.current());
|
||||
html_widget.load(history.current());
|
||||
});
|
||||
|
||||
go_forward_action = GUI::CommonActions::make_go_forward_action([&](auto&) {
|
||||
history.go_forward();
|
||||
update_actions();
|
||||
TemporaryChange<bool> change(should_push_loads_to_history, false);
|
||||
html_widget->load(history.current());
|
||||
html_widget.load(history.current());
|
||||
});
|
||||
|
||||
toolbar->add_action(*go_back_action);
|
||||
toolbar->add_action(*go_forward_action);
|
||||
toolbar.add_action(*go_back_action);
|
||||
toolbar.add_action(*go_forward_action);
|
||||
|
||||
toolbar->add_action(GUI::CommonActions::make_go_home_action([&](auto&) {
|
||||
html_widget->load(home_url);
|
||||
toolbar.add_action(GUI::CommonActions::make_go_home_action([&](auto&) {
|
||||
html_widget.load(home_url);
|
||||
}));
|
||||
|
||||
toolbar->add_action(GUI::CommonActions::make_reload_action([&](auto&) {
|
||||
toolbar.add_action(GUI::CommonActions::make_reload_action([&](auto&) {
|
||||
TemporaryChange<bool> change(should_push_loads_to_history, false);
|
||||
html_widget->reload();
|
||||
html_widget.reload();
|
||||
}));
|
||||
|
||||
auto location_box = toolbar->add<GUI::TextBox>();
|
||||
auto& location_box = toolbar.add<GUI::TextBox>();
|
||||
|
||||
location_box->on_return_pressed = [&] {
|
||||
html_widget->load(location_box->text());
|
||||
location_box.on_return_pressed = [&] {
|
||||
html_widget.load(location_box.text());
|
||||
};
|
||||
|
||||
html_widget->on_load_start = [&](auto& url) {
|
||||
location_box->set_text(url.to_string());
|
||||
html_widget.on_load_start = [&](auto& url) {
|
||||
location_box.set_text(url.to_string());
|
||||
if (should_push_loads_to_history)
|
||||
history.push(url);
|
||||
update_actions();
|
||||
};
|
||||
|
||||
html_widget->on_link_click = [&](auto& url) {
|
||||
html_widget.on_link_click = [&](auto& url) {
|
||||
if (url.starts_with("#")) {
|
||||
html_widget->scroll_to_anchor(url.substring_view(1, url.length() - 1));
|
||||
html_widget.scroll_to_anchor(url.substring_view(1, url.length() - 1));
|
||||
} else {
|
||||
html_widget->load(html_widget->document()->complete_url(url));
|
||||
html_widget.load(html_widget.document()->complete_url(url));
|
||||
}
|
||||
};
|
||||
|
||||
html_widget->on_title_change = [&](auto& title) {
|
||||
html_widget.on_title_change = [&](auto& title) {
|
||||
window->set_title(String::format("%s - Browser", title.characters()));
|
||||
};
|
||||
|
||||
auto focus_location_box_action = GUI::Action::create("Focus location box", { Mod_Ctrl, Key_L }, [&](auto&) {
|
||||
location_box->select_all();
|
||||
location_box->set_focus(true);
|
||||
location_box.select_all();
|
||||
location_box.set_focus(true);
|
||||
});
|
||||
|
||||
auto statusbar = widget.add<GUI::StatusBar>();
|
||||
auto& statusbar = widget.add<GUI::StatusBar>();
|
||||
|
||||
html_widget->on_link_hover = [&](auto& href) {
|
||||
statusbar->set_text(href);
|
||||
html_widget.on_link_hover = [&](auto& href) {
|
||||
statusbar.set_text(href);
|
||||
};
|
||||
|
||||
ResourceLoader::the().on_load_counter_change = [&] {
|
||||
if (ResourceLoader::the().pending_loads() == 0) {
|
||||
statusbar->set_text("");
|
||||
statusbar.set_text("");
|
||||
return;
|
||||
}
|
||||
statusbar->set_text(String::format("Loading (%d pending resources...)", ResourceLoader::the().pending_loads()));
|
||||
statusbar.set_text(String::format("Loading (%d pending resources...)", ResourceLoader::the().pending_loads()));
|
||||
};
|
||||
|
||||
auto menubar = make<GUI::MenuBar>();
|
||||
|
@ -179,13 +179,13 @@ int main(int argc, char** argv)
|
|||
inspect_menu->add_action(GUI::Action::create("View source", { Mod_Ctrl, Key_U }, [&](auto&) {
|
||||
String filename_to_open;
|
||||
char tmp_filename[] = "/tmp/view-source.XXXXXX";
|
||||
ASSERT(html_widget->document());
|
||||
if (html_widget->document()->url().protocol() == "file") {
|
||||
filename_to_open = html_widget->document()->url().path();
|
||||
ASSERT(html_widget.document());
|
||||
if (html_widget.document()->url().protocol() == "file") {
|
||||
filename_to_open = html_widget.document()->url().path();
|
||||
} else {
|
||||
int fd = mkstemp(tmp_filename);
|
||||
ASSERT(fd >= 0);
|
||||
auto source = html_widget->document()->source();
|
||||
auto source = html_widget.document()->source();
|
||||
write(fd, source.characters(), source.length());
|
||||
close(fd);
|
||||
filename_to_open = tmp_filename;
|
||||
|
@ -203,7 +203,7 @@ int main(int argc, char** argv)
|
|||
dom_inspector_window->set_main_widget<InspectorWidget>();
|
||||
}
|
||||
auto* inspector_widget = static_cast<InspectorWidget*>(dom_inspector_window->main_widget());
|
||||
inspector_widget->set_document(html_widget->document());
|
||||
inspector_widget->set_document(html_widget.document());
|
||||
dom_inspector_window->show();
|
||||
dom_inspector_window->move_to_front();
|
||||
}));
|
||||
|
@ -211,21 +211,21 @@ int main(int argc, char** argv)
|
|||
|
||||
auto debug_menu = GUI::Menu::construct("Debug");
|
||||
debug_menu->add_action(GUI::Action::create("Dump DOM tree", [&](auto&) {
|
||||
dump_tree(*html_widget->document());
|
||||
dump_tree(*html_widget.document());
|
||||
}));
|
||||
debug_menu->add_action(GUI::Action::create("Dump Layout tree", [&](auto&) {
|
||||
dump_tree(*html_widget->document()->layout_node());
|
||||
dump_tree(*html_widget.document()->layout_node());
|
||||
}));
|
||||
debug_menu->add_action(GUI::Action::create("Dump Style sheets", [&](auto&) {
|
||||
for (auto& sheet : html_widget->document()->stylesheets()) {
|
||||
for (auto& sheet : html_widget.document()->stylesheets()) {
|
||||
dump_sheet(sheet);
|
||||
}
|
||||
}));
|
||||
debug_menu->add_separator();
|
||||
auto line_box_borders_action = GUI::Action::create("Line box borders", [&](auto& action) {
|
||||
action.set_checked(!action.is_checked());
|
||||
html_widget->set_should_show_line_box_borders(action.is_checked());
|
||||
html_widget->update();
|
||||
html_widget.set_should_show_line_box_borders(action.is_checked());
|
||||
html_widget.update();
|
||||
});
|
||||
line_box_borders_action->set_checkable(true);
|
||||
line_box_borders_action->set_checked(false);
|
||||
|
@ -253,7 +253,7 @@ int main(int argc, char** argv)
|
|||
url_to_load.set_path(app.args()[0]);
|
||||
}
|
||||
|
||||
html_widget->load(url_to_load);
|
||||
html_widget.load(url_to_load);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
@ -61,30 +61,30 @@ int main(int argc, char** argv)
|
|||
widget.set_fill_with_background_color(true);
|
||||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
|
||||
auto board_combo = widget.add<GUI::ComboBox>();
|
||||
board_combo->set_only_allow_values_from_model(true);
|
||||
board_combo->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
board_combo->set_preferred_size(0, 20);
|
||||
board_combo->set_model(BoardListModel::create());
|
||||
auto& board_combo = widget.add<GUI::ComboBox>();
|
||||
board_combo.set_only_allow_values_from_model(true);
|
||||
board_combo.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
board_combo.set_preferred_size(0, 20);
|
||||
board_combo.set_model(BoardListModel::create());
|
||||
|
||||
auto catalog_view = widget.add<GUI::TableView>();
|
||||
catalog_view->set_model(ThreadCatalogModel::create());
|
||||
auto& catalog_model = *static_cast<ThreadCatalogModel*>(catalog_view->model());
|
||||
auto& catalog_view = widget.add<GUI::TableView>();
|
||||
catalog_view.set_model(ThreadCatalogModel::create());
|
||||
auto& catalog_model = *static_cast<ThreadCatalogModel*>(catalog_view.model());
|
||||
|
||||
auto statusbar = widget.add<GUI::StatusBar>();
|
||||
auto& statusbar = widget.add<GUI::StatusBar>();
|
||||
|
||||
board_combo->on_change = [&] (auto&, const GUI::ModelIndex& index) {
|
||||
auto selected_board = board_combo->model()->data(index, GUI::Model::Role::Custom);
|
||||
board_combo.on_change = [&] (auto&, const GUI::ModelIndex& index) {
|
||||
auto selected_board = board_combo.model()->data(index, GUI::Model::Role::Custom);
|
||||
ASSERT(selected_board.is_string());
|
||||
catalog_model.set_board(selected_board.to_string());
|
||||
};
|
||||
|
||||
catalog_model.on_load_started = [&] {
|
||||
statusbar->set_text(String::format("Loading /%s/...", catalog_model.board().characters()));
|
||||
statusbar.set_text(String::format("Loading /%s/...", catalog_model.board().characters()));
|
||||
};
|
||||
|
||||
catalog_model.on_load_finished = [&](bool success) {
|
||||
statusbar->set_text(success ? "Load finished" : "Load failed");
|
||||
statusbar.set_text(success ? "Load finished" : "Load failed");
|
||||
if (success) {
|
||||
window->set_title(String::format("/%s/ - ChanViewer", catalog_model.board().characters()));
|
||||
}
|
||||
|
|
|
@ -125,30 +125,30 @@ void DisplayPropertiesWidget::create_wallpaper_list()
|
|||
|
||||
void DisplayPropertiesWidget::create_frame()
|
||||
{
|
||||
auto tab_widget = m_root_widget->add<GUI::TabWidget>();
|
||||
auto& tab_widget = m_root_widget->add<GUI::TabWidget>();
|
||||
|
||||
auto wallpaper_splitter = tab_widget->add_tab<GUI::VerticalSplitter>("Wallpaper");
|
||||
auto wallpaper_splitter = tab_widget.add_tab<GUI::VerticalSplitter>("Wallpaper");
|
||||
|
||||
auto wallpaper_content = wallpaper_splitter->add<GUI::Widget>();
|
||||
wallpaper_content->set_layout<GUI::VerticalBoxLayout>();
|
||||
wallpaper_content->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
auto& wallpaper_content = wallpaper_splitter->add<GUI::Widget>();
|
||||
wallpaper_content.set_layout<GUI::VerticalBoxLayout>();
|
||||
wallpaper_content.layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
m_wallpaper_preview = wallpaper_splitter->add<GUI::Label>();
|
||||
|
||||
auto wallpaper_list = wallpaper_content->add<GUI::ListView>();
|
||||
wallpaper_list->set_background_color(Color::White);
|
||||
wallpaper_list->set_model(*ItemListModel<AK::String>::create(m_wallpapers));
|
||||
auto& wallpaper_list = wallpaper_content.add<GUI::ListView>();
|
||||
wallpaper_list.set_background_color(Color::White);
|
||||
wallpaper_list.set_model(*ItemListModel<AK::String>::create(m_wallpapers));
|
||||
|
||||
auto wallpaper_model = wallpaper_list->model();
|
||||
auto wallpaper_model = wallpaper_list.model();
|
||||
auto find_first_wallpaper_index = m_wallpapers.find_first_index(m_selected_wallpaper);
|
||||
if (find_first_wallpaper_index.has_value()) {
|
||||
auto wallpaper_index_in_model = wallpaper_model->index(find_first_wallpaper_index.value(), wallpaper_list->model_column());
|
||||
auto wallpaper_index_in_model = wallpaper_model->index(find_first_wallpaper_index.value(), wallpaper_list.model_column());
|
||||
if (wallpaper_model->is_valid(wallpaper_index_in_model))
|
||||
wallpaper_list->selection().set(wallpaper_index_in_model);
|
||||
wallpaper_list.selection().set(wallpaper_index_in_model);
|
||||
}
|
||||
|
||||
wallpaper_list->horizontal_scrollbar().set_visible(false);
|
||||
wallpaper_list->on_selection = [this](auto& index) {
|
||||
wallpaper_list.horizontal_scrollbar().set_visible(false);
|
||||
wallpaper_list.on_selection = [this](auto& index) {
|
||||
StringBuilder builder;
|
||||
m_selected_wallpaper = m_wallpapers.at(index.row());
|
||||
builder.append("/res/wallpapers/");
|
||||
|
@ -157,62 +157,62 @@ void DisplayPropertiesWidget::create_frame()
|
|||
m_wallpaper_preview->set_should_stretch_icon(true);
|
||||
};
|
||||
|
||||
auto settings_splitter = tab_widget->add_tab<GUI::VerticalSplitter>("Settings");
|
||||
auto settings_splitter = tab_widget.add_tab<GUI::VerticalSplitter>("Settings");
|
||||
|
||||
auto settings_content = settings_splitter->add<GUI::Widget>();
|
||||
settings_content->set_layout<GUI::VerticalBoxLayout>();
|
||||
settings_content->layout()->set_margins({ 4, 4, 4, 4 });
|
||||
auto& settings_content = settings_splitter->add<GUI::Widget>();
|
||||
settings_content.set_layout<GUI::VerticalBoxLayout>();
|
||||
settings_content.layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto resolution_list = settings_content->add<GUI::ListView>();
|
||||
resolution_list->set_background_color(Color::White);
|
||||
resolution_list->set_model(*ItemListModel<Gfx::Size>::create(m_resolutions));
|
||||
auto& resolution_list = settings_content.add<GUI::ListView>();
|
||||
resolution_list.set_background_color(Color::White);
|
||||
resolution_list.set_model(*ItemListModel<Gfx::Size>::create(m_resolutions));
|
||||
|
||||
auto resolution_model = resolution_list->model();
|
||||
auto resolution_model = resolution_list.model();
|
||||
auto find_first_resolution_index = m_resolutions.find_first_index(m_selected_resolution);
|
||||
ASSERT(find_first_resolution_index.has_value());
|
||||
auto resolution_index_in_model = resolution_model->index(find_first_resolution_index.value(), resolution_list->model_column());
|
||||
auto resolution_index_in_model = resolution_model->index(find_first_resolution_index.value(), resolution_list.model_column());
|
||||
if (resolution_model->is_valid(resolution_index_in_model))
|
||||
resolution_list->selection().set(resolution_index_in_model);
|
||||
resolution_list.selection().set(resolution_index_in_model);
|
||||
|
||||
resolution_list->horizontal_scrollbar().set_visible(false);
|
||||
resolution_list->on_selection = [this](auto& index) {
|
||||
resolution_list.horizontal_scrollbar().set_visible(false);
|
||||
resolution_list.on_selection = [this](auto& index) {
|
||||
m_selected_resolution = m_resolutions.at(index.row());
|
||||
};
|
||||
|
||||
settings_content->layout()->add_spacer();
|
||||
settings_content.layout()->add_spacer();
|
||||
|
||||
// Add the apply and cancel buttons
|
||||
auto bottom_widget = m_root_widget->add<GUI::Widget>();
|
||||
bottom_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
bottom_widget->layout()->add_spacer();
|
||||
bottom_widget->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
|
||||
bottom_widget->set_preferred_size(1, 22);
|
||||
auto& bottom_widget = m_root_widget->add<GUI::Widget>();
|
||||
bottom_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
bottom_widget.layout()->add_spacer();
|
||||
bottom_widget.set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
|
||||
bottom_widget.set_preferred_size(1, 22);
|
||||
|
||||
auto apply_button = bottom_widget->add<GUI::Button>();
|
||||
apply_button->set_text("Apply");
|
||||
apply_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
|
||||
apply_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
|
||||
apply_button->set_preferred_size(60, 22);
|
||||
apply_button->on_click = [this, tab_widget] {
|
||||
auto& apply_button = bottom_widget.add<GUI::Button>();
|
||||
apply_button.set_text("Apply");
|
||||
apply_button.set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
|
||||
apply_button.set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
|
||||
apply_button.set_preferred_size(60, 22);
|
||||
apply_button.on_click = [this, tab_widget = &tab_widget] {
|
||||
send_settings_to_window_server(tab_widget->active_tab_index());
|
||||
};
|
||||
|
||||
auto ok_button = bottom_widget->add<GUI::Button>();
|
||||
ok_button->set_text("OK");
|
||||
ok_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
|
||||
ok_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
|
||||
ok_button->set_preferred_size(60, 22);
|
||||
ok_button->on_click = [this, tab_widget] {
|
||||
auto& ok_button = bottom_widget.add<GUI::Button>();
|
||||
ok_button.set_text("OK");
|
||||
ok_button.set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
|
||||
ok_button.set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
|
||||
ok_button.set_preferred_size(60, 22);
|
||||
ok_button.on_click = [this, tab_widget = &tab_widget] {
|
||||
send_settings_to_window_server(tab_widget->active_tab_index());
|
||||
GUI::Application::the().quit();
|
||||
};
|
||||
|
||||
auto cancel_button = bottom_widget->add<GUI::Button>();
|
||||
cancel_button->set_text("Cancel");
|
||||
cancel_button->set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
|
||||
cancel_button->set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
|
||||
cancel_button->set_preferred_size(60, 22);
|
||||
cancel_button->on_click = [] {
|
||||
auto& cancel_button = bottom_widget.add<GUI::Button>();
|
||||
cancel_button.set_text("Cancel");
|
||||
cancel_button.set_size_policy(Orientation::Vertical, GUI::SizePolicy::Fixed);
|
||||
cancel_button.set_size_policy(Orientation::Horizontal, GUI::SizePolicy::Fixed);
|
||||
cancel_button.set_preferred_size(60, 22);
|
||||
cancel_button.on_click = [] {
|
||||
GUI::Application::the().quit();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -51,28 +51,28 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
set_rect({ 0, 0, 360, 420 });
|
||||
set_resizable(false);
|
||||
|
||||
auto tab_widget = main_widget.add<GUI::TabWidget>();
|
||||
auto& tab_widget = main_widget.add<GUI::TabWidget>();
|
||||
|
||||
auto general_tab = tab_widget->add_tab<GUI::Widget>("General");
|
||||
auto general_tab = tab_widget.add_tab<GUI::Widget>("General");
|
||||
general_tab->set_layout<GUI::VerticalBoxLayout>();
|
||||
general_tab->layout()->set_margins({ 12, 8, 12, 8 });
|
||||
general_tab->layout()->set_spacing(10);
|
||||
|
||||
general_tab->layout()->add_spacer();
|
||||
|
||||
auto file_container = general_tab->add<GUI::Widget>();
|
||||
file_container->set_layout<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);
|
||||
auto& file_container = general_tab->add<GUI::Widget>();
|
||||
file_container.set_layout<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 = file_container->add<GUI::Label>();
|
||||
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 = file_container->add<GUI::TextBox>();
|
||||
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);
|
||||
|
@ -130,19 +130,19 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
|
||||
general_tab->layout()->add_spacer();
|
||||
|
||||
auto button_widget = main_widget.add<GUI::Widget>();
|
||||
button_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
button_widget->set_preferred_size(0, 24);
|
||||
button_widget->layout()->set_spacing(5);
|
||||
auto& button_widget = main_widget.add<GUI::Widget>();
|
||||
button_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_widget.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
button_widget.set_preferred_size(0, 24);
|
||||
button_widget.layout()->set_spacing(5);
|
||||
|
||||
button_widget->layout()->add_spacer();
|
||||
button_widget.layout()->add_spacer();
|
||||
|
||||
make_button("OK", button_widget)->on_click = [this] {
|
||||
make_button("OK", button_widget).on_click = [this] {
|
||||
if (apply_changes())
|
||||
close();
|
||||
};
|
||||
make_button("Cancel", button_widget)->on_click = [this] {
|
||||
make_button("Cancel", button_widget).on_click = [this] {
|
||||
close();
|
||||
};
|
||||
|
||||
|
@ -215,48 +215,48 @@ bool PropertiesDialog::apply_changes()
|
|||
|
||||
void PropertiesDialog::make_permission_checkboxes(NonnullRefPtr<GUI::Widget>& parent, PermissionMasks masks, String label_string, mode_t mode)
|
||||
{
|
||||
auto widget = parent->add<GUI::Widget>();
|
||||
widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
widget->set_preferred_size(0, 16);
|
||||
widget->layout()->set_spacing(10);
|
||||
auto& widget = parent->add<GUI::Widget>();
|
||||
widget.set_layout<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 = widget->add<GUI::Label>(label_string);
|
||||
label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
auto& label = widget.add<GUI::Label>(label_string);
|
||||
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
|
||||
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_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 = 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_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 = widget->add<GUI::CheckBox>("Execute");
|
||||
box_execute->set_checked(mode & masks.execute);
|
||||
box_execute->on_checked = [&, masks](bool checked) { permission_changed(masks.execute, checked); };
|
||||
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); };
|
||||
}
|
||||
|
||||
void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>& pairs, NonnullRefPtr<GUI::Widget>& parent)
|
||||
void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>& pairs, GUI::Widget& parent)
|
||||
{
|
||||
int max_width = 0;
|
||||
Vector<NonnullRefPtr<GUI::Label>> property_labels;
|
||||
|
||||
property_labels.ensure_capacity(pairs.size());
|
||||
for (auto pair : pairs) {
|
||||
auto label_container = parent->add<GUI::Widget>();
|
||||
label_container->set_layout<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_container = parent.add<GUI::Widget>();
|
||||
label_container.set_layout<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 = 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);
|
||||
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);
|
||||
|
||||
label_container->add<GUI::Label>(pair.value)->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));
|
||||
max_width = max(max_width, label_property.font().width(pair.property));
|
||||
property_labels.append(label_property);
|
||||
}
|
||||
|
||||
|
@ -264,21 +264,21 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>
|
|||
label->set_preferred_size({ max_width, 0 });
|
||||
}
|
||||
|
||||
NonnullRefPtr<GUI::Button> PropertiesDialog::make_button(String text, NonnullRefPtr<GUI::Widget>& parent)
|
||||
GUI::Button& PropertiesDialog::make_button(String text, GUI::Widget& parent)
|
||||
{
|
||||
auto button = parent->add<GUI::Button>(text);
|
||||
button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
button->set_preferred_size(70, 22);
|
||||
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;
|
||||
}
|
||||
|
||||
void PropertiesDialog::make_divider(NonnullRefPtr<GUI::Widget>& parent)
|
||||
void PropertiesDialog::make_divider(GUI::Widget& parent)
|
||||
{
|
||||
parent->layout()->add_spacer();
|
||||
parent.layout()->add_spacer();
|
||||
|
||||
auto divider = parent->add<GUI::Frame>();
|
||||
divider->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
divider->set_preferred_size({ 0, 2 });
|
||||
auto& divider = parent.add<GUI::Frame>();
|
||||
divider.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
divider.set_preferred_size({ 0, 2 });
|
||||
|
||||
parent->layout()->add_spacer();
|
||||
parent.layout()->add_spacer();
|
||||
}
|
||||
|
|
|
@ -75,9 +75,9 @@ private:
|
|||
return "Unknown";
|
||||
}
|
||||
|
||||
NonnullRefPtr<GUI::Button> make_button(String, NonnullRefPtr<GUI::Widget>&);
|
||||
void make_divider(NonnullRefPtr<GUI::Widget>&);
|
||||
void make_property_value_pairs(const Vector<PropertyValuePair>& pairs, NonnullRefPtr<GUI::Widget>& parent);
|
||||
GUI::Button& make_button(String, GUI::Widget& parent);
|
||||
void make_divider(GUI::Widget& parent);
|
||||
void make_property_value_pairs(const Vector<PropertyValuePair>& pairs, GUI::Widget& parent);
|
||||
void make_permission_checkboxes(NonnullRefPtr<GUI::Widget>& parent, PermissionMasks, String label_string, mode_t mode);
|
||||
void permission_changed(mode_t mask, bool set);
|
||||
bool apply_changes();
|
||||
|
|
|
@ -96,56 +96,56 @@ int main(int argc, char** argv)
|
|||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
widget.layout()->set_spacing(0);
|
||||
|
||||
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& 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 = location_toolbar->add<GUI::Label>("Location: ");
|
||||
location_label->size_to_fit();
|
||||
auto& location_label = location_toolbar.add<GUI::Label>("Location: ");
|
||||
location_label.size_to_fit();
|
||||
|
||||
auto location_textbox = location_toolbar->add<GUI::TextBox>();
|
||||
auto& location_textbox = location_toolbar.add<GUI::TextBox>();
|
||||
|
||||
auto splitter = widget.add<GUI::HorizontalSplitter>();
|
||||
auto tree_view = splitter->add<GUI::TreeView>();
|
||||
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);
|
||||
tree_view->set_column_hidden(GUI::FileSystemModel::Column::Size, true);
|
||||
tree_view->set_column_hidden(GUI::FileSystemModel::Column::Owner, true);
|
||||
tree_view->set_column_hidden(GUI::FileSystemModel::Column::Group, true);
|
||||
tree_view->set_column_hidden(GUI::FileSystemModel::Column::Permissions, true);
|
||||
tree_view->set_column_hidden(GUI::FileSystemModel::Column::ModificationTime, true);
|
||||
tree_view->set_column_hidden(GUI::FileSystemModel::Column::Inode, true);
|
||||
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 = splitter->add<DirectoryView>();
|
||||
tree_view.set_model(directories_model);
|
||||
tree_view.set_column_hidden(GUI::FileSystemModel::Column::Icon, true);
|
||||
tree_view.set_column_hidden(GUI::FileSystemModel::Column::Size, true);
|
||||
tree_view.set_column_hidden(GUI::FileSystemModel::Column::Owner, true);
|
||||
tree_view.set_column_hidden(GUI::FileSystemModel::Column::Group, true);
|
||||
tree_view.set_column_hidden(GUI::FileSystemModel::Column::Permissions, true);
|
||||
tree_view.set_column_hidden(GUI::FileSystemModel::Column::ModificationTime, true);
|
||||
tree_view.set_column_hidden(GUI::FileSystemModel::Column::Inode, true);
|
||||
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 = splitter.add<DirectoryView>();
|
||||
|
||||
auto statusbar = widget.add<GUI::StatusBar>();
|
||||
auto& statusbar = widget.add<GUI::StatusBar>();
|
||||
|
||||
auto progressbar = statusbar->add<GUI::ProgressBar>();
|
||||
progressbar->set_caption("Generating thumbnails: ");
|
||||
progressbar->set_format(GUI::ProgressBar::Format::ValueSlashMax);
|
||||
progressbar->set_visible(false);
|
||||
progressbar->set_frame_shape(Gfx::FrameShape::Panel);
|
||||
progressbar->set_frame_shadow(Gfx::FrameShadow::Sunken);
|
||||
progressbar->set_frame_thickness(1);
|
||||
auto& progressbar = statusbar.add<GUI::ProgressBar>();
|
||||
progressbar.set_caption("Generating thumbnails: ");
|
||||
progressbar.set_format(GUI::ProgressBar::Format::ValueSlashMax);
|
||||
progressbar.set_visible(false);
|
||||
progressbar.set_frame_shape(Gfx::FrameShape::Panel);
|
||||
progressbar.set_frame_shadow(Gfx::FrameShadow::Sunken);
|
||||
progressbar.set_frame_thickness(1);
|
||||
|
||||
location_textbox->on_return_pressed = [&] {
|
||||
directory_view->open(location_textbox->text());
|
||||
location_textbox.on_return_pressed = [&] {
|
||||
directory_view.open(location_textbox.text());
|
||||
};
|
||||
|
||||
auto refresh_tree_view = [&] {
|
||||
directories_model->update();
|
||||
|
||||
auto current_path = directory_view->path();
|
||||
auto current_path = directory_view.path();
|
||||
|
||||
struct stat st;
|
||||
// If the directory no longer exists, we find a parent that does.
|
||||
while (stat(current_path.characters(), &st) != 0) {
|
||||
directory_view->open_parent_directory();
|
||||
current_path = directory_view->path();
|
||||
directory_view.open_parent_directory();
|
||||
current_path = directory_view.path();
|
||||
if (current_path == directories_model->root_path()) {
|
||||
break;
|
||||
}
|
||||
|
@ -153,11 +153,11 @@ int main(int argc, char** argv)
|
|||
|
||||
// Reselect the existing folder in the tree.
|
||||
auto new_index = directories_model->index(current_path, GUI::FileSystemModel::Column::Name);
|
||||
tree_view->selection().set(new_index);
|
||||
tree_view->scroll_into_view(new_index, Orientation::Vertical);
|
||||
tree_view->update();
|
||||
tree_view.selection().set(new_index);
|
||||
tree_view.scroll_into_view(new_index, Orientation::Vertical);
|
||||
tree_view.update();
|
||||
|
||||
directory_view->refresh();
|
||||
directory_view.refresh();
|
||||
};
|
||||
|
||||
auto directory_context_menu = GUI::Menu::construct("Directory View Directory");
|
||||
|
@ -167,16 +167,16 @@ int main(int argc, char** argv)
|
|||
auto tree_view_context_menu = GUI::Menu::construct("Tree View");
|
||||
|
||||
auto open_parent_directory_action = GUI::Action::create("Open parent directory", { Mod_Alt, Key_Up }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [&](const GUI::Action&) {
|
||||
directory_view->open_parent_directory();
|
||||
directory_view.open_parent_directory();
|
||||
});
|
||||
|
||||
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 = window->add<GUI::InputBox>("Enter name:", "New directory");
|
||||
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) {
|
||||
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",
|
||||
directory_view->path().characters(),
|
||||
input_box->text_value().characters()));
|
||||
directory_view.path().characters(),
|
||||
input_box.text_value().characters()));
|
||||
int rc = mkdir(new_dir_path.characters(), 0777);
|
||||
if (rc < 0) {
|
||||
GUI::MessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window);
|
||||
|
@ -192,7 +192,7 @@ int main(int argc, char** argv)
|
|||
|
||||
view_as_table_action = GUI::Action::create(
|
||||
"Table view", { Mod_Ctrl, KeyCode::Key_L }, Gfx::Bitmap::load_from_file("/res/icons/16x16/table-view.png"), [&](const GUI::Action&) {
|
||||
directory_view->set_view_mode(DirectoryView::ViewMode::List);
|
||||
directory_view.set_view_mode(DirectoryView::ViewMode::List);
|
||||
view_as_table_action->set_checked(true);
|
||||
|
||||
config->write_entry("DirectoryView", "ViewMode", "List");
|
||||
|
@ -203,7 +203,7 @@ int main(int argc, char** argv)
|
|||
|
||||
view_as_icons_action = GUI::Action::create(
|
||||
"Icon view", { Mod_Ctrl, KeyCode::Key_I }, Gfx::Bitmap::load_from_file("/res/icons/16x16/icon-view.png"), [&](const GUI::Action&) {
|
||||
directory_view->set_view_mode(DirectoryView::ViewMode::Icon);
|
||||
directory_view.set_view_mode(DirectoryView::ViewMode::Icon);
|
||||
view_as_icons_action->set_checked(true);
|
||||
|
||||
config->write_entry("DirectoryView", "ViewMode", "Icon");
|
||||
|
@ -214,7 +214,7 @@ int main(int argc, char** argv)
|
|||
|
||||
view_as_columns_action = GUI::Action::create(
|
||||
"Columns view", Gfx::Bitmap::load_from_file("/res/icons/16x16/columns-view.png"), [&](const GUI::Action&) {
|
||||
directory_view->set_view_mode(DirectoryView::ViewMode::Columns);
|
||||
directory_view.set_view_mode(DirectoryView::ViewMode::Columns);
|
||||
view_as_columns_action->set_checked(true);
|
||||
|
||||
config->write_entry("DirectoryView", "ViewMode", "Columns");
|
||||
|
@ -231,7 +231,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto selected_file_paths = [&] {
|
||||
Vector<String> paths;
|
||||
auto& view = directory_view->current_view();
|
||||
auto& view = directory_view.current_view();
|
||||
auto& model = *view.model();
|
||||
view.selection().for_each_index([&](const GUI::ModelIndex& index) {
|
||||
auto parent_index = model.parent_index(index);
|
||||
|
@ -245,20 +245,20 @@ int main(int argc, char** argv)
|
|||
auto tree_view_selected_file_paths = [&] {
|
||||
Vector<String> paths;
|
||||
auto& view = tree_view;
|
||||
view->selection().for_each_index([&](const GUI::ModelIndex& index) {
|
||||
view.selection().for_each_index([&](const GUI::ModelIndex& index) {
|
||||
paths.append(directories_model->full_path(index));
|
||||
});
|
||||
return paths;
|
||||
};
|
||||
|
||||
auto select_all_action = GUI::Action::create("Select all", { Mod_Ctrl, KeyCode::Key_A }, [&](const GUI::Action&) {
|
||||
directory_view->current_view().select_all();
|
||||
directory_view.current_view().select_all();
|
||||
});
|
||||
|
||||
auto copy_action = GUI::CommonActions::make_copy_action(
|
||||
[&](const GUI::Action& action) {
|
||||
Vector<String> paths;
|
||||
if (action.activator() == directory_context_menu || directory_view->active_widget()->is_focused()) {
|
||||
if (action.activator() == directory_context_menu || directory_view.active_widget()->is_focused()) {
|
||||
paths = selected_file_paths();
|
||||
} else {
|
||||
paths = tree_view_selected_file_paths();
|
||||
|
@ -289,7 +289,7 @@ int main(int argc, char** argv)
|
|||
for (auto& current_path : copied_lines) {
|
||||
if (current_path.is_empty())
|
||||
continue;
|
||||
auto current_directory = directory_view->path();
|
||||
auto current_directory = directory_view.path();
|
||||
auto new_path = String::format("%s/%s",
|
||||
current_directory.characters(),
|
||||
FileSystemPath(current_path).basename().characters());
|
||||
|
@ -312,14 +312,14 @@ int main(int argc, char** argv)
|
|||
auto properties_action
|
||||
= GUI::Action::create(
|
||||
"Properties...", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), [&](const GUI::Action& action) {
|
||||
auto& model = directory_view->model();
|
||||
auto& model = directory_view.model();
|
||||
String path;
|
||||
Vector<String> selected;
|
||||
if (action.activator() == directory_context_menu || directory_view->active_widget()->is_focused()) {
|
||||
path = directory_view->path();
|
||||
if (action.activator() == directory_context_menu || directory_view.active_widget()->is_focused()) {
|
||||
path = directory_view.path();
|
||||
selected = selected_file_paths();
|
||||
} else {
|
||||
path = directories_model->full_path(tree_view->selection().first());
|
||||
path = directories_model->full_path(tree_view.selection().first());
|
||||
selected = tree_view_selected_file_paths();
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto do_delete = [&](ConfirmBeforeDelete confirm, const GUI::Action& action) {
|
||||
Vector<String> paths;
|
||||
if (action.activator() == directory_context_menu || directory_view->active_widget()->is_focused()) {
|
||||
if (action.activator() == directory_context_menu || directory_view.active_widget()->is_focused()) {
|
||||
paths = selected_file_paths();
|
||||
} else {
|
||||
paths = tree_view_selected_file_paths();
|
||||
|
@ -425,19 +425,19 @@ int main(int argc, char** argv)
|
|||
|
||||
auto go_back_action = GUI::CommonActions::make_go_back_action(
|
||||
[&](auto&) {
|
||||
directory_view->open_previous_directory();
|
||||
directory_view.open_previous_directory();
|
||||
},
|
||||
window);
|
||||
|
||||
auto go_forward_action = GUI::CommonActions::make_go_forward_action(
|
||||
[&](auto&) {
|
||||
directory_view->open_next_directory();
|
||||
directory_view.open_next_directory();
|
||||
},
|
||||
window);
|
||||
|
||||
auto go_home_action = GUI::CommonActions::make_go_home_action(
|
||||
[&](auto&) {
|
||||
directory_view->open(get_current_user_home_path());
|
||||
directory_view.open(get_current_user_home_path());
|
||||
},
|
||||
window);
|
||||
|
||||
|
@ -475,52 +475,52 @@ int main(int argc, char** argv)
|
|||
|
||||
app.set_menubar(move(menubar));
|
||||
|
||||
main_toolbar->add_action(go_back_action);
|
||||
main_toolbar->add_action(go_forward_action);
|
||||
main_toolbar->add_action(open_parent_directory_action);
|
||||
main_toolbar->add_action(go_home_action);
|
||||
main_toolbar.add_action(go_back_action);
|
||||
main_toolbar.add_action(go_forward_action);
|
||||
main_toolbar.add_action(open_parent_directory_action);
|
||||
main_toolbar.add_action(go_home_action);
|
||||
|
||||
main_toolbar->add_separator();
|
||||
main_toolbar->add_action(mkdir_action);
|
||||
main_toolbar->add_action(copy_action);
|
||||
main_toolbar->add_action(paste_action);
|
||||
main_toolbar->add_action(delete_action);
|
||||
main_toolbar.add_separator();
|
||||
main_toolbar.add_action(mkdir_action);
|
||||
main_toolbar.add_action(copy_action);
|
||||
main_toolbar.add_action(paste_action);
|
||||
main_toolbar.add_action(delete_action);
|
||||
|
||||
main_toolbar->add_separator();
|
||||
main_toolbar->add_action(*view_as_icons_action);
|
||||
main_toolbar->add_action(*view_as_table_action);
|
||||
main_toolbar->add_action(*view_as_columns_action);
|
||||
main_toolbar.add_separator();
|
||||
main_toolbar.add_action(*view_as_icons_action);
|
||||
main_toolbar.add_action(*view_as_table_action);
|
||||
main_toolbar.add_action(*view_as_columns_action);
|
||||
|
||||
directory_view->on_path_change = [&](const String& new_path) {
|
||||
directory_view.on_path_change = [&](const String& new_path) {
|
||||
window->set_title(String::format("File Manager: %s", new_path.characters()));
|
||||
location_textbox->set_text(new_path);
|
||||
location_textbox.set_text(new_path);
|
||||
auto new_index = directories_model->index(new_path, GUI::FileSystemModel::Column::Name);
|
||||
if (new_index.is_valid()) {
|
||||
tree_view->selection().set(new_index);
|
||||
tree_view->scroll_into_view(new_index, Orientation::Vertical);
|
||||
tree_view->update();
|
||||
tree_view.selection().set(new_index);
|
||||
tree_view.scroll_into_view(new_index, Orientation::Vertical);
|
||||
tree_view.update();
|
||||
}
|
||||
|
||||
go_forward_action->set_enabled(directory_view->path_history_position()
|
||||
< directory_view->path_history_size() - 1);
|
||||
go_back_action->set_enabled(directory_view->path_history_position() > 0);
|
||||
go_forward_action->set_enabled(directory_view.path_history_position()
|
||||
< directory_view.path_history_size() - 1);
|
||||
go_back_action->set_enabled(directory_view.path_history_position() > 0);
|
||||
};
|
||||
|
||||
directory_view->on_status_message = [&](const StringView& message) {
|
||||
statusbar->set_text(message);
|
||||
directory_view.on_status_message = [&](const StringView& message) {
|
||||
statusbar.set_text(message);
|
||||
};
|
||||
|
||||
directory_view->on_thumbnail_progress = [&](int done, int total) {
|
||||
directory_view.on_thumbnail_progress = [&](int done, int total) {
|
||||
if (done == total) {
|
||||
progressbar->set_visible(false);
|
||||
progressbar.set_visible(false);
|
||||
return;
|
||||
}
|
||||
progressbar->set_range(0, total);
|
||||
progressbar->set_value(done);
|
||||
progressbar->set_visible(true);
|
||||
progressbar.set_range(0, total);
|
||||
progressbar.set_value(done);
|
||||
progressbar.set_visible(true);
|
||||
};
|
||||
|
||||
directory_view->on_selection_change = [&](GUI::AbstractView& view) {
|
||||
directory_view.on_selection_change = [&](GUI::AbstractView& view) {
|
||||
// FIXME: Figure out how we can enable/disable the paste action, based on clipboard contents.
|
||||
copy_action->set_enabled(!view.selection().is_empty());
|
||||
delete_action->set_enabled(!view.selection().is_empty());
|
||||
|
@ -561,9 +561,9 @@ int main(int argc, char** argv)
|
|||
tree_view_directory_context_menu->add_separator();
|
||||
tree_view_directory_context_menu->add_action(mkdir_action);
|
||||
|
||||
directory_view->on_context_menu_request = [&](const GUI::AbstractView&, const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
|
||||
directory_view.on_context_menu_request = [&](const GUI::AbstractView&, const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
|
||||
if (index.is_valid()) {
|
||||
auto& node = directory_view->model().node(index);
|
||||
auto& node = directory_view.model().node(index);
|
||||
|
||||
if (node.is_directory())
|
||||
directory_context_menu->popup(event.screen_position());
|
||||
|
@ -574,7 +574,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
};
|
||||
|
||||
directory_view->on_drop = [&](const GUI::AbstractView&, const GUI::ModelIndex& index, const GUI::DropEvent& event) {
|
||||
directory_view.on_drop = [&](const GUI::AbstractView&, const GUI::ModelIndex& index, const GUI::DropEvent& event) {
|
||||
if (!index.is_valid())
|
||||
return;
|
||||
if (!event.mime_data().has_urls())
|
||||
|
@ -585,7 +585,7 @@ int main(int argc, char** argv)
|
|||
return;
|
||||
}
|
||||
|
||||
auto& target_node = directory_view->model().node(index);
|
||||
auto& target_node = directory_view.model().node(index);
|
||||
if (!target_node.is_directory())
|
||||
return;
|
||||
|
||||
|
@ -593,7 +593,7 @@ int main(int argc, char** argv)
|
|||
if (!url_to_copy.is_valid())
|
||||
continue;
|
||||
auto new_path = String::format("%s/%s",
|
||||
target_node.full_path(directory_view->model()).characters(),
|
||||
target_node.full_path(directory_view.model()).characters(),
|
||||
FileSystemPath(url_to_copy.path()).basename().characters());
|
||||
|
||||
if (!FileUtils::copy_file_or_directory(url_to_copy.path(), new_path)) {
|
||||
|
@ -607,16 +607,16 @@ int main(int argc, char** argv)
|
|||
}
|
||||
};
|
||||
|
||||
tree_view->on_selection_change = [&] {
|
||||
auto path = directories_model->full_path(tree_view->selection().first());
|
||||
if (directory_view->path() == path)
|
||||
tree_view.on_selection_change = [&] {
|
||||
auto path = directories_model->full_path(tree_view.selection().first());
|
||||
if (directory_view.path() == path)
|
||||
return;
|
||||
directory_view->open(path);
|
||||
copy_action->set_enabled(!tree_view->selection().is_empty());
|
||||
delete_action->set_enabled(!tree_view->selection().is_empty());
|
||||
directory_view.open(path);
|
||||
copy_action->set_enabled(!tree_view.selection().is_empty());
|
||||
delete_action->set_enabled(!tree_view.selection().is_empty());
|
||||
};
|
||||
|
||||
tree_view->on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
|
||||
tree_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
|
||||
if (index.is_valid()) {
|
||||
tree_view_directory_context_menu->popup(event.screen_position());
|
||||
}
|
||||
|
@ -638,8 +638,8 @@ int main(int argc, char** argv)
|
|||
if (initial_location.is_empty())
|
||||
initial_location = "/";
|
||||
|
||||
directory_view->open(initial_location);
|
||||
directory_view->set_focus(true);
|
||||
directory_view.open(initial_location);
|
||||
directory_view.set_focus(true);
|
||||
|
||||
window->show();
|
||||
|
||||
|
@ -649,13 +649,13 @@ int main(int argc, char** argv)
|
|||
auto dir_view_mode = config->read_entry("DirectoryView", "ViewMode", "Icon");
|
||||
|
||||
if (dir_view_mode.contains("List")) {
|
||||
directory_view->set_view_mode(DirectoryView::ViewMode::List);
|
||||
directory_view.set_view_mode(DirectoryView::ViewMode::List);
|
||||
view_as_table_action->set_checked(true);
|
||||
} else if (dir_view_mode.contains("Columns")) {
|
||||
directory_view->set_view_mode(DirectoryView::ViewMode::Columns);
|
||||
directory_view.set_view_mode(DirectoryView::ViewMode::Columns);
|
||||
view_as_columns_action->set_checked(true);
|
||||
} else {
|
||||
directory_view->set_view_mode(DirectoryView::ViewMode::Icon);
|
||||
directory_view.set_view_mode(DirectoryView::ViewMode::Icon);
|
||||
view_as_icons_action->set_checked(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@ private:
|
|||
FontEditorWidget(const String& path, RefPtr<Gfx::Font>&&);
|
||||
RefPtr<Gfx::Font> m_edited_font;
|
||||
|
||||
GlyphMapWidget* m_glyph_map_widget { nullptr };
|
||||
GlyphEditorWidget* m_glyph_editor_widget { nullptr };
|
||||
RefPtr<GlyphMapWidget> m_glyph_map_widget;
|
||||
RefPtr<GlyphEditorWidget> m_glyph_editor_widget;
|
||||
|
||||
String m_path;
|
||||
|
||||
|
|
|
@ -82,18 +82,18 @@ int main(int argc, char* argv[])
|
|||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
widget.layout()->set_spacing(0);
|
||||
|
||||
auto toolbar = widget.add<GUI::ToolBar>();
|
||||
auto& toolbar = widget.add<GUI::ToolBar>();
|
||||
|
||||
auto splitter = widget.add<GUI::HorizontalSplitter>();
|
||||
auto& splitter = widget.add<GUI::HorizontalSplitter>();
|
||||
|
||||
auto model = ManualModel::create();
|
||||
|
||||
auto tree_view = splitter->add<GUI::TreeView>();
|
||||
tree_view->set_model(model);
|
||||
tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
tree_view->set_preferred_size(200, 500);
|
||||
auto& tree_view = splitter.add<GUI::TreeView>();
|
||||
tree_view.set_model(model);
|
||||
tree_view.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
tree_view.set_preferred_size(200, 500);
|
||||
|
||||
auto html_view = splitter->add<HtmlView>();
|
||||
auto& html_view = splitter.add<HtmlView>();
|
||||
|
||||
History history;
|
||||
|
||||
|
@ -107,7 +107,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
auto open_page = [&](const String& path) {
|
||||
if (path.is_null()) {
|
||||
html_view->set_document(nullptr);
|
||||
html_view.set_document(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -130,16 +130,16 @@ int main(int argc, char* argv[])
|
|||
|
||||
String html = md_document.render_to_html();
|
||||
auto html_document = parse_html_document(html);
|
||||
html_view->set_document(html_document);
|
||||
html_view.set_document(html_document);
|
||||
|
||||
String page_and_section = model->page_and_section(tree_view->selection().first());
|
||||
String page_and_section = model->page_and_section(tree_view.selection().first());
|
||||
window->set_title(String::format("Help: %s", page_and_section.characters()));
|
||||
};
|
||||
|
||||
tree_view->on_selection_change = [&] {
|
||||
String path = model->page_path(tree_view->selection().first());
|
||||
tree_view.on_selection_change = [&] {
|
||||
String path = model->page_path(tree_view.selection().first());
|
||||
if (path.is_null()) {
|
||||
html_view->set_document(nullptr);
|
||||
html_view.set_document(nullptr);
|
||||
return;
|
||||
}
|
||||
history.push(path);
|
||||
|
@ -147,7 +147,7 @@ int main(int argc, char* argv[])
|
|||
open_page(path);
|
||||
};
|
||||
|
||||
html_view->on_link_click = [&](const String& href) {
|
||||
html_view.on_link_click = [&](const String& href) {
|
||||
char* current_path = strdup(history.current().characters());
|
||||
char* dir_path = dirname(current_path);
|
||||
char* path = realpath(String::format("%s/%s", dir_path, href.characters()).characters(), nullptr);
|
||||
|
@ -173,8 +173,8 @@ int main(int argc, char* argv[])
|
|||
go_back_action->set_enabled(false);
|
||||
go_forward_action->set_enabled(false);
|
||||
|
||||
toolbar->add_action(*go_back_action);
|
||||
toolbar->add_action(*go_forward_action);
|
||||
toolbar.add_action(*go_back_action);
|
||||
toolbar.add_action(*go_forward_action);
|
||||
|
||||
auto menubar = make<GUI::MenuBar>();
|
||||
|
||||
|
@ -195,7 +195,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
app.set_menubar(move(menubar));
|
||||
|
||||
window->set_focused_widget(tree_view);
|
||||
window->set_focused_widget(&tree_view);
|
||||
window->show();
|
||||
|
||||
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/book.png"));
|
||||
|
|
|
@ -94,12 +94,12 @@ void IRCAppWindow::setup_client()
|
|||
};
|
||||
|
||||
if (m_client->hostname().is_empty()) {
|
||||
auto input_box = add<GUI::InputBox>("Enter server:", "Connect to server");
|
||||
auto result = input_box->exec();
|
||||
auto& input_box = add<GUI::InputBox>("Enter server:", "Connect to server");
|
||||
auto result = input_box.exec();
|
||||
if (result == GUI::InputBox::ExecCancel)
|
||||
::exit(0);
|
||||
|
||||
m_client->set_server(input_box->text_value(), 6667);
|
||||
m_client->set_server(input_box.text_value(), 6667);
|
||||
}
|
||||
update_title();
|
||||
bool success = m_client->connect();
|
||||
|
@ -109,9 +109,9 @@ void IRCAppWindow::setup_client()
|
|||
void IRCAppWindow::setup_actions()
|
||||
{
|
||||
m_join_action = GUI::Action::create("Join channel", { Mod_Ctrl, Key_J }, Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-join.png"), [&](auto&) {
|
||||
auto input_box = add<GUI::InputBox>("Enter channel name:", "Join channel");
|
||||
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty())
|
||||
m_client->handle_join_action(input_box->text_value());
|
||||
auto& input_box = add<GUI::InputBox>("Enter channel name:", "Join channel");
|
||||
if (input_box.exec() == GUI::InputBox::ExecOK && !input_box.text_value().is_empty())
|
||||
m_client->handle_join_action(input_box.text_value());
|
||||
});
|
||||
|
||||
m_part_action = GUI::Action::create("Part from channel", { Mod_Ctrl, Key_P }, Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-part.png"), [this](auto&) {
|
||||
|
@ -184,24 +184,24 @@ void IRCAppWindow::setup_widgets()
|
|||
widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
widget.layout()->set_spacing(0);
|
||||
|
||||
auto toolbar = widget.add<GUI::ToolBar>();
|
||||
toolbar->set_has_frame(false);
|
||||
toolbar->add_action(*m_change_nick_action);
|
||||
toolbar->add_separator();
|
||||
toolbar->add_action(*m_join_action);
|
||||
toolbar->add_action(*m_part_action);
|
||||
toolbar->add_separator();
|
||||
toolbar->add_action(*m_whois_action);
|
||||
toolbar->add_action(*m_open_query_action);
|
||||
toolbar->add_action(*m_close_query_action);
|
||||
auto& toolbar = widget.add<GUI::ToolBar>();
|
||||
toolbar.set_has_frame(false);
|
||||
toolbar.add_action(*m_change_nick_action);
|
||||
toolbar.add_separator();
|
||||
toolbar.add_action(*m_join_action);
|
||||
toolbar.add_action(*m_part_action);
|
||||
toolbar.add_separator();
|
||||
toolbar.add_action(*m_whois_action);
|
||||
toolbar.add_action(*m_open_query_action);
|
||||
toolbar.add_action(*m_close_query_action);
|
||||
|
||||
auto outer_container = widget.add<GUI::Widget>();
|
||||
outer_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
outer_container->layout()->set_margins({ 2, 0, 2, 2 });
|
||||
auto& outer_container = widget.add<GUI::Widget>();
|
||||
outer_container.set_layout<GUI::VerticalBoxLayout>();
|
||||
outer_container.layout()->set_margins({ 2, 0, 2, 2 });
|
||||
|
||||
auto horizontal_container = outer_container->add<GUI::HorizontalSplitter>();
|
||||
auto& horizontal_container = outer_container.add<GUI::HorizontalSplitter>();
|
||||
|
||||
m_window_list = horizontal_container->add<GUI::TableView>();
|
||||
m_window_list = horizontal_container.add<GUI::TableView>();
|
||||
m_window_list->set_headers_visible(false);
|
||||
m_window_list->set_alternating_row_colors(false);
|
||||
m_window_list->set_size_columns_to_fit_content(true);
|
||||
|
@ -213,7 +213,7 @@ void IRCAppWindow::setup_widgets()
|
|||
set_active_window(m_client->window_at(index.row()));
|
||||
};
|
||||
|
||||
m_container = horizontal_container->add<GUI::StackWidget>();
|
||||
m_container = horizontal_container.add<GUI::StackWidget>();
|
||||
m_container->on_active_widget_change = [this](auto*) {
|
||||
update_part_action();
|
||||
};
|
||||
|
|
|
@ -44,18 +44,18 @@ IRCWindow::IRCWindow(IRCClient& client, void* owner, Type type, const String& na
|
|||
set_layout<GUI::VerticalBoxLayout>();
|
||||
|
||||
// Make a container for the log buffer view + (optional) member list.
|
||||
auto container = add<GUI::HorizontalSplitter>();
|
||||
auto& container = add<GUI::HorizontalSplitter>();
|
||||
|
||||
m_html_view = container->add<HtmlView>();
|
||||
m_html_view = container.add<HtmlView>();
|
||||
|
||||
if (m_type == Channel) {
|
||||
auto member_view = container->add<GUI::TableView>();
|
||||
member_view->set_headers_visible(false);
|
||||
member_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
member_view->set_preferred_size(100, 0);
|
||||
member_view->set_alternating_row_colors(false);
|
||||
member_view->set_model(channel().member_model());
|
||||
member_view->set_activates_on_selection(true);
|
||||
auto& member_view = container.add<GUI::TableView>();
|
||||
member_view.set_headers_visible(false);
|
||||
member_view.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
member_view.set_preferred_size(100, 0);
|
||||
member_view.set_alternating_row_colors(false);
|
||||
member_view.set_model(channel().member_model());
|
||||
member_view.set_activates_on_selection(true);
|
||||
}
|
||||
|
||||
m_text_editor = add<GUI::TextBox>();
|
||||
|
|
|
@ -99,25 +99,25 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget)
|
|||
set_secondary_color(color);
|
||||
};
|
||||
|
||||
auto color_container = add<GUI::Widget>();
|
||||
color_container->set_relative_rect(m_secondary_color_widget->relative_rect().right() + 2, 2, 500, 32);
|
||||
color_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
color_container->layout()->set_spacing(1);
|
||||
auto& color_container = add<GUI::Widget>();
|
||||
color_container.set_relative_rect(m_secondary_color_widget->relative_rect().right() + 2, 2, 500, 32);
|
||||
color_container.set_layout<GUI::VerticalBoxLayout>();
|
||||
color_container.layout()->set_spacing(1);
|
||||
|
||||
auto top_color_container = color_container->add<GUI::Widget>();
|
||||
top_color_container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
top_color_container->layout()->set_spacing(1);
|
||||
auto& top_color_container = color_container.add<GUI::Widget>();
|
||||
top_color_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
top_color_container.layout()->set_spacing(1);
|
||||
|
||||
auto bottom_color_container = color_container->add<GUI::Widget>();
|
||||
bottom_color_container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
bottom_color_container->layout()->set_spacing(1);
|
||||
auto& bottom_color_container = color_container.add<GUI::Widget>();
|
||||
bottom_color_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
bottom_color_container.layout()->set_spacing(1);
|
||||
|
||||
auto add_color_widget = [&](GUI::Widget* container, Color color) {
|
||||
auto color_widget = container->add<ColorWidget>(color, *this);
|
||||
color_widget->set_fill_with_background_color(true);
|
||||
auto pal = color_widget->palette();
|
||||
auto add_color_widget = [&](GUI::Widget& container, Color color) {
|
||||
auto& color_widget = container.add<ColorWidget>(color, *this);
|
||||
color_widget.set_fill_with_background_color(true);
|
||||
auto pal = color_widget.palette();
|
||||
pal.set_color(ColorRole::Background, color);
|
||||
color_widget->set_palette(pal);
|
||||
color_widget.set_palette(pal);
|
||||
};
|
||||
|
||||
add_color_widget(top_color_container, Color::from_rgb(0x000000));
|
||||
|
|
|
@ -74,15 +74,15 @@ ToolboxWidget::ToolboxWidget()
|
|||
layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto add_tool = [&](const StringView& name, const StringView& icon_name, OwnPtr<Tool>&& tool) {
|
||||
auto button = add<ToolButton>(name, move(tool));
|
||||
button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
button->set_preferred_size(0, 32);
|
||||
button->set_checkable(true);
|
||||
button->set_exclusive(true);
|
||||
auto& button = add<ToolButton>(name, move(tool));
|
||||
button.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
button.set_preferred_size(0, 32);
|
||||
button.set_checkable(true);
|
||||
button.set_exclusive(true);
|
||||
|
||||
button->set_icon(Gfx::Bitmap::load_from_file(String::format("/res/icons/paintbrush/%s.png", String(icon_name).characters())));
|
||||
button.set_icon(Gfx::Bitmap::load_from_file(String::format("/res/icons/paintbrush/%s.png", String(icon_name).characters())));
|
||||
|
||||
button->on_checked = [button = button.ptr()](auto checked) {
|
||||
button.on_checked = [button = &button](auto checked) {
|
||||
if (checked)
|
||||
PaintableWidget::the().set_tool(&button->tool());
|
||||
else
|
||||
|
|
|
@ -64,13 +64,13 @@ int main(int argc, char** argv)
|
|||
|
||||
horizontal_container.add<ToolboxWidget>();
|
||||
|
||||
auto vertical_container = horizontal_container.add<GUI::Widget>();
|
||||
vertical_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
vertical_container->layout()->set_spacing(0);
|
||||
auto& vertical_container = horizontal_container.add<GUI::Widget>();
|
||||
vertical_container.set_layout<GUI::VerticalBoxLayout>();
|
||||
vertical_container.layout()->set_spacing(0);
|
||||
|
||||
auto paintable_widget = vertical_container->add<PaintableWidget>();
|
||||
paintable_widget->set_focus(true);
|
||||
vertical_container->add<PaletteWidget>(*paintable_widget);
|
||||
auto& paintable_widget = vertical_container.add<PaintableWidget>();
|
||||
paintable_widget.set_focus(true);
|
||||
vertical_container.add<PaletteWidget>(paintable_widget);
|
||||
|
||||
window->show();
|
||||
|
||||
|
@ -88,7 +88,7 @@ int main(int argc, char** argv)
|
|||
GUI::MessageBox::show(String::format("Failed to load '%s'", open_path.value().characters()), "Open failed", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window);
|
||||
return;
|
||||
}
|
||||
paintable_widget->set_bitmap(*bitmap);
|
||||
paintable_widget.set_bitmap(*bitmap);
|
||||
}));
|
||||
app_menu->add_separator();
|
||||
app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
||||
|
|
|
@ -41,24 +41,24 @@ SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, NonnullRefPtr<Audio::C
|
|||
set_layout<GUI::VerticalBoxLayout>();
|
||||
layout()->set_margins({ 2, 2, 2, 2 });
|
||||
|
||||
auto status_widget = add<GUI::Widget>();
|
||||
status_widget->set_fill_with_background_color(true);
|
||||
status_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
auto& status_widget = add<GUI::Widget>();
|
||||
status_widget.set_fill_with_background_color(true);
|
||||
status_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
m_elapsed = status_widget->add<GUI::Label>();
|
||||
m_elapsed = status_widget.add<GUI::Label>();
|
||||
m_elapsed->set_frame_shape(Gfx::FrameShape::Container);
|
||||
m_elapsed->set_frame_shadow(Gfx::FrameShadow::Sunken);
|
||||
m_elapsed->set_frame_thickness(2);
|
||||
m_elapsed->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
m_elapsed->set_preferred_size(80, 0);
|
||||
|
||||
auto sample_widget_container = status_widget->add<GUI::Widget>();
|
||||
sample_widget_container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
sample_widget_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
auto& sample_widget_container = status_widget.add<GUI::Widget>();
|
||||
sample_widget_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
sample_widget_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
|
||||
m_sample_widget = sample_widget_container->add<SampleWidget>();
|
||||
m_sample_widget = sample_widget_container.add<SampleWidget>();
|
||||
|
||||
m_remaining = status_widget->add<GUI::Label>();
|
||||
m_remaining = status_widget.add<GUI::Label>();
|
||||
m_remaining->set_frame_shape(Gfx::FrameShape::Container);
|
||||
m_remaining->set_frame_shadow(Gfx::FrameShadow::Sunken);
|
||||
m_remaining->set_frame_thickness(2);
|
||||
|
@ -70,22 +70,22 @@ SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, NonnullRefPtr<Audio::C
|
|||
m_slider->set_enabled(false);
|
||||
m_slider->on_knob_released = [&](int value) { m_manager.seek(denormalize_rate(value)); };
|
||||
|
||||
auto control_widget = add<GUI::Widget>();
|
||||
control_widget->set_fill_with_background_color(true);
|
||||
control_widget->set_layout<GUI::HorizontalBoxLayout>();
|
||||
control_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
control_widget->set_preferred_size(0, 30);
|
||||
control_widget->layout()->set_margins({ 10, 2, 10, 2 });
|
||||
control_widget->layout()->set_spacing(10);
|
||||
auto& control_widget = add<GUI::Widget>();
|
||||
control_widget.set_fill_with_background_color(true);
|
||||
control_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
control_widget.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
control_widget.set_preferred_size(0, 30);
|
||||
control_widget.layout()->set_margins({ 10, 2, 10, 2 });
|
||||
control_widget.layout()->set_spacing(10);
|
||||
|
||||
m_play = control_widget->add<GUI::Button>();
|
||||
m_play = control_widget.add<GUI::Button>();
|
||||
m_play->set_icon(*m_pause_icon);
|
||||
m_play->set_enabled(false);
|
||||
m_play->on_click = [this] {
|
||||
m_play->set_icon(m_manager.toggle_pause() ? *m_play_icon : *m_pause_icon);
|
||||
};
|
||||
|
||||
m_stop = control_widget->add<GUI::Button>();
|
||||
m_stop = control_widget.add<GUI::Button>();
|
||||
m_stop->set_enabled(false);
|
||||
m_stop->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/stop.png"));
|
||||
m_stop->on_click = [this] { m_manager.stop(); };
|
||||
|
|
|
@ -75,43 +75,43 @@ PowerDialog::PowerDialog()
|
|||
main.layout()->set_spacing(8);
|
||||
main.set_fill_with_background_color(true);
|
||||
|
||||
auto header = main.add<GUI::Label>();
|
||||
header->set_text("What would you like to do?");
|
||||
header->set_preferred_size(0, 16);
|
||||
header->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
header->set_font(Gfx::Font::default_bold_font());
|
||||
auto& header = main.add<GUI::Label>();
|
||||
header.set_text("What would you like to do?");
|
||||
header.set_preferred_size(0, 16);
|
||||
header.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
header.set_font(Gfx::Font::default_bold_font());
|
||||
|
||||
for (size_t i = 0; i < options.size(); i++) {
|
||||
auto action = options[i];
|
||||
auto radio = main.add<GUI::RadioButton>();
|
||||
radio->set_enabled(action.enabled);
|
||||
radio->set_text(action.title);
|
||||
auto& radio = main.add<GUI::RadioButton>();
|
||||
radio.set_enabled(action.enabled);
|
||||
radio.set_text(action.title);
|
||||
|
||||
radio->on_checked = [this, i](auto) {
|
||||
radio.on_checked = [this, i](auto) {
|
||||
m_selected_option = i;
|
||||
};
|
||||
|
||||
if (action.default_action) {
|
||||
radio->set_checked(true);
|
||||
radio.set_checked(true);
|
||||
m_selected_option = i;
|
||||
}
|
||||
}
|
||||
|
||||
auto button_box = main.add<GUI::Widget>();
|
||||
button_box->set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_box->layout()->set_spacing(8);
|
||||
auto& button_box = main.add<GUI::Widget>();
|
||||
button_box.set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_box.layout()->set_spacing(8);
|
||||
|
||||
auto ok_button = button_box->add<GUI::Button>();
|
||||
ok_button->on_click = [this] {
|
||||
auto& ok_button = button_box.add<GUI::Button>();
|
||||
ok_button.on_click = [this] {
|
||||
done(m_selected_option);
|
||||
};
|
||||
ok_button->set_text("OK");
|
||||
ok_button.set_text("OK");
|
||||
|
||||
auto cancel_button = button_box->add<GUI::Button>();
|
||||
cancel_button->on_click = [this] {
|
||||
auto& cancel_button = button_box.add<GUI::Button>();
|
||||
cancel_button.on_click = [this] {
|
||||
done(-1);
|
||||
};
|
||||
cancel_button->set_text("Cancel");
|
||||
cancel_button.set_text("Cancel");
|
||||
}
|
||||
|
||||
PowerDialog::~PowerDialog()
|
||||
|
|
|
@ -57,15 +57,15 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph)
|
|||
layout()->set_spacing(3);
|
||||
|
||||
auto build_widgets_for_label = [this](const String& description) -> RefPtr<GUI::Label> {
|
||||
auto container = add<GUI::Widget>();
|
||||
container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
container->set_preferred_size(275, 12);
|
||||
auto description_label = container->add<GUI::Label>(description);
|
||||
description_label->set_font(Gfx::Font::default_bold_font());
|
||||
description_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
auto label = container->add<GUI::Label>();
|
||||
label->set_text_alignment(Gfx::TextAlignment::CenterRight);
|
||||
auto& container = add<GUI::Widget>();
|
||||
container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
container.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
container.set_preferred_size(275, 12);
|
||||
auto& description_label = container.add<GUI::Label>(description);
|
||||
description_label.set_font(Gfx::Font::default_bold_font());
|
||||
description_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
auto& label = container.add<GUI::Label>();
|
||||
label.set_text_alignment(Gfx::TextAlignment::CenterRight);
|
||||
return label;
|
||||
};
|
||||
|
||||
|
|
|
@ -37,13 +37,13 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
|
|||
layout()->set_margins({ 4, 4, 4, 4 });
|
||||
set_fill_with_background_color(true);
|
||||
|
||||
auto adapters_group_box = add<GUI::GroupBox>("Adapters");
|
||||
adapters_group_box->set_layout<GUI::VerticalBoxLayout>();
|
||||
adapters_group_box->layout()->set_margins({ 6, 16, 6, 6 });
|
||||
adapters_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
adapters_group_box->set_preferred_size(0, 120);
|
||||
auto& adapters_group_box = add<GUI::GroupBox>("Adapters");
|
||||
adapters_group_box.set_layout<GUI::VerticalBoxLayout>();
|
||||
adapters_group_box.layout()->set_margins({ 6, 16, 6, 6 });
|
||||
adapters_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
adapters_group_box.set_preferred_size(0, 120);
|
||||
|
||||
m_adapter_table_view = adapters_group_box->add<GUI::TableView>();
|
||||
m_adapter_table_view = adapters_group_box.add<GUI::TableView>();
|
||||
m_adapter_table_view->set_size_columns_to_fit_content(true);
|
||||
|
||||
Vector<GUI::JsonArrayModel::FieldSpec> net_adapters_fields;
|
||||
|
@ -57,13 +57,13 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
|
|||
net_adapters_fields.empend("bytes_out", "Bytes Out", Gfx::TextAlignment::CenterRight);
|
||||
m_adapter_table_view->set_model(GUI::JsonArrayModel::create("/proc/net/adapters", move(net_adapters_fields)));
|
||||
|
||||
auto sockets_group_box = add<GUI::GroupBox>("Sockets");
|
||||
sockets_group_box->set_layout<GUI::VerticalBoxLayout>();
|
||||
sockets_group_box->layout()->set_margins({ 6, 16, 6, 6 });
|
||||
sockets_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
sockets_group_box->set_preferred_size(0, 0);
|
||||
auto& sockets_group_box = add<GUI::GroupBox>("Sockets");
|
||||
sockets_group_box.set_layout<GUI::VerticalBoxLayout>();
|
||||
sockets_group_box.layout()->set_margins({ 6, 16, 6, 6 });
|
||||
sockets_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
sockets_group_box.set_preferred_size(0, 0);
|
||||
|
||||
m_socket_table_view = sockets_group_box->add<GUI::TableView>();
|
||||
m_socket_table_view = sockets_group_box.add<GUI::TableView>();
|
||||
m_socket_table_view->set_size_columns_to_fit_content(true);
|
||||
|
||||
Vector<GUI::JsonArrayModel::FieldSpec> net_tcp_fields;
|
||||
|
|
|
@ -120,59 +120,59 @@ int main(int argc, char** argv)
|
|||
keeper.set_fill_with_background_color(true);
|
||||
keeper.layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto tabwidget = keeper.add<GUI::TabWidget>();
|
||||
auto& tabwidget = keeper.add<GUI::TabWidget>();
|
||||
|
||||
auto process_container_splitter = tabwidget->add_tab<GUI::VerticalSplitter>("Processes");
|
||||
auto process_container_splitter = tabwidget.add_tab<GUI::VerticalSplitter>("Processes");
|
||||
|
||||
auto process_table_container = process_container_splitter->add<GUI::Widget>();
|
||||
auto& process_table_container = process_container_splitter->add<GUI::Widget>();
|
||||
|
||||
tabwidget->add_widget("Graphs", build_graphs_tab());
|
||||
tabwidget.add_widget("Graphs", build_graphs_tab());
|
||||
|
||||
tabwidget->add_widget("File systems", build_file_systems_tab());
|
||||
tabwidget.add_widget("File systems", build_file_systems_tab());
|
||||
|
||||
tabwidget->add_widget("PCI devices", build_pci_devices_tab());
|
||||
tabwidget.add_widget("PCI devices", build_pci_devices_tab());
|
||||
|
||||
tabwidget->add_widget("Devices", build_devices_tab());
|
||||
tabwidget.add_widget("Devices", build_devices_tab());
|
||||
|
||||
auto network_stats_widget = NetworkStatisticsWidget::construct();
|
||||
tabwidget->add_widget("Network", network_stats_widget);
|
||||
tabwidget.add_widget("Network", network_stats_widget);
|
||||
|
||||
process_table_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
process_table_container->layout()->set_margins({ 4, 0, 4, 0 });
|
||||
process_table_container->layout()->set_spacing(0);
|
||||
process_table_container.set_layout<GUI::VerticalBoxLayout>();
|
||||
process_table_container.layout()->set_margins({ 4, 0, 4, 0 });
|
||||
process_table_container.layout()->set_spacing(0);
|
||||
|
||||
auto toolbar = process_table_container->add<GUI::ToolBar>();
|
||||
toolbar->set_has_frame(false);
|
||||
auto process_table_view = process_table_container->add<ProcessTableView>();
|
||||
auto& toolbar = process_table_container.add<GUI::ToolBar>();
|
||||
toolbar.set_has_frame(false);
|
||||
auto& process_table_view = process_table_container.add<ProcessTableView>();
|
||||
|
||||
auto refresh_timer = window->add<Core::Timer>(
|
||||
auto& refresh_timer = window->add<Core::Timer>(
|
||||
1000, [&] {
|
||||
process_table_view->refresh();
|
||||
process_table_view.refresh();
|
||||
if (auto* memory_stats_widget = MemoryStatsWidget::the())
|
||||
memory_stats_widget->refresh();
|
||||
});
|
||||
|
||||
auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [process_table_view](const GUI::Action&) {
|
||||
pid_t pid = process_table_view->selected_pid();
|
||||
auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [&process_table_view](const GUI::Action&) {
|
||||
pid_t pid = process_table_view.selected_pid();
|
||||
if (pid != -1)
|
||||
kill(pid, SIGKILL);
|
||||
});
|
||||
|
||||
auto stop_action = GUI::Action::create("Stop process", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/stop16.png"), [process_table_view](const GUI::Action&) {
|
||||
pid_t pid = process_table_view->selected_pid();
|
||||
auto stop_action = GUI::Action::create("Stop process", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/stop16.png"), [&process_table_view](const GUI::Action&) {
|
||||
pid_t pid = process_table_view.selected_pid();
|
||||
if (pid != -1)
|
||||
kill(pid, SIGSTOP);
|
||||
});
|
||||
|
||||
auto continue_action = GUI::Action::create("Continue process", { Mod_Ctrl, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/continue16.png"), [process_table_view](const GUI::Action&) {
|
||||
pid_t pid = process_table_view->selected_pid();
|
||||
auto continue_action = GUI::Action::create("Continue process", { Mod_Ctrl, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/continue16.png"), [&process_table_view](const GUI::Action&) {
|
||||
pid_t pid = process_table_view.selected_pid();
|
||||
if (pid != -1)
|
||||
kill(pid, SIGCONT);
|
||||
});
|
||||
|
||||
toolbar->add_action(kill_action);
|
||||
toolbar->add_action(stop_action);
|
||||
toolbar->add_action(continue_action);
|
||||
toolbar.add_action(kill_action);
|
||||
toolbar.add_action(stop_action);
|
||||
toolbar.add_action(continue_action);
|
||||
|
||||
auto menubar = make<GUI::MenuBar>();
|
||||
auto app_menu = GUI::Menu::construct("System Monitor");
|
||||
|
@ -192,7 +192,7 @@ int main(int argc, char** argv)
|
|||
process_context_menu->add_action(kill_action);
|
||||
process_context_menu->add_action(stop_action);
|
||||
process_context_menu->add_action(continue_action);
|
||||
process_table_view->on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
|
||||
process_table_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
|
||||
(void)index;
|
||||
process_context_menu->popup(event.screen_position());
|
||||
};
|
||||
|
@ -203,7 +203,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto make_frequency_action = [&](auto& title, int interval, bool checked = false) {
|
||||
auto action = GUI::Action::create(title, [&refresh_timer, interval](auto& action) {
|
||||
refresh_timer->restart(interval);
|
||||
refresh_timer.restart(interval);
|
||||
action.set_checked(true);
|
||||
});
|
||||
action->set_checkable(true);
|
||||
|
@ -228,14 +228,14 @@ int main(int argc, char** argv)
|
|||
|
||||
app.set_menubar(move(menubar));
|
||||
|
||||
auto process_tab_widget = process_container_splitter->add<GUI::TabWidget>();
|
||||
auto& process_tab_widget = process_container_splitter->add<GUI::TabWidget>();
|
||||
|
||||
auto memory_map_widget = process_tab_widget->add_tab<ProcessMemoryMapWidget>("Memory map");
|
||||
auto open_files_widget = process_tab_widget->add_tab<ProcessFileDescriptorMapWidget>("Open files");
|
||||
auto unveiled_paths_widget = process_tab_widget->add_tab<ProcessUnveiledPathsWidget>("Unveiled paths");
|
||||
auto stacks_widget = process_tab_widget->add_tab<ProcessStacksWidget>("Stacks");
|
||||
auto memory_map_widget = process_tab_widget.add_tab<ProcessMemoryMapWidget>("Memory map");
|
||||
auto open_files_widget = process_tab_widget.add_tab<ProcessFileDescriptorMapWidget>("Open files");
|
||||
auto unveiled_paths_widget = process_tab_widget.add_tab<ProcessUnveiledPathsWidget>("Unveiled paths");
|
||||
auto stacks_widget = process_tab_widget.add_tab<ProcessStacksWidget>("Stacks");
|
||||
|
||||
process_table_view->on_process_selected = [&](pid_t pid) {
|
||||
process_table_view.on_process_selected = [&](pid_t pid) {
|
||||
open_files_widget->set_pid(pid);
|
||||
stacks_widget->set_pid(pid);
|
||||
memory_map_widget->set_pid(pid);
|
||||
|
@ -274,8 +274,8 @@ NonnullRefPtr<GUI::Widget> build_file_systems_tab()
|
|||
fs_widget->on_first_show = [](GUI::LazyWidget& self) {
|
||||
self.set_layout<GUI::VerticalBoxLayout>();
|
||||
self.layout()->set_margins({ 4, 4, 4, 4 });
|
||||
auto fs_table_view = self.add<GUI::TableView>();
|
||||
fs_table_view->set_size_columns_to_fit_content(true);
|
||||
auto& fs_table_view = self.add<GUI::TableView>();
|
||||
fs_table_view.set_size_columns_to_fit_content(true);
|
||||
|
||||
Vector<GUI::JsonArrayModel::FieldSpec> df_fields;
|
||||
df_fields.empend("mount_point", "Mount point", Gfx::TextAlignment::CenterLeft);
|
||||
|
@ -351,11 +351,11 @@ NonnullRefPtr<GUI::Widget> build_file_systems_tab()
|
|||
df_fields.empend("free_inode_count", "Free inodes", Gfx::TextAlignment::CenterRight);
|
||||
df_fields.empend("total_inode_count", "Total inodes", Gfx::TextAlignment::CenterRight);
|
||||
df_fields.empend("block_size", "Block size", Gfx::TextAlignment::CenterRight);
|
||||
fs_table_view->set_model(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/df", move(df_fields))));
|
||||
fs_table_view.set_model(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/df", move(df_fields))));
|
||||
|
||||
fs_table_view->set_cell_painting_delegate(3, make<ProgressBarPaintingDelegate>());
|
||||
fs_table_view.set_cell_painting_delegate(3, make<ProgressBarPaintingDelegate>());
|
||||
|
||||
fs_table_view->model()->update();
|
||||
fs_table_view.model()->update();
|
||||
};
|
||||
return fs_widget;
|
||||
}
|
||||
|
@ -367,8 +367,8 @@ NonnullRefPtr<GUI::Widget> build_pci_devices_tab()
|
|||
pci_widget->on_first_show = [](GUI::LazyWidget& self) {
|
||||
self.set_layout<GUI::VerticalBoxLayout>();
|
||||
self.layout()->set_margins({ 4, 4, 4, 4 });
|
||||
auto pci_table_view = self.add<GUI::TableView>();
|
||||
pci_table_view->set_size_columns_to_fit_content(true);
|
||||
auto& pci_table_view = self.add<GUI::TableView>();
|
||||
pci_table_view.set_size_columns_to_fit_content(true);
|
||||
|
||||
auto db = PCIDB::Database::open();
|
||||
|
||||
|
@ -411,8 +411,8 @@ NonnullRefPtr<GUI::Widget> build_pci_devices_tab()
|
|||
return String::format("%02x", revision_id);
|
||||
});
|
||||
|
||||
pci_table_view->set_model(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/pci", move(pci_fields))));
|
||||
pci_table_view->model()->update();
|
||||
pci_table_view.set_model(GUI::SortingProxyModel::create(GUI::JsonArrayModel::create("/proc/pci", move(pci_fields))));
|
||||
pci_table_view.model()->update();
|
||||
};
|
||||
|
||||
return pci_widget;
|
||||
|
@ -426,10 +426,10 @@ NonnullRefPtr<GUI::Widget> build_devices_tab()
|
|||
self.set_layout<GUI::VerticalBoxLayout>();
|
||||
self.layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto devices_table_view = self.add<GUI::TableView>();
|
||||
devices_table_view->set_size_columns_to_fit_content(true);
|
||||
devices_table_view->set_model(GUI::SortingProxyModel::create(DevicesModel::create()));
|
||||
devices_table_view->model()->update();
|
||||
auto& devices_table_view = self.add<GUI::TableView>();
|
||||
devices_table_view.set_size_columns_to_fit_content(true);
|
||||
devices_table_view.set_model(GUI::SortingProxyModel::create(DevicesModel::create()));
|
||||
devices_table_view.model()->update();
|
||||
};
|
||||
|
||||
return devices_widget;
|
||||
|
@ -445,36 +445,36 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab()
|
|||
self.set_layout<GUI::VerticalBoxLayout>();
|
||||
self.layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto cpu_graph_group_box = self.add<GUI::GroupBox>("CPU usage");
|
||||
cpu_graph_group_box->set_layout<GUI::VerticalBoxLayout>();
|
||||
cpu_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 });
|
||||
cpu_graph_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
cpu_graph_group_box->set_preferred_size(0, 120);
|
||||
auto cpu_graph = cpu_graph_group_box->add<GraphWidget>();
|
||||
cpu_graph->set_max(100);
|
||||
cpu_graph->set_text_color(Color::Green);
|
||||
cpu_graph->set_graph_color(Color::from_rgb(0x00bb00));
|
||||
cpu_graph->text_formatter = [](int value, int) {
|
||||
auto& cpu_graph_group_box = self.add<GUI::GroupBox>("CPU usage");
|
||||
cpu_graph_group_box.set_layout<GUI::VerticalBoxLayout>();
|
||||
cpu_graph_group_box.layout()->set_margins({ 6, 16, 6, 6 });
|
||||
cpu_graph_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
cpu_graph_group_box.set_preferred_size(0, 120);
|
||||
auto& cpu_graph = cpu_graph_group_box.add<GraphWidget>();
|
||||
cpu_graph.set_max(100);
|
||||
cpu_graph.set_text_color(Color::Green);
|
||||
cpu_graph.set_graph_color(Color::from_rgb(0x00bb00));
|
||||
cpu_graph.text_formatter = [](int value, int) {
|
||||
return String::format("%d%%", value);
|
||||
};
|
||||
|
||||
ProcessModel::the().on_new_cpu_data_point = [graph = cpu_graph.ptr()](float cpu_percent) {
|
||||
ProcessModel::the().on_new_cpu_data_point = [graph = &cpu_graph](float cpu_percent) {
|
||||
graph->add_value(cpu_percent);
|
||||
};
|
||||
|
||||
auto memory_graph_group_box = self.add<GUI::GroupBox>("Memory usage");
|
||||
memory_graph_group_box->set_layout<GUI::VerticalBoxLayout>();
|
||||
memory_graph_group_box->layout()->set_margins({ 6, 16, 6, 6 });
|
||||
memory_graph_group_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
memory_graph_group_box->set_preferred_size(0, 120);
|
||||
auto memory_graph = memory_graph_group_box->add<GraphWidget>();
|
||||
memory_graph->set_text_color(Color::Cyan);
|
||||
memory_graph->set_graph_color(Color::from_rgb(0x00bbbb));
|
||||
memory_graph->text_formatter = [](int value, int max) {
|
||||
auto& memory_graph_group_box = self.add<GUI::GroupBox>("Memory usage");
|
||||
memory_graph_group_box.set_layout<GUI::VerticalBoxLayout>();
|
||||
memory_graph_group_box.layout()->set_margins({ 6, 16, 6, 6 });
|
||||
memory_graph_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
memory_graph_group_box.set_preferred_size(0, 120);
|
||||
auto& memory_graph = memory_graph_group_box.add<GraphWidget>();
|
||||
memory_graph.set_text_color(Color::Cyan);
|
||||
memory_graph.set_graph_color(Color::from_rgb(0x00bbbb));
|
||||
memory_graph.text_formatter = [](int value, int max) {
|
||||
return String::format("%d / %d KB", value, max);
|
||||
};
|
||||
|
||||
auto memory_stats_widget = self.add<MemoryStatsWidget>(*memory_graph);
|
||||
self.add<MemoryStatsWidget>(memory_graph);
|
||||
};
|
||||
return graphs_container;
|
||||
}
|
||||
|
|
|
@ -68,14 +68,14 @@ TaskbarWindow::~TaskbarWindow()
|
|||
|
||||
void TaskbarWindow::create_quick_launch_bar()
|
||||
{
|
||||
auto quick_launch_bar = main_widget()->add<GUI::Frame>();
|
||||
quick_launch_bar->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
quick_launch_bar->set_layout<GUI::HorizontalBoxLayout>();
|
||||
quick_launch_bar->layout()->set_spacing(3);
|
||||
quick_launch_bar->layout()->set_margins({ 3, 0, 3, 0 });
|
||||
quick_launch_bar->set_frame_thickness(1);
|
||||
quick_launch_bar->set_frame_shape(Gfx::FrameShape::Container);
|
||||
quick_launch_bar->set_frame_shadow(Gfx::FrameShadow::Raised);
|
||||
auto& quick_launch_bar = main_widget()->add<GUI::Frame>();
|
||||
quick_launch_bar.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
quick_launch_bar.set_layout<GUI::HorizontalBoxLayout>();
|
||||
quick_launch_bar.layout()->set_spacing(3);
|
||||
quick_launch_bar.layout()->set_margins({ 3, 0, 3, 0 });
|
||||
quick_launch_bar.set_frame_thickness(1);
|
||||
quick_launch_bar.set_frame_shape(Gfx::FrameShape::Container);
|
||||
quick_launch_bar.set_frame_shadow(Gfx::FrameShadow::Raised);
|
||||
|
||||
int total_width = 6;
|
||||
bool first = true;
|
||||
|
@ -92,15 +92,15 @@ void TaskbarWindow::create_quick_launch_bar()
|
|||
auto app_executable = af->read_entry("App", "Executable");
|
||||
auto app_icon_path = af->read_entry("Icons", "16x16");
|
||||
|
||||
auto button = quick_launch_bar->add<GUI::Button>();
|
||||
button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
button->set_preferred_size(22, 22);
|
||||
button->set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
auto& button = quick_launch_bar.add<GUI::Button>();
|
||||
button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
button.set_preferred_size(22, 22);
|
||||
button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
|
||||
button->set_icon(Gfx::Bitmap::load_from_file(app_icon_path));
|
||||
button.set_icon(Gfx::Bitmap::load_from_file(app_icon_path));
|
||||
// FIXME: the tooltip ends up outside the screen rect.
|
||||
button->set_tooltip(name);
|
||||
button->on_click = [app_executable] {
|
||||
button.set_tooltip(name);
|
||||
button.on_click = [app_executable] {
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
|
@ -117,7 +117,7 @@ void TaskbarWindow::create_quick_launch_bar()
|
|||
total_width += 22;
|
||||
}
|
||||
|
||||
quick_launch_bar->set_preferred_size(total_width, 22);
|
||||
quick_launch_bar.set_preferred_size(total_width, 22);
|
||||
}
|
||||
|
||||
void TaskbarWindow::on_screen_rect_change(const Gfx::Rect& rect)
|
||||
|
@ -128,11 +128,11 @@ void TaskbarWindow::on_screen_rect_change(const Gfx::Rect& rect)
|
|||
|
||||
NonnullRefPtr<GUI::Button> TaskbarWindow::create_button(const WindowIdentifier& identifier)
|
||||
{
|
||||
auto button = main_widget()->add<TaskbarButton>(identifier);
|
||||
button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
button->set_preferred_size(140, 22);
|
||||
button->set_checkable(true);
|
||||
button->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
auto& button = main_widget()->add<TaskbarButton>(identifier);
|
||||
button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
button.set_preferred_size(140, 22);
|
||||
button.set_checkable(true);
|
||||
button.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
return button;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,33 +140,33 @@ RefPtr<GUI::Window> create_settings_window(TerminalWidget& terminal)
|
|||
settings.set_layout<GUI::VerticalBoxLayout>();
|
||||
settings.layout()->set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
auto radio_container = settings.add<GUI::GroupBox>("Bell Mode");
|
||||
radio_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
radio_container->layout()->set_margins({ 6, 16, 6, 6 });
|
||||
radio_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
radio_container->set_preferred_size(100, 70);
|
||||
auto& radio_container = settings.add<GUI::GroupBox>("Bell Mode");
|
||||
radio_container.set_layout<GUI::VerticalBoxLayout>();
|
||||
radio_container.layout()->set_margins({ 6, 16, 6, 6 });
|
||||
radio_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
radio_container.set_preferred_size(100, 70);
|
||||
|
||||
auto sysbell_radio = radio_container->add<GUI::RadioButton>("Use (Audible) System Bell");
|
||||
auto visbell_radio = radio_container->add<GUI::RadioButton>("Use (Visual) Terminal Bell");
|
||||
sysbell_radio->set_checked(terminal.should_beep());
|
||||
visbell_radio->set_checked(!terminal.should_beep());
|
||||
sysbell_radio->on_checked = [&terminal](const bool checked) {
|
||||
auto& sysbell_radio = radio_container.add<GUI::RadioButton>("Use (Audible) System Bell");
|
||||
auto& visbell_radio = radio_container.add<GUI::RadioButton>("Use (Visual) Terminal Bell");
|
||||
sysbell_radio.set_checked(terminal.should_beep());
|
||||
visbell_radio.set_checked(!terminal.should_beep());
|
||||
sysbell_radio.on_checked = [&terminal](const bool checked) {
|
||||
terminal.set_should_beep(checked);
|
||||
};
|
||||
|
||||
auto slider_container = settings.add<GUI::GroupBox>("Background Opacity");
|
||||
slider_container->set_layout<GUI::VerticalBoxLayout>();
|
||||
slider_container->layout()->set_margins({ 6, 16, 6, 6 });
|
||||
slider_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
slider_container->set_preferred_size(100, 50);
|
||||
auto slider = slider_container->add<GUI::HorizontalSlider>();
|
||||
auto& slider_container = settings.add<GUI::GroupBox>("Background Opacity");
|
||||
slider_container.set_layout<GUI::VerticalBoxLayout>();
|
||||
slider_container.layout()->set_margins({ 6, 16, 6, 6 });
|
||||
slider_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
slider_container.set_preferred_size(100, 50);
|
||||
auto& slider = slider_container.add<GUI::HorizontalSlider>();
|
||||
|
||||
slider->on_value_changed = [&terminal](int value) {
|
||||
slider.on_value_changed = [&terminal](int value) {
|
||||
terminal.set_opacity(value);
|
||||
};
|
||||
|
||||
slider->set_range(0, 255);
|
||||
slider->set_value(terminal.opacity());
|
||||
slider.set_range(0, 255);
|
||||
slider.set_value(terminal.opacity());
|
||||
|
||||
return window;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ TextEditorWidget::TextEditorWidget()
|
|||
set_layout<GUI::VerticalBoxLayout>();
|
||||
layout()->set_spacing(0);
|
||||
|
||||
auto toolbar = add<GUI::ToolBar>();
|
||||
auto& toolbar = add<GUI::ToolBar>();
|
||||
m_editor = add<GUI::TextEditor>();
|
||||
m_editor->set_ruler_visible(true);
|
||||
m_editor->set_automatic_indentation_enabled(true);
|
||||
|
@ -391,21 +391,21 @@ TextEditorWidget::TextEditorWidget()
|
|||
|
||||
GUI::Application::the().set_menubar(move(menubar));
|
||||
|
||||
toolbar->add_action(*m_new_action);
|
||||
toolbar->add_action(*m_open_action);
|
||||
toolbar->add_action(*m_save_action);
|
||||
toolbar.add_action(*m_new_action);
|
||||
toolbar.add_action(*m_open_action);
|
||||
toolbar.add_action(*m_save_action);
|
||||
|
||||
toolbar->add_separator();
|
||||
toolbar.add_separator();
|
||||
|
||||
toolbar->add_action(m_editor->cut_action());
|
||||
toolbar->add_action(m_editor->copy_action());
|
||||
toolbar->add_action(m_editor->paste_action());
|
||||
toolbar->add_action(m_editor->delete_action());
|
||||
toolbar.add_action(m_editor->cut_action());
|
||||
toolbar.add_action(m_editor->copy_action());
|
||||
toolbar.add_action(m_editor->paste_action());
|
||||
toolbar.add_action(m_editor->delete_action());
|
||||
|
||||
toolbar->add_separator();
|
||||
toolbar.add_separator();
|
||||
|
||||
toolbar->add_action(m_editor->undo_action());
|
||||
toolbar->add_action(m_editor->redo_action());
|
||||
toolbar.add_action(m_editor->undo_action());
|
||||
toolbar.add_action(m_editor->redo_action());
|
||||
}
|
||||
|
||||
TextEditorWidget::~TextEditorWidget()
|
||||
|
|
|
@ -69,11 +69,11 @@ private:
|
|||
|
||||
RefPtr<GUI::TextBox> m_find_textbox;
|
||||
RefPtr<GUI::TextBox> m_replace_textbox;
|
||||
GUI::Button* m_find_previous_button { nullptr };
|
||||
GUI::Button* m_find_next_button { nullptr };
|
||||
GUI::Button* m_replace_previous_button { nullptr };
|
||||
GUI::Button* m_replace_next_button { nullptr };
|
||||
GUI::Button* m_replace_all_button { nullptr };
|
||||
RefPtr<GUI::Button> m_find_previous_button;
|
||||
RefPtr<GUI::Button> m_find_next_button;
|
||||
RefPtr<GUI::Button> m_replace_previous_button;
|
||||
RefPtr<GUI::Button> m_replace_next_button;
|
||||
RefPtr<GUI::Button> m_replace_all_button;
|
||||
RefPtr<GUI::Widget> m_find_replace_widget;
|
||||
RefPtr<GUI::Widget> m_find_widget;
|
||||
RefPtr<GUI::Widget> m_replace_widget;
|
||||
|
|
|
@ -172,84 +172,84 @@ int main(int argc, char** argv)
|
|||
// header
|
||||
//
|
||||
|
||||
auto header = background.add<GUI::Label>();
|
||||
header->set_font(Gfx::Font::load_from_file("/res/fonts/PebbletonBold11.font"));
|
||||
header->set_text("Welcome to SerenityOS!");
|
||||
header->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
header->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
header->set_preferred_size(0, 30);
|
||||
auto& header = background.add<GUI::Label>();
|
||||
header.set_font(Gfx::Font::load_from_file("/res/fonts/PebbletonBold11.font"));
|
||||
header.set_text("Welcome to SerenityOS!");
|
||||
header.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
header.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
header.set_preferred_size(0, 30);
|
||||
|
||||
//
|
||||
// main section
|
||||
//
|
||||
|
||||
auto main_section = background.add<GUI::Widget>();
|
||||
main_section->set_layout<GUI::HorizontalBoxLayout>();
|
||||
main_section->layout()->set_margins({ 0, 0, 0, 0 });
|
||||
main_section->layout()->set_spacing(8);
|
||||
main_section->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
auto& main_section = background.add<GUI::Widget>();
|
||||
main_section.set_layout<GUI::HorizontalBoxLayout>();
|
||||
main_section.layout()->set_margins({ 0, 0, 0, 0 });
|
||||
main_section.layout()->set_spacing(8);
|
||||
main_section.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
|
||||
auto menu = main_section->add<GUI::Widget>();
|
||||
menu->set_layout<GUI::VerticalBoxLayout>();
|
||||
menu->layout()->set_margins({ 0, 0, 0, 0 });
|
||||
menu->layout()->set_spacing(4);
|
||||
menu->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
menu->set_preferred_size(100, 0);
|
||||
auto& menu = main_section.add<GUI::Widget>();
|
||||
menu.set_layout<GUI::VerticalBoxLayout>();
|
||||
menu.layout()->set_margins({ 0, 0, 0, 0 });
|
||||
menu.layout()->set_spacing(4);
|
||||
menu.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
menu.set_preferred_size(100, 0);
|
||||
|
||||
auto stack = main_section->add<GUI::StackWidget>();
|
||||
stack->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
auto& stack = main_section.add<GUI::StackWidget>();
|
||||
stack.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
|
||||
bool first = true;
|
||||
for (auto& page : pages) {
|
||||
auto content = stack->add<GUI::Widget>();
|
||||
content->set_layout<GUI::VerticalBoxLayout>();
|
||||
content->layout()->set_margins({ 0, 0, 0, 0 });
|
||||
content->layout()->set_spacing(8);
|
||||
content->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
auto& content = stack.add<GUI::Widget>();
|
||||
content.set_layout<GUI::VerticalBoxLayout>();
|
||||
content.layout()->set_margins({ 0, 0, 0, 0 });
|
||||
content.layout()->set_spacing(8);
|
||||
content.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||
|
||||
auto title_box = content->add<GUI::Widget>();
|
||||
title_box->set_layout<GUI::HorizontalBoxLayout>();
|
||||
title_box->layout()->set_spacing(4);
|
||||
title_box->set_preferred_size(0, 16);
|
||||
title_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
auto& title_box = content.add<GUI::Widget>();
|
||||
title_box.set_layout<GUI::HorizontalBoxLayout>();
|
||||
title_box.layout()->set_spacing(4);
|
||||
title_box.set_preferred_size(0, 16);
|
||||
title_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
|
||||
if (!page.icon.is_empty()) {
|
||||
auto icon = title_box->add<GUI::Label>();
|
||||
icon->set_icon(Gfx::Bitmap::load_from_file(page.icon));
|
||||
icon->set_preferred_size(16, 16);
|
||||
icon->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
auto& icon = title_box.add<GUI::Label>();
|
||||
icon.set_icon(Gfx::Bitmap::load_from_file(page.icon));
|
||||
icon.set_preferred_size(16, 16);
|
||||
icon.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
}
|
||||
|
||||
auto content_title = title_box->add<GUI::Label>();
|
||||
content_title->set_font(Gfx::Font::default_bold_font());
|
||||
content_title->set_text(page.title);
|
||||
content_title->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
content_title->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
content_title->set_preferred_size(0, 10);
|
||||
auto& content_title = title_box.add<GUI::Label>();
|
||||
content_title.set_font(Gfx::Font::default_bold_font());
|
||||
content_title.set_text(page.title);
|
||||
content_title.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
content_title.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
content_title.set_preferred_size(0, 10);
|
||||
|
||||
for (auto& paragraph : page.content) {
|
||||
auto content_text = content->add<TextWidget>();
|
||||
content_text->set_font(Gfx::Font::default_font());
|
||||
content_text->set_text(paragraph);
|
||||
content_text->set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||
content_text->set_line_height(12);
|
||||
content_text->wrap_and_set_height();
|
||||
auto& content_text = content.add<TextWidget>();
|
||||
content_text.set_font(Gfx::Font::default_font());
|
||||
content_text.set_text(paragraph);
|
||||
content_text.set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||
content_text.set_line_height(12);
|
||||
content_text.wrap_and_set_height();
|
||||
}
|
||||
|
||||
auto menu_option = menu->add<UnuncheckableButton>();
|
||||
menu_option->set_font(Gfx::Font::default_font());
|
||||
menu_option->set_text(page.menu_name);
|
||||
menu_option->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
menu_option->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
menu_option->set_preferred_size(0, 20);
|
||||
menu_option->set_checkable(true);
|
||||
menu_option->set_exclusive(true);
|
||||
auto& menu_option = menu.add<UnuncheckableButton>();
|
||||
menu_option.set_font(Gfx::Font::default_font());
|
||||
menu_option.set_text(page.menu_name);
|
||||
menu_option.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
menu_option.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
menu_option.set_preferred_size(0, 20);
|
||||
menu_option.set_checkable(true);
|
||||
menu_option.set_exclusive(true);
|
||||
|
||||
if (first)
|
||||
menu_option->set_checked(true);
|
||||
menu_option.set_checked(true);
|
||||
|
||||
menu_option->on_click = [content = content.ptr(), &stack] {
|
||||
stack->set_active_widget(content);
|
||||
menu_option.on_click = [content = &content, &stack] {
|
||||
stack.set_active_widget(content);
|
||||
content->invalidate_layout();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue