Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit a892d4e

Browse files
Dominique LouisCartBlanche
Dominique Louis
authored andcommitted
[Mac] Initial Variations Implementation
1 parent f77ce63 commit a892d4e

21 files changed

+496
-43
lines changed

Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using AppKit;
45
using Xamarin.PropertyEditing.ViewModels;
56

67
namespace Xamarin.PropertyEditing.Mac
@@ -9,6 +10,8 @@ internal class BasePopOverViewModelControl : BasePopOverControl
910
{
1011
internal PropertyViewModel ViewModel { get; }
1112

13+
public AutoClosePopOver PopOver { get; internal set; }
14+
1215
public BasePopOverViewModelControl (IHostResourceProvider hostResources, PropertyViewModel viewModel, string title, string imageNamed)
1316
: base (hostResources, title, imageNamed)
1417
{

Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs

+27-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,33 @@ public CommandButton ()
3333
private void CanExecuteChanged (object sender, EventArgs e)
3434
{
3535
if (sender is ICommand cmd)
36-
this.Enabled = cmd.CanExecute (null);
36+
Enabled = cmd.CanExecute (null);
37+
}
38+
}
39+
40+
internal class FocusableCommandButton : CommandButton
41+
{
42+
public override bool CanBecomeKeyView { get { return Enabled; } }
43+
44+
public FocusableCommandButton ()
45+
{
46+
AllowsExpansionToolTips = true;
47+
AllowsMixedState = true;
48+
Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
49+
Cell.UsesSingleLineMode = true;
50+
ControlSize = NSControlSize.Small;
51+
Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small));
52+
Title = string.Empty;
53+
TranslatesAutoresizingMaskIntoConstraints = false;
54+
}
55+
56+
public override bool BecomeFirstResponder ()
57+
{
58+
var willBecomeFirstResponder = base.BecomeFirstResponder ();
59+
if (willBecomeFirstResponder) {
60+
ScrollRectToVisible (Bounds);
61+
}
62+
return willBecomeFirstResponder;
3763
}
3864
}
3965
}

Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs

+28
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,33 @@ public static CommonColor UpdateCMYK (
116116
k: k ?? color.K,
117117
alpha: alpha ?? color.A);
118118
}
119+
120+
public static CGPath ToCGPath (this NSBezierPath nsPath)
121+
{
122+
var cgPath = new CGPath ();
123+
for (var i = 0; i < nsPath.ElementCount; i++) {
124+
NSBezierPathElement type = nsPath.ElementAt (i, out CGPoint[] points);
125+
126+
switch (type) {
127+
case NSBezierPathElement.ClosePath:
128+
cgPath.CloseSubpath ();
129+
break;
130+
131+
case NSBezierPathElement.CurveTo:
132+
cgPath.AddCurveToPoint (points[0], points[1], points[2]);
133+
break;
134+
135+
case NSBezierPathElement.LineTo:
136+
cgPath.AddLineToPoint (points[0]);
137+
break;
138+
139+
case NSBezierPathElement.MoveTo:
140+
cgPath.MoveToPoint (points[0]);
141+
break;
142+
}
143+
}
144+
145+
return cgPath;
146+
}
119147
}
120148
}

Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs

+54-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Threading.Tasks;
34
using AppKit;
45
using CoreGraphics;
56
using Xamarin.PropertyEditing.ViewModels;
@@ -20,16 +21,25 @@ internal PropertyViewModel ViewModel
2021
set {
2122
if (this.viewModel != null) {
2223
this.viewModel.PropertyChanged -= OnPropertyChanged;
24+
2325
if (this.viewModel.SupportsBindings)
2426
this.viewModel.CreateBindingRequested -= OnBindingRequested;
27+
28+
if (this.viewModel.HasVariations)
29+
this.viewModel.CreateVariantRequested -= OnCreateVariantRequested;
2530
}
2631

2732
this.viewModel = value;
2833

2934
if (this.viewModel != null) {
3035
this.viewModel.PropertyChanged += OnPropertyChanged;
36+
3137
if (this.viewModel.SupportsBindings)
3238
this.viewModel.CreateBindingRequested += OnBindingRequested;
39+
40+
if (this.viewModel.HasVariations)
41+
this.viewModel.CreateVariantRequested += OnCreateVariantRequested;
42+
3343
ValueSourceChanged (this.viewModel.ValueSource);
3444
}
3545

@@ -93,7 +103,7 @@ private void PopUpContextMenu ()
93103
AttributedTitle = new Foundation.NSAttributedString (
94104
Properties.Resources.CustomExpressionEllipsis,
95105
new CoreText.CTStringAttributes {
96-
Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
106+
Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultMenuFontSize),
97107
})
98108
};
99109

@@ -110,7 +120,7 @@ private void PopUpContextMenu ()
110120
AttributedTitle = new Foundation.NSAttributedString (
111121
Properties.Resources.ResourceEllipsis,
112122
new CoreText.CTStringAttributes {
113-
Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
123+
Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultMenuFontSize),
114124
})
115125
};
116126

@@ -137,7 +147,7 @@ private void PopUpContextMenu ()
137147
AttributedTitle = new Foundation.NSAttributedString (
138148
Properties.Resources.Reset,
139149
new CoreText.CTStringAttributes {
140-
Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
150+
Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultMenuFontSize),
141151
})
142152
});
143153
}
@@ -154,34 +164,34 @@ private void ToggleFocusImage (bool focused = false)
154164
if (this.viewModel != null) {
155165

156166
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;
185195
}
186196
}
187197
}
@@ -251,7 +261,7 @@ private void OnResourceRequested (object sender, EventArgs e)
251261
Appearance = EffectiveAppearance
252262
};
253263

254-
var resourceSelectorPopOver = new AutoClosePopOver(this.hostResources) {
264+
var resourceSelectorPopOver = new AutoClosePopOver (this.hostResources) {
255265
ContentViewController = new NSViewController (null, null) { View = requestResourceView },
256266
};
257267

@@ -271,5 +281,17 @@ private void OnBindingRequested (object sender, CreateBindingRequestedEventArgs
271281
e.BindingObject = bindingEditorWindow.ViewModel.SelectedObjects.Single ();
272282
}
273283
}
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+
}
274296
}
275297
}

Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public NSColor TextColor {
3939
internal set { this.label.TextColor = value; }
4040
}
4141

42+
public bool Bordered {
43+
get { return this.label.Bordered; }
44+
internal set { this.label.Bordered = value; }
45+
}
46+
4247
public virtual NSBackgroundStyle BackgroundStyle
4348
{
4449
[Export ("backgroundStyle")] get => this.label.Cell.BackgroundStyle;

Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ internal class CustomExpressionView : BasePopOverViewModelControl
1515
private const string PreviewCustomExpressionString = "PreviewCustomExpression";
1616
private const string AutocompleteItemsString = "AutocompleteItems";
1717

18-
public AutoClosePopOver PopOver { get; internal set; }
19-
2018
public CustomExpressionView (IHostResourceProvider hostResources, PropertyViewModel viewModel)
2119
: base (hostResources, viewModel, Properties.Resources.CustomExpression, "pe-custom-expression-32")
2220
{

0 commit comments

Comments
 (0)