TextEditorWidget.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. #include "TextEditorWidget.h"
  27. #include <AK/Optional.h>
  28. #include <AK/StringBuilder.h>
  29. #include <AK/URL.h>
  30. #include <LibCore/File.h>
  31. #include <LibCore/MimeData.h>
  32. #include <LibGUI/AboutDialog.h>
  33. #include <LibGUI/Action.h>
  34. #include <LibGUI/ActionGroup.h>
  35. #include <LibGUI/BoxLayout.h>
  36. #include <LibGUI/Button.h>
  37. #include <LibGUI/CppSyntaxHighlighter.h>
  38. #include <LibGUI/FilePicker.h>
  39. #include <LibGUI/FontDatabase.h>
  40. #include <LibGUI/JSSyntaxHighlighter.h>
  41. #include <LibGUI/Menu.h>
  42. #include <LibGUI/MenuBar.h>
  43. #include <LibGUI/MessageBox.h>
  44. #include <LibGUI/StatusBar.h>
  45. #include <LibGUI/TextBox.h>
  46. #include <LibGUI/TextEditor.h>
  47. #include <LibGUI/ToolBar.h>
  48. #include <LibGfx/Font.h>
  49. #include <string.h>
  50. TextEditorWidget::TextEditorWidget()
  51. {
  52. set_layout<GUI::VerticalBoxLayout>();
  53. layout()->set_spacing(0);
  54. auto& toolbar = add<GUI::ToolBar>();
  55. m_editor = add<GUI::TextEditor>();
  56. m_editor->set_ruler_visible(true);
  57. m_editor->set_automatic_indentation_enabled(true);
  58. m_editor->set_line_wrapping_enabled(true);
  59. m_editor->on_change = [this] {
  60. // Do not mark as diry on the first change (When document is first opened.)
  61. if (m_document_opening) {
  62. m_document_opening = false;
  63. return;
  64. }
  65. bool was_dirty = m_document_dirty;
  66. m_document_dirty = true;
  67. if (!was_dirty)
  68. update_title();
  69. };
  70. m_find_replace_widget = add<GUI::Widget>();
  71. m_find_replace_widget->set_fill_with_background_color(true);
  72. m_find_replace_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
  73. m_find_replace_widget->set_preferred_size(0, 48);
  74. m_find_replace_widget->set_layout<GUI::VerticalBoxLayout>();
  75. m_find_replace_widget->layout()->set_margins({ 2, 2, 2, 4 });
  76. m_find_replace_widget->set_visible(false);
  77. m_find_widget = m_find_replace_widget->add<GUI::Widget>();
  78. m_find_widget->set_fill_with_background_color(true);
  79. m_find_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
  80. m_find_widget->set_preferred_size(0, 22);
  81. m_find_widget->set_layout<GUI::HorizontalBoxLayout>();
  82. m_find_widget->set_visible(false);
  83. m_replace_widget = m_find_replace_widget->add<GUI::Widget>();
  84. m_replace_widget->set_fill_with_background_color(true);
  85. m_replace_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
  86. m_replace_widget->set_preferred_size(0, 22);
  87. m_replace_widget->set_layout<GUI::HorizontalBoxLayout>();
  88. m_replace_widget->set_visible(false);
  89. m_find_textbox = m_find_widget->add<GUI::TextBox>();
  90. m_replace_textbox = m_replace_widget->add<GUI::TextBox>();
  91. m_find_next_action = GUI::Action::create("Find next", { Mod_Ctrl, Key_G }, [&](auto&) {
  92. auto needle = m_find_textbox->text();
  93. if (needle.is_empty()) {
  94. dbg() << "find_next(\"\")";
  95. return;
  96. }
  97. auto found_range = m_editor->document().find_next(needle, m_editor->normalized_selection().end());
  98. dbg() << "find_next(\"" << needle << "\") returned " << found_range;
  99. if (found_range.is_valid()) {
  100. m_editor->set_selection(found_range);
  101. } else {
  102. GUI::MessageBox::show(
  103. String::format("Not found: \"%s\"", needle.characters()),
  104. "Not found",
  105. GUI::MessageBox::Type::Information,
  106. GUI::MessageBox::InputType::OK, window());
  107. }
  108. });
  109. m_find_previous_action = GUI::Action::create("Find previous", { Mod_Ctrl | Mod_Shift, Key_G }, [&](auto&) {
  110. auto needle = m_find_textbox->text();
  111. if (needle.is_empty()) {
  112. dbg() << "find_prev(\"\")";
  113. return;
  114. }
  115. auto selection_start = m_editor->normalized_selection().start();
  116. if (!selection_start.is_valid())
  117. selection_start = m_editor->normalized_selection().end();
  118. auto found_range = m_editor->document().find_previous(needle, selection_start);
  119. dbg() << "find_prev(\"" << needle << "\") returned " << found_range;
  120. if (found_range.is_valid()) {
  121. m_editor->set_selection(found_range);
  122. } else {
  123. GUI::MessageBox::show(
  124. String::format("Not found: \"%s\"", needle.characters()),
  125. "Not found",
  126. GUI::MessageBox::Type::Information,
  127. GUI::MessageBox::InputType::OK, window());
  128. }
  129. });
  130. m_replace_next_action = GUI::Action::create("Replace next", { Mod_Ctrl, Key_F1 }, [&](auto&) {
  131. auto needle = m_find_textbox->text();
  132. auto substitute = m_replace_textbox->text();
  133. if (needle.is_empty())
  134. return;
  135. auto selection_start = m_editor->normalized_selection().start();
  136. if (!selection_start.is_valid())
  137. selection_start = m_editor->normalized_selection().start();
  138. auto found_range = m_editor->document().find_next(needle, selection_start);
  139. if (found_range.is_valid()) {
  140. m_editor->set_selection(found_range);
  141. m_editor->insert_at_cursor_or_replace_selection(substitute);
  142. } else {
  143. GUI::MessageBox::show(
  144. String::format("Not found: \"%s\"", needle.characters()),
  145. "Not found",
  146. GUI::MessageBox::Type::Information,
  147. GUI::MessageBox::InputType::OK, window());
  148. }
  149. });
  150. m_replace_previous_action = GUI::Action::create("Replace previous", { Mod_Ctrl | Mod_Shift, Key_F1 }, [&](auto&) {
  151. auto needle = m_find_textbox->text();
  152. auto substitute = m_replace_textbox->text();
  153. if (needle.is_empty())
  154. return;
  155. auto selection_start = m_editor->normalized_selection().start();
  156. if (!selection_start.is_valid())
  157. selection_start = m_editor->normalized_selection().start();
  158. auto found_range = m_editor->document().find_previous(needle, selection_start);
  159. if (found_range.is_valid()) {
  160. m_editor->set_selection(found_range);
  161. m_editor->insert_at_cursor_or_replace_selection(substitute);
  162. } else {
  163. GUI::MessageBox::show(
  164. String::format("Not found: \"%s\"", needle.characters()),
  165. "Not found",
  166. GUI::MessageBox::Type::Information,
  167. GUI::MessageBox::InputType::OK, window());
  168. }
  169. });
  170. m_replace_all_action = GUI::Action::create("Replace all", { Mod_Ctrl, Key_F2 }, [&](auto&) {
  171. auto needle = m_find_textbox->text();
  172. auto substitute = m_replace_textbox->text();
  173. if (needle.is_empty())
  174. return;
  175. auto found_range = m_editor->document().find_next(needle);
  176. while (found_range.is_valid()) {
  177. m_editor->set_selection(found_range);
  178. m_editor->insert_at_cursor_or_replace_selection(substitute);
  179. found_range = m_editor->document().find_next(needle);
  180. }
  181. });
  182. m_find_previous_button = m_find_widget->add<GUI::Button>("Find previous");
  183. m_find_previous_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
  184. m_find_previous_button->set_preferred_size(150, 0);
  185. m_find_previous_button->set_action(*m_find_previous_action);
  186. m_find_next_button = m_find_widget->add<GUI::Button>("Find next");
  187. m_find_next_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
  188. m_find_next_button->set_preferred_size(150, 0);
  189. m_find_next_button->set_action(*m_find_next_action);
  190. m_find_textbox->on_return_pressed = [this] {
  191. m_find_next_button->click();
  192. };
  193. m_find_textbox->on_escape_pressed = [this] {
  194. m_find_replace_widget->set_visible(false);
  195. m_editor->set_focus(true);
  196. };
  197. m_replace_previous_button = m_replace_widget->add<GUI::Button>("Replace previous");
  198. m_replace_previous_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
  199. m_replace_previous_button->set_preferred_size(100, 0);
  200. m_replace_previous_button->set_action(*m_replace_previous_action);
  201. m_replace_next_button = m_replace_widget->add<GUI::Button>("Replace next");
  202. m_replace_next_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
  203. m_replace_next_button->set_preferred_size(100, 0);
  204. m_replace_next_button->set_action(*m_replace_next_action);
  205. m_replace_all_button = m_replace_widget->add<GUI::Button>("Replace all");
  206. m_replace_all_button->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
  207. m_replace_all_button->set_preferred_size(100, 0);
  208. m_replace_all_button->set_action(*m_replace_all_action);
  209. m_replace_textbox->on_return_pressed = [this] {
  210. m_replace_next_button->click();
  211. };
  212. m_replace_textbox->on_escape_pressed = [this] {
  213. m_find_replace_widget->set_visible(false);
  214. m_editor->set_focus(true);
  215. };
  216. m_find_replace_action = GUI::Action::create("Find/Replace...", { Mod_Ctrl, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [this](auto&) {
  217. m_find_replace_widget->set_visible(true);
  218. m_find_widget->set_visible(true);
  219. m_replace_widget->set_visible(true);
  220. m_find_textbox->set_focus(true);
  221. if (m_editor->has_selection()) {
  222. auto selected_text = m_editor->document().text_in_range(m_editor->normalized_selection());
  223. m_find_textbox->set_text(selected_text);
  224. }
  225. m_find_textbox->select_all();
  226. });
  227. m_editor->add_custom_context_menu_action(*m_find_replace_action);
  228. m_editor->add_custom_context_menu_action(*m_find_next_action);
  229. m_editor->add_custom_context_menu_action(*m_find_previous_action);
  230. m_statusbar = add<GUI::StatusBar>();
  231. m_editor->on_cursor_change = [this] {
  232. StringBuilder builder;
  233. builder.appendf("Line: %d, Column: %d", m_editor->cursor().line() + 1, m_editor->cursor().column());
  234. m_statusbar->set_text(builder.to_string());
  235. };
  236. m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) {
  237. if (m_document_dirty) {
  238. auto save_document_first_result = GUI::MessageBox::show("Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
  239. if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes)
  240. m_save_action->activate();
  241. if (save_document_first_result == GUI::Dialog::ExecResult::ExecCancel)
  242. return;
  243. }
  244. m_document_dirty = false;
  245. m_editor->set_text(StringView());
  246. set_path(FileSystemPath());
  247. update_title();
  248. });
  249. m_open_action = GUI::CommonActions::make_open_action([this](auto&) {
  250. Optional<String> open_path = GUI::FilePicker::get_open_filepath();
  251. if (!open_path.has_value())
  252. return;
  253. if (m_document_dirty) {
  254. auto save_document_first_result = GUI::MessageBox::show("Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel, window());
  255. if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes)
  256. m_save_action->activate();
  257. if (save_document_first_result == GUI::Dialog::ExecResult::ExecCancel)
  258. return;
  259. }
  260. open_sesame(open_path.value());
  261. });
  262. m_save_as_action = GUI::Action::create("Save as...", { Mod_Ctrl | Mod_Shift, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [this](const GUI::Action&) {
  263. Optional<String> save_path = GUI::FilePicker::get_save_filepath(m_name.is_null() ? "Untitled" : m_name, m_extension.is_null() ? "txt" : m_extension);
  264. if (!save_path.has_value())
  265. return;
  266. if (!m_editor->write_to_file(save_path.value())) {
  267. GUI::MessageBox::show("Unable to save file.\n", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
  268. return;
  269. }
  270. m_document_dirty = false;
  271. set_path(FileSystemPath(save_path.value()));
  272. dbg() << "Wrote document to " << save_path.value();
  273. });
  274. m_save_action = GUI::Action::create("Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](const GUI::Action&) {
  275. if (!m_path.is_empty()) {
  276. if (!m_editor->write_to_file(m_path)) {
  277. GUI::MessageBox::show("Unable to save file.\n", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
  278. } else {
  279. m_document_dirty = false;
  280. update_title();
  281. }
  282. return;
  283. }
  284. m_save_as_action->activate();
  285. });
  286. m_line_wrapping_setting_action = GUI::Action::create("Line wrapping", [&](GUI::Action& action) {
  287. action.set_checked(!action.is_checked());
  288. m_editor->set_line_wrapping_enabled(action.is_checked());
  289. });
  290. m_line_wrapping_setting_action->set_checkable(true);
  291. m_line_wrapping_setting_action->set_checked(m_editor->is_line_wrapping_enabled());
  292. auto menubar = make<GUI::MenuBar>();
  293. auto app_menu = GUI::Menu::construct("Text Editor");
  294. app_menu->add_action(*m_new_action);
  295. app_menu->add_action(*m_open_action);
  296. app_menu->add_action(*m_save_action);
  297. app_menu->add_action(*m_save_as_action);
  298. app_menu->add_separator();
  299. app_menu->add_action(GUI::CommonActions::make_quit_action([this](auto&) {
  300. if (!request_close())
  301. return;
  302. GUI::Application::the().quit(0);
  303. }));
  304. menubar->add_menu(move(app_menu));
  305. auto edit_menu = GUI::Menu::construct("Edit");
  306. edit_menu->add_action(m_editor->undo_action());
  307. edit_menu->add_action(m_editor->redo_action());
  308. edit_menu->add_separator();
  309. edit_menu->add_action(m_editor->cut_action());
  310. edit_menu->add_action(m_editor->copy_action());
  311. edit_menu->add_action(m_editor->paste_action());
  312. edit_menu->add_action(m_editor->delete_action());
  313. edit_menu->add_separator();
  314. edit_menu->add_action(*m_find_replace_action);
  315. edit_menu->add_action(*m_find_next_action);
  316. edit_menu->add_action(*m_find_previous_action);
  317. edit_menu->add_action(*m_replace_next_action);
  318. edit_menu->add_action(*m_replace_previous_action);
  319. edit_menu->add_action(*m_replace_all_action);
  320. menubar->add_menu(move(edit_menu));
  321. auto font_menu = GUI::Menu::construct("Font");
  322. GUI::FontDatabase::the().for_each_fixed_width_font([&](const StringView& font_name) {
  323. font_menu->add_action(GUI::Action::create(font_name, [this](const GUI::Action& action) {
  324. m_editor->set_font(GUI::FontDatabase::the().get_by_name(action.text()));
  325. m_editor->update();
  326. }));
  327. });
  328. syntax_actions = GUI::ActionGroup {};
  329. syntax_actions.set_exclusive(true);
  330. auto syntax_menu = GUI::Menu::construct("Syntax");
  331. m_plain_text_highlight = GUI::Action::create("Plain Text", [&](GUI::Action& action) {
  332. action.set_checked(true);
  333. m_editor->set_syntax_highlighter(nullptr);
  334. m_editor->update();
  335. });
  336. m_plain_text_highlight->set_checkable(true);
  337. m_plain_text_highlight->set_checked(true);
  338. syntax_actions.add_action(*m_plain_text_highlight);
  339. syntax_menu->add_action(*m_plain_text_highlight);
  340. m_cpp_highlight = GUI::Action::create("C++", [&](GUI::Action& action) {
  341. action.set_checked(true);
  342. m_editor->set_syntax_highlighter(make<GUI::CppSyntaxHighlighter>());
  343. m_editor->update();
  344. });
  345. m_cpp_highlight->set_checkable(true);
  346. syntax_actions.add_action(*m_cpp_highlight);
  347. syntax_menu->add_action(*m_cpp_highlight);
  348. m_js_highlight = GUI::Action::create("Javascript", [&](GUI::Action& action) {
  349. action.set_checked(true);
  350. m_editor->set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>());
  351. m_editor->update();
  352. });
  353. m_js_highlight->set_checkable(true);
  354. syntax_actions.add_action(*m_js_highlight);
  355. syntax_menu->add_action(*m_js_highlight);
  356. auto view_menu = GUI::Menu::construct("View");
  357. view_menu->add_action(*m_line_wrapping_setting_action);
  358. view_menu->add_separator();
  359. view_menu->add_submenu(move(font_menu));
  360. view_menu->add_submenu(move(syntax_menu));
  361. menubar->add_menu(move(view_menu));
  362. auto help_menu = GUI::Menu::construct("Help");
  363. help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) {
  364. GUI::AboutDialog::show("Text Editor", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-texteditor.png"), window());
  365. }));
  366. menubar->add_menu(move(help_menu));
  367. GUI::Application::the().set_menubar(move(menubar));
  368. toolbar.add_action(*m_new_action);
  369. toolbar.add_action(*m_open_action);
  370. toolbar.add_action(*m_save_action);
  371. toolbar.add_separator();
  372. toolbar.add_action(m_editor->cut_action());
  373. toolbar.add_action(m_editor->copy_action());
  374. toolbar.add_action(m_editor->paste_action());
  375. toolbar.add_action(m_editor->delete_action());
  376. toolbar.add_separator();
  377. toolbar.add_action(m_editor->undo_action());
  378. toolbar.add_action(m_editor->redo_action());
  379. }
  380. TextEditorWidget::~TextEditorWidget()
  381. {
  382. }
  383. void TextEditorWidget::set_path(const FileSystemPath& file)
  384. {
  385. m_path = file.string();
  386. m_name = file.title();
  387. m_extension = file.extension();
  388. if (m_extension == "cpp" || m_extension == "h")
  389. m_cpp_highlight->activate();
  390. else if (m_extension == "js")
  391. m_js_highlight->activate();
  392. else
  393. m_plain_text_highlight->activate();
  394. update_title();
  395. }
  396. void TextEditorWidget::update_title()
  397. {
  398. StringBuilder builder;
  399. builder.append("Text Editor: ");
  400. builder.append(m_path);
  401. if (m_document_dirty)
  402. builder.append(" (*)");
  403. window()->set_title(builder.to_string());
  404. }
  405. void TextEditorWidget::open_sesame(const String& path)
  406. {
  407. auto file = Core::File::construct(path);
  408. if (!file->open(Core::IODevice::ReadOnly)) {
  409. GUI::MessageBox::show(String::format("Opening \"%s\" failed: %s", path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
  410. return;
  411. }
  412. m_editor->set_text(file->read_all());
  413. m_document_dirty = false;
  414. m_document_opening = true;
  415. set_path(FileSystemPath(path));
  416. m_editor->set_focus(true);
  417. }
  418. bool TextEditorWidget::request_close()
  419. {
  420. if (!m_document_dirty)
  421. return true;
  422. auto result = GUI::MessageBox::show("The document has been modified. Would you like to save?", "Unsaved changes", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel, window());
  423. if (result == GUI::MessageBox::ExecYes) {
  424. m_save_action->activate();
  425. return true;
  426. }
  427. if (result == GUI::MessageBox::ExecNo)
  428. return true;
  429. return false;
  430. }
  431. void TextEditorWidget::drop_event(GUI::DropEvent& event)
  432. {
  433. event.accept();
  434. window()->move_to_front();
  435. if (event.mime_data().has_urls()) {
  436. auto urls = event.mime_data().urls();
  437. if (urls.is_empty())
  438. return;
  439. if (urls.size() > 1) {
  440. GUI::MessageBox::show("TextEditor can only open one file at a time!", "One at a time please!", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
  441. return;
  442. }
  443. open_sesame(urls.first().path());
  444. }
  445. }