MCPcopy
hub / github.com/lxn/walk / attachModel

Method attachModel

tableview.go:698–798  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

696}
697
698func (tv *TableView) attachModel() {
699 restoreCurrentItemOrFallbackToFirst := func(ip IDProvider) {
700 if tv.itemStateChangedEventDelay == 0 {
701 defer tv.currentItemChangedPublisher.Publish()
702 } else {
703 if 0 == win.SetTimer(
704 tv.hWnd,
705 tableViewCurrentIndexChangedTimerId,
706 uint32(tv.itemStateChangedEventDelay),
707 0,
708 ) {
709 lastError("SetTimer")
710 }
711 }
712
713 count := tv.model.RowCount()
714 for i := 0; i < count; i++ {
715 if ip.ID(i) == tv.currentItemID {
716 tv.SetCurrentIndex(i)
717 return
718 }
719 }
720
721 tv.SetCurrentIndex(0)
722 }
723
724 tv.rowsResetHandlerHandle = tv.model.RowsReset().Attach(func() {
725 tv.setItemCount()
726
727 if ip, ok := tv.providedModel.(IDProvider); ok && tv.restoringCurrentItemOnReset {
728 if _, ok := tv.model.(Sorter); !ok {
729 restoreCurrentItemOrFallbackToFirst(ip)
730 }
731 } else {
732 tv.SetCurrentIndex(-1)
733 }
734
735 tv.itemCountChangedPublisher.Publish()
736 })
737
738 tv.rowChangedHandlerHandle = tv.model.RowChanged().Attach(func(row int) {
739 tv.UpdateItem(row)
740 })
741
742 tv.rowsChangedHandlerHandle = tv.model.RowsChanged().Attach(func(from, to int) {
743 if s, ok := tv.model.(Sorter); ok {
744 s.Sort(s.SortedColumn(), s.SortOrder())
745 } else {
746 first, last := uintptr(from), uintptr(to)
747 win.SendMessage(tv.hwndFrozenLV, win.LVM_REDRAWITEMS, first, last)
748 win.SendMessage(tv.hwndNormalLV, win.LVM_REDRAWITEMS, first, last)
749 }
750 })
751
752 tv.rowsInsertedHandlerHandle = tv.model.RowsInserted().Attach(func(from, to int) {
753 i := tv.currentIndex
754
755 tv.setItemCount()

Callers 1

SetModelMethod · 0.95

Calls 15

SetCurrentIndexMethod · 0.95
setItemCountMethod · 0.95
UpdateItemMethod · 0.95
setSortIconMethod · 0.95
redrawItemsMethod · 0.95
lastErrorFunction · 0.85
IDMethod · 0.80
RowCountMethod · 0.65
RowsResetMethod · 0.65
RowChangedMethod · 0.65
RowsChangedMethod · 0.65
SortMethod · 0.65

Tested by

no test coverage detected