mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
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
This commit is contained in:
parent
c877612211
commit
5a03b326a7
Notes:
sideshowbarker
2024-07-19 17:29:51 +09:00
Author: https://github.com/thankyouverycool 🔰 Commit: https://github.com/SerenityOS/serenity/commit/5a03b326a79 Pull-request: https://github.com/SerenityOS/serenity/pull/5313
4 changed files with 49 additions and 0 deletions
4
Base/home/anon/.config/TextEditor.ini
Normal file
4
Base/home/anon/.config/TextEditor.ini
Normal file
|
@ -0,0 +1,4 @@
|
|||
[Layout]
|
||||
ShowRuler=1
|
||||
ShowToolbar=1
|
||||
ShowStatusBar=1
|
|
@ -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);
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
}
|
||||
|
||||
@GUI::ToolBarContainer {
|
||||
name: "toolbar_container"
|
||||
|
||||
@GUI::ToolBar {
|
||||
name: "toolbar"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue