HackStudioWidget.h 8.2 KB

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