-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathm_state.go
110 lines (100 loc) · 2.92 KB
/
m_state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"encoding/json"
"os"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/theme"
)
type State struct {
Version string `json:"version"`
WindowSize fyne.Size `json:"window_size"`
Theme string `json:"theme"`
Scale float32 `json:"scale"`
Color string `json:"color"`
Simple bool `json:"simple_mode"`
DisplayDateFormat string `json:"display_date_format"`
Folder string `json:"folder"`
FramePos int `json:"frame_pos"`
FrameSize int `json:"frame_size"`
ItemPos int `json:"item_pos"`
ListOrderColumn int `json:"list_order_column"`
ListOrder order `json:"list_order"`
FavoriteCrops []fyne.Position `json:"favorite_crop"`
List map[string]*Photo `json:"list"`
}
func (a *App) saveState() {
a.state.WindowSize = a.topWindow.Canvas().Size()
a.state.Folder = rootURI.Path()
for i, v := range a.listColumns {
if v.Order != natOrder {
a.state.ListOrderColumn = i
a.state.ListOrder = v.Order
break
}
}
stateList := map[string]*Photo{}
for _, photo := range list {
if photo.isDroped() || photo.isDated() || photo.isCropped() || photo.isAdjusted() {
stateList[photo.fileURI.Name()] = photo
}
}
a.state.List = stateList
bytes, _ := json.Marshal(a.state)
a.Preferences().SetString("state", string(bytes))
}
func (p *Photo) isDroped() bool {
return p.Drop
}
func (p *Photo) isDated() bool {
return p.DateUsed != UseExifDate
}
func (p *Photo) isAdjusted() bool {
for i, v := range p.Adjust {
if v != adjustFiltersDict[i].zero {
return true
}
}
return false
}
func (p *Photo) isCropped() bool {
return !p.CropRectangle.Empty()
}
func (a *App) loadState() {
if state := a.Preferences().String("state"); state != "" {
if err := json.Unmarshal([]byte(state), &a.state); err == nil {
if rootURI, err = storage.ListerForURI(storage.NewFileURI(a.state.Folder)); err == nil {
return
}
}
}
a.defaultState(true)
}
func (a *App) defaultState(init bool) {
a.state.Version = a.Metadata().Version
if init {
a.state.WindowSize = fyne.NewSize(1280, 720)
a.state.Theme = DefaultTheme
a.state.Scale = DefaultScale
a.state.Color = theme.ColorOrange
a.state.Simple = true
a.state.DisplayDateFormat = DefaultDisplayDateFormat
a.state.FavoriteCrops = []fyne.Position{
{X: 1, Y: 1},
{X: 16, Y: 9},
{X: 9, Y: 16},
{X: 5, Y: 4},
{X: 4, Y: 5},
}
}
a.state.List = map[string]*Photo{}
a.state.FramePos = DefaultListPos
a.state.FrameSize = DefaultFrameSize
a.state.ItemPos = DefaultItemPos
a.state.ListOrderColumn = DefaultListOrderColumn
a.state.ListOrder = DefaultListOrder
home, _ := os.UserHomeDir()
a.state.Folder = home
uri := storage.NewFileURI(home)
rootURI, _ = storage.ListerForURI(uri)
}