-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathTotalCmdFuncs.ahk
149 lines (141 loc) · 3.62 KB
/
TotalCmdFuncs.ahk
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
;=========================================Total Commander=====================
TcmdSelByMask(mask) {
IfWinActive ahk_class TTOTAL_CMD
{
PostMessage 1075, 521, , , ahk_class TTOTAL_CMD
send, % mask
Controlclick, OK, ahk_class TCOMBOINPUT
}
}
TcmdDeselByMask(mask) {
IfWinActive ahk_class TTOTAL_CMD
{
PostMessage 1075, 522, , , ahk_class TTOTAL_CMD
send, % mask
Controlclick, OK, ahk_class TCOMBOINPUT
}
}
TcmdSelByList(selection) {
temp := Clipboard
Clipboard := selection
SendMessage, 1075, 2033 ; cm_LoadSelectionFromClip, inactive panel
Clipboard := temp
}
TcmdGetSel() {
IfWinActive, ahk_class TTOTAL_CMD
{
temp := Clipboard
Clipboard := ""
SendMessage, 1075, 2017 ; cm_CopyNamesToClip, active panel
ClipWait, 2
if (Clipboard = "")
{
MsgBox, 16,, Timeout while trying to get selection info (active window).
Return
}
selection := Clipboard
Clipboard := temp
tooltip, % selection
return selection
}
}
TcmdGetSrcPath() {
IfWinActive, ahk_class TTOTAL_CMD
{
temp := Clipboard
Clipboard := ""
SendMessage, 1075, 2029 ; copy source to CB
ClipWait, 2
if (Clipboard = "")
{
MsgBox, 16,, Timeout while trying to get selection info (active window).
Return
}
selection := Clipboard
Clipboard := temp
return selection
}
}
TcmdToggleWindowed() {
IfWinActive, ahk_class TTOTAL_CMD
{
WinGet, maximized, MinMax
if (maximized = 1) {
WinRestore ;windowize
SendMessage, 1075, 910 ;separator 100%
SendMessage, 1075, 2901 ;hide button bars
SendMessage, 1075, 2903 ;hide two drive bars
SendMessage, 1075, 2909 ;hide status
SendMessage, 1075, 2910 ;hide cmd
SendMessage, 1075, 2911 ;hide func
} else {
WinMaximize ;maximize
SendMessage, 1075, 909 ;separator 50%
SendMessage, 1075, 2901 ;show button bars
SendMessage, 1075, 2903 ;show two drive bars
SendMessage, 1075, 2909 ;show status
SendMessage, 1075, 2910 ;show cmd
SendMessage, 1075, 2911 ;show func
}
}
}
resetConsoleCommand(args, arg1) {
console.commandStr := ""
loop, % arg1-1
{
console.commandStr := console.commandStr args[A_Index] " "
}
}
global prevSel = ""
CDX(args, arg1) {
RunOrActivateApp(Path_totalcmd, Wnd_totalcmd)
if (!WinActive(Wnd_totalcmd)) {
console.Accept("Total Commander is not running.", -1, 0xFFDD5555)
return
}
if (!args[arg1]) { ;just display a message that cdx command is found
console.Accept("cdx...", -1, 0xFF99DD99)
send, ^{NumpadSub}{Home}
return
}
if (args[arg1] = ".") { ;send home key
Send, {Home}
console.Accept("cdx: go home", -1, 0xFF55DD55)
return
}
if (args[arg1] = "..") { ;go to parent and reset command
SendMessage, 1075, 2002 ;Go to parent directory
resetConsoleCommand(args, arg1)
console.Accept("cdx: go up", -1, 0xFF55DD55)
return
}
mask := "*" args[arg1] "*"
send, ^{NumpadSub}{Home}
dir := TcmdGetSrcPath()
files := GetFilesFromDir(dir, mask)
if (!files) {
console.Accept("cdx: no matches", -1, 0xFFDD5555)
return
}
TcmdSelByList(files)
SendMessage, 1075, 2053 ;Go to next selected file
splitted := StrSplit(files, "`n")
numMatches := splitted.MaxIndex()
;tooltip, % files "`n`n" prevSelection
if (numMatches = 1) {
;if (prevSel = files) {
SendMessage, 1075, 1001 ;Simulate: Return pressed
resetConsoleCommand(args, arg1)
console.Accept("cdx: " splitted[1], -1, 0xFF00DD00)
;path := TcmdGetSrcPath() "\" splitted[1]
;Run, % Path_filemanager " /O " path
prevSel := ""
return
;} else {
; console.Accept("cdx: " files, -1, 0xFF006600)
; return
;}
}
prevSel := files
console.Accept("cdx: " numMatches " items...", -1, 0xFF006600)
}