TextEditorWidget.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <AK/Function.h>
  28. #include <AK/LexicalPath.h>
  29. #include <LibGUI/ActionGroup.h>
  30. #include <LibGUI/Application.h>
  31. #include <LibGUI/Icon.h>
  32. #include <LibGUI/TextEditor.h>
  33. #include <LibGUI/Widget.h>
  34. #include <LibGUI/Window.h>
  35. #include <LibWeb/Forward.h>
  36. class TextEditorWidget final : public GUI::Widget {
  37. C_OBJECT(TextEditorWidget)
  38. public:
  39. virtual ~TextEditorWidget() override;
  40. void open_sesame(const String& path);
  41. bool request_close();
  42. GUI::TextEditor& editor() { return *m_editor; }
  43. enum class PreviewMode {
  44. None,
  45. Markdown,
  46. HTML,
  47. };
  48. void set_preview_mode(PreviewMode);
  49. void set_auto_detect_preview_mode(bool value) { m_auto_detect_preview_mode = value; }
  50. private:
  51. TextEditorWidget();
  52. void set_path(const LexicalPath& file);
  53. void update_title();
  54. void update_preview();
  55. void update_markdown_preview();
  56. void update_html_preview();
  57. void update_statusbar_cursor_position();
  58. virtual void drop_event(GUI::DropEvent&) override;
  59. RefPtr<GUI::TextEditor> m_editor;
  60. String m_path;
  61. String m_name;
  62. String m_extension;
  63. RefPtr<GUI::Action> m_new_action;
  64. RefPtr<GUI::Action> m_open_action;
  65. RefPtr<GUI::Action> m_save_action;
  66. RefPtr<GUI::Action> m_save_as_action;
  67. RefPtr<GUI::Action> m_find_replace_action;
  68. RefPtr<GUI::Action> m_line_wrapping_setting_action;
  69. RefPtr<GUI::Action> m_find_next_action;
  70. RefPtr<GUI::Action> m_find_regex_action;
  71. RefPtr<GUI::Action> m_find_previous_action;
  72. RefPtr<GUI::Action> m_replace_next_action;
  73. RefPtr<GUI::Action> m_replace_previous_action;
  74. RefPtr<GUI::Action> m_replace_all_action;
  75. GUI::ActionGroup m_preview_actions;
  76. RefPtr<GUI::Action> m_no_preview_action;
  77. RefPtr<GUI::Action> m_markdown_preview_action;
  78. RefPtr<GUI::Action> m_html_preview_action;
  79. RefPtr<GUI::StatusBar> m_statusbar;
  80. RefPtr<GUI::TextBox> m_find_textbox;
  81. RefPtr<GUI::TextBox> m_replace_textbox;
  82. RefPtr<GUI::Button> m_find_previous_button;
  83. RefPtr<GUI::Button> m_find_next_button;
  84. RefPtr<GUI::Button> m_find_regex_button;
  85. RefPtr<GUI::Button> m_replace_previous_button;
  86. RefPtr<GUI::Button> m_replace_next_button;
  87. RefPtr<GUI::Button> m_replace_all_button;
  88. RefPtr<GUI::Widget> m_find_replace_widget;
  89. RefPtr<GUI::Widget> m_find_widget;
  90. RefPtr<GUI::Widget> m_replace_widget;
  91. GUI::ActionGroup syntax_actions;
  92. RefPtr<GUI::Action> m_plain_text_highlight;
  93. RefPtr<GUI::Action> m_cpp_highlight;
  94. RefPtr<GUI::Action> m_js_highlight;
  95. RefPtr<GUI::Action> m_gml_highlight;
  96. RefPtr<GUI::Action> m_ini_highlight;
  97. RefPtr<GUI::Action> m_shell_highlight;
  98. RefPtr<Web::OutOfProcessWebView> m_page_view;
  99. GUI::ActionGroup font_actions;
  100. bool m_document_dirty { false };
  101. bool m_document_opening { false };
  102. bool m_auto_detect_preview_mode { false };
  103. bool m_find_use_regex { false };
  104. PreviewMode m_preview_mode { PreviewMode::None };
  105. };