Giter Club home page Giter Club logo

Comments (8)

lxn avatar lxn commented on May 17, 2024

The new TreeView checks your implementation of the TreeItem.ChildCount method to determine if the item is expandable. Depending on how you populate your model, it may be necessary to notify the TreeView about new items by calling TreeModelBase.PublishItemsReset (if you embed TreeModelBase in your model), or publish the event yourself and pass the parent item (or nil if roots are to be reset) as parameter.

TreeModel has a LazyPopulation method, that controls how a TreeView populates its internal items. So far I have only tested the lazy case. Maybe the eager case (default with TreeModelBase) isn't working yet.

Anyway, see the filebrowser example for how it can be done.

from walk.

lxn avatar lxn commented on May 17, 2024

Whoops, just noticed you asked how it can be done without having children. I guess that isn't supported with the new TreeView. If your motivation for doing this is lazy initialization, my first reply should help.

from walk.

sungit avatar sungit commented on May 17, 2024

Well, I was using the dummy child to handle this problem.

Your comment are very useful, thank you!

from walk.

sungit avatar sungit commented on May 17, 2024

TreeModelBase.PublishItemsReset failed with none nil parent when i want to dynamically populate the treeitem child contents.

After item.children appended new contents, I've tried TreeModelBase.PublishItemsReset(item) and TreeModelBase.PublishItemsReset(item.Parent()) in the handler attached to treeview.ItemExpanded(), but both failed (crash my program with the output below).

I found only TreeModelBase.PublishItemsReset(nil) works as i've tried.

    C:/Go/src/pkg/runtime/proc.c:1443
    C:/Go/src/pkg/runtime/runtime.c:128
    C:/Go/src/pkg/runtime/thread_windows.c:276
    E:/repos/libs/gopkgs/src/github.com/lxn/walk/treeview.go:388
    E:/repos/libs/gopkgs/src/github.com/lxn/walk/container.go:258
    E:/repos/libs/gopkgs/src/github.com/lxn/walk/widget.go:1369
    C:/Go/src/pkg/runtime/cgocall.c:210
    C:/Go/src/pkg/runtime/asm_386.s:473
    C:/Go/src/pkg/runtime/asm_386.s:377
    C:/Go/src/pkg/runtime/cgocall.c:135
    C:/Go/src/pkg/runtime/zsyscall_windows_386.c:97
    e:/repos/libs/gopkgs/src/github.com/lxn/go-winapi/user32.go:1487
    E:/repos/libs/gopkgs/src/github.com/lxn/walk/widget.go:1467
    E:/repos/libs/gopkgs/src/github.com/lxn/walk/treeview.go:432
    E:/repos/libs/gopkgs/src/github.com/lxn/walk/widget.go:1369
    C:/Go/src/pkg/runtime/cgocall.c:210
    C:/Go/src/pkg/runtime/asm_386.s:473
    C:/Go/src/pkg/runtime/asm_386.s:377
    C:/Go/src/pkg/runtime/cgocall.c:135
    C:/Go/src/pkg/runtime/zsyscall_windows_386.c:97
    e:/repos/libs/gopkgs/src/github.com/lxn/go-winapi/user32.go:1727
    E:/repos/libs/gopkgs/src/github.com/lxn/walk/toplevelwindow.go:119
    E:/repos/libs/gopkgs/src/github.com/lxn/walk/dialog.go:219

from walk.

lxn avatar lxn commented on May 17, 2024

Ok, so you just want lazy initialization.

You should do the same as the filebrowser example:

  1. Return true from your implementation of TreeModel.LazyPopulation.
  2. In your implementation(s) of TreeItem.ChildCount check if the children of that item have been initialized.
  3. If they haven't been initialized, initialize them inside ChildCount and return the number of children.

The TreeView then should take care of everything else and only ever ask for one level of items if you expand an item.

Of course the crash problem should be fixed anyway.

Thanks for your feedback!

from walk.

sungit avatar sungit commented on May 17, 2024

Yes, I've tried lazy initialization following the filebrowser example, Just as Step 2 and 3 required.

But it's obviously an synchronous process when creating of the child items and returning the item count in the TreeItem.ChildCount function.

My situation demanding an asynchronous population of the child items, which regards the item expanding click as a trigger to fetch all the content from a remote server. But my communication with the server is asynchronous so i
can only be sure the child items would be fetched, but surely after the TreeItem.ChildCount's being called.

Well, i have't found a solution yet. Any suggestion?

from walk.

lxn avatar lxn commented on May 17, 2024

Please try again with the latest changes.

from walk.

sungit avatar sungit commented on May 17, 2024

Well, thank you!

Your works are really appreciated!

from walk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.