HackStudioWidget.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
  4. * Copyright (c) 2020, the SerenityOS developers
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice, this
  11. * list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "HackStudioWidget.h"
  29. #include "CursorTool.h"
  30. #include "Debugger/DebugInfoWidget.h"
  31. #include "Debugger/Debugger.h"
  32. #include "Debugger/DisassemblyWidget.h"
  33. #include "Dialogs/NewProjectDialog.h"
  34. #include "Editor.h"
  35. #include "EditorWrapper.h"
  36. #include "FindInFilesWidget.h"
  37. #include "FormEditorWidget.h"
  38. #include "FormWidget.h"
  39. #include "Git/DiffViewer.h"
  40. #include "Git/GitWidget.h"
  41. #include "HackStudio.h"
  42. #include "HackStudioWidget.h"
  43. #include "Locator.h"
  44. #include "Project.h"
  45. #include "TerminalWrapper.h"
  46. #include "WidgetTool.h"
  47. #include "WidgetTreeModel.h"
  48. #include <AK/LexicalPath.h>
  49. #include <AK/StringBuilder.h>
  50. #include <LibCore/ArgsParser.h>
  51. #include <LibCore/Event.h>
  52. #include <LibCore/EventLoop.h>
  53. #include <LibCore/File.h>
  54. #include <LibDebug/DebugSession.h>
  55. #include <LibGUI/Action.h>
  56. #include <LibGUI/ActionGroup.h>
  57. #include <LibGUI/Application.h>
  58. #include <LibGUI/BoxLayout.h>
  59. #include <LibGUI/Button.h>
  60. #include <LibGUI/Dialog.h>
  61. #include <LibGUI/EditingEngine.h>
  62. #include <LibGUI/FilePicker.h>
  63. #include <LibGUI/InputBox.h>
  64. #include <LibGUI/ItemListModel.h>
  65. #include <LibGUI/Label.h>
  66. #include <LibGUI/Menu.h>
  67. #include <LibGUI/MenuBar.h>
  68. #include <LibGUI/MessageBox.h>
  69. #include <LibGUI/RegularEditingEngine.h>
  70. #include <LibGUI/Splitter.h>
  71. #include <LibGUI/StackWidget.h>
  72. #include <LibGUI/TabWidget.h>
  73. #include <LibGUI/TableView.h>
  74. #include <LibGUI/TextBox.h>
  75. #include <LibGUI/TextEditor.h>
  76. #include <LibGUI/ToolBar.h>
  77. #include <LibGUI/ToolBarContainer.h>
  78. #include <LibGUI/TreeView.h>
  79. #include <LibGUI/VimEditingEngine.h>
  80. #include <LibGUI/Widget.h>
  81. #include <LibGUI/Window.h>
  82. #include <LibGfx/FontDatabase.h>
  83. #include <LibThread/Lock.h>
  84. #include <LibThread/Thread.h>
  85. #include <LibVT/TerminalWidget.h>
  86. #include <fcntl.h>
  87. #include <spawn.h>
  88. #include <stdio.h>
  89. #include <sys/types.h>
  90. #include <sys/wait.h>
  91. #include <unistd.h>
  92. namespace HackStudio {
  93. HackStudioWidget::HackStudioWidget(const String& path_to_project)
  94. {
  95. set_fill_with_background_color(true);
  96. set_layout<GUI::VerticalBoxLayout>();
  97. layout()->set_spacing(2);
  98. open_project(path_to_project);
  99. auto& toolbar_container = add<GUI::ToolBarContainer>();
  100. auto& outer_splitter = add<GUI::HorizontalSplitter>();
  101. auto& left_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>();
  102. left_hand_splitter.set_fixed_width(150);
  103. create_project_tree_view(left_hand_splitter);
  104. m_project_tree_view_context_menu = create_project_tree_view_context_menu();
  105. create_open_files_view(left_hand_splitter);
  106. m_right_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>();
  107. m_right_hand_stack = m_right_hand_splitter->add<GUI::StackWidget>();
  108. // Put a placeholder widget front & center since we don't have a file open yet.
  109. m_right_hand_stack->add<GUI::Widget>();
  110. create_form_editor(*m_right_hand_stack);
  111. m_diff_viewer = m_right_hand_stack->add<DiffViewer>();
  112. m_editors_splitter = m_right_hand_stack->add<GUI::VerticalSplitter>();
  113. m_editors_splitter->layout()->set_margins({ 0, 3, 0, 0 });
  114. add_new_editor(*m_editors_splitter);
  115. m_switch_to_next_editor = create_switch_to_next_editor_action();
  116. m_switch_to_previous_editor = create_switch_to_previous_editor_action();
  117. m_remove_current_editor_action = create_remove_current_editor_action();
  118. m_open_action = create_open_action();
  119. m_save_action = create_save_action();
  120. m_new_project_action = create_new_project_action();
  121. create_action_tab(*m_right_hand_splitter);
  122. m_add_editor_action = create_add_editor_action();
  123. m_add_terminal_action = create_add_terminal_action();
  124. m_remove_current_terminal_action = create_remove_current_terminal_action();
  125. m_locator = add<Locator>();
  126. m_terminal_wrapper->on_command_exit = [this] {
  127. m_stop_action->set_enabled(false);
  128. };
  129. m_build_action = create_build_action();
  130. m_run_action = create_run_action();
  131. m_stop_action = create_stop_action();
  132. m_debug_action = create_debug_action();
  133. initialize_debugger();
  134. create_toolbar(toolbar_container);
  135. }
  136. void HackStudioWidget::update_actions()
  137. {
  138. auto is_remove_terminal_enabled = [this]() {
  139. auto widget = m_action_tab_widget->active_widget();
  140. if (!widget)
  141. return false;
  142. if (StringView { "TerminalWrapper" } != widget->class_name())
  143. return false;
  144. if (!reinterpret_cast<TerminalWrapper*>(widget)->user_spawned())
  145. return false;
  146. return true;
  147. };
  148. m_remove_current_editor_action->set_enabled(m_all_editor_wrappers.size() > 1);
  149. m_remove_current_terminal_action->set_enabled(is_remove_terminal_enabled());
  150. }
  151. void HackStudioWidget::on_action_tab_change()
  152. {
  153. update_actions();
  154. auto git_widget = m_action_tab_widget->active_widget();
  155. if (!git_widget)
  156. return;
  157. if (StringView { "GitWidget" } != git_widget->class_name())
  158. return;
  159. reinterpret_cast<GitWidget*>(git_widget)->refresh();
  160. }
  161. void HackStudioWidget::open_project(const String& root_path)
  162. {
  163. if (chdir(root_path.characters()) < 0) {
  164. perror("chdir");
  165. exit(1);
  166. }
  167. m_project = Project::open_with_root_path(root_path);
  168. VERIFY(m_project);
  169. if (m_project_tree_view) {
  170. m_project_tree_view->set_model(m_project->model());
  171. m_project_tree_view->update();
  172. }
  173. if (Debugger::is_initialized()) {
  174. Debugger::the().reset_breakpoints();
  175. }
  176. }
  177. Vector<String> HackStudioWidget::selected_file_names() const
  178. {
  179. Vector<String> files;
  180. m_project_tree_view->selection().for_each_index([&](const GUI::ModelIndex& index) {
  181. files.append(index.data().as_string());
  182. });
  183. return files;
  184. }
  185. void HackStudioWidget::open_file(const String& full_filename)
  186. {
  187. String filename = full_filename;
  188. if (full_filename.starts_with(project().root_path())) {
  189. filename = LexicalPath::relative_path(full_filename, project().root_path());
  190. }
  191. dbgln("HackStudio is opening {}", filename);
  192. if (Core::File::is_directory(filename))
  193. return;
  194. if (!currently_open_file().is_empty()) {
  195. // Since the file is previously open, it should always be in m_open_files.
  196. VERIFY(m_open_files.find(currently_open_file()) != m_open_files.end());
  197. auto previous_open_project_file = m_open_files.get(currently_open_file()).value();
  198. // Update the scrollbar values of the previous_open_project_file and save them to m_open_files.
  199. previous_open_project_file->vertical_scroll_value(current_editor().vertical_scrollbar().value());
  200. previous_open_project_file->horizontal_scroll_value(current_editor().horizontal_scrollbar().value());
  201. m_open_files.set(currently_open_file(), previous_open_project_file);
  202. }
  203. RefPtr<ProjectFile> new_project_file = nullptr;
  204. if (auto it = m_open_files.find(filename); it != m_open_files.end()) {
  205. new_project_file = it->value;
  206. } else {
  207. new_project_file = m_project->get_file(filename);
  208. if (!new_project_file) {
  209. new_project_file = ProjectFile::construct_with_name(filename);
  210. }
  211. m_open_files.set(filename, *new_project_file);
  212. m_open_files_vector.append(filename);
  213. m_open_files_view->model()->update();
  214. }
  215. current_editor().set_document(const_cast<GUI::TextDocument&>(new_project_file->document()));
  216. current_editor().set_mode(GUI::TextEditor::Editable);
  217. current_editor().horizontal_scrollbar().set_value(new_project_file->horizontal_scroll_value());
  218. current_editor().vertical_scrollbar().set_value(new_project_file->vertical_scroll_value());
  219. current_editor().set_editing_engine(make<GUI::RegularEditingEngine>());
  220. if (filename.ends_with(".frm")) {
  221. set_edit_mode(EditMode::Form);
  222. } else {
  223. set_edit_mode(EditMode::Text);
  224. }
  225. m_currently_open_file = filename;
  226. String relative_file_path = m_currently_open_file;
  227. if (m_currently_open_file.starts_with(m_project->root_path()))
  228. relative_file_path = m_currently_open_file.substring(m_project->root_path().length() + 1);
  229. window()->set_title(String::formatted("{} - {} - Hack Studio", relative_file_path, m_project->name()));
  230. m_project_tree_view->update();
  231. current_editor_wrapper().filename_label().set_text(filename);
  232. current_editor().set_focus(true);
  233. }
  234. EditorWrapper& HackStudioWidget::current_editor_wrapper()
  235. {
  236. VERIFY(m_current_editor_wrapper);
  237. return *m_current_editor_wrapper;
  238. }
  239. GUI::TextEditor& HackStudioWidget::current_editor()
  240. {
  241. return current_editor_wrapper().editor();
  242. }
  243. void HackStudioWidget::set_edit_mode(EditMode mode)
  244. {
  245. if (mode == EditMode::Text) {
  246. m_right_hand_stack->set_active_widget(m_editors_splitter);
  247. } else if (mode == EditMode::Form) {
  248. m_right_hand_stack->set_active_widget(m_form_inner_container);
  249. } else if (mode == EditMode::Diff) {
  250. m_right_hand_stack->set_active_widget(m_diff_viewer);
  251. } else {
  252. VERIFY_NOT_REACHED();
  253. }
  254. m_right_hand_stack->active_widget()->update();
  255. }
  256. NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu()
  257. {
  258. m_open_selected_action = create_open_selected_action();
  259. m_new_file_action = create_new_file_action();
  260. m_new_directory_action = create_new_directory_action();
  261. m_delete_action = create_delete_action();
  262. auto project_tree_view_context_menu = GUI::Menu::construct("Project Files");
  263. project_tree_view_context_menu->add_action(*m_open_selected_action);
  264. // TODO: Rename, cut, copy, duplicate with new name, show containing folder ...
  265. project_tree_view_context_menu->add_separator();
  266. project_tree_view_context_menu->add_action(*m_new_file_action);
  267. project_tree_view_context_menu->add_action(*m_new_directory_action);
  268. project_tree_view_context_menu->add_action(*m_delete_action);
  269. return project_tree_view_context_menu;
  270. }
  271. NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_file_action()
  272. {
  273. return GUI::Action::create("New file...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) {
  274. String filename;
  275. if (GUI::InputBox::show(window(), filename, "Enter name of new file:", "Add new file to project") != GUI::InputBox::ExecOK)
  276. return;
  277. auto file = Core::File::construct(filename);
  278. if (!file->open((Core::IODevice::OpenMode)(Core::IODevice::WriteOnly | Core::IODevice::MustBeNew))) {
  279. GUI::MessageBox::show(window(), String::formatted("Failed to create '{}'", filename), "Error", GUI::MessageBox::Type::Error);
  280. return;
  281. }
  282. open_file(filename);
  283. });
  284. }
  285. NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_directory_action()
  286. {
  287. return GUI::Action::create("New directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const GUI::Action&) {
  288. String directory_name;
  289. if (GUI::InputBox::show(window(), directory_name, "Enter name of new directory:", "Add new folder to project") != GUI::InputBox::ExecOK)
  290. return;
  291. auto formatted_dir_name = LexicalPath::canonicalized_path(String::formatted("{}/{}", m_project->model().root_path(), directory_name));
  292. int rc = mkdir(formatted_dir_name.characters(), 0755);
  293. if (rc < 0) {
  294. GUI::MessageBox::show(window(), "Failed to create new directory", "Error", GUI::MessageBox::Type::Error);
  295. return;
  296. }
  297. });
  298. }
  299. NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_selected_action()
  300. {
  301. auto open_selected_action = GUI::Action::create("Open", [this](const GUI::Action&) {
  302. auto files = selected_file_names();
  303. for (auto& file : files)
  304. open_file(file);
  305. });
  306. open_selected_action->set_enabled(true);
  307. return open_selected_action;
  308. }
  309. NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
  310. {
  311. auto delete_action = GUI::CommonActions::make_delete_action([this](const GUI::Action&) {
  312. auto files = selected_file_names();
  313. if (files.is_empty())
  314. return;
  315. String message;
  316. if (files.size() == 1) {
  317. message = String::formatted("Really remove {} from disk?", LexicalPath(files[0]).basename());
  318. } else {
  319. message = String::formatted("Really remove {} files from disk?", files.size());
  320. }
  321. auto result = GUI::MessageBox::show(window(),
  322. message,
  323. "Confirm deletion",
  324. GUI::MessageBox::Type::Warning,
  325. GUI::MessageBox::InputType::OKCancel);
  326. if (result == GUI::MessageBox::ExecCancel)
  327. return;
  328. for (auto& file : files) {
  329. struct stat st;
  330. if (lstat(file.characters(), &st) < 0) {
  331. GUI::MessageBox::show(window(),
  332. String::formatted("lstat ({}) failed: {}", file, strerror(errno)),
  333. "Removal failed",
  334. GUI::MessageBox::Type::Error);
  335. break;
  336. }
  337. bool is_directory = S_ISDIR(st.st_mode);
  338. auto result = Core::File::remove(file, Core::File::RecursionMode::Allowed, false);
  339. if (result.is_error()) {
  340. auto& error = result.error();
  341. if (is_directory) {
  342. GUI::MessageBox::show(window(),
  343. String::formatted("Removing directory {} from the project failed: {}", error.file, error.error_code),
  344. "Removal failed",
  345. GUI::MessageBox::Type::Error);
  346. } else {
  347. GUI::MessageBox::show(window(),
  348. String::formatted("Removing file {} from the project failed: {}", error.file, error.error_code),
  349. "Removal failed",
  350. GUI::MessageBox::Type::Error);
  351. }
  352. break;
  353. }
  354. }
  355. });
  356. delete_action->set_enabled(false);
  357. return delete_action;
  358. }
  359. NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_project_action()
  360. {
  361. return GUI::Action::create("New project...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/hackstudio-project.png"), [this](const GUI::Action&) {
  362. auto dialog = NewProjectDialog::construct(window());
  363. dialog->set_icon(window()->icon());
  364. auto result = dialog->exec();
  365. if (result == GUI::Dialog::ExecResult::ExecOK && dialog->created_project_path().has_value())
  366. open_project(dialog->created_project_path().value());
  367. });
  368. }
  369. void HackStudioWidget::add_new_editor(GUI::Widget& parent)
  370. {
  371. auto wrapper = EditorWrapper::construct();
  372. if (m_action_tab_widget) {
  373. parent.insert_child_before(wrapper, *m_action_tab_widget);
  374. } else {
  375. parent.add_child(wrapper);
  376. }
  377. m_current_editor_wrapper = wrapper;
  378. m_all_editor_wrappers.append(wrapper);
  379. wrapper->editor().set_focus(true);
  380. }
  381. NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_next_editor_action()
  382. {
  383. return GUI::Action::create("Switch to next editor", { Mod_Ctrl, Key_E }, [this](auto&) {
  384. if (m_all_editor_wrappers.size() <= 1)
  385. return;
  386. Vector<EditorWrapper*> wrappers;
  387. m_editors_splitter->for_each_child_of_type<EditorWrapper>([this, &wrappers](auto& child) {
  388. wrappers.append(&child);
  389. return IterationDecision::Continue;
  390. });
  391. for (size_t i = 0; i < wrappers.size(); ++i) {
  392. if (m_current_editor_wrapper.ptr() == wrappers[i]) {
  393. if (i == wrappers.size() - 1)
  394. wrappers[0]->editor().set_focus(true);
  395. else
  396. wrappers[i + 1]->editor().set_focus(true);
  397. }
  398. }
  399. });
  400. }
  401. NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_previous_editor_action()
  402. {
  403. return GUI::Action::create("Switch to previous editor", { Mod_Ctrl | Mod_Shift, Key_E }, [this](auto&) {
  404. if (m_all_editor_wrappers.size() <= 1)
  405. return;
  406. Vector<EditorWrapper*> wrappers;
  407. m_editors_splitter->for_each_child_of_type<EditorWrapper>([this, &wrappers](auto& child) {
  408. wrappers.append(&child);
  409. return IterationDecision::Continue;
  410. });
  411. for (int i = wrappers.size() - 1; i >= 0; --i) {
  412. if (m_current_editor_wrapper.ptr() == wrappers[i]) {
  413. if (i == 0)
  414. wrappers.last()->editor().set_focus(true);
  415. else
  416. wrappers[i - 1]->editor().set_focus(true);
  417. }
  418. }
  419. });
  420. }
  421. NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_editor_action()
  422. {
  423. return GUI::Action::create("Remove current editor", { Mod_Alt | Mod_Shift, Key_E }, [this](auto&) {
  424. if (m_all_editor_wrappers.size() <= 1)
  425. return;
  426. auto wrapper = m_current_editor_wrapper;
  427. m_switch_to_next_editor->activate();
  428. m_editors_splitter->remove_child(*wrapper);
  429. m_all_editor_wrappers.remove_first_matching([&wrapper](auto& entry) { return entry == wrapper.ptr(); });
  430. update_actions();
  431. });
  432. }
  433. NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_action()
  434. {
  435. return GUI::Action::create("Open project...", { Mod_Ctrl | Mod_Shift, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), [this](auto&) {
  436. auto open_path = GUI::FilePicker::get_open_filepath(window(), "Open project");
  437. if (!open_path.has_value())
  438. return;
  439. open_project(open_path.value());
  440. update_actions();
  441. });
  442. }
  443. NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_action()
  444. {
  445. return GUI::Action::create("Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [this](auto&) {
  446. if (m_currently_open_file.is_empty())
  447. return;
  448. current_editor().write_to_file(m_currently_open_file);
  449. if (m_git_widget->initialized())
  450. m_git_widget->refresh();
  451. });
  452. }
  453. NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_terminal_action()
  454. {
  455. return GUI::Action::create("Remove current Terminal", { Mod_Alt | Mod_Shift, Key_T }, [this](auto&) {
  456. auto widget = m_action_tab_widget->active_widget();
  457. if (!widget)
  458. return;
  459. if (!is<TerminalWrapper>(widget))
  460. return;
  461. auto& terminal = *static_cast<TerminalWrapper*>(widget);
  462. if (!terminal.user_spawned())
  463. return;
  464. m_action_tab_widget->remove_tab(terminal);
  465. update_actions();
  466. });
  467. }
  468. NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_editor_action()
  469. {
  470. return GUI::Action::create("Add new editor", { Mod_Ctrl | Mod_Alt, Key_E },
  471. Gfx::Bitmap::load_from_file("/res/icons/16x16/app-text-editor.png"),
  472. [this](auto&) {
  473. add_new_editor(*m_editors_splitter);
  474. update_actions();
  475. });
  476. }
  477. NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_terminal_action()
  478. {
  479. return GUI::Action::create("Add new Terminal", { Mod_Ctrl | Mod_Alt, Key_T },
  480. Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"),
  481. [this](auto&) {
  482. auto& terminal_wrapper = m_action_tab_widget->add_tab<TerminalWrapper>("Terminal");
  483. reveal_action_tab(terminal_wrapper);
  484. update_actions();
  485. terminal_wrapper.terminal().set_focus(true);
  486. });
  487. }
  488. void HackStudioWidget::reveal_action_tab(GUI::Widget& widget)
  489. {
  490. if (m_action_tab_widget->min_height() < 200)
  491. m_action_tab_widget->set_fixed_height(200);
  492. m_action_tab_widget->set_active_widget(&widget);
  493. }
  494. NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action()
  495. {
  496. return GUI::Action::create("Debug", Gfx::Bitmap::load_from_file("/res/icons/16x16/debug-run.png"), [this](auto&) {
  497. if (!Core::File::exists(get_project_executable_path())) {
  498. GUI::MessageBox::show(window(), String::formatted("Could not find file: {}. (did you build the project?)", get_project_executable_path()), "Error", GUI::MessageBox::Type::Error);
  499. return;
  500. }
  501. if (Debugger::the().session()) {
  502. GUI::MessageBox::show(window(), "Debugger is already running", "Error", GUI::MessageBox::Type::Error);
  503. return;
  504. }
  505. Debugger::the().set_executable_path(get_project_executable_path());
  506. m_debugger_thread = LibThread::Thread::construct(Debugger::start_static);
  507. m_debugger_thread->start();
  508. });
  509. }
  510. void HackStudioWidget::initialize_debugger()
  511. {
  512. Debugger::initialize(
  513. m_project->root_path(),
  514. [this](const PtraceRegisters& regs) {
  515. VERIFY(Debugger::the().session());
  516. const auto& debug_session = *Debugger::the().session();
  517. auto source_position = debug_session.get_source_position(regs.eip);
  518. if (!source_position.has_value()) {
  519. dbgln("Could not find source position for address: {:p}", regs.eip);
  520. return Debugger::HasControlPassedToUser::No;
  521. }
  522. dbgln("Debugger stopped at source position: {}:{}", source_position.value().file_path, source_position.value().line_number);
  523. Core::EventLoop::main().post_event(
  524. *window(),
  525. make<Core::DeferredInvocationEvent>(
  526. [this, source_position, &regs](auto&) {
  527. m_current_editor_in_execution = get_editor_of_file(source_position.value().file_path);
  528. m_current_editor_in_execution->editor().set_execution_position(source_position.value().line_number - 1);
  529. m_debug_info_widget->update_state(*Debugger::the().session(), regs);
  530. m_debug_info_widget->set_debug_actions_enabled(true);
  531. m_disassembly_widget->update_state(*Debugger::the().session(), regs);
  532. HackStudioWidget::reveal_action_tab(*m_debug_info_widget);
  533. }));
  534. Core::EventLoop::wake();
  535. return Debugger::HasControlPassedToUser::Yes;
  536. },
  537. [this]() {
  538. Core::EventLoop::main().post_event(*window(), make<Core::DeferredInvocationEvent>([this](auto&) {
  539. m_debug_info_widget->set_debug_actions_enabled(false);
  540. if (m_current_editor_in_execution) {
  541. m_current_editor_in_execution->editor().clear_execution_position();
  542. }
  543. }));
  544. Core::EventLoop::wake();
  545. },
  546. [this]() {
  547. Core::EventLoop::main().post_event(*window(), make<Core::DeferredInvocationEvent>([this](auto&) {
  548. m_debug_info_widget->program_stopped();
  549. m_disassembly_widget->program_stopped();
  550. HackStudioWidget::hide_action_tabs();
  551. GUI::MessageBox::show(window(), "Program Exited", "Debugger", GUI::MessageBox::Type::Information);
  552. }));
  553. Core::EventLoop::wake();
  554. });
  555. }
  556. String HackStudioWidget::get_full_path_of_serenity_source(const String& file)
  557. {
  558. auto path_parts = LexicalPath(file).parts();
  559. VERIFY(path_parts[0] == "..");
  560. path_parts.remove(0);
  561. StringBuilder relative_path_builder;
  562. relative_path_builder.join("/", path_parts);
  563. constexpr char SERENITY_LIBS_PREFIX[] = "/usr/src/serenity";
  564. LexicalPath serenity_sources_base(SERENITY_LIBS_PREFIX);
  565. return String::formatted("{}/{}", serenity_sources_base, relative_path_builder.to_string());
  566. }
  567. NonnullRefPtr<EditorWrapper> HackStudioWidget::get_editor_of_file(const String& file_name)
  568. {
  569. String file_path = file_name;
  570. // TODO: We can probably do a more specific condition here, something like
  571. // "if (file.starts_with("../Libraries/") || file.starts_with("../AK/"))"
  572. if (file_name.starts_with("../")) {
  573. file_path = get_full_path_of_serenity_source(file_name);
  574. }
  575. open_file(file_path);
  576. return current_editor_wrapper();
  577. }
  578. String HackStudioWidget::get_project_executable_path() const
  579. {
  580. // FIXME: Dumb heuristic ahead!
  581. // e.g /my/project => /my/project/project
  582. // TODO: Perhaps a Makefile rule for getting the value of $(PROGRAM) would be better?
  583. return String::formatted("{}/{}", m_project->root_path(), LexicalPath(m_project->root_path()).basename());
  584. }
  585. void HackStudioWidget::build(TerminalWrapper& wrapper)
  586. {
  587. if (m_currently_open_file.ends_with(".js"))
  588. wrapper.run_command(String::formatted("js -A {}", m_currently_open_file));
  589. else
  590. wrapper.run_command("make");
  591. }
  592. void HackStudioWidget::run(TerminalWrapper& wrapper)
  593. {
  594. if (m_currently_open_file.ends_with(".js"))
  595. wrapper.run_command(String::formatted("js {}", m_currently_open_file));
  596. else
  597. wrapper.run_command("make run");
  598. }
  599. void HackStudioWidget::hide_action_tabs()
  600. {
  601. m_action_tab_widget->set_fixed_height(24);
  602. };
  603. Project& HackStudioWidget::project()
  604. {
  605. return *m_project;
  606. }
  607. void HackStudioWidget::set_current_editor_wrapper(RefPtr<EditorWrapper> editor_wrapper)
  608. {
  609. m_current_editor_wrapper = editor_wrapper;
  610. }
  611. void HackStudioWidget::create_project_tree_view(GUI::Widget& parent)
  612. {
  613. m_project_tree_view = parent.add<GUI::TreeView>();
  614. m_project_tree_view->set_model(m_project->model());
  615. m_project_tree_view->set_selection_mode(GUI::AbstractView::SelectionMode::MultiSelection);
  616. for (int column_index = 0; column_index < m_project->model().column_count(); ++column_index)
  617. m_project_tree_view->set_column_hidden(column_index, true);
  618. m_project_tree_view->set_column_hidden(GUI::FileSystemModel::Column::Name, false);
  619. m_project_tree_view->on_context_menu_request = [this](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
  620. if (index.is_valid()) {
  621. m_project_tree_view_context_menu->popup(event.screen_position(), m_open_selected_action);
  622. }
  623. };
  624. m_project_tree_view->on_selection_change = [this] {
  625. m_open_selected_action->set_enabled(!m_project_tree_view->selection().is_empty());
  626. m_delete_action->set_enabled(!m_project_tree_view->selection().is_empty());
  627. };
  628. m_project_tree_view->on_activation = [this](auto& index) {
  629. auto full_path_to_file = m_project->model().full_path(index);
  630. open_file(full_path_to_file);
  631. };
  632. }
  633. void HackStudioWidget::create_open_files_view(GUI::Widget& parent)
  634. {
  635. m_open_files_view = parent.add<GUI::ListView>();
  636. auto open_files_model = GUI::ItemListModel<String>::create(m_open_files_vector);
  637. m_open_files_view->set_model(open_files_model);
  638. m_open_files_view->on_activation = [this](auto& index) {
  639. open_file(index.data().to_string());
  640. };
  641. }
  642. void HackStudioWidget::create_form_editor(GUI::Widget& parent)
  643. {
  644. m_form_inner_container = parent.add<GUI::Widget>();
  645. m_form_inner_container->set_layout<GUI::HorizontalBoxLayout>();
  646. auto& form_widgets_toolbar = m_form_inner_container->add<GUI::ToolBar>(Orientation::Vertical, 26);
  647. form_widgets_toolbar.set_fixed_width(38);
  648. GUI::ActionGroup tool_actions;
  649. tool_actions.set_exclusive(true);
  650. auto cursor_tool_action = GUI::Action::create_checkable("Cursor", Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Cursor.png"), [this](auto&) {
  651. m_form_editor_widget->set_tool(make<CursorTool>(*m_form_editor_widget));
  652. });
  653. cursor_tool_action->set_checked(true);
  654. tool_actions.add_action(cursor_tool_action);
  655. form_widgets_toolbar.add_action(cursor_tool_action);
  656. GUI::WidgetClassRegistration::for_each([&, this](const GUI::WidgetClassRegistration& reg) {
  657. constexpr size_t gui_namespace_prefix_length = sizeof("GUI::") - 1;
  658. auto icon_path = String::formatted("/res/icons/hackstudio/G{}.png",
  659. reg.class_name().substring(gui_namespace_prefix_length, reg.class_name().length() - gui_namespace_prefix_length));
  660. if (!Core::File::exists(icon_path))
  661. return;
  662. auto action = GUI::Action::create_checkable(reg.class_name(), Gfx::Bitmap::load_from_file(icon_path), [&reg, this](auto&) {
  663. m_form_editor_widget->set_tool(make<WidgetTool>(*m_form_editor_widget, reg));
  664. auto widget = reg.construct();
  665. m_form_editor_widget->form_widget().add_child(widget);
  666. widget->set_relative_rect(30, 30, 30, 30);
  667. m_form_editor_widget->model().update();
  668. });
  669. action->set_checked(false);
  670. tool_actions.add_action(action);
  671. form_widgets_toolbar.add_action(move(action));
  672. });
  673. auto& form_editor_inner_splitter = m_form_inner_container->add<GUI::HorizontalSplitter>();
  674. m_form_editor_widget = form_editor_inner_splitter.add<FormEditorWidget>();
  675. auto& form_editing_pane_container = form_editor_inner_splitter.add<GUI::VerticalSplitter>();
  676. form_editing_pane_container.set_fixed_width(190);
  677. form_editing_pane_container.set_layout<GUI::VerticalBoxLayout>();
  678. auto add_properties_pane = [&](auto& text, auto& pane_widget) {
  679. auto& wrapper = form_editing_pane_container.add<GUI::Widget>();
  680. wrapper.set_layout<GUI::VerticalBoxLayout>();
  681. auto& label = wrapper.add<GUI::Label>(text);
  682. label.set_fill_with_background_color(true);
  683. label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  684. label.set_font(Gfx::FontDatabase::default_bold_font());
  685. label.set_fixed_height(16);
  686. wrapper.add_child(pane_widget);
  687. };
  688. m_form_widget_tree_view = GUI::TreeView::construct();
  689. m_form_widget_tree_view->set_model(m_form_editor_widget->model());
  690. m_form_widget_tree_view->on_selection_change = [this] {
  691. m_form_editor_widget->selection().disable_hooks();
  692. m_form_editor_widget->selection().clear();
  693. m_form_widget_tree_view->selection().for_each_index([this](auto& index) {
  694. // NOTE: Make sure we don't add the FormWidget itself to the selection,
  695. // since that would allow you to drag-move the FormWidget.
  696. if (index.internal_data() != &m_form_editor_widget->form_widget())
  697. m_form_editor_widget->selection().add(*(GUI::Widget*)index.internal_data());
  698. });
  699. m_form_editor_widget->update();
  700. m_form_editor_widget->selection().enable_hooks();
  701. };
  702. m_form_editor_widget->selection().on_add = [this](auto& widget) {
  703. m_form_widget_tree_view->selection().add(m_form_editor_widget->model().index_for_widget(widget));
  704. };
  705. m_form_editor_widget->selection().on_remove = [this](auto& widget) {
  706. m_form_widget_tree_view->selection().remove(m_form_editor_widget->model().index_for_widget(widget));
  707. };
  708. m_form_editor_widget->selection().on_clear = [this] {
  709. m_form_widget_tree_view->selection().clear();
  710. };
  711. add_properties_pane("Form widget tree:", *m_form_widget_tree_view);
  712. add_properties_pane("Widget properties:", *GUI::TableView::construct());
  713. }
  714. void HackStudioWidget::create_toolbar(GUI::Widget& parent)
  715. {
  716. auto& toolbar = parent.add<GUI::ToolBar>();
  717. toolbar.add_action(*m_new_file_action);
  718. toolbar.add_action(*m_new_directory_action);
  719. toolbar.add_action(*m_save_action);
  720. toolbar.add_action(*m_delete_action);
  721. toolbar.add_separator();
  722. toolbar.add_action(GUI::CommonActions::make_cut_action([this](auto&) { current_editor().cut_action().activate(); }));
  723. toolbar.add_action(GUI::CommonActions::make_copy_action([this](auto&) { current_editor().copy_action().activate(); }));
  724. toolbar.add_action(GUI::CommonActions::make_paste_action([this](auto&) { current_editor().paste_action().activate(); }));
  725. toolbar.add_separator();
  726. toolbar.add_action(GUI::CommonActions::make_undo_action([this](auto&) { current_editor().undo_action().activate(); }));
  727. toolbar.add_action(GUI::CommonActions::make_redo_action([this](auto&) { current_editor().redo_action().activate(); }));
  728. toolbar.add_separator();
  729. toolbar.add_action(*m_build_action);
  730. toolbar.add_separator();
  731. toolbar.add_action(*m_run_action);
  732. toolbar.add_action(*m_stop_action);
  733. toolbar.add_separator();
  734. toolbar.add_action(*m_debug_action);
  735. }
  736. NonnullRefPtr<GUI::Action> HackStudioWidget::create_build_action()
  737. {
  738. return GUI::Action::create("Build", { Mod_Ctrl, Key_B }, Gfx::Bitmap::load_from_file("/res/icons/16x16/build.png"), [this](auto&) {
  739. reveal_action_tab(*m_terminal_wrapper);
  740. build(*m_terminal_wrapper);
  741. m_stop_action->set_enabled(true);
  742. });
  743. }
  744. NonnullRefPtr<GUI::Action> HackStudioWidget::create_run_action()
  745. {
  746. return GUI::Action::create("Run", { Mod_Ctrl, Key_R }, Gfx::Bitmap::load_from_file("/res/icons/16x16/program-run.png"), [this](auto&) {
  747. reveal_action_tab(*m_terminal_wrapper);
  748. run(*m_terminal_wrapper);
  749. m_stop_action->set_enabled(true);
  750. });
  751. }
  752. void HackStudioWidget::create_action_tab(GUI::Widget& parent)
  753. {
  754. m_action_tab_widget = parent.add<GUI::TabWidget>();
  755. m_action_tab_widget->set_fixed_height(24);
  756. m_action_tab_widget->on_change = [this](auto&) {
  757. on_action_tab_change();
  758. static bool first_time = true;
  759. if (!first_time)
  760. m_action_tab_widget->set_fixed_height(200);
  761. first_time = false;
  762. };
  763. m_find_in_files_widget = m_action_tab_widget->add_tab<FindInFilesWidget>("Find in files");
  764. m_terminal_wrapper = m_action_tab_widget->add_tab<TerminalWrapper>("Build", false);
  765. m_debug_info_widget = m_action_tab_widget->add_tab<DebugInfoWidget>("Debug");
  766. m_disassembly_widget = m_action_tab_widget->add_tab<DisassemblyWidget>("Disassembly");
  767. m_git_widget = m_action_tab_widget->add_tab<GitWidget>("Git", LexicalPath(m_project->root_path()));
  768. m_git_widget->set_view_diff_callback([this](const auto& original_content, const auto& diff) {
  769. m_diff_viewer->set_content(original_content, diff);
  770. set_edit_mode(EditMode::Diff);
  771. });
  772. }
  773. void HackStudioWidget::create_app_menubar(GUI::MenuBar& menubar)
  774. {
  775. auto& app_menu = menubar.add_menu("Hack Studio");
  776. app_menu.add_action(*m_new_project_action);
  777. app_menu.add_action(*m_open_action);
  778. app_menu.add_action(*m_save_action);
  779. app_menu.add_separator();
  780. app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
  781. GUI::Application::the()->quit();
  782. }));
  783. }
  784. void HackStudioWidget::create_project_menubar(GUI::MenuBar& menubar)
  785. {
  786. auto& project_menu = menubar.add_menu("Project");
  787. project_menu.add_action(*m_new_file_action);
  788. project_menu.add_action(*m_new_directory_action);
  789. project_menu.add_separator();
  790. project_menu.add_action(*create_set_autocomplete_mode_action());
  791. }
  792. void HackStudioWidget::create_edit_menubar(GUI::MenuBar& menubar)
  793. {
  794. auto& edit_menu = menubar.add_menu("Edit");
  795. edit_menu.add_action(GUI::Action::create("Find in files...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [this](auto&) {
  796. reveal_action_tab(*m_find_in_files_widget);
  797. m_find_in_files_widget->focus_textbox_and_select_all();
  798. }));
  799. edit_menu.add_separator();
  800. auto vim_emulation_setting_action = GUI::Action::create_checkable("Vim emulation", { Mod_Ctrl | Mod_Shift | Mod_Alt, Key_V }, [this](auto& action) {
  801. if (action.is_checked())
  802. current_editor().set_editing_engine(make<GUI::VimEditingEngine>());
  803. else
  804. current_editor().set_editing_engine(make<GUI::RegularEditingEngine>());
  805. });
  806. vim_emulation_setting_action->set_checked(false);
  807. edit_menu.add_action(vim_emulation_setting_action);
  808. }
  809. void HackStudioWidget::create_build_menubar(GUI::MenuBar& menubar)
  810. {
  811. auto& build_menu = menubar.add_menu("Build");
  812. build_menu.add_action(*m_build_action);
  813. build_menu.add_separator();
  814. build_menu.add_action(*m_run_action);
  815. build_menu.add_action(*m_stop_action);
  816. build_menu.add_separator();
  817. build_menu.add_action(*m_debug_action);
  818. }
  819. void HackStudioWidget::create_view_menubar(GUI::MenuBar& menubar)
  820. {
  821. auto hide_action_tabs_action = GUI::Action::create("Hide action tabs", { Mod_Ctrl | Mod_Shift, Key_X }, [this](auto&) {
  822. hide_action_tabs();
  823. });
  824. auto open_locator_action = GUI::Action::create("Open locator", { Mod_Ctrl, Key_K }, [this](auto&) {
  825. m_locator->open();
  826. });
  827. auto& view_menu = menubar.add_menu("View");
  828. view_menu.add_action(hide_action_tabs_action);
  829. view_menu.add_action(open_locator_action);
  830. view_menu.add_separator();
  831. m_wrapping_mode_actions.set_exclusive(true);
  832. auto& wrapping_mode_menu = view_menu.add_submenu("Wrapping mode");
  833. m_no_wrapping_action = GUI::Action::create_checkable("No wrapping", [&](auto&) {
  834. for (auto& wrapper : m_all_editor_wrappers)
  835. wrapper.editor().set_wrapping_mode(GUI::TextEditor::WrappingMode::NoWrap);
  836. });
  837. m_wrap_anywhere_action = GUI::Action::create_checkable("Wrap anywhere", [&](auto&) {
  838. for (auto& wrapper : m_all_editor_wrappers)
  839. wrapper.editor().set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAnywhere);
  840. });
  841. m_wrap_at_words_action = GUI::Action::create_checkable("Wrap at words", [&](auto&) {
  842. for (auto& wrapper : m_all_editor_wrappers)
  843. wrapper.editor().set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAtWords);
  844. });
  845. m_wrapping_mode_actions.add_action(*m_no_wrapping_action);
  846. m_wrapping_mode_actions.add_action(*m_wrap_anywhere_action);
  847. m_wrapping_mode_actions.add_action(*m_wrap_at_words_action);
  848. wrapping_mode_menu.add_action(*m_no_wrapping_action);
  849. wrapping_mode_menu.add_action(*m_wrap_anywhere_action);
  850. wrapping_mode_menu.add_action(*m_wrap_at_words_action);
  851. m_no_wrapping_action->set_checked(true);
  852. view_menu.add_separator();
  853. view_menu.add_action(*m_add_editor_action);
  854. view_menu.add_action(*m_remove_current_editor_action);
  855. view_menu.add_action(*m_add_terminal_action);
  856. view_menu.add_action(*m_remove_current_terminal_action);
  857. }
  858. void HackStudioWidget::create_help_menubar(GUI::MenuBar& menubar)
  859. {
  860. auto& help_menu = menubar.add_menu("Help");
  861. help_menu.add_action(GUI::CommonActions::make_about_action("Hack Studio", GUI::Icon::default_icon("app-hack-studio"), window()));
  862. }
  863. NonnullRefPtr<GUI::Action> HackStudioWidget::create_stop_action()
  864. {
  865. auto action = GUI::Action::create("Stop", Gfx::Bitmap::load_from_file("/res/icons/16x16/program-stop.png"), [this](auto&) {
  866. m_terminal_wrapper->kill_running_command();
  867. });
  868. action->set_enabled(false);
  869. return action;
  870. }
  871. NonnullRefPtr<GUI::Action> HackStudioWidget::create_set_autocomplete_mode_action()
  872. {
  873. auto action = GUI::Action::create_checkable("AutoComplete C++ with Parser", [this](auto& action) {
  874. get_language_client<LanguageClients::Cpp::ServerConnection>(project().root_path())->set_autocomplete_mode(action.is_checked() ? "Parser" : "Lexer");
  875. });
  876. action->set_checked(true);
  877. return action;
  878. }
  879. void HackStudioWidget::initialize_menubar(GUI::MenuBar& menubar)
  880. {
  881. create_app_menubar(menubar);
  882. create_project_menubar(menubar);
  883. create_edit_menubar(menubar);
  884. create_build_menubar(menubar);
  885. create_view_menubar(menubar);
  886. create_help_menubar(menubar);
  887. }
  888. HackStudioWidget::~HackStudioWidget()
  889. {
  890. if (!m_debugger_thread.is_null()) {
  891. Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::Exit);
  892. dbgln("Waiting for debugger thread to terminate");
  893. auto rc = m_debugger_thread->join();
  894. if (rc.is_error()) {
  895. warnln("pthread_join: {}", strerror(rc.error().value()));
  896. dbgln("error joining debugger thread");
  897. }
  898. }
  899. }
  900. }