-
Notifications
You must be signed in to change notification settings - Fork 3
/
wizQuickSearch.ahk
275 lines (224 loc) · 5.99 KB
/
wizQuickSearch.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
; wiz 快速搜索,支持拼音首字母
global gConfig := {}
gConfig.closeAfterOpen := false
; 常量
global WIN_ME_TITLE := "wiz 快捷搜索"
global WIN_WIZ_TITLE := "ahk_class WizNoteMainFrame"
; 变量
MyListView :=
global gDocs := []
global gSearchType := "doc"
global gSearchKeys := { tag: "#", folder: "@", acc: "*" }
global gSearchData := {} ; 缓存
clearSearchData()
; TODO
global gDocsFiltered := []
; 运行
global wiz := new Wiz()
global wizAcc := new WizAcc()
TCMatchOn(A_ScriptDir "\lib\tcmatch.dll")
InitGui()
Menu, Tray, icon, %A_ScriptDir%\wizQuickSearch.ico
WinWaitClose, ahk_exe Wiz.exe
ExitApp
; 注册调用热键
;#IfWinActive, ahk_class WizNoteMainFrame
;^p::
#q::
try {
gDocs := wiz.getAllDocs(0)
} catch e {
msgbox 请重新启动
ExitApp
}
Gui, Show, xCenter yCenter, % WIN_ME_TITLE
GuiControl, Focus, Edit1
GuiControl, , Edit1,
;SwitchIME2()
return
; #IfWinActive
InitGui() {
WIDTH := 550
Gui, Add, Edit, r1 w%WIDTH% gSearchChange
Gui, Add, ListView, xm r20 w%WIDTH% vMyListView gMyListView, 标题|标签|docIndex
Gui, Add, Button, Hidden Default w0 h0, OK
GUi, Add, StatusBar, ,
COLUMN1_WIDTH := 360
LV_ModifyCol(1, COLUMN1_WIDTH)
LV_ModifyCol(2, WIDTH - COLUMN1_WIDTH - 21)
LV_ModifyCol(3, 0)
Hotkey, IfWinActive, % WIN_ME_TITLE
Hotkey, ~up, FocusListView
Hotkey, ~down, FocusListView
Hotkey, ~left, FocusEdit
Hotkey, ~right, FocusEdit
Hotkey, ~BS, FocusEdit
Hotkey, ^enter, SendDocuments
Hotkey, IfWinActive
}
GuiEscape:
GuiClose:
Gui, Cancel
clearSearchData()
return
clearSearchData() {
gSearchData := { tag: [], folder: [], acc: [] }
}
FocusListView:
GuiControl, Focus, MyListView
return
FocusEdit:
GuiControl, Focus, Edit1
return
SendDocuments:
sendDocuments()
return
;~ #if NotFocusListView()
;~ ~up::
;~ ~down::
;~ GuiControl, Focus, MyListView
;~ return
;~ #if
;~ NotFocusListView() {
;~ IfWinActive, % A_ScriptName
;~ {
;~ ControlGetFocus, FocusedControl, A
;~ if FocusedControl <> MyListView
;~ return true
;~ }
;~ return false
;~ }
SearchChange:
searchBreak := True
SetTimer, SearchBreakSub, -200
return
SearchBreakSub:
GuiControlGet, searchWord, , Edit1
LV_Delete()
searchBreak := False
gDocsFiltered := []
searchDoc(searchWord)
return
MyListView:
if A_GuiEvent = DoubleClick
{
openSelectedDoc(A_EventInfo)
}
return
ButtonOK:
Gosub, FocusListView
rowNum := LV_GetNext(0, "Focused")
openSelectedDoc(rowNum)
return
SetStatusBar() {
size := gDocsFiltered.Length()
SB_SetText("共找到 " . size . " 条")
}
getData(type) {
if (type == "tag") {
data := wiz.getAllTags()
} else if (type == "acc") {
data := wizAcc.getLeftTreeItems()
} else if (type == "folder") {
data := wiz.getFolders()
} else {
data := wiz.getAllDocs(0)
}
return data
}
; 用于去除重复
global gFilteredGuids := {}
searchDoc(searchWord) { ; 搜索文档标题
global searchBreak
; 判断搜索的类型
gSearchType := ""
allItems := []
for searchType, searchKey in gSearchKeys
{
if (searchKey and InStr(searchWord, searchKey) == 1) {
gSearchType := searchType
searchWord := LTrim(searchWord, searchKey)
if not gSearchData[searchType].Length()
gSearchData[searchType] := getData(searchType)
allItems := gSearchData[searchType]
break
}
}
if (!gSearchType) {
gSearchType := "doc"
allItems := gDocs
}
; 重置 cache
gFilteredGuids := {}
; 如果是 doc 类型,先搜索标题
addSearchResult(allItems, searchWord)
; 如果是 doc 类型,再搜索 tag
if (gSearchType == "doc") {
addSearchResult(allItems, searchWord, true)
}
; TODO total 不准确,有延迟
SetStatusBar()
}
addSearchResult(allItems, searchWord, isSearchTag:=False) {
global searchBreak
index := isSearchTag ? 100 : 1
for i, info in allItems
{
if (gFilteredGuids[info.guid]) {
continue
}
displayTitle := info.displayTitle ? info.displayTitle : info.title
if (isSearchTag) {
searchTitle := info.tagText ? info.tagText : displayTitle
} else {
searchTitle := info.search ? info.search : displayTitle
}
if TCMatch(searchTitle, searchWord)
{
LV_Add((index == 1 ? "Focus Select" : ""), displayTitle, info.tagText, i)
index++
gDocsFiltered.Push(info)
gFilteredGuids[info.guid] := True
}
if searchBreak
break
}
}
openSelectedDoc(rowNum) {
if (rowNum == 0) {
return
}
LV_GetText(index, rowNum, 3)
data := gSearchData[gSearchType]
if (gSearchType == "doc") {
doc := gDocsFiltered[rowNum]
wiz.openDoc(doc.guid)
} else if (gSearchType == "tag") {
wiz.openTag(data[index])
}else if (gSearchType == "folder") {
wiz.openFolder(data[index])
} else if (gSearchType == "acc") {
wizAcc.clickSelected(data[index])
}
WinActivate, % WIN_WIZ_TITLE
if (gConfig.closeAfterOpen)
Gui, Cancel
}
sendDocuments() {
if (gSearchType == "doc") {
if (gDocsFiltered.Length())
wiz.sendDocuments(gDocsFiltered)
else
wiz.newDocument()
WinActivate, % WIN_WIZ_TITLE
}
}
searchOther() { ; 搜索文件夹、标签
}
clearTip:
ToolTip
return
#Include <Utils>
#Include <wizLib>
#Include <wizAcc>
#Include <tcmatch>