-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathLV_SpecialFunctions.ahk
478 lines (453 loc) · 12.3 KB
/
LV_SpecialFunctions.ahk
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
CompileList(Find, Criteria, Col, LV, ColumnList) {
/*
Find: What do you want to be in "Criteria" Column? (All means ALL)
Criteria: What Column do you want to find "Find"?
Col: What Column will do you want to build list of if "Find" is found?
LV: Which ListView? (Name)
ColumnList: ALWAYS ColumnList
*/
;~ Gui, 1: Default
Gui, ListView, %LV%
loop, parse, ColumnList, `|
{
if (A_Loopfield = Col)
;~ {
A := A_Index
;~ break
;~ }
;~ }
;~ loop, parse, ColumnList, `|
;~ {
if (A_Loopfield = Criteria)
;~ {
B := A_Index
;~ break
;~ }
}
;~ MsgBox, % Find . " / " . Criteria . " " . B . " / " . Col . " " . A . " / " . LV . " / " . ColumnList
NList=
RowNumber = 0
Gui, ListView, %LV%
Ttl := LV_GetCount()
Loop %Ttl%
{
LV_GetText(Text, A_Index, B)
;~ MsgBox, %Text%
if (Find = "NonBlank" and Text <> "")
Text := "NonBlank"
if (Text <> Find and Find <> "All" and Find <> "NONE")
Continue
if (Text = "" and Find = "NONE")
{
LV_GetText(Found, A_Index, A)
if (NList = "")
NList .= Found
else
NList .= "|" . Found
Continue
}
LV_GetText(Found, A_Index, A)
if (NList = "")
NList .= Found
else
NList .= "|" . Found
}
Sort, NList, D| U
;~ MsgBox, %NList%
Return NList
}
Search(ByRef SRow,SearchFor,Col,LV) {
;~ Returns Row Number according to parameters
;~ SRow: Starting row (if set to same variable as returned, can be made into a search loop)
;~ SearchFor: Criteria to be searched for (PCRE options and Wild cards supported, see https://autohotkey.com/docs/misc/RegEx-QuickRef.htm
;~ SearchFor syntax for finding label names is "A)[LabelName]-+")
;~ Col: Column NUMBER to be searched (Can be ALL)
;~ LV: Grid to be searched
StringReplace, SearchFor, SearchFor, `*, `., All
Gui, Listview, %LV%
Ttl := LV_GetCount()
TtlC := LV_GetCount("Column")
SearchLoop:
Loop
{
SRow +=1
if (SRow > Ttl)
Break, SearchLoop
if(Col = "All")
{
Loop, %TtlC%
{
LV_GetText(SText, SRow, A_Index)
;~ OLD WAY (no wildcard support)
;~ if (SText = SearchFor)
;~ Break, SearchLoop
FoundPos := RegExMatch(SText, SearchFor)
if FoundPos
Break, SearchLoop
}
}
else
{
LV_GetText(SText, SRow, Col)
;~ MsgBox, %SText% %SearchFor%
Clipboard := SearchFor
FoundPos := RegExMatch(SText, SearchFor)
if FoundPos
Break, SearchLoop
;~ OLD WAY (no wildcard support)
;~ if (SText = SearchFor)
;~ Break, SearchLoop
}
}
;~ if (SText <> SearchFor)
if not FoundPos
SRow := 0
Return SRow
}
DblSearch(Criteria, Column, Criteria2, Column2, LV) {
;~ Returns RowNumber that meets both Criteria explicitly, does not have support for wildcards yet.
;~ Criteria: Literal, complete phrase you want to find in %Column%
;~ Column: Literal, complete, NAME of column you want to search for %Criteria%
;~ Criteria2: Same as %Criteria% but in relation to %Column2%
;~ Column2: Same as %Column% but in relation to %Criteria2%
;~ LV: Which grid (ListView) you want to find results in
;~ ColumnList: Complete "|" Separated list of Column Names in %LV%
TtlC := LV_GetCount("Column")
Loop, %TtlC%
{
LV_GetText(Name, 0, A_Index)
If (Name = Column)
A := A_Index
else if (Name = Column2)
B := A_Index
if (A <> "" and B <> "")
Break
}
If (A = "" or B = "" or A = 0 or B = 0)
;~ Give better MsgBox when MsgBox app working
MsgBox, Column(s) not Found in %LV%!`n Parameters Given:`n`tColumn:`t%Column%`n`tColumn2:`t%Column2%
;~ OLD WAY OF ASSOCIATING COLUMN NAME WITH COLUMN NUMBER, Uses 6th Parameter (ColumnList)
;~ {
;~ loop, parse, ColumnList, `|
;~ {
;~ if (A_Loopfield = Column)
;~ {
;~ A := A_Index
;~ break
;~ }
;~ }
;~ loop, parse, ColumnList, `|
;~ {
;~ if (A_Loopfield = Column2)
;~ {
;~ B := A_Index
;~ break
;~ }
;~ }
;~ }
RowNumber = 0
Gui, ListView, %LV%
Ttl := LV_GetCount()
Loop %Ttl%
{
LV_GetText(Text, A_Index, A)
LV_GetText(Text2, A_Index, B)
if (Text = Criteria and Text2 = Criteria2)
Found := A_Index
}
;~ if (Found = "")
;~ Found := 0
Return Found
}
TripSearch(Criteria, Column, Criteria2, Column2, Criteria3, Column3, LV) {
;~ Returns RowNumber that meets both Criteria explicitly, does not have support for wildcards yet.
;~ Criteria: Literal, complete phrase you want to find in %Column%
;~ Column: Literal, complete, NAME of column you want to search for %Criteria%
;~ Criteria2: Same as %Criteria% but in relation to %Column2%
;~ Column2: Same as %Column% but in relation to %Criteria2%
;~ LV: Which grid (ListView) you want to find results in
;~ ColumnList: Complete "|" Separated list of Column Names in %LV%
TtlC := LV_GetCount("Column")
Loop, %TtlC%
{
LV_GetText(Name, 0, A_Index)
If (Name = Column)
A := A_Index
else if (Name = Column2)
B := A_Index
else if (Name = Column3)
C := A_Index
if (A <> "" and B <> "" and C <> "")
Break
}
If (A = "" or B = "" or A = 0 or B = 0 or C = "" or C = 0)
;~ Give better MsgBox when MsgBox app working
MsgBox, Column(s) not Found in %LV%!`n Parameters Given:`n`tColumn:`t%Column%`n`tColumn2:`t%Column2%n`tColumn3:`t%Column3%
;~ OLD WAY OF ASSOCIATING COLUMN NAME WITH COLUMN NUMBER, Uses 6th Parameter (ColumnList)
;~ {
;~ loop, parse, ColumnList, `|
;~ {
;~ if (A_Loopfield = Column)
;~ {
;~ A := A_Index
;~ break
;~ }
;~ }
;~ loop, parse, ColumnList, `|
;~ {
;~ if (A_Loopfield = Column2)
;~ {
;~ B := A_Index
;~ break
;~ }
;~ }
;~ }
RowNumber = 0
Gui, ListView, %LV%
Ttl := LV_GetCount()
Loop %Ttl%
{
LV_GetText(Text, A_Index, A)
LV_GetText(Text2, A_Index, B)
LV_GetText(Text3, A_Index, C)
if (Text = Criteria and Text2 = Criteria2 and Text3 = Criteria3)
Found := A_Index
}
;~ if (Found = "")
;~ Found := 0
Return Found
}
CleanArchive(Directory,ArNum) {
;~ Keeps the number of archived inventories below the value defined in the ini (Default is 100)
;~ See "Archived File Name Explanation.txt" in the archive folder for more info and how to change that value if so desired.
Files := ""
Loop %Directory%\*.csv
TtlA := A_Index
if (TtlA > ArNum)
{
TtlA -= ArNum
Loop %Directory%\*.csv
Files .= A_LoopFileLongPath . "|"
Sort, Files, D| \
Loop, parse, files, |
{
if (A_Index <= TtlA)
FileDelete, %A_Loopfield%
else
Break
}
}
return
}
GrabView(SelCols,LV,Issue) {
/*
Returns "," separated list from current view based on criteria WITH HEADERS, commas are ~
SelCols: Which Columns to grab, formatted 1|2|5|8
LV: Which Listview, "ScanGuiAdd", "Inventory", "OHInventory" or "TIInventory"
Issue: "YES" will only collect Checked Items, "NO" grabs all
*/
Grid := ""
Gui, 1: Default
Gui, ListView, %LV%
Ttl := LV_GetCount()
Ttl += 1
Loop, Parse, SelCols, |
TtlC := A_Index
RowNumber := 0
Loop, %Ttl%
{
if (Issue = "YES" and A_Index <> 1)
{
RowNumber := LV_GetNext(RowNumber, "Checked")
If Not RowNumber
Break
}
Loop, Parse, SelCols, | ;Parse through Selected Column Headers (SelCols)
{
LV_GetText(Text, RowNumber, A_Loopfield)
StringReplace, Text, Text, `,, `~, ALL
GridRow .= Text
if (A_Index <> TtlC)
GridRow .= "`,"
}
Grid .= GridRow
GridRow=
if (RowNumber <> Ttl)
Grid .= "`n"
if (Issue = "No")
RowNumber += 1
}
Return Grid
}
CompileItemLists(M,C,List) { ;(MasterIssueList,CompiledList,Desired Thing to be listed("SI"[Serialized Items] {or "ILM"[Issuable Location Models]} or "QI"[Quantified Items])
;~ C := "StartMe"
C := ""
Loop, parse, M, `n, `r
{
Loop, parse, A_Loopfield, csv
{
if (A_Index = 1)
I := A_Loopfield ;Item
if (A_Index = 4)
M := A_Loopfield ;Model
if (A_Index = 7)
S := A_Loopfield ;Serial Number
}
If(List = "SI")
{
if (S <> "" and I <> "Issuable Location")
C .= I . "`,"
;~ C .= "`n" . Item
}
/*
If (List = "ILM")
{
if (I = "Issuable Location")
C.Push(M)
;~ C .= "`n" . Item
}
*/
If (List = "QI")
{
if (S = "")
C .= I . "`,"
;~ C .= "`n" . Item
}
}
StringReplace, C, C, `n,,1
Sort, C, U D`,
Return C
}
CompileSerialLists(M,P,C,SLorQ) { ;(MasterIssueList, ParseList(ItemList), CompiledList, Serialized, Labeled or Quantified)
;~ XMLAddSerials DELETEME
Loop, Parse, P, csv
{
DI := A_Loopfield ;Desired Item
Loop, parse, M, `n, `r
{
If (A_Loopfield = "")
Break
Loop, parse, A_Loopfield, csv
{
if (A_Index = 1)
I := A_Loopfield ;Item
if (A_Index = 3)
L := A_Loopfield ;Label
if (A_Index = 4)
Mo := A_Loopfield ;Model
if (A_Index = 6)
Q := A_Loopfield ;Qty
if (A_Index = 7)
S := A_Loopfield ;Serial Number
}
If (I <> DI)
Continue
C .= "`n"
if (SLorQ = "S")
C .= I . "|" . L . "|" . S
if (SLorQ = "L")
C .= Mo . "|" . S
if (SLorQ = "Q")
{
if (S = "")
C .= I . "|" . Mo . "|" . Q
}
}
}
StringReplace, C, C, `n,
Sort, C
Return C
}
LV_SubitemHitTest(HLV) {
; https://autohotkey.com/board/topic/80265-solved-which-column-is-clicked-in-listview/
; To run this with AHK_Basic change all DllCall types "Ptr" to "UInt", please.
; HLV - ListView's HWND
/*
typedef struct _LVHITTESTINFO {
POINT pt;
UINT flags;
int iItem;
int iSubItem;
int iGroup;
} LVHITTESTINFO, *LPLVHITTESTINFO;
*/
Static LVM_SUBITEMHITTEST := 0x1039
VarSetCapacity(POINT, 8, 0)
; Get the current cursor position in screen coordinates
DllCall("User32.dll\GetCursorPos", "Ptr", &POINT)
; Convert them to client coordinates related to the ListView
DllCall("User32.dll\ScreenToClient", "Ptr", HLV, "Ptr", &POINT)
; Create a LVHITTESTINFO structure (see below)
VarSetCapacity(LVHITTESTINFO, 24, 0)
; Store the relative mouse coordinates
NumPut(NumGet(POINT, 0, "Int"), LVHITTESTINFO, 0, "Int")
NumPut(NumGet(POINT, 4, "Int"), LVHITTESTINFO, 4, "Int")
; Send a LVM_SUBITEMHITTEST to the ListView
SendMessage, LVM_SUBITEMHITTEST, 0, &LVHITTESTINFO, , ahk_id %HLV%
; If no item was found on this position, the return value is -1
If (ErrorLevel = -1)
Return 0
; Get the corresponding subitem (column)
Subitem := NumGet(LVHITTESTINFO, 16, "Int") + 1
Return Subitem
}
ActiveControlIsOfClass(Class) {
ControlGetFocus, FocusedControl, A
ControlGet, FocusedControlHwnd, Hwnd,, %FocusedControl%, A
WinGetClass, FocusedControlClass, ahk_id %FocusedControlHwnd%
return (FocusedControlClass=Class)
}
LetterArray(Begin,End) {
;~ Returns Array of letters at sequential index points, i.e. Columns[1] retrieves the first letter and so on
;~ Begin: First letter to Add to Array
;~ End: Last letter to add
;~ lowercase parameters ok
;~ reverse order letters ok (Means Array := LetterArray("c","a") returns, Array = [C,B,A])
;~ Only Handles A-Z right now will work later on AA and up
Min := Asc(upper(Begin))
Max := Asc(upper(End))
Reverse := "NO"
if (Min > Max)
{
Reverse := "Yes"
tmp := Min
Min := Max
Max := tmp
}
if Max not between 65 and 90
msgbox, Invalid parameters, Begin and End must only be single letters (in quotes if not using variables)
Count := Max - Min + 1
;~ MsgBox, %Count%
Letters := []
loop %Count%
{
AsciiCode := A_Index + Min - 1 ;ASCII code for "A" is 65 for reference
Letter := Chr(AsciiCode)
Letters.Push(Letter) ;adds letter to array with index = A_Index, so if Begin was "A" then Letters[1] = "A" and Letters[2] = "B"...
}
if (Reverse = "NO")
Return Letters
ReverseLetters := []
Index := Count
loop %Count%
{
Letter := Letters[Index]
ReverseLetters.Push(Letter)
Index -= 1
}
Return ReverseLetters
}
Upper(string) {
StringUpper, STRING, String
return STRING
}
hasValue(haystack, needle) {
if(!isObject(haystack))
return false
if(haystack.Length()==0)
return false
for k,v in haystack
if(v==needle)
return true
return false
}