Skip to content

Commit

Permalink
Stylecop fixes.
Browse files Browse the repository at this point in the history
Also added solution-wide stylecop settings.
  • Loading branch information
Steven Kirk committed Dec 4, 2014
1 parent 9ae20bd commit a833a5e
Show file tree
Hide file tree
Showing 40 changed files with 386 additions and 162 deletions.
14 changes: 7 additions & 7 deletions Perspex.Application/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public Styles Styles
private set;
}

public void Run(ICloseable closable)
{
var source = new CancellationTokenSource();
closable.Closed += (s, e) => source.Cancel();
Dispatcher.UIThread.MainLoop(source.Token);
}

protected virtual void RegisterServices()
{
Locator.CurrentMutable.Register(() => this, typeof(IGlobalDataTemplates));
Expand All @@ -84,12 +91,5 @@ protected virtual void RegisterServices()
Locator.CurrentMutable.Register(() => this.InputManager, typeof(IInputManager));
Locator.CurrentMutable.Register(() => this.styler, typeof(IStyler));
}

public void Run(ICloseable closable)
{
var source = new CancellationTokenSource();
closable.Closed += (s, e) => source.Cancel();
Dispatcher.UIThread.MainLoop(source.Token);
}
}
}
10 changes: 7 additions & 3 deletions Perspex.Application/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System.Resources;
// -----------------------------------------------------------------------
// <copyright file="AssemblyInfo.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
Expand Down
1 change: 1 addition & 0 deletions Perspex.Base/Settings.StyleCop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<StyleCopSettings Version="105" />
4 changes: 2 additions & 2 deletions Perspex.Controls/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class Border : Decorator
{
static Border()
{
AffectsRender(BackgroundProperty);
AffectsRender(BorderBrushProperty);
Control.AffectsRender(Border.BackgroundProperty);
Control.AffectsRender(Border.BorderBrushProperty);
}

public override void Render(IDrawingContext context)
Expand Down
6 changes: 3 additions & 3 deletions Perspex.Controls/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class Control : InputElement, IStyleable, IStyleHost

static Control()
{
AffectsMeasure(IsVisibleProperty);
PseudoClass(IsPointerOverProperty, ":pointerover");
PseudoClass(IsFocusedProperty, ":focus");
Control.AffectsMeasure(Control.IsVisibleProperty);
PseudoClass(Control.IsPointerOverProperty, ":pointerover");
PseudoClass(Control.IsFocusedProperty, ":focus");
}

public Brush Background
Expand Down
4 changes: 2 additions & 2 deletions Perspex.Controls/Controls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
// </copyright>
// -----------------------------------------------------------------------

using System.Collections.Generic;

namespace Perspex.Controls
{
using System.Collections.Generic;

public class Controls : PerspexList<Control>
{
public Controls()
Expand Down
12 changes: 6 additions & 6 deletions Perspex.Controls/DataTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ public DataTemplate(Func<object, bool> match, Func<object, Control> build)
this.Build = build;
}

public Func<object, bool> Match { get; private set; }

public Func<object, Control> Build { get; private set; }

public static bool IsInstance(object o, Type t)
{
return t.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo());
}

public Func<object, bool> Match { get; private set; }

public Func<object, Control> Build { get; private set; }
}

public class DataTemplate<T> : DataTemplate
{
public DataTemplate(Func<T, Control> build)
: base(typeof(T), Cast(build))
: base(typeof(T), DataTemplate<T>.Cast(build))
{
}

public DataTemplate(Func<T, bool> match, Func<T, Control> build)
: base(CastMatch(match), Cast(build))
: base(CastMatch(match), DataTemplate<T>.Cast(build))
{
}

Expand Down
8 changes: 4 additions & 4 deletions Perspex.Controls/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,10 @@ private void AssignSize(
// we need to count the number of stars instead.
for (int i = start; i <= end; i++)
{
double segmentSize = desiredSize ? (matrix[i, i].DesiredSize) : matrix[i, i].OfferedSize;
double segmentSize = desiredSize ? (matrix[i, i].DesiredSize) : matrix[i, i].OfferedSize;
if (segmentSize < matrix[i, i].Max)
{
count += type == GridUnitType.Star ? (matrix[i, i].Stars) : 1;
count += type == GridUnitType.Star ? (matrix[i, i].Stars) : 1;
}
}

Expand All @@ -620,15 +620,15 @@ private void AssignSize(

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

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

double newsize = segmentSize;
newsize += contribution * (type == GridUnitType.Star ? (matrix[i, i].Stars) : 1);
newsize += contribution * (type == GridUnitType.Star ? (matrix[i, i].Stars) : 1);
newsize = Math.Min(newsize, matrix[i, i].Max);
assigned |= newsize > segmentSize;
size -= newsize - segmentSize;
Expand Down
6 changes: 3 additions & 3 deletions Perspex.Controls/GridSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ protected override void OnDragDelta(VectorEventArgs e)
{
int col = this.GetValue(Grid.ColumnProperty);

if (grid != null && col > 0)
if (this.grid != null && col > 0)
{
grid.ColumnDefinitions[col - 1].Width = new GridLength(
grid.ColumnDefinitions[col - 1].ActualWidth + e.Vector.X,
this.grid.ColumnDefinitions[col - 1].Width = new GridLength(
this.grid.ColumnDefinitions[col - 1].ActualWidth + e.Vector.X,
GridUnitType.Pixel);
}
}
Expand Down
48 changes: 24 additions & 24 deletions Perspex.Controls/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,6 @@ public override void Render(IDrawingContext drawingContext)
}
}

private static Vector CalculateScaling(Size availableSize, Size imageSize, Stretch stretch)
{
double scaleX = 1;
double scaleY = 1;

if (stretch != Stretch.None)
{
scaleX = availableSize.Width / imageSize.Width;
scaleY = availableSize.Height / imageSize.Height;

switch (stretch)
{
case Stretch.Uniform:
scaleX = scaleY = Math.Min(scaleX, scaleY);
break;
case Stretch.UniformToFill:
scaleX = scaleY = Math.Max(scaleX, scaleY);
break;
}
}

return new Vector(scaleX, scaleY);
}

protected override Size MeasureOverride(Size availableSize)
{
double width = 0;
Expand Down Expand Up @@ -111,5 +87,29 @@ protected override Size ArrangeOverride(Size finalSize)
{
return finalSize;
}

private static Vector CalculateScaling(Size availableSize, Size imageSize, Stretch stretch)
{
double scaleX = 1;
double scaleY = 1;

if (stretch != Stretch.None)
{
scaleX = availableSize.Width / imageSize.Width;
scaleY = availableSize.Height / imageSize.Height;

switch (stretch)
{
case Stretch.Uniform:
scaleX = scaleY = Math.Min(scaleX, scaleY);
break;
case Stretch.UniformToFill:
scaleX = scaleY = Math.Max(scaleX, scaleY);
break;
}
}

return new Vector(scaleX, scaleY);
}
}
}
20 changes: 10 additions & 10 deletions Perspex.Controls/ItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ namespace Perspex.Controls

public class ItemsControl : TemplatedControl
{
private static readonly ItemsPanelTemplate DefaultPanel =
new ItemsPanelTemplate(() => new StackPanel { Orientation = Orientation.Vertical });

public static readonly PerspexProperty<IEnumerable> ItemsProperty =
PerspexProperty.Register<ItemsControl, IEnumerable>("Items");

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

private static readonly ItemsPanelTemplate DefaultPanel =
new ItemsPanelTemplate(() => new StackPanel { Orientation = Orientation.Vertical });

private ItemContainerGenerator itemContainerGenerator;

public ItemsControl()
Expand All @@ -44,11 +44,6 @@ public ItemContainerGenerator ItemContainerGenerator
}
}

protected virtual ItemContainerGenerator CreateItemContainerGenerator()
{
return new ItemContainerGenerator(this);
}

public IEnumerable Items
{
get { return this.GetValue(ItemsProperty); }
Expand All @@ -61,13 +56,18 @@ public ItemsPanelTemplate ItemsPanel
set { this.SetValue(ItemsPanelProperty, value); }
}

protected virtual ItemContainerGenerator CreateItemContainerGenerator()
{
return new ItemContainerGenerator(this);
}

private void ItemsChanged(Tuple<IEnumerable, IEnumerable> value)
{
INotifyPropertyChanged inpc = value.Item1 as INotifyPropertyChanged;

if (inpc != null)
{
inpc.PropertyChanged -= ItemsPropertyChanged;
inpc.PropertyChanged -= this.ItemsPropertyChanged;
}

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

if (inpc != null)
{
inpc.PropertyChanged += ItemsPropertyChanged;
inpc.PropertyChanged += this.ItemsPropertyChanged;
}
}

Expand Down
12 changes: 7 additions & 5 deletions Perspex.Controls/ItemsPanelTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// -----------------------------------------------------------------------
// <copyright file="ItemsPanelTemplate.cs" company="Steven Kirk">
// Copyright 2013 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------

namespace Perspex.Controls
{
using System;

public class ItemsPanelTemplate
{
public ItemsPanelTemplate(Func<Panel> build)
Expand Down
2 changes: 1 addition & 1 deletion Perspex.Controls/ListBoxItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ListBoxItem : ContentControl, ISelectable

static ListBoxItem()
{
PseudoClass(IsSelectedProperty, ":selected");
Control.PseudoClass(IsSelectedProperty, ":selected");
}

public bool IsSelected
Expand Down
6 changes: 3 additions & 3 deletions Perspex.Controls/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Controls Children
if (this.children == null)
{
this.children = new Controls();
this.children.CollectionChanged += ChildrenChanged;
this.children.CollectionChanged += this.ChildrenChanged;
}

return this.children;
Expand All @@ -38,15 +38,15 @@ public Controls Children
{
if (this.children != null)
{
this.children.CollectionChanged -= ChildrenChanged;
this.children.CollectionChanged -= this.ChildrenChanged;
}

this.children = value;
this.ClearVisualChildren();

if (this.children != null)
{
this.children.CollectionChanged += ChildrenChanged;
this.children.CollectionChanged += this.ChildrenChanged;
this.AddVisualChildren(value);
this.InvalidateMeasure();
}
Expand Down
6 changes: 3 additions & 3 deletions Perspex.Controls/Presenters/ItemsPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="ItemsControl.cs" company="Steven Kirk">
// <copyright file="ItemsPresenter.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
Expand Down Expand Up @@ -51,8 +51,8 @@ protected override sealed void ApplyTemplate()

protected override Size MeasureOverride(Size availableSize)
{
panel.Measure(availableSize);
return panel.DesiredSize.Value;
this.panel.Measure(availableSize);
return this.panel.DesiredSize.Value;
}

protected override Size ArrangeOverride(Size finalSize)
Expand Down
10 changes: 5 additions & 5 deletions Perspex.Controls/Presenters/ScrollContentPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ namespace Perspex.Controls.Presenters
using System.Linq;
using Perspex.Layout;

public class ScrollContentPresenter : ContentPresenter
public class ScrollContentPresenter : ContentPresenter
{
public static PerspexProperty<Size> ExtentProperty =
public static readonly PerspexProperty<Size> ExtentProperty =
ScrollViewer.ExtentProperty.AddOwner<ScrollContentPresenter>();

public static PerspexProperty<Vector> OffsetProperty =
public static readonly PerspexProperty<Vector> OffsetProperty =
ScrollViewer.OffsetProperty.AddOwner<ScrollContentPresenter>();

public static PerspexProperty<Size> ViewportProperty =
public static readonly PerspexProperty<Size> ViewportProperty =
ScrollViewer.ViewportProperty.AddOwner<ScrollContentPresenter>();

public ScrollContentPresenter()
{
AffectsRender(OffsetProperty);
Control.AffectsRender(OffsetProperty);
}

public Size Extent
Expand Down
2 changes: 1 addition & 1 deletion Perspex.Controls/Primitives/HeaderedContentControl.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="ContentControl.cs" company="Steven Kirk">
// <copyright file="HeaderedContentControl.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions Perspex.Controls/Primitives/ScrollBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class ScrollBar : TemplatedControl

static ScrollBar()
{
PseudoClass(OrientationProperty, x => x == Orientation.Horizontal, ":horizontal");
PseudoClass(OrientationProperty, x => x == Orientation.Vertical, ":vertical");
Control.PseudoClass(OrientationProperty, x => x == Orientation.Horizontal, ":horizontal");
Control.PseudoClass(OrientationProperty, x => x == Orientation.Vertical, ":vertical");
}

public double Minimum
Expand Down
Loading

0 comments on commit a833a5e

Please sign in to comment.