AutoHotkey: Duplicate starter menu entry: Difference between revisions

From TotalcmdWiki
Jump to navigation Jump to search
(Update for TC 7.50 rc1)
(Update for TC 7.55 (and 7.50a), adjust to control names dynamically)
Line 1: Line 1:
<pre>
<pre>
; ////////////////////////////////////////////////////////////////////////////
; ////////////////////////////////////////////////////////////////////////////
; // TC_StartMenu_DuplicateEntry.ahk V1.2
; // TC_StartMenu_DuplicateEntry.ahk V2.0
; // (W) StatusQuo 2008-2009 for TC 7.02a (tested up to 7.04a and 7.50 rc1)
; // (W) StatusQuo 2008-2010 for TC 7.02a (tested up to 7.04a, 7.50a and 7.55)
; //
; //
; // Duplicates an entry in TC Start Menu or Directory Hotlist
; // Duplicates an entry in TC Start Menu or Directory Hotlist
; ////////////////////////////////////////////////////////////////////////////
; ////////////////////////////////////////////////////////////////////////////
#SingleInstance, Force


; *** set window class names
; *** set window class names
Line 15: Line 17:
IfWinNotActive, ahk_class %sClassMainWin%,, WinActivate, ahk_class %sClassMainWin%,  
IfWinNotActive, ahk_class %sClassMainWin%,, WinActivate, ahk_class %sClassMainWin%,  
WinWaitActive , ahk_class %sClassMainWin%, ; main "Change Start Menu"
WinWaitActive , ahk_class %sClassMainWin%, ; main "Change Start Menu"
; *** store source values
ControlGetText,    sText3,                TEdit3, ahk_class %sClassMainWin%, ; main window ; TC 7.04a, command
ControlGetText,    sText2,                TEdit2, ahk_class %sClassMainWin%, ; main window ; TC 7.04a, parameters
ControlGetText,    sText1,                TEdit1, ahk_class %sClassMainWin%, ; main window ; TC 7.04a, start path
sEditName1 := "TEdit1" ; <= TC 7.04a
sEditName2 := "TEdit2" ; <= TC 7.04a
sEditName3 := "TEdit3" ; <= TC 7.04a
if (sText3 . sText2 . sText1 = "")
{
sEditName1 :=          "TAltEdit1" ; >= TC 7.50
sEditName2 :=          "TAltEdit2" ; >= TC 7.50
sEditName3 :=          "TAltEdit3" ; >= TC 7.50
ControlGetText, sText3, TAltEdit3, ahk_class %sClassMainWin%, ; main window ; TC 7.50 , command
ControlGetText, sText2, TAltEdit2, ahk_class %sClassMainWin%, ; main window ; TC 7.50 , parameters
ControlGetText, sText1, TAltEdit1, ahk_class %sClassMainWin%, ; main window ; TC 7.50 , start path
}


/*
/*
; --- TC7.04 uses TEdit1+2 for dir menu, TEdit3 is "command" in start menu and empty in dir menu
* /
; --- unusable in TC 7.50 (Beta 4): both dialogs use the same control names + window classes
sTmpButtonList := ""
; *** Auto-detect dir <> starter menu
Loop, 9
if (sText3 = "") ; "command" string empty => only usable up to TC 7.04a
{
{
sDialogType := "dir"
; --- get button names
} else {
sTmpVar := "sTmpButNam" . a_index
sDialogType := "start"
ControlGetText, %sTmpVar%, TButton%a_index%
ControlGet,    iCBox2, Checked,, TCheckBox2, ahk_class %sClassMainWin%, ; main window, as symbol
sTmpButtonList := sTmpButtonList . a_index . "=" . %sTmpVar% . "`n"
ControlGet,    iCBox1, Checked,, TCheckBox1, ahk_class %sClassMainWin%, ; main window, fullscreen
}
}
MsgBox, %sTmpButtonList%
ExitApp
/*
*/
*/


; *** Auto-detect dir <> starter menu
DetectButtonNames() ; get current button names
If (WinActive("Startermenü ändern ahk_class TUSERMENUCHANGE") or WinActive("Change start menu ahk_class TUSERMENUCHANGE"))
 
ControlGetText, AltEdit3, TAltEdit3, ahk_class %sClassMainWin%
ControlGetText, AltEdit2, TAltEdit2, ahk_class %sClassMainWin%
ControlGetText, AltEdit1, TAltEdit1, ahk_class %sClassMainWin%
ControlGetText, Edit3,    TEdit3,    ahk_class %sClassMainWin% ; old TC 7.04a
ControlGetText, Edit2,    TEdit2,    ahk_class %sClassMainWin% ; old TC 7.04a
ControlGetText, Edit1,    TEdit1,    ahk_class %sClassMainWin% ; old TC 7.04a
ControlGetText, V6Edit3,  Edit1,    ahk_class %sClassMainWin% ; old TC 6.56, replaces TAltEdit3; does not work properly!
ControlGet,    CheckBox2, Checked,, TCheckBox2, ahk_class %sClassMainWin%, ; main window, "as symbol"
ControlGet,    CheckBox1, Checked,, TCheckBox1, ahk_class %sClassMainWin%, ; main window, "fullscreen"
;TMyComboBox1 ; Shortcut key
;TComboBox1 ; Shortcut key ; old TC 7.04a
 
if (AltEdit3 . AltEdit2 . AltEdit1 <> "")
{
{
sDialogType := "start"
sText1 := AltEdit1
ControlGet,    iCBox2, Checked,, TCheckBox2, ahk_class %sClassMainWin%, ; main window, as symbol
sText2 := AltEdit2
ControlGet,    iCBox1, Checked,, TCheckBox1, ahk_class %sClassMainWin%, ; main window, fullscreen
sText3 := AltEdit3
} else {
} else {
If (WinActive("Verzeichnismenü ändern ahk_class TUSERMENUCHANGE") or WinActive("Change directory menu ahk_class TUSERMENUCHANGE"))
sText1 := Edit1
{
sText2 := Edit2
sDialogType := "dir"
sText3 := Edit3
}
if (Edit3 = "")
sText3 := V6Edit3
}
}


If (sDialogType = "") ; autodetect failed
; *** get title of entry + *** Auto-detect name of Edit control
ControlSend,  %varButTit%, {Space},      ahk_class %sClassMainWin%, ; Button "Change Title"
WinWaitActive,                            ahk_class %sClassDialog%, ; dialog  "Change Title"
ControlGetText, sMenuTitle, TAltEdit1, ahk_class %sClassDialog% ; get old title
if (sMenuTitle = "")
{
{
MsgBox, 3,, Dialog auto-detection failed (unknown language or version).`n`nIs the dialog = directory hotlist?`n`tYes = directory hotlist`n`tNo  = starter menu
ControlGetText, sMenuTitle, TEdit1, ahk_class %sClassDialog% ; get old title
IfMsgBox, Yes
sEditName1 := "TEdit1" ; TC 7.04a
sDialogType := "dir"
sEditName2 := "TEdit2" ; TC 7.04a
IfMsgBox, No
sEditName3 := "TEdit3" ; TC 7.04a
sDialogType := "start"
if (Edit3 . AltEdit3 = "")
IfMsgBox, Cancel
sEditName3 := "Edit1" ; TC 6.51
Return
} else {
sEditName1 := "TAltEdit1"
sEditName2 := "TAltEdit2"
sEditName3 := "TAltEdit3"
}
}
; ControlSend,  TButton1, {Space},        ahk_class %sClassDialog%, ; Button "Cancel", close "Change Title" dialog
DetectTitleOkButton()
ControlSend,  %sOkButName%, {Space},    ahk_class %sClassDialog%, ; Button OK, close "Title" dialog
WinWaitActive,                            ahk_class %sClassMainWin%, ; main hotlist editor window


; *** get entry title
; *** sending {Space} to "Change title" button changes button names in Dir Hotlist (#1 gets "&>>" instead of "Help")
if (sDialogType = "dir")
; *** ControlClick instead of {Space} leaves button names unchanged
{
; *** => redetect button names here
; ControlClick,  TButton4, ahk_class %sClassMainWin%, ; Button "Change Title"; DirMenu
DetectButtonNames() ; get current button names
ControlSend,  TButton4, {Space}, ahk_class %sClassMainWin%, ; Button "Change Title"; DirMenu
} else {
; ControlClick,  TButton5, ahk_class %sClassMainWin%, ; Button "Change Title"; StartMenu
ControlSend,  TButton5, {Space}, ahk_class %sClassMainWin%, ; Button "Change Title"; StartMenu
}
WinWaitActive,                      ahk_class %sClassDialog%, ; dialog  "Change Title"
; ControlGetText, sMenuTitle, TEdit1, ahk_class %sClassDialog% ; get old title
ControlGetText, sMenuTitle, %sEditName1%, ahk_class %sClassDialog% ; get old title
; ControlClick,  TButton1,          ahk_class %sClassDialog%, ; Button Cancel, close "Change Title" dialog
ControlSend,  TButton1, {Space},  ahk_class %sClassDialog%, ; Button Cancel, close "Change Title" dialog
WinWaitActive,                      ahk_class %sClassMainWin%, ; main window


; *** add new entry
; *** add new entry
if (sDialogType = "dir")
ControlSend,  %varButAdd%, {Space},               ahk_class %sClassMainWin%, ; Button "Add Menu Entry"
{
WinWaitActive,                                     ahk_class %sClassDialog%, ; dialog  "Change Title"
; ControlClick,  TButton7, ahk_class %sClassMainWin%, ; Button "Add Menu Entry"
ControlSetText, %sEditName1%, %sMenuTitle% [copy], ahk_class %sClassDialog% ; Title (TC7.04a:TEdit1, TC7.50a:TAltEdit1)
ControlSend,  TButton7, {Space}, ahk_class %sClassMainWin%, ; Button "Add Menu Entry"
DetectTitleOkButton()
} else {
ControlSend,  %sOkButName%, {Space},        ahk_class %sClassDialog%, ; Button OK, close "Title" dialog
; ControlClick,  TButton8, ahk_class %sClassMainWin%, ; Button "Add Menu Entry"
WinWaitActive,                               ahk_class %sClassMainWin%, ; main window
ControlSend,  TButton8, {Space}, ahk_class %sClassMainWin%, ; Button "Add Menu Entry"
 
}
; *** sending {Space} to "OK" button changes button names in Dir Hotlist (#1 gets "&>>" instead of "Help")
WinWaitActive,                               ahk_class %sClassDialog%, ; dialog  "Change Title"
; *** ControlClick does the same here
; ControlSetText, TEdit1, %sMenuTitle% [copy], ahk_class %sClassDialog% ; Title
; *** => redetect button names!
ControlSetText, %sEditName1%, %sMenuTitle% [copy], ahk_class %sClassDialog% ; Title (TC7.04a:TEdit1)
DetectButtonNames() ; get current button names
sOKButTit := "TButton3"  ; >= TC 7.50
if (sEditName1 = "TEdit1") ; <= TC 7.04a
sOKButTit := "TButton2"
; ControlClick,  TButton2,                    ahk_class %sClassDialog%, ; Button OK, close "Title" dialog
; ControlClick,  %sOKButTit%,                ahk_class %sClassDialog%, ; Button OK, close "Title" dialog
ControlSend,  %sOKButTit%, {Space},        ahk_class %sClassDialog%, ; Button OK, close "Title" dialog
WinWaitActive,                               ahk_class %sClassMainWin%, ; main window


; *** fill stored values from source entry
; *** fill stored values from source entry ; TC 7.04a uses just TEdit1+2 for dir hotlist
; if (sDialogType = "start") ; only TC 7.04a uses just TEdit1+2 for dir menu
ControlSetText, %sEditName3%, %sText3%, ahk_class %sClassMainWin%, ; main window ; TAltEdit3 / TEdit3
{
; ControlSetText, TEdit3, %sText3%, ahk_class %sClassMainWin%, ; main window
ControlSetText, %sEditName3%, %sText3%, ahk_class %sClassMainWin%, ; main window
}
ControlSetText, %sEditName2%, %sText2%, ahk_class %sClassMainWin%, ; main window
ControlSetText, %sEditName2%, %sText2%, ahk_class %sClassMainWin%, ; main window
ControlSetText, %sEditName1%, %sText1%, ahk_class %sClassMainWin%, ; main window
ControlSetText, %sEditName1%, %sText1%, ahk_class %sClassMainWin%, ; main window
 
; if (sDialogType = "start")
if (sDialogType = "start")
; {
{
if CheckBox2
if iCBox2
Control, Check,,  TCheckBox2, ahk_class %sClassMainWin%, ; main window
Control, Check,,  TCheckBox2, ahk_class %sClassMainWin%, ; main window
else
else
Control, UnCheck,, TCheckBox2, ahk_class %sClassMainWin%, ; main window
Control, UnCheck,, TCheckBox2, ahk_class %sClassMainWin%, ; main window
if iCBox1
if CheckBox1
Control, Check,,  TCheckBox1, ahk_class %sClassMainWin%, ; main window
Control, Check,,  TCheckBox1, ahk_class %sClassMainWin%, ; main window
else
else
Control, UnCheck,, TCheckBox1, ahk_class %sClassMainWin%, ; main window
Control, UnCheck,, TCheckBox1, ahk_class %sClassMainWin%, ; main window


; *** set cursor to command value
; *** set cursor to command value
; ControlFocus, TEdit3, ahk_class %sClassMainWin%, ; main window
ControlFocus, %sEditName3%, ahk_class %sClassMainWin%, ; main window ; TAltEdit3
ControlFocus, %sEditName3%, ahk_class %sClassMainWin%, ; main window
ControlSend, %sEditName3%, {HOME},  
ControlSend,  %sEditName3%, {HOME},  
; }
 
Return
 
; *****************************************************************************************************
 
DetectButtonNames()
{
global
ControlGetTExt, sButNam1, TButton1
if (sButNam1="&>>")
{
; *** Starter menu (and Dir Hotlist after "Change Title" in TC 7.50a/7.55, using ControlClick or sending {Space})
varButAdd := "TButton8" ;;* 8=&Add Item...
varButSub := "TButton7" ;;* 7=Add s&ubmenu...
varButDel := "TButton6" ;;* 6=&Delete Item
varButTit := "TButton5" ;;* 5=Change &Title
varButOK := "TButton4" ;;* 4=OK
varButCan := "TButton3" ;;* 3=Cancel
;;* 2=Help
;;* 1=&>>
} else {
; *** Dir Hotlist
varButAdd := "TButton7" ;;* 7=&Add Item...
varButSub := "TButton6" ;;* 6=Add s&ubmenu...
varButDel := "TButton5" ;;* 5=&Delete Item
varButTit := "TButton4" ;;* 4=Change &Title
varButOK  := "TButton3" ;;* 3=OK
varButCan := "TButton2" ;;* 2=Cancel
;;* 1=Help
}
}
 
DetectTitleOkButton()
{
; *** Autodetect name of OK-button in dialog "Add Item";
global
Loop, 3
{
ControlGetText, sTmp, TButton%a_index%
if (sTmp="OK")
{
sOkButName=TButton%a_index%
Break
}
}
if (sOkButName="")
{
MsgBox, Error: Version/Language autodetect failed (adding title), stopping script.
ExitApp
}
}
}
</pre>
</pre>

Revision as of 19:25, 25 June 2010

	; ////////////////////////////////////////////////////////////////////////////
	; // TC_StartMenu_DuplicateEntry.ahk V2.0
	; // (W) StatusQuo 2008-2010 for TC 7.02a (tested up to 7.04a, 7.50a and 7.55)
	; //
	; // Duplicates an entry in TC Start Menu or Directory Hotlist
	; ////////////////////////////////////////////////////////////////////////////

#SingleInstance, Force

	; *** set window class names
sClassMainWin := "TUSERMENUCHANGE"
sClassDialog  := "TSTDTREEDLG"

	; *** wait for & activate window
WinWait       , ahk_class %sClassMainWin%, 
IfWinNotActive, ahk_class %sClassMainWin%,, WinActivate, ahk_class %sClassMainWin%, 
WinWaitActive , ahk_class %sClassMainWin%,	; main "Change Start Menu"

/*
* /
sTmpButtonList := ""
Loop, 9
{
		; --- get button names
	sTmpVar := "sTmpButNam" . a_index
	ControlGetText, %sTmpVar%, TButton%a_index%
	sTmpButtonList := sTmpButtonList . a_index . "=" . %sTmpVar% . "`n"
}
MsgBox, %sTmpButtonList%
ExitApp
/*
*/

DetectButtonNames()	; get current button names

ControlGetText, AltEdit3, TAltEdit3, ahk_class %sClassMainWin%
ControlGetText, AltEdit2, TAltEdit2, ahk_class %sClassMainWin%
ControlGetText, AltEdit1, TAltEdit1, ahk_class %sClassMainWin%
ControlGetText, Edit3,    TEdit3,    ahk_class %sClassMainWin%	; old TC 7.04a
ControlGetText, Edit2,    TEdit2,    ahk_class %sClassMainWin%	; old TC 7.04a
ControlGetText, Edit1,    TEdit1,    ahk_class %sClassMainWin%	; old TC 7.04a
ControlGetText, V6Edit3,  Edit1,     ahk_class %sClassMainWin%	; old TC 6.56, replaces TAltEdit3; does not work properly!
ControlGet,     CheckBox2, Checked,, TCheckBox2, ahk_class %sClassMainWin%,	; main window, "as symbol"
ControlGet,     CheckBox1, Checked,, TCheckBox1, ahk_class %sClassMainWin%,	; main window, "fullscreen"
;TMyComboBox1	; Shortcut key
;TComboBox1	; Shortcut key	; old TC 7.04a

if (AltEdit3 . AltEdit2 . AltEdit1 <> "")
{
	sText1 := AltEdit1
	sText2 := AltEdit2
	sText3 := AltEdit3
} else {
	sText1 := Edit1
	sText2 := Edit2
	sText3 := Edit3
	if (Edit3 = "")
		sText3 := V6Edit3
}

	; *** get title of entry + *** Auto-detect name of Edit control
ControlSend,   %varButTit%, {Space},      ahk_class %sClassMainWin%,	; Button "Change Title"
WinWaitActive,                            ahk_class %sClassDialog%,	; dialog  "Change Title"
ControlGetText, sMenuTitle, TAltEdit1, ahk_class %sClassDialog%	; get old title
if (sMenuTitle = "")
{
	ControlGetText, sMenuTitle, TEdit1, ahk_class %sClassDialog%	; get old title
	sEditName1 := "TEdit1"	; TC 7.04a
	sEditName2 := "TEdit2"	; TC 7.04a
	sEditName3 := "TEdit3"	; TC 7.04a
	if (Edit3 . AltEdit3 = "")
		sEditName3 := "Edit1"	; TC 6.51
} else {
	sEditName1 := "TAltEdit1"
	sEditName2 := "TAltEdit2"
	sEditName3 := "TAltEdit3"
}
; ControlSend,   TButton1, {Space},         ahk_class %sClassDialog%,	; Button "Cancel", close "Change Title" dialog
DetectTitleOkButton()
ControlSend,   %sOkButName%, {Space},     ahk_class %sClassDialog%,	; Button OK, close "Title" dialog
WinWaitActive,                            ahk_class %sClassMainWin%,	; main hotlist editor window

	; *** sending {Space} to "Change title" button changes button names in Dir Hotlist (#1 gets "&>>" instead of "Help")
	; *** ControlClick instead of {Space} leaves button names unchanged
	; *** => redetect button names here
DetectButtonNames()	; get current button names

	; *** add new entry
ControlSend,   %varButAdd%, {Space},               ahk_class %sClassMainWin%,	; Button "Add Menu Entry"
WinWaitActive,                                     ahk_class %sClassDialog%,	; dialog  "Change Title"
ControlSetText, %sEditName1%, %sMenuTitle% [copy], ahk_class %sClassDialog%	; Title (TC7.04a:TEdit1, TC7.50a:TAltEdit1)
DetectTitleOkButton()
ControlSend,   %sOkButName%, {Space},         ahk_class %sClassDialog%,	; Button OK, close "Title" dialog
WinWaitActive,                                ahk_class %sClassMainWin%,	; main window

	; *** sending {Space} to "OK" button changes button names in Dir Hotlist (#1 gets "&>>" instead of "Help")
	; *** ControlClick does the same here
	; *** => redetect button names!
DetectButtonNames()	; get current button names

	; *** fill stored values from source entry	; TC 7.04a uses just TEdit1+2 for dir hotlist
ControlSetText, %sEditName3%, %sText3%, ahk_class %sClassMainWin%,	; main window	; TAltEdit3 / TEdit3
ControlSetText, %sEditName2%, %sText2%, ahk_class %sClassMainWin%,	; main window
ControlSetText, %sEditName1%, %sText1%, ahk_class %sClassMainWin%,	; main window
; if (sDialogType = "start")
; {
	if CheckBox2
		Control, Check,,   TCheckBox2, ahk_class %sClassMainWin%,	; main window
	else
		Control, UnCheck,, TCheckBox2, ahk_class %sClassMainWin%,	; main window
	if CheckBox1
		Control, Check,,   TCheckBox1, ahk_class %sClassMainWin%,	; main window
	else
		Control, UnCheck,, TCheckBox1, ahk_class %sClassMainWin%,	; main window

		; *** set cursor to command value
	ControlFocus, %sEditName3%, ahk_class %sClassMainWin%,	; main window	; TAltEdit3
	ControlSend,  %sEditName3%, {HOME}, 
; }

Return

; *****************************************************************************************************

DetectButtonNames()
{
	global
	ControlGetTExt, sButNam1, TButton1
	if (sButNam1="&>>")
	{
			; *** Starter menu (and Dir Hotlist after "Change Title" in TC 7.50a/7.55, using ControlClick or sending {Space})
		varButAdd := "TButton8"	;;* 8=&Add Item...
		varButSub := "TButton7"	;;* 7=Add s&ubmenu...
		varButDel := "TButton6"	;;* 6=&Delete Item
		varButTit := "TButton5"	;;* 5=Change &Title
		varButOK  := "TButton4"	;;* 4=OK
		varButCan := "TButton3"	;;* 3=Cancel
										;;* 2=Help
										;;* 1=&>>
	} else {
			; *** Dir Hotlist
		varButAdd := "TButton7"	;;* 7=&Add Item...
		varButSub := "TButton6"	;;* 6=Add s&ubmenu...
		varButDel := "TButton5"	;;* 5=&Delete Item
		varButTit := "TButton4"	;;* 4=Change &Title
		varButOK  := "TButton3"	;;* 3=OK
		varButCan := "TButton2"	;;* 2=Cancel
										;;* 1=Help
	}
}

DetectTitleOkButton()
{
		; *** Autodetect name of OK-button in dialog "Add Item"; 
	global
	Loop, 3
	{
		ControlGetText, sTmp, TButton%a_index%	
		if (sTmp="OK")
		{
			sOkButName=TButton%a_index%	
			Break
		}
	}
	if (sOkButName="")
	{
		MsgBox, Error: Version/Language autodetect failed (adding title), stopping script.
		ExitApp
	}
}

Back to AutoHotkey