AutoHotkey: AppendLnk option for packing (plus: Automatically assign name for archive)

From TotalcmdWiki
Revision as of 01:43, 18 January 2008 by StatusQuo (talk | contribs) (1.01 - fixed timeout from inside archives)
Jump to navigation Jump to search

Context sensitive extension of TC's suggested name in packing dialog (Alt-F5), emulating the missing AppendLnkPack option in TC up to 7.02a.

- Stays resident in memory, can be quit via its icon in the system tray.
- Gets invoked with Alt-F5, replacing TC's standard name suggestion.
- The originally suggested name can be restored by pressing Alt-Backspace once, if needed.
; // Resulting archive name:
; //   - if only 1 file selected -------------------- :  zip:filename.ext.zip (*.*.zip)
; //   - if multiple files /      same name  selected :  zip:filename.zip     (  *.zip)
; //   - if multiple files / different names selected :  zip:dirname.zip (as suggested by TC)

Related links:


	; ////////////////////////////////////////////////////////////////////////////
	; // TC_AppendLnkPack.ahk v1.01  -  (W) StatusQuo 2008     (for TC 7.0 and up)
	; //
	; // Context sensitive extension of TC's suggested name in packing dialog (Alt-F5),
	; // emulating the missing AppendLnkPack option,
	; // => http://ghisler.ch/board/viewtopic.php?p=120095#120095
	; //
	; // Option 2 ("multiple files, same name") inspired by
	; // http://www.ghisler.ch/wiki/index.php/AutoHotkey:_Automatically_assign_name_for_archive
	; //
	; ////////////////////////////////////////////////////////////////////////////
	; //
	; // Resulting archive name:
	; //   - only 1 file selected:            zip:filename.ext.zip
	; //   - multiple files, same name:       zip:filename.zip
	; //   - multiple files, different names: zip:dirname.zip (as suggested by TC)
	; //
	; ////////////////////////////////////////////////////////////////////////////

#SingleInstance force
#IfWinActive ahk_class TTOTAL_CMD
!F5::
	IfWinNotExist,  ahk_class TTOTAL_CMD, return
	IfWinNotActive, ahk_class TTOTAL_CMD, , WinActivate, ahk_class TTOTAL_CMD, 
	WinWaitActive,  ahk_class TTOTAL_CMD
		; save active control name (side of active panel);
		; while TC is inactive in background, nothing has the focus!
	ControlGetFocus, sLastFocus, ahk_class TTOTAL_CMD
		; check, if TC's main window is active
	IfNotInString, sLastFocus, TMyListBox, return
	
		; 2017 - cm_CopyNamesToClip - copy selected file names to clipboard
	Clipboard=
	SendMessage, 1075, 2017
	ClipWait, 1
	if ErrorLevel
	{	MsgBox, 49, TimeOut - %A_ScriptName%, - TimeOut - `n`nCould not get selected file names from TC`n(cm_CopyToClipboard)., 7
		IfMsgBox, Cancel,  Return
		IfMsgBox, Timeout, Return
		ControlSend,  TPanel1, !{F5}
		Return
	}
	
		; parse selected file names
	 iLines = 0
	boUseName = 1
	 sFirstName =
	 sFirstFullName =
	Loop, Parse, Clipboard, `n, `r
	{	iLines += 1
			; cut path and extension
		SplitPath, A_LoopField, FullFileName, , , FileNameNoExt

			; use first name for comparison
		if (sFirstName = "") 
		{	 sFirstName     = %FileNameNoExt%
			 sFirstFullName = %FullFileName%
		} else {
				; check if there is a different file name
			if (FileNameNoExt <> sFirstName)
			{	boUseName = 0
				break
			}
		}
	}
	
		; multiple files selected:
	if (iLines > 1)
	{	ControlSend,  TPanel1, !{F5}
			; different file names selected: => use dirname.zip
			; (change nothing at all, use TC's suggestion)
		IfEqual, boUseName, 0
			return
			; all files have same name:     => use filename.zip
		WinWait,       ahk_class TDLGZIP
		ControlSend,  TEdit1, !{F5}%sFirstName%{HOME}+{END}
		return
	}

		; single file name selected:   => use filename.ext.zip
	ControlSend,  TPanel1, !{F5}
	WinWait,       ahk_class TDLGZIP
	ControlSend,  TEdit1, !{F5}%sFirstFullName%{HOME}+{END}
#IfWinActive
;