Page 1 of 1

[newbie] Explorer Tree Gadget problem

Posted: Sun Jun 07, 2009 7:58 pm
by abarkley
A real PB beginner here - been going about 2 weeks.

I want to show a directory (and contents) and get the user to select a (image) file which then gets loaded and worked on. Hard, huh?

What's wrong with this code:

If OpenWindow(0, 0, 0, 230, 220, "File example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
ExplorerTreeGadget(0, 10, 10, 280, 280, "C:\Documents And Settings\Alastair\My Documents\My Pictures\project\*.*")
EndIf

Repeat
Event = WaitWindowEvent()

Select Event

Case #PB_Event_Gadget
Select EventGadget()
Case 1
Select EventType()
Case #PB_EventType_LeftClick : Debug "Click with left mouse button"
Case #PB_EventType_RightClick : Debug "Click with right mouse button"
Case #PB_EventType_LeftDoubleClick : Debug "Double-click with left mouse button"
Case #PB_EventType_RightDoubleClick : Debug "Double-click with right mouse button"
EndSelect
EndSelect

EndSelect


Until Event = #PB_Event_CloseWindow
EndIf


This seems to work for other gadget types but not with this one. What I'm expecting is that clicking on a file opens the Debug window....no it doesn't.

The rest of the code will be to get the actual file name and then use it for loading. How will that work?

I guess I may not have understood properly how this gadget really works.

Posted: Sun Jun 07, 2009 8:02 pm
by srod
Change 'Case 1' to 'Case 0'. :wink:

Posted: Sun Jun 07, 2009 8:41 pm
by abarkley
Thanks. I knocked together the code from a couple of examples - I guess I'll see the error next time.

Please can you advise on the second problem: once I've been through the file tree and double clicked on the file that I want, how do I get the filename$?

Posted: Sun Jun 07, 2009 8:46 pm
by srod

Code: Select all

If OpenWindow(0, 0, 0, 230, 220, "File example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  If CreateGadgetList(WindowID(0)) 
    ExplorerTreeGadget(0, 10, 10, 280, 280, "C:\Documents And Settings\Alastair\My Documents\My Pictures\project\*.*") 
  EndIf 

  Repeat 
    Event = WaitWindowEvent() 
    Select Event 
      Case #PB_Event_Gadget 
        Select EventGadget() 
          Case 0 
            Select EventType() 
              Case #PB_EventType_LeftDoubleClick
                Select GetGadgetState(0)
                  Case #PB_Explorer_File 
                    Debug "Double-clicked file : " + GetGadgetText(0)
                  Case #PB_Explorer_Directory
                    Debug "Double-clicked folder : " + GetGadgetText(0)
                EndSelect
            EndSelect 
        EndSelect 
    EndSelect 
  Until Event = #PB_Event_CloseWindow 
EndIf 

Posted: Sun Jun 07, 2009 10:07 pm
by abarkley
Thanks.

Exactly what I was trying unsuccessfully to do.

Posted: Mon Jun 08, 2009 10:42 am
by srod
You're welcome.