Skip to content

Commit a833a5e

Browse files
author
Steven Kirk
committed
Stylecop fixes.
Also added solution-wide stylecop settings.
1 parent 9ae20bd commit a833a5e

40 files changed

+386
-162
lines changed

Perspex.Application/Application.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ public Styles Styles
7676
private set;
7777
}
7878

79+
public void Run(ICloseable closable)
80+
{
81+
var source = new CancellationTokenSource();
82+
closable.Closed += (s, e) => source.Cancel();
83+
Dispatcher.UIThread.MainLoop(source.Token);
84+
}
85+
7986
protected virtual void RegisterServices()
8087
{
8188
Locator.CurrentMutable.Register(() => this, typeof(IGlobalDataTemplates));
@@ -84,12 +91,5 @@ protected virtual void RegisterServices()
8491
Locator.CurrentMutable.Register(() => this.InputManager, typeof(IInputManager));
8592
Locator.CurrentMutable.Register(() => this.styler, typeof(IStyler));
8693
}
87-
88-
public void Run(ICloseable closable)
89-
{
90-
var source = new CancellationTokenSource();
91-
closable.Closed += (s, e) => source.Cancel();
92-
Dispatcher.UIThread.MainLoop(source.Token);
93-
}
9494
}
9595
}

Perspex.Application/Properties/AssemblyInfo.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
using System.Resources;
1+
// -----------------------------------------------------------------------
2+
// <copyright file="AssemblyInfo.cs" company="Steven Kirk">
3+
// Copyright 2014 MIT Licence. See licence.md for more information.
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
27
using System.Reflection;
3-
using System.Runtime.CompilerServices;
4-
using System.Runtime.InteropServices;
8+
using System.Resources;
59

610
// General Information about an assembly is controlled through the following
711
// set of attributes. Change these attribute values to modify the information

Perspex.Base/Settings.StyleCop

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<StyleCopSettings Version="105" />

Perspex.Controls/Border.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class Border : Decorator
1515
{
1616
static Border()
1717
{
18-
AffectsRender(BackgroundProperty);
19-
AffectsRender(BorderBrushProperty);
18+
Control.AffectsRender(Border.BackgroundProperty);
19+
Control.AffectsRender(Border.BorderBrushProperty);
2020
}
2121

2222
public override void Render(IDrawingContext context)

Perspex.Controls/Control.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public class Control : InputElement, IStyleable, IStyleHost
4343

4444
static Control()
4545
{
46-
AffectsMeasure(IsVisibleProperty);
47-
PseudoClass(IsPointerOverProperty, ":pointerover");
48-
PseudoClass(IsFocusedProperty, ":focus");
46+
Control.AffectsMeasure(Control.IsVisibleProperty);
47+
PseudoClass(Control.IsPointerOverProperty, ":pointerover");
48+
PseudoClass(Control.IsFocusedProperty, ":focus");
4949
}
5050

5151
public Brush Background

Perspex.Controls/Controls.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// </copyright>
55
// -----------------------------------------------------------------------
66

7-
using System.Collections.Generic;
8-
97
namespace Perspex.Controls
108
{
9+
using System.Collections.Generic;
10+
1111
public class Controls : PerspexList<Control>
1212
{
1313
public Controls()

Perspex.Controls/DataTemplate.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,25 @@ public DataTemplate(Func<object, bool> match, Func<object, Control> build)
3333
this.Build = build;
3434
}
3535

36+
public Func<object, bool> Match { get; private set; }
37+
38+
public Func<object, Control> Build { get; private set; }
39+
3640
public static bool IsInstance(object o, Type t)
3741
{
3842
return t.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo());
3943
}
40-
41-
public Func<object, bool> Match { get; private set; }
42-
43-
public Func<object, Control> Build { get; private set; }
4444
}
4545

4646
public class DataTemplate<T> : DataTemplate
4747
{
4848
public DataTemplate(Func<T, Control> build)
49-
: base(typeof(T), Cast(build))
49+
: base(typeof(T), DataTemplate<T>.Cast(build))
5050
{
5151
}
5252

5353
public DataTemplate(Func<T, bool> match, Func<T, Control> build)
54-
: base(CastMatch(match), Cast(build))
54+
: base(CastMatch(match), DataTemplate<T>.Cast(build))
5555
{
5656
}
5757

Perspex.Controls/Grid.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,10 @@ private void AssignSize(
605605
// we need to count the number of stars instead.
606606
for (int i = start; i <= end; i++)
607607
{
608-
double segmentSize = desiredSize ? (matrix[i, i].DesiredSize) : matrix[i, i].OfferedSize;
608+
double segmentSize = desiredSize ? (matrix[i, i].DesiredSize) : matrix[i, i].OfferedSize;
609609
if (segmentSize < matrix[i, i].Max)
610610
{
611-
count += type == GridUnitType.Star ? (matrix[i, i].Stars) : 1;
611+
count += type == GridUnitType.Star ? (matrix[i, i].Stars) : 1;
612612
}
613613
}
614614

@@ -620,15 +620,15 @@ private void AssignSize(
620620

621621
for (int i = start; i <= end; i++)
622622
{
623-
double segmentSize = desiredSize ? (matrix[i, i].DesiredSize) : matrix[i, i].OfferedSize;
623+
double segmentSize = desiredSize ? (matrix[i, i].DesiredSize) : matrix[i, i].OfferedSize;
624624

625625
if (!(matrix[i, i].Type == type && segmentSize < matrix[i, i].Max))
626626
{
627627
continue;
628628
}
629629

630630
double newsize = segmentSize;
631-
newsize += contribution * (type == GridUnitType.Star ? (matrix[i, i].Stars) : 1);
631+
newsize += contribution * (type == GridUnitType.Star ? (matrix[i, i].Stars) : 1);
632632
newsize = Math.Min(newsize, matrix[i, i].Max);
633633
assigned |= newsize > segmentSize;
634634
size -= newsize - segmentSize;

Perspex.Controls/GridSplitter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ protected override void OnDragDelta(VectorEventArgs e)
1818
{
1919
int col = this.GetValue(Grid.ColumnProperty);
2020

21-
if (grid != null && col > 0)
21+
if (this.grid != null && col > 0)
2222
{
23-
grid.ColumnDefinitions[col - 1].Width = new GridLength(
24-
grid.ColumnDefinitions[col - 1].ActualWidth + e.Vector.X,
23+
this.grid.ColumnDefinitions[col - 1].Width = new GridLength(
24+
this.grid.ColumnDefinitions[col - 1].ActualWidth + e.Vector.X,
2525
GridUnitType.Pixel);
2626
}
2727
}

Perspex.Controls/Image.cs

+24-24
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,6 @@ public override void Render(IDrawingContext drawingContext)
5656
}
5757
}
5858

59-
private static Vector CalculateScaling(Size availableSize, Size imageSize, Stretch stretch)
60-
{
61-
double scaleX = 1;
62-
double scaleY = 1;
63-
64-
if (stretch != Stretch.None)
65-
{
66-
scaleX = availableSize.Width / imageSize.Width;
67-
scaleY = availableSize.Height / imageSize.Height;
68-
69-
switch (stretch)
70-
{
71-
case Stretch.Uniform:
72-
scaleX = scaleY = Math.Min(scaleX, scaleY);
73-
break;
74-
case Stretch.UniformToFill:
75-
scaleX = scaleY = Math.Max(scaleX, scaleY);
76-
break;
77-
}
78-
}
79-
80-
return new Vector(scaleX, scaleY);
81-
}
82-
8359
protected override Size MeasureOverride(Size availableSize)
8460
{
8561
double width = 0;
@@ -111,5 +87,29 @@ protected override Size ArrangeOverride(Size finalSize)
11187
{
11288
return finalSize;
11389
}
90+
91+
private static Vector CalculateScaling(Size availableSize, Size imageSize, Stretch stretch)
92+
{
93+
double scaleX = 1;
94+
double scaleY = 1;
95+
96+
if (stretch != Stretch.None)
97+
{
98+
scaleX = availableSize.Width / imageSize.Width;
99+
scaleY = availableSize.Height / imageSize.Height;
100+
101+
switch (stretch)
102+
{
103+
case Stretch.Uniform:
104+
scaleX = scaleY = Math.Min(scaleX, scaleY);
105+
break;
106+
case Stretch.UniformToFill:
107+
scaleX = scaleY = Math.Max(scaleX, scaleY);
108+
break;
109+
}
110+
}
111+
112+
return new Vector(scaleX, scaleY);
113+
}
114114
}
115115
}

Perspex.Controls/ItemsControl.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ namespace Perspex.Controls
1515

1616
public class ItemsControl : TemplatedControl
1717
{
18-
private static readonly ItemsPanelTemplate DefaultPanel =
19-
new ItemsPanelTemplate(() => new StackPanel { Orientation = Orientation.Vertical });
20-
2118
public static readonly PerspexProperty<IEnumerable> ItemsProperty =
2219
PerspexProperty.Register<ItemsControl, IEnumerable>("Items");
2320

2421
public static readonly PerspexProperty<ItemsPanelTemplate> ItemsPanelProperty =
2522
PerspexProperty.Register<ItemsControl, ItemsPanelTemplate>("ItemsPanel", defaultValue: DefaultPanel);
2623

24+
private static readonly ItemsPanelTemplate DefaultPanel =
25+
new ItemsPanelTemplate(() => new StackPanel { Orientation = Orientation.Vertical });
26+
2727
private ItemContainerGenerator itemContainerGenerator;
2828

2929
public ItemsControl()
@@ -44,11 +44,6 @@ public ItemContainerGenerator ItemContainerGenerator
4444
}
4545
}
4646

47-
protected virtual ItemContainerGenerator CreateItemContainerGenerator()
48-
{
49-
return new ItemContainerGenerator(this);
50-
}
51-
5247
public IEnumerable Items
5348
{
5449
get { return this.GetValue(ItemsProperty); }
@@ -61,13 +56,18 @@ public ItemsPanelTemplate ItemsPanel
6156
set { this.SetValue(ItemsPanelProperty, value); }
6257
}
6358

59+
protected virtual ItemContainerGenerator CreateItemContainerGenerator()
60+
{
61+
return new ItemContainerGenerator(this);
62+
}
63+
6464
private void ItemsChanged(Tuple<IEnumerable, IEnumerable> value)
6565
{
6666
INotifyPropertyChanged inpc = value.Item1 as INotifyPropertyChanged;
6767

6868
if (inpc != null)
6969
{
70-
inpc.PropertyChanged -= ItemsPropertyChanged;
70+
inpc.PropertyChanged -= this.ItemsPropertyChanged;
7171
}
7272

7373
if (value.Item2 == null || !value.Item2.OfType<object>().Any())
@@ -83,7 +83,7 @@ private void ItemsChanged(Tuple<IEnumerable, IEnumerable> value)
8383

8484
if (inpc != null)
8585
{
86-
inpc.PropertyChanged += ItemsPropertyChanged;
86+
inpc.PropertyChanged += this.ItemsPropertyChanged;
8787
}
8888
}
8989

Perspex.Controls/ItemsPanelTemplate.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
// -----------------------------------------------------------------------
2+
// <copyright file="ItemsPanelTemplate.cs" company="Steven Kirk">
3+
// Copyright 2013 MIT Licence. See licence.md for more information.
4+
// </copyright>
5+
// -----------------------------------------------------------------------
66

77
namespace Perspex.Controls
88
{
9+
using System;
10+
911
public class ItemsPanelTemplate
1012
{
1113
public ItemsPanelTemplate(Func<Panel> build)

Perspex.Controls/ListBoxItem.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ListBoxItem : ContentControl, ISelectable
1313

1414
static ListBoxItem()
1515
{
16-
PseudoClass(IsSelectedProperty, ":selected");
16+
Control.PseudoClass(IsSelectedProperty, ":selected");
1717
}
1818

1919
public bool IsSelected

Perspex.Controls/Panel.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Controls Children
2424
if (this.children == null)
2525
{
2626
this.children = new Controls();
27-
this.children.CollectionChanged += ChildrenChanged;
27+
this.children.CollectionChanged += this.ChildrenChanged;
2828
}
2929

3030
return this.children;
@@ -38,15 +38,15 @@ public Controls Children
3838
{
3939
if (this.children != null)
4040
{
41-
this.children.CollectionChanged -= ChildrenChanged;
41+
this.children.CollectionChanged -= this.ChildrenChanged;
4242
}
4343

4444
this.children = value;
4545
this.ClearVisualChildren();
4646

4747
if (this.children != null)
4848
{
49-
this.children.CollectionChanged += ChildrenChanged;
49+
this.children.CollectionChanged += this.ChildrenChanged;
5050
this.AddVisualChildren(value);
5151
this.InvalidateMeasure();
5252
}

Perspex.Controls/Presenters/ItemsPresenter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// -----------------------------------------------------------------------
2-
// <copyright file="ItemsControl.cs" company="Steven Kirk">
2+
// <copyright file="ItemsPresenter.cs" company="Steven Kirk">
33
// Copyright 2014 MIT Licence. See licence.md for more information.
44
// </copyright>
55
// -----------------------------------------------------------------------
@@ -51,8 +51,8 @@ protected override sealed void ApplyTemplate()
5151

5252
protected override Size MeasureOverride(Size availableSize)
5353
{
54-
panel.Measure(availableSize);
55-
return panel.DesiredSize.Value;
54+
this.panel.Measure(availableSize);
55+
return this.panel.DesiredSize.Value;
5656
}
5757

5858
protected override Size ArrangeOverride(Size finalSize)

Perspex.Controls/Presenters/ScrollContentPresenter.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ namespace Perspex.Controls.Presenters
99
using System.Linq;
1010
using Perspex.Layout;
1111

12-
public class ScrollContentPresenter : ContentPresenter
12+
public class ScrollContentPresenter : ContentPresenter
1313
{
14-
public static PerspexProperty<Size> ExtentProperty =
14+
public static readonly PerspexProperty<Size> ExtentProperty =
1515
ScrollViewer.ExtentProperty.AddOwner<ScrollContentPresenter>();
1616

17-
public static PerspexProperty<Vector> OffsetProperty =
17+
public static readonly PerspexProperty<Vector> OffsetProperty =
1818
ScrollViewer.OffsetProperty.AddOwner<ScrollContentPresenter>();
1919

20-
public static PerspexProperty<Size> ViewportProperty =
20+
public static readonly PerspexProperty<Size> ViewportProperty =
2121
ScrollViewer.ViewportProperty.AddOwner<ScrollContentPresenter>();
2222

2323
public ScrollContentPresenter()
2424
{
25-
AffectsRender(OffsetProperty);
25+
Control.AffectsRender(OffsetProperty);
2626
}
2727

2828
public Size Extent

Perspex.Controls/Primitives/HeaderedContentControl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// -----------------------------------------------------------------------
2-
// <copyright file="ContentControl.cs" company="Steven Kirk">
2+
// <copyright file="HeaderedContentControl.cs" company="Steven Kirk">
33
// Copyright 2014 MIT Licence. See licence.md for more information.
44
// </copyright>
55
// -----------------------------------------------------------------------

Perspex.Controls/Primitives/ScrollBar.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public class ScrollBar : TemplatedControl
2828

2929
static ScrollBar()
3030
{
31-
PseudoClass(OrientationProperty, x => x == Orientation.Horizontal, ":horizontal");
32-
PseudoClass(OrientationProperty, x => x == Orientation.Vertical, ":vertical");
31+
Control.PseudoClass(OrientationProperty, x => x == Orientation.Horizontal, ":horizontal");
32+
Control.PseudoClass(OrientationProperty, x => x == Orientation.Vertical, ":vertical");
3333
}
3434

3535
public double Minimum

0 commit comments

Comments
 (0)