HackStudioWidget.h 11 KB

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