2020-09-19 17:25:05 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
2021-05-09 17:09:30 +00:00
|
|
|
* Copyright (c) 2020-2021, the SerenityOS developers.
|
2020-09-19 17:25:05 +03:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-19 17:25:05 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-04-10 17:38:11 +03:00
|
|
|
#include "ClassViewWidget.h"
|
2020-09-19 17:25:05 +03:00
|
|
|
#include "Debugger/DebugInfoWidget.h"
|
|
|
|
#include "Debugger/DisassemblyWidget.h"
|
|
|
|
#include "EditorWrapper.h"
|
|
|
|
#include "FindInFilesWidget.h"
|
2021-07-28 20:58:16 +01:00
|
|
|
#include "GMLPreviewWidget.h"
|
2020-09-19 17:25:05 +03:00
|
|
|
#include "Git/DiffViewer.h"
|
|
|
|
#include "Git/GitWidget.h"
|
|
|
|
#include "Locator.h"
|
|
|
|
#include "Project.h"
|
2022-01-07 17:23:50 +02:00
|
|
|
#include "ProjectBuilder.h"
|
2020-12-10 18:59:03 +01:00
|
|
|
#include "ProjectFile.h"
|
2020-09-19 17:25:05 +03:00
|
|
|
#include "TerminalWrapper.h"
|
2021-05-22 14:14:49 +02:00
|
|
|
#include "ToDoEntriesWidget.h"
|
2021-11-19 16:13:07 +02:00
|
|
|
#include <LibCoredump/Inspector.h>
|
2021-01-09 22:47:48 +10:00
|
|
|
#include <LibGUI/ActionGroup.h>
|
2021-04-13 16:18:20 +02:00
|
|
|
#include <LibGUI/Scrollbar.h>
|
2020-09-19 17:25:05 +03:00
|
|
|
#include <LibGUI/Splitter.h>
|
|
|
|
#include <LibGUI/Widget.h>
|
2021-10-06 16:01:52 +02:00
|
|
|
#include <LibGfx/Font.h>
|
2021-05-22 18:47:42 +02:00
|
|
|
#include <LibThreading/Thread.h>
|
2020-09-19 17:25:05 +03:00
|
|
|
|
|
|
|
namespace HackStudio {
|
|
|
|
|
|
|
|
class HackStudioWidget : public GUI::Widget {
|
|
|
|
C_OBJECT(HackStudioWidget)
|
|
|
|
|
|
|
|
public:
|
2020-09-26 11:23:49 +03:00
|
|
|
virtual ~HackStudioWidget() override;
|
2021-08-27 16:18:00 +03:00
|
|
|
|
|
|
|
bool open_file(String const& filename, size_t line = 0, size_t column = 0);
|
2021-08-01 13:01:49 +01:00
|
|
|
void close_file_in_all_editors(String const& filename);
|
2020-09-19 17:25:05 +03:00
|
|
|
|
|
|
|
void update_actions();
|
|
|
|
Project& project();
|
|
|
|
GUI::TextEditor& current_editor();
|
2021-08-27 16:26:18 +03:00
|
|
|
GUI::TextEditor const& current_editor() const;
|
2020-09-19 17:25:05 +03:00
|
|
|
EditorWrapper& current_editor_wrapper();
|
2021-08-27 16:26:18 +03:00
|
|
|
EditorWrapper const& current_editor_wrapper() const;
|
2020-09-19 17:25:05 +03:00
|
|
|
void set_current_editor_wrapper(RefPtr<EditorWrapper>);
|
|
|
|
|
2021-05-01 13:04:19 +03:00
|
|
|
const String& active_file() const { return m_current_editor_wrapper->filename(); }
|
2021-07-21 21:21:03 +02:00
|
|
|
void initialize_menubar(GUI::Window&);
|
2020-09-19 17:25:05 +03:00
|
|
|
|
2021-02-27 09:50:02 +02:00
|
|
|
Locator& locator()
|
|
|
|
{
|
|
|
|
VERIFY(m_locator);
|
|
|
|
return *m_locator;
|
|
|
|
}
|
|
|
|
|
2021-05-01 13:42:07 +03:00
|
|
|
enum class ContinueDecision {
|
|
|
|
No,
|
|
|
|
Yes
|
|
|
|
};
|
|
|
|
ContinueDecision warn_unsaved_changes(const String& prompt);
|
|
|
|
|
2021-11-19 16:13:07 +02:00
|
|
|
enum class Mode {
|
|
|
|
Code,
|
|
|
|
Coredump
|
|
|
|
};
|
|
|
|
|
|
|
|
void open_coredump(String const& coredump_path);
|
2021-12-03 09:38:03 +02:00
|
|
|
void for_each_open_file(Function<void(ProjectFile const&)>);
|
2021-11-19 16:13:07 +02:00
|
|
|
|
2020-09-19 17:25:05 +03:00
|
|
|
private:
|
|
|
|
static String get_full_path_of_serenity_source(const String& file);
|
2021-11-19 16:13:07 +02:00
|
|
|
String get_absolute_path(String const&) const;
|
2021-03-31 02:54:39 +02:00
|
|
|
Vector<String> selected_file_paths() const;
|
2020-09-19 17:25:05 +03:00
|
|
|
|
2021-11-19 16:13:07 +02:00
|
|
|
HackStudioWidget(String path_to_project);
|
2020-12-10 18:59:03 +01:00
|
|
|
void open_project(const String& root_path);
|
2020-09-19 17:25:05 +03:00
|
|
|
|
|
|
|
enum class EditMode {
|
|
|
|
Text,
|
|
|
|
Diff,
|
|
|
|
};
|
|
|
|
|
|
|
|
void set_edit_mode(EditMode);
|
|
|
|
|
|
|
|
NonnullRefPtr<GUI::Menu> create_project_tree_view_context_menu();
|
2021-07-30 22:06:47 +02:00
|
|
|
NonnullRefPtr<GUI::Action> create_new_file_action(String const& label, String const& icon, String const& extension);
|
2021-01-31 19:06:41 +01:00
|
|
|
NonnullRefPtr<GUI::Action> create_new_directory_action();
|
2020-09-19 17:25:05 +03:00
|
|
|
NonnullRefPtr<GUI::Action> create_open_selected_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_delete_action();
|
2021-02-13 21:22:48 +11:00
|
|
|
NonnullRefPtr<GUI::Action> create_new_project_action();
|
2020-09-19 17:25:05 +03:00
|
|
|
NonnullRefPtr<GUI::Action> create_switch_to_next_editor_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_switch_to_previous_editor_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_remove_current_editor_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_open_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_save_action();
|
2021-08-12 17:07:39 +02:00
|
|
|
NonnullRefPtr<GUI::Action> create_save_as_action();
|
2021-06-11 23:33:39 +02:00
|
|
|
NonnullRefPtr<GUI::Action> create_show_in_file_manager_action();
|
2020-09-19 17:25:05 +03:00
|
|
|
NonnullRefPtr<GUI::Action> create_add_editor_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_add_terminal_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_remove_current_terminal_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_debug_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_build_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_run_action();
|
|
|
|
NonnullRefPtr<GUI::Action> create_stop_action();
|
2021-08-27 16:26:18 +03:00
|
|
|
void create_location_history_actions();
|
2020-09-19 17:25:05 +03:00
|
|
|
|
|
|
|
void add_new_editor(GUI::Widget& parent);
|
2021-04-29 21:46:15 +02:00
|
|
|
RefPtr<EditorWrapper> get_editor_of_file(const String& filename);
|
2020-09-19 17:25:05 +03:00
|
|
|
String get_project_executable_path() const;
|
|
|
|
|
|
|
|
void on_action_tab_change();
|
|
|
|
void reveal_action_tab(GUI::Widget&);
|
|
|
|
void initialize_debugger();
|
2021-07-01 20:39:17 -04:00
|
|
|
void update_statusbar();
|
2020-09-19 17:25:05 +03:00
|
|
|
|
2021-04-28 16:01:14 +02:00
|
|
|
void handle_external_file_deletion(const String& filepath);
|
2021-08-02 01:11:42 +01:00
|
|
|
void stop_debugger_if_running();
|
2021-08-02 20:14:15 +01:00
|
|
|
void close_current_project();
|
2021-04-28 16:01:14 +02:00
|
|
|
|
2020-10-26 12:13:32 +01:00
|
|
|
void create_open_files_view(GUI::Widget& parent);
|
2020-09-19 17:25:05 +03:00
|
|
|
void create_toolbar(GUI::Widget& parent);
|
|
|
|
void create_action_tab(GUI::Widget& parent);
|
2021-07-21 21:21:03 +02:00
|
|
|
void create_file_menu(GUI::Window&);
|
|
|
|
void create_project_menu(GUI::Window&);
|
|
|
|
void create_edit_menu(GUI::Window&);
|
|
|
|
void create_build_menu(GUI::Window&);
|
|
|
|
void create_view_menu(GUI::Window&);
|
|
|
|
void create_help_menu(GUI::Window&);
|
2021-04-10 17:38:11 +03:00
|
|
|
void create_project_tab(GUI::Widget& parent);
|
|
|
|
void configure_project_tree_view();
|
2020-09-19 17:25:05 +03:00
|
|
|
|
2022-01-07 17:23:50 +02:00
|
|
|
void run();
|
|
|
|
void build();
|
2020-09-19 17:25:05 +03:00
|
|
|
|
|
|
|
void hide_action_tabs();
|
2021-05-01 13:42:07 +03:00
|
|
|
bool any_document_is_dirty() const;
|
2020-09-19 17:25:05 +03:00
|
|
|
|
2021-07-28 20:58:16 +01:00
|
|
|
void update_gml_preview();
|
2021-08-22 19:38:05 +02:00
|
|
|
void update_tree_view();
|
2021-08-13 13:10:58 +02:00
|
|
|
void update_window_title();
|
2021-08-27 16:26:18 +03:00
|
|
|
void on_cursor_change();
|
2021-09-24 18:31:08 +02:00
|
|
|
void file_renamed(String const& old_name, String const& new_name);
|
2021-08-27 16:26:18 +03:00
|
|
|
|
|
|
|
struct ProjectLocation {
|
|
|
|
String filename;
|
|
|
|
size_t line { 0 };
|
|
|
|
size_t column { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
ProjectLocation current_project_location() const;
|
|
|
|
void update_history_actions();
|
2021-07-28 20:58:16 +01:00
|
|
|
|
2020-09-19 17:25:05 +03:00
|
|
|
NonnullRefPtrVector<EditorWrapper> m_all_editor_wrappers;
|
|
|
|
RefPtr<EditorWrapper> m_current_editor_wrapper;
|
|
|
|
|
2020-10-26 12:13:32 +01:00
|
|
|
HashMap<String, NonnullRefPtr<ProjectFile>> m_open_files;
|
2021-05-09 17:09:30 +00:00
|
|
|
RefPtr<Core::FileWatcher> m_file_watcher;
|
2021-04-28 16:01:14 +02:00
|
|
|
Vector<String> m_open_files_vector; // NOTE: This contains the keys from m_open_files and m_file_watchers
|
2020-10-26 12:13:32 +01:00
|
|
|
|
2020-09-19 17:25:05 +03:00
|
|
|
OwnPtr<Project> m_project;
|
2020-09-27 00:11:15 +03:00
|
|
|
|
2021-08-27 16:26:18 +03:00
|
|
|
Vector<ProjectLocation> m_locations_history;
|
|
|
|
// This index is the boundary between the "Go Back" and "Go Forward" locations.
|
|
|
|
// It always points at one past the current location in the list.
|
|
|
|
size_t m_locations_history_end_index { 0 };
|
|
|
|
bool m_locations_history_disabled { false };
|
|
|
|
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<GUI::TreeView> m_project_tree_view;
|
2020-10-26 12:13:32 +01:00
|
|
|
RefPtr<GUI::ListView> m_open_files_view;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<GUI::VerticalSplitter> m_right_hand_splitter;
|
|
|
|
RefPtr<GUI::StackWidget> m_right_hand_stack;
|
|
|
|
RefPtr<GUI::Splitter> m_editors_splitter;
|
|
|
|
RefPtr<DiffViewer> m_diff_viewer;
|
|
|
|
RefPtr<GitWidget> m_git_widget;
|
2021-07-28 20:58:16 +01:00
|
|
|
RefPtr<GMLPreviewWidget> m_gml_preview_widget;
|
2021-04-10 17:38:11 +03:00
|
|
|
RefPtr<ClassViewWidget> m_class_view;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<GUI::Menu> m_project_tree_view_context_menu;
|
2021-07-01 20:39:17 -04:00
|
|
|
RefPtr<GUI::Statusbar> m_statusbar;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<GUI::TabWidget> m_action_tab_widget;
|
2021-04-10 17:38:11 +03:00
|
|
|
RefPtr<GUI::TabWidget> m_project_tab;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<TerminalWrapper> m_terminal_wrapper;
|
|
|
|
RefPtr<Locator> m_locator;
|
|
|
|
RefPtr<FindInFilesWidget> m_find_in_files_widget;
|
2021-05-22 14:14:49 +02:00
|
|
|
RefPtr<ToDoEntriesWidget> m_todo_entries_widget;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<DebugInfoWidget> m_debug_info_widget;
|
|
|
|
RefPtr<DisassemblyWidget> m_disassembly_widget;
|
2021-05-22 18:47:42 +02:00
|
|
|
RefPtr<Threading::Thread> m_debugger_thread;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<EditorWrapper> m_current_editor_in_execution;
|
|
|
|
|
2021-07-30 22:06:47 +02:00
|
|
|
NonnullRefPtrVector<GUI::Action> m_new_file_actions;
|
|
|
|
RefPtr<GUI::Action> m_new_plain_file_action;
|
|
|
|
|
2021-01-31 19:06:41 +01:00
|
|
|
RefPtr<GUI::Action> m_new_directory_action;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<GUI::Action> m_open_selected_action;
|
2021-06-11 23:33:39 +02:00
|
|
|
RefPtr<GUI::Action> m_show_in_file_manager_action;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<GUI::Action> m_delete_action;
|
2021-09-24 18:31:08 +02:00
|
|
|
RefPtr<GUI::Action> m_tree_view_rename_action;
|
2021-02-13 21:22:48 +11:00
|
|
|
RefPtr<GUI::Action> m_new_project_action;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<GUI::Action> m_switch_to_next_editor;
|
|
|
|
RefPtr<GUI::Action> m_switch_to_previous_editor;
|
|
|
|
RefPtr<GUI::Action> m_remove_current_editor_action;
|
|
|
|
RefPtr<GUI::Action> m_open_action;
|
|
|
|
RefPtr<GUI::Action> m_save_action;
|
2021-08-12 17:07:39 +02:00
|
|
|
RefPtr<GUI::Action> m_save_as_action;
|
2020-09-19 17:25:05 +03:00
|
|
|
RefPtr<GUI::Action> m_add_editor_action;
|
|
|
|
RefPtr<GUI::Action> m_add_terminal_action;
|
|
|
|
RefPtr<GUI::Action> m_remove_current_terminal_action;
|
|
|
|
RefPtr<GUI::Action> m_stop_action;
|
|
|
|
RefPtr<GUI::Action> m_debug_action;
|
|
|
|
RefPtr<GUI::Action> m_build_action;
|
|
|
|
RefPtr<GUI::Action> m_run_action;
|
2021-08-27 16:26:18 +03:00
|
|
|
RefPtr<GUI::Action> m_locations_history_back_action;
|
|
|
|
RefPtr<GUI::Action> m_locations_history_forward_action;
|
2021-01-09 22:47:48 +10:00
|
|
|
|
2021-10-06 16:01:52 +02:00
|
|
|
RefPtr<Gfx::Font> read_editor_font_from_config();
|
|
|
|
void change_editor_font(RefPtr<Gfx::Font>);
|
|
|
|
RefPtr<Gfx::Font> m_editor_font;
|
|
|
|
RefPtr<GUI::Action> m_editor_font_action;
|
|
|
|
|
2021-01-09 22:47:48 +10:00
|
|
|
GUI::ActionGroup m_wrapping_mode_actions;
|
|
|
|
RefPtr<GUI::Action> m_no_wrapping_action;
|
|
|
|
RefPtr<GUI::Action> m_wrap_anywhere_action;
|
|
|
|
RefPtr<GUI::Action> m_wrap_at_words_action;
|
2021-11-19 16:13:07 +02:00
|
|
|
|
|
|
|
Mode m_mode { Mode::Code };
|
|
|
|
OwnPtr<Coredump::Inspector> m_coredump_inspector;
|
2022-01-07 17:23:50 +02:00
|
|
|
OwnPtr<ProjectBuilder> m_project_builder;
|
2020-09-19 17:25:05 +03:00
|
|
|
};
|
|
|
|
}
|