diff --git a/DevTools/HackStudio/HackStudioWidget.cpp b/DevTools/HackStudio/HackStudioWidget.cpp index ffe54ca1ea..ef79a84bd2 100644 --- a/DevTools/HackStudio/HackStudioWidget.cpp +++ b/DevTools/HackStudio/HackStudioWidget.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -97,9 +98,15 @@ HackStudioWidget::HackStudioWidget(const String& path_to_project) auto& toolbar_container = add(); auto& outer_splitter = add(); - create_project_tree_view(outer_splitter); + + auto& left_hand_splitter = outer_splitter.add(); + left_hand_splitter.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); + left_hand_splitter.set_preferred_size(150, 0); + create_project_tree_view(left_hand_splitter); m_project_tree_view_context_menu = create_project_tree_view_context_menu(); + create_open_files_view(left_hand_splitter); + m_right_hand_splitter = outer_splitter.add(); m_right_hand_stack = m_right_hand_splitter->add(); create_form_editor(*m_right_hand_stack); @@ -198,15 +205,23 @@ Vector HackStudioWidget::selected_file_names() const void HackStudioWidget::open_file(const String& filename) { auto project_file = m_project->get_file(filename); - if (project_file) { - current_editor().set_document(const_cast(project_file->document())); - current_editor().set_mode(GUI::TextEditor::Editable); - } else { - auto external_file = ProjectFile::construct_with_name(filename); - current_editor().set_document(const_cast(external_file->document())); - current_editor().set_mode(GUI::TextEditor::ReadOnly); + + if (!project_file) { + if (auto it = m_open_files.find(filename); it != m_open_files.end()) { + project_file = it->value; + } else { + project_file = ProjectFile::construct_with_name(filename); + } } + if (m_open_files.set(filename, *project_file) == AK::HashSetResult::InsertedNewEntry) { + m_open_files_vector.append(filename); + m_open_files_view->model()->update(); + } + + current_editor().set_document(const_cast(project_file->document())); + current_editor().set_mode(GUI::TextEditor::Editable); + if (filename.ends_with(".frm")) { set_edit_mode(EditMode::Form); } else { @@ -625,8 +640,6 @@ void HackStudioWidget::create_project_tree_view(GUI::Widget& parent) { m_project_tree_view = parent.add(); m_project_tree_view->set_model(m_project->model()); - m_project_tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); - m_project_tree_view->set_preferred_size(140, 0); m_project_tree_view->toggle_index(m_project_tree_view->model()->index(0, 0)); m_project_tree_view->on_context_menu_request = [this](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) { @@ -646,6 +659,17 @@ void HackStudioWidget::create_project_tree_view(GUI::Widget& parent) }; } +void HackStudioWidget::create_open_files_view(GUI::Widget& parent) +{ + m_open_files_view = parent.add(); + auto open_files_model = GUI::ItemListModel::create(m_open_files_vector); + m_open_files_view->set_model(open_files_model); + + m_open_files_view->on_activation = [this] (auto& index) { + open_file(index.data().to_string()); + }; +} + void HackStudioWidget::create_form_editor(GUI::Widget& parent) { m_form_inner_container = parent.add(); diff --git a/DevTools/HackStudio/HackStudioWidget.h b/DevTools/HackStudio/HackStudioWidget.h index c7f254446b..f6e930de3a 100644 --- a/DevTools/HackStudio/HackStudioWidget.h +++ b/DevTools/HackStudio/HackStudioWidget.h @@ -103,6 +103,7 @@ private: void initialize_debugger(); void create_project_tree_view(GUI::Widget& parent); + void create_open_files_view(GUI::Widget& parent); void create_form_editor(GUI::Widget& parent); void create_toolbar(GUI::Widget& parent); void create_action_tab(GUI::Widget& parent); @@ -121,10 +122,16 @@ private: NonnullRefPtrVector m_all_editor_wrappers; RefPtr m_current_editor_wrapper; + // FIXME: This doesn't seem compatible with multiple split editors String m_currently_open_file; + + HashMap> m_open_files; + Vector m_open_files_vector; // NOTE: This contains the keys from m_open_files + OwnPtr m_project; RefPtr m_project_tree_view; + RefPtr m_open_files_view; RefPtr m_right_hand_splitter; RefPtr m_right_hand_stack; RefPtr m_editors_splitter; diff --git a/DevTools/HackStudio/Project.cpp b/DevTools/HackStudio/Project.cpp index 6c71337896..8ff6a13a06 100644 --- a/DevTools/HackStudio/Project.cpp +++ b/DevTools/HackStudio/Project.cpp @@ -291,7 +291,7 @@ bool Project::save() return true; } -ProjectFile* Project::get_file(const String& filename) +RefPtr Project::get_file(const String& filename) { for (auto& file : m_files) { if (LexicalPath(file.name()).string() == LexicalPath(filename).string()) diff --git a/DevTools/HackStudio/Project.h b/DevTools/HackStudio/Project.h index d1a3c31ac8..dddb34726f 100644 --- a/DevTools/HackStudio/Project.h +++ b/DevTools/HackStudio/Project.h @@ -55,7 +55,7 @@ public: [[nodiscard]] bool remove_file(const String& filename); [[nodiscard]] bool save(); - ProjectFile* get_file(const String& filename); + RefPtr get_file(const String& filename); ProjectType type() const { return m_type; } GUI::Model& model() { return *m_model; }