@@ -17,6 +17,7 @@ public EditorContainer (IHostResourceProvider hostResources, IEditorView editorV
17
17
}
18
18
19
19
private const string FrameChangedObservableProperty = "frame" ;
20
+ private readonly NSString observerKeyPath = new NSString ( FrameChangedObservableProperty ) ;
20
21
21
22
public IEditorView EditorView => ( IEditorView ) NativeContainer ;
22
23
@@ -131,62 +132,62 @@ private void UpdateVariations ()
131
132
if ( this . viewModelAsPropertyViewModel . HasVariations ) {
132
133
133
134
if ( this . viewModelAsPropertyViewModel . IsVariant ) {
134
-
135
- if ( this . deleteVariantButton == null ) {
136
- this . deleteVariantButton = new VariationButton ( HostResources , "pe-variation-delete-button-active-mac-10" , "pe-variation-delete-button-mac-10" ) {
137
- AccessibilityEnabled = true ,
138
- AccessibilityTitle = Properties . Resources . AccessibilityDeleteVariationButton ,
139
- Command = this . viewModelAsPropertyViewModel . RemoveVariationCommand ,
140
- ToolTip = Properties . Resources . RemoveVariant ,
141
- TranslatesAutoresizingMaskIntoConstraints = false ,
142
- } ;
143
-
144
- AddSubview ( this . deleteVariantButton ) ;
145
- AddConstraints ( new [ ] {
146
- NSLayoutConstraint . Create ( this . deleteVariantButton , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , 8f ) ,
147
- NSLayoutConstraint . Create ( this . deleteVariantButton , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 20f ) ,
148
- } ) ;
149
-
150
- this . variationControlsList . Add ( this . deleteVariantButton ) ;
151
-
152
- // Hook into the delete button's frame change, so we can fire off some drawing. If there's a better way, let me know.
153
- this . deleteVariantButton . AddObserver ( this , new NSString ( FrameChangedObservableProperty ) , NSKeyValueObservingOptions . New , IntPtr . Zero ) ;
154
- }
135
+ this . deleteVariantButton = new VariationButton ( HostResources , "pe-variation-delete-button-active-mac-10" , "pe-variation-delete-button-mac-10" ) {
136
+ AccessibilityEnabled = true ,
137
+ AccessibilityTitle = Properties . Resources . AccessibilityDeleteVariationButton ,
138
+ Command = this . viewModelAsPropertyViewModel . RemoveVariationCommand ,
139
+ ToolTip = Properties . Resources . RemoveVariant ,
140
+ TranslatesAutoresizingMaskIntoConstraints = false ,
141
+ } ;
142
+
143
+ AddSubview ( this . deleteVariantButton ) ;
144
+ AddConstraints ( new [ ] {
145
+ NSLayoutConstraint . Create ( this . deleteVariantButton , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , 8f ) ,
146
+ NSLayoutConstraint . Create ( this . deleteVariantButton , NSLayoutAttribute . Left , NSLayoutRelation . Equal , this , NSLayoutAttribute . Left , 1f , 20f ) ,
147
+ } ) ;
148
+
149
+ this . variationControlsList . Add ( this . deleteVariantButton ) ;
150
+
151
+ // Hook into the delete button's frame change, so we can fire off some drawing. If there's a better way, let me know.
152
+ this . deleteVariantButton . AddObserver ( this , this . observerKeyPath , NSKeyValueObservingOptions . New , IntPtr . Zero ) ;
153
+
154
+
155
+ // Cache these before the loop
156
+ var variationBgColour = HostResources . GetNamedColor ( NamedResources . FrameBoxButtonBackgroundColor ) ;
155
157
156
158
NSView previousControl = this . deleteVariantButton ;
157
159
foreach ( PropertyVariationOption item in this . viewModelAsPropertyViewModel . Variation ) {
158
- var selectedVariationTextField = new UnfocusableTextField {
159
- BackgroundColor = HostResources . GetNamedColor ( NamedResources . FrameBoxButtonBackgroundColor ) ,
160
+ var selectedVariationTextField = new UnfocusableTextField {
161
+ BackgroundColor = variationBgColour ,
160
162
Bordered = false ,
161
- Font = NSFont . SystemFontOfSize ( NSFont . SystemFontSizeForControlSize ( NSControlSize . Small ) - 1f ) ,
163
+ Font = VariationOptionFont ,
162
164
TranslatesAutoresizingMaskIntoConstraints = false ,
163
165
StringValue = string . Format ( " {0}: {1} " , item . Category , item . Name ) ,
164
166
} ;
165
167
166
168
AddSubview ( selectedVariationTextField ) ;
167
- AddConstraints ( new [ ] {
168
- NSLayoutConstraint . Create ( selectedVariationTextField , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , 5f ) ,
169
+ AddConstraints ( new [ ] {
170
+ NSLayoutConstraint . Create ( selectedVariationTextField , NSLayoutAttribute . Top , NSLayoutRelation . Equal , this , NSLayoutAttribute . Top , 1f , VariationBorderOffset ) ,
169
171
NSLayoutConstraint . Create ( selectedVariationTextField , NSLayoutAttribute . Left , NSLayoutRelation . Equal , previousControl , NSLayoutAttribute . Right , 1f , 6f ) ,
170
172
NSLayoutConstraint . Create ( selectedVariationTextField , NSLayoutAttribute . Height , NSLayoutRelation . Equal , 1f , 16f ) ,
171
173
} ) ;
172
174
173
175
previousControl = selectedVariationTextField ;
174
176
this . variationControlsList . Add ( selectedVariationTextField ) ;
175
177
}
176
- } else {
177
- if ( this . addVariantButton == null ) {
178
- this . addVariantButton = new VariationButton ( HostResources , "pe-variation-add-button-active-mac-10" , "pe-variation-add-button-mac-10" ) {
179
- AccessibilityEnabled = true ,
180
- AccessibilityTitle = Properties . Resources . AccessibilityAddVariationButton ,
181
- Command = this . viewModelAsPropertyViewModel . RequestCreateVariantCommand ,
182
- ToolTip = Properties . Resources . AddVariant ,
183
- TranslatesAutoresizingMaskIntoConstraints = false ,
184
- } ;
185
-
186
- LeftEdgeView = this . addVariantButton ;
187
-
188
- this . variationControlsList . Add ( this . addVariantButton ) ;
189
- }
178
+ } else {
179
+ this . addVariantButton = new VariationButton ( HostResources , "pe-variation-add-button-active-mac-10" , "pe-variation-add-button-mac-10" ) {
180
+ AccessibilityEnabled = true ,
181
+ AccessibilityTitle = Properties . Resources . AccessibilityAddVariationButton ,
182
+ Command = this . viewModelAsPropertyViewModel . RequestCreateVariantCommand ,
183
+ ToolTip = Properties . Resources . AddVariant ,
184
+ TranslatesAutoresizingMaskIntoConstraints = false ,
185
+ } ;
186
+
187
+ LeftEdgeView = this . addVariantButton ;
188
+
189
+ this . variationControlsList . Add ( this . addVariantButton ) ;
190
+
190
191
}
191
192
}
192
193
}
@@ -201,7 +202,11 @@ private void ClearSubViews ()
201
202
this . variationControlsList . Clear ( ) ;
202
203
203
204
this . addVariantButton = null ;
204
- this . deleteVariantButton = null ;
205
+
206
+ if ( this . deleteVariantButton != null ) {
207
+ this . deleteVariantButton . RemoveObserver ( this , this . observerKeyPath ) ;
208
+ this . deleteVariantButton = null ;
209
+ }
205
210
}
206
211
207
212
private void ClearChildLayers ( )
@@ -315,6 +320,8 @@ public NSColor LabelTextColor {
315
320
private VariationButton addVariantButton ;
316
321
private const float treeLineLeftEdge = 14f ;
317
322
private const float treeLineLeafIndent = 4f ;
323
+ internal const float VariationBorderOffset = 5f ;
324
+ internal static NSFont VariationOptionFont = NSFont . SystemFontOfSize ( NSFont . SystemFontSizeForControlSize ( NSControlSize . Small ) - 1f ) ;
318
325
private nfloat ViewVariationChildVerticalDrawPoint => this . deleteVariantButton . Frame . Top + 5 ;
319
326
private nfloat ViewVariationParentVerticalDrawPoint => this . addVariantButton . Frame . Top - 2 ;
320
327
private PropertyViewModel viewModelAsPropertyViewModel ;
0 commit comments