1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:37:37 +00:00

TextEditor: Rename TextEditorWidget => TextEditor::MainWidget

This commit is contained in:
Andreas Kling 2021-05-01 18:26:44 +02:00
parent 2fa765bbd5
commit b424e6c86f
4 changed files with 37 additions and 26 deletions

View file

@ -2,7 +2,7 @@ compile_gml(TextEditorWindow.gml TextEditorWindowGML.h text_editor_window_gml)
set(SOURCES
main.cpp
TextEditorWidget.cpp
MainWidget.cpp
TextEditorWindowGML.h
)

View file

@ -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());
}
}

View file

@ -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 };
};
}

View file

@ -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;