Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Maupin <ermaup@microsoft.com>2019-01-18 20:49:12 +0300
committerEric Maupin <ermaup@microsoft.com>2019-01-18 20:49:12 +0300
commit22cc654deacc69c8bd60313bf474b94354991553 (patch)
tree58164b5e100ae3faaf739363b05c7d23ef749ab5 /Xamarin.PropertyEditing.Mac
parentea3ffb25b52cc576ebd4ab2418d15ed07b2a8cd5 (diff)
[mac] Fix missing methods
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePanel.cs2
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePreviewPanel.cs158
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/RequestResource/ResourceTableDelegate.cs2
3 files changed, 89 insertions, 73 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePanel.cs b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePanel.cs
index 2a3143b..0d6df02 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePanel.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePanel.cs
@@ -119,7 +119,7 @@ namespace Xamarin.PropertyEditing.Mac
this.tableContainer.DocumentView = resourceTable;
AddSubview (this.tableContainer);
- this.previewPanel = new RequestResourcePreviewPanel (new CGRect (Frame.Width - FrameWidthThird, 0, FrameWidthThird, Frame.Height));
+ this.previewPanel = new RequestResourcePreviewPanel (hostResources, new CGRect (Frame.Width - FrameWidthThird, 0, FrameWidthThird, Frame.Height));
AddSubview (this.previewPanel);
this.AddConstraints (new[] {
diff --git a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePreviewPanel.cs b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePreviewPanel.cs
index aab5ae5..e2b4c4d 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePreviewPanel.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourcePreviewPanel.cs
@@ -8,69 +8,14 @@ namespace Xamarin.PropertyEditing.Mac
{
internal class RequestResourcePreviewPanel : NSView
{
- private UnfocusableTextField noPreviewAvailable;
- private NSView previewView;
-
- private Resource selectedResource;
- public Resource SelectedResource {
- internal get { return this.selectedResource; }
-
- set {
- if (this.selectedResource != value) {
- this.selectedResource = value;
-
- if (this.selectedResource != null) {
- // Let's find the next View
- var pView = GetPreviewView (this.selectedResource);
-
- if (pView == null) {
- ShowNoPreviewText ();
- } else {
- this.noPreviewAvailable.Hidden = true;
- this.previewView.Hidden = false;
-
- switch (this.selectedResource) {
- case Resource<CommonColor> colour:
- if (pView is CommonBrushView cc) {
- cc.Brush = new CommonSolidBrush (colour.Value);
- }
- break;
-
- case Resource<CommonGradientBrush> gradient:
- if (pView is CommonBrushView vg) {
- vg.Brush = gradient.Value;
- }
- break;
-
- case Resource<CommonSolidBrush> solid:
- if (pView is CommonBrushView vs) {
- vs.Brush = solid.Value;
- }
- break;
- }
-
- // Only 1 subview allowed (must be a better way to handle this??)
- if (this.previewView.Subviews.Count () > 0) {
- this.previewView.Subviews[0].RemoveFromSuperview ();
- }
- // Free up anything from the previous view
- this.previewView.AddSubview (pView);
- }
- } else {
- ShowNoPreviewText ();
- }
- }
- }
- }
-
- private void ShowNoPreviewText ()
+ public RequestResourcePreviewPanel (IHostResourceProvider hostResources, CGRect frame)
+ : base (frame)
{
- this.noPreviewAvailable.Hidden = false;
- this.previewView.Hidden = true;
- }
+ if (hostResources == null)
+ throw new ArgumentNullException (nameof (hostResources));
+
+ this.hostResources = hostResources;
- public RequestResourcePreviewPanel (CGRect frame) : base (frame)
- {
var FrameHeightHalf = (Frame.Height - 32) / 2;
var FrameWidthHalf = (Frame.Width - 32) / 2;
var FrameWidthThird = (Frame.Width - 32) / 3;
@@ -88,7 +33,87 @@ namespace Xamarin.PropertyEditing.Mac
AddSubview (this.previewView);
}
- NSView GetPreviewView (Resource resource)
+ public Resource SelectedResource
+ {
+ get { return this.selectedResource; }
+ set
+ {
+ if (this.selectedResource == value)
+ return;
+
+ this.selectedResource = value;
+
+ if (this.selectedResource != null) {
+ PreviewResource ();
+ } else {
+ ShowNoPreviewText ();
+ }
+ }
+ }
+
+ private readonly IHostResourceProvider hostResources;
+
+ private UnfocusableTextField noPreviewAvailable;
+ private NSView previewView;
+
+ private Resource selectedResource;
+
+ private void PreviewResource()
+ {
+ // Let's find the next View
+ var pView = GetPreviewView (this.selectedResource);
+
+ if (pView == null) {
+ ShowNoPreviewText ();
+ } else {
+ this.noPreviewAvailable.Hidden = true;
+ this.previewView.Hidden = false;
+
+ switch (this.selectedResource) {
+ case Resource<CommonColor> colour:
+ if (pView is CommonBrushView cc) {
+ cc.Brush = new CommonSolidBrush (colour.Value);
+ }
+ break;
+
+ case Resource<CommonGradientBrush> gradient:
+ if (pView is CommonBrushView vg) {
+ vg.Brush = gradient.Value;
+ }
+ break;
+
+ case Resource<CommonSolidBrush> solid:
+ if (pView is CommonBrushView vs) {
+ vs.Brush = solid.Value;
+ }
+ break;
+ }
+
+ NSView[] subviews = this.previewView.Subviews;
+ if (subviews.Length > 0) {
+ subviews[0].RemoveFromSuperview ();
+ }
+ // Free up anything from the previous view
+ this.previewView.AddSubview (pView);
+ }
+ }
+
+ private void ShowNoPreviewText ()
+ {
+ this.noPreviewAvailable.Hidden = false;
+ this.previewView.Hidden = true;
+ }
+
+ private NSView SetUpPreviewer (Type previewRenderType)
+ {
+ var view = (NSView)Activator.CreateInstance (previewRenderType, this.hostResources);
+ view.Identifier = previewRenderType.Name;
+ view.Frame = new CGRect (0, 0, this.previewView.Frame.Width, this.previewView.Frame.Height);
+
+ return view;
+ }
+
+ private NSView GetPreviewView (Resource resource)
{
Type[] genericArgs = null;
Type previewRenderType;
@@ -111,15 +136,6 @@ namespace Xamarin.PropertyEditing.Mac
return SetUpPreviewer (previewRenderType);
}
- private NSView SetUpPreviewer (Type previewRenderType)
- {
- var view = (NSView)Activator.CreateInstance (previewRenderType);
- view.Identifier = previewRenderType.Name;
- view.Frame = new CGRect (0, 0, this.previewView.Frame.Width, this.previewView.Frame.Height);
-
- return view;
- }
-
internal static readonly Dictionary<Type, Type> PreviewValueTypes = new Dictionary<Type, Type> {
{typeof (CommonSolidBrush), typeof (CommonBrushView)},
{typeof (CommonColor), typeof (CommonBrushView)},
diff --git a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/ResourceTableDelegate.cs b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/ResourceTableDelegate.cs
index b712edf..8861ac6 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/ResourceTableDelegate.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/ResourceTableDelegate.cs
@@ -153,7 +153,7 @@ namespace Xamarin.PropertyEditing.Mac
// set up the editor based on the type of view model
private NSView SetUpRenderer (Type valueRenderType)
{
- var view = (NSView)Activator.CreateInstance (valueRenderType);
+ var view = (NSView)Activator.CreateInstance (valueRenderType, this.hostResources);
return view;
}