Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Display Total Commander Favorites menu anywhere


  • Please log in to reply
10 replies to this topic
majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Features:
- Full TC's favorites menu
- If called inside active dialog (save, open, browse):
   - if path is choosen, change the path IN dialog
   - if plugin is choosen, start or activate TC and switch to the plugin
- If called on ANY active window that is NOT the dialog activate or open TC
- If called on TC, redirect to TCs own dialog to be able to see configuration enteries

Soon:
- Add current source and target
- Add submenu with environement variables which point to valid paths
- Add submenu with system folders: My Computer, Control Panel, Recycle Been
- Refresh menu on every call to reflect recent changes inside TC

Setup
Edit path to ini and executable and set cm_DirectoryHotlist & cm_editpath to hotkeys you use.
If you want to handle more dialogs like Open/Save put desired keywords in Dialogs variable.

Please report bugs if you find them.

;============================  SETUP ==================================
tcExe = %COMMANDER_PATH%\TotalCmd.exe
tcIni = %COMMANDER_PATH%\wincmd.ini

 cm_DirectoryHotlist = !1
   cm_editpath =^{F2}    

cm_CopySrcPathToClip = ^+!{F3}  ;for future
cm_CopyTrgPathToClip = ^+!{F4}  ;for future

dialogs = Open,Save,Browse,Find
;======================================================================
Menu tray, icon, %SystemRoot%\System32\shell32.dll, 44
SetKeyDelay, -1 

g_sub_cnt = 0
g_mnu_cnt = 0

CreateFullMenu()

;------------------------------------------------------------------------
;------------------------------------------------------------------------

^w::
 ;handle Total COmmander; call its own menu
 IfWinActive ahk_class TTOTAL_CMD
 {
  Send %cm_DirectoryHotlist%
  return
 }

 Menu, sub1, show, A_CaretX, A_CaretY  
return

;-------------------------------------------------------------------------

CreateMenu()
{
 local separator, cmd_cnt, submenu_id, sub_num
 
 separator := false
 cmd_cnt  = 0
 g_sub_cnt += 1


 sub_num  = %g_sub_cnt%
 submenu_id = sub%sub_num%

 Loop 
 {
  ;read next menu item 
  g_mnu_cnt += 1
  IniRead, mnu, %tcIni%, DirMenu, menu%g_mnu_cnt%, & 
  IniRead, cmd, %tcIni%, DirMenu, cmd%g_mnu_cnt% 
  if (mnu = "&")
   break

  ;is it separator ?
  if (mnu = "-")
      { 
   if ( separator = true )
    continue 
   separator := true

   Menu, %submenu_id%, add 
   cmd_cnt += 1
   continue 
   } 

  ;not a separator, determine what is it from next 2 charachters
  StringMid, c1, mnu, 1, 1 
  StringMid, c2, mnu, 2, 1 

  ; "--" exit condition (end of submenu), return this menu to the caller
  if (c2 = "-")
   return %submenu_id%
  
  ; "-....." submenu, create it
  if (c1 = "-")
  {
   StringMid, name, mnu, 2, 100 
   Menu, %submenu_id%, add, %name%, % ":" . CreateMenu()

   cmd_cnt += 1
   continue
  }

  Menu, %submenu_id%, add, %mnu%, MenuHandler
  cmd_cnt += 1
     command%sub_num%_%cmd_cnt% := cmd

  separator := false
 }
}

;-----------

MenuHandler:

 j := A_ThisMenuItemPos
 if (A_ThisMenu = "sub1")
	j -= 0  ;substruct custom items here (for future)
 StringReplace i, A_ThisMenu, sub,
 keys := % command%i%_%j%

 ; cd \\\plugin  - call total commander unconditionaly
 ; cd path  - send keys if dialog else call TC
 StringMid keys, keys, 4
 StringGetPos tmp, keys, \\\
 if (tmp != -1)
   openTC(keys)
 else {
  WinGetActiveTitle active_title
  if active_title contains %dialogs%
  {
   SendInput %keys%{ENTER}
   return
  }
  openTC(keys) 
 }
 
return 

;--------------------------------------------------------------------------

OpenTc(keys)
{ 
 global

 if not WinExist("ahk_class TTOTAL_CMD")
 {
  Run %tcExe%
  WinWait, ahk_class TTOTAL_CMD
 }
  
 WinActivate ahk_class TTOTAL_CMD
 Send %cm_editpath% 
 SendRaw, %keys%
 Send, {ENTER}
}

;--------------------------------------------------------------------------

CreateFullMenu()
{
 global

 ; to do - add left and right panel
 ifWinExist ahk_class TTOTAL_CMD1
 {
  ControlSend ,,%cm_CopySrcPathToClip%
  Menu sub1, add,  %clipboard% , FullMenuHandler
  
  ControlSend ,,%cm_CopyTrgPathToClip%
  Menu sub1, add,  %clipboard% , FullMenuHandler

  Menu sub1, add
 }

 CreateMenu()
}


FullMenuHandler:
; to do
return


Posted Image

Chicken Pie 4 Tea
  • Members
  • 379 posts
  • Last active: Dec 12 2014 06:46 PM
  • Joined: 18 Aug 2009
wow took me ages to come across this, will be really useful, thanks and cant believe no replies! am I the ony one left using TC?
"Choose your parents wisely"

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
You might like to try Favmenu 3 (or 2) here:
http://www.autohotke... ... ht=favmenu

Chicken Pie 4 Tea
  • Members
  • 379 posts
  • Last active: Dec 12 2014 06:46 PM
  • Joined: 18 Aug 2009
Thanks for the link Hugov, it's a much updated version. I dont feel so lonely as a TC user now :D
"Choose your parents wisely"

kodybrown
  • Members
  • 6 posts
  • Last active: Aug 02 2015 11:14 PM
  • Joined: 14 Dec 2007
I use Total Commander (#E) and AutoHotkey all day, constantly!!
Thank you for such great code!! 8^)

I had to make one change because I don't have a shortcut defined to change the current path. I thought I'd share it, here is that code:

OpenTc(keys)
{ 
	global

	if not WinExist("ahk_class TTOTAL_CMD")
	{
		Run %tcExe%
		WinWait, ahk_class TTOTAL_CMD
	}
	
	Sleep 100 ; I had weird issues where TC wouldn't always show up without this Sleep here..
	WinActivate ahk_class TTOTAL_CMD
	
	;Send %cm_editpath%
	;SendRaw, %keys%
	;Send, {ENTER}
	
	; This works well for me...
	Sleep 100
	Send ^T ; Open new tab
	Sleep 50
	;Send {Home} ; If you don't open a new tab, send Home before F2..
	Send {F2}
	Sleep 50
	SendRaw %keys%
	Sleep 100
	Send {ENTER}
}

Then I realized I don't really need that, because I don't want the Ctrl+D overriding default application behaviors (such as create bookmark in Chrome), unless the active window is a file dialog. Here is that code:

; I changed the shortcut from ^W to ^D to match TC's default
^D::

	;handle Total Commander; call its own menu
	IfWinActive ahk_class TTOTAL_CMD
	{
		Send %cm_DirectoryHotlist%
		return
	}

	; Only show the popup menu when there is a
	; popup dialog active..
	WinGetActiveTitle active_title

	if active_title contains %dialogs%
	{
		; todo: Make sure the textbox is the active control?
			
		; Show the menu..
		Menu , sub1, show, A_CaretX, A_CaretY  
	}
	else
	{
		; Send the Control+D to the application, like normal
		; todo: this doesn't seem to work correctly!?
		Send ^D
	}

return

So, the second code segment really makes the first un-necessary, but I thought someone else might like it.



I have a couple questions though...

1) Using the second code block; when I am in other applications (for instance Chrome) and a file open dialog is not active. I want the code to create a bookmark, but the Send ^D does not seem to work!?

2) How do I ensure that the active control on the file dialog is the textbox!? I don't know even what to search for?


Any ideas?

Thanks,
Kody

kodybrown
  • Members
  • 6 posts
  • Last active: Aug 02 2015 11:14 PM
  • Joined: 14 Dec 2007
I just realized what is happening with my second question..

The Send ^D command is sending Ctrl+Shift+D, instead of just Ctrl+D..

I'm not sure how to fix that though.. I'm looking for more details now..

comvox
  • Members
  • 143 posts
  • Last active: Jan 29 2017 06:53 AM
  • Joined: 20 May 2009

The Send ^D command is sending Ctrl+Shift+D, instead of just Ctrl+D..

Try Send ^d

kodybrown
  • Members
  • 6 posts
  • Last active: Aug 02 2015 11:14 PM
  • Joined: 14 Dec 2007
Thanks for the suggestion! I tried it and now the Ctrl+D in Chrome does nothing.. (Still works within the file open dialog, just not the normal create bookmark behavior without the dialog open..)



Actually, after trying it for a few seconds I got this error:

| 71 hotkeys have been received in the last 109ms.
|
| Do you want to continue?
| (see #MaxHotkeysPerInterval in the help file)
|
| [Yes] [No]

I didn't hold down the key, nor press that many times that fast obviously! :-) When I click yes, it starts over; No closes the script.


I am not sure why it does this now or what the difference is between ^D and ^d..

Any other ideas?

comvox
  • Members
  • 143 posts
  • Last active: Jan 29 2017 06:53 AM
  • Joined: 20 May 2009

Actually, after trying it for a few seconds I got this error:

71 hotkeys have been received in the last 109ms.

So many hotkeys firing would seem to indicate a vicious circle. And what I didn't notice is that you define ^D as a hotkey and then in the definition of this hotkey, use Send ^D, which triggers the ^D hotkey again. (Same problem if they are small d's.) To prevent this vicious circle, one can define $^D as the hotkey, where the "$" modifier prevents the Send ^D from triggering the hotkey again.

As to the difference between ^D and ^d, it's the difference between holding down control and pressing capital D, and holding down control and pressing small d. However, the prompts in interfaces generally ask one to supply Control-D, when they mean ^d. If they meant ^D, they would ask for Control-Shift-D.

kodybrown
  • Members
  • 6 posts
  • Last active: Aug 02 2015 11:14 PM
  • Joined: 14 Dec 2007
Dang!! I can't believe I didn't see that!! Thanks for the help comvox!

You're right, that was definitely the problem. I changed the shortcut to $^D as you suggested and it works perfect now! I didn't know you could do that, Thank you so much!

And, thanks for the additional info too!

Kody

comvox
  • Members
  • 143 posts
  • Last active: Jan 29 2017 06:53 AM
  • Joined: 20 May 2009
You're very welcome, Kody. I'm glad it worked! Autohotkey does have a lot of amazing stuff in it, doesn't it?!