mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:07:35 +00:00
Userspace: Use Core::Object::add() when building interfaces
This commit is contained in:
parent
7ec758773c
commit
3d20da9ee4
87 changed files with 403 additions and 438 deletions
|
@ -43,14 +43,13 @@
|
|||
|
||||
//#define EDITOR_DEBUG
|
||||
|
||||
Editor::Editor(GUI::Widget* parent)
|
||||
: TextEditor(GUI::TextEditor::MultiLine, parent)
|
||||
Editor::Editor()
|
||||
{
|
||||
m_documentation_tooltip_window = GUI::Window::construct();
|
||||
m_documentation_tooltip_window->set_rect(0, 0, 500, 400);
|
||||
m_documentation_tooltip_window->set_window_type(GUI::WindowType::Tooltip);
|
||||
|
||||
m_documentation_html_view = HtmlView::construct(nullptr);
|
||||
m_documentation_html_view = HtmlView::construct();
|
||||
m_documentation_tooltip_window->set_main_widget(m_documentation_html_view);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ private:
|
|||
|
||||
void show_documentation_tooltip_if_available(const String&, const Gfx::Point& screen_location);
|
||||
|
||||
explicit Editor(GUI::Widget* parent);
|
||||
explicit Editor();
|
||||
|
||||
RefPtr<GUI::Window> m_documentation_tooltip_window;
|
||||
RefPtr<HtmlView> m_documentation_html_view;
|
||||
|
|
|
@ -34,29 +34,28 @@
|
|||
|
||||
extern RefPtr<EditorWrapper> g_current_editor_wrapper;
|
||||
|
||||
EditorWrapper::EditorWrapper(GUI::Widget* parent)
|
||||
: GUI::Widget(parent)
|
||||
EditorWrapper::EditorWrapper()
|
||||
{
|
||||
set_layout(make<GUI::VerticalBoxLayout>());
|
||||
|
||||
auto label_wrapper = GUI::Widget::construct(this);
|
||||
auto label_wrapper = add<GUI::Widget>();
|
||||
label_wrapper->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
label_wrapper->set_preferred_size(0, 14);
|
||||
label_wrapper->set_fill_with_background_color(true);
|
||||
label_wrapper->set_layout(make<GUI::HorizontalBoxLayout>());
|
||||
label_wrapper->layout()->set_margins({ 2, 0, 2, 0 });
|
||||
|
||||
m_filename_label = GUI::Label::construct("(Untitled)", label_wrapper);
|
||||
m_filename_label = label_wrapper->add<GUI::Label>("(Untitled)");
|
||||
m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
m_filename_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_filename_label->set_preferred_size(0, 14);
|
||||
|
||||
m_cursor_label = GUI::Label::construct("(Cursor)", label_wrapper);
|
||||
m_cursor_label = label_wrapper->add<GUI::Label>("(Cursor)");
|
||||
m_cursor_label->set_text_alignment(Gfx::TextAlignment::CenterRight);
|
||||
m_cursor_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_cursor_label->set_preferred_size(0, 14);
|
||||
|
||||
m_editor = Editor::construct(this);
|
||||
m_editor = add<Editor>();
|
||||
m_editor->set_ruler_visible(true);
|
||||
m_editor->set_line_wrapping_enabled(true);
|
||||
m_editor->set_automatic_indentation_enabled(true);
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
void set_editor_has_focus(Badge<Editor>, bool);
|
||||
|
||||
private:
|
||||
explicit EditorWrapper(GUI::Widget* parent = nullptr);
|
||||
explicit EditorWrapper();
|
||||
|
||||
RefPtr<GUI::Label> m_filename_label;
|
||||
RefPtr<GUI::Label> m_cursor_label;
|
||||
|
|
|
@ -127,18 +127,17 @@ static RefPtr<SearchResultsModel> find_in_files(const StringView& text)
|
|||
return adopt(*new SearchResultsModel(move(matches)));
|
||||
}
|
||||
|
||||
FindInFilesWidget::FindInFilesWidget(GUI::Widget* parent)
|
||||
: GUI::Widget(parent)
|
||||
FindInFilesWidget::FindInFilesWidget()
|
||||
{
|
||||
set_layout(make<GUI::VerticalBoxLayout>());
|
||||
m_textbox = GUI::TextBox::construct(this);
|
||||
m_textbox = add<GUI::TextBox>();
|
||||
m_textbox->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_textbox->set_preferred_size(0, 20);
|
||||
m_button = GUI::Button::construct("Find in files", this);
|
||||
m_button = add<GUI::Button>("Find in files");
|
||||
m_button->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_button->set_preferred_size(0, 20);
|
||||
|
||||
m_result_view = GUI::TableView::construct(this);
|
||||
m_result_view = add<GUI::TableView>();
|
||||
m_result_view->set_size_columns_to_fit_content(true);
|
||||
|
||||
m_result_view->on_activation = [](auto& index) {
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
void focus_textbox_and_select_all();
|
||||
|
||||
private:
|
||||
explicit FindInFilesWidget(GUI::Widget* parent);
|
||||
explicit FindInFilesWidget();
|
||||
|
||||
RefPtr<GUI::TextBox> m_textbox;
|
||||
RefPtr<GUI::Button> m_button;
|
||||
|
|
|
@ -30,9 +30,8 @@
|
|||
#include "WidgetTreeModel.h"
|
||||
#include <LibGUI/Painter.h>
|
||||
|
||||
FormEditorWidget::FormEditorWidget(GUI::Widget* parent)
|
||||
: ScrollableWidget(parent)
|
||||
, m_tool(make<CursorTool>(*this))
|
||||
FormEditorWidget::FormEditorWidget()
|
||||
: m_tool(make<CursorTool>(*this))
|
||||
{
|
||||
set_fill_with_background_color(true);
|
||||
set_background_color(Color::MidGray);
|
||||
|
@ -41,7 +40,7 @@ FormEditorWidget::FormEditorWidget(GUI::Widget* parent)
|
|||
set_frame_shadow(Gfx::FrameShadow::Sunken);
|
||||
set_frame_thickness(2);
|
||||
|
||||
m_form_widget = FormWidget::construct(*this);
|
||||
m_form_widget = add<FormWidget>();
|
||||
m_widget_tree_model = WidgetTreeModel::create(*m_form_widget);
|
||||
}
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ public:
|
|||
private:
|
||||
virtual void paint_event(GUI::PaintEvent&) override;
|
||||
|
||||
explicit FormEditorWidget(GUI::Widget* parent);
|
||||
FormEditorWidget();
|
||||
|
||||
RefPtr<FormWidget> m_form_widget;
|
||||
RefPtr<WidgetTreeModel> m_widget_tree_model;
|
||||
|
|
|
@ -29,8 +29,7 @@
|
|||
#include "Tool.h"
|
||||
#include <LibGUI/Painter.h>
|
||||
|
||||
FormWidget::FormWidget(FormEditorWidget& parent)
|
||||
: GUI::Widget(&parent)
|
||||
FormWidget::FormWidget()
|
||||
{
|
||||
set_fill_with_background_color(true);
|
||||
set_relative_rect(5, 5, 400, 300);
|
||||
|
|
|
@ -53,7 +53,7 @@ private:
|
|||
virtual void mousemove_event(GUI::MouseEvent&) override;
|
||||
virtual void keydown_event(GUI::KeyEvent&) override;
|
||||
|
||||
explicit FormWidget(FormEditorWidget& parent);
|
||||
FormWidget();
|
||||
|
||||
int m_grid_size { 5 };
|
||||
};
|
||||
|
|
|
@ -92,14 +92,10 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
LocatorTextBox(GUI::Widget* parent)
|
||||
: GUI::TextBox(parent)
|
||||
{
|
||||
}
|
||||
LocatorTextBox() {}
|
||||
};
|
||||
|
||||
Locator::Locator(GUI::Widget* parent)
|
||||
: GUI::Widget(parent)
|
||||
Locator::Locator()
|
||||
{
|
||||
if (!s_cplusplus_icon) {
|
||||
s_file_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png");
|
||||
|
@ -110,7 +106,7 @@ Locator::Locator(GUI::Widget* parent)
|
|||
set_layout(make<GUI::VerticalBoxLayout>());
|
||||
set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
set_preferred_size(0, 20);
|
||||
m_textbox = LocatorTextBox::construct(this);
|
||||
m_textbox = add<LocatorTextBox>();
|
||||
m_textbox->on_change = [this] {
|
||||
update_suggestions();
|
||||
};
|
||||
|
@ -154,7 +150,7 @@ Locator::Locator(GUI::Widget* parent)
|
|||
m_popup_window->set_window_type(GUI::WindowType::Tooltip);
|
||||
m_popup_window->set_rect(0, 0, 500, 200);
|
||||
|
||||
m_suggestion_view = GUI::TableView::construct(nullptr);
|
||||
m_suggestion_view = GUI::TableView::construct();
|
||||
m_suggestion_view->set_size_columns_to_fit_content(true);
|
||||
m_suggestion_view->set_headers_visible(false);
|
||||
m_popup_window->set_main_widget(m_suggestion_view);
|
||||
|
|
|
@ -42,7 +42,7 @@ private:
|
|||
void update_suggestions();
|
||||
void open_suggestion(const GUI::ModelIndex&);
|
||||
|
||||
explicit Locator(GUI::Widget* parent);
|
||||
Locator();
|
||||
|
||||
RefPtr<LocatorTextBox> m_textbox;
|
||||
RefPtr<GUI::Window> m_popup_window;
|
||||
|
|
|
@ -32,8 +32,7 @@
|
|||
#include <LibGfx/Font.h>
|
||||
#include <unistd.h>
|
||||
|
||||
ProcessStateWidget::ProcessStateWidget(GUI::Widget* parent)
|
||||
: GUI::Widget(parent)
|
||||
ProcessStateWidget::ProcessStateWidget()
|
||||
{
|
||||
set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
set_preferred_size(0, 20);
|
||||
|
@ -41,24 +40,24 @@ ProcessStateWidget::ProcessStateWidget(GUI::Widget* parent)
|
|||
|
||||
set_layout(make<GUI::HorizontalBoxLayout>());
|
||||
|
||||
auto pid_label_label = GUI::Label::construct("Process:", this);
|
||||
auto pid_label_label = add<GUI::Label>("Process:");
|
||||
pid_label_label->set_font(Gfx::Font::default_bold_font());
|
||||
m_pid_label = GUI::Label::construct("", this);
|
||||
m_pid_label = add<GUI::Label>("");
|
||||
|
||||
auto state_label_label = GUI::Label::construct("State:", this);
|
||||
auto state_label_label = add<GUI::Label>("State:");
|
||||
state_label_label->set_font(Gfx::Font::default_bold_font());
|
||||
m_state_label = GUI::Label::construct("", this);
|
||||
m_state_label = add<GUI::Label>("");
|
||||
|
||||
// FIXME: This should show CPU% instead.
|
||||
auto cpu_label_label = GUI::Label::construct("Times scheduled:", this);
|
||||
auto cpu_label_label = add<GUI::Label>("Times scheduled:");
|
||||
cpu_label_label->set_font(Gfx::Font::default_bold_font());
|
||||
m_cpu_label = GUI::Label::construct("", this);
|
||||
m_cpu_label = add<GUI::Label>("");
|
||||
|
||||
auto memory_label_label = GUI::Label::construct("Memory (resident):", this);
|
||||
auto memory_label_label = add<GUI::Label>("Memory (resident):");
|
||||
memory_label_label->set_font(Gfx::Font::default_bold_font());
|
||||
m_memory_label = GUI::Label::construct("", this);
|
||||
m_memory_label = add<GUI::Label>("");
|
||||
|
||||
m_timer = Core::Timer::construct(500, [this] {
|
||||
m_timer = add<Core::Timer>(500, [this] {
|
||||
refresh();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
void set_tty_fd(int);
|
||||
|
||||
private:
|
||||
explicit ProcessStateWidget(GUI::Widget* parent);
|
||||
explicit ProcessStateWidget();
|
||||
|
||||
void refresh();
|
||||
|
||||
|
|
|
@ -166,16 +166,13 @@ void TerminalWrapper::kill_running_command()
|
|||
(void)killpg(m_pid, SIGTERM);
|
||||
}
|
||||
|
||||
TerminalWrapper::TerminalWrapper(GUI::Widget* parent)
|
||||
: GUI::Widget(parent)
|
||||
TerminalWrapper::TerminalWrapper()
|
||||
{
|
||||
set_layout(make<GUI::VerticalBoxLayout>());
|
||||
|
||||
RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("Terminal");
|
||||
m_terminal_widget = TerminalWidget::construct(-1, false, config);
|
||||
add_child(*m_terminal_widget);
|
||||
|
||||
m_process_state_widget = ProcessStateWidget::construct(this);
|
||||
m_terminal_widget = add<TerminalWidget>(-1, false, config);
|
||||
m_process_state_widget = add<ProcessStateWidget>();
|
||||
}
|
||||
|
||||
TerminalWrapper::~TerminalWrapper()
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
Function<void()> on_command_exit;
|
||||
|
||||
private:
|
||||
explicit TerminalWrapper(GUI::Widget* parent);
|
||||
explicit TerminalWrapper();
|
||||
|
||||
RefPtr<ProcessStateWidget> m_process_state_widget;
|
||||
RefPtr<TerminalWidget> m_terminal_widget;
|
||||
|
|
|
@ -80,7 +80,7 @@ static RefPtr<GUI::TabWidget> s_action_tab_widget;
|
|||
|
||||
void add_new_editor(GUI::Widget& parent)
|
||||
{
|
||||
auto wrapper = EditorWrapper::construct(nullptr);
|
||||
auto wrapper = EditorWrapper::construct();
|
||||
if (s_action_tab_widget) {
|
||||
parent.insert_child_before(wrapper, *s_action_tab_widget);
|
||||
} else {
|
||||
|
@ -165,7 +165,7 @@ int main(int argc, char** argv)
|
|||
g_project = Project::load_from_file("little.files");
|
||||
ASSERT(g_project);
|
||||
|
||||
auto toolbar = GUI::ToolBar::construct(widget);
|
||||
auto toolbar = widget->add<GUI::ToolBar>();
|
||||
|
||||
auto selected_file_names = [&] {
|
||||
Vector<String> files;
|
||||
|
@ -176,7 +176,7 @@ int main(int argc, char** argv)
|
|||
};
|
||||
|
||||
auto new_action = GUI::Action::create("Add new file to project...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) {
|
||||
auto input_box = GUI::InputBox::construct("Enter name of new file:", "Add new file to project", g_window);
|
||||
auto input_box = g_window->add<GUI::InputBox>("Enter name of new file:", "Add new file to project");
|
||||
if (input_box->exec() == GUI::InputBox::ExecCancel)
|
||||
return;
|
||||
auto filename = input_box->text_value();
|
||||
|
@ -247,8 +247,8 @@ int main(int argc, char** argv)
|
|||
project_tree_view_context_menu->add_action(add_existing_file_action);
|
||||
project_tree_view_context_menu->add_action(delete_action);
|
||||
|
||||
auto outer_splitter = GUI::HorizontalSplitter::construct(widget);
|
||||
g_project_tree_view = GUI::TreeView::construct(outer_splitter);
|
||||
auto outer_splitter = widget->add<GUI::HorizontalSplitter>();
|
||||
g_project_tree_view = outer_splitter->add<GUI::TreeView>();
|
||||
g_project_tree_view->set_model(g_project->model());
|
||||
g_project_tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
g_project_tree_view->set_preferred_size(140, 0);
|
||||
|
@ -263,11 +263,11 @@ int main(int argc, char** argv)
|
|||
delete_action->set_enabled(!g_project_tree_view->selection().is_empty());
|
||||
};
|
||||
|
||||
g_right_hand_stack = GUI::StackWidget::construct(outer_splitter);
|
||||
g_right_hand_stack = outer_splitter->add<GUI::StackWidget>();
|
||||
|
||||
g_form_inner_container = GUI::Widget::construct(g_right_hand_stack);
|
||||
g_form_inner_container = g_right_hand_stack->add<GUI::Widget>();
|
||||
g_form_inner_container->set_layout(make<GUI::HorizontalBoxLayout>());
|
||||
auto form_widgets_toolbar = GUI::ToolBar::construct(Orientation::Vertical, 26, g_form_inner_container);
|
||||
auto form_widgets_toolbar = g_form_inner_container->add<GUI::ToolBar>(Orientation::Vertical, 26);
|
||||
form_widgets_toolbar->set_preferred_size(38, 0);
|
||||
|
||||
GUI::ActionGroup tool_actions;
|
||||
|
@ -296,19 +296,19 @@ int main(int argc, char** argv)
|
|||
form_widgets_toolbar->add_action(move(action));
|
||||
});
|
||||
|
||||
auto form_editor_inner_splitter = GUI::HorizontalSplitter::construct(g_form_inner_container);
|
||||
auto form_editor_inner_splitter = g_form_inner_container->add<GUI::HorizontalSplitter>();
|
||||
|
||||
g_form_editor_widget = FormEditorWidget::construct(form_editor_inner_splitter);
|
||||
g_form_editor_widget = form_editor_inner_splitter->add<FormEditorWidget>();
|
||||
|
||||
auto form_editing_pane_container = GUI::VerticalSplitter::construct(form_editor_inner_splitter);
|
||||
auto form_editing_pane_container = form_editor_inner_splitter->add<GUI::VerticalSplitter>();
|
||||
form_editing_pane_container->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
|
||||
form_editing_pane_container->set_preferred_size(190, 0);
|
||||
form_editing_pane_container->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
|
||||
auto add_properties_pane = [&](auto& text, auto pane_widget) {
|
||||
auto wrapper = GUI::Widget::construct(form_editing_pane_container.ptr());
|
||||
auto wrapper = form_editing_pane_container->add<GUI::Widget>();
|
||||
wrapper->set_layout(make<GUI::VerticalBoxLayout>());
|
||||
auto label = GUI::Label::construct(text, wrapper);
|
||||
auto label = wrapper->add<GUI::Label>(text);
|
||||
label->set_fill_with_background_color(true);
|
||||
label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
label->set_font(Gfx::Font::default_bold_font());
|
||||
|
@ -317,7 +317,7 @@ int main(int argc, char** argv)
|
|||
wrapper->add_child(pane_widget);
|
||||
};
|
||||
|
||||
auto form_widget_tree_view = GUI::TreeView::construct(nullptr);
|
||||
auto form_widget_tree_view = GUI::TreeView::construct();
|
||||
form_widget_tree_view->set_model(g_form_editor_widget->model());
|
||||
form_widget_tree_view->on_selection_change = [&] {
|
||||
g_form_editor_widget->selection().disable_hooks();
|
||||
|
@ -343,9 +343,9 @@ int main(int argc, char** argv)
|
|||
};
|
||||
|
||||
add_properties_pane("Form widget tree:", form_widget_tree_view);
|
||||
add_properties_pane("Widget properties:", GUI::TableView::construct(nullptr));
|
||||
add_properties_pane("Widget properties:", GUI::TableView::construct());
|
||||
|
||||
g_text_inner_splitter = GUI::VerticalSplitter::construct(g_right_hand_stack);
|
||||
g_text_inner_splitter = g_right_hand_stack->add<GUI::VerticalSplitter>();
|
||||
g_text_inner_splitter->layout()->set_margins({ 0, 3, 0, 0 });
|
||||
add_new_editor(*g_text_inner_splitter);
|
||||
|
||||
|
@ -420,7 +420,7 @@ int main(int argc, char** argv)
|
|||
open_file(filename);
|
||||
};
|
||||
|
||||
s_action_tab_widget = GUI::TabWidget::construct(g_text_inner_splitter);
|
||||
s_action_tab_widget = g_text_inner_splitter->add<GUI::TabWidget>();
|
||||
|
||||
s_action_tab_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
s_action_tab_widget->set_preferred_size(0, 24);
|
||||
|
@ -444,13 +444,13 @@ int main(int argc, char** argv)
|
|||
update_actions();
|
||||
});
|
||||
|
||||
auto find_in_files_widget = FindInFilesWidget::construct(nullptr);
|
||||
auto find_in_files_widget = FindInFilesWidget::construct();
|
||||
s_action_tab_widget->add_widget("Find in files", find_in_files_widget);
|
||||
|
||||
auto terminal_wrapper = TerminalWrapper::construct(nullptr);
|
||||
auto terminal_wrapper = TerminalWrapper::construct();
|
||||
s_action_tab_widget->add_widget("Console", terminal_wrapper);
|
||||
|
||||
auto locator = Locator::construct(widget);
|
||||
auto locator = widget->add<Locator>();
|
||||
|
||||
auto open_locator_action = GUI::Action::create("Open Locator...", { Mod_Ctrl, Key_K }, [&](auto&) {
|
||||
locator->open();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue