diff options
author | Alexander Neumann <alexander.neumann@picos-software.com> | 2018-12-05 16:38:50 +0100 |
---|---|---|
committer | Alexander Neumann <alexander.neumann@picos-software.com> | 2018-12-05 16:38:50 +0100 |
commit | e7059012c1907a9c9aca0116b4300d27bcb4f962 (patch) | |
tree | b0901a44be11f5f11d4ff2809a8d4d240f9ce264 | |
parent | WindowBase: Add ForEachDescendant (diff) | |
download | wireguard-windows-e7059012c1907a9c9aca0116b4300d27bcb4f962.tar.xz wireguard-windows-e7059012c1907a9c9aca0116b4300d27bcb4f962.zip |
WindowBase: Add persistence implementations that recursively call descendant's
-rw-r--r-- | window.go | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -915,6 +915,42 @@ func setWindowText(hwnd win.HWND, text string) error { return nil } +func (wb *WindowBase) RestoreState() (err error) { + wb.ForEachDescendant(func(widget Widget) bool { + if persistable, ok := widget.(Persistable); ok && persistable.Persistent() { + if err = persistable.RestoreState(); err != nil { + return false + } + } + + if _, ok := widget.(Container); ok { + return false + } + + return true + }) + + return +} + +func (wb *WindowBase) SaveState() (err error) { + wb.ForEachDescendant(func(widget Widget) bool { + if persistable, ok := widget.(Persistable); ok && persistable.Persistent() { + if err = persistable.SaveState(); err != nil { + return false + } + } + + if _, ok := widget.(Container); ok { + return false + } + + return true + }) + + return +} + func forEachDescendant(hwnd win.HWND, lParam uintptr) uintptr { if window := windowFromHandle(hwnd); window != nil && forEachDescendantCallback(window.(Widget)) { return 1 |