ExplorerTreeGadget() and GetGadgetItemText()

Just starting out? Need help? Post your questions and find answers here.
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

ExplorerTreeGadget() and GetGadgetItemText()

Post by Jacobus »

Hello,
I'm experiencing a return value issue with the GetGadgetItemText() function from an ExplorerTreeGadget(), and I'm wondering if this is a bug.
GetGadgetText() returns the full path of the selected item, while GetGadgetItemText() returns the root directory of a file, but a different root directory for a folder.
I find this very strange!??? :?
A little test code to see the problem. Have I misinterpreted it?
(Test performed with PB 6.21 32-bit, Windows 11 Professional)

Code: Select all

If OpenWindow(0, 0, 0, 300, 300, "ExplorerTreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  
  ExplorerTreeGadget(0, 10, 10, 280, 280, "")
  
  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  
                  Debug GetGadgetText(0) 
                  Debug GetGadgetItemText(0, SelectElement, 0) ;<-- return C:\   ??
                  
                ElseIf SelectElement & #PB_Explorer_Directory                
                  Debug GetGadgetText(0) 
                  Debug GetGadgetItemText(0, SelectElement, 0) ;<-- return D:\   ??
                EndIf 
                
              EndIf 
              
          EndSelect
          
          
      EndSelect
     EndIf  
    
  Until Event() = #PB_Event_CloseWindow
  
  EndIf 
Last edited by Jacobus on Thu Jul 17, 2025 6:57 pm, edited 1 time in total.
PureBasicien tu es, PureBasicien tu resteras.
Axolotl
Enthusiast
Enthusiast
Posts: 798
Joined: Wed Dec 31, 2008 3:36 pm

Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?

Post by Axolotl »

I dont know, but I think that you cannot do this?
SelectElement is the position.
The Constants are not "compatible" with the position. I added a comment with what the compiler see.....

Code: Select all

; .....
                If SelectElement & #PB_Explorer_File    ; <<  SelectElement & $01  
; .....
                ElseIf SelectElement & #PB_Explorer_Directory         ; <<  SelectElement & $02  
; .....
You can use FileSize() to detect the File or Directory Type.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?

Post by Jacobus »

Hi Axoltl,

In my documentation ExplorerTreeGadget() is explained:
GetGadgetState() : Lets you know if the selected item is a directory or a file. <<
GetGadgetItemText() : Returns the full path of the specified item.
GetGadgetText() : Returns the full path of the selected directory or file.

This can be a big problem if you want to use GetGadgetItemText(#Gadget, Item [, Column]) to delete a file or directory. Thinking you got the full path to your file, you got a root directory. :?
It can be funny :mrgreen:
PureBasicien tu es, PureBasicien tu resteras.
Sirius-2337
User
User
Posts: 59
Joined: Sat May 14, 2011 10:39 am

Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?

Post by Sirius-2337 »

Jacobus wrote: Thu Jul 17, 2025 5:28 pm In my documentation ExplorerTreeGadget() is explained:
GetGadgetState() : Lets you know if the selected item is a directory or a file. <<
That is correct, but you are using the return value as 'position' for GetGadgetItemText.
It's not returning an index, just the type of the selected item.
Little John
Addict
Addict
Posts: 4773
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?

Post by Little John »

Jacobus wrote: Thu Jul 17, 2025 5:28 pm ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?
I wonder whether it is possible to ask a simple coding question without using the word “bug”. :?
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

Re: ExplorerTreeGadget() and GetGadgetItemText()

Post by Jacobus »

Little John wrote: Thu Jul 17, 2025 6:48 pm
Jacobus wrote: Thu Jul 17, 2025 5:28 pm ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?
I wonder whether it is possible to ask a simple coding question without using the word “bug”. :?
bug was removed from the title.
PureBasicien tu es, PureBasicien tu resteras.
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?

Post by Jacobus »

Sirius-2337 wrote: Thu Jul 17, 2025 6:07 pm
Jacobus wrote: Thu Jul 17, 2025 5:28 pm In my documentation ExplorerTreeGadget() is explained:
GetGadgetState() : Lets you know if the selected item is a directory or a file. <<
That is correct, but you are using the return value as 'position' for GetGadgetItemText.
It's not returning an index, just the type of the selected item.
Ok, but in these conditions how do you get the position of the element in question?
PureBasicien tu es, PureBasicien tu resteras.
Axolotl
Enthusiast
Enthusiast
Posts: 798
Joined: Wed Dec 31, 2008 3:36 pm

Re: ExplorerTreeGadget() and GetGadgetItemText()

Post by Axolotl »

Okay, I read you code and not the help for that command.
You are right. The GetGadgetState() is different for this Gadget.
HELP-Text:
The following functions can be used to control the gadget:

- GetGadgetText(): Get the full path of the currently selected directory/file.
- SetGadgetText(): Set the currently selected file/directory.
- GetGadgetState(): Check if the selected item is a file or a directory.
- GetGadgetItemText(): Returns the full path of the specified item.
So there seems to be no PB way to identify the selected element. Which would be needed for the parameter Position in the GetGadgetItemText()
Furthermore, GetGadgetItemText() would only return the same result as GetGadgetText().
From my point of view, the help should probably be corrected by removing the forth function.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

Re: ExplorerTreeGadget() and GetGadgetItemText()

Post by Jacobus »

Axolotl wrote: Fri Jul 18, 2025 11:03 am So there seems to be no PB way to identify the selected element. Which would be needed for the parameter Position in the GetGadgetItemText()
Furthermore, GetGadgetItemText() would only return the same result as GetGadgetText().
From my point of view, the help should probably be corrected by removing the forth function.
I came to the same conclusion. That was also why I wanted to test both functions and see the difference in the results. But the function is incomplete if we can't have the position argument.
PureBasicien tu es, PureBasicien tu resteras.
User avatar
HeX0R
Addict
Addict
Posts: 1187
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: ExplorerTreeGadget() and GetGadgetItemText()

Post by HeX0R »

I'd say GetGadgetState() should work like for all the other gadgets and return the selected index.
It feels strange, when it here returns the kind of selection.
Anyway, no bug, more a feature request.
Unfortunately it would break existing codes.
Not mine though, I never use ExplorerTreeGadgets :mrgreen:
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ExplorerTreeGadget() and GetGadgetItemText()

Post by mk-soft »

HeX0R wrote: Fri Jul 18, 2025 5:26 pm I'd say GetGadgetState() should work like for all the other gadgets and return the selected index.
It feels strange, when it here returns the kind of selection.
Anyway, no bug, more a feature request.
Unfortunately it would break existing codes.
Not mine though, I never use ExplorerTreeGadgets :mrgreen:
See GetGadgetState Help. Is not always the index ...

Depending on the gadget type, it is different.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
HeX0R
Addict
Addict
Posts: 1187
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: ExplorerTreeGadget() and GetGadgetItemText()

Post by HeX0R »

I was talking about those Gadgets which allow more entries.
Here I see exactly one, where things are different.
Especially if you compare ExplorerList and ExplorerTree gadget.
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

Re: ExplorerTreeGadget() and GetGadgetItemText()

Post by Jacobus »

HeX0R wrote: Fri Jul 18, 2025 8:39 pm I was talking about those Gadgets which allow more entries.
Here I see exactly one, where things are different.
Especially if you compare ExplorerList and ExplorerTree gadget.
This is exactly what is confusing. Especially since GetGadgetState() in ExplorerTreeGadget() must obtain the index of the selection to be able to tell if it is a file or a folder. At least, it seems so to me. In this case, it would indeed be desirable for a function to be able to return the index of a file in an ExplorerTreeGadget() to fully exploit it, without torturing oneself to write a routine that gives the index. :)
PureBasicien tu es, PureBasicien tu resteras.
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ExplorerTreeGadget() and GetGadgetItemText()

Post by mk-soft »

The index changes every time a tree is opened or closed.
Thus, the index does not help.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
BarryG
Addict
Addict
Posts: 4121
Joined: Thu Apr 18, 2019 8:17 am

Re: ExplorerTreeGadget() and GetGadgetItemText()

Post by BarryG »

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).

Image
Post Reply