MainWidget.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include "MainWidget.h"
  8. #include <AK/Optional.h>
  9. #include <AK/StringBuilder.h>
  10. #include <AK/URL.h>
  11. #include <Applications/TextEditor/TextEditorWindowGML.h>
  12. #include <LibCMake/CMakeCache/SyntaxHighlighter.h>
  13. #include <LibCMake/SyntaxHighlighter.h>
  14. #include <LibConfig/Client.h>
  15. #include <LibCore/Debounce.h>
  16. #include <LibCpp/SyntaxHighlighter.h>
  17. #include <LibDesktop/Launcher.h>
  18. #include <LibGUI/Action.h>
  19. #include <LibGUI/BoxLayout.h>
  20. #include <LibGUI/Button.h>
  21. #include <LibGUI/CheckBox.h>
  22. #include <LibGUI/FilePicker.h>
  23. #include <LibGUI/FontPicker.h>
  24. #include <LibGUI/GML/SyntaxHighlighter.h>
  25. #include <LibGUI/GitCommitSyntaxHighlighter.h>
  26. #include <LibGUI/GroupBox.h>
  27. #include <LibGUI/INISyntaxHighlighter.h>
  28. #include <LibGUI/Menu.h>
  29. #include <LibGUI/Menubar.h>
  30. #include <LibGUI/MessageBox.h>
  31. #include <LibGUI/RegularEditingEngine.h>
  32. #include <LibGUI/Statusbar.h>
  33. #include <LibGUI/TextBox.h>
  34. #include <LibGUI/TextEditor.h>
  35. #include <LibGUI/Toolbar.h>
  36. #include <LibGUI/ToolbarContainer.h>
  37. #include <LibGUI/VimEditingEngine.h>
  38. #include <LibGfx/Font/Font.h>
  39. #include <LibGfx/Painter.h>
  40. #include <LibJS/SyntaxHighlighter.h>
  41. #include <LibMarkdown/Document.h>
  42. #include <LibSQL/AST/SyntaxHighlighter.h>
  43. #include <LibWeb/CSS/SyntaxHighlighter/SyntaxHighlighter.h>
  44. #include <LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.h>
  45. #include <LibWebView/OutOfProcessWebView.h>
  46. #include <Shell/SyntaxHighlighter.h>
  47. namespace TextEditor {
  48. MainWidget::MainWidget()
  49. {
  50. load_from_gml(text_editor_window_gml).release_value_but_fixme_should_propagate_errors();
  51. m_toolbar = *find_descendant_of_type_named<GUI::Toolbar>("toolbar");
  52. m_toolbar_container = *find_descendant_of_type_named<GUI::ToolbarContainer>("toolbar_container");
  53. m_editor = *find_descendant_of_type_named<GUI::TextEditor>("editor");
  54. m_editor->set_ruler_visible(true);
  55. m_editor->set_automatic_indentation_enabled(true);
  56. if (m_editor->editing_engine()->is_regular())
  57. m_editor->set_editing_engine(make<GUI::RegularEditingEngine>());
  58. else if (m_editor->editing_engine()->is_vim())
  59. m_editor->set_editing_engine(make<GUI::VimEditingEngine>());
  60. else
  61. VERIFY_NOT_REACHED();
  62. auto font_entry = Config::read_string("TextEditor"sv, "Text"sv, "Font"sv, "default"sv);
  63. if (font_entry != "default")
  64. m_editor->set_font(Gfx::FontDatabase::the().get_by_name(font_entry));
  65. m_editor->on_change = Core::debounce([this] {
  66. update_preview();
  67. },
  68. 100);
  69. m_editor->on_modified_change = [this](bool modified) {
  70. window()->set_modified(modified);
  71. };
  72. m_find_replace_widget = *find_descendant_of_type_named<GUI::GroupBox>("find_replace_widget");
  73. m_find_widget = *find_descendant_of_type_named<GUI::Widget>("find_widget");
  74. m_replace_widget = *find_descendant_of_type_named<GUI::Widget>("replace_widget");
  75. m_find_textbox = *find_descendant_of_type_named<GUI::TextBox>("find_textbox");
  76. m_find_textbox->set_placeholder("Find"sv);
  77. m_replace_textbox = *find_descendant_of_type_named<GUI::TextBox>("replace_textbox");
  78. m_replace_textbox->set_placeholder("Replace"sv);
  79. m_match_case_checkbox = *find_descendant_of_type_named<GUI::CheckBox>("match_case_checkbox");
  80. m_match_case_checkbox->on_checked = [this](auto is_checked) {
  81. m_match_case = is_checked;
  82. };
  83. m_match_case_checkbox->set_checked(true);
  84. m_regex_checkbox = *find_descendant_of_type_named<GUI::CheckBox>("regex_checkbox");
  85. m_regex_checkbox->on_checked = [this](auto is_checked) {
  86. m_use_regex = is_checked;
  87. };
  88. m_regex_checkbox->set_checked(false);
  89. m_wrap_around_checkbox = *find_descendant_of_type_named<GUI::CheckBox>("wrap_around_checkbox");
  90. m_wrap_around_checkbox->on_checked = [this](auto is_checked) {
  91. m_should_wrap = is_checked;
  92. };
  93. m_wrap_around_checkbox->set_checked(true);
  94. m_find_next_action = GUI::Action::create("Find &Next", { Mod_Ctrl, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find-next.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) {
  95. find_text(GUI::TextEditor::SearchDirection::Forward, ShowMessageIfNoResults::Yes);
  96. });
  97. m_find_previous_action = GUI::Action::create("Find Pr&evious", { Mod_Ctrl | Mod_Shift, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find-previous.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) {
  98. find_text(GUI::TextEditor::SearchDirection::Backward, ShowMessageIfNoResults::Yes);
  99. });
  100. m_replace_action = GUI::Action::create("Rep&lace", { Mod_Ctrl, Key_F1 }, [&](auto&) {
  101. auto needle = m_find_textbox->text();
  102. auto substitute = m_replace_textbox->text();
  103. if (needle.is_empty())
  104. return;
  105. if (m_use_regex)
  106. m_editor->document().update_regex_matches(needle);
  107. auto found_range = m_editor->document().find_next(needle, m_editor->normalized_selection().start(), m_should_wrap ? GUI::TextDocument::SearchShouldWrap::Yes : GUI::TextDocument::SearchShouldWrap::No, m_use_regex, m_match_case);
  108. if (found_range.is_valid()) {
  109. m_editor->set_selection(found_range);
  110. m_editor->insert_at_cursor_or_replace_selection(substitute);
  111. } else {
  112. GUI::MessageBox::show(window(),
  113. DeprecatedString::formatted("Not found: \"{}\"", needle),
  114. "Not found"sv,
  115. GUI::MessageBox::Type::Information);
  116. }
  117. });
  118. m_replace_all_action = GUI::Action::create("Replace &All", { Mod_Ctrl, Key_F2 }, [&](auto&) {
  119. auto needle = m_find_textbox->text();
  120. auto substitute = m_replace_textbox->text();
  121. auto length_delta = substitute.length() - needle.length();
  122. if (needle.is_empty())
  123. return;
  124. if (m_use_regex)
  125. m_editor->document().update_regex_matches(needle);
  126. auto found_range = m_editor->document().find_next(needle, {}, GUI::TextDocument::SearchShouldWrap::No, m_use_regex, m_match_case);
  127. if (found_range.is_valid()) {
  128. while (found_range.is_valid()) {
  129. m_editor->set_selection(found_range);
  130. m_editor->insert_at_cursor_or_replace_selection(substitute);
  131. auto next_start = GUI::TextPosition(found_range.end().line(), found_range.end().column() + length_delta);
  132. found_range = m_editor->document().find_next(needle, next_start, GUI::TextDocument::SearchShouldWrap::No, m_use_regex, m_match_case);
  133. }
  134. } else {
  135. GUI::MessageBox::show(window(),
  136. DeprecatedString::formatted("Not found: \"{}\"", needle),
  137. "Not found"sv,
  138. GUI::MessageBox::Type::Information);
  139. }
  140. });
  141. m_find_previous_button = *find_descendant_of_type_named<GUI::Button>("find_previous_button");
  142. m_find_previous_button->set_action(*m_find_previous_action);
  143. m_find_previous_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/find-previous.png"sv).release_value_but_fixme_should_propagate_errors());
  144. m_find_next_button = *find_descendant_of_type_named<GUI::Button>("find_next_button");
  145. m_find_next_button->set_action(*m_find_next_action);
  146. m_find_next_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/find-next.png"sv).release_value_but_fixme_should_propagate_errors());
  147. m_find_textbox->on_return_pressed = [this] {
  148. m_find_next_button->click();
  149. };
  150. m_find_textbox->on_escape_pressed = [this] {
  151. m_find_replace_widget->set_visible(false);
  152. m_editor->set_focus(true);
  153. m_editor->reset_search_results();
  154. };
  155. m_find_textbox->on_change = [this] {
  156. m_editor->reset_search_results();
  157. find_text(GUI::TextEditor::SearchDirection::Forward, ShowMessageIfNoResults::No);
  158. };
  159. m_replace_button = *find_descendant_of_type_named<GUI::Button>("replace_button");
  160. m_replace_button->set_action(*m_replace_action);
  161. m_replace_all_button = *find_descendant_of_type_named<GUI::Button>("replace_all_button");
  162. m_replace_all_button->set_action(*m_replace_all_action);
  163. m_replace_textbox->on_return_pressed = [this] {
  164. m_replace_button->click();
  165. };
  166. m_replace_textbox->on_escape_pressed = [this] {
  167. m_find_replace_widget->set_visible(false);
  168. m_editor->set_focus(true);
  169. };
  170. m_vim_emulation_setting_action = GUI::Action::create_checkable("&Vim Emulation", { Mod_Ctrl | Mod_Shift | Mod_Alt, Key_V }, [&](auto& action) {
  171. if (action.is_checked())
  172. m_editor->set_editing_engine(make<GUI::VimEditingEngine>());
  173. else
  174. m_editor->set_editing_engine(make<GUI::RegularEditingEngine>());
  175. });
  176. m_vim_emulation_setting_action->set_checked(false);
  177. m_find_replace_action = GUI::Action::create("&Find/Replace...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"sv).release_value_but_fixme_should_propagate_errors(), [this](auto&) {
  178. m_find_replace_widget->set_visible(true);
  179. m_find_widget->set_visible(true);
  180. m_replace_widget->set_visible(true);
  181. m_find_textbox->set_focus(true);
  182. if (m_editor->has_selection()) {
  183. auto selected_text = m_editor->document().text_in_range(m_editor->normalized_selection());
  184. m_find_textbox->set_text(selected_text);
  185. }
  186. m_find_textbox->select_all();
  187. });
  188. m_editor->add_custom_context_menu_action(*m_find_replace_action);
  189. m_editor->add_custom_context_menu_action(*m_find_next_action);
  190. m_editor->add_custom_context_menu_action(*m_find_previous_action);
  191. m_line_column_statusbar_menu = GUI::Menu::construct();
  192. m_syntax_statusbar_menu = GUI::Menu::construct();
  193. m_statusbar = *find_descendant_of_type_named<GUI::Statusbar>("statusbar");
  194. m_statusbar->segment(1).set_mode(GUI::Statusbar::Segment::Mode::Auto);
  195. m_statusbar->segment(1).set_clickable(true);
  196. m_statusbar->segment(1).set_menu(m_syntax_statusbar_menu);
  197. m_statusbar->segment(2).set_mode(GUI::Statusbar::Segment::Mode::Fixed);
  198. auto width = font().width("Ln 0000, Col 000"sv) + font().max_glyph_width();
  199. m_statusbar->segment(2).set_fixed_width(width);
  200. m_statusbar->segment(2).set_clickable(true);
  201. m_statusbar->segment(2).set_menu(m_line_column_statusbar_menu);
  202. GUI::Application::the()->on_action_enter = [this](GUI::Action& action) {
  203. auto text = action.status_tip();
  204. if (text.is_empty())
  205. text = Gfx::parse_ampersand_string(action.text());
  206. m_statusbar->set_override_text(move(text));
  207. };
  208. GUI::Application::the()->on_action_leave = [this](GUI::Action&) {
  209. m_statusbar->set_override_text({});
  210. };
  211. m_editor->on_cursor_change = [this] { update_statusbar(); };
  212. m_editor->on_selection_change = [this] { update_statusbar(); };
  213. m_editor->on_highlighter_change = [this] { update_statusbar(); };
  214. m_new_action = GUI::Action::create("&New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"sv).release_value_but_fixme_should_propagate_errors(), [this](GUI::Action const&) {
  215. if (editor().document().is_modified()) {
  216. auto save_document_first_result = GUI::MessageBox::ask_about_unsaved_changes(window(), m_path, editor().document().undo_stack().last_unmodified_timestamp());
  217. if (save_document_first_result == GUI::Dialog::ExecResult::Yes)
  218. m_save_action->activate();
  219. if (save_document_first_result != GUI::Dialog::ExecResult::No && editor().document().is_modified())
  220. return;
  221. }
  222. m_editor->set_text(StringView());
  223. set_path({});
  224. update_title();
  225. });
  226. m_open_action = GUI::CommonActions::make_open_action([this](auto&) {
  227. if (editor().document().is_modified()) {
  228. auto save_document_first_result = GUI::MessageBox::ask_about_unsaved_changes(window(), m_path, editor().document().undo_stack().last_unmodified_timestamp());
  229. if (save_document_first_result == GUI::Dialog::ExecResult::Yes)
  230. m_save_action->activate();
  231. if (save_document_first_result != GUI::Dialog::ExecResult::No && editor().document().is_modified())
  232. return;
  233. }
  234. auto response = FileSystemAccessClient::Client::the().open_file(window());
  235. if (response.is_error())
  236. return;
  237. if (auto result = read_file(response.value().filename(), response.value().stream()); result.is_error())
  238. GUI::MessageBox::show(window(), "Unable to open file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
  239. });
  240. m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
  241. auto extension = m_extension;
  242. if (extension.is_null() && m_editor->syntax_highlighter())
  243. extension = Syntax::common_language_extension(m_editor->syntax_highlighter()->language());
  244. auto response = FileSystemAccessClient::Client::the().save_file(window(), m_name, extension);
  245. if (response.is_error())
  246. return;
  247. auto file = response.release_value();
  248. if (auto result = m_editor->write_to_file(file.stream()); result.is_error()) {
  249. GUI::MessageBox::show(window(), "Unable to save file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
  250. return;
  251. }
  252. set_path(file.filename());
  253. GUI::Application::the()->set_most_recently_open_file(file.filename());
  254. dbgln("Wrote document to {}", file.filename());
  255. });
  256. m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
  257. if (m_path.is_empty()) {
  258. m_save_as_action->activate();
  259. return;
  260. }
  261. auto response = FileSystemAccessClient::Client::the().request_file(window(), m_path, Core::File::OpenMode::Truncate | Core::File::OpenMode::Write);
  262. if (response.is_error())
  263. return;
  264. if (auto result = m_editor->write_to_file(response.value().stream()); result.is_error()) {
  265. GUI::MessageBox::show(window(), "Unable to save file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
  266. }
  267. });
  268. auto file_manager_icon = Gfx::Bitmap::load_from_file("/res/icons/16x16/app-file-manager.png"sv).release_value_but_fixme_should_propagate_errors();
  269. m_open_folder_action = GUI::Action::create("Reveal in File Manager", { Mod_Ctrl | Mod_Shift, Key_O }, file_manager_icon, [&](auto&) {
  270. auto lexical_path = LexicalPath(m_path);
  271. Desktop::Launcher::open(URL::create_with_file_scheme(lexical_path.dirname(), lexical_path.basename()));
  272. });
  273. m_open_folder_action->set_enabled(!m_path.is_empty());
  274. m_open_folder_action->set_status_tip("Open the current file location in File Manager");
  275. m_toolbar->add_action(*m_new_action);
  276. m_toolbar->add_action(*m_open_action);
  277. m_toolbar->add_action(*m_save_action);
  278. m_toolbar->add_separator();
  279. m_toolbar->add_action(*m_open_folder_action);
  280. m_toolbar->add_separator();
  281. m_toolbar->add_action(m_editor->cut_action());
  282. m_toolbar->add_action(m_editor->copy_action());
  283. m_toolbar->add_action(m_editor->paste_action());
  284. m_toolbar->add_separator();
  285. m_toolbar->add_action(m_editor->undo_action());
  286. m_toolbar->add_action(m_editor->redo_action());
  287. }
  288. WebView::OutOfProcessWebView& MainWidget::ensure_web_view()
  289. {
  290. if (!m_page_view) {
  291. auto& web_view_container = *find_descendant_of_type_named<GUI::Widget>("web_view_container");
  292. m_page_view = web_view_container.add<WebView::OutOfProcessWebView>();
  293. m_page_view->on_link_hover = [this](auto& url) {
  294. if (url.is_valid())
  295. m_statusbar->set_text(url.to_deprecated_string());
  296. else
  297. update_statusbar();
  298. };
  299. m_page_view->on_link_click = [&](auto& url, auto&, unsigned) {
  300. if (!Desktop::Launcher::open(url)) {
  301. GUI::MessageBox::show(
  302. window(),
  303. DeprecatedString::formatted("The link to '{}' could not be opened.", url),
  304. "Failed to open link"sv,
  305. GUI::MessageBox::Type::Error);
  306. }
  307. };
  308. }
  309. return *m_page_view;
  310. }
  311. void MainWidget::initialize_menubar(GUI::Window& window)
  312. {
  313. auto& file_menu = window.add_menu("&File");
  314. file_menu.add_action(*m_new_action);
  315. file_menu.add_action(*m_open_action);
  316. file_menu.add_action(*m_save_action);
  317. file_menu.add_action(*m_save_as_action);
  318. file_menu.add_separator();
  319. file_menu.add_action(*m_open_folder_action);
  320. file_menu.add_separator();
  321. // FIXME: Propagate errors.
  322. (void)file_menu.add_recent_files_list([&](auto& action) {
  323. if (editor().document().is_modified()) {
  324. auto save_document_first_result = GUI::MessageBox::ask_about_unsaved_changes(&window, m_path, editor().document().undo_stack().last_unmodified_timestamp());
  325. if (save_document_first_result == GUI::Dialog::ExecResult::Yes)
  326. m_save_action->activate();
  327. if (save_document_first_result != GUI::Dialog::ExecResult::No && editor().document().is_modified())
  328. return;
  329. }
  330. auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(&window, action.text());
  331. if (response.is_error())
  332. return;
  333. if (auto result = read_file(response.value().filename(), response.value().stream()); result.is_error())
  334. GUI::MessageBox::show(&window, "Unable to open file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
  335. });
  336. file_menu.add_action(GUI::CommonActions::make_quit_action([this](auto&) {
  337. if (!request_close())
  338. return;
  339. GUI::Application::the()->quit();
  340. }));
  341. auto& edit_menu = window.add_menu("&Edit");
  342. edit_menu.add_action(m_editor->undo_action());
  343. edit_menu.add_action(m_editor->redo_action());
  344. edit_menu.add_separator();
  345. edit_menu.add_action(m_editor->cut_action());
  346. edit_menu.add_action(m_editor->copy_action());
  347. edit_menu.add_action(m_editor->paste_action());
  348. edit_menu.add_separator();
  349. edit_menu.add_action(m_editor->insert_emoji_action());
  350. edit_menu.add_action(*m_vim_emulation_setting_action);
  351. edit_menu.add_separator();
  352. edit_menu.add_action(*m_find_replace_action);
  353. edit_menu.add_action(*m_find_next_action);
  354. edit_menu.add_action(*m_find_previous_action);
  355. edit_menu.add_action(*m_replace_action);
  356. edit_menu.add_action(*m_replace_all_action);
  357. m_no_preview_action = GUI::Action::create_checkable(
  358. "&No Preview", [this](auto&) {
  359. set_preview_mode(PreviewMode::None);
  360. });
  361. m_markdown_preview_action = GUI::Action::create_checkable(
  362. "&Markdown Preview", [this](auto&) {
  363. set_preview_mode(PreviewMode::Markdown);
  364. },
  365. this);
  366. m_html_preview_action = GUI::Action::create_checkable(
  367. "&HTML Preview", [this](auto&) {
  368. set_preview_mode(PreviewMode::HTML);
  369. },
  370. this);
  371. m_preview_actions.add_action(*m_no_preview_action);
  372. m_preview_actions.add_action(*m_markdown_preview_action);
  373. m_preview_actions.add_action(*m_html_preview_action);
  374. m_preview_actions.set_exclusive(true);
  375. m_layout_toolbar_action = GUI::Action::create_checkable("&Toolbar", [&](auto& action) {
  376. action.is_checked() ? m_toolbar_container->set_visible(true) : m_toolbar_container->set_visible(false);
  377. Config::write_bool("TextEditor"sv, "Layout"sv, "ShowToolbar"sv, action.is_checked());
  378. });
  379. auto show_toolbar = Config::read_bool("TextEditor"sv, "Layout"sv, "ShowToolbar"sv, true);
  380. m_layout_toolbar_action->set_checked(show_toolbar);
  381. m_toolbar_container->set_visible(show_toolbar);
  382. m_layout_statusbar_action = GUI::Action::create_checkable("&Status Bar", [&](auto& action) {
  383. action.is_checked() ? m_statusbar->set_visible(true) : m_statusbar->set_visible(false);
  384. Config::write_bool("TextEditor"sv, "Layout"sv, "ShowStatusbar"sv, action.is_checked());
  385. update_statusbar();
  386. });
  387. auto show_statusbar = Config::read_bool("TextEditor"sv, "Layout"sv, "ShowStatusbar"sv, true);
  388. m_layout_statusbar_action->set_checked(show_statusbar);
  389. m_statusbar->set_visible(show_statusbar);
  390. m_layout_ruler_action = GUI::Action::create_checkable("&Ruler", [&](auto& action) {
  391. action.is_checked() ? m_editor->set_ruler_visible(true) : m_editor->set_ruler_visible(false);
  392. Config::write_bool("TextEditor"sv, "Layout"sv, "ShowRuler"sv, action.is_checked());
  393. });
  394. auto show_ruler = Config::read_bool("TextEditor"sv, "Layout"sv, "ShowRuler"sv, true);
  395. m_layout_ruler_action->set_checked(show_ruler);
  396. m_editor->set_ruler_visible(show_ruler);
  397. auto& view_menu = window.add_menu("&View");
  398. auto& layout_menu = view_menu.add_submenu("&Layout");
  399. layout_menu.add_action(*m_layout_toolbar_action);
  400. layout_menu.add_action(*m_layout_statusbar_action);
  401. layout_menu.add_action(*m_layout_ruler_action);
  402. view_menu.add_separator();
  403. view_menu.add_action(GUI::Action::create("Editor &Font...", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png"sv).release_value_but_fixme_should_propagate_errors(),
  404. [&](auto&) {
  405. auto picker = GUI::FontPicker::construct(&window, &m_editor->font(), false);
  406. if (picker->exec() == GUI::Dialog::ExecResult::OK) {
  407. dbgln("setting font {}", picker->font()->qualified_name());
  408. m_editor->set_font(picker->font());
  409. Config::write_string("TextEditor"sv, "Text"sv, "Font"sv, picker->font()->qualified_name());
  410. }
  411. }));
  412. view_menu.add_separator();
  413. m_wrapping_mode_actions.set_exclusive(true);
  414. auto& wrapping_mode_menu = view_menu.add_submenu("&Wrapping Mode");
  415. m_no_wrapping_action = GUI::Action::create_checkable("&No Wrapping", [&](auto&) {
  416. m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::NoWrap);
  417. Config::write_string("TextEditor"sv, "View"sv, "WrappingMode"sv, "None"sv);
  418. });
  419. m_wrap_anywhere_action = GUI::Action::create_checkable("Wrap &Anywhere", [&](auto&) {
  420. m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAnywhere);
  421. Config::write_string("TextEditor"sv, "View"sv, "WrappingMode"sv, "Anywhere"sv);
  422. });
  423. m_wrap_at_words_action = GUI::Action::create_checkable("Wrap at &Words", [&](auto&) {
  424. m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAtWords);
  425. Config::write_string("TextEditor"sv, "View"sv, "WrappingMode"sv, "Words"sv);
  426. });
  427. m_wrapping_mode_actions.add_action(*m_no_wrapping_action);
  428. m_wrapping_mode_actions.add_action(*m_wrap_anywhere_action);
  429. m_wrapping_mode_actions.add_action(*m_wrap_at_words_action);
  430. wrapping_mode_menu.add_action(*m_no_wrapping_action);
  431. wrapping_mode_menu.add_action(*m_wrap_anywhere_action);
  432. wrapping_mode_menu.add_action(*m_wrap_at_words_action);
  433. auto word_wrap = Config::read_string("TextEditor"sv, "View"sv, "WrappingMode"sv, "Words"sv);
  434. if (word_wrap == "None") {
  435. m_no_wrapping_action->set_checked(true);
  436. m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::NoWrap);
  437. } else if (word_wrap == "Anywhere") {
  438. m_wrap_anywhere_action->set_checked(true);
  439. m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAnywhere);
  440. } else {
  441. m_wrap_at_words_action->set_checked(true);
  442. m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAtWords);
  443. }
  444. m_soft_tab_width_actions.set_exclusive(true);
  445. auto& soft_tab_width_menu = view_menu.add_submenu("&Tab Width");
  446. m_soft_tab_1_width_action = GUI::Action::create_checkable("1", [&](auto&) {
  447. m_editor->set_soft_tab_width(1);
  448. });
  449. m_soft_tab_2_width_action = GUI::Action::create_checkable("2", [&](auto&) {
  450. m_editor->set_soft_tab_width(2);
  451. });
  452. m_soft_tab_4_width_action = GUI::Action::create_checkable("4", [&](auto&) {
  453. m_editor->set_soft_tab_width(4);
  454. });
  455. m_soft_tab_8_width_action = GUI::Action::create_checkable("8", [&](auto&) {
  456. m_editor->set_soft_tab_width(8);
  457. });
  458. m_soft_tab_16_width_action = GUI::Action::create_checkable("16", [&](auto&) {
  459. m_editor->set_soft_tab_width(16);
  460. });
  461. m_soft_tab_width_actions.add_action(*m_soft_tab_1_width_action);
  462. m_soft_tab_width_actions.add_action(*m_soft_tab_2_width_action);
  463. m_soft_tab_width_actions.add_action(*m_soft_tab_4_width_action);
  464. m_soft_tab_width_actions.add_action(*m_soft_tab_8_width_action);
  465. m_soft_tab_width_actions.add_action(*m_soft_tab_16_width_action);
  466. soft_tab_width_menu.add_action(*m_soft_tab_1_width_action);
  467. soft_tab_width_menu.add_action(*m_soft_tab_2_width_action);
  468. soft_tab_width_menu.add_action(*m_soft_tab_4_width_action);
  469. soft_tab_width_menu.add_action(*m_soft_tab_8_width_action);
  470. soft_tab_width_menu.add_action(*m_soft_tab_16_width_action);
  471. m_soft_tab_4_width_action->set_checked(true);
  472. view_menu.add_separator();
  473. m_visualize_trailing_whitespace_action = GUI::Action::create_checkable("T&railing Whitespace", [&](auto&) {
  474. m_editor->set_visualize_trailing_whitespace(m_visualize_trailing_whitespace_action->is_checked());
  475. });
  476. m_visualize_leading_whitespace_action = GUI::Action::create_checkable("L&eading Whitespace", [&](auto&) {
  477. m_editor->set_visualize_leading_whitespace(m_visualize_leading_whitespace_action->is_checked());
  478. });
  479. m_visualize_trailing_whitespace_action->set_checked(true);
  480. m_visualize_trailing_whitespace_action->set_status_tip("Visualize trailing whitespace");
  481. m_visualize_leading_whitespace_action->set_status_tip("Visualize leading whitespace");
  482. view_menu.add_action(*m_visualize_trailing_whitespace_action);
  483. view_menu.add_action(*m_visualize_leading_whitespace_action);
  484. m_cursor_line_highlighting_action = GUI::Action::create_checkable("L&ine Highlighting", [&](auto&) {
  485. m_editor->set_cursor_line_highlighting(m_cursor_line_highlighting_action->is_checked());
  486. });
  487. m_cursor_line_highlighting_action->set_checked(true);
  488. m_cursor_line_highlighting_action->set_status_tip("Highlight the current line");
  489. view_menu.add_action(*m_cursor_line_highlighting_action);
  490. m_relative_line_number_action = GUI::Action::create_checkable("R&elative Line Number", [&](auto& action) {
  491. m_editor->set_relative_line_number(action.is_checked());
  492. Config::write_bool("TextEditor"sv, "View"sv, "RelativeLineNumber"sv, action.is_checked());
  493. });
  494. auto show_relative_line_number = Config::read_bool("TextEditor"sv, "View"sv, "RelativeLineNumber"sv, false);
  495. m_relative_line_number_action->set_checked(show_relative_line_number);
  496. m_editor->set_relative_line_number(show_relative_line_number);
  497. m_relative_line_number_action->set_status_tip("Set relative line number");
  498. view_menu.add_action(*m_relative_line_number_action);
  499. view_menu.add_separator();
  500. view_menu.add_action(*m_no_preview_action);
  501. view_menu.add_action(*m_markdown_preview_action);
  502. view_menu.add_action(*m_html_preview_action);
  503. m_no_preview_action->set_checked(true);
  504. view_menu.add_separator();
  505. syntax_actions.set_exclusive(true);
  506. auto& syntax_menu = view_menu.add_submenu("&Syntax");
  507. m_plain_text_highlight = GUI::Action::create_checkable("&Plain Text", [&](auto&) {
  508. m_statusbar->set_text(1, "Plain Text");
  509. m_editor->set_syntax_highlighter({});
  510. m_editor->update();
  511. });
  512. m_plain_text_highlight->set_checked(true);
  513. m_statusbar->set_text(1, "Plain Text");
  514. syntax_actions.add_action(*m_plain_text_highlight);
  515. syntax_menu.add_action(*m_plain_text_highlight);
  516. m_cpp_highlight = GUI::Action::create_checkable("&C++", [&](auto&) {
  517. m_editor->set_syntax_highlighter(make<Cpp::SyntaxHighlighter>());
  518. m_editor->update();
  519. });
  520. syntax_actions.add_action(*m_cpp_highlight);
  521. syntax_menu.add_action(*m_cpp_highlight);
  522. m_cmake_highlight = GUI::Action::create_checkable("C&Make", [&](auto&) {
  523. m_editor->set_syntax_highlighter(make<CMake::SyntaxHighlighter>());
  524. m_editor->update();
  525. });
  526. syntax_actions.add_action(*m_cmake_highlight);
  527. syntax_menu.add_action(*m_cmake_highlight);
  528. m_cmakecache_highlight = GUI::Action::create_checkable("CM&akeCache", [&](auto&) {
  529. m_editor->set_syntax_highlighter(make<CMake::Cache::SyntaxHighlighter>());
  530. m_editor->update();
  531. });
  532. syntax_actions.add_action(*m_cmakecache_highlight);
  533. syntax_menu.add_action(*m_cmakecache_highlight);
  534. m_js_highlight = GUI::Action::create_checkable("&JavaScript", [&](auto&) {
  535. m_editor->set_syntax_highlighter(make<JS::SyntaxHighlighter>());
  536. m_editor->update();
  537. });
  538. syntax_actions.add_action(*m_js_highlight);
  539. syntax_menu.add_action(*m_js_highlight);
  540. m_css_highlight = GUI::Action::create_checkable("C&SS", [&](auto&) {
  541. m_editor->set_syntax_highlighter(make<Web::CSS::SyntaxHighlighter>());
  542. m_editor->update();
  543. });
  544. syntax_actions.add_action(*m_css_highlight);
  545. syntax_menu.add_action(*m_css_highlight);
  546. m_html_highlight = GUI::Action::create_checkable("&HTML File", [&](auto&) {
  547. m_editor->set_syntax_highlighter(make<Web::HTML::SyntaxHighlighter>());
  548. m_editor->update();
  549. });
  550. syntax_actions.add_action(*m_html_highlight);
  551. syntax_menu.add_action(*m_html_highlight);
  552. m_git_highlight = GUI::Action::create_checkable("Gi&t Commit", [&](auto&) {
  553. m_editor->set_syntax_highlighter(make<GUI::GitCommitSyntaxHighlighter>());
  554. m_editor->update();
  555. });
  556. syntax_actions.add_action(*m_git_highlight);
  557. syntax_menu.add_action(*m_git_highlight);
  558. m_gml_highlight = GUI::Action::create_checkable("&GML", [&](auto&) {
  559. m_editor->set_syntax_highlighter(make<GUI::GML::SyntaxHighlighter>());
  560. m_editor->update();
  561. });
  562. syntax_actions.add_action(*m_gml_highlight);
  563. syntax_menu.add_action(*m_gml_highlight);
  564. m_ini_highlight = GUI::Action::create_checkable("&INI File", [&](auto&) {
  565. m_editor->set_syntax_highlighter(make<GUI::IniSyntaxHighlighter>());
  566. m_editor->update();
  567. });
  568. syntax_actions.add_action(*m_ini_highlight);
  569. syntax_menu.add_action(*m_ini_highlight);
  570. m_shell_highlight = GUI::Action::create_checkable("Sh&ell File", [&](auto&) {
  571. m_editor->set_syntax_highlighter(make<Shell::SyntaxHighlighter>());
  572. m_editor->update();
  573. });
  574. syntax_actions.add_action(*m_shell_highlight);
  575. syntax_menu.add_action(*m_shell_highlight);
  576. m_sql_highlight = GUI::Action::create_checkable("S&QL File", [&](auto&) {
  577. m_editor->set_syntax_highlighter(make<SQL::AST::SyntaxHighlighter>());
  578. m_editor->update();
  579. });
  580. syntax_actions.add_action(*m_sql_highlight);
  581. syntax_menu.add_action(*m_sql_highlight);
  582. auto& help_menu = window.add_menu("&Help");
  583. help_menu.add_action(GUI::CommonActions::make_command_palette_action(&window));
  584. help_menu.add_action(GUI::CommonActions::make_help_action([](auto&) {
  585. Desktop::Launcher::open(URL::create_with_file_scheme("/usr/share/man/man1/TextEditor.md"), "/bin/Help");
  586. }));
  587. help_menu.add_action(GUI::CommonActions::make_about_action("Text Editor", GUI::Icon::default_icon("app-text-editor"sv), &window));
  588. auto& wrapping_statusbar_menu = m_line_column_statusbar_menu->add_submenu("&Wrapping Mode");
  589. wrapping_statusbar_menu.add_action(*m_no_wrapping_action);
  590. wrapping_statusbar_menu.add_action(*m_wrap_anywhere_action);
  591. wrapping_statusbar_menu.add_action(*m_wrap_at_words_action);
  592. auto& tab_width_statusbar_menu = m_line_column_statusbar_menu->add_submenu("&Tab Width");
  593. tab_width_statusbar_menu.add_action(*m_soft_tab_1_width_action);
  594. tab_width_statusbar_menu.add_action(*m_soft_tab_2_width_action);
  595. tab_width_statusbar_menu.add_action(*m_soft_tab_4_width_action);
  596. tab_width_statusbar_menu.add_action(*m_soft_tab_8_width_action);
  597. tab_width_statusbar_menu.add_action(*m_soft_tab_16_width_action);
  598. m_line_column_statusbar_menu->add_separator();
  599. m_line_column_statusbar_menu->add_action(*m_cursor_line_highlighting_action);
  600. m_syntax_statusbar_menu->add_action(*m_plain_text_highlight);
  601. m_syntax_statusbar_menu->add_action(*m_cpp_highlight);
  602. m_syntax_statusbar_menu->add_action(*m_cmake_highlight);
  603. m_syntax_statusbar_menu->add_action(*m_cmakecache_highlight);
  604. m_syntax_statusbar_menu->add_action(*m_css_highlight);
  605. m_syntax_statusbar_menu->add_action(*m_git_highlight);
  606. m_syntax_statusbar_menu->add_action(*m_gml_highlight);
  607. m_syntax_statusbar_menu->add_action(*m_html_highlight);
  608. m_syntax_statusbar_menu->add_action(*m_ini_highlight);
  609. m_syntax_statusbar_menu->add_action(*m_js_highlight);
  610. m_syntax_statusbar_menu->add_action(*m_shell_highlight);
  611. m_syntax_statusbar_menu->add_action(*m_sql_highlight);
  612. }
  613. void MainWidget::set_path(StringView path)
  614. {
  615. if (path.is_empty()) {
  616. m_path = {};
  617. m_name = {};
  618. m_extension = {};
  619. } else {
  620. auto lexical_path = LexicalPath(path);
  621. m_path = lexical_path.string();
  622. m_name = lexical_path.title();
  623. m_extension = lexical_path.extension();
  624. }
  625. if (m_extension == "c" || m_extension == "cc" || m_extension == "cxx" || m_extension == "cpp" || m_extension == "c++"
  626. || m_extension == "h" || m_extension == "hh" || m_extension == "hxx" || m_extension == "hpp" || m_extension == "h++") {
  627. m_cpp_highlight->activate();
  628. } else if (m_extension == "cmake" || (m_extension == "txt" && m_name == "CMakeLists")) {
  629. m_cmake_highlight->activate();
  630. } else if (m_extension == "txt" && m_name == "CMakeCache") {
  631. m_cmakecache_highlight->activate();
  632. } else if (m_extension == "js" || m_extension == "mjs" || m_extension == "json") {
  633. m_js_highlight->activate();
  634. } else if (m_name == "COMMIT_EDITMSG") {
  635. m_git_highlight->activate();
  636. } else if (m_extension == "gml") {
  637. m_gml_highlight->activate();
  638. } else if (m_extension == "ini" || m_extension == "af") {
  639. m_ini_highlight->activate();
  640. } else if (m_extension == "sh" || m_extension == "bash") {
  641. m_shell_highlight->activate();
  642. } else if (m_extension == "sql") {
  643. m_sql_highlight->activate();
  644. } else if (m_extension == "html" || m_extension == "htm") {
  645. m_html_highlight->activate();
  646. } else if (m_extension == "css") {
  647. m_css_highlight->activate();
  648. } else {
  649. m_plain_text_highlight->activate();
  650. }
  651. if (m_auto_detect_preview_mode) {
  652. if (m_extension == "md")
  653. set_preview_mode(PreviewMode::Markdown);
  654. else if (m_extension == "html" || m_extension == "htm")
  655. set_preview_mode(PreviewMode::HTML);
  656. else
  657. set_preview_mode(PreviewMode::None);
  658. }
  659. m_open_folder_action->set_enabled(!path.is_empty());
  660. update_title();
  661. }
  662. void MainWidget::update_title()
  663. {
  664. StringBuilder builder;
  665. if (m_path.is_empty())
  666. builder.append("Untitled"sv);
  667. else
  668. builder.append(m_path);
  669. builder.append("[*] - Text Editor"sv);
  670. window()->set_title(builder.to_deprecated_string());
  671. }
  672. ErrorOr<void> MainWidget::read_file(String const& filename, Core::File& file)
  673. {
  674. m_editor->set_text(TRY(file.read_until_eof()));
  675. set_path(filename);
  676. GUI::Application::the()->set_most_recently_open_file(filename);
  677. m_editor->set_focus(true);
  678. return {};
  679. }
  680. void MainWidget::open_nonexistent_file(DeprecatedString const& path)
  681. {
  682. m_editor->set_text({});
  683. set_path(path);
  684. m_editor->set_focus(true);
  685. }
  686. bool MainWidget::request_close()
  687. {
  688. if (!editor().document().is_modified())
  689. return true;
  690. auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), m_path, editor().document().undo_stack().last_unmodified_timestamp());
  691. if (result == GUI::MessageBox::ExecResult::Yes) {
  692. m_save_action->activate();
  693. if (editor().document().is_modified())
  694. return false;
  695. return true;
  696. }
  697. if (result == GUI::MessageBox::ExecResult::No)
  698. return true;
  699. return false;
  700. }
  701. void MainWidget::drag_enter_event(GUI::DragEvent& event)
  702. {
  703. auto const& mime_types = event.mime_types();
  704. if (mime_types.contains_slow("text/uri-list"))
  705. event.accept();
  706. }
  707. void MainWidget::drop_event(GUI::DropEvent& event)
  708. {
  709. event.accept();
  710. window()->move_to_front();
  711. if (event.mime_data().has_urls()) {
  712. auto urls = event.mime_data().urls();
  713. if (urls.is_empty())
  714. return;
  715. if (urls.size() > 1) {
  716. GUI::MessageBox::show(window(), "TextEditor can only open one file at a time!"sv, "One at a time please!"sv, GUI::MessageBox::Type::Error);
  717. return;
  718. }
  719. if (!request_close())
  720. return;
  721. auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().path());
  722. if (response.is_error())
  723. return;
  724. if (auto result = read_file(response.value().filename(), response.value().stream()); result.is_error())
  725. GUI::MessageBox::show(window(), "Unable to open file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
  726. }
  727. }
  728. void MainWidget::set_web_view_visible(bool visible)
  729. {
  730. if (!visible && !m_page_view)
  731. return;
  732. ensure_web_view();
  733. auto& web_view_container = *find_descendant_of_type_named<GUI::Widget>("web_view_container");
  734. web_view_container.set_visible(visible);
  735. }
  736. void MainWidget::set_preview_mode(PreviewMode mode)
  737. {
  738. if (m_preview_mode == mode)
  739. return;
  740. m_preview_mode = mode;
  741. if (m_preview_mode == PreviewMode::HTML) {
  742. m_html_preview_action->set_checked(true);
  743. set_web_view_visible(true);
  744. update_html_preview();
  745. } else if (m_preview_mode == PreviewMode::Markdown) {
  746. m_markdown_preview_action->set_checked(true);
  747. set_web_view_visible(true);
  748. update_markdown_preview();
  749. } else {
  750. m_no_preview_action->set_checked(true);
  751. set_web_view_visible(false);
  752. }
  753. }
  754. void MainWidget::update_preview()
  755. {
  756. switch (m_preview_mode) {
  757. case PreviewMode::Markdown:
  758. update_markdown_preview();
  759. break;
  760. case PreviewMode::HTML:
  761. update_html_preview();
  762. break;
  763. default:
  764. break;
  765. }
  766. }
  767. void MainWidget::update_markdown_preview()
  768. {
  769. auto document = Markdown::Document::parse(m_editor->text());
  770. if (document) {
  771. auto html = document->render_to_html();
  772. auto current_scroll_pos = m_page_view->visible_content_rect();
  773. m_page_view->load_html(html, URL::create_with_file_scheme(m_path));
  774. m_page_view->scroll_into_view(current_scroll_pos, true, true);
  775. }
  776. }
  777. void MainWidget::update_html_preview()
  778. {
  779. auto current_scroll_pos = m_page_view->visible_content_rect();
  780. m_page_view->load_html(m_editor->text(), URL::create_with_file_scheme(m_path));
  781. m_page_view->scroll_into_view(current_scroll_pos, true, true);
  782. }
  783. void MainWidget::update_statusbar()
  784. {
  785. if (!m_statusbar->is_visible())
  786. return;
  787. StringBuilder builder;
  788. if (m_editor->has_selection()) {
  789. DeprecatedString selected_text = m_editor->selected_text();
  790. auto word_count = m_editor->number_of_selected_words();
  791. builder.appendff("{} {} ({} {}) selected", selected_text.length(), selected_text.length() == 1 ? "character" : "characters", word_count, word_count != 1 ? "words" : "word");
  792. } else {
  793. DeprecatedString text = m_editor->text();
  794. auto word_count = m_editor->number_of_words();
  795. builder.appendff("{} {} ({} {})", text.length(), text.length() == 1 ? "character" : "characters", word_count, word_count != 1 ? "words" : "word");
  796. }
  797. m_statusbar->set_text(0, builder.to_deprecated_string());
  798. if (m_editor && m_editor->syntax_highlighter()) {
  799. auto language = m_editor->syntax_highlighter()->language();
  800. m_statusbar->set_text(1, Syntax::language_to_string(language));
  801. }
  802. m_statusbar->set_text(2, DeprecatedString::formatted("Ln {}, Col {}", m_editor->cursor().line() + 1, m_editor->cursor().column()));
  803. }
  804. void MainWidget::find_text(GUI::TextEditor::SearchDirection direction, ShowMessageIfNoResults show_message)
  805. {
  806. auto needle = m_find_textbox->text();
  807. if (needle.is_empty())
  808. return;
  809. if (m_use_regex)
  810. m_editor->document().update_regex_matches(needle);
  811. auto result = m_editor->find_text(needle, direction,
  812. m_should_wrap ? GUI::TextDocument::SearchShouldWrap::Yes : GUI::TextDocument::SearchShouldWrap::No,
  813. m_use_regex, m_match_case);
  814. if (!result.is_valid() && show_message == ShowMessageIfNoResults::Yes) {
  815. GUI::MessageBox::show(window(),
  816. DeprecatedString::formatted("Not found: \"{}\"", needle),
  817. "Not found"sv,
  818. GUI::MessageBox::Type::Information);
  819. }
  820. }
  821. }