summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio/Git/GitFilesModel.cpp
blob: 99cb8a6f4e588efbfed7e7fd72a1d10ca3c2a675 (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
/*
 * Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include "GitFilesModel.h"

namespace HackStudio {

NonnullRefPtr<GitFilesModel> GitFilesModel::create(Vector<LexicalPath>&& files)
{
    return adopt_ref(*new GitFilesModel(move(files)));
}

GitFilesModel::GitFilesModel(Vector<LexicalPath>&& files)
    : m_files(move(files))
{
}

GUI::Variant GitFilesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
{
    if (role == GUI::ModelRole::Display) {
        return m_files.at(index.row()).string();
    }
    return {};
}

GUI::ModelIndex GitFilesModel::index(int row, int column, const GUI::ModelIndex&) const
{
    if (row < 0 || row >= static_cast<int>(m_files.size()))
        return {};
    return create_index(row, column, &m_files.at(row));
}

};