diff options
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/TextEditor/TextEditorWidget.cpp | 31 | ||||
-rw-r--r-- | Applications/TextEditor/TextEditorWidget.h | 9 |
2 files changed, 39 insertions, 1 deletions
diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index e0d14a3bc7..39b339de3c 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -74,6 +74,9 @@ TextEditorWidget::TextEditorWidget() if (m_markdown_preview_enabled) update_markdown_preview(); + if (m_html_preview_enabled) + update_html_preview(); + // Do not mark as dirty on the first change (When document is first opened.) if (m_document_opening) { m_document_opening = false; @@ -390,10 +393,21 @@ TextEditorWidget::TextEditorWidget() }, this); + m_html_preview_action = GUI::Action::create_checkable( + "HTML preview", [this](auto& action) { + set_html_preview_enabled(action.is_checked()); + }, + this); + + m_preview_actions.add_action(*m_markdown_preview_action); + m_preview_actions.add_action(*m_html_preview_action); + m_preview_actions.set_exclusive(true); + auto& view_menu = menubar->add_menu("View"); view_menu.add_action(*m_line_wrapping_setting_action); view_menu.add_separator(); view_menu.add_action(*m_markdown_preview_action); + view_menu.add_action(*m_html_preview_action); view_menu.add_separator(); auto& font_menu = view_menu.add_submenu("Font"); @@ -481,6 +495,7 @@ void TextEditorWidget::set_path(const LexicalPath& lexical_path) } set_markdown_preview_enabled(m_extension == "md"); + set_html_preview_enabled(m_extension == "html"); update_title(); } @@ -546,6 +561,17 @@ void TextEditorWidget::drop_event(GUI::DropEvent& event) } } +void TextEditorWidget::set_html_preview_enabled(bool enabled) +{ + if (m_html_preview_enabled == enabled) + return; + m_html_preview_enabled = enabled; + m_html_preview_action->set_checked(enabled); + m_page_view->set_visible(enabled); + if (enabled) + update_html_preview(); +} + void TextEditorWidget::set_markdown_preview_enabled(bool enabled) { if (m_markdown_preview_enabled == enabled) @@ -565,3 +591,8 @@ void TextEditorWidget::update_markdown_preview() m_page_view->load_html(html, URL::create_with_file_protocol(m_path)); } } + +void TextEditorWidget::update_html_preview() +{ + m_page_view->load_html(m_editor->text(), URL::create_with_file_protocol(m_path)); +} diff --git a/Applications/TextEditor/TextEditorWidget.h b/Applications/TextEditor/TextEditorWidget.h index cb21db1bc3..23802f531a 100644 --- a/Applications/TextEditor/TextEditorWidget.h +++ b/Applications/TextEditor/TextEditorWidget.h @@ -45,12 +45,14 @@ public: GUI::TextEditor& editor() { return *m_editor; } void set_markdown_preview_enabled(bool); + void set_html_preview_enabled(bool); private: TextEditorWidget(); void set_path(const LexicalPath& file); void update_title(); void update_markdown_preview(); + void update_html_preview(); virtual void drop_event(GUI::DropEvent&) override; @@ -64,13 +66,17 @@ private: RefPtr<GUI::Action> m_save_as_action; RefPtr<GUI::Action> m_find_replace_action; RefPtr<GUI::Action> m_line_wrapping_setting_action; - RefPtr<GUI::Action> m_markdown_preview_action; + RefPtr<GUI::Action> m_find_next_action; RefPtr<GUI::Action> m_find_previous_action; RefPtr<GUI::Action> m_replace_next_action; RefPtr<GUI::Action> m_replace_previous_action; RefPtr<GUI::Action> m_replace_all_action; + GUI::ActionGroup m_preview_actions; + RefPtr<GUI::Action> m_markdown_preview_action; + RefPtr<GUI::Action> m_html_preview_action; + RefPtr<GUI::StatusBar> m_statusbar; RefPtr<GUI::TextBox> m_find_textbox; @@ -95,4 +101,5 @@ private: bool m_document_dirty { false }; bool m_document_opening { false }; bool m_markdown_preview_enabled { false }; + bool m_html_preview_enabled { false }; }; |