Project.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "ProjectFile.h"
  8. #include <AK/LexicalPath.h>
  9. #include <AK/Noncopyable.h>
  10. #include <AK/OwnPtr.h>
  11. #include <LibGUI/FileSystemModel.h>
  12. namespace HackStudio {
  13. class Project {
  14. AK_MAKE_NONCOPYABLE(Project);
  15. AK_MAKE_NONMOVABLE(Project);
  16. public:
  17. static OwnPtr<Project> open_with_root_path(const String& root_path);
  18. GUI::FileSystemModel& model() { return *m_model; }
  19. const GUI::FileSystemModel& model() const { return *m_model; }
  20. String name() const { return LexicalPath(m_root_path).basename(); }
  21. String root_path() const { return m_root_path; }
  22. NonnullRefPtr<ProjectFile> get_file(const String& path) const;
  23. void for_each_text_file(Function<void(const ProjectFile&)>) const;
  24. private:
  25. explicit Project(const String& root_path);
  26. String to_absolute_path(const String&) const;
  27. RefPtr<GUI::FileSystemModel> m_model;
  28. mutable NonnullRefPtrVector<ProjectFile> m_files;
  29. String m_root_path;
  30. };
  31. }