forked from JasonGoemaat/CheatEngineMonoHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formSearch.lua
145 lines (124 loc) · 4.56 KB
/
formSearch.lua
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
--[[
Form for searching an image.
Controls:
pageMain.tabSearch - main tab
editSearchText: TCEEdit
listSearchClasses: TCEListView
listSearchFields: TCEListView
listSearchMethods: TCEListView
miImage: TMenuItem - main menu Image entry
miImageSelectImage - entry to re-open select image form
--]]
mono.formSearch.found = mono.formSearch.found or {}
mono.formSearch.found.classes = mono.formSearch.found.classes or {}
mono.formSearch.found.fields = mono.formSearch.found.fields or {}
mono.formSearch.found.methods = mono.formSearch.found.methods or {}
--[[
Show the search form, mono.selectedImage should be set to the
image to search.
--]]
function mono.formSearch:show()
if mono.selectedImage == nil then return end
self.image = mono.selectedImage
-- setup event handlers
formMonoSearch.miImageSelectImage.OnClick = function(sender) self:SelectImageClick() end
formMonoSearch.listSearchClasses.OnData = function(sender, listitem)
self:listSearchClasses_OnData(sender, listitem)
end
formMonoSearch.listSearchClasses.OnDblClick = function(sender)
local class = self.found.classes[sender.ItemIndex + 1]
mono.formClass:show(class, nil, nil)
end
formMonoSearch.listSearchFields.OnData = function(sender, listitem)
self:listSearchFields_OnData(sender, listitem)
end
formMonoSearch.listSearchFields.OnDblClick = function(sender)
local field = self.found.fields[sender.ItemIndex + 1]
if field then
mono.formClass:show(field.class, field, nil)
end
end
formMonoSearch.listSearchMethods.OnData = function(sender, listitem)
self:listSearchMethods_OnData(sender, listitem)
end
formMonoSearch.listSearchMethods.OnDblClick = function(sender)
local method = self.found.methods[sender.ItemIndex + 1]
if method then
mono.formClass:show(method.class, nil, method)
end
end
formMonoSearch.editSearchText.OnChange = function(sender)
self:search(sender.text)
end
-- popups
formMonoSearch.listSearchClasses.PopupMenu = formMonoSearch.popupClasses
local count = 0
formMonoSearch.popupClasses.OnPopup = function(sender)
print('formMonoSearch.popupClasses.OnPopup "'..tostring(sender.name)..'" count '..tostring(count))
count = count + 1
end
-- perform initial search to set 'found' results, probably empty text
self:search(formMonoSearch.editSearchText.Text)
-- show form
formMonoSearch.show()
end
--[[
When menu item to select an image is clicked, hide this form and
show the image select form
--]]
function mono.formSearch:SelectImageClick()
formMonoSearch.close()
mono.formSelectImage:show()
end
--[[
When typing in the edit box to filter results, filter the lists of
classes, fields, and methods with the lower case of the text
--]]
function mono.formSearch:search(text)
local lower = nil
if text ~= nil then lower = text:lower() end
local classes = {}
local methods = {}
local fields = {}
for i,class in ipairs(self.image.classes) do
if lower == nil or class.lowerName:find(lower, 1, true) ~= nil then table.insert(classes, class) end
for j,method in ipairs(class.methods) do
if lower == nil or method.lowerName:find(lower, 1, true) ~= nil then table.insert(methods, method) end
end
for j,field in ipairs(class.fields) do
if lower == nil or field.lowerName:find(lower, 1, true) ~= nil then table.insert(fields, field) end
end
end
self.found.classes = classes
self.found.fields = fields
self.found.methods = methods
formMonoSearch.listSearchClasses.Items.Count = #classes
formMonoSearch.listSearchFields.Items.Count = #fields
formMonoSearch.listSearchMethods.Items.Count = #methods
end
-- handler to display classes in list view
function mono.formSearch:listSearchClasses_OnData(sender, listitem)
local index = listitem.Index + 1
local class = self.found.classes[index]
listitem.Caption = class.name
end
-- handler to display fields in list view
function mono.formSearch:listSearchFields_OnData(sender, listitem)
local field = self.found.fields[listitem.Index + 1]
if field == nil then
listitem.Caption = 'nil index '..tostring(index)
else
listitem.Caption = field.name
listitem.SubItems.text = field.class.name
end
end
-- handler to display methods in list view
function mono.formSearch:listSearchMethods_OnData(sender, listitem)
local method = self.found.methods[listitem.Index + 1]
if method == nil then
listitem.Caption = 'nil index '..tostring(index)
else
listitem.Caption = method.name
listitem.SubItems.text = method.class.name
end
end