AHK-script for MiniTree - automatic expanding and collapsing

Discuss and share scripts and script files...
autocart
Posts: 1248
Joined: 26 Sep 2013 15:22

AHK-script for MiniTree - automatic expanding and collapsing

Post by autocart »

[edited multiple times]

Hi all,

Topic MiniTree: Vanilla XY only gives you the option to expand the destination node (current path) in the tree if you manually click on it in the tree. By other navigation means the tree normally syncs but the dest node does not expand, if it is collapsed. And even then, it is not sure that all the subfolders are expanded, since it is the MiniTree. Also, the auto-optimization only works if you expand a node in the tree, which means you must click on it in the tree, but again, not if the folder you are navigating to is already expanded. For some, maybe even for the most (?), this may work and suit their work-flow. But somehow it's hard for me to fully get used to it.
Therefore, I made 2 AHK-scripts for a more customizable auto-optimization (expanding and collapsing) of the minitree. One very simple and one more complex script. (They are still under development and need YOUR help to reach their full potential. ;) )

In both versions I check XY (with AHK) every 150 ms for a folder change. It is not noticealbe to me as far a CPU usage. But it does mean that this extra script needs to run continuosly in the background apart from XY. Of course since it is AHK, AHK needs to be installed or else, for the brave ones, I also provide a compiled exe in the download besides the code (because of a user wish :o ).

The simple version will only expand the destination node in the MiniTree, regardless of how one navigates there. This version is called "XYplorer_MiniTreeExpandDestination". (It does not depend on an ini file as does the other version.)

The more complex version is called "XYplorer_MiniTreeBrowsing". It works like this:
If folder change occured it collects the folders I want to display in minitree and updates the minitree by way of "loadtree".
In effect, this means that the whole current minitree is deleted and replaced by the following folders.

The script collects:
now current folder (must be first entry of course)
favorite mini tree folders (read out of the XYplorer.ini file)
all direct (not recursive) sub-folders of the current folder -> This can be turned on/off in a seperat ini file (details in the ini incl. in download).
all sibling folders of the current folder (up to a max. count, defined in the ini file; if the count of folders would be higher than defined maximum, then no siblings are displayed at all; setting it to 0 turns it completely off; setting it to nothing turns it completely on. One can also define parent-paths in the ini who's children should never be displayed as siblings.)
certain paths that are calculated dynamically based on path groups (for more detail see the ini-file or this post: http://www.xyplorer.com/xyfc/viewtopic. ... 45#p112381)

The collection of all these folders and the loading by way of "loadtree" happens so fast that it feels almost natural. I have an Intel Core i5 650@3.20GHz and 4GB RAM. Most folders I access are on the company network. I do not know the specs of the network/server. But as said, everything is very fast.

MiniTree of course needs to be turned on. Else, with normal tree, the script has no effect at all. I did not test all XY-Settings in connection with this script, though.

The script works with an ini file (as mentioned), which must be named "XYplorer_MiniTreeBrowsing.ini".
The default ini file is included in the download.
The ini needs to be located in the xydata path. (Format based on SkyFrontier's suggestion ;) )
You can put it in the XYplorer-data-path manually. Else, if it is not there the script tries to create it automatically on the first run of the exe.

Hint:
For an "optimized" MiniTree-browsing experience in connection with this script you might want to try turning OFF "Expand dest node in tree", "Expand tree nodes on sgl click" and "auto-optimize tree" (Tools menu/Configuragtion.../General/Tree and List/Tree). It might also be influenced by "Lock Tree" (View menu). Maybe you will notice a difference and maybe not.


Feedback welcome, thx!

Newest version can be downloaded "always" from here:

!!!! USAGE AT EVERYONE'S OWN RISK !!!!!!!!
XYplorer_MiniTreeExpandDestination v0.003.zip
(384.31 KiB) Downloaded 210 times
XYplorer_MiniTreeBrowsing v0.013.zip
(391.98 KiB) Downloaded 182 times
some previous versions:
XYplorer_MiniTreeExpandDestination v0.002.zip
(383.98 KiB) Downloaded 167 times
XYplorer_MiniTreeExpandDestination v0.001.zip
(383.83 KiB) Downloaded 179 times
XYplorer_MiniTreeBrowsing v0.012.zip
(391.81 KiB) Downloaded 159 times
XYplorer_MiniTreeBrowsing v0.011.zip
(388.63 KiB) Downloaded 173 times
Change-Log:

XYplorer_MiniTreeExpandDestination:
v0.003: improved the handling of differentiating btw. navigating "upwards" in path and collapsing a super-node of the current path (which also results in an "upward"-navigation but in which case the node obviously is not desired to be reopened immediately)
v0.002:
added a work around for making mouse down blowup work again in connection with this script
added work-around for cycling through tabs with a KS including the SHIFT-key (loadtree would trigger a new tab together with SHIFT); now the script waits until SHIFT is released

XYplorer_MiniTreeBrowsing:
v0.013:
added ignorance for search results (sometimes it could have come to interferences)
added a version check; XY must be at least "14.50.0107" (needed for ignoring search results)
v0.012:
new ini-file
added a switch in the ini-file to toggle the termination behaviour of the script (details in the ini-file)
changed the meaning of the value of showDirectSubfolders slightly (in order to be more logical); now: 0 or blank means no. Everything else means yes.
introduced path groups (for more detail see the ini-file or this post: http://www.xyplorer.com/xyfc/viewtopic. ... 45#p112381)
v0.011: added ignorance for paper folders (before paper folder caused a problem, since they are not visible in the tree)
v0.010: improved the handling of differentiating btw. navigating "upwards" in path and collapsing a super-node of the current path (which also results in an "upward"-navigation but in which case the node obviously is not desired to be reopened immediately)
v0.009: added a work around for making mouse down blowup work again in connection with this script
v0.008:
changed "refresh" (#1001) to "refresh tree" (#482)
added the script name & versionNr to the XYplorer window title
added check if the new path is a parent to the previous path -> no action if yes (then the tree hopefully does not need any refreshment, but especially clicking the minus-symbol would not work right otherwise)
added work-around for cycling through tabs with a KS including the SHIFT-key (loadtree would trigger a new tab together with SHIFT); now the script waits until SHIFT is released
added limitation of effects to first found XY-instance; script gets terminated if this instance closes
v0.007:
added support for dynamic drives
added a security check, so that the script only takes effect if the MiniTree is turned on manually
added a refresh (#1001;) after loadtree
added an option to the ini file: "showDirectSubfolders" (1 means yes. Everything else means no.)
v0.006:
changed behaviour of maxDisplayedSiblings: in order not to use it (deactivate it) simply do not define any number (leave blank)
corrected a bug with FileAppend writing ini if it was not there
added #SingleInstance force
v0.005: corrected an error popping up when browsing to a drive that is not ready, e.g. empty CD-ROM drives
v0.004: simplified the ini file
Last edited by autocart on 29 Sep 2014 13:00, edited 45 times in total.

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

Re: AHK-script for better surfing of minitree

Post by SkyFrontier »

Please!
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...

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

Re: AHK-script for better surfing of minitree

Post by autocart »

SkyFrontier wrote:Please!
I was afraid, someone would say that. Now I have to clean up the code :wink:
I'll post it in a few moments.

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

Re: AHK-script for better surfing of minitree

Post by SkyFrontier »

Thanks in advance, then!
With my humble apologies...
;)
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...

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

Re: AHK-script for better surfing of minitree

Post by autocart »

I was faster with clean up than what I thought: :D

!!!!!!!! USAGE OF CODE ONLY AT OWN RISK !!!!!!!

One optical "problem": With "loadtree" the subfolders in the tree are not checked by XY. Therefore it always displays the ugly '+' sign in the minitree. I did not find a way around this.

AHK-code:

Code: Select all

   #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
   #Persistent

    global XY_eval_and_returnvalue_XYRETURN
    global XY_max_number_of_siblingFolders_shown_in_MiniTree

	XY_max_number_of_siblingFolders_shown_in_MiniTree := 30


    ;***************************************************************************************
    ;** code from others (or based on) **
    ;***************************************************************************************

    ;heavily based on
    ;http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=9233&p=89555&hilit=messenger#p89555
    
    ;~ MsgBox % A_ScriptHwnd + 0
    ;~ OnMessage(0x4a, "Function_Receive_WM_COPYDATA")

        XY_eval_and_returnvalue(stringToEval)          ;Send message to XYplorer
        {
          global XY_eval_and_returnvalue_XYRETURN
          SenderHWND := A_ScriptHwnd + 0  ;Return this script's hidden hwdn id.  +0 to convert from Hex to Dec
          if (SubStr(stringToEval,1,9) = "noreturn ")
          {
            stringToEval := SubStr(stringToEval,10)
            MessagetoXYplorer := "::" stringToEval    ;"noreturn loadtree get('tree').'|'.listfolder(,,2)"  resolved to sth like this:   ::loadtree get('tree').'|'.listfolder(,,2)
          }
          else
          {
            MessagetoXYplorer := "::CopyData " SenderHWND ", " stringToEval ", 0"    ;resolved to sth like this:   ::CopyData 7409230, <curitem>, 0   _OR like this:  ::CopyData 7409230, tab('get','count'), 0
          }
          SetTitleMatchMode, 2
          HWND := WinExist("XYplorer ahk_class ThunderRT6FormDC")
          Size := StrLen(MessagetoXYplorer)
          If !(A_IsUnicode)
          {
          VarSetCapacity(Data, Size * 2, 0)
          StrPut(MessagetoXYplorer, &Data, Size, "UTF-16")
          }
          Else
          Data := MessagetoXYplorer

          VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
          NumPut(4194305, COPYDATA, 0, "Ptr")
          NumPut(Size * 2, COPYDATA, A_PtrSize, "UInt")
          NumPut(&Data, COPYDATA, A_PtrSize * 2, "Ptr")
          XY_eval_and_returnvalue_XYRETURN = ""
          OnMessage(0x4a, "Function_Receive_WM_COPYDATA")  ; 0x4a is WM_COPYDATA. This onhold and wait for the WM_Copydata from XYplorer then execute Function_Receive_WM_COPYDATA(wParam, lParam) below
          SendMessage, 0x4a, 0, &COPYDATA, , ahk_id %HWND% ;SendMessage waits for the target window to process the message, up until the timeout period expires.
          OnMessage(0x4a, "")
          return XY_eval_and_returnvalue_XYRETURN
        }

        Function_Receive_WM_COPYDATA(wParam, lParam)
        {
          global XY_eval_and_returnvalue_XYRETURN
          StringAddress := NumGet(lParam + 2*A_PtrSize) ;lParam+8 is the address of CopyDataStruct's lpData member.
          CopyOfData := StrGet(StringAddress)    ;May also specify CP0 (default) or UTF-8 or UTF-16:   StrGet(StringAddress, NumGet(lParam+A_PtrSize), "UTF-16")
          cbData := NumGet(lParam+A_PtrSize)/2  ;cbData/2 = String length
          StringLeft, Datareceived, CopyOfData, cbData
          XY_eval_and_returnvalue_XYRETURN := Datareceived
          ;~ MsgBox % Datareceived
        }
		
    ;***************************************************************************************

        XY_curPath := XY_eval_and_returnvalue("<curpath>")
        SetTimer, Label1, 150
        return
		
		Label1:
        XY_curPathNew := XY_eval_and_returnvalue("<curpath>")
        
        If (XY_curPath != XY_curPathNew)
		{
          XY_curPath := XY_curPathNew

          XYfavMiniTree_paths := ""
          XYdata_path := XY_eval_and_returnvalue("<xydata>")
          XYini_file := FileOpen(XYdata_path . "\XYplorer.ini", "r")
          if XYini_file
          {
            XYini_line := ""
            Loop
            {
              XYini_line := XYini_file.ReadLine()
            }
            until SubStr(XYini_line, 1, 22) = "MiniTreePathsFavorite="
            XYini_file.Close()
            XYfavMiniTree_paths := SubStr(XYini_line, 23)
            XYfavMiniTree_paths := RTrim(XYfavMiniTree_paths, "`n`r")
          }
          
          XYcurFolder_directSubfolderPaths := ""
          XYcurFolder_directSubfolderPaths := XY_eval_and_returnvalue("listfolder('" . XY_curPath . "',,2)")
          
          XYcurFolder_siblingFolderPaths := ""
          SplitPath, XY_curPath,,XY_curPath_parent ;only works correctly on XY_curPath withOUT trailing backslash which is the case with <curpath> (see up above)
          XYcurFolder_siblingFoldersCount := XY_eval_and_returnvalue("listfolder('" . XY_curPath_parent . "',,34)")
          if (XYcurFolder_siblingFoldersCount <= XY_max_number_of_siblingFolders_shown_in_MiniTree)
          {
            XYcurFolder_siblingFolderPaths := XY_eval_and_returnvalue("listfolder('" . XY_curPath_parent . "',,2)")
          }
          
          XY_eval_and_returnvalue("noreturn loadtree '" . XY_curPath . "|" . XYfavMiniTree_paths . "|" . XYcurFolder_directSubfolderPaths . "|" . XYcurFolder_siblingFolderPaths . "'")
        }
        return

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

Re: AHK-script for better surfing of minitree

Post by SkyFrontier »

the compiled exe, please! :biggrin:
(and/or please point me at a method for this! my AHK stuff are out of reach as of now and I can't recall a straight method for doing it!)
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...

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

Re: AHK-script for better surfing of minitree

Post by autocart »

Sorry, my workday is over.
Monday morning, then.

What I wanted to say, though, is that with this script I have a smoother minitree-browsing experience if I turn OFF "Expand dest node in tree", "Expand tree nodes on sgl click" and "auto-optimize tree".

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

Re: AHK-script for better surfing of minitree

Post by SkyFrontier »

Error at line 18 using AH Toolkit 0.8.1.1.
Any hints?
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...

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

Re: AHK-script for better surfing of minitree

Post by autocart »

SkyFrontier wrote:Error at line 18 using AH Toolkit 0.8.1.1.
Any hints?
Nope, sorry.

The good news is, I made some "overtime hours" at home.
I compiled the exe (from 6 KB to 798 KB :) ).
Its attached as zip.
I also could not test it at home. I tested the uncompiled script running it through ahk on win7 at work, though.

Again, usage is completely at everyones own risk !!!!!!!!!!!!!
Usage:
Start the exe. It should run in the system tray and have immediate effect on the browsing of the MiniTree in XYplorer.
Attachments
XYplorer_MiniTreeBrowsing.zip
(380.46 KiB) Downloaded 138 times

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: AHK-script for better surfing of minitree

Post by bdeshi »

Thanks, it works fine here.
SF, you could try the (portable) AHK package from ahkscript.org
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: AHK-script for better surfing of minitree

Post by SkyFrontier »

Yes, it works! Thanks for the extra time, autocart!
Sammay: thank you, too!
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: AHK-script for better surfing of minitree

Post by binocular222 »

There's a better way than checking every 150ms.
- Use a tweak: add <path> to TitlebarTemplate, such as TitlebarTemplate="<path>|<ver> - <app>"
- Use winwaitclose in AHK, example:

Code: Select all

Settitlematchmode, 2
RenameXYplorer:
WinwaitClose, %CurrentTitle%
if(WinExist("ahk_class ThunderRT6FormDC") = 0)
{
	Winwaitactive, XYplorer ahk_class ThunderRT6FormDC
	Varsetcapacity(CurrentTitle)
	gosub RenameXYplorer
}
Else
{
	WinGetTitle, CurrentTitle, XYplorer ahk_class ThunderRT6FormDC
	FunctionMessagetoXYplorer("::msg Hi")
	gosub RenameXYplorer
}
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

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

Re: AHK-script for better surfing of minitree

Post by autocart »

Uahahaha, I think you got that idea with winwaitclose from me... :mrgreen:

However.... as far as I remember right now (or found out in the meantime), the title is limited to a number of chars. For "normal" circumstances long enough, but IF there is a very long, long path then it could cut it short and there you go running into an error. Thanks, for your feedback, though. :D

Didn't I get the idea of waiting 150 ms with settimer from you? :whistle: :biggrin: (http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=11002)

EDIT: and thx also to SF and SS for your feedback, and to anyone else who might give it in the future. :)

EDIT2: What do you guys think of the 30 sibling-folders-limit?? Is it practical that way? Should the number be changed? Or should it be completely replaced, maybe by user-defined paths, that state the folders which's children should not be displayed as siblings? This would of course be a lot of work for me coding the user-define-handling of the folders.... But for you guys, I might do it... :kidding:

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

Re: AHK-script for better surfing of minitree

Post by SkyFrontier »

I'd really love to experiment the alternative method, autocart.
Specially because limits would leave partial support for large sessions of surfing, thus breaking the main point of keeping miniTree on, in a reliable way.

-you're welcome!
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...

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

Re: AHK-script for better surfing of minitree

Post by autocart »

Ok, here is my new ahk-code and the compiled exe attached (inside zip).
In both cases, as always, USAGE AT OWN RISK!!!!!

Last week, the whole thing seemed to work faster. Now there is a little delay with loading the adapted tree. I don't know why, but I think it is still usable. Maybe it is because of Monday :eh:
EDIT: Found the villain and corrected it in code and exe.

There is also an ini file now, which must be named "XYplorer_MiniTreeBrowsing.ini".
It need to be located in the xydata path. If it is not there it will be created automatically on first run of exe.
I hope it is self-explainatory. Else, please ask.

AND: For a little bit smoother tree-loading you can lock the tree (in the view menu)!

EDIT2: On folders with a LOT of sub-/sibling-folders (e.g. 300 in my case) or many long paths it COULD come to an "overflow 0 \ 0" error in connection with loadtree. If this happens then add that parent-folder-path to the "parentPathsOfNotDisplayedSiblings" and avoid browsing that parent-folder :mrgreen: I hope that Don will be able to fix that bug soon.

"XYplorer_MiniTreeBrowsing.ini":
EDIT3: starting with v0.006 the default ini file (crated on start if it does not exist already), will look like this:
[values]

; MaxDisplayedSiblings is an all-or-nothing setting.
; If the sibling folders (in relation to the current path) would be more than the here
; defined number then they are not shown in the MiniTree. In order not to use this feature,
; simply do not define any number. In this case all siblings are shown (depending on the
; next value, though).

maxDisplayedSiblings=

; You can define for which folders, when they become current, NO siblings should be shown
; in the MiniTree, by defining the PARENT path here. Paths are seperated by "|". In order
; not to use this feature, simply do not define any path. (This value and the previous one
; are additional to each other. If no "path" applies but the count of siblings is more than
; maxDisplayedSiblings then they are still not displayed and vice versa.)

parentPathsOfNotDisplayedSiblings=

Code: Select all

        #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
        #Persistent

        global XY_eval_and_returnvalue_XYRETURN
        XYdata_path := XY_eval_and_returnvalue("<xydata>")
        
        if (not FileExist(XYdata_path . "\XYplorer_MiniTreeBrowsing.ini"))
        {
          FileAppend [on/off settings]`nUse_maxDisplayedSiblings=1`nUse_parentPathsOfNotDisplayedSiblings=1`n`n[values]`nmaxDisplayedSiblings=30`n; paths are seperated by "|"`nparentPathsOfNotDisplayedSiblings=
            , %XYdata_path%\XYplorer_MiniTreeBrowsing.ini
          if ErrorLevel
          {
            MsgBox %XYdata_path%\XYplorer_MiniTreeBrowsing.ini`n`nProblem writing to ini file. Exiting script.
            ExitApp
          }
          Use_maxDisplayedSiblings := 1
          Use_parentPathsOfNotDisplayedSiblings := 0
          maxDisplayedSiblings := 30
          parentPathsOfNotDisplayedSiblings := ""
        }
        else
        {
          iniReadError := ""
          IniRead Use_maxDisplayedSiblings, %XYdata_path%\XYplorer_MiniTreeBrowsing.ini, on/off settings, Use_maxDisplayedSiblings
          iniReadError := iniReadError . Use_maxDisplayedSiblings . "|"
          IniRead Use_parentPathsOfNotDisplayedSiblings, %XYdata_path%\XYplorer_MiniTreeBrowsing.ini, on/off settings, Use_parentPathsOfNotDisplayedSiblings
          iniReadError := iniReadError . Use_parentPathsOfNotDisplayedSiblings . "|"
          IniRead maxDisplayedSiblings, %XYdata_path%\XYplorer_MiniTreeBrowsing.ini, values, maxDisplayedSiblings
          iniReadError := iniReadError . maxDisplayedSiblings . "|"
          IniRead parentPathsOfNotDisplayedSiblings, %XYdata_path%\XYplorer_MiniTreeBrowsing.ini, values, parentPathsOfNotDisplayedSiblings
          iniReadError := iniReadError . parentPathsOfNotDisplayedSiblings . "|"
          if (InStr(iniReadError, "ERROR", 1))
          {
            MsgBox %XYdata_path%\XYplorer_MiniTreeBrowsing.ini`n`nProblem reading from ini file. To ensure that at least the format of the ini file is correct, delete it and run the exe again, so that it will create it anew. Exiting script.
            ExitApp
          }
        }
        
        
        ;***************************************************************************************
        ;** code from others (or based on) **
        ;***************************************************************************************

        ;heavily based on
        ;http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=9233&p=89555&hilit=messenger#p89555
       
        ;~ MsgBox % A_ScriptHwnd + 0
        ;~ OnMessage(0x4a, "Function_Receive_WM_COPYDATA")

            XY_eval_and_returnvalue(stringToEval)          ;Send message to XYplorer
            {
              SetTitleMatchMode, 2
              SetWinDelay, 0
              WinWait XYplorer ahk_class ThunderRT6FormDC
              global XY_eval_and_returnvalue_XYRETURN
              SenderHWND := A_ScriptHwnd + 0  ;Return this script's hidden hwdn id.  +0 to convert from Hex to Dec
              if (SubStr(stringToEval,1,9) = "noreturn ")
              {
                stringToEval := SubStr(stringToEval,10)
                MessagetoXYplorer := "::" stringToEval    ;"noreturn loadtree get('tree').'|'.listfolder(,,2)"  resolved to sth like this:   ::loadtree get('tree').'|'.listfolder(,,2)
              }
              else
              {
                MessagetoXYplorer := "::CopyData " SenderHWND ", " stringToEval ", 0"    ;resolved to sth like this:   ::CopyData 7409230, <curitem>, 0   _OR like this:  ::CopyData 7409230, tab('get','count'), 0
              }
              HWND := WinExist("XYplorer ahk_class ThunderRT6FormDC")
              Size := StrLen(MessagetoXYplorer)
              If !(A_IsUnicode)
              {
              VarSetCapacity(Data, Size * 2, 0)
              StrPut(MessagetoXYplorer, &Data, Size, "UTF-16")
              }
              Else
              Data := MessagetoXYplorer

              VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
              NumPut(4194305, COPYDATA, 0, "Ptr")
              NumPut(Size * 2, COPYDATA, A_PtrSize, "UInt")
              NumPut(&Data, COPYDATA, A_PtrSize * 2, "Ptr")
              XY_eval_and_returnvalue_XYRETURN := ""
              OnMessage(0x4a, "Function_Receive_WM_COPYDATA")  ; 0x4a is WM_COPYDATA. This onhold and wait for the WM_Copydata from XYplorer then execute Function_Receive_WM_COPYDATA(wParam, lParam) below
              SendMessage, 0x4a, 0, &COPYDATA, , ahk_id %HWND% ;SendMessage waits for the target window to process the message, up until the timeout period expires.
              OnMessage(0x4a, "")
              return XY_eval_and_returnvalue_XYRETURN
            }

            Function_Receive_WM_COPYDATA(wParam, lParam)
            {
              global XY_eval_and_returnvalue_XYRETURN
              StringAddress := NumGet(lParam + 2*A_PtrSize) ;lParam+8 is the address of CopyDataStruct's lpData member.
              CopyOfData := StrGet(StringAddress)    ;May also specify CP0 (default) or UTF-8 or UTF-16:   StrGet(StringAddress, NumGet(lParam+A_PtrSize), "UTF-16")
              cbData := NumGet(lParam+A_PtrSize)/2  ;cbData/2 = String length
              StringLeft, Datareceived, CopyOfData, cbData
              XY_eval_and_returnvalue_XYRETURN := Datareceived
              ;~ MsgBox % Datareceived
            }
          
        ;***************************************************************************************

            XY_curPath := XY_eval_and_returnvalue("<curpath>")
            SetTimer, Label1, 150
            return
          
          Label1:
            XY_curPath_new := XY_eval_and_returnvalue("<curpath>")
           
            If (XY_curPath != XY_curPath_new)
            {
              XY_curPath := XY_curPath_new
              
              FileGetTime, XYini_lastModTime_new, %XYdata_path%\XYplorer.ini, M
              if (XYini_lastModTime != XYini_lastModTime_new)
              {
                XYini_file := FileOpen(XYdata_path . "\XYplorer.ini", "r")
                if XYini_file
                {
                  XYini_lastModTime := XYini_lastModTime_new
                  XYini_line := ""
                  Loop
                  {
                    XYini_line := XYini_file.ReadLine()
                  }
                  until SubStr(XYini_line, 1, 22) = "MiniTreePathsFavorite=" or XYini_file.AtEOF
                  if (XYini_file.AtEOF)
                  {
                    XYfavMiniTree_paths := ""
                  }
                  else
                  {
                    XYfavMiniTree_paths := SubStr(XYini_line, 23)
                    XYfavMiniTree_paths := RTrim(XYfavMiniTree_paths, "`n`r")
                    if (XYfavMiniTree_paths)
                    {
                      XYfavMiniTree_paths := XYfavMiniTree_paths . "|"
                    }
                  }
                  XYini_file.Close()
                }
                else
                {
                  XYfavMiniTree_paths := ""
                }
              }

              XYcurFolder_directSubfolderPaths := XY_eval_and_returnvalue("listfolder('" . XY_curPath . "',,2)")
              if (XYcurFolder_directSubfolderPaths)
              {
                XYcurFolder_directSubfolderPaths := XYcurFolder_directSubfolderPaths . "|"
              }

              XYcurFolder_siblingFolderPaths := ""
              SplitPath, XY_curPath,,XY_curPath_parent ;only works correctly on XY_curPath withOUT trailing backslash which is the case with <curpath> (see up above)
              if (XY_curPath != XY_curPath_parent) ;if XY_curPath is the root of a drive (e.g. only "C:") then the result for parent is the same and also there are no siblings for the tree
              {
                retrieveSiblingFolders := 1
                if (Use_parentPathsOfNotDisplayedSiblings and InStr(parentPathsOfNotDisplayedSiblings, XY_curPath_parent))
                {
                  retrieveSiblingFolders := 0
                }
                XYcurFolder_siblingFoldersCount := XY_eval_and_returnvalue("listfolder('" . XY_curPath_parent . "',,34)")
                if (Use_maxDisplayedSiblings and XYcurFolder_siblingFoldersCount > maxDisplayedSiblings)
                {
                  retrieveSiblingFolders := 0
                }
                if (retrieveSiblingFolders)
                {
                  XYcurFolder_siblingFolderPaths := XY_eval_and_returnvalue("listfolder('" . XY_curPath_parent . "',,2)")
                }
              }
              
              ;~ MsgBox % XY_curPath . "|" . XYfavMiniTree_paths . XYcurFolder_directSubfolderPaths . XYcurFolder_siblingFolderPaths
              XY_eval_and_returnvalue("noreturn loadtree '" . XY_curPath . "|" . XYfavMiniTree_paths . XYcurFolder_directSubfolderPaths . XYcurFolder_siblingFolderPaths . "'")
            }
            return
Attachments
XYplorer_MiniTreeBrowsing.zip
(371.49 KiB) Downloaded 134 times
Last edited by autocart on 28 Jul 2014 15:05, edited 1 time in total.

Post Reply