func (mw *MainWindow) populateTreeViewItem(parent *walk.TreeViewItem) { mw.treeView.SetSuspended(true) defer mw.treeView.SetSuspended(false) // Remove dummy child parent.Children().Clear() dirPath := pathForTreeViewItem(parent) dir, err := os.Open(dirPath) if err != nil { mw.showError(err) return } defer dir.Close() names, err := dir.Readdirnames(-1) panicIfErr(err) for _, name := range names { fi, err := os.Stat(path.Join(dirPath, name)) panicIfErr(err) if !excludePath(name) && fi.IsDir() { child := newTreeViewItem(name) parent.Children().Add(child) } } }
func pathForTreeViewItem(item *walk.TreeViewItem) string { var parts []string for item != nil { parts = append([]string{item.Text()}, parts...) item = item.Parent() } return path.Join(parts...) }