Advertisement
Tark_Wight

FileMaker skript for AHK

Jun 5th, 2025 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.32 KB | Source Code | 0 0
  1. ; AutoHotkey v2
  2.  
  3. global lastC := 0
  4. global lastX := 0
  5. global clickTimerC := false
  6. global clickTimerX := false
  7.  
  8. GetActivePath() {
  9.     hwnd := WinActive("A")
  10.     for window in ComObject("Shell.Application").Windows {
  11.         try {
  12.             if (window.HWND == hwnd)
  13.                 return window.Document.Folder.Self.Path
  14.         } catch {
  15.             continue
  16.         }
  17.     }
  18.     return ""
  19. }
  20.  
  21. AskFileName(ext) {
  22.     input := InputBox("Введите имя файла (без расширения):", "Создание " . ext)
  23.     if input.Result = "Cancel"
  24.         return ""
  25.     return input.Value != "" ? input.Value : "file"
  26. }
  27.  
  28. CreateFile(path, filename) {
  29.     full := path "\" filename
  30.    if FileExist(full) {
  31.        TrayTip "Уведомление", "Файл уже существует: " filename, 2
  32.        return
  33.    }
  34.  
  35.    dotPos := InStr(filename, ".", , -1)
  36.    ext := SubStr(filename, dotPos + 1)
  37.    name := SubStr(filename, 1, dotPos - 1)
  38.  
  39.    content := ""
  40.  
  41.    if ext = "h" || ext = "hpp" {
  42.        guard := RegExReplace(name, "\W", "_")
  43.        guard := StrUpper(guard) . "_" . StrUpper(ext)
  44.  
  45.        content := "#ifndef " . guard . "`n"
  46.         content .= "#define " . guard . "`n`n"
  47.         content .= "`n"
  48.        content .= "#endif // " . guard . "`n"
  49.     }
  50.  
  51.     FileAppend(content, full)
  52.     TrayTip "Создан файл", filename, 2
  53. }
  54.  
  55. ; --- Стандартные ---
  56. #!t:: {
  57.     path := GetActivePath()
  58.     if path != "" {
  59.         name := AskFileName("txt")
  60.         if name != ""
  61.             CreateFile(path, name . ".txt")
  62.     }
  63. }
  64.  
  65. #!s:: {
  66.     path := GetActivePath()
  67.     if path != "" {
  68.         name := AskFileName("swift")
  69.         if name != ""
  70.             CreateFile(path, name . ".swift")
  71.     }
  72. }
  73.  
  74. ; --- Ctrl + Alt + C: одиночное → .c, двойное → .h ---
  75. #!c:: {
  76.     global lastC, clickTimerC
  77.     now := A_TickCount
  78.  
  79.     if (now - lastC < 400) {
  80.         clickTimerC := false
  81.         path := GetActivePath()
  82.         if path != "" {
  83.             name := AskFileName("h")
  84.             if name != ""
  85.                 CreateFile(path, name . ".h")
  86.         }
  87.     } else {
  88.         lastC := now
  89.         clickTimerC := true
  90.         SetTimer(() => HandleSingleC(), -400)
  91.     }
  92. }
  93.  
  94. HandleSingleC() {
  95.     global clickTimerC
  96.     if clickTimerC {
  97.         path := GetActivePath()
  98.         if path != "" {
  99.             name := AskFileName("c")
  100.             if name != ""
  101.                 CreateFile(path, name . ".c")
  102.         }
  103.     }
  104.     clickTimerC := false
  105. }
  106.  
  107. ; --- Ctrl + Alt + X: одиночное → .cpp, двойное → .hpp ---
  108. #!x:: {
  109.     global lastX, clickTimerX
  110.     now := A_TickCount
  111.  
  112.     if (now - lastX < 400) {
  113.         clickTimerX := false
  114.         path := GetActivePath()
  115.         if path != "" {
  116.             name := AskFileName("hpp")
  117.             if name != ""
  118.                 CreateFile(path, name . ".hpp")
  119.         }
  120.     } else {
  121.         lastX := now
  122.         clickTimerX := true
  123.         SetTimer(() => HandleSingleX(), -400)
  124.     }
  125. }
  126.  
  127. HandleSingleX() {
  128.     global clickTimerX
  129.     if clickTimerX {
  130.         path := GetActivePath()
  131.         if path != "" {
  132.             name := AskFileName("cpp")
  133.             if name != ""
  134.                 CreateFile(path, name . ".cpp")
  135.         }
  136.     }
  137.     clickTimerX := false
  138. }
  139.  
Tags: ahk
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement