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

Commit 4e23272

Browse files
authored
Merge pull request #508 from xamarin/ermau-fix-hostresources
[mac] Fix editor panel theme handling
2 parents 33c8c86 + 78f6f47 commit 4e23272

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,27 @@ internal class DynamicFillBox
88
{
99
public DynamicFillBox (IHostResourceProvider hostResources, string colorName)
1010
{
11-
this.hostResources = hostResources;
11+
if (hostResources == null)
12+
throw new ArgumentNullException (nameof (hostResources));
13+
1214
BorderWidth = 0;
1315
BoxType = NSBoxType.NSBoxCustom;
1416
TranslatesAutoresizingMaskIntoConstraints = false;
1517
this.colorName = colorName;
1618
if (colorName == null)
1719
FillColor = NSColor.Clear;
1820

19-
ViewDidChangeEffectiveAppearance ();
21+
HostResourceProvider = hostResources;
22+
}
23+
24+
public IHostResourceProvider HostResourceProvider
25+
{
26+
get { return this.hostResources; }
27+
set
28+
{
29+
this.hostResources = value;
30+
ViewDidChangeEffectiveAppearance ();
31+
}
2032
}
2133

2234
public string FillColorName
@@ -37,10 +49,14 @@ public override void ViewDidChangeEffectiveAppearance ()
3749
if (this.colorName == null)
3850
return;
3951

40-
FillColor = this.hostResources.GetNamedColor (this.colorName);
52+
NSColor color = this.hostResources.GetNamedColor (this.colorName);
53+
if (color == null)
54+
return;
55+
56+
FillColor = color;
4157
}
4258

43-
private readonly IHostResourceProvider hostResources;
59+
private IHostResourceProvider hostResources;
4460
private string colorName;
4561
}
4662
}

Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ public IHostResourceProvider HostResourceProvider
6464
throw new ArgumentNullException (nameof (value), "Cannot set HostResourceProvider to null");
6565

6666
this.hostResources = value;
67-
if (this.propertyTable.Delegate != null)
68-
this.propertyTable.Delegate = new PropertyTableDelegate (value, this.dataSource);
67+
UpdateResourceProvider ();
6968
}
7069
}
7170

@@ -139,31 +138,31 @@ public override void ViewDidChangeEffectiveAppearance ()
139138

140139
private NSSearchField propertyFilter;
141140
private NSStackView tabStack;
141+
private DynamicFillBox header, border;
142142

143-
// Shared initialization code
144143
private void Initialize ()
145144
{
146145
AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
147146

148147
NSControlSize controlSize = NSControlSize.Small;
149148

150-
var header = new DynamicFillBox (HostResourceProvider, NamedResources.PanelTabBackground) {
149+
this.header = new DynamicFillBox (HostResourceProvider, NamedResources.PanelTabBackground) {
151150
ContentViewMargins = new CGSize (0, 0),
152151
ContentView = new NSView ()
153152
};
154-
AddSubview (header);
153+
AddSubview (this.header);
155154

156-
var border = new DynamicFillBox (HostResourceProvider, NamedResources.TabBorderColor) {
155+
this.border = new DynamicFillBox (HostResourceProvider, NamedResources.TabBorderColor) {
157156
Frame = new CGRect (0, 0, 1, 1)
158157
};
159-
header.AddSubview (border);
158+
header.AddSubview (this.border);
160159

161160
this.propertyFilter = new NSSearchField {
162161
ControlSize = controlSize,
163162
PlaceholderString = LocalizationResources.PropertyFilterLabel,
164163
TranslatesAutoresizingMaskIntoConstraints = false,
165164
};
166-
((NSView)header.ContentView).AddSubview (this.propertyFilter);
165+
((NSView)this.header.ContentView).AddSubview (this.propertyFilter);
167166

168167
this.propertyFilter.Changed += OnPropertyFilterChanged;
169168

@@ -173,7 +172,7 @@ private void Initialize ()
173172
EdgeInsets = new NSEdgeInsets (0, 0, 0, 0)
174173
};
175174

176-
((NSView)header.ContentView).AddSubview (this.tabStack);
175+
((NSView)this.header.ContentView).AddSubview (this.tabStack);
177176

178177
this.propertyTable = new FirstResponderOutlineView {
179178
RefusesFirstResponder = true,
@@ -219,6 +218,17 @@ private void Initialize ()
219218
ViewDidChangeEffectiveAppearance ();
220219
}
221220

221+
private void UpdateResourceProvider()
222+
{
223+
if (this.propertyTable.Delegate != null)
224+
this.propertyTable.Delegate = new PropertyTableDelegate (HostResourceProvider, this.dataSource);
225+
226+
this.header.HostResourceProvider = HostResourceProvider;
227+
this.border.HostResourceProvider = HostResourceProvider;
228+
229+
ViewDidChangeEffectiveAppearance ();
230+
}
231+
222232
private void OnPropertiesChanged (object sender, EventArgs e)
223233
{
224234
this.propertyTable.ReloadData ();

0 commit comments

Comments
 (0)