-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPropertyListView.cs
More file actions
266 lines (225 loc) · 8.83 KB
/
PropertyListView.cs
File metadata and controls
266 lines (225 loc) · 8.83 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
using System;
using System.Collections.Generic;
using System.Linq;
using NStack;
namespace Terminal.Gui.Designer
{
public class PropertyListView : FrameView
{
private View _targetView;
private readonly DesignerState _state;
public PropertyListView(DesignerState state) : base("Properties")
{
_state = state;
}
public void SetTargetView(View view)
{
if (view == null)
{
RemoveAll();
return;
}
_targetView = view;
RemoveAll();
var scrollView = new ScrollView()
{
X = 0,
Y = 0,
Height = Dim.Fill(),
Width = Dim.Fill(),
ContentSize = new Size(50, 50),
ShowVerticalScrollIndicator = true
};
int y = 0;
foreach (var property in _targetView.GetType().GetProperties().Where(m => m.CanWrite).OrderBy(m => m.Name))
{
if (Constants.SkippedProperties.Contains(property.Name)) continue;
var label = new Label(property.Name)
{
Y = y,
X = 0,
Height = 1,
Width = Dim.Fill()
};
scrollView.Add(label);
y++;
var value = property.GetValue(_targetView);
View valueView;
if (property.PropertyType == typeof(Boolean))
{
var chk = new CheckBox();
chk.Checked = (bool)property.GetValue(_targetView);
chk.Toggled += arg =>
{
_state.IsDirty = true;
property.SetValue(_targetView, chk.Checked);
};
valueView = chk;
}
else if (property.PropertyType.IsEnum)
{
var text = new TextField
{
Text = value.ToString(),
ReadOnly = true
};
text.MouseClick += (args) =>
{
var currentValue = property.GetValue(_targetView);
var enumEditor = new EnumEditorView(currentValue, property.Name);
enumEditor.ValueChanged += (sender, args1) =>
{
_state.IsDirty = true;
property.SetValue(_targetView, args1);
text.Text = property.GetValue(_targetView).ToString();
};
Application.Run(enumEditor);
};
valueView = text;
}
else if (property.PropertyType == typeof(Dim))
{
var dimEditorTxt = new TextField
{
Text = value.ToString(),
ReadOnly = true
};
dimEditorTxt.MouseClick += (args) =>
{
var currentValue = property.GetValue(_targetView);
var dimEditor = new DimEditorView(currentValue as Dim);
dimEditor.DimChanged += (sender, args1) =>
{
_state.IsDirty = true;
property.SetValue(_targetView, args1.Dim);
dimEditorTxt.Text = property.GetValue(_targetView).ToString();
};
Application.Run(dimEditor);
};
valueView = dimEditorTxt;
}
else if (property.PropertyType == typeof(Pos))
{
var dimEditorTxt = new TextField
{
Text = value.ToString(),
ReadOnly = true
};
dimEditorTxt.MouseClick += (args) =>
{
var currentValue = property.GetValue(_targetView);
var dimEditor = new PosEditorView(currentValue as Pos, _state);
dimEditor.ValueChanged += (sender, args1) =>
{
_state.IsDirty = true;
property.SetValue(_targetView, args1.Pos);
dimEditorTxt.Text = property.GetValue(_targetView).ToString();
};
Application.Run(dimEditor);
};
valueView = dimEditorTxt;
}
else if (property.PropertyType == typeof(ustring[]))
{
var dimEditorTxt = new TextField
{
Text = value.ToString(),
ReadOnly = true
};
dimEditorTxt.MouseClick += (args) =>
{
var currentValue = property.GetValue(_targetView);
var dimEditor = new StringListView(currentValue as ustring[], property.Name);
dimEditor.ValueChanged += (sender, args1) =>
{
_state.IsDirty = true;
property.SetValue(_targetView, args1);
dimEditorTxt.Text = property.GetValue(_targetView).ToString();
};
Application.Run(dimEditor);
};
valueView = dimEditorTxt;
}
else if (property.PropertyType == typeof(MenuBarItem[]))
{
var dimEditorTxt = new TextField
{
Text = value.ToString(),
ReadOnly = true
};
dimEditorTxt.MouseClick += (args) =>
{
var currentValue = property.GetValue(_targetView);
var dimEditor = new StringListView(currentValue as ustring[], property.Name);
dimEditor.ValueChanged += (sender, args1) =>
{
_state.IsDirty = true;
property.SetValue(_targetView, args1);
dimEditorTxt.Text = property.GetValue(_targetView).ToString();
};
Application.Run(dimEditor);
};
valueView = dimEditorTxt;
}
else
{
var textField = new TextField();
if (property.PropertyType == typeof(ustring))
{
textField.TextChanged += str =>
{
_state.IsDirty = true;
property.SetValue(_targetView, textField.Text);
};
}
if (value != null)
{
textField.Text = value.ToString();
}
valueView = textField;
}
valueView.Y = y;
valueView.X = Pos.Left(label) + 1;
valueView.Height = 1;
valueView.Width = Dim.Fill();
scrollView.Add(valueView);
y++;
}
foreach (var property in _targetView.GetType().GetEvents().OrderBy(m => m.Name))
{
var label = new Label(property.Name)
{
Y = y,
X = 0,
Height = 1,
Width = Dim.Fill()
};
scrollView.Add(label);
y++;
View valueView;
var dimEditorTxt = new Button
{
Text = "Edit",
};
dimEditorTxt.MouseClick += (args) =>
{
var dimEditor = new EventEditorView(property.Name);
dimEditor.ValueChanged += (sender, args1) =>
{
_state.IsDirty = true;
};
Application.Run(dimEditor);
};
valueView = dimEditorTxt;
valueView.Y = y;
valueView.X = Pos.Left(label) + 1;
valueView.Height = 1;
valueView.Width = Dim.Fill();
scrollView.Add(valueView);
y++;
}
Add(scrollView);
SetNeedsDisplay();
}
}
}