AHK:: Find Files : Toggle Modal

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

AHK:: Find Files : Toggle Modal

Post by *Balderstrom »

AHK Script, original post easily toggle the "Modal-ness" of the search window, with the Search hotkey, ALT+F7.
AutoHotkey script wrote:Alt+F7::
1) Make the find dialog non-modal, AND
2) If a Find Dialog exists, and is active, Alt+F7 minimizes it.
---- Can then use TC as normal.
3) If a Find dialog exists, and is minimized, Alt+F7 restores it.
---- Find Window becomes modal again.

Code: Select all

;; 
;; TC_FindFilesModalFix.ahk
;;    Version 1.2
;;    Balderstrom, Nov.2011
;;
;;    TC:  Compatible with TC 7.56 and TC 8.0beta
;;    OS: Tested with Win2K and Win7 (x64)
;;    AHK: Current version of AHK_L (for sure), 
;;          likely will work with the deprecated AHK from 2009.
;;

	#SingleInstance, Force 
	#Persistent
	#NoEnv
SetBatchLInes, -1
SendMode Input

GroupAdd, TCWinFF, ahk_class TTOTAL_CMD
GroupAdd, TCWinFF, Find Files ahk_class TFindFile

#ifWinActive, ahk_group TCWinFF
	$!F7::TCFindFiles(WinActive("ahk_class TTOTAL_CMD"))
return

TCFindFiles( tcWin )
{
	if( tcWin && !(ffWin:=WinExist("ahk_class TFindFile")))
		PostMessage, 0x433, 501, 0,, A
	else
	if( !tcWin ) 
	{
		tcWin:=DllCall("GetWindow", "uint", ffWin:=WinExist("A"),"int",4)	; GW_OWNER
		WinGetClass, aClass, ahk_id %tcWin%
		if( aClass == "TTOTAL_CMD" )
		{
			WinMinimize, ahk_id %ffWin%
			WinActivate, ahk_id %tcWin% ; Win7 FIX
		}
	}
	else
	{	;; TOTAL COMMANDER is active, and a TFindFile exists.
		ownerID:=DllCall("GetWindow", "uint", ffWin,"int",4)	; GW_OWNER
		if( ownerID == tcWin )
		{
			WinRestore,  ahk_id %ffWin%
			WinActivate, ahk_id %ffWin%
		}
		else
			PostMessage, 0x433, 501, 0,, A
	}
	WinSet, Enable,, ahk_id %tcWin%
return
}

History:

V1.0 : Original Script
V1.1 : Fix for multiple instances of TC.
V1.2 : Small compatibility fix for Win7.
User avatar
hoppfrosch
Junior Member
Junior Member
Posts: 67
Joined: 2004-10-20, 05:39 UTC

Post by *hoppfrosch »

:-(
Does not work here ...
Pressing ALT-F7 brings up the "Find Files" dialog as usual. ("Find Files" is modal as ever ...)
Pressing ALT-F7 again does have no more effect - "Find Files" stays on top and remains modal ...


TC8 Beta9
AHK_L 1.1.05.01
Win7 64bit Ultimate
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6967
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Post by *Horst.Epp »

hoppfrosch wrote::-(
Does not work here ...
Pressing ALT-F7 brings up the "Find Files" dialog as usual. ("Find Files" is modal as ever ...)
Pressing ALT-F7 again does have no more effect - "Find Files" stays on top and remains modal ...


TC8 Beta9
AHK_L 1.1.05.01
Win7 64bit Ultimate
Works here in the same environment !
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

@hoppfrosch,
If you've installed AHK or preferably AHK_L, and launched the script... Not sure what it could be. I likewise am using Win7 x64 Ultimate.

Note, AHK Scripts generally go in "Documents\AutoHotkey".

You could try running the script as Admin.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
User avatar
LonerD
Senior Member
Senior Member
Posts: 381
Joined: 2010-06-19, 20:18 UTC
Location: Makeyevka/Makiivka
Contact:

Post by *LonerD »

Hi Balderstrom.
Thanks for script. I compile it into FindFilesModalFix.exe and run it with cm_SearchFor command with TCMC.

Please, help modify script. I want to automatical close FindFilesModalFix.exe process when I close "Find Files" dialog window.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

AddThis

Code: Select all

#ifWinActive Find Files ahk_class TFindFile

	$ESC::
		aWin:=WinActive("A")
		Send, {ESC}
		Sleep, 250
		if(!WinExist("ahk_id " aWin))
			ExitApp
	return

	$~LButton::
		if( WM_NCHITTEST() <> "CLOSE" )
			return
		aWin:=WinActive("A")
		KeyWait, LButton
		Sleep, 50
		if(!WinExist("ahk_id " aWin))
			ExitApp
		return
return

WM_NCHITTEST() 
{ 
	CoordMode, Mouse, Screen 
	MouseGetPos, x, y, z 
	SendMessage, 0x84, 0, (x&0xFFFF)|(y&0xFFFF)<<16,, ahk_id %z% 
	RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" ErrorLevel+2&0xFFFFFFFF "}(?<AREA>\w+\b)", HT) 
Return   HTAREA 
} 
User avatar
LonerD
Senior Member
Senior Member
Posts: 381
Joined: 2010-06-19, 20:18 UTC
Location: Makeyevka/Makiivka
Contact:

Post by *LonerD »

Balderstrom
Thanks. It work in most cases.
But sometime FindFilesModalFix process continues to work when I close the Find Files window.
For example, I noted that the process is working when I turn from the search box to the file that was found
aamurph
Junior Member
Junior Member
Posts: 2
Joined: 2011-12-22, 13:54 UTC

Post by *aamurph »

LonerD wrote: But sometime FindFilesModalFix process continues to work when I close the Find Files window.
Hm, didn't happen to me
Last edited by aamurph on 2011-12-29, 19:23 UTC, edited 1 time in total.
User avatar
LonerD
Senior Member
Senior Member
Posts: 381
Joined: 2010-06-19, 20:18 UTC
Location: Makeyevka/Makiivka
Contact:

Post by *LonerD »

But sometime FindFilesModalFix process continues to work when I close the Find Files window.
Corrected - when I go to finded file or press Cansel - then FindFilesModalFix not closed.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Try this, if you find the script still running after clicking Cancel, then up the Sleep period from 50 to 100 or so.

Code: Select all

#ifWinActive Find Files ahk_class TFindFile 

    $ESC:: 
       aWin:=WinActive("A") 
       Send, {ESC} 
       Sleep, 250 
       if(!WinExist("ahk_id " aWin)) 
          ExitApp 
    return 

    $~LButton:: 
       exitScript:=(WM_NCHITTEST() == "CLOSE")
       aWin:=WinActive("A") 
       KeyWait, LButton 
       Sleep, 50 
       if(exitScript || !WinExist("ahk_id " aWin)) 
          ExitApp 
       return 
 return 

 WM_NCHITTEST() 
 { 
    CoordMode, Mouse, Screen 
    MouseGetPos, x, y, z 
    SendMessage, 0x84, 0, (x&0xFFFF)|(y&0xFFFF)<<16,, ahk_id %z% 
    RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" ErrorLevel+2&0xFFFFFFFF "}(?<AREA>\w+\b)", HT) 
 Return   HTAREA 
 }
User avatar
LonerD
Senior Member
Senior Member
Posts: 381
Joined: 2010-06-19, 20:18 UTC
Location: Makeyevka/Makiivka
Contact:

Post by *LonerD »

Balderstrom
Thanks.

You can make an extended script that will be resident work during TC working?
The script must follow the different modal windows (search, comparison, synchronization, group rename). If they active, script make it non-modal automatical. When user press Shift + Escape (or some other common shortcut keys) - this windows minimized. Also if user click on minimize button in this window - then minimized only this window, not TC
Koshmaar
New Member
New Member
Posts: 1
Joined: 2015-01-05, 14:53 UTC
Location: Gdansk

Post by *Koshmaar »

hoppfrosch wrote::-(
Does not work here ...
Pressing ALT-F7 brings up the "Find Files" dialog as usual. ("Find Files" is modal as ever ...)
Pressing ALT-F7 again does have no more effect - "Find Files" stays on top and remains modal ...

TC8 Beta9
AHK_L 1.1.05.01
Win7 64bit Ultimate
Doesn't work for me also - alt+f7 simply brings the find files dialog, while pressing alt+f7 on it again, makes the dialog and TC window blink/dance, but it doesn't change anything. I put the file in a separate script.

TC 8.51a 64 bit
AHK 1.0.48.05
Windows 8/x64

Would switching to AHK_L make this work? Having this script work would be so awesome... the modal seach window is seriously irritating.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

All my scripts are based on Lexikos AHK @ ahkscript.net (autohotkey.com is a bad joke, they offer a version that is 8+ years old, and is never going to be updated)

I don't know if this one will work with TC x64 or not. I stopped supporting x64 and didn't even bother installing TC on my laptop.

My reasons can be summed up in this thread: Mouse scroll through directory tabs (aka Firefox-feature), and in my sig.

I primarily use MultiCommander, and some FileExplorer extensions like QT-TabBar.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
sgp
Senior Member
Senior Member
Posts: 355
Joined: 2005-01-31, 16:04 UTC

Post by *sgp »

Balderstrom wrote: My reasons can be summed up in this thread: Mouse scroll through directory tabs (aka Firefox-feature), and in my sig.
Very informative. Let me try to summarize my understanding of it. Although the thread title is just about mouse scrolling tabs, the underlying point is that TC lacks scripting capabilities, and some forum members are frustrated that Ghisler hasn't taken action so far. More frustration arises from 64-bit TC, which isn't fully compatible with external scripting engines, like powerpro and AHK_L, because many existing, member-developed scripts don't work with 64-bit TC. Is my summary correct?

I for one would love to see scripting added to TC. I tried scripting XYplorer and I was impressed at how easy and useful it is.
I primarily use MultiCommander, and some FileExplorer extensions like QT-TabBar.
How are you finding multicommander's scripting engine? I know powerpro well and some AHK_L, is MC's scripting similar? What sort of things have you done with it?
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

sgp wrote:
Balderstrom wrote: My reasons can be summed up in this thread: Mouse scroll through directory tabs (aka Firefox-feature), and in my sig.
Very informative. Let me try to summarize my understanding of it. Although the thread title is just about mouse scrolling tabs, the underlying point is that TC lacks scripting capabilities, and some forum members are frustrated that Ghisler hasn't taken action so far. More frustration arises from 64-bit TC, which isn't fully compatible with external scripting engines, like powerpro and AHK_L, because many existing, member-developed scripts don't work with 64-bit TC. Is my summary correct?
Scripting in TC 32bit was always not straight-forward, but we made do - even with minimal support from Ghisler. Scripting in x64 is almost impossible - it can be done, but since so many "control-names" are called 'Window##' you cannot easily/or accurately query for a piece of info that can be used. Yes yer summary is pretty spot on.

I have 1000+ lines of scripts (mostly libraries) for interfacing AHK with TC - almost none of that works with x64. I don't need any libraries to interface with File Explorer, or MC (C++ program with proper control names) --- although I don't think it reacts to SendMessage/PostMessage that is easily worked around with it's Alias/UserDefinedCommands abilities.

There have been numerous suggestions on how to resolve this problem, every suggestion is shot down by Ghisler, or he claims it isn't possible, or he lies (or forgets?) about the actual capabilities of WM_COPYDATA that he finally implemented 3+ years ago. Where he states "WM_COPYDATA" can only return an integer... what he implemented 3 years ago isn't limited to only returning an integer. It's not limited in any way at all --- beyond the limitations he has created by what can be queried. WM_COPYDATA could return Megabyte+ sized variables if needed (without memory leaks).
sgp wrote:I for one would love to see scripting added to TC. I tried scripting XYplorer and I was impressed at how easy and useful it is.
I primarily use MultiCommander, and some FileExplorer extensions like QT-TabBar.
How are you finding multicommander's scripting engine? I know powerpro well and some AHK_L, is MC's scripting similar? What sort of things have you done with it?
Personally, I haven't done a whole lot with its scripting capabilities. A lot of my time has been consumed with staying on top of WebDevelopment changes, and trying to get our base (starting) platform off of Joomla to ProcessWire.

As far as I can tell, from discussions with Mathias (author), the forum ,(decent) documentation, and using some of the examples --- it seems to be about as robust as XYPlorer's scripting capabilities.

The syntax is pretty standard, so it's mostly just a matter of looking up what the MC (internal) function is. It does have one odd quirk, which you'll see in the examples below ::
@var $varname = "foo"; // to create/assign a variable
$varname // to query a variable.
$varname = "foobar"; // assign an already created variable.

(I've seen such syntax before, but it's not common).

Here's a few examples from the MC Script docs

Search on google from the commandline bar
Take the parameters to this command and build a search url for google and then go to that url.

Create the command. then go to the Alias Manager and assign 'g' to "@<Unique command id>"

Code: Select all

function CreateGoolgeSearchQuery()
{
  @var $query = "";
  @var $n = 0;
  for( $n = 0; $n < $argcount; $n = $n + 1 )
  {
    if( $n > 0 )
    {
      $query = $query + "+";
    }
    $query = $query + $arg($n);
  }
  return $query;
}
@var $s = "";
$s = "http://www.google.com/search?g=" + CreateGoolgeSearchQuery();
MC.Run CMD="{$s}" SHELL
View first *.txt file found in the folder currently in focus

Connect this command to a hotkey, for example ALT+V. When you then in the explorer panel have a folder in focus, if you press ALT+V and if a *.txt file exists under that folder, that file will now be shown.

Code: Select all

MC.DataViewer.View FILE={_findfirstfile( "{focusfilepath}\\*.txt" )}

Play First *.avi or *.mkv found in folder currently in focus

Connect this command to a hotkey, for example ALT+P. When you then in the explorer panel have a folder in focus, if you press ALT+P, the first *.avi or *.mkv found will be played in your default movie player.;

Code: Select all

@var $file;
$file = _findfirstfile( "{focusfilepath}\\*.avi" );
if(StrIsEqual($file,""))
{
  $file = _findfirstfile( "{focusfilepath}\\*.mkv" );
}
MC.Run CMD={$file} SHELL

And yes, My sig is kinda assholish, but its pretty damned true, and it's about the only protest I know how to make. I'm sure in a few more years I wont care at all. And will leave like a number of other high-profile posters/users have in the past - which either moved on to Linux/Mac or other File Managers for Windows.

OT:
I showed the wife the thread about TC 9... her response was something to the effect of, "I can't believe he just said he doesn't see any point in making his program 10% better. Why do those people (TC users) put up with his attitude??!" (Along her usual refrain to the odd post I show to her, "I can't believe he said that.", "I can't believe he said no cuz his users are *idiots", "I can't believe he said no, <insert some other excuse here>"

Which again, kinda proves my sig, no?


(*) Ghisler never used the term 'idiots' but phrased in a way that said, It might cause data loss in a rare case (UNDO function), user might expect X but in a rare case would get Y. Or his stance on Junction/Hardlink/Symlink support - that it's too complicated for his users (pretty close to calling us idiots). And in that case Ghisler flat out refused assistance from Hermann Schinagl to help integrate Link Shell Extension with TC.

Or one of my **favorites FTP Editing online Files (Improvement), which has been requested in some form or another since ~2005?... I think it was implemented in 2012-2013? I don't know I stopped using TC for FTP/SFTP. Easier to just locally edit, and run an "scp" script (to upload) when the file changed (locally). Or just use a SFTP aware editor.

(**) favorite, meaning: I couldn't freaking believe he found an excuse not to do that request either.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
Post Reply