Autohotkey: When switching panels also transfer file selection

From TotalcmdWiki
Revision as of 20:21, 26 August 2009 by StatusQuo (talk | contribs) (compatibility info)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
	; ////////////////////////////////////////////////////////////////////////////
	; // TC_Exchange_TransferSelection.ahk  (W) StatusQuo 2008
	; // http://ghisler.ch/board/viewtopic.php?p=152474
	; // 
	; // When panels are exchanged (like ^U), this also transfers file selection.
	; // Use this instead of the original hotkey.
	; // 
	; // Tested successfully with TC 7.04a up to 7.50 rc1
	; ////////////////////////////////////////////////////////////////////////////
	
IfWinActive, ahk_class TTOTAL_CMD
{
	iSleepLen := 80
	boDebug   := 0

	iReGet2 := 0
	
	Clipboard := ""
	SendMessage, 1075, 2017	; cm_CopyNamesToClip, active panel
	ClipWait, 3
	if (Clipboard = "")
	{
		MsgBox, 16,, Timeout while trying to get selection info (active window).
		Return
	}
	sSel1 := Clipboard
	
	Send, {TAB}            	; focus inactive panel
ReGet2:
	Sleep, %iSleepLen%

	Clipboard := ""
	SendMessage, 1075, 2017	; cm_CopyNamesToClip, inactive panel
	ClipWait, 3
	if (Clipboard = "")
	{
		MsgBox, 16,, Timeout while trying to get selection info (inactive window).
		Return
	}
	sSel2 := Clipboard

	if (sSel1 = sSel2)
	{
		if (boDebug)
			MsgBox, 64,, (sSel1 = sSel2):`n%sSel2%
		if (iReGet2)	; prevent endless loop
		{
			if (boDebug)
				MsgBox, 16,, Repeated timeout while trying to get selection info (inactive window)`n(or identical selections).
			; Return	;	would prevent usage with identical selections
		}
		Sleep, %iSleepLen%
		if (not iReGet2)	; prevent endless loop
		{
			iReGet2 := 1
			Goto, ReGet2
		}
	}
	
	SendMessage, 1075, 531	; cm_Exchange
	Sleep, %iSleepLen%
	
	Clipboard := sSel1
	SendMessage, 1075, 2033	; cm_LoadSelectionFromClip, inactive panel
	
	Send, {TAB}            	; focus active panel
	Sleep, %iSleepLen%
	
	Clipboard := sSel2
	SendMessage, 1075, 2033	; cm_LoadSelectionFromClip, active panel

	Send, {TAB}            	; focus inactive panel (content of previously active panel)
	Return
}

;

Back to AutoHotkey