Collapse and expand Tree View Widget from code

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

vincitygialam
Posts: 1
Joined: Tue Sep 11, 2018 3:46 am

Collapse and expand Tree View Widget from code

Post by vincitygialam » Tue Sep 11, 2018 4:18 am

Anybody know how to collapse a treeview widget with code?
I want to reset a treeview widget for users from within the code?
Would be even better if I had full control over what part to expand and collapse.

Regards,

Quda

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Collapse and expand Tree View Widget from code

Post by bwmilby » Mon Sep 17, 2018 1:25 am

Currently there isn't a way to change the fold state from code.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 818
Joined: Fri Feb 06, 2015 4:03 pm

Re: Collapse and expand Tree View Widget from code

Post by LiveCode_Panos » Mon Sep 17, 2018 11:45 am

You could try the following - it is not very efficient, but seems to work.

1. Find the location of the arrow you want to click so as as to expand/collapse the tree view widget. To do that, you can place the cursor over the tree arrow and type in the message box (*while the cursor is still over the arrow*):

"put the mouseloc"

This will return a pair of card coordinates, e.g. "65,121"

2. Then you can do:

"click at 65,121"

This will make the tree view to expand/collapse

PS: Make sure you are in Run mode.

Best,
Panos
--

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Collapse and expand Tree View Widget from code

Post by bwmilby » Mon Sep 17, 2018 1:59 pm

I think I need to do another PR to make it easier :D
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

LiveCode_Panos
Livecode Staff Member
Livecode Staff Member
Posts: 818
Joined: Fri Feb 06, 2015 4:03 pm

Re: Collapse and expand Tree View Widget from code

Post by LiveCode_Panos » Mon Sep 17, 2018 2:40 pm

Hehe, you are more than welcome :)

seaniepie
Posts: 154
Joined: Wed Sep 07, 2011 10:56 am

Re: Collapse and expand Tree View Widget from code

Post by seaniepie » Tue Oct 09, 2018 2:16 am

Similar to this, when I do a search within the Tree View I would need it to unfold to reveal where it is nested in the array when all entries are folded. Assume the element is contained four folds deep, eg

Code: Select all

Root
- Fold 1
  - Fold 2
      Element = Value
    - Fold 3
      - Fold 4
          Element = Value
          
= Root[Fold1][Fold2][Fold3][Fold4][Element]          
I can't get my head around how to recode the widget in LCB to unfold a particular tree element. Any clues?

Thanks

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Collapse and expand Tree View Widget from code

Post by bwmilby » Tue Oct 09, 2018 6:06 am

Yes. I have code close to ready. I’m waiting for a merge PR to get finalized before I submit to be sure it will result in a clean merge.

The initial fix will auto-unfold on selection and provide a way to reset the fold state. Being able to collapse individual keys is going to need to wait for another PR to merge (send widget ...)

I could expose the full fold state array as a temp solution but then one would need to manually manipulate it.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

seaniepie
Posts: 154
Joined: Wed Sep 07, 2011 10:56 am

Re: Collapse and expand Tree View Widget from code

Post by seaniepie » Wed Oct 10, 2018 2:25 am

Hi Brian,
Thanks for the update. Do you have it up in a GitHub branch to view at all before you submit for PR. It may help me understand this aspect of LCB a little better.
Personally I wouldn't need to get a 'full fold state' array, though I can see why this would be handy. At the moment I just need it to unfold to reveal and highlight the selected element. I've seen your PR/Merge for the auto-scroll properties which will also be a welcome addition.
Thanks and well done.
π

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Collapse and expand Tree View Widget from code

Post by bwmilby » Wed Oct 10, 2018 5:08 am

I just posted my in progress work:
https://github.com/bwmilby/livecode/tre ... -fold-test
https://github.com/bwmilby/livecode/blo ... eeview.lcb
https://github.com/bwmilby/livecode/com ... ed440a9da2

Some pertinent handlers with changes
1393 - pathIsValid (new)
1729 - unfoldPath
1742 - unfoldFullPath (new)
1762 - selectPath
1846 - applyFoldStateKey
1968 - setSelectedElement

The updates allow the widget to unfold the tree to display the selected path. Interactively there is no way to select a path that isn't visible. If setting the selection by code, it is possible. Before this update, the selection just silently failed in that case.

There are also a couple of new handlers in this version that won't get included until later (require the ability to call widget handlers from LCS which isn't available yet).

Once PR 6702 is merged, I'll get an update together with most of the code in this test branch.
https://github.com/livecode/livecode/pull/6702

(An update was merged in the 9.0 branch and some of the changes in develop conflicted. The changes to implement the fold logic further change the same area. Waiting to be sure that I don't create another merge conflict with the update to the widget.)
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 261
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Collapse and expand Tree View Widget from code

Post by SWEdeAndy » Fri Oct 12, 2018 7:11 pm

Ah, I just ran into this inability of the tree widget. Great to go to the forum for help and see a solution may just be on its way! :D

Just to check: In my case, I have two tree widgets side by side (with same array structure), and when I fold/unfold in one, I want the other to do the same. Will the improvement described above allow this to be coded?
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Collapse and expand Tree View Widget from code

Post by bwmilby » Thu Oct 18, 2018 6:20 am

PR submitted:
https://github.com/livecode/livecode/pull/6738

@SWEdeAndy
This update doesn't allow to keep two widgets completely in sync automatically. You could always take a selection from one widget and then select in the other widget. This would only do the unfold part. There is another PR required to allow calling handlers inside the LCB code directly.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

markhinnebusch
Posts: 40
Joined: Thu May 17, 2018 7:32 pm
Location: Florida, USA

Re: Collapse and expand Tree View Widget from code

Post by markhinnebusch » Sun Apr 21, 2019 11:41 pm

Hello,

I am wondering if there is any further activity on this issue. Specifically, I need to:

1. get a message when the user collapses/expands a fold

2. be able to expand/collapse a fold from code.

thanks,
Mark

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Collapse and expand Tree View Widget from code

Post by bwmilby » Sun Apr 21, 2019 11:51 pm

This has been merged into the develop branch band will appear in the first release in the 9.1 line. You can download the LCB file and compile it now though. You will need to hack your install slightly to replace the widget. The advantage of doing that is that your stacks will work with the release copy once it comes out. If you want further help in how to do this, let me know.

#2 is addressed in the merged code. #1 is not but would be easy to add.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

markhinnebusch
Posts: 40
Joined: Thu May 17, 2018 7:32 pm
Location: Florida, USA

Re: Collapse and expand Tree View Widget from code

Post by markhinnebusch » Mon Apr 22, 2019 8:30 pm

Thanks for the update. I'll check it out. And thank you for the widget!

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Collapse and expand Tree View Widget from code

Post by mrcoollion » Thu Sep 26, 2019 12:09 pm

Just a small addition to this thread.

Following code will collaps the Tree Widget (LC 9.5)

Code: Select all

on mouseUp
   set the FoldState of widget "ArrayView" to true
end mouseUp
However I could not find a command to Expand the whole tree :(

Code: Select all

set the FoldState of widget "ArrayView" to false
does the same as

Code: Select all

set the FoldState of widget "ArrayView" to true


Regards,

Paul

Post Reply

Return to “Talking LiveCode”