Skip to content

Commit

Permalink
TerminalSettings: Port to GML Compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
mrunix00 authored and timschumi committed Jan 19, 2024
1 parent f6c32ea commit 2440a2f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
11 changes: 4 additions & 7 deletions Userland/Applications/TerminalSettings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
21 changes: 10 additions & 11 deletions Userland/Applications/TerminalSettings/MainWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <AK/Assertions.h>
#include <AK/JsonObject.h>
#include <AK/QuickSort.h>
#include <Applications/TerminalSettings/TerminalSettingsMainGML.h>
#include <LibConfig/Client.h>
#include <LibCore/DirIterator.h>
#include <LibGUI/Application.h>
Expand All @@ -28,17 +27,16 @@
#include <LibVT/TerminalWidget.h>
#include <spawn.h>

ErrorOr<NonnullRefPtr<TerminalSettingsMainWidget>> TerminalSettingsMainWidget::try_create()
namespace TerminalSettings {
ErrorOr<NonnullRefPtr<MainWidget>> 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<void> TerminalSettingsMainWidget::setup()
ErrorOr<void> MainWidget::setup()
{
TRY(load_from_gml(terminal_settings_main_gml));

auto& beep_bell_radio = *find_descendant_of_type_named<GUI::RadioButton>("beep_bell_radio");
auto& visual_bell_radio = *find_descendant_of_type_named<GUI::RadioButton>("visual_bell_radio");
auto& no_bell_radio = *find_descendant_of_type_named<GUI::RadioButton>("no_bell_radio");
Expand Down Expand Up @@ -86,7 +84,7 @@ ErrorOr<void> 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;
Expand All @@ -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";
Expand All @@ -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();
}
}
9 changes: 6 additions & 3 deletions Userland/Applications/TerminalSettings/MainWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
#include <LibGUI/TextEditor.h>
#include <LibVT/TerminalWidget.h>

class TerminalSettingsMainWidget final : public GUI::SettingsWindow::Tab {
namespace TerminalSettings {
class MainWidget final : public GUI::SettingsWindow::Tab {
C_OBJECT_ABSTRACT(TerminalSettingsMainWidget)
public:
static ErrorOr<NonnullRefPtr<TerminalSettingsMainWidget>> try_create();
static ErrorOr<NonnullRefPtr<MainWidget>> create();

virtual void apply_settings() override;
virtual void cancel_settings() override;

private:
TerminalSettingsMainWidget() = default;
static ErrorOr<NonnullRefPtr<MainWidget>> try_create();
MainWidget() = default;
ErrorOr<void> setup();
void write_back_settings() const;

Expand All @@ -35,3 +37,4 @@ class TerminalSettingsMainWidget final : public GUI::SettingsWindow::Tab {
VT::TerminalWidget::BellMode m_original_bell_mode;
bool m_orignal_confirm_close { true };
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@GUI::Widget {
@TerminalSettings::MainWidget {
fill_with_background_color: true
layout: @GUI::VerticalBoxLayout {
margins: [10]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@GUI::Widget {
@TerminalSettings::ViewWidget {
fill_with_background_color: true
layout: @GUI::VerticalBoxLayout {
margins: [10]
Expand Down Expand Up @@ -27,7 +27,7 @@

@GUI::Label {
background_role: "Base"
style: "SunkenContainer"
frame_style: "SunkenContainer"
fill_with_background_color: true
name: "terminal_font_label"
}
Expand Down Expand Up @@ -111,7 +111,6 @@
name: "history_size_spinbox"
min: 0
max: 40960
orientation: "Horizontal"
preferred_width: 100
}

Expand Down
17 changes: 8 additions & 9 deletions Userland/Applications/TerminalSettings/ViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <AK/Assertions.h>
#include <AK/JsonObject.h>
#include <AK/QuickSort.h>
#include <Applications/TerminalSettings/TerminalSettingsViewGML.h>
#include <LibConfig/Client.h>
#include <LibCore/DirIterator.h>
#include <LibGUI/Application.h>
Expand All @@ -28,17 +27,16 @@
#include <LibVT/TerminalWidget.h>
#include <spawn.h>

ErrorOr<NonnullRefPtr<TerminalSettingsViewWidget>> TerminalSettingsViewWidget::try_create()
namespace TerminalSettings {
ErrorOr<NonnullRefPtr<ViewWidget>> 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<void> TerminalSettingsViewWidget::setup()
ErrorOr<void> ViewWidget::setup()
{
TRY(load_from_gml(terminal_settings_view_gml));

auto& slider = *find_descendant_of_type_named<GUI::HorizontalOpacitySlider>("background_opacity_slider");
m_opacity = Config::read_i32("Terminal"sv, "Window"sv, "Opacity"sv);
m_original_opacity = m_opacity;
Expand Down Expand Up @@ -166,7 +164,7 @@ ErrorOr<void> TerminalSettingsViewWidget::setup()
return {};
}

void TerminalSettingsViewWidget::apply_settings()
void ViewWidget::apply_settings()
{
m_original_opacity = m_opacity;
m_original_font = m_font;
Expand All @@ -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<i32>(m_original_opacity));
Config::write_string("Terminal"sv, "Text"sv, "Font"sv, m_original_font->qualified_name());
Expand All @@ -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();
}
}
9 changes: 6 additions & 3 deletions Userland/Applications/TerminalSettings/ViewWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
#include <LibGUI/TextEditor.h>
#include <LibVT/TerminalWidget.h>

class TerminalSettingsViewWidget final : public GUI::SettingsWindow::Tab {
namespace TerminalSettings {
class ViewWidget final : public GUI::SettingsWindow::Tab {
C_OBJECT_ABSTRACT(TerminalSettingsViewWidget)
public:
static ErrorOr<NonnullRefPtr<TerminalSettingsViewWidget>> try_create();
static ErrorOr<NonnullRefPtr<ViewWidget>> try_create();
static ErrorOr<NonnullRefPtr<ViewWidget>> create();

virtual void apply_settings() override;
virtual void cancel_settings() override;

private:
TerminalSettingsViewWidget() = default;
ViewWidget() = default;
ErrorOr<void> setup();
void write_back_settings() const;

Expand All @@ -42,3 +44,4 @@ class TerminalSettingsViewWidget final : public GUI::SettingsWindow::Tab {
size_t m_original_max_history_size;
bool m_original_show_scrollbar { true };
};
}
4 changes: 2 additions & 2 deletions Userland/Applications/TerminalSettings/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ ErrorOr<int> 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<TerminalSettingsViewWidget>("View"_string, "view"sv));
(void)TRY(window->add_tab<TerminalSettingsMainWidget>("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();
Expand Down

0 comments on commit 2440a2f

Please sign in to comment.