/
MediaBrowserTreeView.cpp
139 lines (116 loc) · 4.42 KB
/
MediaBrowserTreeView.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
#include "MediaBrowserTreeView.h"
#include "i18n.h"
#include "icommandsystem.h"
#include "ui/materials/MaterialDefinitionView.h"
#include "TextureDirectoryLoader.h"
#include "wxutil/ModalProgressDialog.h"
namespace ui
{
namespace
{
constexpr const char* const LOAD_TEXTURE_TEXT = N_("Load in Textures view");
constexpr const char* const LOAD_TEXTURE_ICON = "textureLoadInTexWindow16.png";
constexpr const char* const APPLY_TEXTURE_TEXT = N_("Apply to selection");
constexpr const char* const APPLY_TEXTURE_ICON = "textureApplyToSelection16.png";
constexpr const char* const SHOW_SHADER_DEF_TEXT = N_("Show Shader Definition");
constexpr const char* const SHOW_SHADER_DEF_ICON = "icon_script.png";
constexpr const char* const SELECT_ITEMS = N_("Select elements using this shader");
constexpr const char* const DESELECT_ITEMS = N_("Deselect elements using this shader");
constexpr const char* const TEXTURE_ICON = "icon_texture.png";
}
MediaBrowserTreeView::MediaBrowserTreeView(wxWindow* parent) :
MaterialTreeView(parent)
{
Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &MediaBrowserTreeView::_onTreeViewItemActivated, this);
}
void MediaBrowserTreeView::PopulateContextMenu(wxutil::PopupMenu& popupMenu)
{
// Construct the popup context menu
popupMenu.addItem(
new wxutil::IconTextMenuItem(_(LOAD_TEXTURE_TEXT), LOAD_TEXTURE_ICON),
std::bind(&MediaBrowserTreeView::_onLoadInTexView, this),
std::bind(&MediaBrowserTreeView::_testLoadInTexView, this)
);
popupMenu.addItem(
new wxutil::IconTextMenuItem(_(APPLY_TEXTURE_TEXT), APPLY_TEXTURE_ICON),
std::bind(&MediaBrowserTreeView::_onApplyToSel, this),
std::bind(&MediaBrowserTreeView::_testSingleTexSel, this)
);
popupMenu.addItem(
new wxutil::IconTextMenuItem(_(SHOW_SHADER_DEF_TEXT), SHOW_SHADER_DEF_ICON),
std::bind(&MediaBrowserTreeView::_onShowShaderDefinition, this),
std::bind(&MediaBrowserTreeView::_testSingleTexSel, this)
);
popupMenu.addItem(
new wxutil::IconTextMenuItem(_(SELECT_ITEMS), TEXTURE_ICON),
std::bind(&MediaBrowserTreeView::_onSelectItems, this, true),
std::bind(&MediaBrowserTreeView::_testSingleTexSel, this)
);
popupMenu.addItem(
new wxutil::IconTextMenuItem(_(DESELECT_ITEMS), TEXTURE_ICON),
std::bind(&MediaBrowserTreeView::_onSelectItems, this, false),
std::bind(&MediaBrowserTreeView::_testSingleTexSel, this)
);
ResourceTreeView::PopulateContextMenu(popupMenu);
}
void MediaBrowserTreeView::_onLoadInTexView()
{
// Use a TextureDirectoryLoader functor to search the directory. This
// may throw an exception if cancelled by user.
TextureDirectoryLoader loader(GetSelectedFullname());
try
{
GlobalMaterialManager().foreachShaderName(std::bind(&TextureDirectoryLoader::visit, &loader, std::placeholders::_1));
}
catch (wxutil::ModalProgressDialog::OperationAbortedException&)
{
// Ignore the error and return from the function normally
}
}
bool MediaBrowserTreeView::_testLoadInTexView()
{
// "Load in textures view" requires a directory selection
if (IsDirectorySelected())
return true;
else
return false;
}
void MediaBrowserTreeView::_onApplyToSel()
{
// Pass shader name to the selection system
GlobalCommandSystem().executeCommand("SetShaderOnSelection", GetSelectedFullname());
}
bool MediaBrowserTreeView::_testSingleTexSel()
{
return !IsDirectorySelected() && !GetSelectedFullname().empty();
}
void MediaBrowserTreeView::_onShowShaderDefinition()
{
std::string shaderName = GetSelectedFullname();
// Construct a shader view and pass the shader name
auto view = new MaterialDefinitionView(shaderName);
view->ShowModal();
view->Destroy();
}
void MediaBrowserTreeView::_onSelectItems(bool select)
{
std::string shaderName = GetSelectedFullname();
if (select)
{
GlobalCommandSystem().executeCommand("SelectItemsByShader", shaderName);
}
else
{
GlobalCommandSystem().executeCommand("DeselectItemsByShader", shaderName);
}
}
void MediaBrowserTreeView::_onTreeViewItemActivated(wxDataViewEvent& ev)
{
std::string selection = GetSelectedFullname();
if (!IsDirectorySelected() && !selection.empty())
{
// Pass shader name to the selection system
GlobalCommandSystem().executeCommand("SetShaderOnSelection", selection);
}
}
}