From 057ed83125aedafa56e89c8e463b72979d7d4be5 Mon Sep 17 00:00:00 2001 From: "Mr.UNIX" Date: Thu, 18 Jan 2024 14:42:23 +0100 Subject: [PATCH 1/5] TerminalSettings: Split TerminalSettingsWidget into different files --- .../TerminalSettings/CMakeLists.txt | 3 +- .../TerminalSettings/MainWidget.cpp | 126 ++++++++++++++++++ .../TerminalSettings/MainWidget.h | 37 +++++ ...minalSettingsWidget.cpp => ViewWidget.cpp} | 100 +------------- ...{TerminalSettingsWidget.h => ViewWidget.h} | 23 ---- .../Applications/TerminalSettings/main.cpp | 3 +- 6 files changed, 168 insertions(+), 124 deletions(-) create mode 100644 Userland/Applications/TerminalSettings/MainWidget.cpp create mode 100644 Userland/Applications/TerminalSettings/MainWidget.h rename Userland/Applications/TerminalSettings/{TerminalSettingsWidget.cpp => ViewWidget.cpp} (69%) rename Userland/Applications/TerminalSettings/{TerminalSettingsWidget.h => ViewWidget.h} (61%) diff --git a/Userland/Applications/TerminalSettings/CMakeLists.txt b/Userland/Applications/TerminalSettings/CMakeLists.txt index ddcab96e1819e4..24786b705673c1 100644 --- a/Userland/Applications/TerminalSettings/CMakeLists.txt +++ b/Userland/Applications/TerminalSettings/CMakeLists.txt @@ -8,7 +8,8 @@ stringify_gml(TerminalSettingsMain.gml TerminalSettingsMainGML.h terminal_settin stringify_gml(TerminalSettingsView.gml TerminalSettingsViewGML.h terminal_settings_view_gml) set(SOURCES - TerminalSettingsWidget.cpp + MainWidget.cpp + ViewWidget.cpp main.cpp ) diff --git a/Userland/Applications/TerminalSettings/MainWidget.cpp b/Userland/Applications/TerminalSettings/MainWidget.cpp new file mode 100644 index 00000000000000..878c76e34c56c7 --- /dev/null +++ b/Userland/Applications/TerminalSettings/MainWidget.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2018-2021, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "MainWidget.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +ErrorOr> TerminalSettingsMainWidget::try_create() +{ + auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) TerminalSettingsMainWidget())); + TRY(widget->setup()); + return widget; +} + +ErrorOr TerminalSettingsMainWidget::setup() +{ + TRY(load_from_gml(terminal_settings_main_gml)); + + auto& beep_bell_radio = *find_descendant_of_type_named("beep_bell_radio"); + auto& visual_bell_radio = *find_descendant_of_type_named("visual_bell_radio"); + auto& no_bell_radio = *find_descendant_of_type_named("no_bell_radio"); + + m_bell_mode = parse_bell(Config::read_string("Terminal"sv, "Window"sv, "Bell"sv)); + m_original_bell_mode = m_bell_mode; + + switch (m_bell_mode) { + case VT::TerminalWidget::BellMode::Visible: + visual_bell_radio.set_checked(true, GUI::AllowCallback::No); + break; + case VT::TerminalWidget::BellMode::AudibleBeep: + beep_bell_radio.set_checked(true, GUI::AllowCallback::No); + break; + case VT::TerminalWidget::BellMode::Disabled: + no_bell_radio.set_checked(true, GUI::AllowCallback::No); + break; + } + + beep_bell_radio.on_checked = [this](bool) { + m_bell_mode = VT::TerminalWidget::BellMode::AudibleBeep; + Config::write_string("Terminal"sv, "Window"sv, "Bell"sv, stringify_bell(m_bell_mode)); + set_modified(true); + }; + visual_bell_radio.on_checked = [this](bool) { + m_bell_mode = VT::TerminalWidget::BellMode::Visible; + Config::write_string("Terminal"sv, "Window"sv, "Bell"sv, stringify_bell(m_bell_mode)); + set_modified(true); + }; + no_bell_radio.on_checked = [this](bool) { + m_bell_mode = VT::TerminalWidget::BellMode::Disabled; + Config::write_string("Terminal"sv, "Window"sv, "Bell"sv, stringify_bell(m_bell_mode)); + set_modified(true); + }; + + m_confirm_close = Config::read_bool("Terminal"sv, "Terminal"sv, "ConfirmClose"sv, true); + m_orignal_confirm_close = m_confirm_close; + auto& confirm_close_checkbox = *find_descendant_of_type_named("terminal_confirm_close"); + confirm_close_checkbox.on_checked = [&](bool confirm_close) { + m_confirm_close = confirm_close; + Config::write_bool("Terminal"sv, "Terminal"sv, "ConfirmClose"sv, confirm_close); + set_modified(true); + }; + confirm_close_checkbox.set_checked(m_confirm_close, GUI::AllowCallback::No); + return {}; +} + +VT::TerminalWidget::BellMode TerminalSettingsMainWidget::parse_bell(StringView bell_string) +{ + if (bell_string == "AudibleBeep") + return VT::TerminalWidget::BellMode::AudibleBeep; + if (bell_string == "Visible") + return VT::TerminalWidget::BellMode::Visible; + if (bell_string == "Disabled") + return VT::TerminalWidget::BellMode::Disabled; + VERIFY_NOT_REACHED(); +} + +ByteString TerminalSettingsMainWidget::stringify_bell(VT::TerminalWidget::BellMode bell_mode) +{ + if (bell_mode == VT::TerminalWidget::BellMode::AudibleBeep) + return "AudibleBeep"; + if (bell_mode == VT::TerminalWidget::BellMode::Disabled) + return "Disabled"; + if (bell_mode == VT::TerminalWidget::BellMode::Visible) + return "Visible"; + VERIFY_NOT_REACHED(); +} + +void TerminalSettingsMainWidget::apply_settings() +{ + m_original_bell_mode = m_bell_mode; + m_orignal_confirm_close = m_confirm_close; + write_back_settings(); +} +void TerminalSettingsMainWidget::write_back_settings() const +{ + Config::write_bool("Terminal"sv, "Terminal"sv, "ConfirmClose"sv, m_orignal_confirm_close); + Config::write_string("Terminal"sv, "Window"sv, "Bell"sv, stringify_bell(m_original_bell_mode)); +} + +void TerminalSettingsMainWidget::cancel_settings() +{ + write_back_settings(); +} diff --git a/Userland/Applications/TerminalSettings/MainWidget.h b/Userland/Applications/TerminalSettings/MainWidget.h new file mode 100644 index 00000000000000..5f8f25aceab0b5 --- /dev/null +++ b/Userland/Applications/TerminalSettings/MainWidget.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018-2021, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +class TerminalSettingsMainWidget final : public GUI::SettingsWindow::Tab { + C_OBJECT_ABSTRACT(TerminalSettingsMainWidget) +public: + static ErrorOr> try_create(); + + virtual void apply_settings() override; + virtual void cancel_settings() override; + +private: + TerminalSettingsMainWidget() = default; + ErrorOr setup(); + void write_back_settings() const; + + static VT::TerminalWidget::BellMode parse_bell(StringView bell_string); + static ByteString stringify_bell(VT::TerminalWidget::BellMode bell_mode); + + VT::TerminalWidget::BellMode m_bell_mode { VT::TerminalWidget::BellMode::Disabled }; + bool m_confirm_close { true }; + + VT::TerminalWidget::BellMode m_original_bell_mode; + bool m_orignal_confirm_close { true }; +}; diff --git a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp b/Userland/Applications/TerminalSettings/ViewWidget.cpp similarity index 69% rename from Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp rename to Userland/Applications/TerminalSettings/ViewWidget.cpp index bcfb6404c69c06..63f526f122a88e 100644 --- a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.cpp +++ b/Userland/Applications/TerminalSettings/ViewWidget.cpp @@ -4,11 +4,10 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "TerminalSettingsWidget.h" +#include "ViewWidget.h" #include #include #include -#include #include #include #include @@ -29,64 +28,6 @@ #include #include -ErrorOr> TerminalSettingsMainWidget::try_create() -{ - auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) TerminalSettingsMainWidget())); - TRY(widget->setup()); - return widget; -} - -ErrorOr TerminalSettingsMainWidget::setup() -{ - TRY(load_from_gml(terminal_settings_main_gml)); - - auto& beep_bell_radio = *find_descendant_of_type_named("beep_bell_radio"); - auto& visual_bell_radio = *find_descendant_of_type_named("visual_bell_radio"); - auto& no_bell_radio = *find_descendant_of_type_named("no_bell_radio"); - - m_bell_mode = parse_bell(Config::read_string("Terminal"sv, "Window"sv, "Bell"sv)); - m_original_bell_mode = m_bell_mode; - - switch (m_bell_mode) { - case VT::TerminalWidget::BellMode::Visible: - visual_bell_radio.set_checked(true, GUI::AllowCallback::No); - break; - case VT::TerminalWidget::BellMode::AudibleBeep: - beep_bell_radio.set_checked(true, GUI::AllowCallback::No); - break; - case VT::TerminalWidget::BellMode::Disabled: - no_bell_radio.set_checked(true, GUI::AllowCallback::No); - break; - } - - beep_bell_radio.on_checked = [this](bool) { - m_bell_mode = VT::TerminalWidget::BellMode::AudibleBeep; - Config::write_string("Terminal"sv, "Window"sv, "Bell"sv, stringify_bell(m_bell_mode)); - set_modified(true); - }; - visual_bell_radio.on_checked = [this](bool) { - m_bell_mode = VT::TerminalWidget::BellMode::Visible; - Config::write_string("Terminal"sv, "Window"sv, "Bell"sv, stringify_bell(m_bell_mode)); - set_modified(true); - }; - no_bell_radio.on_checked = [this](bool) { - m_bell_mode = VT::TerminalWidget::BellMode::Disabled; - Config::write_string("Terminal"sv, "Window"sv, "Bell"sv, stringify_bell(m_bell_mode)); - set_modified(true); - }; - - m_confirm_close = Config::read_bool("Terminal"sv, "Terminal"sv, "ConfirmClose"sv, true); - m_orignal_confirm_close = m_confirm_close; - auto& confirm_close_checkbox = *find_descendant_of_type_named("terminal_confirm_close"); - confirm_close_checkbox.on_checked = [&](bool confirm_close) { - m_confirm_close = confirm_close; - Config::write_bool("Terminal"sv, "Terminal"sv, "ConfirmClose"sv, confirm_close); - set_modified(true); - }; - confirm_close_checkbox.set_checked(m_confirm_close, GUI::AllowCallback::No); - return {}; -} - ErrorOr> TerminalSettingsViewWidget::try_create() { auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) TerminalSettingsViewWidget())); @@ -225,45 +166,6 @@ ErrorOr TerminalSettingsViewWidget::setup() return {}; } -VT::TerminalWidget::BellMode TerminalSettingsMainWidget::parse_bell(StringView bell_string) -{ - if (bell_string == "AudibleBeep") - return VT::TerminalWidget::BellMode::AudibleBeep; - if (bell_string == "Visible") - return VT::TerminalWidget::BellMode::Visible; - if (bell_string == "Disabled") - return VT::TerminalWidget::BellMode::Disabled; - VERIFY_NOT_REACHED(); -} - -ByteString TerminalSettingsMainWidget::stringify_bell(VT::TerminalWidget::BellMode bell_mode) -{ - if (bell_mode == VT::TerminalWidget::BellMode::AudibleBeep) - return "AudibleBeep"; - if (bell_mode == VT::TerminalWidget::BellMode::Disabled) - return "Disabled"; - if (bell_mode == VT::TerminalWidget::BellMode::Visible) - return "Visible"; - VERIFY_NOT_REACHED(); -} - -void TerminalSettingsMainWidget::apply_settings() -{ - m_original_bell_mode = m_bell_mode; - m_orignal_confirm_close = m_confirm_close; - write_back_settings(); -} -void TerminalSettingsMainWidget::write_back_settings() const -{ - Config::write_bool("Terminal"sv, "Terminal"sv, "ConfirmClose"sv, m_orignal_confirm_close); - Config::write_string("Terminal"sv, "Window"sv, "Bell"sv, stringify_bell(m_original_bell_mode)); -} - -void TerminalSettingsMainWidget::cancel_settings() -{ - write_back_settings(); -} - void TerminalSettingsViewWidget::apply_settings() { m_original_opacity = m_opacity; diff --git a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.h b/Userland/Applications/TerminalSettings/ViewWidget.h similarity index 61% rename from Userland/Applications/TerminalSettings/TerminalSettingsWidget.h rename to Userland/Applications/TerminalSettings/ViewWidget.h index df0be97d1ceb5e..651fdfb0a822a7 100644 --- a/Userland/Applications/TerminalSettings/TerminalSettingsWidget.h +++ b/Userland/Applications/TerminalSettings/ViewWidget.h @@ -13,29 +13,6 @@ #include #include -class TerminalSettingsMainWidget final : public GUI::SettingsWindow::Tab { - C_OBJECT_ABSTRACT(TerminalSettingsMainWidget) -public: - static ErrorOr> try_create(); - - virtual void apply_settings() override; - virtual void cancel_settings() override; - -private: - TerminalSettingsMainWidget() = default; - ErrorOr setup(); - void write_back_settings() const; - - static VT::TerminalWidget::BellMode parse_bell(StringView bell_string); - static ByteString stringify_bell(VT::TerminalWidget::BellMode bell_mode); - - VT::TerminalWidget::BellMode m_bell_mode { VT::TerminalWidget::BellMode::Disabled }; - bool m_confirm_close { true }; - - VT::TerminalWidget::BellMode m_original_bell_mode; - bool m_orignal_confirm_close { true }; -}; - class TerminalSettingsViewWidget final : public GUI::SettingsWindow::Tab { C_OBJECT_ABSTRACT(TerminalSettingsViewWidget) public: diff --git a/Userland/Applications/TerminalSettings/main.cpp b/Userland/Applications/TerminalSettings/main.cpp index aede5e9599bbc1..819ec4e4cf58e0 100644 --- a/Userland/Applications/TerminalSettings/main.cpp +++ b/Userland/Applications/TerminalSettings/main.cpp @@ -4,7 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "TerminalSettingsWidget.h" +#include "MainWidget.h" +#include "ViewWidget.h" #include #include #include From 87bb0f97bdca23df0f36774a00f653b6388003d6 Mon Sep 17 00:00:00 2001 From: "Mr.UNIX" Date: Thu, 18 Jan 2024 14:58:03 +0100 Subject: [PATCH 2/5] GMLCompiler: Add OpacitySlider header to class file mappings --- Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp index c06adea9c30d4d..0418e156df2987 100644 --- a/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp @@ -36,6 +36,7 @@ static Optional map_class_to_file(StringView class_) { "GUI::VerticalProgressbar"sv, "GUI/Progressbar"sv }, { "GUI::DialogButton"sv, "GUI/Button"sv }, { "GUI::PasswordBox"sv, "GUI/TextBox"sv }, + { "GUI::HorizontalOpacitySlider"sv, "GUI/OpacitySlider"sv }, // Map Layout::Spacer to the Layout header even though it's a pseudo class. { "GUI::Layout::Spacer"sv, "GUI/Layout"sv }, }; From 42342e7ad2c8134c40289f0a78910946c6709a39 Mon Sep 17 00:00:00 2001 From: "Mr.UNIX" Date: Thu, 18 Jan 2024 14:59:18 +0100 Subject: [PATCH 3/5] GMLCompiler: Add enum initializer for orientation --- Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp index 0418e156df2987..e0d925ea985ee2 100644 --- a/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp @@ -183,6 +183,7 @@ static ErrorOr> generate_enum_initializer_for(StringView proper { "button_style"sv, "Gfx::ButtonStyle"sv }, { "mode"sv, "GUI::TextEditor::Mode"sv }, { "font_weight"sv, "Gfx::FontWeight"sv }, + { "orientation"sv, "Gfx::Orientation"sv }, }; auto const& enum_type_name = enum_properties.get(property_name); From d1a8432d1ad0f1d832192d1d2c4188bc209acf89 Mon Sep 17 00:00:00 2001 From: "Mr.UNIX" Date: Thu, 18 Jan 2024 15:05:05 +0100 Subject: [PATCH 4/5] GMLCompiler: Add enum initializer for background_role --- Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp index e0d925ea985ee2..4e522e06360b9b 100644 --- a/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp @@ -174,6 +174,7 @@ static ErrorOr> generate_enum_initializer_for(StringView proper static HashMap enum_properties = { { "text_alignment"sv, "Gfx::TextAlignment"sv }, { "focus_policy"sv, "GUI::FocusPolicy"sv }, + { "background_role"sv, "Gfx::ColorRole"sv }, { "foreground_role"sv, "Gfx::ColorRole"sv }, { "frame_style"sv, "Gfx::FrameStyle"sv }, { "text_wrapping"sv, "Gfx::TextWrapping"sv }, From 90f2038dc4f9be139702a236cb882fc2761f5724 Mon Sep 17 00:00:00 2001 From: "Mr.UNIX" Date: Thu, 18 Jan 2024 15:07:55 +0100 Subject: [PATCH 5/5] TerminalSettings: Port to GML Compiler --- .../TerminalSettings/CMakeLists.txt | 11 ++++------ .../TerminalSettings/MainWidget.cpp | 21 +++++++++---------- .../TerminalSettings/MainWidget.h | 9 +++++--- .../TerminalSettings/TerminalSettingsMain.gml | 2 +- .../TerminalSettings/TerminalSettingsView.gml | 5 ++--- .../TerminalSettings/ViewWidget.cpp | 17 +++++++-------- .../TerminalSettings/ViewWidget.h | 9 +++++--- .../Applications/TerminalSettings/main.cpp | 4 ++-- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Userland/Applications/TerminalSettings/CMakeLists.txt b/Userland/Applications/TerminalSettings/CMakeLists.txt index 24786b705673c1..b8dd06bf6fb414 100644 --- a/Userland/Applications/TerminalSettings/CMakeLists.txt +++ b/Userland/Applications/TerminalSettings/CMakeLists.txt @@ -4,19 +4,16 @@ serenity_component( TARGETS TerminalSettings ) -stringify_gml(TerminalSettingsMain.gml TerminalSettingsMainGML.h terminal_settings_main_gml) -stringify_gml(TerminalSettingsView.gml TerminalSettingsViewGML.h terminal_settings_view_gml) +compile_gml(TerminalSettingsMain.gml TerminalSettingsMainGML.cpp) +compile_gml(TerminalSettingsView.gml TerminalSettingsViewGML.cpp) set(SOURCES + TerminalSettingsMainGML.cpp + TerminalSettingsViewGML.cpp MainWidget.cpp ViewWidget.cpp main.cpp ) -set(GENERATED_SOURCES - TerminalSettingsMainGML.h - TerminalSettingsViewGML.h -) - serenity_app(TerminalSettings ICON app-terminal) target_link_libraries(TerminalSettings PRIVATE LibCore LibGfx LibGUI LibConfig LibMain LibVT) diff --git a/Userland/Applications/TerminalSettings/MainWidget.cpp b/Userland/Applications/TerminalSettings/MainWidget.cpp index 878c76e34c56c7..6b4d96d1736c0e 100644 --- a/Userland/Applications/TerminalSettings/MainWidget.cpp +++ b/Userland/Applications/TerminalSettings/MainWidget.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -28,17 +27,16 @@ #include #include -ErrorOr> TerminalSettingsMainWidget::try_create() +namespace TerminalSettings { +ErrorOr> MainWidget::create() { - auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) TerminalSettingsMainWidget())); + auto widget = MainWidget::try_create().release_value_but_fixme_should_propagate_errors(); TRY(widget->setup()); return widget; } -ErrorOr TerminalSettingsMainWidget::setup() +ErrorOr MainWidget::setup() { - TRY(load_from_gml(terminal_settings_main_gml)); - auto& beep_bell_radio = *find_descendant_of_type_named("beep_bell_radio"); auto& visual_bell_radio = *find_descendant_of_type_named("visual_bell_radio"); auto& no_bell_radio = *find_descendant_of_type_named("no_bell_radio"); @@ -86,7 +84,7 @@ ErrorOr TerminalSettingsMainWidget::setup() return {}; } -VT::TerminalWidget::BellMode TerminalSettingsMainWidget::parse_bell(StringView bell_string) +VT::TerminalWidget::BellMode MainWidget::parse_bell(StringView bell_string) { if (bell_string == "AudibleBeep") return VT::TerminalWidget::BellMode::AudibleBeep; @@ -97,7 +95,7 @@ VT::TerminalWidget::BellMode TerminalSettingsMainWidget::parse_bell(StringView b VERIFY_NOT_REACHED(); } -ByteString TerminalSettingsMainWidget::stringify_bell(VT::TerminalWidget::BellMode bell_mode) +ByteString MainWidget::stringify_bell(VT::TerminalWidget::BellMode bell_mode) { if (bell_mode == VT::TerminalWidget::BellMode::AudibleBeep) return "AudibleBeep"; @@ -108,19 +106,20 @@ ByteString TerminalSettingsMainWidget::stringify_bell(VT::TerminalWidget::BellMo VERIFY_NOT_REACHED(); } -void TerminalSettingsMainWidget::apply_settings() +void MainWidget::apply_settings() { m_original_bell_mode = m_bell_mode; m_orignal_confirm_close = m_confirm_close; write_back_settings(); } -void TerminalSettingsMainWidget::write_back_settings() const +void MainWidget::write_back_settings() const { Config::write_bool("Terminal"sv, "Terminal"sv, "ConfirmClose"sv, m_orignal_confirm_close); Config::write_string("Terminal"sv, "Window"sv, "Bell"sv, stringify_bell(m_original_bell_mode)); } -void TerminalSettingsMainWidget::cancel_settings() +void MainWidget::cancel_settings() { write_back_settings(); } +} diff --git a/Userland/Applications/TerminalSettings/MainWidget.h b/Userland/Applications/TerminalSettings/MainWidget.h index 5f8f25aceab0b5..416c67f9ba1111 100644 --- a/Userland/Applications/TerminalSettings/MainWidget.h +++ b/Userland/Applications/TerminalSettings/MainWidget.h @@ -13,16 +13,18 @@ #include #include -class TerminalSettingsMainWidget final : public GUI::SettingsWindow::Tab { +namespace TerminalSettings { +class MainWidget final : public GUI::SettingsWindow::Tab { C_OBJECT_ABSTRACT(TerminalSettingsMainWidget) public: - static ErrorOr> try_create(); + static ErrorOr> create(); virtual void apply_settings() override; virtual void cancel_settings() override; private: - TerminalSettingsMainWidget() = default; + static ErrorOr> try_create(); + MainWidget() = default; ErrorOr setup(); void write_back_settings() const; @@ -35,3 +37,4 @@ class TerminalSettingsMainWidget final : public GUI::SettingsWindow::Tab { VT::TerminalWidget::BellMode m_original_bell_mode; bool m_orignal_confirm_close { true }; }; +} diff --git a/Userland/Applications/TerminalSettings/TerminalSettingsMain.gml b/Userland/Applications/TerminalSettings/TerminalSettingsMain.gml index e9b11c4220e3c9..3fb72e1e2b2a3d 100644 --- a/Userland/Applications/TerminalSettings/TerminalSettingsMain.gml +++ b/Userland/Applications/TerminalSettings/TerminalSettingsMain.gml @@ -1,4 +1,4 @@ -@GUI::Widget { +@TerminalSettings::MainWidget { fill_with_background_color: true layout: @GUI::VerticalBoxLayout { margins: [10] diff --git a/Userland/Applications/TerminalSettings/TerminalSettingsView.gml b/Userland/Applications/TerminalSettings/TerminalSettingsView.gml index a46f271dda4b0a..15f3772349ab38 100644 --- a/Userland/Applications/TerminalSettings/TerminalSettingsView.gml +++ b/Userland/Applications/TerminalSettings/TerminalSettingsView.gml @@ -1,4 +1,4 @@ -@GUI::Widget { +@TerminalSettings::ViewWidget { fill_with_background_color: true layout: @GUI::VerticalBoxLayout { margins: [10] @@ -27,7 +27,7 @@ @GUI::Label { background_role: "Base" - style: "SunkenContainer" + frame_style: "SunkenContainer" fill_with_background_color: true name: "terminal_font_label" } @@ -111,7 +111,6 @@ name: "history_size_spinbox" min: 0 max: 40960 - orientation: "Horizontal" preferred_width: 100 } diff --git a/Userland/Applications/TerminalSettings/ViewWidget.cpp b/Userland/Applications/TerminalSettings/ViewWidget.cpp index 63f526f122a88e..c107bafce2fd64 100644 --- a/Userland/Applications/TerminalSettings/ViewWidget.cpp +++ b/Userland/Applications/TerminalSettings/ViewWidget.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -28,17 +27,16 @@ #include #include -ErrorOr> TerminalSettingsViewWidget::try_create() +namespace TerminalSettings { +ErrorOr> ViewWidget::create() { - auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) TerminalSettingsViewWidget())); + auto widget = TRY(ViewWidget::try_create()); TRY(widget->setup()); return widget; } -ErrorOr TerminalSettingsViewWidget::setup() +ErrorOr ViewWidget::setup() { - TRY(load_from_gml(terminal_settings_view_gml)); - auto& slider = *find_descendant_of_type_named("background_opacity_slider"); m_opacity = Config::read_i32("Terminal"sv, "Window"sv, "Opacity"sv); m_original_opacity = m_opacity; @@ -166,7 +164,7 @@ ErrorOr TerminalSettingsViewWidget::setup() return {}; } -void TerminalSettingsViewWidget::apply_settings() +void ViewWidget::apply_settings() { m_original_opacity = m_opacity; m_original_font = m_font; @@ -177,7 +175,7 @@ void TerminalSettingsViewWidget::apply_settings() write_back_settings(); } -void TerminalSettingsViewWidget::write_back_settings() const +void ViewWidget::write_back_settings() const { Config::write_i32("Terminal"sv, "Window"sv, "Opacity"sv, static_cast(m_original_opacity)); Config::write_string("Terminal"sv, "Text"sv, "Font"sv, m_original_font->qualified_name()); @@ -187,7 +185,8 @@ void TerminalSettingsViewWidget::write_back_settings() const Config::write_bool("Terminal"sv, "Terminal"sv, "ShowScrollBar"sv, m_original_show_scrollbar); } -void TerminalSettingsViewWidget::cancel_settings() +void ViewWidget::cancel_settings() { write_back_settings(); } +} diff --git a/Userland/Applications/TerminalSettings/ViewWidget.h b/Userland/Applications/TerminalSettings/ViewWidget.h index 651fdfb0a822a7..e35845ba272f48 100644 --- a/Userland/Applications/TerminalSettings/ViewWidget.h +++ b/Userland/Applications/TerminalSettings/ViewWidget.h @@ -13,16 +13,18 @@ #include #include -class TerminalSettingsViewWidget final : public GUI::SettingsWindow::Tab { +namespace TerminalSettings { +class ViewWidget final : public GUI::SettingsWindow::Tab { C_OBJECT_ABSTRACT(TerminalSettingsViewWidget) public: - static ErrorOr> try_create(); + static ErrorOr> try_create(); + static ErrorOr> create(); virtual void apply_settings() override; virtual void cancel_settings() override; private: - TerminalSettingsViewWidget() = default; + ViewWidget() = default; ErrorOr setup(); void write_back_settings() const; @@ -42,3 +44,4 @@ class TerminalSettingsViewWidget final : public GUI::SettingsWindow::Tab { size_t m_original_max_history_size; bool m_original_show_scrollbar { true }; }; +} diff --git a/Userland/Applications/TerminalSettings/main.cpp b/Userland/Applications/TerminalSettings/main.cpp index 819ec4e4cf58e0..38bc80a2dc2bc0 100644 --- a/Userland/Applications/TerminalSettings/main.cpp +++ b/Userland/Applications/TerminalSettings/main.cpp @@ -33,8 +33,8 @@ ErrorOr serenity_main(Main::Arguments arguments) auto window = TRY(GUI::SettingsWindow::create("Terminal Settings")); window->set_icon(app_icon.bitmap_for_size(16)); - (void)TRY(window->add_tab("View"_string, "view"sv)); - (void)TRY(window->add_tab("Terminal"_string, "terminal"sv)); + (void)TRY(window->add_tab(TRY(TerminalSettings::ViewWidget::create()), "View"_string, "view"sv)); + (void)TRY(window->add_tab(TRY(TerminalSettings::MainWidget::create()), "Terminal"_string, "terminal"sv)); window->set_active_tab(selected_tab); window->show();