-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoraAutoPrompt.ahk
More file actions
344 lines (275 loc) · 10.3 KB
/
Copy pathVoraAutoPrompt.ahk
File metadata and controls
344 lines (275 loc) · 10.3 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
; AutoHotkey v2 Script
#Requires AutoHotkey v2.0
VORA_PATH := "D:\vora"
; ==============================================================================
; Backtick / Tilde Key (*SC029): تولید ساختار درختی فایلهای tracked گیت
; ==============================================================================
*SC029:: {
ShowCustomToolTip("Generating Git File Tree...")
tempFile := A_Temp . "\git_tree_temp.txt"
if FileExist(tempFile)
FileDelete(tempFile)
execCmd := 'cmd.exe /c "cd /d "' . VORA_PATH . '" && git ls-files > "' . tempFile . '""'
RunWait(execCmd, , "Hide")
if (!FileExist(tempFile)) {
ShowCustomToolTip("Failed to execute Git command!")
return
}
rawGitOutput := FileRead(tempFile, "UTF-8")
FileDelete(tempFile)
if (Trim(rawGitOutput) = "") {
ShowCustomToolTip("Git directory empty or not a git repository!")
return
}
treeOutput := BuildTreeFromGitList(rawGitOutput)
previousClipboard := A_Clipboard
A_Clipboard := treeOutput
Sleep(50)
Send("^v")
Sleep(150)
A_Clipboard := previousClipboard
ShowCustomToolTip("Git File Tree Pasted!")
}
; ==============================================================================
; F2: خواندن نام فایلها، استخراج کد و ساخت پرامپت یکپارچه
; ==============================================================================
F2:: {
Send("^a")
Sleep(100)
Send("^c")
Sleep(150)
rawInput := Trim(A_Clipboard)
if (rawInput = "") {
ShowCustomToolTip("Text box is empty!")
return
}
fileEntries := StrSplit(rawInput, ["`r`n", "`n", "`r"])
targets := []
for item in fileEntries {
cleaned := Trim(item)
if (cleaned != "") {
targets.Push(cleaned)
}
}
if (targets.Length = 0) {
ShowCustomToolTip("No valid filenames provided!")
return
}
resolvedFiles := []
for index, inputQuery in targets {
normalizedQuery := StrReplace(inputQuery, "/", "\")
SplitPath(normalizedQuery, &targetFileName)
if RegExMatch(targetFileName, "i)^[\w\.\-]+\.(tsx?|rs|toml)$") {
matches := FindMatchingFiles(normalizedQuery, targetFileName)
if (matches.Length = 1) {
resolvedFiles.Push({path: matches[1], name: targetFileName})
}
else if (matches.Length > 1) {
chosenPath := ShowGeminiGuiSync(matches, targetFileName, inputQuery)
if (chosenPath != "") {
resolvedFiles.Push({path: chosenPath, name: targetFileName})
} else {
ShowCustomToolTip("Selection cancelled for: " . targetFileName)
return
}
}
else {
ShowCustomToolTip("File not found: " . inputQuery)
return
}
} else {
ShowCustomToolTip("Invalid extension: " . inputQuery)
return
}
}
finalOutput := ""
for idx, item in resolvedFiles {
fileContent := FileRead(item.path, "UTF-8")
promptHeader := 'این محتوای کامل فایل فعلی "' . item.name . '" من هست به صورت کامل این محتوا را آپدیت کن بدون هیچ حذفیاتی همه آپشن ها و بخش های دیگه را نگه دار فقط اون بخشی که باگ داره یا آپشنی که میخای اضافه کنی را اضافه کنه یا اون بخشی که باگ داره را ویرایش کن و هیچ چیز دیگری را دستکاری نکن و نسخه نهایی را بهم بده که فقط کپی پیست کنم'
if (idx > 1) {
finalOutput .= "`n`n"
}
finalOutput .= promptHeader . "`n" . fileContent
}
A_Clipboard := finalOutput
Sleep(100)
Send("^a")
Sleep(50)
Send("^v")
ShowCustomToolTip("Processed " . resolvedFiles.Length . " file(s) successfully!")
}
; ==============================================================================
; F4: جایگذاری یا ساخت خودکار پوشه/فایل و بروزرسانی محتوا پس از کپی
; ==============================================================================
F4:: {
Send("^c")
Sleep(150)
selectedText := Trim(A_Clipboard)
if (selectedText = "") {
ShowCustomToolTip("Please select a filename first!")
return
}
normalizedQuery := StrReplace(selectedText, "/", "\")
SplitPath(normalizedQuery, &targetFileName, &targetDir)
if !RegExMatch(targetFileName, "i)^[\w\.\-]+\.(tsx?|rs|toml)$") {
ShowCustomToolTip("Invalid target filename selected!")
return
}
matches := FindMatchingFiles(normalizedQuery, targetFileName)
targetPath := ""
if (matches.Length = 1) {
targetPath := matches[1]
}
else if (matches.Length > 1) {
targetPath := ShowGeminiGuiSync(matches, targetFileName, selectedText)
}
else {
targetPath := VORA_PATH "\" normalizedQuery
SplitPath(targetPath, , &parentFolder)
try {
if (!DirExist(parentFolder)) {
DirCreate(parentFolder)
}
if (!FileExist(targetPath)) {
FileAppend("", targetPath, "UTF-8")
}
} catch {
ShowCustomToolTip("Failed to create folder or file structure!")
return
}
}
if (targetPath = "") {
ShowCustomToolTip("Operation cancelled.")
return
}
ShowCustomToolTip("Target set: " . targetFileName . "`nNow copy the new code (Ctrl+C)...")
initialClipboard := A_Clipboard
startTime := A_TickCount
while (A_TickCount - startTime < 60000) {
if (A_Clipboard != initialClipboard && Trim(A_Clipboard) != "") {
newCode := A_Clipboard
try {
fileObj := FileOpen(targetPath, "w", "UTF-8")
fileObj.Write(newCode)
fileObj.Close()
ShowCustomToolTip("File successfully updated/created: " . targetFileName)
} catch {
ShowCustomToolTip("Failed to write to file: " . targetFileName)
}
return
}
Sleep(200)
}
ShowCustomToolTip("Timeout! No new code copied.")
}
; ==============================================================================
; F6: پیست کردن متن ثابت پروژهای
; ==============================================================================
F6:: {
targetText := "خب بریم قدم بعدی را با وسواس کامل و دقیق ترین و حرفه ای ترین شکل ممکن پیاده سازی کنیم"
previousClipboard := A_Clipboard
A_Clipboard := targetText
Sleep(50)
Send("^v")
Sleep(150)
A_Clipboard := previousClipboard
}
; ==============================================================================
; توابع ساخت ساختار درختی و موتور جستجو
; ==============================================================================
BuildTreeFromGitList(gitFileList) {
lines := StrSplit(gitFileList, ["`r`n", "`n"])
treeMap := Map()
for line in lines {
path := Trim(line)
if (path = "")
continue
parts := StrSplit(path, "/")
curr := treeMap
for idx, part in parts {
if (idx = parts.Length) {
if (!curr.Has(part))
curr[part] := true
} else {
if (!curr.Has(part) || curr[part] = true)
curr[part] := Map()
curr := curr[part]
}
}
}
result := "vora/`n"
result .= RenderMapTree(treeMap, "")
return result
}
RenderMapTree(nodeMap, indent) {
out := ""
keys := []
for k in nodeMap
keys.Push(k)
for idx, key in keys {
isLast := (idx = keys.Length)
prefix := isLast ? "└── " : "├── "
nextIndent := indent . (isLast ? " " : "│ ")
val := nodeMap[key]
if (Type(val) = "Map") {
out .= indent . prefix . key . "/`n"
out .= RenderMapTree(val, nextIndent)
} else {
out .= indent . prefix . key . "`n"
}
}
return out
}
FindMatchingFiles(normalizedQuery, targetFileName) {
matches := []
Loop Files, VORA_PATH "\" targetFileName, "R" {
if (InStr(A_LoopFileFullPath, normalizedQuery)) {
matches.Push(A_LoopFileFullPath)
}
}
return matches
}
ShowGeminiGuiSync(fileList, fileName, queryText) {
guiObj := Gui("+AlwaysOnTop -MaximizeBox -MinimizeBox +Owner", "Gemini File Selector — " . fileName)
guiObj.BackColor := "131314"
guiObj.SetFont("s10 bold", "Segoe UI")
guiObj.Add("Text", "x20 y15 w560 cA8C7FA", "Multiple matches for '" . queryText . "'. Select correct path:")
guiObj.SetFont("s10 norm", "Segoe UI")
listBox := guiObj.Add("ListBox", "x20 y42 w560 r" . Min(fileList.Length, 8) . " Background1E1F20 cE3E2E6 AltSubmit")
for filePath in fileList {
relativePath := SubStr(filePath, StrLen(VORA_PATH) + 2)
listBox.Add([relativePath])
}
listBox.Choose(1)
guiObj.SetFont("s10 bold", "Segoe UI")
btnSelect := guiObj.Add("Button", "x440 y+12 w140 h36 Default", "Select (Enter)")
selectedPath := ""
isDone := false
OnSubmit(*) {
if (listBox.Value > 0) {
selectedPath := fileList[listBox.Value]
isDone := true
guiObj.Destroy()
}
}
btnSelect.OnEvent("Click", OnSubmit)
listBox.OnEvent("DoubleClick", OnSubmit)
guiObj.OnEvent("Escape", (*) => (isDone := true, guiObj.Destroy()))
guiObj.Show("w600 Center")
try {
DwmSetWindowAttribute := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "dwmapi", "Ptr"), "AStr", "DwmSetWindowAttribute", "Ptr")
if (DwmSetWindowAttribute) {
value := Buffer(4, 0)
NumPut("UInt", 1, value)
DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", guiObj.Hwnd, "UInt", 20, "Ptr", value, "UInt", 4)
}
}
while (!isDone) {
Sleep(50)
}
return selectedPath
}
ShowCustomToolTip(msg) {
ToolTip(msg)
SetTimer () => ToolTip(), -2500
}