7995 wrote: 2021-12-13, 15:48 UTC
This is a separate button. Can i create a button which as a toggle has two commands: show/hide foiders?
Since there is no internal command like
cm_ShowFilesOnly we have to create a own UserDefinedCommand,
I named it "
em_SrcNoFolders" and wrote it to my usercmd.ini
[em_SrcNoFolders]
cmd=cd |*\
With this both commands, em_SrcNoFolders and cm_SrcAllFiles we have two commands which we can use to toggle the view.
em_SrcNoFolders => show files only, do not show folders
cm_SrcAllFiles ===> show all files and folders
For to send that commands to TC, we need a tool which can execute SendMessage for both cm and em commands.
With the AutoHotkey.exe in the TC folder and a AHK-Script we can do that.
Here is a AHK-Script (AHK v1.1.xx) which works for me:
You can execute that script from a button, assign an keyboard shortcut to or add an alias for the TC command line. (see my sig)
myScript.ahk
Code: Select all
#SingleInstance force
; TOGGLE the view
; Stefan 2021-12-13 Mon 19:09:46
; Found at https://ghisler.ch/board/viewtopic.php?p=408256#p408256
;
; AutoHotkey script, execute like "AutoHotkey.exe myScript.ahk" (tested with AutoHotkey.exe 1.1.22.9 of 2015)
;
; 1) create first a UserDefinedCommand in "usercmd.ini"
; [em_SrcNoFolders]
; cmd=cd |*\
;
;
; ############# script settings to do the wanted behaviour ###################
; Create a userAHK.ini to store the current state:
EnvGet, CommPath, Commander_Path
myUserAHKini=%CommPath%\userAHK.ini ;// ini file in TC main folder
;myUserAHKini:=SubStr(A_ScriptName, 1, -4) . ".ini" ;// ini file in folder with *.ahk file
; --------------------------------
; Set default and/or read the userAHK.ini
myViewFoldersONLYstate=0
IfExist, %myUserAHKini%
{
;IniRead, OutputVar, Filename, Section, Key [, Default]
IniRead, myViewFoldersONLYstate, %myUserAHKini%, Toggles, myViewFoldersONLY
}
; --------------------------------
; Execute an command based on the current state, stored in the userAHK.ini
If(myViewFoldersONLYstate=1)
{
TC_SendData("cm_SrcAllFiles" , "EM")
; cm_SrcAllFiles=312;Source: All files ; see "TOTALCMD.INC" text file in TC-folder:
IniWrite, 0, %myUserAHKini%, Toggles, myViewFoldersONLY
}
Else
{
TC_SendData("em_SrcNoFolders" , "EM")
; create that command yourself in "usercmd.ini"
;IniWrite, Value, Filename, Section, Key
IniWrite, 1, %myUserAHKini%, Toggles, myViewFoldersONLY
}
ExitApp
; --------------------------------
; ############# special code by artt , don't touch ###################
;//https://ghisler.ch/board/viewtopic.php?f=6&t=32658&start=30
;//New WM_COPYData Examples
;//artt Junior Member Junior Member Posts: 39 Joined: Sun May 03, 2009 9:03
TC_SendData(Cmd, CmdType="", msg="", hwnd="") {
Critical ; Define "OnMessage" as STATIC it is registered at Script startup.
STATIC om:=OnMessage(0x4a, "TC_SendData"), TC_ReceiveDataValue:="", TC_DataReceived:="" ; 0x4a is WM_COPYDATA
IF ((msg=0x4A) AND (hwnd=A_ScriptHwnd)) ; EnSure is trigered by this Script.
EXIT (TC_ReceiveDataValue:=StrGet(NumGet(CmdType + A_PtrSize * 2)), TC_DataReceived:="1")
VarSetCapacity(CopyDataStruct, A_PtrSize * 3), TC_ReceiveDataValue:=1, TC_DataReceived:=""
IF CmdType IN LR,ST ; CD Command
DirType:=CmdType, CmdType:="CD"
ELSE IF (CmdType="") ; Ask TC
CmdType:=(A_IsUnicode ? "GW" : "GA"), TC_ReceiveDataValue:=""
If( A_IsUnicode ) {
VarSetCapacity( cmdA, StrPut(cmd, "cp0"),0) ; 3rd parameter "0" is necessary for CD "LeftPath only"
Loop, % StrLen(cmd)
NumPut( Asc(SubStr(cmd, A_Index, 1)), cmdA, A_Index - 1, "Char")
}
NumPut( Asc(SubStr(CmdType,1,1)) + 256 * Asc(SubStr(CmdType,2,1)), CopyDataStruct,0 )
NumPut( StrLen(cmd) + (CmdType="CD" ? 5 : 0), CopyDataStruct, A_PtrSize )
NumPut((A_IsUnicode ? &cmdA : &cmd), CopyDataStruct, A_PtrSize * 2)
Loop, % (CmdType=="CD" ? 2 : 0)
NumPut(Asc(SubStr(DirType,A_Index,1)), (A_IsUnicode ? cmdA : cmd), (StrLen(cmd)+A_Index),"Char")
SendMessage, 0x4A,%A_ScriptHwnd%, &CopyDataStruct,, ahk_class TTOTAL_CMD
;IF you send a 'request' command to TC (all Ask TC commands: A, LP, LC, ...), script is waiting for (500 x 10 = 5000ms = 5 seconds) for TC to response/answer.
;If the answer arrives before the 5 seconds, it is immediately breaking the interaction and return the answer to the user (normally their is no delay).
While (TC_ReceiveDataValue="") {
IfEqual, TC_DataReceived, 1, Break
IfGreaterOrEqual, A_Index, 500, Break
Sleep,10
}
Return TC_ReceiveDataValue
}
; ############# EOF #####################################