Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TerminalSettings: Port to GML Compiler #22512

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Meta/Lagom/Tools/CodeGenerators/GMLCompiler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static Optional<StringView> 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 },
};
Expand Down Expand Up @@ -173,6 +174,7 @@ static ErrorOr<Optional<String>> generate_enum_initializer_for(StringView proper
static HashMap<StringView, StringView> 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 },
Expand All @@ -182,6 +184,7 @@ static ErrorOr<Optional<String>> 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);
Expand Down
14 changes: 6 additions & 8 deletions Userland/Applications/TerminalSettings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +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
TerminalSettingsWidget.cpp
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)
125 changes: 125 additions & 0 deletions Userland/Applications/TerminalSettings/MainWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (c) 2018-2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include "MainWidget.h"
#include <AK/Assertions.h>
#include <AK/JsonObject.h>
#include <AK/QuickSort.h>
#include <LibConfig/Client.h>
#include <LibCore/DirIterator.h>
#include <LibGUI/Application.h>
#include <LibGUI/Button.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/FontPicker.h>
#include <LibGUI/ItemListModel.h>
#include <LibGUI/Label.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/OpacitySlider.h>
#include <LibGUI/RadioButton.h>
#include <LibGUI/SpinBox.h>
#include <LibGUI/Widget.h>
#include <LibGfx/Font/Font.h>
#include <LibGfx/Font/FontDatabase.h>
#include <LibKeyboard/CharacterMap.h>
#include <LibVT/TerminalWidget.h>
#include <spawn.h>

namespace TerminalSettings {
ErrorOr<NonnullRefPtr<MainWidget>> MainWidget::create()
{
auto widget = MainWidget::try_create().release_value_but_fixme_should_propagate_errors();
TRY(widget->setup());
return widget;
}

ErrorOr<void> MainWidget::setup()
{
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");

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<GUI::CheckBox>("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 MainWidget::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 MainWidget::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 MainWidget::apply_settings()
{
m_original_bell_mode = m_bell_mode;
m_orignal_confirm_close = m_confirm_close;
write_back_settings();
}
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 MainWidget::cancel_settings()
{
write_back_settings();
}
}
40 changes: 40 additions & 0 deletions Userland/Applications/TerminalSettings/MainWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2018-2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibGUI/Button.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/SettingsWindow.h>
#include <LibGUI/TextEditor.h>
#include <LibVT/TerminalWidget.h>

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

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

private:
static ErrorOr<NonnullRefPtr<MainWidget>> try_create();
MainWidget() = default;
ErrorOr<void> 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 };
};
}
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
Loading
Loading