mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
TerminalSettings: Port to GML Compiler
This commit is contained in:
parent
f6c32ea45e
commit
2440a2f83f
8 changed files with 39 additions and 39 deletions
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -35,3 +37,4 @@ private:
|
|||
VT::TerminalWidget::BellMode m_original_bell_mode;
|
||||
bool m_orignal_confirm_close { true };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@GUI::Widget {
|
||||
@TerminalSettings::MainWidget {
|
||||
fill_with_background_color: true
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [10]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -42,3 +44,4 @@ private:
|
|||
size_t m_original_max_history_size;
|
||||
bool m_original_show_scrollbar { true };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue