1
1
using System ;
2
2
using System . Linq ;
3
+ using System . Threading . Tasks ;
3
4
using AppKit ;
4
5
using CoreGraphics ;
5
6
using Xamarin . PropertyEditing . ViewModels ;
@@ -20,16 +21,25 @@ internal PropertyViewModel ViewModel
20
21
set {
21
22
if ( this . viewModel != null ) {
22
23
this . viewModel . PropertyChanged -= OnPropertyChanged ;
24
+
23
25
if ( this . viewModel . SupportsBindings )
24
26
this . viewModel . CreateBindingRequested -= OnBindingRequested ;
27
+
28
+ if ( this . viewModel . HasVariations )
29
+ this . viewModel . CreateVariantRequested -= OnCreateVariantRequested ;
25
30
}
26
31
27
32
this . viewModel = value ;
28
33
29
34
if ( this . viewModel != null ) {
30
35
this . viewModel . PropertyChanged += OnPropertyChanged ;
36
+
31
37
if ( this . viewModel . SupportsBindings )
32
38
this . viewModel . CreateBindingRequested += OnBindingRequested ;
39
+
40
+ if ( this . viewModel . HasVariations )
41
+ this . viewModel . CreateVariantRequested += OnCreateVariantRequested ;
42
+
33
43
ValueSourceChanged ( this . viewModel . ValueSource ) ;
34
44
}
35
45
@@ -93,7 +103,7 @@ private void PopUpContextMenu ()
93
103
AttributedTitle = new Foundation . NSAttributedString (
94
104
Properties . Resources . CustomExpressionEllipsis ,
95
105
new CoreText . CTStringAttributes {
96
- Font = new CoreText . CTFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultFontSize + 1 ) ,
106
+ Font = new CoreText . CTFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultMenuFontSize ) ,
97
107
} )
98
108
} ;
99
109
@@ -110,7 +120,7 @@ private void PopUpContextMenu ()
110
120
AttributedTitle = new Foundation . NSAttributedString (
111
121
Properties . Resources . ResourceEllipsis ,
112
122
new CoreText . CTStringAttributes {
113
- Font = new CoreText . CTFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultFontSize + 1 ) ,
123
+ Font = new CoreText . CTFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultMenuFontSize ) ,
114
124
} )
115
125
} ;
116
126
@@ -137,7 +147,7 @@ private void PopUpContextMenu ()
137
147
AttributedTitle = new Foundation . NSAttributedString (
138
148
Properties . Resources . Reset ,
139
149
new CoreText . CTStringAttributes {
140
- Font = new CoreText . CTFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultFontSize + 1 ) ,
150
+ Font = new CoreText . CTFont ( PropertyEditorControl . DefaultFontName , PropertyEditorControl . DefaultMenuFontSize ) ,
141
151
} )
142
152
} ) ;
143
153
}
@@ -154,34 +164,34 @@ private void ToggleFocusImage (bool focused = false)
154
164
if ( this . viewModel != null ) {
155
165
156
166
switch ( this . viewModel . ValueSource ) {
157
- case ValueSource . Binding :
158
- Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-bound-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-bound-mac-10" ) ;
159
- break ;
160
-
161
- case ValueSource . Default :
162
- Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-default-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-default-mac-10" ) ;
163
- break ;
164
-
165
- case ValueSource . Local :
166
- Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-local-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-local-mac-10" ) ;
167
- break ;
168
-
169
- case ValueSource . Inherited :
170
- Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-inherited-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-inherited-mac-10" ) ;
171
- break ;
172
-
173
- case ValueSource . Resource :
174
- Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-inherited-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-inherited-mac-10" ) ;
175
- break ;
176
-
177
- case ValueSource . Unset :
178
- Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-default-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-default-mac-10" ) ;
179
- break ;
180
-
181
- default :
182
- // To Handle ValueSource.DefaultStyle, ValueSource.Style etc.
183
- Image = null ;
184
- break ;
167
+ case ValueSource . Binding :
168
+ Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-bound-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-bound-mac-10" ) ;
169
+ break ;
170
+
171
+ case ValueSource . Default :
172
+ Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-default-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-default-mac-10" ) ;
173
+ break ;
174
+
175
+ case ValueSource . Local :
176
+ Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-local-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-local-mac-10" ) ;
177
+ break ;
178
+
179
+ case ValueSource . Inherited :
180
+ Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-inherited-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-inherited-mac-10" ) ;
181
+ break ;
182
+
183
+ case ValueSource . Resource :
184
+ Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-inherited-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-inherited-mac-10" ) ;
185
+ break ;
186
+
187
+ case ValueSource . Unset :
188
+ Image = focused ? this . hostResources . GetNamedImage ( "pe-property-button-default-mac-active-10" ) : this . hostResources . GetNamedImage ( "pe-property-button-default-mac-10" ) ;
189
+ break ;
190
+
191
+ default :
192
+ // To Handle ValueSource.DefaultStyle, ValueSource.Style etc.
193
+ Image = null ;
194
+ break ;
185
195
}
186
196
}
187
197
}
@@ -251,7 +261,7 @@ private void OnResourceRequested (object sender, EventArgs e)
251
261
Appearance = EffectiveAppearance
252
262
} ;
253
263
254
- var resourceSelectorPopOver = new AutoClosePopOver ( this . hostResources ) {
264
+ var resourceSelectorPopOver = new AutoClosePopOver ( this . hostResources ) {
255
265
ContentViewController = new NSViewController ( null , null ) { View = requestResourceView } ,
256
266
} ;
257
267
@@ -271,5 +281,17 @@ private void OnBindingRequested (object sender, CreateBindingRequestedEventArgs
271
281
e . BindingObject = bindingEditorWindow . ViewModel . SelectedObjects . Single ( ) ;
272
282
}
273
283
}
284
+
285
+ private void OnCreateVariantRequested ( object sender , CreateVariantEventArgs e )
286
+ {
287
+ var createVariantWindow = new CreateVariantWindow ( this . hostResources , this . viewModel ) {
288
+ Appearance = EffectiveAppearance ,
289
+ } ;
290
+
291
+ var result = ( NSModalResponse ) ( int ) NSApplication . SharedApplication . RunModalForWindow ( createVariantWindow ) ;
292
+ if ( result == NSModalResponse . OK ) {
293
+ e . Variation = Task . FromResult ( createVariantWindow . ViewModel . Variation ) ;
294
+ }
295
+ }
274
296
}
275
297
}
0 commit comments