1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:35:08 +00:00
serenity/DevTools/HackStudio/Project.h
Andreas Kling 6e27b14a4a HackStudio: Sort the project tree alphabetically
I had to turn the tree nodes into RefCounted objects since it's not
possible to quick_sort() a Vector<OwnPtr<T>> at the moment.
2019-12-23 10:55:34 +01:00

50 lines
1.1 KiB
C++

#pragma once
#include "ProjectFile.h"
#include <AK/Noncopyable.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/OwnPtr.h>
#include <LibGUI/GIcon.h>
#include <LibGUI/GModel.h>
class Project {
AK_MAKE_NONCOPYABLE(Project)
AK_MAKE_NONMOVABLE(Project)
public:
~Project();
static OwnPtr<Project> load_from_file(const String& path);
[[nodiscard]] bool add_file(const String& filename);
ProjectFile* get_file(const String& filename);
GModel& model() { return *m_model; }
template<typename Callback>
void for_each_text_file(Callback callback) const
{
for (auto& file : m_files) {
callback(file);
}
}
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();
String m_path;
RefPtr<GModel> m_model;
NonnullRefPtrVector<ProjectFile> m_files;
RefPtr<ProjectTreeNode> m_root_node;
GIcon m_directory_icon;
GIcon m_file_icon;
GIcon m_cplusplus_icon;
GIcon m_header_icon;
GIcon m_project_icon;
};