CEA - Custom Event Actions

Features wanted...
Post Reply
autocart
Posts: 1246
Joined: 26 Sep 2013 15:22

CEA - Custom Event Actions

Post by autocart »

Hi Don,
I was thinking about this already for so long, now I simply ask it:

A Custom Event Action CAE_LocationChange (to take effect whenever the location in a XY pane changes) would be so much help for scripting customization IMHO.

I personally have some scripts that watch XY for location change from the outside. It would be so much better if XY could invoke a script in this case actively on its own.

So, now it is said. Hope you do not find it completely useless. This would really be one of my biggest wishes (no exaggeration).
But I do not want to stress you with this. Better the thought matures slowly than you being stressed.

Anybody else who would find this useful?
Regards, Stephan

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: CAE_LocationChange, pleeeeease...

Post by SkyFrontier »

In the meantime, I'd suggest a workaround (sorry if this is redundant to you, but valid for viewers after a solution anyway):

-endless/"timeoutless" script running in background (yeah, I hate this part...);
-at each 500/"x" ms get("pane"); store the value at [$ref];
-trigger if get("pane") != $ref, else do nothing.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

binocular222
Posts: 1416
Joined: 04 Nov 2008 05:35
Location: Hanoi, Vietnam

Re: CAE_LocationChange, pleeeeease...

Post by binocular222 »

+1
I asked this long time ago. I have to workaround using AHK:
- Push the <path> to Titlebar via ini tweak TitlebarTemplate="<path> - <app> <ver>"
- Use AHK to watch for Titlebar change:

Code: Select all

Settitlematchmode, 2
RenameXYplorer:
WinwaitClose, %CurrentTitle%
if(WinExist("ahk_class ThunderRT6FormDC") = 0)  ;XYplorer window is Closed
{
	Winwaitactive, XYplorer ahk_class ThunderRT6FormDC
	WinGetTitle, CurrentTitle, XYplorer ahk_class ThunderRT6FormDC
	gosub RenameXYplorer
}
Else 			;XYplorer change Tab location
{
	WinGetTitle, CurrentTitle, XYplorer ahk_class ThunderRT6FormDC
	FunctionMessagetoXYplorer("::load Rename3")
	gosub RenameXYplorer
}
This script triggers whenever <path> change instead of checking every xx ms.
Anyway, this is still a workaround.
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

autocart
Posts: 1246
Joined: 26 Sep 2013 15:22

Re: CAE_LocationChange, pleeeeease...

Post by autocart »

binocular222 wrote:- Use AHK to watch for Titlebar change
I know, because I gave you that hint back then. :mrgreen: :mrgreen:
Still, atm I am doing it as SF said (checking every 150 ms, though, or so in order to have a faster reaction time), because IF the path is too long then it gets truncated in the titlebar, making a reliable compare impossible, besides clogging up the titlebar like that is not really nice to look at.
Thinking of which, maybe it could help to use "short" DOS-paths instead of the full paths, making the truncation less likely. But would it then be 100% reliable, I wonder? Would have to do some testing. It surely also depends on what else is in the titlebar.
Regards

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: CAE_LocationChange, pleeeeease...

Post by admin »

The next beta will offer a Custom Event Action that will call a script of your making before or after browsing to a new folder. :beer:

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: CAE_LocationChange, pleeeeease...

Post by klownboy »

That sounds nifty. Would the script be able to execute different actions based on the new folder's location? Or, would the folder be a set location in XYplorer.ini file? If the latter was the case, you'd probably need multiple CEA entries in the ini.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: CAE_LocationChange, pleeeeease...

Post by highend »

No, you have to define on what folder the script reacts

Code: Select all

if (<newpath> LikeI "C:") {
    ...
} elseif (<newpath> LikeI "D:\Temp") {
    ...
}
The best way would to define a heredoc with all folders and their action(s) afterwards...
One of my scripts helped you out? Please donate via Paypal

autocart
Posts: 1246
Joined: 26 Sep 2013 15:22

Re: CAE_LocationChange, pleeeeease...

Post by autocart »

From the beta log:
v21.30.0005 - 2020-11-30 13:17
    + Custom Event Actions (CEA): Now you can run or load a script at the event 
      of browsing to a new folder. Note that there is no action when the current 
      folder is rebrowsed, i.e. refreshed.
      Like all CEAs, it is currently only implemented as a tweak.
      Example for the tweaked INI file:
        ; Tweak: 0=None, 1=Before Browse, 2=After Browse, 3=Both
        CEA_OnBrowseScript=1
        CEA_OnBrowseScript_Script=echo "Hi!"
      You would probably use a script that loads some script file that does 
      some interesting things. This would load "AfterBrowse.xys" (located in the 
      Scripts subfolder of the app data folder) after browsing a folder:
        CEA_OnBrowseScript=2
        CEA_OnBrowseScript_Script=load "AfterBrowse"
      To do something useful the script should know about the new path. You can 
      refer to it by the new variable <newpath>. It will return the full new 
      path, without trailing backslash. For example:
        CEA_OnBrowseScript=1
        CEA_OnBrowseScript_Script=echo "Going to <newpath>."
      If you want to call one script before and another script after the browse 
      you can pass 2 scripts separated by "||":
        CEA_OnBrowseScript=3
        CEA_OnBrowseScript_Script=echo "Going to <newpath>."||echo "Went to <newpath>."

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: CAE_LocationChange, pleeeeease...

Post by highend »

A bit more sophisticated / user changeable...

Code: Select all

    $actions = <<<>>>
        D:\Users\%USERNAME%\Bilder|#308
        D:\Users\%USERNAME%\Dropbox|#309
    >>>;
    $actions = regexreplace($actions, "^[ \t]+");

    foreach($action, $actions, <crlf>, "e") {
        $path = trim(gettoken($action, 1, "|"), "\", "R");
        $cmd  = gettoken($action, 2, "|", "t", 2);

        if (<newpath> LikeI $path) {
            load $cmd, , "s";
            break;
        }
    }

One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: CAE_LocationChange, pleeeeease...

Post by klownboy »

Sounds great! I hadn't realized Don had already issued the beta when I wrote my comment. Thanks guys and Don of course.

You could probably use a switch statement for this as well.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: CAE_LocationChange, pleeeeease...

Post by admin »

I would recommend to resolve <newpath> before any loop. Just a habit to gain speed...

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: CAE_LocationChange, pleeeeease...

Post by highend »

I can't see any speed improvements assigning <newpath> before the loop and do the comparison with that variable instead...
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: CAE_LocationChange, pleeeeease...

Post by admin »

But I can because I see the code. :) Resolving script variables is faster. Should be. Or did you test it?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: CAE_LocationChange, pleeeeease...

Post by highend »

Of course I did test it before :)

Code: Select all

    $start = now("msecs");
    while($i++ < 10000) {
        if ("path_x" LikeI <curpath>) {
        }
    }
    status "Time: " . now("msecs") - $start . " msecs";
    // Result = 1828
    
    $current = <curpath>;
    $start = now("msecs");
    while($i++ < 10000) {
        if ("path_x" LikeI $current) {
        }
    }
    status "Time: " . now("msecs") - $start . " msecs";
    // Result = 1818
These values vary a bit but they're always very close together and 10 ms on 10.000 runs... Neglectable...
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: CAE_LocationChange, pleeeeease...

Post by admin »

Interesting, thank you! :tup:

Post Reply