快速定位函数|热键|标签的工具脚本

与AutoHotkey相关的工具

Moderators: tmplinshi, arcticir

ZeronoFreya
Posts: 16
Joined: 31 Jan 2015, 09:28

快速定位函数|热键|标签的工具脚本

03 Apr 2015, 23:07

转自http://ahk8.com/thread-5665-post-33301.html#pid33301
...嘛,虽然是我自己写的,姑且...
更新:2015-4-4
4.添加了中键弹出窗口
3.修改了标签名后不能有空格的bug,优化了函数名的判断
2.更改了正则,可以支持中文
1.使用^g的方式跳转,避免了调试中不能跳转的问题(但会闪现一个跳转窗口)
(如果无效,很可能是 跳至 ahk_class #32770这个多重条件判断不匹配你的跳转窗口名,请自行修改"跳至")

适用于Scite4AutoHotkey(最新版)
~~~没在老版测试是主要原因~~~
~~~也不保证原版可用~~~

Scite4AutoHotkey自带的TillaGoto.ahk有定位不准的BUG,
看了源码,嗯,不是咱新手能解读的......

参考了帮助文档及TillaGoto.ahk中的部分代码,盗用了GetSciTEInstance()函数...
...等等
花了一下午,挤了一个简单的出来.........
Image
热键添加了中键

Code: Select all

#NoEnv
 ;~ #NoTrayIcon
 #SingleInstance Ignore

 global fontColor        := "293134"            ;字体颜色
 ,groundColor     := "FFFFFF"            ;控件背景颜色
 ,CustomColor     := "000000"            ;Gui背景颜色
 ,GuiH            := 257                ;窗口高度

 oSciTE := GetSciTEInstance()        ;与Scite的com接口相关
 if !oSciTE
 {
     MsgBox, 16,, Cannot find SciTE!
     ExitApp
 }

 /*
 ┌──────────────┐
 ├────创建窗口
 └──────────────┘
 */

 Gui,+AlwaysOnTop +Owner +ToolWindow -caption
 Gui, Color, %CustomColor%
 Gui, font, s14, Microsoft YaHei Mono
 Gui, Add, Text, x-1 y-1 w222 h24 cFFFFFF +CEnter +Border gGuiMove,                    ;移动窗口位置
 Gui, Add, Text, x221 y-1 w90 h24 cFFFFFF +CEnter +Border gRefreshGui,Refresh        ;刷新
 Gui, Add, Text, x311 y-1 w35 h24 cFFFFFF +CEnter +Border gExpandGui vExpGui,▼        ;展开
 Gui, Add, Text, x346 y-1 w30 h24 cFFFFFF +CEnter +Border gCloseGui,╳                ;关闭窗口
 Gui, Font,c%fontColor% s12,Microsoft YaHei Mono                
 Gui, Add, TreeView,x0 y22 w375 h235 -HScroll gjumpChoose vMyTreeView Background%groundColor%
 GuiControl,Font, MyTreeView                ;更改TreeView字体样式
 return

 /*
 ┌───────────────────┐
 ├────显示窗口加载数据
 └───────────────────┘
 */
 ~MButton::
 #F::
 WinGetClass, class, A
 if class <> SciTEWindow
     return
 MouseGetPos, , , , control
 if control = SciTeTabCtrl1
     return

 RefreshGui:

     AllText := oSciTE.Document
     TV_Delete()
     P1 := TV_Add("标签",,"Bold")
     P2 := TV_Add("函数",,"Bold")
     P3 := TV_Add("热键",,"Bold")
     GuiControl, -Redraw, MyTreeView
     Loop, Parse, AllText, `n, `r
     {
         if functionName                     ;functionName初始为空,当找到函数名时,赋值;继续匹配下一行,若为"{",则
         {                                     ;    functionName为函数体,添加此次循环的(A_index-1)及函数名到TreeView
             if A_LoopField = {
                 TV_Add(A_Index-1 . "__" . functionName,P2)
                 functionName := ""
                 continue
         }
         if RegExMatch(A_LoopField ,"S)^[^;]*[^:]:\s*?$")                    ;匹配    Label:
             TV_Add(A_Index . "__" . A_LoopField,P1)
         else if RegExMatch(A_LoopField ,"S)^[^;!=,]*\(.*\)\s*?$")        ;匹配    function()
         {                                                        ;        {
             ;~ functionName := A_LoopField                            ;            }
             functionName := RegExReplace(A_LoopField, "\(.*\)\s*?$", "()")        ;省略参数的显示
             continue
         }
         else if RegExMatch(A_LoopField ,"S)^[^;]*\(.*\)\s*?{$")    ;匹配    function() {
         {
             noParam := RegExReplace(A_LoopField, "\(.*\)", "()")        ;省略参数的显示
             TV_Add(A_Index . "__" . noParam,P2)
         }
         else if RegExMatch(A_LoopField ,"S)^[^;]*::")            ;匹配    Hotkey::
         {
             hotKeyText := RegExReplace(A_LoopField, "::.*", "::")    
             TV_Add(A_Index . "__" . hotKeyText,P3)
         }
     }
     GuiControl, +Redraw, MyTreeView
     ;~ TV_Modify(P1,"Expand")
     AllText := ""
     ControlGetPos,, y, w,, Scintilla1, ahk_class SciTEWindow
     gX := w-375-20
     Gui, Show,x%gX% y%y% w375 h%GuiH%, myFunction
 return

 /*
 ┌────────────┐
 ├────跳转
 └────────────┘
 */

 jumpChoose:
 if !TV_GetParent(A_EventInfo)
 {
     TV_Modify(itemId,"-Expand")
     if TV_Get(A_EventInfo, "Expand")
         TV_Modify(A_EventInfo,"-Expand")
     else TV_Modify(A_EventInfo,"Expand")
     itemId := A_EventInfo
 }


     if A_GuiEvent <> DoubleClick
         return
     TV_GetText(OutputText, A_EventInfo)
     if OutputText in 标签,函数,热键
         return
     OutputText := RegExReplace(OutputText, "\_.*")

 ControlSend , , ^g, ahk_class SciTEWindow
 WinWait , 跳至 ahk_class #32770
 ControlSetText , Edit1, %OutputText%,  跳至 ahk_class #32770
 Sleep,200
 ControlSend , , {Enter}, 跳至 ahk_class #32770
     Sleep,200
     Gui, Cancel
 return


 GuiMove:
     PostMessage, 0xA1, 2,,, A
 return

 /*
 ┌────────────┐
 ├────展开Gui
 └────────────┘
 */

 ExpandGui:

     if !isExpand
     {
         isExpand = 1
         ControlGetPos,,,, h, Scintilla1, ahk_class SciTEWindow
         GuiH := h-30
         GuiControl, Move, MyTreeView, % "h" GuiH-22
         Gui, Show,h%GuiH%, myFunction
         GuiControl,,ExpGui,▲
     }
     else
     {
         isExpand = 0
         GuiControl, Move, MyTreeView, h235
         GuiH := 257
         Gui, Show,h%GuiH%, myFunction
         GuiControl,,ExpGui,▼
     }
 return

 CloseGui:
     Gui, Cancel
 return

 GetSciTEInstance()
 {
     olderr := ComObjError()
     ComObjError(false)
     scite := ComObjActive("{D7334085-22FB-416E-B398-B5038A5A0784}")
     ComObjError(olderr)
     return IsObject(scite) ? scite : ""
 }
gotoFunction.zip
(1.97 KiB) Downloaded 634 times
Autohotkey2

Return to “相关工具”

Who is online

Users browsing this forum: No registered users and 19 guests