Advertisement
congdantoancau

Explorer Navigator with domain

Nov 28th, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DEFAULT_LABEL := "D:"
  2.  
  3. transTopDomain(topLevel)
  4. {
  5.     if (topLevel == "src")
  6.         result := "Sources"
  7.     else if (topLevel == "rt" or topLevel == "r")
  8.         result := "" ; Default top
  9.     return result
  10. }
  11.  
  12. transDomain(sub, sec, top)
  13. {
  14.     if (sec != "")
  15.         res = %top%\%sec%\%sub%
  16.     else
  17.         res = %top%\%sub%
  18.     return res
  19. }
  20.  
  21. isDomainValid(domain)
  22. {
  23.     FoundPos := RegExMatch(domain, "\w+(\.\w+\.\w+)?") ; Accept even only top
  24.     if (FoundPos == 1)
  25.         return true
  26.     else
  27.         return false
  28.  
  29.     ;return true ; Set this always true for expandability of searching folder
  30. }
  31.  
  32. #IfWinActive, ahk_class CabinetWClass
  33.  
  34. ; Explorer Navigator
  35. ; Domain format: SubDomain.SecondLevelDomain.TopLevelDomain
  36.     $Enter::
  37.         ControlGetFocus, ctrl, ahk_class CabinetWClass
  38.        
  39.         if (ctrl != "Edit1")
  40.         {
  41.             Send, {enter}
  42.         }
  43.         else ;(ctrl == "Edit1")
  44.         {
  45.             ControlGetText, url, Edit1, ahk_class CabinetWClass
  46.             if RegExMatch(url, "\w:") ; D:\top\sec\sub0\sub1\sub2\...\subn
  47.                 Send, {Enter}
  48.             else ; sub.sec.top/class1/class2/.../classn
  49.             {
  50.                 /**
  51.                 * Todo: Split url to:
  52.                 * * domainArray: sub.sec.top
  53.                 * * domainSub: /class1/class2/.../classn
  54.                 */
  55.                 domArr := StrSplit(url, ".")
  56.                 urlPartition := domArr.MaxIndex()
  57.                
  58.                 if (urlPartition > 3)
  59.                     MsgBox, Invalid domain
  60.                 else if (urlPartition == 3)
  61.                 {
  62.                     ; Now domArr would like: sub | sec | top/sub1/sub2/subn
  63.                     ; We need to split top/sub1/sub2/subn it out to: [top][/sub1/sub2/subn]
  64.                     domSub := StrSplit(domArr[3], "/")
  65.                     subPartsSize := domSub.MaxIndex()
  66.                     if (subPartsSize > 0)
  67.                     {
  68.                         ; Now domSub would like: top (| sub1 | sub2 | subn)*
  69.                         domArr[3] := domSub[1]
  70.                         ; Now domArr would like: sub | sec | top
  71.                         domSub.Remove(1)
  72.                         ; Update subPartsSize
  73.                         subPartsSize := domSub.MaxIndex()
  74.                         ; Noew domSub would like: sub1 | sub2 | subn
  75.                         ; domSub may have none elements. It's ok
  76.                        
  77.                         Loop, %subPartsSize%
  78.                         {
  79.                             subPart .= domSub[A_Index] . "\"
  80.                         }
  81.                     }
  82.                    
  83.                     ; Done, the domain now is like sub.sec.top and subparts like: sub1/sub2/subn
  84.                     ; We need to translate them to Label:\top\sec\sub\sub1\sub2\subn
  85.                     ; First, translate top. Forturnally Only top need to be translate
  86.                     top := transTopDomain(domArr[3])
  87.                    
  88.                     sec := domArr[2]
  89.                     sub := domArr[1]
  90.                    
  91.                     url = %DEFAULT_LABEL%\%top%\%sec%\%sub%\%subPart%
  92.                     subPart := ""
  93.                 }
  94.                 else if (urlPartition == 2)
  95.                 {
  96.                     top := transTopDomain(domArr[2])
  97.                     sec := domArr[1]
  98.                     url = %DEFAULT_LABEL%\%top%\%sec%
  99.                 }
  100.                 else
  101.                 {
  102.                     url = %DEFAULT_LABEL%\%url%
  103.                 }
  104.                 ControlSetText, Edit1, %url%, ahk_class CabinetWClass
  105.                 Send {Enter}
  106.                 url := ""
  107.             }
  108.         }
  109.  
  110.     return
  111.    
  112. ; Explorer omnibox control
  113.     F6::
  114.         Send {F4}
  115.         Send ^a
  116.     return
  117.     F4::F4
  118.    
  119.     End::
  120.         ControlGetFocus, ctrl, ahk_class CabinetWClass
  121.         if (ctrl == "Edit1")
  122.             send ^{Right 10}
  123.         else
  124.             Send {end}
  125.     return
  126.     +End::
  127.         ControlGetFocus, ctrl, ahk_class CabinetWClass
  128.         if (ctrl == "Edit1")
  129.             send +{Right 255}
  130.         else
  131.             Send +{End}
  132.     return
  133.     Home::
  134.         ControlGetFocus, ctrl, ahk_class CabinetWClass
  135.         if (ctrl == "Edit1")
  136.             send ^{Left 10}
  137.         else
  138.             Send {Home}
  139.     return
  140.     +Home::
  141.         ControlGetFocus, ctrl, ahk_class CabinetWClass
  142.         if (ctrl == "Edit1")
  143.             send ^+{left 10}
  144.         else
  145.             Send +{home}
  146.     return
  147. #IfWinactive
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement