summaryrefslogtreecommitdiff
path: root/Applications/TextEditor
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-20 11:47:44 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-20 11:59:40 +0100
commit822dc56ef309e9fc053fd39dad7d7b33f397a566 (patch)
tree37f1ecdbcdd1db3e8454edcc02ffa5903bdc33c3 /Applications/TextEditor
parent18f1c49804f3888d3f588f68fee9f73e04258588 (diff)
downloadserenity-822dc56ef309e9fc053fd39dad7d7b33f397a566.zip
LibGUI: Introduce GML - a simple GUI Markup Language :^)
This patch replaces the UI-from-JSON mechanism with a more human-friendly DSL. The current implementation simply converts the GML into a JSON object that can be consumed by GUI::Widget::load_from_json(). The parser is not very helpful if you make a mistake. The language offers a very simple way to instantiate any registered Core::Object class by simply saying @ClassName @GUI::Label { text: "Hello friends!" tooltip: ":^)" } Layouts are Core::Objects and can be assigned to the "layout" property: @GUI::Widget { layout: @GUI::VerticalBoxLayout { spacing: 2 margins: [8, 8, 8, 8] } } And finally, child objects are simply nested within their parent: @GUI::Widget { layout: @GUI::HorizontalBoxLayout { } @GUI::Button { text: "OK" } @GUI::Button { text: "Cancel" } } This feels a *lot* more pleasant to write than the JSON we had. The fact that no new code was being written with the JSON mechanism was pretty telling, so let's approach this with developer convenience in mind. :^)
Diffstat (limited to 'Applications/TextEditor')
-rw-r--r--Applications/TextEditor/CMakeLists.txt4
-rw-r--r--Applications/TextEditor/MainWindow.gml105
-rw-r--r--Applications/TextEditor/MainWindow.json120
-rw-r--r--Applications/TextEditor/TextEditorWidget.cpp4
4 files changed, 109 insertions, 124 deletions
diff --git a/Applications/TextEditor/CMakeLists.txt b/Applications/TextEditor/CMakeLists.txt
index eadf6decfb..897a77f287 100644
--- a/Applications/TextEditor/CMakeLists.txt
+++ b/Applications/TextEditor/CMakeLists.txt
@@ -1,9 +1,9 @@
-compile_json_gui(MainWindow.json MainWindowUI.h main_window_ui_json)
+compile_gml(MainWindow.gml MainWindowGML.h main_window_gml)
set(SOURCES
main.cpp
TextEditorWidget.cpp
- MainWindowUI.h
+ MainWindowGML.h
)
serenity_bin(TextEditor)
diff --git a/Applications/TextEditor/MainWindow.gml b/Applications/TextEditor/MainWindow.gml
new file mode 100644
index 0000000000..d766a57e0a
--- /dev/null
+++ b/Applications/TextEditor/MainWindow.gml
@@ -0,0 +1,105 @@
+@GUI::Widget {
+ name: "main"
+ fill_with_background_color: true
+
+ layout: @GUI::VerticalBoxLayout {
+ spacing: 2
+ }
+
+ @GUI::ToolBarContainer {
+ @GUI::ToolBar {
+ name: "toolbar"
+ }
+ }
+
+ @GUI::HorizontalSplitter {
+ @GUI::TextEditor {
+ name: "editor"
+ }
+
+ @Web::OutOfProcessWebView {
+ name: "webview"
+ visible: false
+ }
+ }
+
+ @GUI::Widget {
+ name: "find_replace_widget"
+ visible: false
+ fill_with_background_color: true
+ horizontal_size_policy: "Fill"
+ vertical_size_policy: "Fixed"
+ preferred_height: 48
+
+ layout: @GUI::VerticalBoxLayout {
+ margins: [2, 2, 2, 4]
+ }
+
+ @GUI::Widget {
+ name: "find_widget"
+ fill_with_background_color: true
+ horizontal_size_policy: "Fill"
+ vertical_size_policy: "Fixed"
+ preferred_height: 22
+
+ layout: @GUI::HorizontalBoxLayout {
+ }
+
+ @GUI::Button {
+ name: "find_previous_button"
+ text: "Find previous"
+ horizontal_size_policy: "Fixed"
+ vertical_size_policy: "Fill"
+ preferred_width: 150
+ }
+
+ @GUI::Button {
+ name: "find_next_button"
+ text: "Find next"
+ horizontal_size_policy: "Fixed"
+ vertical_size_policy: "Fill"
+ preferred_width: 150
+ }
+ }
+
+ @GUI::Widget {
+ name: "replace_widget"
+ fill_with_background_color: true
+ horizontal_size_policy: "Fill"
+ vertical_size_policy: "Fixed"
+ preferred_height: 22
+
+ layout: @GUI::HorizontalBoxLayout {
+ }
+
+ @GUI::Button {
+ name: "replace_previous_button"
+ text: "Replace previous"
+ horizontal_size_policy: "Fixed"
+ vertical_size_policy: "Fill"
+ preferred_width: 100
+ }
+
+ @GUI::Button {
+ name: "replace_next_button"
+ text: "Replace next"
+ horizontal_size_policy: "Fixed"
+ vertical_size_policy: "Fill"
+ preferred_width: 100
+ }
+
+ @GUI::Button {
+ name: "replace_all_button"
+ text: "Replace all"
+ horizontal_size_policy: "Fixed"
+ vertical_size_policy: "Fill"
+ preferred_width: 100
+ }
+ }
+ }
+
+ @GUI::StatusBar {
+ name: "statusbar"
+ }
+}
+
diff --git a/Applications/TextEditor/MainWindow.json b/Applications/TextEditor/MainWindow.json
deleted file mode 100644
index 899dc1befe..0000000000
--- a/Applications/TextEditor/MainWindow.json
+++ /dev/null
@@ -1,120 +0,0 @@
-{
- "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::OutOfProcessWebView",
- "name": "webview",
- "visible": false
- }
- ]
- },
- {
- "class": "GUI::Widget",
- "name": "find_replace_widget",
- "visible": false,
- "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 ]
- },
- "children": [
- {
- "class": "GUI::Widget",
- "name": "find_widget",
- "fill_with_background_color": true,
- "horizontal_size_policy": "Fill",
- "vertical_size_policy": "Fixed",
- "preferred_height": 22,
- "layout": {
- "class": "GUI::HorizontalBoxLayout"
- },
- "children": [
- {
- "class": "GUI::Button",
- "name": "find_previous_button",
- "text": "Find previous",
- "horizontal_size_policy": "Fixed",
- "vertical_size_policy": "Fill",
- "preferred_width": 150
- },
- {
- "class": "GUI::Button",
- "name": "find_next_button",
- "text": "Find next",
- "horizontal_size_policy": "Fixed",
- "vertical_size_policy": "Fill",
- "preferred_width": 150
- }
- ]
- },
- {
- "class": "GUI::Widget",
- "name": "replace_widget",
- "fill_with_background_color": true,
- "horizontal_size_policy": "Fill",
- "vertical_size_policy": "Fixed",
- "preferred_height": 22,
- "layout": {
- "class": "GUI::HorizontalBoxLayout"
- },
- "children": [
- {
- "class": "GUI::Button",
- "name": "replace_previous_button",
- "text": "Replace previous",
- "horizontal_size_policy": "Fixed",
- "vertical_size_policy": "Fill",
- "preferred_width": 100
- },
- {
- "class": "GUI::Button",
- "name": "replace_next_button",
- "text": "Replace next",
- "horizontal_size_policy": "Fixed",
- "vertical_size_policy": "Fill",
- "preferred_width": 100
- },
- {
- "class": "GUI::Button",
- "name": "replace_all_button",
- "text": "Replace all",
- "horizontal_size_policy": "Fixed",
- "vertical_size_policy": "Fill",
- "preferred_width": 100
- }
- ]
- }
- ]
- },
- {
- "class": "GUI::StatusBar",
- "name": "statusbar"
- }
- ]
-}
diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp
index 9d8e6e9e4b..6325a1a0a0 100644
--- a/Applications/TextEditor/TextEditorWidget.cpp
+++ b/Applications/TextEditor/TextEditorWidget.cpp
@@ -30,7 +30,7 @@
#include <AK/Optional.h>
#include <AK/StringBuilder.h>
#include <AK/URL.h>
-#include <Applications/TextEditor/MainWindowUI.h>
+#include <Applications/TextEditor/MainWindowGML.h>
#include <LibCore/File.h>
#include <LibCore/MimeData.h>
#include <LibDesktop/Launcher.h>
@@ -61,7 +61,7 @@
TextEditorWidget::TextEditorWidget()
{
- load_from_json(main_window_ui_json);
+ load_from_gml(main_window_gml);
auto& toolbar = static_cast<GUI::ToolBar&>(*find_descendant_by_name("toolbar"));