From d7dce19ad8da92eb5715467bc7fa9af2b97b25c2 Mon Sep 17 00:00:00 2001 From: greatYear Date: Sat, 22 Apr 2017 15:08:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81wiz=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + README.md | 46 ++-- plugin.ini | Bin 0 -> 846 bytes wizQuickSearch.ahk | 523 +++++++++++++++++++++++---------------------- 4 files changed, 292 insertions(+), 279 deletions(-) create mode 100644 .gitignore create mode 100644 plugin.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a6820e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode +dist \ No newline at end of file diff --git a/README.md b/README.md index 7b6f42c..a2519ac 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,29 @@ -# wiz 快速搜索插件 - -wiz(为知笔记)快速搜索插件,仅支持 windows。 - -![](示例图.jpg) - -## 使用说明 - -点击 `wizQuickSearch.exe` 启动后,使用按键 `#q`(win键 + Q键) 打开搜索框搜索(支持拼音首字母)。 - - 直接搜索文档标题+标签 - - `@` 搜索文件夹 - - `#` 搜索标签 - - `*` 使用 acc 搜索(将被移除) - -搜索框输入完成后: - - `Up`、`Down` 直接切换选中条目 - - `Left`、`Right` 直接输入框移动 - - `Enter` 打开选中的文档 +# wiz 快速搜索插件 + +wiz(为知笔记)快速搜索插件,仅支持 windows。 + +![](示例图.jpg) + +## 使用说明 + +### 安装 + +以插件形式安装:下载并安装 `wizQuickSearch.wizplugin`,然后在 wiz 菜单 `工具->wiz快速搜索` 点击启动。 + +也可直接下载源文件,放在独立目录,点击 `wizQuickSearch.exe` 启动。 + +注意:wiz 关闭后会自动退出,重新打开 wiz 也要重新启动本工具。 + +### 使用 + +启动后,使用按键 `#q`(win键 + Q键) 打开搜索框搜索(支持拼音首字母)。 + - 直接搜索文档标题+标签 + - `@` 搜索文件夹 + - `#` 搜索标签 + - `*` 使用 acc 搜索(将被移除) + +搜索框输入完成后: + - `Up`、`Down` 直接切换选中条目 + - `Left`、`Right` 直接输入框移动 + - `Enter` 打开选中的文档 - `Ctrl + Enter` 发送搜索到的列表到wiz \ No newline at end of file diff --git a/plugin.ini b/plugin.ini new file mode 100644 index 0000000000000000000000000000000000000000..7ceb3ae2335a8a280bfebbd30ac5c3db733ac1a1 GIT binary patch literal 846 zcmbV~-AV#c6ouDy&>I9n_lh&kIMam}VHsT%#aK5IgF04{shH9qzC-WnJ5=93VvRx> zaX51}d$0Ys)_lA-RMkNDoPqkf(xx_4!|o|lMrM&YCWy9f zUDm#aod4oe`6?;oyXZ7ax8Jt1ovBTr(6T{qQ{E_AE|@UOb2OQ2mvY#36h zK%EkHgcYc)7Pk3(_Ooc2NX#{?N1mrW7n|m`uIriIjiox=8G8@8=p~U6p04A#LWLq7 zZLb72jkN*su~u=u!<r`IG|E}69c2%{!!g+-^R?l0Oe|mh6T794W&i*H literal 0 HcmV?d00001 diff --git a/wizQuickSearch.ahk b/wizQuickSearch.ahk index 023d7ff..79cb32b 100644 --- a/wizQuickSearch.ahk +++ b/wizQuickSearch.ahk @@ -1,262 +1,263 @@ -; 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("lib\tcmatch.dll") -InitGui() -Menu, Tray, icon, %A_ScriptDir%\wizQuickSearch.ico - -WinWaitClose, ahk_exe Wiz.exe -ExitApp - -; 注册调用热键 -;#IfWinActive, ahk_class WizNoteMainFrame - ;^p:: - #q:: - ; 解决 wiz 重启后报错 - 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 - - 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 - -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 -} - -searchDoc(searchWord) { ; 搜索文档标题 - global searchBreak - - ; 判断搜索的类型 - gSearchType := "" - 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) - data := gSearchData[searchType] - break - } - } - - if (!gSearchType) { - gSearchType := "doc" - data := gDocs - } - - index := 1 - for i, info in data - { - displayTitle := info.displayTitle ? info.displayTitle : info.title - searchTitle := info.search ? info.search : displayTitle - if TCMatch(searchTitle, searchWord) - { - ; if (gSearchType != "doc") - LV_Add((index == 1 ? "Focus Select" : ""), displayTitle, info.tagText, i) - - index++ - gDocsFiltered.Push(info) - } - if searchBreak - break - } - - ; ; 提高 doc 搜索的精准度。 - ; if (gSearchType == "doc") { - ; docSorted := [] - ; docSorted2 := [] - ; For i, info in gDocsFiltered - ; { - ; if TCMatch(info.title, searchWord) - ; docSorted.Push(info) - ; else - ; docSorted2.Push(info) - ; } - - ; Array_concat(docSorted, docSorted2) - - ; gDocsFiltered := [] - ; For i, info in docSorted - ; { - ; LV_Add((i == 1 ? "Focus Select" : ""), info.title, info.tagText, i) - ; gDocsFiltered.Push(info) - ; 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 -#Include -#Include +; 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:: + ; 解决 wiz 重启后报错 + 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 + + 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 + +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 +} + +searchDoc(searchWord) { ; 搜索文档标题 + global searchBreak + + ; 判断搜索的类型 + gSearchType := "" + 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) + data := gSearchData[searchType] + break + } + } + + if (!gSearchType) { + gSearchType := "doc" + data := gDocs + } + + index := 1 + for i, info in data + { + displayTitle := info.displayTitle ? info.displayTitle : info.title + searchTitle := info.search ? info.search : displayTitle + if TCMatch(searchTitle, searchWord) + { + ; if (gSearchType != "doc") + LV_Add((index == 1 ? "Focus Select" : ""), displayTitle, info.tagText, i) + + index++ + gDocsFiltered.Push(info) + } + if searchBreak + break + } + + ; ; 提高 doc 搜索的精准度。 + ; if (gSearchType == "doc") { + ; docSorted := [] + ; docSorted2 := [] + ; For i, info in gDocsFiltered + ; { + ; if TCMatch(info.title, searchWord) + ; docSorted.Push(info) + ; else + ; docSorted2.Push(info) + ; } + + ; Array_concat(docSorted, docSorted2) + + ; gDocsFiltered := [] + ; For i, info in docSorted + ; { + ; LV_Add((i == 1 ? "Focus Select" : ""), info.title, info.tagText, i) + ; gDocsFiltered.Push(info) + ; 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 +#Include +#Include #Include \ No newline at end of file