1
1
using System ;
2
+ using System . Threading . Tasks ;
2
3
using AppKit ;
3
4
using CoreGraphics ;
4
5
using Xamarin . PropertyEditing . ViewModels ;
@@ -19,6 +20,7 @@ internal PropertyViewModel ViewModel
19
20
set {
20
21
if ( this . viewModel != null ) {
21
22
this . viewModel . PropertyChanged -= OnPropertyChanged ;
23
+ this . viewModel . CreateVariantRequested -= OnCreateVariantRequested ;
22
24
}
23
25
24
26
this . viewModel = value ;
@@ -110,13 +112,27 @@ private void PopUpContextMenu ()
110
112
this . popUpContextMenu . AddItem ( NSMenuItem . SeparatorItem ) ;
111
113
112
114
// TODO If we add more menu items consider making the Label/Command a dictionary that we can iterate over to populate everything.
113
- this . popUpContextMenu . AddItem ( new CommandMenuItem ( Properties . Resources . Reset , viewModel . ClearValueCommand ) {
115
+ this . popUpContextMenu . AddItem ( new CommandMenuItem ( Properties . Resources . Reset , this . viewModel . ClearValueCommand ) {
114
116
AttributedTitle = new Foundation . NSAttributedString (
115
117
Properties . Resources . Reset ,
116
118
new CoreText . CTStringAttributes {
117
119
Font = new CoreText . CTFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultFontSize + 1 ) ,
118
120
} )
119
121
} ) ;
122
+
123
+ this . popUpContextMenu . AddItem ( NSMenuItem . SeparatorItem ) ;
124
+
125
+ if ( this . viewModel . HasVariations ) {
126
+ this . popUpContextMenu . AddItem ( new CommandMenuItem ( Properties . Resources . AddVariant , this . viewModel . RequestCreateVariantCommand ) {
127
+ AttributedTitle = new Foundation . NSAttributedString (
128
+ Properties . Resources . AddVariant ,
129
+ new CoreText . CTStringAttributes {
130
+ Font = new CoreText . CTFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultFontSize + 1 ) ,
131
+ } )
132
+ } ) ;
133
+
134
+ this . viewModel . CreateVariantRequested += OnCreateVariantRequested ;
135
+ }
120
136
}
121
137
122
138
var menuOrigin = this . Superview . ConvertPointToView ( new CGPoint ( Frame . Location . X - 1 , Frame . Location . Y + Frame . Size . Height + 4 ) , null ) ;
@@ -166,34 +182,34 @@ private void ToggleFocusImage (bool focused = false)
166
182
private void ValueSourceChanged ( ValueSource valueSource )
167
183
{
168
184
switch ( valueSource ) {
169
- case ValueSource . Binding :
170
- ToolTip = Properties . Resources . Binding ;
171
- break ;
172
-
173
- case ValueSource . Default :
174
- ToolTip = Properties . Resources . Default ;
175
- return ;
176
-
177
- case ValueSource . Local :
178
- ToolTip = Properties . Resources . Local ;
179
- break ;
180
-
181
- case ValueSource . Inherited :
182
- ToolTip = Properties . Resources . Inherited ;
183
- break ;
184
-
185
- case ValueSource . Resource :
186
- ToolTip = ( this . viewModel ? . Resource ? . Name != null ) ? String . Format ( Properties . Resources . ResourceWithName , this . viewModel . Resource . Name ) : Properties . Resources . Resource ;
187
- break ;
188
-
189
- case ValueSource . Unset :
190
- ToolTip = Properties . Resources . Unset ;
191
- break ;
192
-
193
- default :
194
- // To Handle ValueSource.DefaultStyle, ValueSource.Style etc.
195
- ToolTip = string . Empty ;
196
- break ;
185
+ case ValueSource . Binding :
186
+ ToolTip = Properties . Resources . Binding ;
187
+ break ;
188
+
189
+ case ValueSource . Default :
190
+ ToolTip = Properties . Resources . Default ;
191
+ return ;
192
+
193
+ case ValueSource . Local :
194
+ ToolTip = Properties . Resources . Local ;
195
+ break ;
196
+
197
+ case ValueSource . Inherited :
198
+ ToolTip = Properties . Resources . Inherited ;
199
+ break ;
200
+
201
+ case ValueSource . Resource :
202
+ ToolTip = ( this . viewModel ? . Resource ? . Name != null ) ? String . Format ( Properties . Resources . ResourceWithName , this . viewModel . Resource . Name ) : Properties . Resources . Resource ;
203
+ break ;
204
+
205
+ case ValueSource . Unset :
206
+ ToolTip = Properties . Resources . Unset ;
207
+ break ;
208
+
209
+ default :
210
+ // To Handle ValueSource.DefaultStyle, ValueSource.Style etc.
211
+ ToolTip = string . Empty ;
212
+ break ;
197
213
}
198
214
199
215
ToggleFocusImage ( ) ;
@@ -228,13 +244,37 @@ private void OnResourceRequested (object sender, EventArgs e)
228
244
Appearance = EffectiveAppearance
229
245
} ;
230
246
231
- var resourceSelectorPopOver = new AutoClosePopOver ( this . hostResources ) {
247
+ var resourceSelectorPopOver = new AutoClosePopOver ( this . hostResources ) {
232
248
ContentViewController = new NSViewController ( null , null ) { View = requestResourceView } ,
233
249
} ;
234
250
235
251
requestResourceView . PopOver = resourceSelectorPopOver ;
236
252
237
253
resourceSelectorPopOver . Show ( requestResourceView . Frame , ( NSView ) this , NSRectEdge . MinYEdge ) ;
238
254
}
255
+
256
+ private void OnCreateVariantRequested ( object sender , CreateVariantEventArgs e )
257
+ {
258
+ /*var createVariantView = new CreateVariantView (this.hostResources, this.viewModel, new CreateVariantViewModel (this.viewModel.Property)) {
259
+ Appearance = EffectiveAppearance
260
+ };
261
+
262
+ var createVariantPopOver = new AutoClosePopOver (this.hostResources) {
263
+ ContentViewController = new NSViewController (null, null) { View = createVariantView },
264
+ };
265
+
266
+ createVariantView.PopOver = createVariantPopOver;
267
+
268
+ createVariantPopOver.Show (createVariantView.Frame, (NSView)this, NSRectEdge.MinYEdge);*/
269
+
270
+ var createVariantWindow = new CreateVariantWindow ( this . hostResources , this . viewModel ) {
271
+ Appearance = EffectiveAppearance ,
272
+ } ;
273
+
274
+ var result = ( NSModalResponse ) ( int ) NSApplication . SharedApplication . RunModalForWindow ( createVariantWindow ) ;
275
+ if ( result == NSModalResponse . OK ) {
276
+ e . Variation = Task . FromResult ( createVariantWindow . ViewModel ? . Variation ) ;
277
+ }
278
+ }
239
279
}
240
280
}
0 commit comments