AutoHotkey: Inplace rename with dialog

From TotalcmdWiki
Revision as of 22:45, 20 October 2005 by Sheepdog (talk | contribs)
Jump to navigation Jump to search
; Inplace rename with dialog box.
;
; Hotkey: Win-q
;
; Assumptions:
; - Space selects the file and does not move the cursor
;   (careful when selecting a folder, by default it calculates the size,
;    which can be time consuming)
; - Shift-F6 is still defined as inplace rename (default)
; - The [..] folder is present (so it wont work in the root folder!)


LB_GETCURSEL := 0x188

$#q::
	if not WinActive( "ahk_class TTOTAL_CMD" )
	{
		Send #q
		Return
	}

	ControlGetFocus sf_FocusedControl
	if (sf_FocusedControl != "TMyListBox1" and sf_FocusedControl != "TMyListBox2")
		Return

	SendMessage %LB_GETCURSEL%, 0, 0, %sf_FocusedControl%, ahk_class TTOTAL_CMD
	sf_Position := ErrorLevel
	if sf_Position = 0
		Return

	SendTCCommand( "cm_ClearAll" )
	Send {Space}{Home}{Space}+{F6}
	WinWait ahk_class TCheckEditBox

	; Wait until the user has finished renaming the file
	WinWaitClose
	SendTCCommand( "cm_ClearAll" )
	Sleep 100

	; Go back to the original position
	; The message was taken from Winspector
	SendMessage 0x19e, %sf_Position%, 0, %sf_FocusedControl%, ahk_class TTOTAL_CMD

	Return

;
; SendTCCommand 0.1
;
; Function purpose:
;    Sends a Total Commander internal command to a TC instance.
;    It can be used to automate Total Commander.
;
; Parameters:
;    xsTCCommand: The Total Commander internal command, see the list here:
;                 %COMMANDER_PATH%\TOTALCMD.INC
;
; Usage example:
;	SendTCCommand( "cm_RereadSource" )
;

SendTCCommand( xsTCCommand )
{
	loop Read, %COMMANDER_PATH%\TOTALCMD.INC
	{
		StringSplit asCommands, A_LoopReadLine, =
		if (asCommands1 = xsTCCommand)
		{
			StringSplit asCommandsValues, asCommands2, `;
			Break
		}
	}

	if (asCommandsValues1 > 0)
		PostMessage 1075, %asCommandsValues1%, 0, , ahk_class TTOTAL_CMD
}



Back to AutoHotkey