AutoHotkey: From FileSync open another TC instance with selected files: Difference between revisions
Jump to navigation
Jump to search
(added: use the same helper instance of TC for every call) |
(added: support for single files (in other panel cd to dir) + optional settings) |
||
Line 20: | Line 20: | ||
; please adjust path here; %COMMANDER_PATH% is not available outside of TC | ; please adjust path here; %COMMANDER_PATH% is not available outside of TC | ||
sTCExe := "C:\totalcmd\TOTALCMD.EXE" | sTCExe := "C:\totalcmd\TOTALCMD.EXE" | ||
boAlwaysOpenNewTask := 0 ; set to 1 to not re-use TC target window (always open a new one) | |||
boCdToFolderOnly := 0 ; set to 1 to just cd to dirs (does not use Lister to select file) | |||
iListerTimeOutSecs := 1 ; if using Lister: timeout after n seconds of not appearing Lister | |||
; static pidTC2 | ; static pidTC2 | ||
Send, {F3} | ; | ||
sLDirName := | LB_GETCARETINDEX := 0x019F | ||
Send, +{F3} | LB_GETTEXT := 0x0189 | ||
ControlGetFocus, Panel_id, A | |||
SendMessage, %LB_GETCARETINDEX%, 0, 0, %Panel_id%, A | |||
LB_CursorPosition := ErrorLevel | |||
VarSetCapacity(LB_String, 1024, 0) | |||
SendMessage, %LB_GETTEXT%, %LB_CursorPosition%, &LB_String, %Panel_id%, A | |||
LB_CursorLine := LB_String | |||
Loop ; find subdirectory | |||
{ | |||
If (SubStr(LB_String, StrLen(LB_String)) = "\") | |||
or (LB_CursorPosition < 1) | |||
Break | |||
LB_CursorPosition -= 1 | |||
SendMessage, %LB_GETTEXT%, %LB_CursorPosition%, &LB_String, %Panel_id%, A | |||
} | |||
LB_SubDir := LB_String | |||
ControlGetText, sLPath, TEdit2, ahk_class TCmpForm | |||
ControlGetText, sRPath, TEdit1, ahk_class TCmpForm | |||
; | |||
sLDirName := "" ; get left path name | |||
if (not boCdToFolderOnly) | |||
and (SubStr(LB_CursorLine, StrLen(LB_CursorLine), 1) != "\") | |||
{ | |||
Send, {F3} | |||
sLDirName := GetActiveTCListerPath() | |||
} | |||
If (sLDirName = "") | |||
sLDirName := sLPath . LB_SubDir | |||
; | |||
sRDirName := "" | |||
if (not boCdToFolderOnly) | |||
and (SubStr(LB_CursorLine, StrLen(LB_CursorLine), 1) != "\") | |||
{ | |||
Send, +{F3} | |||
sRDirName := GetActiveTCListerPath() | |||
} | |||
If (sRDirName = "") | |||
sRDirName := sRPath . LB_SubDir | |||
; | |||
If boAlwaysOpenNewTask | |||
or (not WinExist("ahk_pid " . pidTC2)) | |||
pidTC2 := "" | pidTC2 := "" | ||
if not (pidTC2 = "") | if not (pidTC2 = "") | ||
Line 33: | Line 73: | ||
sTCExe = %sTCExe% /O | sTCExe = %sTCExe% /O | ||
} | } | ||
; | |||
sRunStr := sTCExe | sRunStr := sTCExe | ||
if (sLDirName != "") | if (sLDirName != "") | ||
Line 45: | Line 85: | ||
else | else | ||
Run, %sRunStr% | Run, %sRunStr% | ||
; | |||
Return | Return | ||
#IfWinActive | #IfWinActive | ||
GetActiveTCListerPath() | GetActiveTCListerPath() | ||
{ | { | ||
WinWaitNotActive, ahk_class TCmpForm,, | global boCdToFolderOnly, iListerTimeOutSecs | ||
WinWaitNotActive, ahk_class TCmpForm,, %iListerTimeOutSecs% ; wait for starting lister, timeout in seconds | |||
IfWinActive, ahk_class TCmpForm ; Lister hasn't started - no file on this panel side? | IfWinActive, ahk_class TCmpForm ; Lister hasn't started - no file on this panel side? | ||
Return | Return | ||
WinGetActiveTitle, sWinTitle | SetTitleMatchMode, 1 | ||
IfWinActive, Lister | |||
{ | |||
WinGetActiveTitle, sWinTitle | |||
WinClose, %sWinTitle% | |||
} | |||
iNamePos := (InStr(sWinTitle, "[", false, 0) + 1) | iNamePos := (InStr(sWinTitle, "[", false, 0) + 1) | ||
If (boCdToFolderOnly) ; folder only | |||
Return, % SubStr(sWinTitle, iNamePos, (InStr(sWinTitle, "\", false, 0) + 1) - iNamePos) | |||
else ; folder + file name | |||
Return, % SubStr(sWinTitle, iNamePos, StrLen(sWinTitle) - iNamePos) | |||
} | } | ||
Revision as of 17:40, 24 July 2008
; ////////////////////////////////////////////////////////////////////////////
; // TC_Sync_OpenFolderInSecondTC.ahk V0.12 (W) StatusQuo 2008
; // http://ghisler.ch/board/viewtopic.php?t=19713
; //
; // open another TC instance
; // with the folders of the currently selected file in cm_FileSync
; // via hotkey: Ctrl+Win+T
; ////////////////////////////////////////////////////////////////////////////
#SingleInstance, Force
Return
#IfWinActive, ahk_class TCmpForm
^#t:: ; hotkey = Ctrl+Win+T
; please adjust path here; %COMMANDER_PATH% is not available outside of TC
sTCExe := "C:\totalcmd\TOTALCMD.EXE"
boAlwaysOpenNewTask := 0 ; set to 1 to not re-use TC target window (always open a new one)
boCdToFolderOnly := 0 ; set to 1 to just cd to dirs (does not use Lister to select file)
iListerTimeOutSecs := 1 ; if using Lister: timeout after n seconds of not appearing Lister
; static pidTC2
;
LB_GETCARETINDEX := 0x019F
LB_GETTEXT := 0x0189
ControlGetFocus, Panel_id, A
SendMessage, %LB_GETCARETINDEX%, 0, 0, %Panel_id%, A
LB_CursorPosition := ErrorLevel
VarSetCapacity(LB_String, 1024, 0)
SendMessage, %LB_GETTEXT%, %LB_CursorPosition%, &LB_String, %Panel_id%, A
LB_CursorLine := LB_String
Loop ; find subdirectory
{
If (SubStr(LB_String, StrLen(LB_String)) = "\")
or (LB_CursorPosition < 1)
Break
LB_CursorPosition -= 1
SendMessage, %LB_GETTEXT%, %LB_CursorPosition%, &LB_String, %Panel_id%, A
}
LB_SubDir := LB_String
ControlGetText, sLPath, TEdit2, ahk_class TCmpForm
ControlGetText, sRPath, TEdit1, ahk_class TCmpForm
;
sLDirName := "" ; get left path name
if (not boCdToFolderOnly)
and (SubStr(LB_CursorLine, StrLen(LB_CursorLine), 1) != "\")
{
Send, {F3}
sLDirName := GetActiveTCListerPath()
}
If (sLDirName = "")
sLDirName := sLPath . LB_SubDir
;
sRDirName := ""
if (not boCdToFolderOnly)
and (SubStr(LB_CursorLine, StrLen(LB_CursorLine), 1) != "\")
{
Send, +{F3}
sRDirName := GetActiveTCListerPath()
}
If (sRDirName = "")
sRDirName := sRPath . LB_SubDir
;
If boAlwaysOpenNewTask
or (not WinExist("ahk_pid " . pidTC2))
pidTC2 := ""
if not (pidTC2 = "")
{
WinActivate, ahk_pid %pidTC2%
sTCExe = %sTCExe% /O
}
;
sRunStr := sTCExe
if (sLDirName != "")
sRunStr = %sRunStr% /L="%sLDirName%"
if (sRDirName != "")
sRunStr = %sRunStr% /R="%sRDirName%"
if (sRunStr = sTCExe)
Return
if (pidTC2 = "")
Run, %sRunStr%,,, pidTC2
else
Run, %sRunStr%
;
Return
#IfWinActive
GetActiveTCListerPath()
{
global boCdToFolderOnly, iListerTimeOutSecs
WinWaitNotActive, ahk_class TCmpForm,, %iListerTimeOutSecs% ; wait for starting lister, timeout in seconds
IfWinActive, ahk_class TCmpForm ; Lister hasn't started - no file on this panel side?
Return
SetTitleMatchMode, 1
IfWinActive, Lister
{
WinGetActiveTitle, sWinTitle
WinClose, %sWinTitle%
}
iNamePos := (InStr(sWinTitle, "[", false, 0) + 1)
If (boCdToFolderOnly) ; folder only
Return, % SubStr(sWinTitle, iNamePos, (InStr(sWinTitle, "\", false, 0) + 1) - iNamePos)
else ; folder + file name
Return, % SubStr(sWinTitle, iNamePos, StrLen(sWinTitle) - iNamePos)
}
;
Back to AutoHotkey