/
DeclarationSelector.cpp
148 lines (116 loc) · 4.29 KB
/
DeclarationSelector.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "DeclarationSelector.h"
#include <wx/sizer.h>
#include "wxutil/dataview/ResourceTreeViewToolbar.h"
#include "wxutil/DeclFileInfo.h"
namespace ui
{
DeclarationSelector::DeclarationSelector(wxWindow* parent, decl::Type declType) :
DeclarationSelector(parent, declType, CreateDefaultColumns())
{}
DeclarationSelector::DeclarationSelector(wxWindow* parent, decl::Type declType,
const wxutil::DeclarationTreeView::Columns& columns) :
wxPanel(parent),
_declType(declType),
_columns(columns),
_treeView(nullptr),
_horizontalSizer(nullptr),
_treeViewSizerItem(nullptr)
{
SetSizer(new wxBoxSizer(wxVERTICAL));
createTreeView();
auto* toolbar = new wxutil::ResourceTreeViewToolbar(this, _treeView);
_declFileInfo = new wxutil::DeclFileInfo(this, _declType);
auto treeVbox = new wxBoxSizer(wxVERTICAL);
treeVbox->Add(toolbar, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 6);
treeVbox->Add(_treeView, 1, wxEXPAND);
treeVbox->Add(_declFileInfo, 0, wxEXPAND | wxTOP | wxBOTTOM, 6);
_horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
_treeViewSizerItem = _horizontalSizer->Add(treeVbox, 1, wxEXPAND);
// the horizontal sizer has room for a preview widget => AddPreviewToRightPane
GetSizer()->Add(_horizontalSizer, 1, wxEXPAND);
// a preview widget can be appended to the vertical sizer => AddPreviewToBottom
}
void DeclarationSelector::AddPreviewToRightPane(IDeclarationPreview* preview, int sizerProportion)
{
auto widget = preview->GetPreviewWidget();
// Tree view no longer takes full proportion after a full-size preview has been added
if (sizerProportion == 1)
{
_treeViewSizerItem->SetProportion(0);
}
widget->Reparent(this);
_horizontalSizer->Add(widget, sizerProportion, wxEXPAND | wxLEFT, 6);
_previews.push_back(preview);
}
void DeclarationSelector::AddPreviewToBottom(IDeclarationPreview* preview, int sizerProportion)
{
auto widget = preview->GetPreviewWidget();
widget->Reparent(this);
GetSizer()->Add(widget, sizerProportion, wxEXPAND | wxTOP, 3);
_previews.push_back(preview);
}
void DeclarationSelector::createTreeView()
{
_treeView = new wxutil::DeclarationTreeView(this, _declType, _columns, wxDV_NO_HEADER | wxDV_SINGLE);
// Single visible column, containing the directory/decl name and the icon
_treeView->AppendIconTextColumn(decl::getTypeName(_declType), _columns.iconAndName.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE);
// Use the TreeModel's full string search function
_treeView->AddSearchColumn(_columns.leafName);
// Get selection and connect the changed callback
_treeView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &DeclarationSelector::onTreeViewSelectionChanged, this);
_treeView->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &DeclarationSelector::onTreeViewItemActivated, this);
}
wxutil::DeclarationTreeView* DeclarationSelector::GetTreeView() const
{
return _treeView;
}
const wxutil::DeclarationTreeView::Columns& DeclarationSelector::GetColumns() const
{
return _columns;
}
std::string DeclarationSelector::GetSelectedDeclName() const
{
return _treeView->GetSelectedDeclName();
}
void DeclarationSelector::SetSelectedDeclName(const std::string& declName)
{
_treeView->SetSelectedDeclName(declName);
}
void DeclarationSelector::PopulateTreeView(const wxutil::IResourceTreePopulator::Ptr& populator)
{
_treeView->Populate(populator);
}
const wxutil::DeclarationTreeView::Columns& DeclarationSelector::CreateDefaultColumns()
{
static wxutil::DeclarationTreeView::Columns _treeViewColumns;
return _treeViewColumns;
}
void DeclarationSelector::onTreeViewSelectionChanged(wxDataViewEvent& ev)
{
auto declName = _treeView->GetSelectedDeclName();
// Notify all previews
for (auto preview : _previews)
{
preview->SetPreviewDeclName(declName);
}
// Update the info labels
if (!declName.empty())
{
_declFileInfo->SetDeclarationName(declName);
}
else
{
_declFileInfo->Clear();
}
// Invoke the virtual method
onTreeViewSelectionChanged();
ev.Skip();
}
void DeclarationSelector::onTreeViewItemActivated(wxDataViewEvent& ev)
{
// Invoke the virtual method
onTreeViewItemActivated();
ev.Skip();
}
}