blob: 30acbc7729ec89136808bece736f52584efa26b4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#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);
}
if (role == Role::Font) {
extern String g_currently_open_file;
if (m_project.m_files.at(row) == g_currently_open_file)
return Font::default_bold_font();
return {};
}
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)));
}
|