-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI-BrowseDialog.cpp
174 lines (143 loc) · 5.12 KB
/
GUI-BrowseDialog.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "GUI-BrowseDialog.h"
#include "GUI-ChatMain.h"
#include "MessageCore.h"
#include "BValue.h"
#include "RainSandboxApp.h"
#include "ManifestManager.h"
#include "ManifestService.h"
using namespace RAIN;
using namespace RAIN::GUI;
extern RAIN::MessageCore *globalMessageCore;
BEGIN_EVENT_TABLE(RAIN::GUI::BrowseDialog, wxDialog)
EVT_TREE_SEL_CHANGED(ID_GBD_TREE, RAIN::GUI::BrowseDialog::OnSelect)
EVT_BUTTON(ID_GBD_OK, RAIN::GUI::BrowseDialog::OnOk)
EVT_BUTTON(ID_GBD_CANCEL, RAIN::GUI::BrowseDialog::OnCancel)
END_EVENT_TABLE()
enum
{
IM_IDX_RAINROOT,
IM_IDX_FOLDER
};
/** browsedialog is a windows-esque directory browser which instead browses the mesh
* content. this is always used as a modal dialog! */
BrowseDialog::BrowseDialog(wxWindow* parent)
: wxDialog(parent, -1, wxT("Browse Virtual Drive"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxTHICK_FRAME)
{
HelpLabel = new wxStaticText(this, -1, wxT("<instruction text here>"));
Tree = new wxTreeCtrl(this, ID_GBD_TREE, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS|wxSUNKEN_BORDER);
CurrentPath = new wxTextCtrl(this, -1, wxT(""));
Spacer = new wxPanel(this, -1);
CancelButton = new wxButton(this, ID_GBD_CANCEL, wxT("&Cancel"));
OkButton = new wxButton(this, ID_GBD_OK, wxT("&OK"));
set_properties();
do_layout();
wxImageList *im = new wxImageList(16, 16);
im->Add(wxBitmap("IDB_RAINROOT", wxBITMAP_TYPE_BMP_RESOURCE), wxColour(0xFF, 0x00, 0xFF));
#ifdef __WXMSW__
im->Add(wxIcon(wxIconLocation("shell32.dll", 3)));
#endif//__WXMSW__
this->Tree->AssignImageList(im);
wxTreeItemId root = this->Tree->AddRoot("Virtual Drive", IM_IDX_RAINROOT);
this->FillTree(root);
this->Tree->Expand(root);
}
void BrowseDialog::set_properties()
{
SetTitle(wxT("Browse Virtual Drive"));
OkButton->SetDefault();
}
void BrowseDialog::do_layout()
{
wxBoxSizer* MainSizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
MainSizer->Add(HelpLabel, 0, wxLEFT|wxRIGHT|wxTOP|wxFIXED_MINSIZE, 10);
MainSizer->Add(Tree, 1, wxLEFT|wxRIGHT|wxTOP|wxEXPAND, 10);
MainSizer->Add(CurrentPath, 0, wxLEFT|wxRIGHT|wxTOP|wxEXPAND|wxFIXED_MINSIZE, 10);
ButtonSizer->Add(Spacer, 1, wxEXPAND, 0);
ButtonSizer->Add(CancelButton, 0, wxLEFT|wxTOP|wxBOTTOM|wxFIXED_MINSIZE, 10);
ButtonSizer->Add(OkButton, 0, wxALL|wxFIXED_MINSIZE, 10);
MainSizer->Add(ButtonSizer, 0, wxEXPAND, 0);
SetAutoLayout(true);
SetSizer(MainSizer);
MainSizer->Fit(this);
MainSizer->SetSizeHints(this);
Layout();
this->SetSize(this->GetSize().x * 1.5, this->GetSize().y * 1.5);
}
/** empties the treectrl, then refills it using the manifests it gets from the
* manifestmanager */
void BrowseDialog::FillTree(const wxTreeItemId& root)
{
std::vector<ManifestEntry *> entries;
globalMessageCore->app->manifest->GetAllManifests(entries);
this->Tree->DeleteChildren(root);
for (size_t i = 0; i < entries.size(); i++)
{
BENC_SAFE_CAST(entries[i]->getFiles()->getDictValue("names"), filenames, List);
for (size_t n = 0; n < filenames->getListSize(); n++)
{
BENC_SAFE_CAST(filenames->getListItem(n), listitem, String);
wxString filename = listitem->getString();
wxStringTokenizer tok(filename, "/");
wxTreeItemId currentNode, parentNode = root;
while (tok.HasMoreTokens())
{
wxString token = tok.GetNextToken();
if (token.Length() == 0)
continue;
if (currentNode.IsOk())
parentNode = currentNode;
currentNode = this->GetNodesChild(parentNode, token);
if (!currentNode.IsOk() && tok.HasMoreTokens())
currentNode = this->Tree->InsertItem(parentNode, 0, token, IM_IDX_FOLDER);
}
}
}
while (entries.size() > 0)
{
delete entries[0];
entries.erase(entries.begin());
}
}
/** iterates through <b>node</b>'s children, attempting to match against <b>name</b>
* returns the wxTreeItemId of the found node, or an invalid wxTreeItemId otherwise */
wxTreeItemId BrowseDialog::GetNodesChild(const wxTreeItemId& node, const wxString& name)
{
wxTreeItemIdValue cookie;
wxTreeItemId my = this->Tree->GetFirstChild(node, cookie);
while (my.IsOk())
{
if (this->Tree->GetItemText(my) == name)
return my;
my = this->Tree->GetNextChild(node, cookie);
}
return my;
}
/** single left click handler for the treectrl - decends the tree and builds a pathname
* into CurrentPath */
void BrowseDialog::OnSelect(wxTreeEvent &e)
{
if (e.GetItem() == this->Tree->GetRootItem())
{
this->CurrentPath->SetValue("/");
return;
}
this->CurrentPath->SetValue("");
wxTreeItemId id = e.GetItem();
while (id != this->Tree->GetRootItem())
{
this->CurrentPath->SetValue("/" + this->Tree->GetItemText(id) + this->CurrentPath->GetValue());
id = this->Tree->GetItemParent(id);
}
this->CurrentPath->SetValue(this->CurrentPath->GetValue() + "/" );
}
/** click handler for ok button */
void BrowseDialog::OnOk(wxCommandEvent &e)
{
this->EndModal(true);
}
/** click handler for cancel button */
void BrowseDialog::OnCancel(wxCommandEvent &e)
{
this->EndModal(false);
}