HackStudioWidget.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020-2022, Itamar S. <itamar8910@gmail.com>
  4. * Copyright (c) 2020-2021, the SerenityOS developers.
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include "ClassViewWidget.h"
  10. #include "Debugger/DebugInfoWidget.h"
  11. #include "Debugger/DisassemblyWidget.h"
  12. #include "EditorWrapper.h"
  13. #include "FindInFilesWidget.h"
  14. #include "GMLPreviewWidget.h"
  15. #include "Git/DiffViewer.h"
  16. #include "Git/GitWidget.h"
  17. #include "Locator.h"
  18. #include "Project.h"
  19. #include "ProjectBuilder.h"
  20. #include "ProjectFile.h"
  21. #include "TerminalWrapper.h"
  22. #include "ToDoEntriesWidget.h"
  23. #include <LibCoredump/Inspector.h>
  24. #include <LibGUI/ActionGroup.h>
  25. #include <LibGUI/Scrollbar.h>
  26. #include <LibGUI/Splitter.h>
  27. #include <LibGUI/Widget.h>
  28. #include <LibGfx/Font/Font.h>
  29. #include <LibThreading/Thread.h>
  30. namespace HackStudio {
  31. class HackStudioWidget : public GUI::Widget {
  32. C_OBJECT(HackStudioWidget)
  33. public:
  34. virtual ~HackStudioWidget() override;
  35. bool open_file(String const& filename, size_t line = 0, size_t column = 0);
  36. void close_file_in_all_editors(String const& filename);
  37. void update_actions();
  38. Project& project();
  39. GUI::TextEditor& current_editor();
  40. GUI::TextEditor const& current_editor() const;
  41. EditorWrapper& current_editor_wrapper();
  42. EditorWrapper const& current_editor_wrapper() const;
  43. void set_current_editor_wrapper(RefPtr<EditorWrapper>);
  44. void set_current_editor_tab_widget(RefPtr<GUI::TabWidget>);
  45. GUI::TabWidget& current_editor_tab_widget();
  46. GUI::TabWidget const& current_editor_tab_widget() const;
  47. String const& active_file() const { return m_current_editor_wrapper->filename(); }
  48. void initialize_menubar(GUI::Window&);
  49. Locator& locator()
  50. {
  51. VERIFY(m_locator);
  52. return *m_locator;
  53. }
  54. enum class ContinueDecision {
  55. No,
  56. Yes
  57. };
  58. ContinueDecision warn_unsaved_changes(String const& prompt);
  59. enum class Mode {
  60. Code,
  61. Coredump
  62. };
  63. void open_coredump(String const& coredump_path);
  64. void for_each_open_file(Function<void(ProjectFile const&)>);
  65. bool semantic_syntax_highlighting_is_enabled() const;
  66. static Vector<String> read_recent_projects();
  67. private:
  68. static constexpr size_t recent_projects_history_size = 15;
  69. static String get_full_path_of_serenity_source(String const& file);
  70. String get_absolute_path(String const&) const;
  71. Vector<String> selected_file_paths() const;
  72. HackStudioWidget(String path_to_project);
  73. void open_project(String const& root_path);
  74. enum class EditMode {
  75. Text,
  76. Diff,
  77. };
  78. void set_edit_mode(EditMode);
  79. NonnullRefPtr<GUI::Menu> create_project_tree_view_context_menu();
  80. NonnullRefPtr<GUI::Action> create_new_file_action(String const& label, String const& icon, String const& extension);
  81. NonnullRefPtr<GUI::Action> create_new_directory_action();
  82. NonnullRefPtr<GUI::Action> create_open_selected_action();
  83. NonnullRefPtr<GUI::Action> create_delete_action();
  84. NonnullRefPtr<GUI::Action> create_new_project_action();
  85. NonnullRefPtr<GUI::Action> create_switch_to_next_editor_tab_widget_action();
  86. NonnullRefPtr<GUI::Action> create_switch_to_next_editor_action();
  87. NonnullRefPtr<GUI::Action> create_switch_to_previous_editor_action();
  88. NonnullRefPtr<GUI::Action> create_remove_current_editor_tab_widget_action();
  89. NonnullRefPtr<GUI::Action> create_remove_current_editor_action();
  90. NonnullRefPtr<GUI::Action> create_open_action();
  91. NonnullRefPtr<GUI::Action> create_save_action();
  92. NonnullRefPtr<GUI::Action> create_save_as_action();
  93. NonnullRefPtr<GUI::Action> create_show_in_file_manager_action();
  94. NonnullRefPtr<GUI::Action> create_add_editor_tab_widget_action();
  95. NonnullRefPtr<GUI::Action> create_add_editor_action();
  96. NonnullRefPtr<GUI::Action> create_add_terminal_action();
  97. NonnullRefPtr<GUI::Action> create_remove_current_terminal_action();
  98. NonnullRefPtr<GUI::Action> create_debug_action();
  99. NonnullRefPtr<GUI::Action> create_build_action();
  100. NonnullRefPtr<GUI::Action> create_run_action();
  101. NonnullRefPtr<GUI::Action> create_stop_action();
  102. NonnullRefPtr<GUI::Action> create_toggle_syntax_highlighting_mode_action();
  103. NonnullRefPtr<GUI::Action> create_open_project_configuration_action();
  104. void create_location_history_actions();
  105. void add_new_editor_tab_widget(GUI::Widget& parent);
  106. void add_new_editor(GUI::TabWidget& parent);
  107. RefPtr<EditorWrapper> get_editor_of_file(String const& filename);
  108. String get_project_executable_path() const;
  109. void on_action_tab_change();
  110. void reveal_action_tab(GUI::Widget&);
  111. void initialize_debugger();
  112. void update_statusbar();
  113. void handle_external_file_deletion(String const& filepath);
  114. void stop_debugger_if_running();
  115. void close_current_project();
  116. void create_open_files_view(GUI::Widget& parent);
  117. void create_toolbar(GUI::Widget& parent);
  118. void create_action_tab(GUI::Widget& parent);
  119. void create_file_menu(GUI::Window&);
  120. void update_recent_projects_submenu();
  121. void create_edit_menu(GUI::Window&);
  122. void create_build_menu(GUI::Window&);
  123. void create_view_menu(GUI::Window&);
  124. void create_help_menu(GUI::Window&);
  125. void create_project_tab(GUI::Widget& parent);
  126. void configure_project_tree_view();
  127. void run();
  128. void build();
  129. void hide_action_tabs();
  130. bool any_document_is_dirty() const;
  131. void update_gml_preview();
  132. void update_tree_view();
  133. void update_window_title();
  134. void update_current_editor_title();
  135. void on_cursor_change();
  136. void file_renamed(String const& old_name, String const& new_name);
  137. struct ProjectLocation {
  138. String filename;
  139. size_t line { 0 };
  140. size_t column { 0 };
  141. };
  142. ProjectLocation current_project_location() const;
  143. void update_history_actions();
  144. NonnullRefPtrVector<EditorWrapper> m_all_editor_wrappers;
  145. RefPtr<EditorWrapper> m_current_editor_wrapper;
  146. NonnullRefPtrVector<GUI::TabWidget> m_all_editor_tab_widgets;
  147. RefPtr<GUI::TabWidget> m_current_editor_tab_widget;
  148. HashMap<String, NonnullRefPtr<ProjectFile>> m_open_files;
  149. RefPtr<Core::FileWatcher> m_file_watcher;
  150. Vector<String> m_open_files_vector; // NOTE: This contains the keys from m_open_files and m_file_watchers
  151. OwnPtr<Project> m_project;
  152. Vector<ProjectLocation> m_locations_history;
  153. // This index is the boundary between the "Go Back" and "Go Forward" locations.
  154. // It always points at one past the current location in the list.
  155. size_t m_locations_history_end_index { 0 };
  156. bool m_locations_history_disabled { false };
  157. RefPtr<GUI::TreeView> m_project_tree_view;
  158. RefPtr<GUI::ListView> m_open_files_view;
  159. RefPtr<GUI::VerticalSplitter> m_right_hand_splitter;
  160. RefPtr<GUI::StackWidget> m_right_hand_stack;
  161. RefPtr<GUI::Splitter> m_editors_splitter;
  162. RefPtr<DiffViewer> m_diff_viewer;
  163. RefPtr<GitWidget> m_git_widget;
  164. RefPtr<GMLPreviewWidget> m_gml_preview_widget;
  165. RefPtr<ClassViewWidget> m_class_view;
  166. RefPtr<GUI::Menu> m_project_tree_view_context_menu;
  167. RefPtr<GUI::Statusbar> m_statusbar;
  168. RefPtr<GUI::TabWidget> m_action_tab_widget;
  169. RefPtr<GUI::TabWidget> m_project_tab;
  170. RefPtr<TerminalWrapper> m_terminal_wrapper;
  171. RefPtr<Locator> m_locator;
  172. RefPtr<FindInFilesWidget> m_find_in_files_widget;
  173. RefPtr<ToDoEntriesWidget> m_todo_entries_widget;
  174. RefPtr<DebugInfoWidget> m_debug_info_widget;
  175. RefPtr<DisassemblyWidget> m_disassembly_widget;
  176. RefPtr<Threading::Thread> m_debugger_thread;
  177. RefPtr<EditorWrapper> m_current_editor_in_execution;
  178. RefPtr<GUI::Menu> m_recent_projects_submenu { nullptr };
  179. NonnullRefPtrVector<GUI::Action> m_new_file_actions;
  180. RefPtr<GUI::Action> m_new_plain_file_action;
  181. RefPtr<GUI::Action> m_new_directory_action;
  182. RefPtr<GUI::Action> m_open_selected_action;
  183. RefPtr<GUI::Action> m_show_in_file_manager_action;
  184. RefPtr<GUI::Action> m_delete_action;
  185. RefPtr<GUI::Action> m_tree_view_rename_action;
  186. RefPtr<GUI::Action> m_new_project_action;
  187. RefPtr<GUI::Action> m_switch_to_next_editor_tab_widget;
  188. RefPtr<GUI::Action> m_switch_to_next_editor;
  189. RefPtr<GUI::Action> m_switch_to_previous_editor;
  190. RefPtr<GUI::Action> m_remove_current_editor_tab_widget_action;
  191. RefPtr<GUI::Action> m_remove_current_editor_action;
  192. RefPtr<GUI::Action> m_open_action;
  193. RefPtr<GUI::Action> m_save_action;
  194. RefPtr<GUI::Action> m_save_as_action;
  195. RefPtr<GUI::Action> m_add_editor_action;
  196. RefPtr<GUI::Action> m_add_editor_tab_widget_action;
  197. RefPtr<GUI::Action> m_add_terminal_action;
  198. RefPtr<GUI::Action> m_remove_current_terminal_action;
  199. RefPtr<GUI::Action> m_stop_action;
  200. RefPtr<GUI::Action> m_debug_action;
  201. RefPtr<GUI::Action> m_build_action;
  202. RefPtr<GUI::Action> m_run_action;
  203. RefPtr<GUI::Action> m_locations_history_back_action;
  204. RefPtr<GUI::Action> m_locations_history_forward_action;
  205. RefPtr<GUI::Action> m_toggle_semantic_highlighting_action;
  206. RefPtr<GUI::Action> m_open_project_configuration_action;
  207. RefPtr<Gfx::Font> read_editor_font_from_config();
  208. void change_editor_font(RefPtr<Gfx::Font>);
  209. RefPtr<Gfx::Font> m_editor_font;
  210. RefPtr<GUI::Action> m_editor_font_action;
  211. GUI::ActionGroup m_wrapping_mode_actions;
  212. RefPtr<GUI::Action> m_no_wrapping_action;
  213. RefPtr<GUI::Action> m_wrap_anywhere_action;
  214. RefPtr<GUI::Action> m_wrap_at_words_action;
  215. Mode m_mode { Mode::Code };
  216. OwnPtr<Coredump::Inspector> m_coredump_inspector;
  217. OwnPtr<ProjectBuilder> m_project_builder;
  218. };
  219. }