Project.h 839 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include "TextDocument.h"
  3. #include <AK/Noncopyable.h>
  4. #include <AK/NonnullRefPtrVector.h>
  5. #include <AK/OwnPtr.h>
  6. #include <LibGUI/GModel.h>
  7. class Project {
  8. AK_MAKE_NONCOPYABLE(Project)
  9. AK_MAKE_NONMOVABLE(Project)
  10. public:
  11. static OwnPtr<Project> load_from_file(const String& path);
  12. [[nodiscard]] bool add_file(const String& filename);
  13. TextDocument* get_file(const String& filename);
  14. GModel& model() { return *m_model; }
  15. template<typename Callback>
  16. void for_each_text_file(Callback callback) const
  17. {
  18. for (auto& file : m_files) {
  19. callback(file);
  20. }
  21. }
  22. private:
  23. friend class ProjectModel;
  24. explicit Project(const String& path, Vector<String>&& files);
  25. String m_path;
  26. RefPtr<GModel> m_model;
  27. NonnullRefPtrVector<TextDocument> m_files;
  28. };