Page 2 of 2

Re: ExplorerTreeGadget() and GetGadgetItemText()

Posted: Sat Jul 19, 2025 5:43 am
by normeus
Looks like the 2nd parameter of GetGadgetItemText() is an index to a list of items being displayed:

Code: Select all

If OpenWindow(0, 0, 0, 300, 300, "ExplorerTreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  
  ExplorerTreeGadget(0, 10, 10, 280, 280, "",#PB_Explorer_AlwaysShowSelection)
  
  Repeat 
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Gadget
      Select EventGadget()
          
        Case 0
          Select EventType()          
            Case #PB_EventType_RightClick
              SelectElement = GetGadgetState(0)
              
              If SelectElement >= 0
                
                If SelectElement & #PB_Explorer_File  
                  x=1
                  Debug GetGadgetText(0)+"<-- File Name" 
                  Debug "list of items being displayed in the tree window"
                  f$=GetGadgetItemText(0,x )
                  While f$<>#Null$ 
                    f$=GetGadgetItemText(0,x )
                    Debug  "-"+f$+"<--- item" + Str(x)
                    x=x+1
                  Wend
                  
                ElseIf SelectElement & #PB_Explorer_Directory
                  x=1
                  Debug GetGadgetText(0)+"<-- Directory name " 
                  Debug "list of items being displayed in the tree window"
                  f$=GetGadgetItemText(0,x )
                  While f$<>#Null$ 
                    f$=GetGadgetItemText(0,x )
                    Debug  "-"+f$+"<--- item" + Str(x)
                    x=x+1
                  Wend
                EndIf 
                
              EndIf 
              
          EndSelect
          
          
      EndSelect
    EndIf  
    
  Until Event() = #PB_Event_CloseWindow
  
EndIf 
Norm

Re: ExplorerTreeGadget() and GetGadgetItemText()

Posted: Sat Jul 19, 2025 11:18 am
by mk-soft
BarryG wrote: Sat Jul 19, 2025 2:11 am
mk-soft wrote: Fri Jul 18, 2025 11:57 pmThe index changes every time a tree is opened or closed.
But if you run the code from the first post and DON'T open anything, and just simply right-click "C:\" and don't do anything else, the debug output shows both "C:\" and "D:\" for that selected item. (Assuming you have a D: drive, like I do).
Logical. The marked element is a directory and thus 2. So as index uses the third entry from the displayed tree.
SelectElement is also false. It's SelectedType.

Re: ExplorerTreeGadget() and GetGadgetItemText()

Posted: Sat Jul 19, 2025 12:01 pm
by mk-soft
Information.

With GetGadgetItemText you get the item stored in the gadget. As soon as you open a node, the entries are first read by the drive and stored in the gadget. Thus, it is not necessary to read the drive again every time when closing and opening a node.

Code: Select all

;-TOP by mk-soft

Procedure CountExplorerTreeItems(Gadget)
  Protected cnt
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      cnt = CocoaMessage(0, GadgetID(Gadget), "numberOfRows")
    CompilerCase #PB_OS_Windows
      cnt = SendMessage_(GadgetID(Gadget), #TVM_GETCOUNT, 0, 0)
    CompilerCase #PB_OS_Linux
      ; todo
  CompilerEndSelect
  ProcedureReturn cnt
EndProcedure

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
  ResizeGadget(0, 0, 0, dx, dy)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("&File")
    MenuItem(99, "E&xit")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    ExplorerTreeGadget(1, 0, 0, dx / 2, dy / 2, "")
    ListViewGadget(2, dx / 2, 0, dx / 2, dy / 2)
    SplitterGadget(0, 0, 0, dx, dy, 1, 2, #PB_Splitter_Vertical)
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            Case 99
              PostEvent(#PB_Event_CloseWindow, 0, 0)
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              Select EventType()
                Case #PB_EventType_LeftClick
                  ClearGadgetItems(2)
                  uBound = CountExplorerTreeItems(1) - 1
                  For i = 0 To uBound
                    AddGadgetItem(2, -1, GetGadgetItemText(1, i))
                  Next
              EndSelect
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()

Re: ExplorerTreeGadget() and GetGadgetItemText()

Posted: Mon Jul 21, 2025 3:40 pm
by Jacobus
normeus wrote: Sat Jul 19, 2025 5:43 am Looks like the 2nd parameter of GetGadgetItemText() is an index to a list of items being displayed:
Indeed, with your method we do obtain an index number, but unfortunately as mk-soft pointed out, this number changes all the time as soon as you open a node and you end up with two identical numbers for two different elements.
mk-soft wrote: Sat Jul 19, 2025 12:01 pm With GetGadgetItemText you get the item stored in the gadget. As soon as you open a node, the entries are first read by the drive and stored in the gadget. Thus, it is not necessary to read the drive again every time when closing and opening a node.
Thanks for this approach which shows a possible use, but I think this remains a niche use for GetGadgetItemText() in this explorer. I see the difference with GetGadgetText() better now.