2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2021-05-01 13:26:44 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-07-11 15:52:33 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2020-05-26 08:52:44 -03:00
|
|
|
#include <AK/LexicalPath.h>
|
2021-07-11 12:16:26 -03:00
|
|
|
#include <LibFileSystemAccessClient/Client.h>
|
2020-03-10 22:02:37 -03:00
|
|
|
#include <LibGUI/ActionGroup.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Application.h>
|
2020-11-02 16:30:17 -03:00
|
|
|
#include <LibGUI/Icon.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/TextEditor.h>
|
|
|
|
|
#include <LibGUI/Widget.h>
|
|
|
|
|
#include <LibGUI/Window.h>
|
2020-04-28 16:42:45 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2020-05-26 08:52:44 -03:00
|
|
|
|
2021-05-01 13:26:44 -03:00
|
|
|
namespace TextEditor {
|
|
|
|
|
|
|
|
|
|
class MainWidget final : public GUI::Widget {
|
|
|
|
|
C_OBJECT(MainWidget);
|
|
|
|
|
|
2019-07-11 15:52:33 -03:00
|
|
|
public:
|
2021-05-01 13:26:44 -03:00
|
|
|
virtual ~MainWidget() override;
|
2021-06-30 10:13:06 -03:00
|
|
|
bool read_file_and_close(int fd, String const& path);
|
2021-07-21 14:35:52 -03:00
|
|
|
void open_nonexistent_file(String const& path);
|
2019-08-27 15:37:41 -03:00
|
|
|
bool request_close();
|
2019-07-11 15:52:33 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
GUI::TextEditor& editor() { return *m_editor; }
|
2019-11-30 11:34:08 -03:00
|
|
|
|
2020-07-04 16:19:01 -03:00
|
|
|
enum class PreviewMode {
|
|
|
|
|
None,
|
|
|
|
|
Markdown,
|
|
|
|
|
HTML,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void set_preview_mode(PreviewMode);
|
2020-07-06 11:18:49 -03:00
|
|
|
void set_auto_detect_preview_mode(bool value) { m_auto_detect_preview_mode = value; }
|
2020-04-28 16:42:45 -03:00
|
|
|
|
2020-12-29 23:44:38 -03:00
|
|
|
void update_title();
|
2021-07-21 16:21:03 -03:00
|
|
|
void initialize_menubar(GUI::Window&);
|
2020-12-29 23:44:38 -03:00
|
|
|
|
2019-07-11 15:52:33 -03:00
|
|
|
private:
|
2021-05-01 13:26:44 -03:00
|
|
|
MainWidget();
|
2021-06-29 15:12:53 -03:00
|
|
|
void set_path(StringView const&);
|
2020-07-04 16:19:01 -03:00
|
|
|
void update_preview();
|
2020-04-28 16:42:45 -03:00
|
|
|
void update_markdown_preview();
|
2020-06-26 17:47:29 -03:00
|
|
|
void update_html_preview();
|
2021-03-14 09:58:57 -03:00
|
|
|
void update_statusbar();
|
2019-07-24 01:32:30 -03:00
|
|
|
|
2021-05-20 17:00:31 -03:00
|
|
|
Web::OutOfProcessWebView& ensure_web_view();
|
|
|
|
|
void set_web_view_visible(bool);
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
virtual void drop_event(GUI::DropEvent&) override;
|
2019-12-19 16:20:20 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
RefPtr<GUI::TextEditor> m_editor;
|
2019-07-13 21:58:04 -03:00
|
|
|
String m_path;
|
2019-07-29 01:45:50 -03:00
|
|
|
String m_name;
|
|
|
|
|
String m_extension;
|
2020-02-02 11:07:41 -03:00
|
|
|
RefPtr<GUI::Action> m_new_action;
|
|
|
|
|
RefPtr<GUI::Action> m_open_action;
|
|
|
|
|
RefPtr<GUI::Action> m_save_action;
|
|
|
|
|
RefPtr<GUI::Action> m_save_as_action;
|
|
|
|
|
RefPtr<GUI::Action> m_find_replace_action;
|
2021-01-02 07:59:55 -03:00
|
|
|
RefPtr<GUI::Action> m_vim_emulation_setting_action;
|
2020-06-26 17:47:29 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
RefPtr<GUI::Action> m_find_next_action;
|
|
|
|
|
RefPtr<GUI::Action> m_find_previous_action;
|
2021-02-21 21:01:26 -03:00
|
|
|
RefPtr<GUI::Action> m_replace_action;
|
2020-02-02 11:07:41 -03:00
|
|
|
RefPtr<GUI::Action> m_replace_all_action;
|
2019-08-21 16:30:20 -03:00
|
|
|
|
2021-02-12 14:34:04 -03:00
|
|
|
RefPtr<GUI::Action> m_layout_toolbar_action;
|
|
|
|
|
RefPtr<GUI::Action> m_layout_statusbar_action;
|
|
|
|
|
RefPtr<GUI::Action> m_layout_ruler_action;
|
|
|
|
|
|
2020-06-26 17:47:29 -03:00
|
|
|
GUI::ActionGroup m_preview_actions;
|
2020-07-04 16:19:01 -03:00
|
|
|
RefPtr<GUI::Action> m_no_preview_action;
|
2020-06-26 17:47:29 -03:00
|
|
|
RefPtr<GUI::Action> m_markdown_preview_action;
|
|
|
|
|
RefPtr<GUI::Action> m_html_preview_action;
|
|
|
|
|
|
2021-04-13 11:18:20 -03:00
|
|
|
RefPtr<GUI::Toolbar> m_toolbar;
|
|
|
|
|
RefPtr<GUI::ToolbarContainer> m_toolbar_container;
|
|
|
|
|
RefPtr<GUI::Statusbar> m_statusbar;
|
2019-09-21 11:29:47 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
RefPtr<GUI::TextBox> m_find_textbox;
|
|
|
|
|
RefPtr<GUI::TextBox> m_replace_textbox;
|
2020-03-04 15:07:55 -03:00
|
|
|
RefPtr<GUI::Button> m_find_previous_button;
|
|
|
|
|
RefPtr<GUI::Button> m_find_next_button;
|
2021-02-21 21:01:26 -03:00
|
|
|
RefPtr<GUI::Button> m_replace_button;
|
2020-03-04 15:07:55 -03:00
|
|
|
RefPtr<GUI::Button> m_replace_all_button;
|
2020-02-02 11:07:41 -03:00
|
|
|
RefPtr<GUI::Widget> m_find_replace_widget;
|
|
|
|
|
RefPtr<GUI::Widget> m_find_widget;
|
|
|
|
|
RefPtr<GUI::Widget> m_replace_widget;
|
2021-02-21 21:01:26 -03:00
|
|
|
RefPtr<GUI::CheckBox> m_regex_checkbox;
|
|
|
|
|
RefPtr<GUI::CheckBox> m_match_case_checkbox;
|
|
|
|
|
RefPtr<GUI::CheckBox> m_wrap_around_checkbox;
|
2019-08-27 15:18:19 -03:00
|
|
|
|
2021-01-09 09:47:48 -03:00
|
|
|
GUI::ActionGroup m_wrapping_mode_actions;
|
|
|
|
|
RefPtr<GUI::Action> m_no_wrapping_action;
|
|
|
|
|
RefPtr<GUI::Action> m_wrap_anywhere_action;
|
|
|
|
|
RefPtr<GUI::Action> m_wrap_at_words_action;
|
|
|
|
|
|
2021-03-17 13:52:54 -03:00
|
|
|
RefPtr<GUI::Action> m_visualize_trailing_whitespace_action;
|
|
|
|
|
RefPtr<GUI::Action> m_visualize_leading_whitespace_action;
|
2021-09-11 12:08:01 -03:00
|
|
|
RefPtr<GUI::Action> m_cursor_line_highlighting_action;
|
2021-03-17 13:52:54 -03:00
|
|
|
|
2021-03-15 18:28:24 -03:00
|
|
|
GUI::ActionGroup m_soft_tab_width_actions;
|
|
|
|
|
RefPtr<GUI::Action> m_soft_tab_1_width_action;
|
|
|
|
|
RefPtr<GUI::Action> m_soft_tab_2_width_action;
|
|
|
|
|
RefPtr<GUI::Action> m_soft_tab_4_width_action;
|
|
|
|
|
RefPtr<GUI::Action> m_soft_tab_8_width_action;
|
|
|
|
|
RefPtr<GUI::Action> m_soft_tab_16_width_action;
|
|
|
|
|
|
2020-03-10 22:02:37 -03:00
|
|
|
GUI::ActionGroup syntax_actions;
|
|
|
|
|
RefPtr<GUI::Action> m_plain_text_highlight;
|
|
|
|
|
RefPtr<GUI::Action> m_cpp_highlight;
|
2020-03-12 19:53:22 -03:00
|
|
|
RefPtr<GUI::Action> m_js_highlight;
|
2021-05-20 15:47:30 -03:00
|
|
|
RefPtr<GUI::Action> m_html_highlight;
|
2020-12-21 09:59:21 -03:00
|
|
|
RefPtr<GUI::Action> m_gml_highlight;
|
2020-04-30 19:57:06 -03:00
|
|
|
RefPtr<GUI::Action> m_ini_highlight;
|
2020-09-28 07:58:44 -03:00
|
|
|
RefPtr<GUI::Action> m_shell_highlight;
|
2021-05-08 22:30:44 -03:00
|
|
|
RefPtr<GUI::Action> m_sql_highlight;
|
2020-03-10 22:02:37 -03:00
|
|
|
|
2020-10-08 17:12:10 -03:00
|
|
|
RefPtr<Web::OutOfProcessWebView> m_page_view;
|
2020-04-28 16:42:45 -03:00
|
|
|
|
2020-07-06 11:18:49 -03:00
|
|
|
bool m_auto_detect_preview_mode { false };
|
2021-02-21 21:01:26 -03:00
|
|
|
bool m_use_regex { false };
|
|
|
|
|
bool m_match_case { true };
|
|
|
|
|
bool m_should_wrap { true };
|
2020-07-04 16:19:01 -03:00
|
|
|
|
|
|
|
|
PreviewMode m_preview_mode { PreviewMode::None };
|
2019-07-24 01:32:30 -03:00
|
|
|
};
|
2021-05-01 13:26:44 -03:00
|
|
|
|
|
|
|
|
}
|