1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

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.
This commit is contained in:
Andreas Kling 2020-12-10 18:59:03 +01:00
parent 5d0fda3d39
commit dd3e6451ac
6 changed files with 86 additions and 468 deletions

View file

@ -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);
explicit Project(const String& root_path);
const ProjectTreeNode& root_node() const { return *m_root_node; }
void rebuild_tree();
RefPtr<GUI::FileSystemModel> m_model;
mutable NonnullRefPtrVector<ProjectFile> m_files;
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;
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;
};
}