HackStudioWidget.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2020, 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.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. const String& active_file() const { return m_current_editor_wrapper->filename(); }
  45. void initialize_menubar(GUI::Window&);
  46. Locator& locator()
  47. {
  48. VERIFY(m_locator);
  49. return *m_locator;
  50. }
  51. enum class ContinueDecision {
  52. No,
  53. Yes
  54. };
  55. ContinueDecision warn_unsaved_changes(const String& prompt);
  56. enum class Mode {
  57. Code,
  58. Coredump
  59. };
  60. void open_coredump(String const& coredump_path);
  61. void for_each_open_file(Function<void(ProjectFile const&)>);
  62. bool semantic_syntax_highlighting_is_enabled() const;
  63. static Vector<String> read_recent_projects();
  64. private:
  65. static constexpr size_t recent_projects_history_size = 15;
  66. static String get_full_path_of_serenity_source(const String& file);
  67. String get_absolute_path(String const&) const;
  68. Vector<String> selected_file_paths() const;
  69. HackStudioWidget(String path_to_project);
  70. void open_project(const String& root_path);
  71. enum class EditMode {
  72. Text,
  73. Diff,
  74. };
  75. void set_edit_mode(EditMode);
  76. NonnullRefPtr<GUI::Menu> create_project_tree_view_context_menu();
  77. NonnullRefPtr<GUI::Action> create_new_file_action(String const& label, String const& icon, String const& extension);
  78. NonnullRefPtr<GUI::Action> create_new_directory_action();
  79. NonnullRefPtr<GUI::Action> create_open_selected_action();
  80. NonnullRefPtr<GUI::Action> create_delete_action();
  81. NonnullRefPtr<GUI::Action> create_new_project_action();
  82. NonnullRefPtr<GUI::Action> create_switch_to_next_editor_action();
  83. NonnullRefPtr<GUI::Action> create_switch_to_previous_editor_action();
  84. NonnullRefPtr<GUI::Action> create_remove_current_editor_action();
  85. NonnullRefPtr<GUI::Action> create_open_action();
  86. NonnullRefPtr<GUI::Action> create_save_action();
  87. NonnullRefPtr<GUI::Action> create_save_as_action();
  88. NonnullRefPtr<GUI::Action> create_show_in_file_manager_action();
  89. NonnullRefPtr<GUI::Action> create_add_editor_action();
  90. NonnullRefPtr<GUI::Action> create_add_terminal_action();
  91. NonnullRefPtr<GUI::Action> create_remove_current_terminal_action();
  92. NonnullRefPtr<GUI::Action> create_debug_action();
  93. NonnullRefPtr<GUI::Action> create_build_action();
  94. NonnullRefPtr<GUI::Action> create_run_action();
  95. NonnullRefPtr<GUI::Action> create_stop_action();
  96. NonnullRefPtr<GUI::Action> create_toggle_syntax_highlighting_mode_action();
  97. void create_location_history_actions();
  98. void add_new_editor(GUI::Widget& parent);
  99. RefPtr<EditorWrapper> get_editor_of_file(const String& filename);
  100. String get_project_executable_path() const;
  101. void on_action_tab_change();
  102. void reveal_action_tab(GUI::Widget&);
  103. void initialize_debugger();
  104. void update_statusbar();
  105. void handle_external_file_deletion(const String& filepath);
  106. void stop_debugger_if_running();
  107. void close_current_project();
  108. void create_open_files_view(GUI::Widget& parent);
  109. void create_toolbar(GUI::Widget& parent);
  110. void create_action_tab(GUI::Widget& parent);
  111. void create_file_menu(GUI::Window&);
  112. void update_recent_projects_submenu();
  113. void create_edit_menu(GUI::Window&);
  114. void create_build_menu(GUI::Window&);
  115. void create_view_menu(GUI::Window&);
  116. void create_help_menu(GUI::Window&);
  117. void create_project_tab(GUI::Widget& parent);
  118. void configure_project_tree_view();
  119. void run();
  120. void build();
  121. void hide_action_tabs();
  122. bool any_document_is_dirty() const;
  123. void update_gml_preview();
  124. void update_tree_view();
  125. void update_window_title();
  126. void on_cursor_change();
  127. void file_renamed(String const& old_name, String const& new_name);
  128. struct ProjectLocation {
  129. String filename;
  130. size_t line { 0 };
  131. size_t column { 0 };
  132. };
  133. ProjectLocation current_project_location() const;
  134. void update_history_actions();
  135. NonnullRefPtrVector<EditorWrapper> m_all_editor_wrappers;
  136. RefPtr<EditorWrapper> m_current_editor_wrapper;
  137. HashMap<String, NonnullRefPtr<ProjectFile>> m_open_files;
  138. RefPtr<Core::FileWatcher> m_file_watcher;
  139. Vector<String> m_open_files_vector; // NOTE: This contains the keys from m_open_files and m_file_watchers
  140. OwnPtr<Project> m_project;
  141. Vector<ProjectLocation> m_locations_history;
  142. // This index is the boundary between the "Go Back" and "Go Forward" locations.
  143. // It always points at one past the current location in the list.
  144. size_t m_locations_history_end_index { 0 };
  145. bool m_locations_history_disabled { false };
  146. RefPtr<GUI::TreeView> m_project_tree_view;
  147. RefPtr<GUI::ListView> m_open_files_view;
  148. RefPtr<GUI::VerticalSplitter> m_right_hand_splitter;
  149. RefPtr<GUI::StackWidget> m_right_hand_stack;
  150. RefPtr<GUI::Splitter> m_editors_splitter;
  151. RefPtr<DiffViewer> m_diff_viewer;
  152. RefPtr<GitWidget> m_git_widget;
  153. RefPtr<GMLPreviewWidget> m_gml_preview_widget;
  154. RefPtr<ClassViewWidget> m_class_view;
  155. RefPtr<GUI::Menu> m_project_tree_view_context_menu;
  156. RefPtr<GUI::Statusbar> m_statusbar;
  157. RefPtr<GUI::TabWidget> m_action_tab_widget;
  158. RefPtr<GUI::TabWidget> m_project_tab;
  159. RefPtr<TerminalWrapper> m_terminal_wrapper;
  160. RefPtr<Locator> m_locator;
  161. RefPtr<FindInFilesWidget> m_find_in_files_widget;
  162. RefPtr<ToDoEntriesWidget> m_todo_entries_widget;
  163. RefPtr<DebugInfoWidget> m_debug_info_widget;
  164. RefPtr<DisassemblyWidget> m_disassembly_widget;
  165. RefPtr<Threading::Thread> m_debugger_thread;
  166. RefPtr<EditorWrapper> m_current_editor_in_execution;
  167. RefPtr<GUI::Menu> m_recent_projects_submenu { nullptr };
  168. NonnullRefPtrVector<GUI::Action> m_new_file_actions;
  169. RefPtr<GUI::Action> m_new_plain_file_action;
  170. RefPtr<GUI::Action> m_new_directory_action;
  171. RefPtr<GUI::Action> m_open_selected_action;
  172. RefPtr<GUI::Action> m_show_in_file_manager_action;
  173. RefPtr<GUI::Action> m_delete_action;
  174. RefPtr<GUI::Action> m_tree_view_rename_action;
  175. RefPtr<GUI::Action> m_new_project_action;
  176. RefPtr<GUI::Action> m_switch_to_next_editor;
  177. RefPtr<GUI::Action> m_switch_to_previous_editor;
  178. RefPtr<GUI::Action> m_remove_current_editor_action;
  179. RefPtr<GUI::Action> m_open_action;
  180. RefPtr<GUI::Action> m_save_action;
  181. RefPtr<GUI::Action> m_save_as_action;
  182. RefPtr<GUI::Action> m_add_editor_action;
  183. RefPtr<GUI::Action> m_add_terminal_action;
  184. RefPtr<GUI::Action> m_remove_current_terminal_action;
  185. RefPtr<GUI::Action> m_stop_action;
  186. RefPtr<GUI::Action> m_debug_action;
  187. RefPtr<GUI::Action> m_build_action;
  188. RefPtr<GUI::Action> m_run_action;
  189. RefPtr<GUI::Action> m_locations_history_back_action;
  190. RefPtr<GUI::Action> m_locations_history_forward_action;
  191. RefPtr<GUI::Action> m_toggle_semantic_highlighting_action;
  192. RefPtr<Gfx::Font> read_editor_font_from_config();
  193. void change_editor_font(RefPtr<Gfx::Font>);
  194. RefPtr<Gfx::Font> m_editor_font;
  195. RefPtr<GUI::Action> m_editor_font_action;
  196. GUI::ActionGroup m_wrapping_mode_actions;
  197. RefPtr<GUI::Action> m_no_wrapping_action;
  198. RefPtr<GUI::Action> m_wrap_anywhere_action;
  199. RefPtr<GUI::Action> m_wrap_at_words_action;
  200. Mode m_mode { Mode::Code };
  201. OwnPtr<Coredump::Inspector> m_coredump_inspector;
  202. OwnPtr<ProjectBuilder> m_project_builder;
  203. };
  204. }