From 0cd4b8cbb7529dbf108a5f6ecf7b86987a90c59c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 25 Aug 2021 23:56:50 +0200 Subject: [PATCH] TextEditor: Use LibConfig instead of Core::ConfigFile --- .../Applications/TextEditor/CMakeLists.txt | 2 +- .../Applications/TextEditor/MainWidget.cpp | 27 +++++-------------- Userland/Applications/TextEditor/MainWidget.h | 4 --- Userland/Applications/TextEditor/main.cpp | 9 +++---- 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/Userland/Applications/TextEditor/CMakeLists.txt b/Userland/Applications/TextEditor/CMakeLists.txt index 94d15da7928..8d2993c363b 100644 --- a/Userland/Applications/TextEditor/CMakeLists.txt +++ b/Userland/Applications/TextEditor/CMakeLists.txt @@ -15,4 +15,4 @@ set(SOURCES ) serenity_app(TextEditor ICON app-text-editor) -target_link_libraries(TextEditor LibWeb LibMarkdown LibGUI LibShell LibRegex LibDesktop LibCpp LibJS LibSQL LibFileSystemAccessClient) +target_link_libraries(TextEditor LibWeb LibMarkdown LibGUI LibShell LibRegex LibDesktop LibCpp LibJS LibSQL LibFileSystemAccessClient LibConfig) diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index 157daea08bf..e92e161efbf 100644 --- a/Userland/Applications/TextEditor/MainWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -46,8 +47,6 @@ MainWidget::MainWidget() { load_from_gml(text_editor_window_gml); - m_config = open_config_file(); - m_toolbar = *find_descendant_of_type_named("toolbar"); m_toolbar_container = *find_descendant_of_type_named("toolbar_container"); @@ -344,15 +343,6 @@ MainWidget::~MainWidget() { } -static RefPtr s_config; - -RefPtr MainWidget::open_config_file() -{ - if (!s_config) - s_config = Core::ConfigFile::open_for_app("TextEditor", Core::ConfigFile::AllowWriting::Yes); - return s_config; -} - Web::OutOfProcessWebView& MainWidget::ensure_web_view() { if (!m_page_view) { @@ -432,28 +422,25 @@ void MainWidget::initialize_menubar(GUI::Window& window) m_layout_toolbar_action = GUI::Action::create_checkable("&Toolbar", [&](auto& action) { action.is_checked() ? m_toolbar_container->set_visible(true) : m_toolbar_container->set_visible(false); - m_config->write_bool_entry("Layout", "ShowToolbar", action.is_checked()); - m_config->sync(); + Config::write_bool("TextEditor", "Layout", "ShowToolbar", action.is_checked()); }); - auto show_toolbar = m_config->read_bool_entry("Layout", "ShowToolbar", true); + auto show_toolbar = Config::read_bool("TextEditor", "Layout", "ShowToolbar", true); m_layout_toolbar_action->set_checked(show_toolbar); m_toolbar_container->set_visible(show_toolbar); m_layout_statusbar_action = GUI::Action::create_checkable("&Status Bar", [&](auto& action) { action.is_checked() ? m_statusbar->set_visible(true) : m_statusbar->set_visible(false); - m_config->write_bool_entry("Layout", "ShowStatusbar", action.is_checked()); - m_config->sync(); + Config::write_bool("TextEditor", "Layout", "ShowStatusbar", action.is_checked()); }); - auto show_statusbar = m_config->read_bool_entry("Layout", "ShowStatusbar", true); + auto show_statusbar = Config::read_bool("TextEditor", "Layout", "ShowStatusbar", true); m_layout_statusbar_action->set_checked(show_statusbar); m_statusbar->set_visible(show_statusbar); m_layout_ruler_action = GUI::Action::create_checkable("Ruler", [&](auto& action) { action.is_checked() ? m_editor->set_ruler_visible(true) : m_editor->set_ruler_visible(false); - m_config->write_bool_entry("Layout", "ShowRuler", action.is_checked()); - m_config->sync(); + Config::write_bool("TextEditor", "Layout", "ShowRuler", action.is_checked()); }); - auto show_ruler = m_config->read_bool_entry("Layout", "ShowRuler", true); + auto show_ruler = Config::read_bool("TextEditor", "Layout", "ShowRuler", true); m_layout_ruler_action->set_checked(show_ruler); m_editor->set_ruler_visible(show_ruler); diff --git a/Userland/Applications/TextEditor/MainWidget.h b/Userland/Applications/TextEditor/MainWidget.h index fad97abfaa1..c620affe1ed 100644 --- a/Userland/Applications/TextEditor/MainWidget.h +++ b/Userland/Applications/TextEditor/MainWidget.h @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -43,8 +42,6 @@ public: void update_title(); void initialize_menubar(GUI::Window&); - static RefPtr open_config_file(); - private: MainWidget(); void set_path(StringView const&); @@ -126,7 +123,6 @@ private: RefPtr m_sql_highlight; RefPtr m_page_view; - RefPtr m_config; bool m_auto_detect_preview_mode { false }; bool m_use_regex { false }; diff --git a/Userland/Applications/TextEditor/main.cpp b/Userland/Applications/TextEditor/main.cpp index 34b1790f411..732bbf5ebbb 100644 --- a/Userland/Applications/TextEditor/main.cpp +++ b/Userland/Applications/TextEditor/main.cpp @@ -6,6 +6,7 @@ #include "FileArgument.h" #include "MainWidget.h" +#include #include #include #include @@ -23,6 +24,8 @@ int main(int argc, char** argv) auto app = GUI::Application::construct(argc, argv); + Config::pledge_domains("TextEditor"); + char const* preview_mode = "auto"; char const* file_to_edit = nullptr; Core::ArgsParser parser; @@ -32,7 +35,6 @@ int main(int argc, char** argv) parser.parse(argc, argv); String file_to_edit_full_path; - auto config_filename = MainWidget::open_config_file()->filename(); if (file_to_edit) { FileArgument parsed_argument(file_to_edit); @@ -48,11 +50,6 @@ int main(int argc, char** argv) } } - if (unveil(config_filename.characters(), "rwc") < 0) { - perror("unveil"); - return 1; - } - if (unveil("/res", "r") < 0) { perror("unveil"); return 1;