Page 1 of 2

Collapse and expand Tree View Widget from code

Posted: Tue Sep 11, 2018 4:18 am
by vincitygialam
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

Re: Collapse and expand Tree View Widget from code

Posted: Mon Sep 17, 2018 1:25 am
by bwmilby
Currently there isn't a way to change the fold state from code.

Re: Collapse and expand Tree View Widget from code

Posted: Mon Sep 17, 2018 11:45 am
by LiveCode_Panos
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
--

Re: Collapse and expand Tree View Widget from code

Posted: Mon Sep 17, 2018 1:59 pm
by bwmilby
I think I need to do another PR to make it easier :D

Re: Collapse and expand Tree View Widget from code

Posted: Mon Sep 17, 2018 2:40 pm
by LiveCode_Panos
Hehe, you are more than welcome :)

Re: Collapse and expand Tree View Widget from code

Posted: Tue Oct 09, 2018 2:16 am
by seaniepie
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

Re: Collapse and expand Tree View Widget from code

Posted: Tue Oct 09, 2018 6:06 am
by bwmilby
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.

Re: Collapse and expand Tree View Widget from code

Posted: Wed Oct 10, 2018 2:25 am
by seaniepie
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.
π

Re: Collapse and expand Tree View Widget from code

Posted: Wed Oct 10, 2018 5:08 am
by bwmilby
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.)

Re: Collapse and expand Tree View Widget from code

Posted: Fri Oct 12, 2018 7:11 pm
by SWEdeAndy
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?

Re: Collapse and expand Tree View Widget from code

Posted: Thu Oct 18, 2018 6:20 am
by bwmilby
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.

Re: Collapse and expand Tree View Widget from code

Posted: Sun Apr 21, 2019 11:41 pm
by markhinnebusch
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

Re: Collapse and expand Tree View Widget from code

Posted: Sun Apr 21, 2019 11:51 pm
by bwmilby
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.

Re: Collapse and expand Tree View Widget from code

Posted: Mon Apr 22, 2019 8:30 pm
by markhinnebusch
Thanks for the update. I'll check it out. And thank you for the widget!

Re: Collapse and expand Tree View Widget from code

Posted: Thu Sep 26, 2019 12:09 pm
by mrcoollion
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