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

Commit 0acb05e

Browse files
author
Eric Maupin
committed
[mac] Update arrange mode to tabs
1 parent 488124c commit 0acb05e

File tree

15 files changed

+222
-60
lines changed

15 files changed

+222
-60
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
},
6+
"colors" : [
7+
{
8+
"idiom" : "universal",
9+
"color" : {
10+
"color-space" : "srgb",
11+
"components" : {
12+
"red" : "0xF8",
13+
"alpha" : "1.000",
14+
"blue" : "0xF7",
15+
"green" : "0xF8"
16+
}
17+
}
18+
},
19+
{
20+
"idiom" : "universal",
21+
"appearances" : [
22+
{
23+
"appearance" : "luminosity",
24+
"value" : "dark"
25+
}
26+
],
27+
"color" : {
28+
"color-space" : "srgb",
29+
"components" : {
30+
"red" : "0x55",
31+
"alpha" : "1.000",
32+
"blue" : "0x55",
33+
"green" : "0x55"
34+
}
35+
}
36+
}
37+
]
38+
}

Xamarin.PropertyEditing.Mac.Standalone/Xamarin.PropertyEditing.Mac.Standalone.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<ImageAsset Include="Assets.xcassets\ValueBlockBackgroundColor.colorset\Contents.json" />
7676
<ImageAsset Include="Assets.xcassets\DescriptionLabelColor.colorset\Contents.json" />
7777
<ImageAsset Include="Assets.xcassets\TabBorderColor.colorset\Contents.json" />
78+
<ImageAsset Include="Assets.xcassets\PanelTabBackground.colorset\Contents.json" />
7879
</ItemGroup>
7980
<ItemGroup>
8081
<Folder Include="Resources\" />
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using AppKit;
3+
using CoreGraphics;
4+
using Foundation;
5+
6+
namespace Xamarin.PropertyEditing.Mac
7+
{
8+
internal class TabButton
9+
: NSButton
10+
{
11+
public TabButton (IHostResourceProvider hostResource, string imageName)
12+
{
13+
if (hostResource == null)
14+
throw new ArgumentNullException (nameof (hostResource));
15+
if (imageName == null)
16+
throw new ArgumentNullException (nameof (imageName));
17+
18+
Bordered = false;
19+
Action = new ObjCRuntime.Selector (ClickedName);
20+
21+
var clicked = new NSClickGestureRecognizer (OnClicked);
22+
AddGestureRecognizer (clicked);
23+
24+
this.hostResource = hostResource;
25+
this.imageName = imageName;
26+
27+
ViewDidChangeEffectiveAppearance ();
28+
}
29+
30+
public event EventHandler Clicked;
31+
32+
public bool Selected
33+
{
34+
get { return this.selected; }
35+
set
36+
{
37+
Enabled = value;
38+
this.selected = value;
39+
NeedsDisplay = true;
40+
}
41+
}
42+
43+
public override CGSize IntrinsicContentSize
44+
{
45+
get
46+
{
47+
var size = base.IntrinsicContentSize;
48+
return new CGSize (size.Width + 2 + 10, size.Height + 2 + 10);
49+
}
50+
}
51+
52+
public override void ViewDidChangeEffectiveAppearance ()
53+
{
54+
base.ViewDidChangeEffectiveAppearance ();
55+
Image = this.hostResource.GetNamedImage (this.imageName);
56+
}
57+
58+
public override void DrawRect (CGRect dirtyRect)
59+
{
60+
base.DrawRect (dirtyRect);
61+
if (!Selected)
62+
return;
63+
64+
NSBezierPath path = new NSBezierPath ();
65+
path.AppendPathWithRect (new CGRect (Bounds.X, Bounds.Height - 2, Bounds.Width, 2));
66+
(Selected ? NSColor.Text : NSColor.DisabledControlText).Set ();
67+
path.Fill ();
68+
}
69+
70+
private readonly string imageName;
71+
private readonly IHostResourceProvider hostResource;
72+
private bool selected;
73+
74+
private const string ClickedName = "OnClicked";
75+
76+
[Export (ClickedName)]
77+
private void OnClicked()
78+
{
79+
Clicked?.Invoke (this, EventArgs.Empty);
80+
}
81+
}
82+
}

Xamarin.PropertyEditing.Mac/HostResourceProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ public static class NamedResources
5252
public const string DescriptionLabelColor = "DescriptionLabelColor";
5353
public const string ValueBlockBackgroundColor = "ValueBlockBackgroundColor";
5454
public const string TabBorderColor = "TabBorderColor";
55+
public const string PanelTabBackground = "PanelTabBackground";
5556
}
5657
}

Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Collections.Generic;
34
using System.ComponentModel;
45

@@ -43,13 +44,6 @@ public bool IsArrangeEnabled
4344
return;
4445

4546
this.isArrangeEnabled = value;
46-
if (value) {
47-
AddSubview (this.propertyArrangeMode);
48-
AddSubview (this.propertyArrangeModeLabel);
49-
} else {
50-
this.propertyArrangeMode.RemoveFromSuperview ();
51-
this.propertyArrangeModeLabel.RemoveFromSuperview ();
52-
}
5347
}
5448
}
5549

@@ -77,6 +71,11 @@ public TargetPlatform TargetPlatform
7771
if (this.viewModel != null) {
7872
this.viewModel.ArrangedPropertiesChanged -= OnPropertiesChanged;
7973
this.viewModel.PropertyChanged -= OnVmPropertyChanged;
74+
75+
var views = this.tabStack.Views;
76+
for (int i = 0; i < views.Length; i++) {
77+
((TabButton)views[i]).Clicked -= OnArrangeModeChanged;
78+
}
8079
}
8180

8281
this.targetPlatform = value;
@@ -90,12 +89,18 @@ public TargetPlatform TargetPlatform
9089
this.viewModel.ArrangedPropertiesChanged += OnPropertiesChanged;
9190
this.viewModel.PropertyChanged += OnVmPropertyChanged;
9291

93-
this.propertyArrangeMode.RemoveAll ();
94-
foreach (ArrangeModeViewModel item in this.viewModel.ArrangeModes) {
95-
var itemAsString = new NSString (item.ArrangeMode.ToString ());
96-
this.propertyArrangeMode.Add (itemAsString);
97-
if (item.IsChecked)
98-
this.propertyArrangeMode.Select (itemAsString);
92+
for (int i = 0; i < this.viewModel.ArrangeModes.Count; i++) {
93+
var item = this.viewModel.ArrangeModes[i];
94+
string imageName = GetIconName (item.ArrangeMode);
95+
TabButton arrangeMode = new TabButton (this.hostResources, imageName) {
96+
Bounds = new CGRect (0, 0, 32, 30),
97+
Tag = i,
98+
Selected = item.IsChecked
99+
};
100+
101+
arrangeMode.Clicked += OnArrangeModeChanged;
102+
103+
this.tabStack.AddView (arrangeMode, NSStackViewGravity.Top);
99104
}
100105
}
101106
}
@@ -113,12 +118,9 @@ public void Select (IEnumerable<object> selectedItems)
113118

114119
public override void ViewDidChangeEffectiveAppearance ()
115120
{
116-
if (this.propertyArrangeMode == null)
121+
if (this.propertyTable == null)
117122
return;
118123

119-
this.propertyArrangeMode.Font = HostResourceProvider.GetNamedFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize);
120-
this.propertyFilter.Font = HostResourceProvider.GetNamedFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize);
121-
122124
this.propertyTable.BackgroundColor = this.hostResources.GetNamedColor (NamedResources.PadBackgroundColor);
123125
}
124126

@@ -130,8 +132,7 @@ public override void ViewDidChangeEffectiveAppearance ()
130132
private PanelViewModel viewModel;
131133

132134
private NSSearchField propertyFilter;
133-
private NSComboBox propertyArrangeMode;
134-
private NSTextField propertyArrangeModeLabel;
135+
private NSStackView tabStack;
135136

136137
// Shared initialization code
137138
private void Initialize ()
@@ -140,79 +141,73 @@ private void Initialize ()
140141

141142
NSControlSize controlSize = NSControlSize.Small;
142143

143-
this.propertyArrangeModeLabel = new NSTextField {
144-
ControlSize = controlSize,
145-
BackgroundColor = NSColor.Clear,
146-
Bezeled = false,
147-
Editable = false,
148-
StringValue = LocalizationResources.ArrangeByLabel,
149-
TranslatesAutoresizingMaskIntoConstraints = false,
144+
var header = new DynamicFillBox (HostResourceProvider, NamedResources.PanelTabBackground) {
145+
ContentViewMargins = new CGSize (0, 0),
146+
ContentView = new NSView ()
150147
};
148+
AddSubview (header);
151149

152-
this.propertyArrangeMode = new NSComboBox {
153-
ControlSize = controlSize,
154-
Editable = false,
155-
TranslatesAutoresizingMaskIntoConstraints = false,
150+
var border = new DynamicFillBox (HostResourceProvider, NamedResources.TabBorderColor) {
151+
Frame = new CGRect (0, 0, 1, 1)
156152
};
157-
158-
if (IsArrangeEnabled) {
159-
AddSubview (this.propertyArrangeMode);
160-
AddSubview (this.propertyArrangeModeLabel);
161-
}
153+
header.AddSubview (border);
162154

163155
this.propertyFilter = new NSSearchField {
164156
ControlSize = controlSize,
165157
PlaceholderString = LocalizationResources.PropertyFilterLabel,
166158
TranslatesAutoresizingMaskIntoConstraints = false,
167159
};
168-
AddSubview (this.propertyFilter);
160+
((NSView)header.ContentView).AddSubview (this.propertyFilter);
169161

170-
// If either the Filter Mode or PropertySearchFilter Change Filter the Data
171-
this.propertyArrangeMode.SelectionChanged += OnArrangeModeChanged;
172162
this.propertyFilter.Changed += OnPropertyFilterChanged;
173163

164+
this.tabStack = new NSStackView {
165+
Orientation = NSUserInterfaceLayoutOrientation.Horizontal,
166+
TranslatesAutoresizingMaskIntoConstraints = false,
167+
EdgeInsets = new NSEdgeInsets (0, 0, 0, 0)
168+
};
169+
170+
((NSView)header.ContentView).AddSubview (this.tabStack);
171+
174172
this.propertyTable = new FirstResponderOutlineView {
175173
RefusesFirstResponder = true,
176-
AutoresizingMask = NSViewResizingMask.WidthSizable,
177174
SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.None,
178175
HeaderView = null,
179176
};
180177

181-
#if DESIGNER_DEBUG
182-
propertyTable.GridStyleMask = NSTableViewGridStyle.SolidHorizontalLine | NSTableViewGridStyle.SolidVerticalLine;
183-
#endif
184-
185178
var propertyEditors = new NSTableColumn (PropertyEditorColId);
186179
this.propertyTable.AddColumn (propertyEditors);
187180

188181
// Set OutlineTableColumn or the arrows showing children/expansion will not be drawn
189182
this.propertyTable.OutlineTableColumn = propertyEditors;
190183

191-
// create a table view and a scroll view
192184
var tableContainer = new NSScrollView {
193185
TranslatesAutoresizingMaskIntoConstraints = false,
194186
};
195187

196-
// add the panel to the window
197188
tableContainer.DocumentView = this.propertyTable;
198189
AddSubview (tableContainer);
199190

200191
this.AddConstraints (new[] {
201-
NSLayoutConstraint.Create (this.propertyArrangeModeLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f),
202-
NSLayoutConstraint.Create (this.propertyArrangeModeLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 10f),
192+
NSLayoutConstraint.Create (header, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 0),
193+
NSLayoutConstraint.Create (header, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1, 0),
194+
NSLayoutConstraint.Create (header, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, 30),
195+
196+
NSLayoutConstraint.Create (this.tabStack, NSLayoutAttribute.Left, NSLayoutRelation.Equal, header, NSLayoutAttribute.Left, 1, 0),
197+
NSLayoutConstraint.Create (this.tabStack, NSLayoutAttribute.Top, NSLayoutRelation.Equal, header, NSLayoutAttribute.Top, 1, 0),
198+
NSLayoutConstraint.Create (this.tabStack, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, header, NSLayoutAttribute.Bottom, 1, 0),
199+
NSLayoutConstraint.Create (this.tabStack, NSLayoutAttribute.Right, NSLayoutRelation.LessThanOrEqual, this.propertyFilter, NSLayoutAttribute.Left, 1, 0),
203200

204-
NSLayoutConstraint.Create (this.propertyArrangeMode, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 4f),
205-
NSLayoutConstraint.Create (this.propertyArrangeMode, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 90f),
206-
NSLayoutConstraint.Create (this.propertyArrangeMode, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 130f),
201+
NSLayoutConstraint.Create (this.propertyFilter, NSLayoutAttribute.Right, NSLayoutRelation.Equal, header, NSLayoutAttribute.Right, 1, -15),
202+
NSLayoutConstraint.Create (this.propertyFilter, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, 150),
203+
NSLayoutConstraint.Create (this.propertyFilter, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, header, NSLayoutAttribute.CenterY, 1, 0),
207204

208-
NSLayoutConstraint.Create (this.propertyFilter, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f),
209-
NSLayoutConstraint.Create (this.propertyFilter, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 255f),
210-
NSLayoutConstraint.Create (this.propertyFilter, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -265f),
205+
NSLayoutConstraint.Create (border, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, header, NSLayoutAttribute.Bottom, 1, 0),
206+
NSLayoutConstraint.Create (border, NSLayoutAttribute.Width, NSLayoutRelation.Equal, header, NSLayoutAttribute.Width, 1, 0),
211207

212-
NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 30f),
213-
NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 10f),
214-
NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -20f),
215-
NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, -37f),
208+
NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Top, NSLayoutRelation.Equal, border, NSLayoutAttribute.Bottom, 1, 0),
209+
NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, 0),
210+
NSLayoutConstraint.Create (tableContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1, 0),
216211
});
217212

218213
ViewDidChangeEffectiveAppearance ();
@@ -227,7 +222,7 @@ private void OnPropertiesChanged (object sender, EventArgs e)
227222

228223
private void OnArrangeModeChanged (object sender, EventArgs e)
229224
{
230-
this.viewModel.ArrangeMode = this.viewModel.ArrangeModes[(int)this.propertyArrangeMode.SelectedIndex].ArrangeMode;
225+
this.viewModel.ArrangeMode = this.viewModel.ArrangeModes[(int)((NSView)sender).Tag].ArrangeMode;
231226
}
232227

233228
private void OnPropertyFilterChanged (object sender, EventArgs e)
@@ -239,8 +234,25 @@ private void OnPropertyFilterChanged (object sender, EventArgs e)
239234

240235
private void OnVmPropertyChanged (object sender, PropertyChangedEventArgs e)
241236
{
242-
if (e.PropertyName == nameof (PanelViewModel.ArrangeMode) || String.IsNullOrEmpty (e.PropertyName))
243-
this.propertyArrangeMode.Select (new NSString (this.viewModel.ArrangeMode.ToString ()));
237+
if (e.PropertyName == nameof (PanelViewModel.ArrangeMode) || String.IsNullOrEmpty (e.PropertyName)) {
238+
int selected = this.viewModel.ArrangeModes.Select (vm => vm.ArrangeMode).IndexOf (this.viewModel.ArrangeMode);
239+
var views = this.tabStack.Views;
240+
for (int i = 0; i < views.Length; i++) {
241+
((TabButton)views[i]).Selected = (i == selected);
242+
}
243+
}
244+
}
245+
246+
private string GetIconName (PropertyArrangeMode mode)
247+
{
248+
switch (mode) {
249+
case PropertyArrangeMode.Name:
250+
return "sort-alphabetically-16";
251+
case PropertyArrangeMode.Category:
252+
return "group-by-category-16";
253+
default:
254+
throw new ArgumentException();
255+
}
244256
}
245257

246258
private class FirstResponderOutlineView : NSOutlineView
142 Bytes
Loading
221 Bytes
Loading
142 Bytes
Loading
219 Bytes
Loading
329 Bytes
Loading

0 commit comments

Comments
 (0)