aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-30 22:16:00 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-01-21 15:09:54 +0100
commite7fc19d483bd79b9c24ec6200700ab7d8899e7d0 (patch)
treeac77bdb9e1e56e6d03f3b1330ba5a36667c0eb7d
parentRemove math/big usage (diff)
downloadwireguard-windows-pkg/walk.tar.xz
wireguard-windows-pkg/walk.zip
Remove use of json, which we don't usepkg/walk
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--tableview.go220
1 files changed, 0 insertions, 220 deletions
diff --git a/tableview.go b/tableview.go
index e879c911..b28fb74f 100644
--- a/tableview.go
+++ b/tableview.go
@@ -7,7 +7,6 @@
package walk
import (
- "encoding/json"
"fmt"
"reflect"
"syscall"
@@ -1614,225 +1613,6 @@ type tableViewColumnState struct {
LastSeenDate string
}
-// SaveState writes the UI state of the *TableView to the settings.
-func (tv *TableView) SaveState() error {
- if tv.columns.Len() == 0 {
- return nil
- }
-
- if tv.state == nil {
- tv.state = new(tableViewState)
- }
-
- tvs := tv.state
-
- tvs.SortColumnName = tv.columns.items[tv.sortedColumnIndex].name
- tvs.SortOrder = tv.sortOrder
-
- // tvs.Columns = make([]tableViewColumnState, tv.columns.Len())
-
- for _, tvc := range tv.columns.items {
- var tvcs *tableViewColumnState
- for _, cur := range tvs.Columns {
- if cur.Name == tvc.name {
- tvcs = cur
- break
- }
- }
-
- // tvcs := &tvs.Columns[i]
-
- if tvcs == nil {
- tvs.Columns = append(tvs.Columns, new(tableViewColumnState))
- tvcs = tvs.Columns[len(tvs.Columns)-1]
- }
-
- tvcs.Name = tvc.name
- tvcs.Title = tvc.titleOverride
- tvcs.Width = tvc.Width()
- tvcs.Visible = tvc.Visible()
- tvcs.Frozen = tvc.Frozen()
- tvcs.LastSeenDate = time.Now().Format("2006-01-02")
- }
-
- visibleCols := tv.visibleColumns()
- frozenCount := tv.visibleFrozenColumnCount()
- normalCount := len(visibleCols) - frozenCount
- indices := make([]int32, len(visibleCols))
- var lp uintptr
- if frozenCount > 0 {
- lp = uintptr(unsafe.Pointer(&indices[0]))
-
- if 0 == win.SendMessage(tv.hwndFrozenLV, win.LVM_GETCOLUMNORDERARRAY, uintptr(frozenCount), lp) {
- return newError("LVM_GETCOLUMNORDERARRAY")
- }
- }
- if normalCount > 0 {
- lp = uintptr(unsafe.Pointer(&indices[frozenCount]))
-
- if 0 == win.SendMessage(tv.hwndNormalLV, win.LVM_GETCOLUMNORDERARRAY, uintptr(normalCount), lp) {
- return newError("LVM_GETCOLUMNORDERARRAY")
- }
- }
-
- tvs.ColumnDisplayOrder = make([]string, len(visibleCols))
- for i, j := range indices {
- if i >= frozenCount {
- j += int32(frozenCount)
- }
- tvs.ColumnDisplayOrder[i] = visibleCols[j].name
- }
-
- state, err := json.Marshal(tvs)
- if err != nil {
- return err
- }
-
- return tv.WriteState(string(state))
-}
-
-// RestoreState restores the UI state of the *TableView from the settings.
-func (tv *TableView) RestoreState() error {
- state, err := tv.ReadState()
- if err != nil {
- return err
- }
- if state == "" {
- return nil
- }
-
- tv.SetSuspended(true)
- defer tv.SetSuspended(false)
-
- if tv.state == nil {
- tv.state = new(tableViewState)
- }
-
- tvs := tv.state
-
- if err := json.Unmarshal(([]byte)(state), tvs); err != nil {
- return err
- }
-
- name2tvc := make(map[string]*TableViewColumn)
-
- for _, tvc := range tv.columns.items {
- name2tvc[tvc.name] = tvc
- }
-
- name2tvcs := make(map[string]*tableViewColumnState)
-
- tvcsRetained := make([]*tableViewColumnState, 0, len(tvs.Columns))
- for _, tvcs := range tvs.Columns {
- if tvcs.LastSeenDate != "" {
- if lastSeen, err := time.Parse("2006-02-01", tvcs.LastSeenDate); err != nil {
- tvcs.LastSeenDate = ""
- } else if name2tvc[tvcs.Name] == nil && lastSeen.Add(time.Hour*24*90).Before(time.Now()) {
- continue
- }
- }
- tvcsRetained = append(tvcsRetained, tvcs)
-
- name2tvcs[tvcs.Name] = tvcsRetained[len(tvcsRetained)-1]
-
- if tvc := name2tvc[tvcs.Name]; tvc != nil {
- if err := tvc.SetFrozen(tvcs.Frozen); err != nil {
- return err
- }
- var visible bool
- for _, name := range tvs.ColumnDisplayOrder {
- if name == tvc.name {
- visible = true
- break
- }
- }
- if err := tvc.SetVisible(tvc.visible && (visible || tvcs.Visible)); err != nil {
- return err
- }
- if err := tvc.SetTitleOverride(tvcs.Title); err != nil {
- return err
- }
- if err := tvc.SetWidth(tvcs.Width); err != nil {
- return err
- }
- }
- }
- tvs.Columns = tvcsRetained
-
- visibleCount := tv.visibleColumnCount()
- frozenCount := tv.visibleFrozenColumnCount()
- normalCount := visibleCount - frozenCount
-
- indices := make([]int32, visibleCount)
-
- knownNames := make(map[string]struct{})
-
- displayOrder := make([]string, 0, visibleCount)
- for _, name := range tvs.ColumnDisplayOrder {
- knownNames[name] = struct{}{}
- if tvc, ok := name2tvc[name]; ok && tvc.visible {
- displayOrder = append(displayOrder, name)
- }
- }
- for _, tvc := range tv.visibleColumns() {
- if _, ok := knownNames[tvc.name]; !ok {
- displayOrder = append(displayOrder, tvc.name)
- }
- }
-
- for i, tvc := range tv.visibleColumns() {
- for j, name := range displayOrder {
- if tvc.name == name && j < visibleCount {
- idx := i
- if j >= frozenCount {
- idx -= frozenCount
- }
- indices[j] = int32(idx)
- break
- }
- }
- }
-
- var lp uintptr
- if frozenCount > 0 {
- lp = uintptr(unsafe.Pointer(&indices[0]))
-
- if 0 == win.SendMessage(tv.hwndFrozenLV, win.LVM_SETCOLUMNORDERARRAY, uintptr(frozenCount), lp) {
- return newError("LVM_SETCOLUMNORDERARRAY")
- }
- }
- if normalCount > 0 {
- lp = uintptr(unsafe.Pointer(&indices[frozenCount]))
-
- if 0 == win.SendMessage(tv.hwndNormalLV, win.LVM_SETCOLUMNORDERARRAY, uintptr(normalCount), lp) {
- return newError("LVM_SETCOLUMNORDERARRAY")
- }
- }
-
- for i, c := range tvs.Columns {
- if c.Name == tvs.SortColumnName && i < visibleCount {
- tv.sortedColumnIndex = i
- tv.sortOrder = tvs.SortOrder
- break
- }
- }
-
- if sorter, ok := tv.model.(Sorter); ok {
- if !sorter.ColumnSortable(tv.sortedColumnIndex) {
- for i := range tvs.Columns {
- if sorter.ColumnSortable(i) {
- tv.sortedColumnIndex = i
- break
- }
- }
- }
-
- sorter.Sort(tv.sortedColumnIndex, tvs.SortOrder)
- }
-
- return nil
-}
-
func (tv *TableView) toggleItemChecked(index int) error {
checked := tv.itemChecker.Checked(index)