()
| 696 | } |
| 697 | |
| 698 | func (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() |
no test coverage detected