mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 10:01:13 +09:00
HackStudio: Start working on an IDE for SerenityOS
This will be fun. :^)
This commit is contained in:
parent
74bba649c3
commit
0311e8d50a
Notes:
sideshowbarker
2024-07-19 11:35:48 +09:00
Author: https://github.com/awesomekling
Commit: 0311e8d50a
6 changed files with 157 additions and 0 deletions
48
DevTools/HackStudio/Project.cpp
Normal file
48
DevTools/HackStudio/Project.cpp
Normal file
|
@ -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)));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue