/
KeyValueTable.cpp
67 lines (50 loc) · 1.36 KB
/
KeyValueTable.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "KeyValueTable.h"
#include "i18n.h"
namespace wxutil
{
namespace
{
// Column setup for the list store
struct Columns :
public wxutil::TreeModel::ColumnRecord
{
Columns() :
key(add(wxutil::TreeModel::Column::String)),
value(add(wxutil::TreeModel::Column::String))
{}
wxutil::TreeModel::Column key;
wxutil::TreeModel::Column value;
};
const Columns& COLUMNS()
{
static const Columns _instance;
return _instance;
}
}
KeyValueTable::KeyValueTable(wxWindow* parent) :
wxutil::TreeView(parent, nullptr, wxDV_NO_HEADER | wxDV_SINGLE),
_store(new wxutil::TreeModel(COLUMNS(), true)) // list model
{
AssociateModel(_store.get());
EnableAutoColumnWidthFix(false); // we don't need this
// Single visible column, containing the directory/shader name and the icon
AppendTextColumn(_("Key"), COLUMNS().key.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE);
AppendTextColumn(_("Value"), COLUMNS().value.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE);
}
void KeyValueTable::Clear()
{
_store->Clear();
}
void KeyValueTable::Append(const std::string& key, const std::string& value)
{
wxutil::TreeModel::Row row = _store->AddItem();
wxDataViewItemAttr bold;
bold.SetBold(true);
row[COLUMNS().key] = key;
row[COLUMNS().key] = bold;
row[COLUMNS().value] = value;
row.SendItemAdded();
}
} // namespace