mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
TextEditor: Move the main window UI to JSON
This is our first client of the new JSON GUI declaration thingy. The skeleton of the TextEditor app GUI is now declared separately from the C++ logic, and we use the Core::Object::name() of widgets to locate them once they have been instantiated by the GUI builder.
This commit is contained in:
parent
40892ac72e
commit
2e547ce7a3
Notes:
sideshowbarker
2024-07-19 02:25:40 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2e547ce7a35
@ -1,6 +1,13 @@
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
TextEditorWidget.cpp
|
||||
MainWindowUI.h
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT MainWindowUI.h
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.json
|
||||
COMMAND ${write_if_different} MainWindowUI.h ${CMAKE_SOURCE_DIR}/Meta/text-to-cpp-string.sh main_window_ui_json ${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.json
|
||||
)
|
||||
|
||||
serenity_bin(TextEditor)
|
||||
|
50
Applications/TextEditor/MainWindow.json
Normal file
50
Applications/TextEditor/MainWindow.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "main",
|
||||
"fill_with_background_color": true,
|
||||
|
||||
"layout": {
|
||||
"class": "GUI::VerticalBoxLayout",
|
||||
"spacing": 2
|
||||
},
|
||||
|
||||
"children": [
|
||||
{
|
||||
"class": "GUI::ToolBarContainer",
|
||||
"children": [
|
||||
{
|
||||
"class": "GUI::ToolBar",
|
||||
"name": "toolbar"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"class": "GUI::HorizontalSplitter",
|
||||
"children": [
|
||||
{
|
||||
"class": "GUI::TextEditor",
|
||||
"name": "editor"
|
||||
},
|
||||
{
|
||||
"class": "Web::InProcessWebView",
|
||||
"name": "webview"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"class": "GUI::Widget",
|
||||
"name": "find_replace_widget",
|
||||
"fill_with_background_color": true,
|
||||
"horizontal_size_policy": "Fill",
|
||||
"vertical_size_policy": "Fixed",
|
||||
"preferred_height": 48,
|
||||
"layout": {
|
||||
"class": "GUI::VerticalBoxLayout",
|
||||
"margins": [ 2, 2, 2, 4 ]
|
||||
}
|
||||
},
|
||||
{
|
||||
"class": "GUI::StatusBar",
|
||||
"name": "statusbar"
|
||||
}
|
||||
]
|
||||
}
|
@ -25,9 +25,12 @@
|
||||
*/
|
||||
|
||||
#include "TextEditorWidget.h"
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/URL.h>
|
||||
#include <Applications/TextEditor/MainWindowUI.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
@ -57,16 +60,11 @@
|
||||
|
||||
TextEditorWidget::TextEditorWidget()
|
||||
{
|
||||
set_fill_with_background_color(true);
|
||||
set_layout<GUI::VerticalBoxLayout>();
|
||||
layout()->set_spacing(2);
|
||||
load_from_json(main_window_ui_json);
|
||||
|
||||
auto& toolbar_container = add<GUI::ToolBarContainer>();
|
||||
auto& toolbar = toolbar_container.add<GUI::ToolBar>();
|
||||
auto& toolbar = static_cast<GUI::ToolBar&>(*find_descendant_by_name("toolbar"));
|
||||
|
||||
auto& splitter = add<GUI::HorizontalSplitter>();
|
||||
|
||||
m_editor = splitter.add<GUI::TextEditor>();
|
||||
m_editor = static_cast<GUI::TextEditor&>(*find_descendant_by_name("editor"));
|
||||
m_editor->set_ruler_visible(true);
|
||||
m_editor->set_automatic_indentation_enabled(true);
|
||||
m_editor->set_line_wrapping_enabled(true);
|
||||
@ -86,7 +84,7 @@ TextEditorWidget::TextEditorWidget()
|
||||
update_title();
|
||||
};
|
||||
|
||||
m_page_view = splitter.add<Web::InProcessWebView>();
|
||||
m_page_view = static_cast<Web::InProcessWebView&>(*find_descendant_by_name("webview"));
|
||||
m_page_view->set_visible(false);
|
||||
m_page_view->on_link_hover = [this](auto& url) {
|
||||
if (url.is_valid())
|
||||
@ -104,12 +102,7 @@ TextEditorWidget::TextEditorWidget()
|
||||
}
|
||||
};
|
||||
|
||||
m_find_replace_widget = add<GUI::Widget>();
|
||||
m_find_replace_widget->set_fill_with_background_color(true);
|
||||
m_find_replace_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_find_replace_widget->set_preferred_size(0, 48);
|
||||
m_find_replace_widget->set_layout<GUI::VerticalBoxLayout>();
|
||||
m_find_replace_widget->layout()->set_margins({ 2, 2, 2, 4 });
|
||||
m_find_replace_widget = *find_descendant_by_name("find_replace_widget");
|
||||
m_find_replace_widget->set_visible(false);
|
||||
|
||||
m_find_widget = m_find_replace_widget->add<GUI::Widget>();
|
||||
@ -292,7 +285,7 @@ TextEditorWidget::TextEditorWidget()
|
||||
m_editor->add_custom_context_menu_action(*m_find_next_action);
|
||||
m_editor->add_custom_context_menu_action(*m_find_previous_action);
|
||||
|
||||
m_statusbar = add<GUI::StatusBar>();
|
||||
m_statusbar = static_cast<GUI::StatusBar&>(*find_descendant_by_name("statusbar"));
|
||||
|
||||
m_editor->on_cursor_change = [this] { update_statusbar_cursor_position(); };
|
||||
|
||||
|
@ -197,6 +197,7 @@ add_link_options(--sysroot ${CMAKE_BINARY_DIR}/Root)
|
||||
include_directories(Libraries/LibC)
|
||||
include_directories(Libraries/LibM)
|
||||
include_directories(Services)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/Services)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/Libraries)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user