diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-10 18:59:03 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-10 20:42:11 +0100 |
commit | dd3e6451ac9f74ecdd59e774be5da67ffe2213d4 (patch) | |
tree | 0f4c728c7f547a7e0be8c35beb6d95ed8e7c2c60 /DevTools/HackStudio/Project.h | |
parent | 5d0fda3d39c978f06744863c8808218431665c94 (diff) | |
download | serenity-dd3e6451ac9f74ecdd59e774be5da67ffe2213d4.zip |
HackStudio: Rethink the "project" concept to be about a directory
Instead of having .hsp files that determine which files are members
of a project, a project is now an entire directory tree instead.
This feels a lot less cumbersome to work with, and removes a fair
amount of busywork that would otherwise be expected from the user.
This patch refactors large parts of HackStudio to implement the new
way of thinking. I've probably missed some details here and there,
but generally I think it's pretty OK.
Diffstat (limited to 'DevTools/HackStudio/Project.h')
-rw-r--r-- | DevTools/HackStudio/Project.h | 60 |
1 files changed, 12 insertions, 48 deletions
diff --git a/DevTools/HackStudio/Project.h b/DevTools/HackStudio/Project.h index dddb34726f..6d3453e84e 100644 --- a/DevTools/HackStudio/Project.h +++ b/DevTools/HackStudio/Project.h @@ -29,19 +29,11 @@ #include "ProjectFile.h" #include <AK/LexicalPath.h> #include <AK/Noncopyable.h> -#include <AK/NonnullRefPtrVector.h> #include <AK/OwnPtr.h> -#include <LibGUI/Icon.h> -#include <LibGUI/Model.h> +#include <LibGUI/FileSystemModel.h> namespace HackStudio { -enum class ProjectType { - Unknown, - Cpp, - JavaScript -}; - class Project { AK_MAKE_NONCOPYABLE(Project); AK_MAKE_NONMOVABLE(Project); @@ -49,52 +41,24 @@ class Project { public: ~Project(); - static OwnPtr<Project> load_from_file(const String& path); + static OwnPtr<Project> open_with_root_path(const String& root_path); - [[nodiscard]] bool add_file(const String& filename); - [[nodiscard]] bool remove_file(const String& filename); - [[nodiscard]] bool save(); + GUI::FileSystemModel& model() { return *m_model; } + const GUI::FileSystemModel& model() const { return *m_model; } + String name() const { return LexicalPath(m_root_path).basename(); } + String root_path() const { return m_root_path; } - RefPtr<ProjectFile> get_file(const String& filename); + RefPtr<ProjectFile> get_file(const String& path) const; - ProjectType type() const { return m_type; } - GUI::Model& model() { return *m_model; } - String default_file() const; - String name() const { return m_name; } - String path() const { return m_path; } - String root_directory() const { return LexicalPath(m_path).dirname(); } - - template<typename Callback> - void for_each_text_file(Callback callback) const - { - for (auto& file : m_files) { - callback(file); - } - } + void for_each_text_file(Function<void(const ProjectFile&)>) const; private: - friend class ProjectModel; - struct ProjectTreeNode; - explicit Project(const String& path, Vector<String>&& files); - - const ProjectTreeNode& root_node() const { return *m_root_node; } - void rebuild_tree(); + explicit Project(const String& root_path); - ProjectType m_type { ProjectType::Unknown }; - String m_name; - String m_path; - RefPtr<GUI::Model> m_model; - NonnullRefPtrVector<ProjectFile> m_files; - RefPtr<ProjectTreeNode> m_root_node; + RefPtr<GUI::FileSystemModel> m_model; + mutable NonnullRefPtrVector<ProjectFile> m_files; - GUI::Icon m_directory_icon; - GUI::Icon m_file_icon; - GUI::Icon m_cplusplus_icon; - GUI::Icon m_header_icon; - GUI::Icon m_project_icon; - GUI::Icon m_javascript_icon; - GUI::Icon m_hackstudio_icon; - GUI::Icon m_form_icon; + String m_root_path; }; } |