summaryrefslogtreecommitdiff
path: root/DevTools/HackStudio/Project.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-21 18:46:55 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-21 18:46:55 +0200
commit0311e8d50a9f1e74102d4b404feccc3c2f157cd7 (patch)
tree27b64f96bd5851189b4e11a42e38ebfd7403ef46 /DevTools/HackStudio/Project.cpp
parent74bba649c3f3efd36b05f05b40d4346a501b213c (diff)
downloadserenity-0311e8d50a9f1e74102d4b404feccc3c2f157cd7.zip
HackStudio: Start working on an IDE for SerenityOS
This will be fun. :^)
Diffstat (limited to 'DevTools/HackStudio/Project.cpp')
-rw-r--r--DevTools/HackStudio/Project.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/DevTools/HackStudio/Project.cpp b/DevTools/HackStudio/Project.cpp
new file mode 100644
index 0000000000..d1a4da35d1
--- /dev/null
+++ b/DevTools/HackStudio/Project.cpp
@@ -0,0 +1,48 @@
+#include "Project.h"
+#include <LibCore/CFile.h>
+
+class ProjectModel final : public GModel {
+public:
+ explicit ProjectModel(Project& project)
+ : m_project(project)
+ {
+ }
+
+ virtual int row_count(const GModelIndex& = GModelIndex()) const override { return m_project.m_files.size(); }
+ virtual int column_count(const GModelIndex& = GModelIndex()) const override { return 1; }
+ virtual GVariant data(const GModelIndex& index, Role role = Role::Display) const override
+ {
+ int row = index.row();
+ if (role == Role::Display) {
+ return m_project.m_files.at(row);
+ }
+ return {};
+ }
+ virtual void update() override {}
+
+private:
+ Project& m_project;
+};
+
+Project::Project(Vector<String>&& files)
+ : m_files(move(files))
+{
+ m_model = adopt(*new ProjectModel(*this));
+}
+
+OwnPtr<Project> Project::load_from_file(const String& path)
+{
+ auto file = CFile::construct(path);
+ if (!file->open(CFile::ReadOnly))
+ return nullptr;
+
+ Vector<String> files;
+ for (;;) {
+ auto line = file->read_line(1024);
+ if (line.is_null())
+ break;
+ files.append(String::copy(line, Chomp));
+ }
+
+ return OwnPtr(new Project(move(files)));
+}