HackStudio: Save editor's font in configs

This commit is contained in:
Marco Cutecchia 2021-10-06 16:53:43 +02:00 committed by Andreas Kling
parent 423c2e44c9
commit 3c5e07fa1c
2 changed files with 15 additions and 3 deletions

View file

@ -26,6 +26,7 @@
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <Kernel/API/InodeWatcherEvent.h>
#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
@ -1426,8 +1427,15 @@ void HackStudioWidget::update_history_actions()
RefPtr<Gfx::Font> HackStudioWidget::read_editor_font_from_config()
{
// FIXME: Actually read the font from config
return Gfx::FontDatabase::the().get("Csilla", "Regular", 10);
auto font_family = Config::read_string("HackStudio", "EditorFont", "Family", "Csilla");
auto font_variant = Config::read_string("HackStudio", "EditorFont", "Variant", "Regular");
auto font_size = Config::read_i32("HackStudio", "EditorFont", "Size", 10);
auto font = Gfx::FontDatabase::the().get(font_family, font_variant, font_size);
if (font.is_null())
return Gfx::FontDatabase::the().default_fixed_width_font();
return font;
}
void HackStudioWidget::change_editor_font(RefPtr<Gfx::Font> font)
@ -1437,7 +1445,9 @@ void HackStudioWidget::change_editor_font(RefPtr<Gfx::Font> font)
editor_wrapper.editor().set_font(*m_editor_font);
}
// TODO: Save into config
Config::write_string("HackStudio", "EditorFont", "Family", m_editor_font->family());
Config::write_string("HackStudio", "EditorFont", "Variant", m_editor_font->variant());
Config::write_i32("HackStudio", "EditorFont", "Size", m_editor_font->presentation_size());
}
}

View file

@ -9,6 +9,7 @@
#include "HackStudioWidget.h"
#include "Project.h"
#include <AK/StringBuilder.h>
#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibGUI/Application.h>
@ -38,6 +39,7 @@ int main(int argc, char** argv)
}
auto app = GUI::Application::construct(argc, argv);
Config::pledge_domains({ "HackStudio", "Terminal" });
auto window = GUI::Window::construct();
window->resize(840, 600);