How can I unfold a TreeGadget?

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

How can I unfold a TreeGadget?

Post by Wolfram »

How can I unfold all nodes of a TreeGadget?
macOS Catalina 10.15.7
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: How can I unfold a TreeGadget?

Post by wombats »

Do you mean collapse them all at once?

Code: Select all

Procedure OnExpandAll()
  Protected i
  For i = 0 To CountGadgetItems(0) - 1
    SetGadgetItemState(0, i, #PB_Tree_Expanded)
  Next
EndProcedure

Procedure OnCollapseAll()
  Protected i
  For i = 0 To CountGadgetItems(0) - 1
    SetGadgetItemState(0, i, #PB_Tree_Collapsed)
  Next
EndProcedure

If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TreeGadget(0, 10, 10, 160, 160)                                        
  For a = 0 To 10
    AddGadgetItem (ID, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use
    AddGadgetItem (ID, -1, "Node "+Str(a), 0, 0)        ; ImageID(x) as 4th parameter
    AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1)           ; These are on the 1st sublevel
    AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1)
    AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1)
    AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1)
    AddGadgetItem (ID, -1, "File "+Str(a), 0, 0) ; sublevel 0 again
  Next
  ButtonGadget(1, 180, 10, 125, 25, "Expand All")
  ButtonGadget(2, 180, 40, 125, 25, "Collapse All")
  BindGadgetEvent(1, @OnExpandAll())
  BindGadgetEvent(2, @OnCollapseAll())
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: How can I unfold a TreeGadget?

Post by Wolfram »

Thanks!
This is ok for a few hundert items, but on 7000 items it takes 40 seconds to open them.

I hope there is a better way.
macOS Catalina 10.15.7
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: How can I unfold a TreeGadget?

Post by Lord »

Did you try HideGadget(0, #True) and HideGadget(0, #False)?
Or was it DisableGadget()? Try it.

For Windows only:

Code: Select all

Procedure OnExpandAll()
  Protected i
  SendMessage_(GadgetID(0),#WM_SETREDRAW,#False,0)
  For i = 0 To CountGadgetItems(0) - 1
    SetGadgetItemState(0, i, #PB_Tree_Expanded)
  Next
  SendMessage_(GadgetID(0),#WM_SETREDRAW,#True,0)
EndProcedure
and

Code: Select all

Procedure OnCollapseAll()
  Protected i
 SendMessage_(GadgetID(0),#WM_SETREDRAW,#False,0)
  For i = 0 To CountGadgetItems(0) - 1
    SetGadgetItemState(0, i, #PB_Tree_Collapsed)
  Next
  SendMessage_(GadgetID(0),#WM_SETREDRAW,#True,0)
EndProcedure
Image
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: How can I unfold a TreeGadget?

Post by Wolfram »

No, it does not help.
If I use a shortcut (option + arrowRight) it opens in a second.
macOS Catalina 10.15.7
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: How can I unfold a TreeGadget?

Post by AZJIO »

viewtopic.php?p=576903#p576903
You can also use the asterisk (*) on the numeric keypad, this is a native way to expand the entire tree (it definitely works on Win10).
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: How can I unfold a TreeGadget?

Post by Wolfram »

Here is what I was looking for...

Code: Select all

CocoaMessage(0, GadgetID(tree), "expandItem:", #nil,  "expandChildren:", #YES)
macOS Catalina 10.15.7
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: How can I unfold a TreeGadget?

Post by AZJIO »

Wolfram
I'm sorry, I didn't even pay attention to the Mac OSX section.
User avatar
Piero
Addict
Addict
Posts: 862
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: How can I unfold a TreeGadget?

Post by Piero »

AZJIO wrote: Tue Jun 17, 2025 9:54 amI didn't even pay attention to the Mac OSX section.
You know that it hurts my feelings (like pineapple pizza) but I forgive you
Post Reply