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

Commit cb6103b

Browse files
Dominique LouisCartBlanche
Dominique Louis
authored andcommitted
[Mac] Initial Variations Implementation
1 parent 807d5c7 commit cb6103b

19 files changed

+569
-66
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/PropertyButton.cs

+70-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using AppKit;
34
using CoreGraphics;
45
using Xamarin.PropertyEditing.ViewModels;
@@ -19,6 +20,7 @@ internal PropertyViewModel ViewModel
1920
set {
2021
if (this.viewModel != null) {
2122
this.viewModel.PropertyChanged -= OnPropertyChanged;
23+
this.viewModel.CreateVariantRequested -= OnCreateVariantRequested;
2224
}
2325

2426
this.viewModel = value;
@@ -110,13 +112,27 @@ private void PopUpContextMenu ()
110112
this.popUpContextMenu.AddItem (NSMenuItem.SeparatorItem);
111113

112114
// 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) {
114116
AttributedTitle = new Foundation.NSAttributedString (
115117
Properties.Resources.Reset,
116118
new CoreText.CTStringAttributes {
117119
Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1),
118120
})
119121
});
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+
}
120136
}
121137

122138
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)
166182
private void ValueSourceChanged (ValueSource valueSource)
167183
{
168184
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;
197213
}
198214

199215
ToggleFocusImage ();
@@ -228,13 +244,37 @@ private void OnResourceRequested (object sender, EventArgs e)
228244
Appearance = EffectiveAppearance
229245
};
230246

231-
var resourceSelectorPopOver = new AutoClosePopOver(this.hostResources) {
247+
var resourceSelectorPopOver = new AutoClosePopOver (this.hostResources) {
232248
ContentViewController = new NSViewController (null, null) { View = requestResourceView },
233249
};
234250

235251
requestResourceView.PopOver = resourceSelectorPopOver;
236252

237253
resourceSelectorPopOver.Show (requestResourceView.Frame, (NSView)this, NSRectEdge.MinYEdge);
238254
}
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+
}
239279
}
240280
}

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
{

Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Xamarin.PropertyEditing.Mac
88
internal abstract class EntryPropertyEditor<T>
99
: PropertyEditorControl<PropertyViewModel<T>>
1010
{
11-
public EntryPropertyEditor (IHostResourceProvider hostResources)
11+
protected EntryPropertyEditor (IHostResourceProvider hostResources)
1212
: base (hostResources)
1313
{
1414
Entry = new PropertyTextField {

Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourceView.cs

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ internal class RequestResourceView
2626
NSSegmentedControl segmentedControl;
2727
NSButton showPreviewImage;
2828
RequestResourcePanel resourceSelectorPanel;
29-
30-
public NSPopover PopOver { get; internal set; }
31-
3229
private bool showPreview;
3330
public bool ShowPreview
3431
{

0 commit comments

Comments
 (0)