-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchWindow.cpp
104 lines (78 loc) · 2.86 KB
/
SearchWindow.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
#include "MobiView.h"
SearchWindow::SearchWindow()
{
CtrlLayout(*this, "MobiView search");
Sizeable();
SearchField.WhenAction = THISBACK(Find);
ResultField.AddColumn("Name");
ResultField.AddColumn("Group");
ResultField.WhenSel = THISBACK(SelectItem);
}
void SearchWindow::Find()
{
void *DataSet = ParentWindow->DataSet;
model_dll_interface &ModelDll = ParentWindow->ModelDll;
if(ModelDll.IsLoaded() && DataSet)
{
//NOTE: For some reason the callback is called by ResultField.Clear() below, causing a crash unless we remove the callback and re-add it later.
ResultField.WhenSel.Clear();
ResultField.Clear();
String Match = SearchField.GetData();
std::string MatchText = Match.ToStd();
std::transform(MatchText.begin(), MatchText.end(), MatchText.begin(), ::tolower); //TODO: trim leading whitespace
uint64 GroupCount = ModelDll.GetAllParameterGroupsCount(DataSet, "__all!!__");
std::vector<char *> GroupNames(GroupCount);
ModelDll.GetAllParameterGroups(DataSet, GroupNames.data(), "__all!!__");
for(int Idx = 0; Idx < GroupCount; ++Idx)
{
char *GroupName = GroupNames[Idx];
uint64 ParCount = ModelDll.GetAllParametersCount(DataSet, GroupName);
std::vector<char *> ParNames(ParCount);
std::vector<char *> ParTypes(ParCount);
ModelDll.GetAllParameters(DataSet, ParNames.data(), ParTypes.data(), GroupName);
for(int Par = 0; Par < ParCount; ++Par)
{
//TODO: Better matching algorithm?
std::string ParName = ParNames[Par];
std::transform(ParName.begin(), ParName.end(), ParName.begin(), ::tolower);
size_t Pos = ParName.find(MatchText);
if(Pos != std::string::npos)
{
ResultField.Add(ParNames[Par], GroupName);
}
}
}
ResultField.WhenSel = THISBACK(SelectItem);
ParentWindow->CheckDllUserError();
}
}
void SearchWindow::SelectItem()
{
String SelectedParameterName = ResultField.Get(0);
String SelectedGroupName = ResultField.Get(1);
TreeCtrl &GroupSelect = ParentWindow->ParameterGroupSelecter;
uint64 Count = GroupSelect.GetLineCount(); //TODO: This is not ideal since it may not work if somebody collapses a branch!!
for(int Row = 1; Row < Count; ++Row) //NOTE: Start at 1 since Row 0 is the name of the model. Causes problems when model name is the same as one of the groups
{
String CurName = GroupSelect.Get(Row);
if(CurName == SelectedGroupName) //TODO: This may break if a module is named the same thing as a parameter group.
{
//GroupSelect.ClearSelection(true);
GroupSelect.SetFocus();
GroupSelect.SetCursor(Row);
break;
}
}
ArrayCtrl &ParameterSelect = ParentWindow->Params.ParameterView;
Count = ParameterSelect.GetCount();
for(int Row = 0; Row < Count; ++Row)
{
String CurName = ParameterSelect.Get(Row, 0);
if(CurName == SelectedParameterName)
{
ParameterSelect.SetFocus();
ParameterSelect.SetCursor(Row);
break;
}
}
}