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

Method RestoreState

tableview.go:1696–1835  ·  view source on GitHub ↗

RestoreState restores the UI state of the *TableView from the settings.

()

Source from the content-addressed store, hash-verified

1694
1695// RestoreState restores the UI state of the *TableView from the settings.
1696func (tv *TableView) RestoreState() error {
1697 state, err := tv.ReadState()
1698 if err != nil {
1699 return err
1700 }
1701 if state == "" {
1702 return nil
1703 }
1704
1705 tv.SetSuspended(true)
1706 defer tv.SetSuspended(false)
1707
1708 if tv.state == nil {
1709 tv.state = new(tableViewState)
1710 }
1711
1712 tvs := tv.state
1713
1714 if err := json.Unmarshal(([]byte)(state), tvs); err != nil {
1715 return err
1716 }
1717
1718 name2tvc := make(map[string]*TableViewColumn)
1719
1720 for _, tvc := range tv.columns.items {
1721 name2tvc[tvc.name] = tvc
1722 }
1723
1724 name2tvcs := make(map[string]*tableViewColumnState)
1725
1726 tvcsRetained := make([]*tableViewColumnState, 0, len(tvs.Columns))
1727 for _, tvcs := range tvs.Columns {
1728 if tvcs.LastSeenDate != "" {
1729 if lastSeen, err := time.Parse("2006-02-01", tvcs.LastSeenDate); err != nil {
1730 tvcs.LastSeenDate = ""
1731 } else if name2tvc[tvcs.Name] == nil && lastSeen.Add(time.Hour*24*90).Before(time.Now()) {
1732 continue
1733 }
1734 }
1735 tvcsRetained = append(tvcsRetained, tvcs)
1736
1737 name2tvcs[tvcs.Name] = tvcsRetained[len(tvcsRetained)-1]
1738
1739 if tvc := name2tvc[tvcs.Name]; tvc != nil {
1740 if err := tvc.SetFrozen(tvcs.Frozen); err != nil {
1741 return err
1742 }
1743 var visible bool
1744 for _, name := range tvs.ColumnDisplayOrder {
1745 if name == tvc.name {
1746 visible = true
1747 break
1748 }
1749 }
1750 if err := tvc.SetVisible(tvc.visible && (visible || tvcs.Visible)); err != nil {
1751 return err
1752 }
1753 if err := tvc.SetTitleOverride(tvcs.Title); err != nil {

Callers

nothing calls this directly

Calls 14

visibleColumnCountMethod · 0.95
visibleColumnsMethod · 0.95
newErrorFunction · 0.85
ReadStateMethod · 0.80
SetFrozenMethod · 0.80
SetTitleOverrideMethod · 0.80
SetSuspendedMethod · 0.65
SetVisibleMethod · 0.65
SetWidthMethod · 0.65
SendMessageMethod · 0.65
ColumnSortableMethod · 0.65

Tested by

no test coverage detected