Page 1 of 1

watch XY for tab count change event [title changed]

Posted: 23 Jan 2014 10:02
by autocart
would like to have an option to have the number of tabs in the title bar
for ahk-scripting reasons

Re: number of tabs var for titlebar template

Posted: 23 Jan 2014 11:08
by binocular222
No, AHK can already querry number of tabs using SendMessage (see part 2 in http://www.xyplorer.com/xyfc/viewtopic. ... 233#p82412)

Re: number of tabs var for titlebar template

Posted: 23 Jan 2014 12:20
by autocart
I know but I'd like to "watch" XY from ahk to react on the event of a new tab.
This would be easier (for me) if the tab count was part of the title.

Re: number of tabs var for titlebar template

Posted: 23 Jan 2014 13:03
by binocular222
To watch XY's titlebar, you need Settimer, right?
You can Settimer then SendMessage every xx milisecond to querry number of Tab is as effective as Settimer then watch titlebar

Re: number of tabs var for titlebar template

Posted: 23 Jan 2014 17:32
by autocart
binocular222 wrote:To watch XY's titlebar, you need Settimer, right?
You can Settimer then SendMessage every xx milisecond to querry number of Tab is as effective as Settimer then watch titlebar
I would do it like that:
1) On start I wait for XY window and remember the title.
2) Then I wait for the XY window with that title to not exist
3) as long as there is a XY window with a new title I rememeber that new title and go to step 2)
4) go to step 1)

Re: number of tabs var for titlebar template

Posted: 23 Jan 2014 17:38
by binocular222
So you use WinWaitClose.
ok, I will not hijack your thread anymore.
Don, can you add number of tabs var for titlebar template?

Re: number of tabs var for titlebar template

Posted: 23 Jan 2014 17:46
by autocart
binocular222 wrote:So you use WinWaitClose.
ok, I will not hijack your thread anymore.
Don, can you add number of tabs var for titlebar template?
hey , thx for the help and thought provoking remarks well meant are always good
actually i didnt think you would give up so fast ;)

Re: number of tabs var for titlebar template

Posted: 31 Mar 2014 14:09
by autocart
Even better would be a completely scriptable part of the titlebar, i.e. with a "return" command like in custom columns.
However, in order to always keep the titlebar current, the result of the script would probably have to be checked continously... :cry:
On the other hand I am confident that Don is able to find a good solution. :biggrin:

Re: number of tabs var for titlebar template

Posted: 01 Apr 2014 06:57
by bdeshi
Even better would be a completely scriptable part of the titlebar, i.e. with a "return" command like in custom columns.
+1

Re: number of tabs var for titlebar template

Posted: 01 Apr 2014 11:09
by admin
autocart wrote:However, in order to always keep the titlebar current, the result of the script would probably have to be checked continously... :cry:
On the other hand I am confident that Don is able to find a good solution. :biggrin:
1. Yes
2. No

:)

Re: number of tabs var for titlebar template

Posted: 25 Apr 2014 09:48
by autocart
Okidokie,
I now did it with SetTimer every 150 ms and SendMessage -> tab('get', 'count')
I was afraid that it would be a burden on the PC (performance) or similar, but the ahk script runs with ~0% CPU usage and still works.
So everything is ok.

Re: watch XY for tab count change event

Posted: 28 Apr 2014 11:39
by autocart
I am so happy with this solution now that I want to share my AHK-code with all of you, for anyone who could use it:

The ACTIV(AT)E(D) TAB after "add/delete tab" will first always be automatically LOCKED and then RENAMED (code needs to be adapted to your own needs/wishes). The code is not perfect but works for me right now.

heavily based on:
http://www.xyplorer.com/xyfc/viewtopic. ... =messenger

Code: Select all

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

    global XY_eval_and_returnvalue_XYRETURN

    ;***************************************************************************************
    ;** heavily based on:
    ;** http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=9233&hilit=messenger
    ;***************************************************************************************

        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
          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")
          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
        }
		
		XY_tabCount := XY_eval_and_returnvalue("tab('get','count')")
        SetTimer, Label1, 150
        Exit
		
		Label1:
		XY_tabCountNew := XY_eval_and_returnvalue("tab('get','count')")
		If (XY_tabCount != XY_tabCountNew)
		{
          XY_tabCount := XY_tabCountNew
		  
          XY_eval_and_returnvalue("tab('lock', 1)") ; <-- The ACTIV(AT)E(D) TAB after "add/delete tab" will always be automatically LOCKED
          
          /* ||
             vv Below from here: The ACTIV(AT)E(D) TAB after "add/delete tab" will always be automatically RENAMED (according to below user-programmed rules)
          */
          XY_tabPath := XY_eval_and_returnvalue("tab('get', 'path')")
          newTabName := SubStr(XY_tabPath,1,2)
          If(SubStr(XY_tabPath,1,17) == "path_to_specific_folder")
          {
            newTabName := newTabName . "B:"
            If(InStr(XY_tabPath, "\", , 0) > 17)
            {
              newTabName := newTabName . SubStr(XY_tabPath,19,2) . ":" 
            }
          }
          else If(SubStr(XY_tabPath,1,47) == "path_to_other_specific_folder")
          {
            newTabName := newTabName . "A:"
          }
          else If(SubStr(XY_tabPath,1,38) == "path_to_3rd_specific_folder")
          {
            newTabName := newTabName . "A:Doku:"
          }
          else If(SubStr(XY_tabPath,1,10) == "path_to_4th_specific_folder")
          {
            newTabName := newTabName . "A:"
          }
          else If(SubStr(XY_tabPath,1,10) == "path_to_5th_specific_folder")
          {
            newTabName := newTabName . "XY:"
          }
          
          subcategories := "generic_folder1|generic_folder2|generic_folder3|generic_folderN"
          If(InStr(subcategories, SubStr(XY_tabPath, 1 + InStr(XY_tabPath, "\", , 0))))
          {
            index_renamedTab := XY_eval_and_returnvalue("tab('rename', '" . newTabName . "' . getpathcomponent(tab('get', 'path'), 'parent') . ':' . getpathcomponent(tab('get', 'path'), 'component', -1))")
          }
          else
          {
            index_renamedTab := XY_eval_and_returnvalue("tab('rename', '" . newTabName . "' . getpathcomponent(tab('get', 'path'), 'component', -1))")
          }
	    }
        return