예제 #1
0
파일: gunvalue.go 프로젝트: sqp/godock
// SelectedIter returns the iter matching the selected line.
//
func SelectedIter(model *gtk.ListStore, selection *gtk.TreeSelection) (*gtk.TreeIter, error) {
	if selection.CountSelectedRows() == 0 {
		return nil, errors.New("no line selected")
	}

	_, iter, ok := selection.GetSelected()
	if !ok {
		return nil, errors.New("SelectedIter: GetSelected failed")
	}
	return iter, nil
}
예제 #2
0
// Handle selection
func treeSelectionChangedCB(selection *gtk.TreeSelection) {
	var iter *gtk.TreeIter
	var model gtk.ITreeModel
	var ok bool
	model, iter, ok = selection.GetSelected()
	if ok {
		tpath, err := model.(*gtk.TreeModel).GetPath(iter)
		if err != nil {
			log.Printf("treeSelectionChangedCB: Could not get path from model: %s\n", err)
			return
		}
		log.Printf("treeSelectionChangedCB: selected path: %s\n", tpath)
	}
}
예제 #3
0
// Handler of "changed" signal of TreeView's selection
func SelectionChanged(s *gtk.TreeSelection) {
	// Returns glib.List of gtk.TreePath pointers
	rows := s.GetSelectedRows(ListStore)
	items := make([]string, 0, rows.Length())

	for l := rows; l != nil; l = l.Next() {
		path := l.Data().(*gtk.TreePath)
		iter, _ := ListStore.GetIter(path)
		value, _ := ListStore.GetValue(iter, 0)
		str, _ := value.GetString()
		items = append(items, str)
	}

	Entry.SetText(fmt.Sprint(items))
}