-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.go
183 lines (152 loc) · 3.86 KB
/
dialog.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package declarative
import (
"github.com/lxn/walk"
)
type Dialog struct {
// Window
Accessibility Accessibility
Background Brush
ContextMenuItems []MenuItem
DoubleBuffering bool
Enabled Property
Font Font
MaxSize Size
MinSize Size
Name string
OnBoundsChanged walk.EventHandler
OnKeyDown walk.KeyEventHandler
OnKeyPress walk.KeyEventHandler
OnKeyUp walk.KeyEventHandler
OnMouseDown walk.MouseEventHandler
OnMouseMove walk.MouseEventHandler
OnMouseUp walk.MouseEventHandler
OnSizeChanged walk.EventHandler
Persistent bool
RightToLeftLayout bool
RightToLeftReading bool
ToolTipText Property
Visible Property
// Container
DataBinder DataBinder
Layout Layout
Children []Widget
// Form
Expressions func() map[string]walk.Expression
Functions map[string]func(args ...interface{}) (interface{}, error)
Icon Property
Title Property
Size Size
// Dialog
AssignTo **walk.Dialog
CancelButton **walk.PushButton
DefaultButton **walk.PushButton
FixedSize bool
}
func (d Dialog) Create(owner walk.Form) error {
var w *walk.Dialog
var err error
if d.FixedSize {
w, err = walk.NewDialogWithFixedSize(owner)
} else {
w, err = walk.NewDialog(owner)
}
if err != nil {
return err
}
if d.AssignTo != nil {
*d.AssignTo = w
}
fi := formInfo{
// Window
Background: d.Background,
ContextMenuItems: d.ContextMenuItems,
DoubleBuffering: d.DoubleBuffering,
Enabled: d.Enabled,
Font: d.Font,
MaxSize: d.MaxSize,
MinSize: d.MinSize,
Name: d.Name,
OnBoundsChanged: d.OnBoundsChanged,
OnKeyDown: d.OnKeyDown,
OnKeyPress: d.OnKeyPress,
OnKeyUp: d.OnKeyUp,
OnMouseDown: d.OnMouseDown,
OnMouseMove: d.OnMouseMove,
OnMouseUp: d.OnMouseUp,
OnSizeChanged: d.OnSizeChanged,
RightToLeftReading: d.RightToLeftReading,
ToolTipText: "",
Visible: d.Visible,
Accessibility: d.Accessibility,
// Container
Children: d.Children,
DataBinder: d.DataBinder,
Layout: d.Layout,
// Form
Icon: d.Icon,
Title: d.Title,
}
var db *walk.DataBinder
if d.DataBinder.AssignTo == nil {
d.DataBinder.AssignTo = &db
}
builder := NewBuilder(nil)
w.SetSuspended(true)
builder.Defer(func() error {
w.SetSuspended(false)
return nil
})
if err := w.SetRightToLeftLayout(d.RightToLeftLayout); err != nil {
return err
}
return builder.InitWidget(fi, w, func() error {
if d.Size.Width > 0 && d.Size.Height > 0 {
if err := w.SetSize(d.Size.toW()); err != nil {
return err
}
}
if d.DefaultButton != nil {
if err := w.SetDefaultButton(*d.DefaultButton); err != nil {
return err
}
if db := *d.DataBinder.AssignTo; db != nil {
if db.DataSource() != nil {
(*d.DefaultButton).SetEnabled(db.CanSubmit())
}
db.CanSubmitChanged().Attach(func() {
(*d.DefaultButton).SetEnabled(db.CanSubmit())
})
}
}
if d.CancelButton != nil {
if err := w.SetCancelButton(*d.CancelButton); err != nil {
return err
}
}
if d.Expressions != nil {
for name, expr := range d.Expressions() {
builder.expressions[name] = expr
}
}
if d.Functions != nil {
for name, fn := range d.Functions {
builder.functions[name] = fn
}
}
return nil
})
}
func (d Dialog) Run(owner walk.Form) (int, error) {
var w *walk.Dialog
if d.AssignTo == nil {
d.AssignTo = &w
}
if err := d.Create(owner); err != nil {
return 0, err
}
return (*d.AssignTo).Run(), nil
}