diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-01 18:26:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-01 19:42:29 +0200 |
commit | b424e6c86fb2b923849a1b4263e15ec00c0d83a7 (patch) | |
tree | 813368249a192353bc1bcd7326d54a7709ea5c86 /Userland/Applications | |
parent | 2fa765bbd53f2b07eba8012e350cdea8b8afe13c (diff) | |
download | serenity-b424e6c86fb2b923849a1b4263e15ec00c0d83a7.zip |
TextEditor: Rename TextEditorWidget => TextEditor::MainWidget
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/TextEditor/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Applications/TextEditor/MainWidget.cpp (renamed from Userland/Applications/TextEditor/TextEditorWidget.cpp) | 32 | ||||
-rw-r--r-- | Userland/Applications/TextEditor/MainWidget.h (renamed from Userland/Applications/TextEditor/TextEditorWidget.h) | 15 | ||||
-rw-r--r-- | Userland/Applications/TextEditor/main.cpp | 14 |
4 files changed, 37 insertions, 26 deletions
diff --git a/Userland/Applications/TextEditor/CMakeLists.txt b/Userland/Applications/TextEditor/CMakeLists.txt index 3cbbd52373..6550582a02 100644 --- a/Userland/Applications/TextEditor/CMakeLists.txt +++ b/Userland/Applications/TextEditor/CMakeLists.txt @@ -2,7 +2,7 @@ compile_gml(TextEditorWindow.gml TextEditorWindowGML.h text_editor_window_gml) set(SOURCES main.cpp - TextEditorWidget.cpp + MainWidget.cpp TextEditorWindowGML.h ) diff --git a/Userland/Applications/TextEditor/TextEditorWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index 8724942e1a..aba5901976 100644 --- a/Userland/Applications/TextEditor/TextEditorWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "TextEditorWidget.h" +#include "MainWidget.h" #include <AK/JsonObject.h> #include <AK/JsonValue.h> #include <AK/Optional.h> @@ -44,7 +44,9 @@ #include <LibWeb/OutOfProcessWebView.h> #include <Shell/SyntaxHighlighter.h> -TextEditorWidget::TextEditorWidget() +namespace TextEditor { + +MainWidget::MainWidget() { load_from_gml(text_editor_window_gml); @@ -347,11 +349,11 @@ TextEditorWidget::TextEditorWidget() m_toolbar->add_action(m_editor->redo_action()); } -TextEditorWidget::~TextEditorWidget() +MainWidget::~MainWidget() { } -void TextEditorWidget::initialize_menubar(GUI::Menubar& menubar) +void MainWidget::initialize_menubar(GUI::Menubar& menubar) { auto& file_menu = menubar.add_menu("&File"); file_menu.add_action(*m_new_action); @@ -580,7 +582,7 @@ void TextEditorWidget::initialize_menubar(GUI::Menubar& menubar) help_menu.add_action(GUI::CommonActions::make_about_action("Text Editor", GUI::Icon::default_icon("app-text-editor"), window())); } -void TextEditorWidget::set_path(const LexicalPath& lexical_path) +void MainWidget::set_path(const LexicalPath& lexical_path) { m_path = lexical_path.string(); m_name = lexical_path.title(); @@ -610,7 +612,7 @@ void TextEditorWidget::set_path(const LexicalPath& lexical_path) update_title(); } -void TextEditorWidget::update_title() +void MainWidget::update_title() { StringBuilder builder; if (m_path.is_empty()) @@ -623,7 +625,7 @@ void TextEditorWidget::update_title() window()->set_title(builder.to_string()); } -bool TextEditorWidget::open_file(const String& path) +bool MainWidget::open_file(const String& path) { auto file = Core::File::construct(path); if (!file->open(Core::IODevice::ReadOnly) && file->error() != ENOENT) { @@ -647,7 +649,7 @@ bool TextEditorWidget::open_file(const String& path) return true; } -bool TextEditorWidget::request_close() +bool MainWidget::request_close() { if (!m_document_dirty) return true; @@ -664,7 +666,7 @@ bool TextEditorWidget::request_close() return false; } -void TextEditorWidget::drop_event(GUI::DropEvent& event) +void MainWidget::drop_event(GUI::DropEvent& event) { event.accept(); window()->move_to_front(); @@ -681,7 +683,7 @@ void TextEditorWidget::drop_event(GUI::DropEvent& event) } } -void TextEditorWidget::set_preview_mode(PreviewMode mode) +void MainWidget::set_preview_mode(PreviewMode mode) { if (m_preview_mode == mode) return; @@ -701,7 +703,7 @@ void TextEditorWidget::set_preview_mode(PreviewMode mode) } } -void TextEditorWidget::update_preview() +void MainWidget::update_preview() { switch (m_preview_mode) { case PreviewMode::Markdown: @@ -715,7 +717,7 @@ void TextEditorWidget::update_preview() } } -void TextEditorWidget::update_markdown_preview() +void MainWidget::update_markdown_preview() { auto document = Markdown::Document::parse(m_editor->text()); if (document) { @@ -726,14 +728,14 @@ void TextEditorWidget::update_markdown_preview() } } -void TextEditorWidget::update_html_preview() +void MainWidget::update_html_preview() { auto current_scroll_pos = m_page_view->visible_content_rect(); m_page_view->load_html(m_editor->text(), URL::create_with_file_protocol(m_path)); m_page_view->scroll_into_view(current_scroll_pos, true, true); } -void TextEditorWidget::update_statusbar() +void MainWidget::update_statusbar() { StringBuilder builder; builder.appendff("Line: {}, Column: {}", m_editor->cursor().line() + 1, m_editor->cursor().column()); @@ -757,3 +759,5 @@ void TextEditorWidget::update_statusbar() } m_statusbar->set_text(builder.to_string()); } + +} diff --git a/Userland/Applications/TextEditor/TextEditorWidget.h b/Userland/Applications/TextEditor/MainWidget.h index 270e4f0fbb..7abaafeffb 100644 --- a/Userland/Applications/TextEditor/TextEditorWidget.h +++ b/Userland/Applications/TextEditor/MainWidget.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -16,10 +16,13 @@ #include <LibGUI/Window.h> #include <LibWeb/Forward.h> -class TextEditorWidget final : public GUI::Widget { - C_OBJECT(TextEditorWidget) +namespace TextEditor { + +class MainWidget final : public GUI::Widget { + C_OBJECT(MainWidget); + public: - virtual ~TextEditorWidget() override; + virtual ~MainWidget() override; bool open_file(const String& path); bool request_close(); @@ -38,7 +41,7 @@ public: void initialize_menubar(GUI::Menubar&); private: - TextEditorWidget(); + MainWidget(); void set_path(const LexicalPath& file); void update_preview(); void update_markdown_preview(); @@ -124,3 +127,5 @@ private: PreviewMode m_preview_mode { PreviewMode::None }; }; + +} diff --git a/Userland/Applications/TextEditor/main.cpp b/Userland/Applications/TextEditor/main.cpp index b514ee31b9..d4ee1d114a 100644 --- a/Userland/Applications/TextEditor/main.cpp +++ b/Userland/Applications/TextEditor/main.cpp @@ -1,16 +1,18 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ -#include "TextEditorWidget.h" +#include "MainWidget.h" #include <LibCore/ArgsParser.h> #include <LibGUI/Menubar.h> #include <LibGfx/Bitmap.h> #include <stdio.h> #include <unistd.h> +using namespace TextEditor; + int main(int argc, char** argv) { if (pledge("stdio recvfd sendfd thread rpath accept cpath wpath unix fattr", nullptr) < 0) { @@ -42,7 +44,7 @@ int main(int argc, char** argv) auto window = GUI::Window::construct(); window->resize(640, 400); - auto& text_widget = window->set_main_widget<TextEditorWidget>(); + auto& text_widget = window->set_main_widget<MainWidget>(); text_widget.editor().set_focus(true); @@ -55,11 +57,11 @@ int main(int argc, char** argv) if (preview_mode_view == "auto") { text_widget.set_auto_detect_preview_mode(true); } else if (preview_mode_view == "markdown") { - text_widget.set_preview_mode(TextEditorWidget::PreviewMode::Markdown); + text_widget.set_preview_mode(MainWidget::PreviewMode::Markdown); } else if (preview_mode_view == "html") { - text_widget.set_preview_mode(TextEditorWidget::PreviewMode::HTML); + text_widget.set_preview_mode(MainWidget::PreviewMode::HTML); } else if (preview_mode_view == "none") { - text_widget.set_preview_mode(TextEditorWidget::PreviewMode::None); + text_widget.set_preview_mode(MainWidget::PreviewMode::None); } else { warnln("Invalid mode '{}'", preview_mode); return 1; |