diff options
author | thankyouverycool <n/a> | 2021-02-12 12:34:04 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-13 11:01:59 +0100 |
commit | 5a03b326a79042b1672e2546ca15d457edbf38c2 (patch) | |
tree | d63a112aa11d9c8e6c424813770073fda6f51339 | |
parent | c877612211e3eada3cedd489a088c04440b6c459 (diff) | |
download | serenity-5a03b326a79042b1672e2546ca15d457edbf38c2.zip |
TextEditor: Add layout options to View menu
Toolbar, status bar, and ruler can now be toggled on/off and their
settings are saved in ~/.config/TextEditor.ini
4 files changed, 49 insertions, 0 deletions
diff --git a/Base/home/anon/.config/TextEditor.ini b/Base/home/anon/.config/TextEditor.ini new file mode 100644 index 0000000000..e45dc6dea1 --- /dev/null +++ b/Base/home/anon/.config/TextEditor.ini @@ -0,0 +1,4 @@ +[Layout] +ShowRuler=1 +ShowToolbar=1 +ShowStatusBar=1 diff --git a/Userland/Applications/TextEditor/TextEditorWidget.cpp b/Userland/Applications/TextEditor/TextEditorWidget.cpp index 3bff09c7b2..c273d42e01 100644 --- a/Userland/Applications/TextEditor/TextEditorWidget.cpp +++ b/Userland/Applications/TextEditor/TextEditorWidget.cpp @@ -31,6 +31,7 @@ #include <AK/StringBuilder.h> #include <AK/URL.h> #include <Applications/TextEditor/TextEditorWindowGML.h> +#include <LibCore/ConfigFile.h> #include <LibCore/File.h> #include <LibCore/MimeData.h> #include <LibCpp/SyntaxHighlighter.h> @@ -65,7 +66,10 @@ TextEditorWidget::TextEditorWidget() { load_from_gml(text_editor_window_gml); + m_config = Core::ConfigFile::get_for_app("TextEditor"); + auto& toolbar = *find_descendant_of_type_named<GUI::ToolBar>("toolbar"); + auto& toolbar_container = *find_descendant_of_type_named<GUI::ToolBarContainer>("toolbar_container"); m_editor = *find_descendant_of_type_named<GUI::TextEditor>("editor"); m_editor->set_ruler_visible(true); @@ -417,7 +421,41 @@ TextEditorWidget::TextEditorWidget() m_preview_actions.add_action(*m_html_preview_action); m_preview_actions.set_exclusive(true); + m_layout_toolbar_action = GUI::Action::create_checkable("Toolbar", [&](auto& action) { + action.is_checked() ? toolbar_container.set_visible(true) : toolbar_container.set_visible(false); + m_config->write_bool_entry("Layout", "ShowToolbar", action.is_checked()); + m_config->sync(); + }); + auto show_toolbar = m_config->read_bool_entry("Layout", "ShowToolbar", true); + m_layout_toolbar_action->set_checked(show_toolbar); + 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(); + }); + auto show_statusbar = m_config->read_bool_entry("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(); + }); + auto show_ruler = m_config->read_bool_entry("Layout", "ShowRuler", true); + m_layout_ruler_action->set_checked(show_ruler); + m_editor->set_ruler_visible(show_ruler); + auto& view_menu = menubar->add_menu("View"); + auto& layout_menu = view_menu.add_submenu("Layout"); + layout_menu.add_action(*m_layout_toolbar_action); + layout_menu.add_action(*m_layout_statusbar_action); + layout_menu.add_action(*m_layout_ruler_action); + + view_menu.add_separator(); + view_menu.add_action(GUI::Action::create("Editor font...", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png"), [&](auto&) { auto picker = GUI::FontPicker::construct(window(), &m_editor->font(), true); diff --git a/Userland/Applications/TextEditor/TextEditorWidget.h b/Userland/Applications/TextEditor/TextEditorWidget.h index 8359df6fbe..20f7b3a9ba 100644 --- a/Userland/Applications/TextEditor/TextEditorWidget.h +++ b/Userland/Applications/TextEditor/TextEditorWidget.h @@ -84,6 +84,10 @@ private: RefPtr<GUI::Action> m_replace_previous_action; RefPtr<GUI::Action> m_replace_all_action; + RefPtr<GUI::Action> m_layout_toolbar_action; + RefPtr<GUI::Action> m_layout_statusbar_action; + RefPtr<GUI::Action> m_layout_ruler_action; + GUI::ActionGroup m_preview_actions; RefPtr<GUI::Action> m_no_preview_action; RefPtr<GUI::Action> m_markdown_preview_action; @@ -117,6 +121,7 @@ private: RefPtr<GUI::Action> m_shell_highlight; RefPtr<Web::OutOfProcessWebView> m_page_view; + RefPtr<Core::ConfigFile> m_config; bool m_document_dirty { false }; bool m_document_opening { false }; diff --git a/Userland/Applications/TextEditor/TextEditorWindow.gml b/Userland/Applications/TextEditor/TextEditorWindow.gml index 433d01abff..ad02320c50 100644 --- a/Userland/Applications/TextEditor/TextEditorWindow.gml +++ b/Userland/Applications/TextEditor/TextEditorWindow.gml @@ -7,6 +7,8 @@ } @GUI::ToolBarContainer { + name: "toolbar_container" + @GUI::ToolBar { name: "toolbar" } |