From 27df0f6c3748558173ff61e47bbb2898f72c2915 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 22 Sep 2015 22:34:36 +0200 Subject: [PATCH 01/24] Give TextBox a background. --- src/Perspex.Themes.Default/TextBoxStyle.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Perspex.Themes.Default/TextBoxStyle.cs b/src/Perspex.Themes.Default/TextBoxStyle.cs index bde64d2110..3b3bfca452 100644 --- a/src/Perspex.Themes.Default/TextBoxStyle.cs +++ b/src/Perspex.Themes.Default/TextBoxStyle.cs @@ -28,6 +28,7 @@ namespace Perspex.Themes.Default Setters = new[] { new Setter(TemplatedControl.TemplateProperty, new ControlTemplate(Template)), + new Setter(TemplatedControl.BackgroundProperty, Brushes.White), new Setter(TemplatedControl.BorderBrushProperty, new SolidColorBrush(0xff707070)), new Setter(TemplatedControl.BorderThicknessProperty, 2.0), new Setter(Control.FocusAdornerProperty, null), From 6cf8712088d6d9aa1b347945fb8073d46e45a380 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Wed, 23 Sep 2015 13:48:49 +0300 Subject: [PATCH 02/24] Updated readme with nightly build installation instructions --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 6e9216e558..4a5d3556c7 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ A multi-platform .NET UI framework. ## NuGet Perspex is delivered as a NuGet package. -You can find the packages here: ([stable(ish)](https://www.nuget.org/packages/Perspex/), [nightly](https://www.myget.org/F/perspex-nightly/api/v2/Packages)) +You can find the packages here: ([stable(ish)](https://www.nuget.org/packages/Perspex/), [nightly](https://github.com/Perspex/Perspex/wiki/Using-nightly-build-feed)) You can install the package like this: `Install-Package Perspex -Pre` From 24f9b2de9c348c0285c5494cf5a54bc55351d0bd Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 23 Sep 2015 18:13:53 +0200 Subject: [PATCH 03/24] Updated OmniXAML --- src/Markup/Perspex.Markup.Xaml/OmniXAML | 2 +- src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Markup/Perspex.Markup.Xaml/OmniXAML b/src/Markup/Perspex.Markup.Xaml/OmniXAML index 586e2e521c..7b13ebcde0 160000 --- a/src/Markup/Perspex.Markup.Xaml/OmniXAML +++ b/src/Markup/Perspex.Markup.Xaml/OmniXAML @@ -1 +1 @@ -Subproject commit 586e2e521c85a4b111c394e8aee178bbdfc9c1df +Subproject commit 7b13ebcde030df9f8d538917e57b3a34ea9edf32 diff --git a/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj b/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj index 4fe8fda36a..6da087ac13 100644 --- a/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj +++ b/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj @@ -194,6 +194,7 @@ + @@ -207,6 +208,7 @@ + From 1b745ab62cacbab4e56f9a1b2a94c29c76424916 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 23 Sep 2015 19:20:31 +0200 Subject: [PATCH 04/24] Removed NGenerics. Closes #7. --- Perspex.sln | 9 - .../XamlTestApplication.csproj | 4 - src/NGenerics/Constants.cs | 19 - .../Comparers/ComparisonComparer.cs | 80 --- .../Comparers/KeyValuePairComparer.cs | 93 --- .../Comparers/ReverseComparer.cs | 84 --- src/NGenerics/DataStructures/General/Heap.cs | 405 ----------- .../DataStructures/General/HeapType.cs | 32 - src/NGenerics/DataStructures/General/IHeap.cs | 44 -- src/NGenerics/DataStructures/Queues/IQueue.cs | 46 -- .../DataStructures/Queues/PriorityQueue.cs | 556 --------------- .../Queues/PriorityQueueType.cs | 30 - .../Trees/BinarySearchTreeBase.cs | 529 -------------- .../DataStructures/Trees/BinaryTree.cs | 674 ------------------ .../DataStructures/Trees/ISearchTree.cs | 68 -- src/NGenerics/DataStructures/Trees/ITree.cs | 82 --- .../DataStructures/Trees/NodeColor.cs | 21 - .../DataStructures/Trees/RedBlackTree.cs | 291 -------- .../Trees/RedBlackTreeDictionary.cs | 251 ------- .../DataStructures/Trees/RedBlackTreeList.cs | 232 ------ .../DataStructures/Trees/RedBlackTreeNode.cs | 107 --- src/NGenerics/NGenerics.csproj | 76 -- src/NGenerics/Patterns/Visitor/IVisitor.cs | 34 - .../Patterns/Visitor/InOrderVisitor.cs | 51 -- .../Patterns/Visitor/KeyTrackingVisitor.cs | 65 -- .../Patterns/Visitor/OrderedVisitor.cs | 102 --- .../Patterns/Visitor/TrackingVisitor.cs | 65 -- .../Patterns/Visitor/ValueTrackingVisitor.cs | 66 -- src/NGenerics/Properties/AssemblyInfo.cs | 33 - src/NGenerics/Util/Guard.cs | 59 -- src/Perspex.Base/Perspex.Base.csproj | 6 - src/Perspex.Base/Threading/MainLoop.cs | 8 +- src/Perspex.Layout/LayoutManager.cs | 16 +- src/Perspex.Layout/Perspex.Layout.csproj | 4 - .../Perspex.Interactivity.UnitTests.csproj | 4 - .../Perspex.Layout.UnitTests.csproj | 4 - .../Perspex.Markup.Xaml.UnitTests.csproj | 4 - 37 files changed, 13 insertions(+), 4241 deletions(-) delete mode 100644 src/NGenerics/Constants.cs delete mode 100644 src/NGenerics/DataStructures/Comparers/ComparisonComparer.cs delete mode 100644 src/NGenerics/DataStructures/Comparers/KeyValuePairComparer.cs delete mode 100644 src/NGenerics/DataStructures/Comparers/ReverseComparer.cs delete mode 100644 src/NGenerics/DataStructures/General/Heap.cs delete mode 100644 src/NGenerics/DataStructures/General/HeapType.cs delete mode 100644 src/NGenerics/DataStructures/General/IHeap.cs delete mode 100644 src/NGenerics/DataStructures/Queues/IQueue.cs delete mode 100644 src/NGenerics/DataStructures/Queues/PriorityQueue.cs delete mode 100644 src/NGenerics/DataStructures/Queues/PriorityQueueType.cs delete mode 100644 src/NGenerics/DataStructures/Trees/BinarySearchTreeBase.cs delete mode 100644 src/NGenerics/DataStructures/Trees/BinaryTree.cs delete mode 100644 src/NGenerics/DataStructures/Trees/ISearchTree.cs delete mode 100644 src/NGenerics/DataStructures/Trees/ITree.cs delete mode 100644 src/NGenerics/DataStructures/Trees/NodeColor.cs delete mode 100644 src/NGenerics/DataStructures/Trees/RedBlackTree.cs delete mode 100644 src/NGenerics/DataStructures/Trees/RedBlackTreeDictionary.cs delete mode 100644 src/NGenerics/DataStructures/Trees/RedBlackTreeList.cs delete mode 100644 src/NGenerics/DataStructures/Trees/RedBlackTreeNode.cs delete mode 100644 src/NGenerics/NGenerics.csproj delete mode 100644 src/NGenerics/Patterns/Visitor/IVisitor.cs delete mode 100644 src/NGenerics/Patterns/Visitor/InOrderVisitor.cs delete mode 100644 src/NGenerics/Patterns/Visitor/KeyTrackingVisitor.cs delete mode 100644 src/NGenerics/Patterns/Visitor/OrderedVisitor.cs delete mode 100644 src/NGenerics/Patterns/Visitor/TrackingVisitor.cs delete mode 100644 src/NGenerics/Patterns/Visitor/ValueTrackingVisitor.cs delete mode 100644 src/NGenerics/Properties/AssemblyInfo.cs delete mode 100644 src/NGenerics/Util/Guard.cs diff --git a/Perspex.sln b/Perspex.sln index 59287f9d89..22b196d2c8 100644 --- a/Perspex.sln +++ b/Perspex.sln @@ -31,10 +31,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Application", "src\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Diagnostics", "src\Perspex.Diagnostics\Perspex.Diagnostics.csproj", "{7062AE20-5DCC-4442-9645-8195BDECE63E}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utils", "Utils", "{2BAFBE53-7FA4-4BB9-976F-9AFCC4F9847D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NGenerics", "src\NGenerics\NGenerics.csproj", "{415E048E-4611-4815-9CF2-D774E29079AC}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Animation", "src\Perspex.Animation\Perspex.Animation.csproj", "{D211E587-D8BC-45B9-95A4-F297C8FA5200}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}" @@ -163,10 +159,6 @@ Global {7062AE20-5DCC-4442-9645-8195BDECE63E}.Debug|Any CPU.Build.0 = Debug|Any CPU {7062AE20-5DCC-4442-9645-8195BDECE63E}.Release|Any CPU.ActiveCfg = Release|Any CPU {7062AE20-5DCC-4442-9645-8195BDECE63E}.Release|Any CPU.Build.0 = Release|Any CPU - {415E048E-4611-4815-9CF2-D774E29079AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {415E048E-4611-4815-9CF2-D774E29079AC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {415E048E-4611-4815-9CF2-D774E29079AC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {415E048E-4611-4815-9CF2-D774E29079AC}.Release|Any CPU.Build.0 = Release|Any CPU {D211E587-D8BC-45B9-95A4-F297C8FA5200}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D211E587-D8BC-45B9-95A4-F297C8FA5200}.Debug|Any CPU.Build.0 = Debug|Any CPU {D211E587-D8BC-45B9-95A4-F297C8FA5200}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -251,7 +243,6 @@ Global {811A76CF-1CF6-440F-963B-BBE31BD72A82} = {B39A8919-9F95-48FE-AD7B-76E08B509888} {3E908F67-5543-4879-A1DC-08EACE79B3CD} = {B39A8919-9F95-48FE-AD7B-76E08B509888} {EC42600F-049B-43FF-AED1-8314D61B2749} = {B39A8919-9F95-48FE-AD7B-76E08B509888} - {415E048E-4611-4815-9CF2-D774E29079AC} = {2BAFBE53-7FA4-4BB9-976F-9AFCC4F9847D} {47ECDF59-DEF8-4C53-87B1-2098A3429059} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} {5CCB5571-7C30-4E7D-967D-0E2158EBD91F} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} {76716382-3159-460E-BDA6-C5715CF606D7} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B} diff --git a/samples/XamlTestApplication/XamlTestApplication.csproj b/samples/XamlTestApplication/XamlTestApplication.csproj index 52030934a1..5e99700b38 100644 --- a/samples/XamlTestApplication/XamlTestApplication.csproj +++ b/samples/XamlTestApplication/XamlTestApplication.csproj @@ -85,10 +85,6 @@ - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation diff --git a/src/NGenerics/Constants.cs b/src/NGenerics/Constants.cs deleted file mode 100644 index 0d7597bab4..0000000000 --- a/src/NGenerics/Constants.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - -namespace NGenerics -{ - internal static class Constants - { - public const string NotEnoughSpaceInTheTargetArray = "Not enough space in the target array."; - } -} \ No newline at end of file diff --git a/src/NGenerics/DataStructures/Comparers/ComparisonComparer.cs b/src/NGenerics/DataStructures/Comparers/ComparisonComparer.cs deleted file mode 100644 index aee2fd48d1..0000000000 --- a/src/NGenerics/DataStructures/Comparers/ComparisonComparer.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; -using System.Collections.Generic; -using NGenerics.Util; - -namespace NGenerics.Comparers -{ - /// - /// A Comparer using a Comparison delegate for comparisons between items. - /// - /// The type of the objects to compare. - //[Serializable] - public sealed class ComparisonComparer : IComparer - { - #region Globals - - private Comparison _comparison; - - #endregion - - #region Construction - - - /// The comparison. - /// is a null reference (Nothing in Visual Basic). - public ComparisonComparer(Comparison comparison) - { - Guard.ArgumentNotNull(comparison, "comparison"); - - _comparison = comparison; - } - - #endregion - - #region Public Members - - /// - /// Gets or sets the comparison used in this comparer. - /// - /// The comparison used in this comparer. - /// is a null reference (Nothing in Visual Basic). - public Comparison Comparison - { - get - { - return _comparison; - } - set - { - Guard.ArgumentNotNull(value, "value"); - - _comparison = value; - } - } - - #endregion - - #region IComparer Members - - /// - public int Compare(T x, T y) - { - return _comparison(x, y); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/DataStructures/Comparers/KeyValuePairComparer.cs b/src/NGenerics/DataStructures/Comparers/KeyValuePairComparer.cs deleted file mode 100644 index 8b7a258f39..0000000000 --- a/src/NGenerics/DataStructures/Comparers/KeyValuePairComparer.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; -using System.Collections.Generic; - -namespace NGenerics.Comparers -{ - /// - /// A comparer for comparing keys for the KeyValuePair class. - /// - /// The key type. - /// The value type. - //[Serializable] - public class KeyValuePairComparer : IComparer> - { - #region Globals - - private readonly IComparer _comparer; - - #endregion - - #region Construction - - /// - /// Initializes a new instance of the class. - /// - public KeyValuePairComparer() - { - _comparer = Comparer.Default; - } - - /// - /// Initializes a new instance of the class. - /// - /// The comparer. - public KeyValuePairComparer(IComparer comparer) - { - if (comparer == null) - { - throw new ArgumentNullException("comparer"); - } - - _comparer = comparer; - } - - /// - /// Initializes a new instance of the class. - /// - /// The comparison. - public KeyValuePairComparer(Comparison comparison) - { - if (comparison == null) - { - throw new ArgumentNullException("comparison"); - } - - _comparer = new ComparisonComparer(comparison); - } - - #endregion - - #region IComparer> Members - - /// - public int Compare(KeyValuePair x, KeyValuePair y) - { - return _comparer.Compare(x.Key, y.Key); - } - - #endregion - - #region IComparer Members - - /// - public int Compare(TKey x, TKey y) - { - return _comparer.Compare(x, y); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/DataStructures/Comparers/ReverseComparer.cs b/src/NGenerics/DataStructures/Comparers/ReverseComparer.cs deleted file mode 100644 index fbfa55cc25..0000000000 --- a/src/NGenerics/DataStructures/Comparers/ReverseComparer.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; -using System.Collections.Generic; -using NGenerics.Util; - -namespace NGenerics.Comparers -{ - /// - /// A comparer that wraps the IComparable interface to reproduce the opposite comparison result. - /// - /// The type of the objects to compare. - //[Serializable] - public sealed class ReverseComparer : IComparer - { - #region Globals - - private IComparer _comparerToUse; - - #endregion - - #region Construction - /// - public ReverseComparer() - { - _comparerToUse = Comparer.Default; - } - - - /// The comparer to reverse. - /// is a null reference (Nothing in Visual Basic). - public ReverseComparer(IComparer comparer) - { - Guard.ArgumentNotNull(comparer, "comparer"); - _comparerToUse = comparer; - } - - #endregion - - #region IComparer Members - - /// - public int Compare(T x, T y) - { - return (_comparerToUse.Compare(y, x)); - } - - #endregion - - #region Public Members - - /// - /// Gets or sets the comparer used in this instance. - /// - /// The comparer. - /// is a null reference (Nothing in Visual Basic). - public IComparer Comparer - { - get - { - return _comparerToUse; - } - set - { - Guard.ArgumentNotNull(value, "value"); - - _comparerToUse = value; - } - } - - #endregion - } -} diff --git a/src/NGenerics/DataStructures/General/Heap.cs b/src/NGenerics/DataStructures/General/Heap.cs deleted file mode 100644 index 155ad10059..0000000000 --- a/src/NGenerics/DataStructures/General/Heap.cs +++ /dev/null @@ -1,405 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; -using System.Collections; -using System.Collections.Generic; -using NGenerics.Comparers; -using System.Diagnostics.CodeAnalysis; -using NGenerics.Util; - -namespace NGenerics.DataStructures.General -{ - /// - /// An implementation of a Heap data structure. - /// - /// The type of item stored in the . - //[Serializable] - [SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] - [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] - public class Heap : ICollection, IHeap - { - #region Globals - - private const string heapIsEmpty = "The heap is empty."; - private readonly List _data; - private readonly IComparer _comparerToUse; - private readonly HeapType _thisType; - - #endregion - - #region Construction - - /// - /// Initializes a new instance of the class. - /// - /// The type of Heap to create. - /// is not either or . - /// - /// - /// - /// - public Heap(HeapType type) : this(type, Comparer.Default) { } - - - /// - /// Initializes a new instance of the class. - /// - /// The type of heap. - /// The capacity. - /// is not either or . - /// is less than 0. - /// . - /// - /// - /// - /// - public Heap(HeapType type, int capacity) : this(type, capacity, Comparer.Default) { } - - - /// - /// Initializes a new instance of the class. - /// - /// The type of heap. - /// The comparer. - /// is not either or . - public Heap(HeapType type, Comparison comparer) : this(type, new ComparisonComparer(comparer)) { } - - /// - /// Initializes a new instance of the class. - /// - /// The type of heap. - /// The capacity of the heap to start with. - /// The comparer. - /// is not either or . - /// is less than 0. - public Heap(HeapType type, int capacity, Comparison comparer) : this(type, capacity, new ComparisonComparer(comparer)) { } - - /// - /// Initializes a new instance of the class. - /// - /// The type of Heap to create. - /// The comparer to use. - /// is a null reference (Nothing in Visual Basic). - /// is not either or . - /// - /// - /// - /// - public Heap(HeapType type, IComparer comparer) - { - Guard.ArgumentNotNull(comparer, "comparer"); - - if ((type != HeapType.Minimum) && (type != HeapType.Maximum)) - { - throw new ArgumentOutOfRangeException("type"); - } - - _thisType = type; - - _data = new List { default(T) }; - - _comparerToUse = type == HeapType.Minimum ? comparer : new ReverseComparer(comparer); - } - - - /// The type of heap. - /// The initial capacity of the Heap. - /// The comparer to use. - /// is less than 0.. - /// is a null reference (Nothing in Visual Basic). - /// is not either or . - public Heap(HeapType type, int capacity, IComparer comparer) - { - Guard.ArgumentNotNull(comparer, "comparer"); - - if ((type != HeapType.Minimum) && (type != HeapType.Maximum)) - { - throw new ArgumentOutOfRangeException("type"); - } - _thisType = type; - - _data = new List(capacity) { default(T) }; - - _comparerToUse = type == HeapType.Minimum ? comparer : new ReverseComparer(comparer); - } - - #endregion - - #region Public Members - - - /// - /// - /// - /// - /// - public T Root - { - get - { - #region Validation - - if (Count == 0) - { - throw new InvalidOperationException(heapIsEmpty); - } - - #endregion - - return _data[1]; - } - } - - - /// - /// - /// - /// - /// - public T RemoveRoot() - { - #region Validation - - if (Count == 0) - { - throw new InvalidOperationException(heapIsEmpty); - } - - #endregion - - // The minimum item to return. - var minimum = _data[1]; - - RemoveRootItem(minimum); - return minimum; - } - - - /// - /// Removes the root item. - /// - /// The item. - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the method. - /// - protected virtual void RemoveRootItem(T item) - { - // The last item in the heap - var last = _data[Count]; - _data.RemoveAt(Count); - - // If there's still items left in this heap, re-heapify it. - if (Count > 0) - { - // Re-heapify the binary tree to conform to the heap property - var counter = 1; - - while ((counter * 2) < (_data.Count)) - { - var child = counter * 2; - - if (((child + 1) < (_data.Count)) && - (_comparerToUse.Compare(_data[child + 1], _data[child]) < 0)) - { - child++; - } - - if (_comparerToUse.Compare(last, _data[child]) <= 0) - { - break; - } - - _data[counter] = _data[child]; - counter = child; - } - - _data[counter] = last; - } - } - - - /// - /// Gets the type of heap represented by this instance. - /// - /// The type of heap. - /// - /// - /// - /// - [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] - public HeapType Type => _thisType; - - #endregion - - #region ICollection Members - - - - /// - /// - /// - /// - /// - public bool IsEmpty => Count == 0; - - - /// - /// - /// - /// - /// - public bool Contains(T item) - { - return _data.Contains(item); - } - - /// - /// - /// - /// - /// - public void CopyTo(T[] array, int arrayIndex) - { - #region Validation - - Guard.ArgumentNotNull(array, "array"); - - if ((array.Length - arrayIndex) < Count) - { - throw new ArgumentException(Constants.NotEnoughSpaceInTheTargetArray, "array"); - } - - #endregion - - for (var i = 1; i < _data.Count; i++) - { - array[arrayIndex++] = _data[i]; - } - } - - /// - /// - /// - /// - /// - public int Count => _data.Count - 1; - - /// - /// - /// - /// - /// - public void Add(T item) - { - AddItem(item); - } - - /// - /// Adds the item. - /// - /// The item to add. - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the method. - /// - protected virtual void AddItem(T item) - { - // Add a dummy to the end of the list (it will be replaced) - _data.Add(default(T)); - - var counter = _data.Count - 1; - - while ((counter > 1) && (_comparerToUse.Compare(_data[counter / 2], item) > 0)) - { - _data[counter] = _data[counter / 2]; - counter = counter / 2; - } - - _data[counter] = item; - } - - - - /// - /// Always. - [SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] - bool ICollection.Remove(T item) - { - throw new NotSupportedException(); - } - - /// - /// Returns an enumerator that iterates through the collection. - /// - /// - /// A that can be used to iterate through the collection. - /// - /// - /// - /// - /// - public IEnumerator GetEnumerator() - { - for (var i = 1; i < _data.Count; i++) - { - yield return _data[i]; - } - } - - /// - /// - /// - /// - /// - public void Clear() - { - ClearItems(); - } - /// - /// Clears all the objects in this instance. - /// - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the method. - /// - protected virtual void ClearItems() - { - _data.RemoveRange(1, _data.Count - 1); // Clears all objects in this instance except the first dummy one. - } - - #endregion - - #region ICollection Members - - /// - /// - /// - /// - /// - public bool IsReadOnly => false; - - #endregion - - #region IEnumerable Members - - /// - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - #endregion - } -} diff --git a/src/NGenerics/DataStructures/General/HeapType.cs b/src/NGenerics/DataStructures/General/HeapType.cs deleted file mode 100644 index 5622bdb10c..0000000000 --- a/src/NGenerics/DataStructures/General/HeapType.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - - -namespace NGenerics.DataStructures.General -{ - /// - /// The type of to implemented. - /// - public enum HeapType - { - /// - /// Makes the heap a Minimum-Heap - the smallest item is kept in the root of the . - /// - Minimum, - - /// - /// Makes the heap a Maximum-Heap - the largest item is kept in the root of the . - /// - Maximum - } -} \ No newline at end of file diff --git a/src/NGenerics/DataStructures/General/IHeap.cs b/src/NGenerics/DataStructures/General/IHeap.cs deleted file mode 100644 index c8db163f01..0000000000 --- a/src/NGenerics/DataStructures/General/IHeap.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; - -namespace NGenerics.DataStructures.General -{ - /// - /// An interface for the data structure. - /// - /// The type of elements in the heap. - public interface IHeap - { - /// - /// Adds the specified item. - /// - /// The item. - void Add(T item); - - /// - /// Removes the root and returns it. - /// - /// The root of the . - /// The is empty. - T RemoveRoot(); - - /// - /// Gets the root. - /// - /// The root. - /// The is empty. - T Root { get; } - } -} diff --git a/src/NGenerics/DataStructures/Queues/IQueue.cs b/src/NGenerics/DataStructures/Queues/IQueue.cs deleted file mode 100644 index e1e6df809d..0000000000 --- a/src/NGenerics/DataStructures/Queues/IQueue.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; -using System.Diagnostics.CodeAnalysis; - -namespace NGenerics.DataStructures.Queues -{ - /// - /// A queue interface. - /// - /// The type of the elements in the queue. - [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] - public interface IQueue - { - /// - /// Enqueues the item at the back of the queue. - /// - /// The item. - void Enqueue(T item); - - /// - /// Dequeues the item at the front of the queue. - /// - /// The item at the front of the queue. - /// The is empty. - T Dequeue(); - - /// - /// Peeks at the item in the front of the queue, without removing it. - /// - /// The item at the front of the queue. - /// The is empty. - T Peek(); - } -} diff --git a/src/NGenerics/DataStructures/Queues/PriorityQueue.cs b/src/NGenerics/DataStructures/Queues/PriorityQueue.cs deleted file mode 100644 index ec91df458e..0000000000 --- a/src/NGenerics/DataStructures/Queues/PriorityQueue.cs +++ /dev/null @@ -1,556 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. - - Community contributions : - - TKey Peek(out TPriority) contributed by Karl Shulze (http://www.karlschulze.com/). -*/ - - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using NGenerics.Comparers; -using NGenerics.DataStructures.Trees; -using NGenerics.Util; - -namespace NGenerics.DataStructures.Queues -{ - /// - /// An implementation of a Priority Queue (can be or ). - /// - /// The type of the priority in the . - /// The type of the elements in the . - [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] - [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] - //[Serializable] - public class PriorityQueue : ICollection, IQueue - { - #region Globals - - private readonly RedBlackTreeList _tree; - private TPriority _defaultPriority; - private readonly PriorityQueueType _queueType; - - #endregion - - #region Construction - - /// Type of the queue. - /// - /// - /// - /// - public PriorityQueue(PriorityQueueType queueType) : - this(queueType, Comparer.Default) - { - } - - /// - public PriorityQueue(PriorityQueueType queueType, IComparer comparer) - { - if ((queueType != PriorityQueueType.Minimum) && (queueType != PriorityQueueType.Maximum)) - { - throw new ArgumentOutOfRangeException("queueType"); - } - _queueType = queueType; - _tree = new RedBlackTreeList(comparer); - } - - /// - /// Initializes a new instance of the class. - /// - /// Type of the queue. - /// The comparison. - /// - public PriorityQueue(PriorityQueueType queueType, Comparison comparison) : - this(queueType, new ComparisonComparer(comparison)) - { - } - - #endregion - - #region IQueue Members - - /// - /// - /// - /// - /// - public void Enqueue(TValue item) - { - Add(item); - } - - /// - /// Enqueues the specified item. - /// - /// The item. - /// The priority. - /// - /// - /// - /// - public void Enqueue(TValue item, TPriority priority) - { - Add(item, priority); - } - - /// - /// Dequeues the item at the front of the queue. - /// - /// The item at the front of the queue. - /// - /// - /// - /// - public TValue Dequeue() - { - TPriority priority; - return Dequeue(out priority); - } - - - /// - /// Peeks at the item in the front of the queue, without removing it. - /// - /// The item at the front of the queue. - /// - /// - /// - /// - public TValue Peek() - { - var association = GetNextItem(); - - // Always dequeue in FIFO manner - return association.Value.First.Value; - } - - - /// - /// Peeks at the item in the front of the queue, without removing it. - /// - /// The priority of the item. - /// The item at the front of the queue. - /// - /// - /// - /// - public TValue Peek(out TPriority priority) - { - var association = GetNextItem(); - var item = association.Value.First.Value; - priority = association.Key; - return item; - } - - #endregion - - #region ICollection Members - - /// - /// - /// - /// - /// - public bool IsReadOnly => false; - - #endregion - - #region IEnumerable Members - - /// - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - /// - /// Returns an enumerator that iterates through the collection. - /// - /// - /// A that can be used to iterate through the collection. - /// - /// - /// - /// - /// - public IEnumerator GetEnumerator() - { - return _tree.GetValueEnumerator(); - } - - #endregion - - #region Public Members - - /// - /// - /// - /// - /// - public int Count { get; private set; } - - /// - /// - /// - /// - /// - public bool Contains(TValue item) - { - return _tree.ContainsValue(item); - } - - /// - /// - /// - /// - /// - public void CopyTo(TValue[] array, int arrayIndex) - { - #region Validation - - Guard.ArgumentNotNull(array, "array"); - - if ((array.Length - arrayIndex) < Count) - { - throw new ArgumentException(Constants.NotEnoughSpaceInTheTargetArray, "array"); - } - - #endregion - - - foreach (var association in _tree) - { - var items = association.Value; - - foreach (var item in items) - { - array.SetValue(item, arrayIndex++); - } - } - } - - /// - /// - /// - /// - /// - public void Add(TValue item) - { - Add(item, _defaultPriority); - } - - /// - /// Adds an item to the . - /// - /// The object to add to the . - /// The priority of the item. - /// The is read-only. - /// - /// - /// - /// - public void Add(TValue item, TPriority priority) - { - AddItem(item, priority); - } - - /// - public bool Remove(TValue item) - { - TPriority priority; - return Remove(item, out priority); - } - - /// - /// Returns an enumerator that iterates through the keys in the collection. - /// - /// A that can be used to iterate through the keys in the collection. - /// - /// - /// - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] - public IEnumerator> GetKeyEnumerator() - { - return _tree.GetKeyEnumerator(); - } - - /// - /// - /// - /// - /// - public void Clear() - { - ClearItems(); - } - - /// - /// Dequeues the item from the head of the queue. - /// - /// The priority of the item to dequeue. - /// The item at the head of the queue. - /// The is empty. - /// - /// - /// - /// - [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")] - public TValue Dequeue(out TPriority priority) - { - return DequeueItem(out priority); - } - - /// - /// Dequeues the item at the front of the queue. - /// - /// The item at the front of the queue. - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the or methods. - /// - [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")] - protected virtual TValue DequeueItem(out TPriority priority) - { - var association = GetNextItem(); - - var item = association.Value.First.Value; - association.Value.RemoveFirst(); - - var key = association.Key; - - if (association.Value.Count == 0) - { - _tree.Remove(association.Key); - } - - Count--; - - priority = key; - return item; - } - - /// - /// Gets or sets the default priority. - /// - /// The default priority. - public TPriority DefaultPriority - { - get - { - return _defaultPriority; - } - set - { - _defaultPriority = value; - } - } - - /// - /// Removes the first occurrence of the specified item from the property queue. - /// - /// The item to remove. - /// The priority associated with the item. - /// true if the item exists in the and has been removed; otherwise false. - [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "1#")] - public bool Remove(TValue item, out TPriority priority) - { - return RemoveItem(item, out priority); - } - /// - /// Removes the item. - /// - /// The item to remove - /// The priority of the item that was removed. - /// An indication of whether the item was found, and removed. - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the method. - /// - [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "1#")] - protected virtual bool RemoveItem(TValue item, out TPriority priority) - { - var removed = _tree.Remove(item, out priority); - - if (removed) - { - Count--; - } - - return removed; - } - - /// - /// Removes the items with the specified priority. - /// - /// The priority. - /// true if the priority exists in the and has been removed; otherwise false. - public bool RemovePriorityGroup(TPriority priority) - { - return RemoveItems(priority); - } - - /// - /// Removes the items from the collection with the specified priority. - /// - /// The priority to search for. - /// An indication of whether items were found having the specified priority. - protected virtual bool RemoveItems(TPriority priority) - { - LinkedList items; - - if (_tree.TryGetValue(priority, out items)) - { - _tree.Remove(priority); - Count -= items.Count; - return true; - } - - return false; - } - - /// - /// Removes the items with the specified priority. - /// - /// The priority. - /// The items with the specified priority. - public IList GetPriorityGroup(TPriority priority) - { - LinkedList items; - - return _tree.TryGetValue(priority, out items) ? new List(items) : new List(); - } - - - /// - /// Adds the specified items to the priority queue with the specified priority. - /// - /// The items. - /// The priority. - /// is a null reference (Nothing in Visual Basic). - public void AddPriorityGroup(IList items, TPriority priority) - { - #region Validation - - Guard.ArgumentNotNull(items, "items"); - - #endregion - - AddPriorityGroupItem(items, priority); - } - - /// - /// Adds the specified items to the priority queue with the specified priority. - /// - /// The items. - /// The priority. - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the method. - /// - protected virtual void AddPriorityGroupItem(IList items, TPriority priority) - { - LinkedList currentValues; - - if (_tree.TryGetValue(priority, out currentValues)) - { - for (var i = 0; i < items.Count; i++) - { - currentValues.AddLast(items[i]); - } - } - else - { - currentValues = new LinkedList(items); - _tree.Add(priority, currentValues); - } - } - - #endregion - - #region Protected Members - - /// - /// Adds the item to the queue. - /// - /// The item to add. - /// The priority of the item. - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the method. - /// - protected virtual void AddItem(TValue item, TPriority priority) - { - LinkedList list; - - if (_tree.TryGetValue(priority, out list)) - { - list.AddLast(item); - } - else - { - list = new LinkedList(); - list.AddLast(item); - _tree.Add(priority, list); - } - - Count++; - } - - /// - /// Clears all the objects in this instance. - /// - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the method. - /// - protected virtual void ClearItems() - { - _tree.Clear(); - Count = 0; - } - - #endregion - - #region Private Members - - /// - /// Checks if the list is not empty, and if it is, throw an exception. - /// - private void CheckTreeNotEmpty() - { - if (_tree.Count == 0) - { - throw new InvalidOperationException("The Priority Queue is empty."); - } - } - - /// - /// Gets the next item. - /// - private KeyValuePair> GetNextItem() - { - #region Validation - - CheckTreeNotEmpty(); - - #endregion - - return _queueType == PriorityQueueType.Maximum ? _tree.Maximum : _tree.Minimum; - } - - #endregion - } -} diff --git a/src/NGenerics/DataStructures/Queues/PriorityQueueType.cs b/src/NGenerics/DataStructures/Queues/PriorityQueueType.cs deleted file mode 100644 index 94ee9a2dd9..0000000000 --- a/src/NGenerics/DataStructures/Queues/PriorityQueueType.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - -namespace NGenerics.DataStructures.Queues -{ - /// - /// Specifies the Priority Queue type (min or max). - /// - public enum PriorityQueueType - { - /// - /// Specify a Minimum . - /// - Minimum = 0, - - /// - /// Specify a Maximum . - /// - Maximum = 1 - } -} \ No newline at end of file diff --git a/src/NGenerics/DataStructures/Trees/BinarySearchTreeBase.cs b/src/NGenerics/DataStructures/Trees/BinarySearchTreeBase.cs deleted file mode 100644 index f7a55392d6..0000000000 --- a/src/NGenerics/DataStructures/Trees/BinarySearchTreeBase.cs +++ /dev/null @@ -1,529 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using NGenerics.Comparers; -using NGenerics.Patterns.Visitor; -using NGenerics.Util; - -namespace NGenerics.DataStructures.Trees -{ - /// - /// A base class for Binary Search Trees that store a single value in each node. - /// - /// - //[Serializable] - public abstract class BinarySearchTreeBase : ISearchTree - { - #region Globals - - internal const string alreadyContainedInTheTree = "The item is already contained in the tree."; - private BinaryTree _tree; - private readonly IComparer _comparer; - - #endregion - - #region Delegates - - /// - /// A custom comparison between some search value and the type of item that is kept in the tree. - /// - /// The type of the search. - protected delegate int CustomComparison(TSearch value, T item); - - #endregion - - #region Construction - - /// - /// Initializes a new instance of the class. - /// - protected BinarySearchTreeBase() - { - _comparer = Comparer.Default; - } - - /// - /// Initializes a new instance of the class. - /// - /// The comparer to use when comparing items. - /// is a null reference (Nothing in Visual Basic). - protected BinarySearchTreeBase(IComparer comparer) - { - Guard.ArgumentNotNull(comparer, "comparer"); - _comparer = comparer; - } - - /// - /// Initializes a new instance of the class. - /// - /// The comparison. - protected BinarySearchTreeBase(Comparison comparison) - { - Guard.ArgumentNotNull(comparison, "comparison"); - _comparer = new ComparisonComparer(comparison); - } - - #endregion - - #region Public Members - - /// - /// Gets the comparer. - /// - /// The comparer. - public IComparer Comparer => _comparer; - - #endregion - - #region Protected Members - - /// - /// Finds the node containing the specified data key. - /// - /// The item. - /// - /// The node with the specified key if found. If the key is not in the tree, this method returns null. - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - protected virtual BinaryTree FindNode(T item) - { - if (_tree == null) - { - return null; - } - - var currentNode = _tree; - - while (currentNode != null) - { - var nodeResult = _comparer.Compare(item, currentNode.Data); - - if (nodeResult == 0) - { - return currentNode; - } - - currentNode = nodeResult < 0 ? currentNode.Left : currentNode.Right; - } - - return null; - } - - /// - /// Finds the node that matches the custom delegate. - /// - /// The type of the search. - /// The value. - /// The custom comparison. - /// The item if found, else null. - protected virtual BinaryTree FindNode(TSearch value, CustomComparison customComparison) - { - if (_tree == null) - { - return null; - } - - var currentNode = _tree; - - while (currentNode != null) - { - var nodeResult = customComparison(value, currentNode.Data); - - if (nodeResult == 0) - { - return currentNode; - } - - currentNode = nodeResult < 0 ? currentNode.Left : currentNode.Right; - } - - return null; - } - - /// - /// Removes the item from the tree. - /// - /// The item to remove. - /// An indication of whether the item has been removed from the tree. - protected abstract bool RemoveItem(T item); - - /// - /// Adds the item. - /// - /// The item. - protected abstract void AddItem(T item); - - - /// - /// Find the maximum node. - /// - /// The maximum node. - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - protected BinaryTree FindMaximumNode() - { - #region Debug - - Debug.Assert(_tree != null); - - #endregion - - return FindMaximumNode(_tree); - } - - - /// - /// Find the minimum node. - /// - /// The minimum node. - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - protected BinaryTree FindMinimumNode() - { - #region Debug - - Debug.Assert(_tree != null); - - #endregion - - return FindMinimumNode(_tree); - } - - /// - /// Finds the maximum node. - /// - /// The start node. - /// The maximum node below this node. - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")] - protected static BinaryTree FindMaximumNode(BinaryTree startNode) - { - #region Asserts - - Debug.Assert(startNode != null); - - #endregion - - var searchNode = startNode; - - while (searchNode.Right != null) - { - searchNode = searchNode.Right; - } - - return searchNode; - } - - - /// - /// Finds the minimum node. - /// - /// The start node. - /// The minimum node below this node. - [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")] - protected static BinaryTree FindMinimumNode(BinaryTree startNode) - { - #region Asserts - - Debug.Assert(startNode != null); - - #endregion - - var searchNode = startNode; - - while (searchNode.Left != null) - { - searchNode = searchNode.Left; - } - - return searchNode; - } - - /// - /// Gets or sets the for this . - /// - [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - protected BinaryTree Tree - { - get - { - return _tree; - } - set - { - _tree = value; - } - } - - #endregion - - #region Private Members - - /// - /// Visits the node in an in-order fashion. - /// - /// The node. - /// The visitor. - private static void VisitNode(BinaryTree node, OrderedVisitor visitor) - { - if (node != null) - { - var pair = node.Data; - - visitor.VisitPreOrder(pair); - - VisitNode(node.Left, visitor); - - visitor.VisitInOrder(pair); - - VisitNode(node.Right, visitor); - - visitor.VisitPostOrder(pair); - } - } - - #endregion - - #region ISearchTree Members - - /// - /// - /// - /// - /// - public virtual T Minimum - { - get - { - #region Validation - - ValidateEmpty(); - - #endregion - - return FindMinimumNode().Data; - } - } - - private void ValidateEmpty() - { - if (Count == 0) - { - throw new InvalidOperationException("The search tree is empty."); - } - } - - /// - /// - /// - /// - /// - public virtual T Maximum - { - get - { - ValidateEmpty(); - - return FindMaximumNode().Data; - } - } /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - public void DepthFirstTraversal(OrderedVisitor visitor) - { - Guard.ArgumentNotNull(visitor, "visitor"); - - VisitNode(_tree, visitor); - } - - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] - public IEnumerator GetOrderedEnumerator() - { - if (_tree != null) - { - var trackingVisitor = new TrackingVisitor(); - var inOrderVisitor = new InOrderVisitor(trackingVisitor); - - _tree.DepthFirstTraversal(inOrderVisitor); - - var trackingList = trackingVisitor.TrackingList; - - for (var i = 0; i < trackingList.Count; i++) - { - yield return trackingList[i]; - } - } - } - - /// - /// - /// - /// - /// - public bool IsEmpty => Count == 0; - - /// - public bool Remove(T item) - { - var itemRemoved = RemoveItem(item); - - if (itemRemoved) - { - Count--; - } - - return itemRemoved; - } - - /// - /// - /// - /// - /// - public void Clear() - { - ClearItems(); - } - - /// - /// Clears all the objects in this instance. - /// - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the method. - /// - protected virtual void ClearItems() - { - _tree = null; - Count = 0; - } - - /// - /// - /// - /// - /// - public int Count { get; private set; } - - #endregion - - #region IEnumerable Members - - /// - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - /// - /// Returns an enumerator that iterates through the collection. - /// - /// - /// A that can be used to iterate through the collection. - /// - /// - /// - /// - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - public IEnumerator GetEnumerator() - { - if (_tree != null) - { - var stack = new Stack>(); - - stack.Push(_tree); - - while (stack.Count > 0) - { - var binaryTree = stack.Pop(); - - yield return binaryTree.Data; - - if (binaryTree.Left != null) - { - stack.Push(binaryTree.Left); - } - - if (binaryTree.Right != null) - { - stack.Push(binaryTree.Right); - } - } - } - } - - #endregion - - - #region ICollection Members - - /// - /// - /// - /// - /// - public void Add(T item) - { - AddItem(item); - Count++; - } - - /// - /// - /// - /// - /// - public virtual bool Contains(T item) - { - var node = FindNode(item); - return node != null; - } - - - /// - /// - /// - /// - /// - public void CopyTo(T[] array, int arrayIndex) - { - #region Validation - - Guard.ArgumentNotNull(array, "array"); - - if ((array.Length - arrayIndex) < Count) - { - throw new ArgumentException(Constants.NotEnoughSpaceInTheTargetArray, "array"); - } - - #endregion - - foreach (var association in _tree) - { - array[arrayIndex++] = association; - } - } - /// - /// - /// - /// - /// - public bool IsReadOnly => false; - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/DataStructures/Trees/BinaryTree.cs b/src/NGenerics/DataStructures/Trees/BinaryTree.cs deleted file mode 100644 index 6f3f953f97..0000000000 --- a/src/NGenerics/DataStructures/Trees/BinaryTree.cs +++ /dev/null @@ -1,674 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; -using System.Collections; -using System.Collections.Generic; -using NGenerics.Patterns.Visitor; -using NGenerics.Util; -using System.Diagnostics.CodeAnalysis; - -namespace NGenerics.DataStructures.Trees -{ - /// - /// An implementation of a Binary Tree data structure. - /// - /// The type of elements in the . - //[Serializable] - [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] - public class BinaryTree : ICollection, ITree - { - #region Globals - - private BinaryTree _leftSubtree; - private BinaryTree _rightSubtree; - private T _data; - - #endregion - - #region Construction - - /// The data contained in this node. - public BinaryTree(T data) : this(data, null, null) { } - - /// The data. - /// The data of the left subtree. - /// The data of the right subtree. - public BinaryTree(T data, T left, T right) : this(data, new BinaryTree(left), new BinaryTree(right)) { } - - /// The data contained in this node. - /// The left subtree. - /// The right subtree. - public BinaryTree(T data, BinaryTree left, BinaryTree right) - : this(data, left, right, true) - { - } - - - - /// The data contained in this node. - /// The left subtree. - /// The right subtree. - /// to validate ; otherwise . - internal BinaryTree(T data, BinaryTree left, BinaryTree right, bool validateData) - { - #region Validation - - //TODO: probably not the most efficient way of doing this but SplayTree needs to use a BinaryTree with null data. - if (validateData) - { - Guard.ArgumentNotNull(data, "data"); - } - - #endregion - - _leftSubtree = left; - - if (left != null) - { - left.Parent = this; - } - - _rightSubtree = right; - - if (right != null) - { - right.Parent = this; - } - - _data = data; - } - - - - #endregion - - #region ICollection Members - - /// - public bool IsEmpty => Count == 0; - - /// - public bool IsFull => (_leftSubtree != null) && (_rightSubtree != null); - - /// - public bool Contains(T item) - { - foreach (var thisItem in this) - { - if (item.Equals(thisItem)) - { - return true; - } - } - - return false; - } - - /// - public void CopyTo(T[] array, int arrayIndex) - { - Guard.ArgumentNotNull(array, "array"); - - foreach (var item in this) - { - #region Validation - - if (arrayIndex >= array.Length) - { - throw new ArgumentException(Constants.NotEnoughSpaceInTheTargetArray, "array"); - } - - #endregion - - array[arrayIndex++] = item; - } - } - - /// - public int Count - { - get - { - var count = 0; - - if (_leftSubtree != null) - { - count++; - } - - if (_rightSubtree != null) - { - count++; - } - - return count; - } - } - - /// - public void Add(T item) - { - AddItem(new BinaryTree(item)); - } - - /// - public bool Remove(T item) - { - if (_leftSubtree != null) - { - if (_leftSubtree._data.Equals(item)) - { - RemoveLeft(); - return true; - } - } - - if (_rightSubtree != null) - { - if (_rightSubtree._data.Equals(item)) - { - RemoveRight(); - return true; - } - } - - return false; - } - - /// - /// Removes the specified child. - /// - /// The child. - /// A value indicating whether the child was found (and removed) from this tree. - public bool Remove(BinaryTree child) - { - if (_leftSubtree != null) - { - if (_leftSubtree == child) - { - RemoveLeft(); - return true; - } - } - - if (_rightSubtree != null) - { - if (_rightSubtree == child) - { - RemoveRight(); - return true; - } - } - - return false; - } - - /// - /// Returns an enumerator that iterates through the collection. - /// - /// - /// A that can be used to iterate through the collection. - /// - public IEnumerator GetEnumerator() - { - var stack = new Stack>(); - - stack.Push(this); - - while (stack.Count > 0) - { - var tree = stack.Pop(); - - yield return tree.Data; - - if (tree._leftSubtree != null) - { - stack.Push(tree._leftSubtree); - } - - if (tree._rightSubtree != null) - { - stack.Push(tree._rightSubtree); - } - } - } - - /// - public virtual void Clear() - { - if (_leftSubtree != null) - { - _leftSubtree.Parent = null; - _leftSubtree = null; - } - - if (_rightSubtree != null) - { - _rightSubtree.Parent = null; - _rightSubtree = null; - } - } - - #endregion - - #region ITree Members - - /// - void ITree.Add(ITree child) - { - AddItem((BinaryTree)child); - } - - /// - ITree ITree.GetChild(int index) - { - return GetChild(index); - } - - /// - bool ITree.Remove(ITree child) - { - return Remove((BinaryTree)child); - } - - /// - ITree ITree.FindNode(Predicate condition) - { - return FindNode(condition); - } - - /// - ITree ITree.Parent => Parent; - - #endregion - - #region Public Members - - /// - /// Gets the parent of the current node.. - /// - /// The parent of the current node. - public BinaryTree Parent { get; private set; } - - /// - /// Finds the node with the specified condition. If a node is not found matching - /// the specified condition, null is returned. - /// - /// The condition to test. - /// The first node that matches the condition supplied. If a node is not found, null is returned. - /// is a null reference (Nothing in Visual Basic). - public BinaryTree FindNode(Predicate condition) - { - Guard.ArgumentNotNull(condition, "condition"); - - if (condition(Data)) - { - return this; - } - - if (_leftSubtree != null) - { - var ret = _leftSubtree.FindNode(condition); - - if (ret != null) - { - return ret; - } - } - - if (_rightSubtree != null) - { - var ret = _rightSubtree.FindNode(condition); - - if (ret != null) - { - return ret; - } - } - - return null; - } - - /// - /// Gets or sets the left subtree. - /// - /// The left subtree. - [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - public virtual BinaryTree Left - { - get - { - return _leftSubtree; - } - set - { - if (_leftSubtree != null) - { - RemoveLeft(); - } - - if (value != null) - { - if (value.Parent != null) - { - value.Parent.Remove(value); - } - - value.Parent = this; - } - - _leftSubtree = value; - } - } - - /// - /// Gets or sets the right subtree. - /// - /// The right subtree. - [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - public virtual BinaryTree Right - { - get - { - return _rightSubtree; - } - set - { - if (_rightSubtree != null) - { - RemoveRight(); - } - - if (value != null) - { - if (value.Parent != null) - { - value.Parent.Remove(value); - } - - value.Parent = this; - } - - _rightSubtree = value; - } - } - - /// - public virtual T Data - { - get - { - return _data; - } - set - { - #region Validation - - Guard.ArgumentNotNull(value, "data"); - - #endregion - - _data = value; - } - } - - /// - public int Degree => Count; - - /// - /// Gets the child at the specified index. - /// - /// The index of the child in question. - /// The child at the specified index. - /// does not equal 0 or 1. - public BinaryTree GetChild(int index) - { - switch (index) - { - case 0: - return _leftSubtree; - case 1: - return _rightSubtree; - default: - throw new ArgumentOutOfRangeException("index"); - } - } - /// - public virtual int Height - { - get - { - if (Degree == 0) - { - return 0; - } - - return 1 + FindMaximumChildHeight(); - } - } - - - /// - /// Performs a depth first traversal on this tree with the specified visitor. - /// - /// The ordered visitor. - /// is a null reference (Nothing in Visual Basic). - public virtual void DepthFirstTraversal(OrderedVisitor orderedVisitor) - { - Guard.ArgumentNotNull(orderedVisitor, "orderedVisitor"); - - if (orderedVisitor.HasCompleted) - { - return; - } - - // Preorder visit - orderedVisitor.VisitPreOrder(Data); - - if (_leftSubtree != null) - { - _leftSubtree.DepthFirstTraversal(orderedVisitor); - } - - // In-order visit - orderedVisitor.VisitInOrder(_data); - - if (_rightSubtree != null) - { - _rightSubtree.DepthFirstTraversal(orderedVisitor); - } - - // PostOrder visit - orderedVisitor.VisitPostOrder(Data); - } - - /// - /// Performs a breadth first traversal on this tree with the specified visitor. - /// - /// The visitor. - /// is a null reference (Nothing in Visual Basic). - public virtual void BreadthFirstTraversal(IVisitor visitor) - { - Guard.ArgumentNotNull(visitor, "visitor"); - - var queue = new Queue>(); - - queue.Enqueue(this); - - while (queue.Count > 0) - { - if (visitor.HasCompleted) - { - break; - } - - var binaryTree = queue.Dequeue(); - visitor.Visit(binaryTree.Data); - - for (var i = 0; i < binaryTree.Degree; i++) - { - var child = binaryTree.GetChild(i); - - if (child != null) - { - queue.Enqueue(child); - } - } - } - } - - - /// - public virtual bool IsLeafNode => Degree == 0; - - /// - /// Removes the left child. - /// - public virtual void RemoveLeft() - { - if (_leftSubtree != null) - { - _leftSubtree.Parent = null; - _leftSubtree = null; - } - } - - /// - /// Removes the left child. - /// - public virtual void RemoveRight() - { - if (_rightSubtree != null) - { - _rightSubtree.Parent = null; - _rightSubtree = null; - } - } - - /// - /// Adds an item to the . - /// - /// The subtree. - /// The is read-only. - /// The is full. - /// is null (Nothing in Visual Basic). - public void Add(BinaryTree subtree) - { - Guard.ArgumentNotNull(subtree, "subtree"); - - AddItem(subtree); - } - - /// - /// Adds an item to the . - /// - /// The subtree. - /// - /// Notes to Inheritors: - /// Derived classes can override this method to change the behavior of the method. - /// - protected virtual void AddItem(BinaryTree subtree) - { - if (_leftSubtree == null) - { - if (subtree.Parent != null) - { - subtree.Parent.Remove(subtree); - } - - _leftSubtree = subtree; - subtree.Parent = this; - } - else if (_rightSubtree == null) - { - if (subtree.Parent != null) - { - subtree.Parent.Remove(subtree); - } - - _rightSubtree = subtree; - subtree.Parent = this; - } - else - { - throw new InvalidOperationException("This binary tree is full."); - } - } - - - #endregion - - #region Private Members - - /// - /// Finds the maximum height between the child nodes. - /// - /// The maximum height of the tree between all paths from this node and all leaf nodes. - protected virtual int FindMaximumChildHeight() - { - var leftHeight = 0; - var rightHeight = 0; - - if (_leftSubtree != null) - { - leftHeight = _leftSubtree.Height; - } - - if (_rightSubtree != null) - { - rightHeight = _rightSubtree.Height; - } - - return leftHeight > rightHeight ? leftHeight : rightHeight; - } - - #endregion - - #region Operator Overloads - - /// - /// Gets the at the specified index. - /// - public BinaryTree this[int index] => GetChild(index); - - #endregion - - #region ICollection Members - - /// - public bool IsReadOnly => false; - - #endregion - - #region IEnumerable Members - - /// - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - #endregion - - #region Object Members - - /// - public override string ToString() - { - return _data.ToString(); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/DataStructures/Trees/ISearchTree.cs b/src/NGenerics/DataStructures/Trees/ISearchTree.cs deleted file mode 100644 index 08cc31ddfa..0000000000 --- a/src/NGenerics/DataStructures/Trees/ISearchTree.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using NGenerics.Patterns.Visitor; - -namespace NGenerics.DataStructures.Trees -{ - /// - /// An interface for Search Trees that mimic a dictionary. - /// - /// The type of element to hold in the tree. - [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] - public interface ISearchTree : ICollection - { - /// - /// Gets the largest item in the tree. - /// - /// The largest item in the tree. - /// The is empty. - T Maximum { get; } - - /// - /// Gets the smallest item in the tree. - /// - /// The smallest item in the tree. - /// The is empty. - T Minimum { get; } - - /// - /// Performs a depth first traversal on the search tree. - /// - /// The visitor to use. - /// is a null reference (Nothing in Visual Basic). - /// - /// - /// - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - void DepthFirstTraversal(OrderedVisitor visitor); - - /// - /// Returns an enumerator that iterates through the collection. - /// - /// - /// A that can be used to iterate through the collection. - /// - /// - /// - /// - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] - IEnumerator GetOrderedEnumerator(); - } -} diff --git a/src/NGenerics/DataStructures/Trees/ITree.cs b/src/NGenerics/DataStructures/Trees/ITree.cs deleted file mode 100644 index 7d2f7d134a..0000000000 --- a/src/NGenerics/DataStructures/Trees/ITree.cs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - -using System; - -namespace NGenerics.DataStructures.Trees -{ - /// - /// An interface for the tree data structure - /// - /// The type of elements in the tree. - public interface ITree - { - /// - /// Adds the specified child to the tree. - /// - /// The child to add.. - void Add(ITree child); - - /// - /// Gets the data held in this node. - /// - /// The data. - T Data { get; } - - /// - /// Gets the degree of this node. - /// - /// The degree of this node. - int Degree { get; } - - /// - /// Gets the child at the specified index. - /// - /// The index. - /// The child at the specified index. - ITree GetChild(int index); - - /// - /// Gets the height of this tree. - /// - /// The height of this tree. - int Height { get; } - - /// - /// Gets a value indicating whether this instance is leaf node. - /// - /// - /// true if this instance is leaf node; otherwise, false. - /// - bool IsLeafNode { get; } - - /// - /// Removes the specified child. - /// - /// The child. - /// An indication of whether the child was found (and removed) from this tree. - bool Remove(ITree child); - - /// - /// Finds the node for which the given predicate holds true. - /// - /// The condition to test on the data item. - /// The fist node that matches the condition if found, otherwise null. - ITree FindNode(Predicate condition); - - /// - /// Gets the parent of the current node. - /// - /// The parent of the current node. - ITree Parent { get; } - } -} diff --git a/src/NGenerics/DataStructures/Trees/NodeColor.cs b/src/NGenerics/DataStructures/Trees/NodeColor.cs deleted file mode 100644 index 839c1fbe0e..0000000000 --- a/src/NGenerics/DataStructures/Trees/NodeColor.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -namespace NGenerics.DataStructures.Trees -{ - internal enum NodeColor - { - Red = 0, - Black = 1 - } -} \ No newline at end of file diff --git a/src/NGenerics/DataStructures/Trees/RedBlackTree.cs b/src/NGenerics/DataStructures/Trees/RedBlackTree.cs deleted file mode 100644 index a2c76971c5..0000000000 --- a/src/NGenerics/DataStructures/Trees/RedBlackTree.cs +++ /dev/null @@ -1,291 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -/* - * The insertion and deletion code is based on the code found at http://eternallyconfuzzled.com/tuts/redblack.htm. - * It's an excellent tutorial - if you want to understand Red Black trees, look there first. - */ - -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; - -namespace NGenerics.DataStructures.Trees -{ - /// - /// An implementation of a Red-Black tree. - /// - /// The type of element to keep in the tree. - [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] - //[Serializable] - public class RedBlackTree : BinarySearchTreeBase - { - #region Construction - - /// - public RedBlackTree() - { - // Do nothing - the default Comparer will be used by the base class. - } - - - /// - public RedBlackTree(IComparer comparer) - : base(comparer) - { - // Do nothing else. - } - - /// - public RedBlackTree(Comparison comparison) - : base(comparison) - { - // Do nothing else. - } - - #endregion - - #region Public Members - - /// - /// Adds an element with the provided key and value to the . - /// - /// The item. - protected override void AddItem(T item) - { - #region Validation - - if (Equals(item, null)) - { - throw new ArgumentNullException("item"); - } - - #endregion - - var root = (RedBlackTreeNode)Tree; - - var newRoot = InsertNode(root, item); - newRoot.Color = NodeColor.Black; - Tree = newRoot; - } - - /// - /// Removes the element with the specified key from the . - /// - /// The item to remove. - /// - /// true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original . - /// - /// - protected override bool RemoveItem(T item) - { - if (Tree != null) - { - var startNode = new RedBlackTreeNode(default(T)); - - var childNode = startNode; - startNode.Right = (RedBlackTreeNode)Tree; - - RedBlackTreeNode parent = null; - RedBlackTreeNode foundNode = null; - - var direction = true; - - while (childNode[direction] != null) - { - var lastDirection = direction; - - var grandParent = parent; - parent = childNode; - childNode = childNode[direction]; - - var comparisonValue = Comparer.Compare(childNode.Data, item); - - if (comparisonValue == 0) - { - foundNode = childNode; - } - - direction = comparisonValue < 0; - - if ((IsBlack(childNode)) && (IsBlack(childNode[direction]))) - { - if (IsRed(childNode[!direction])) - { - parent = parent[lastDirection] = SingleRotation(childNode, direction); - } - else if (IsBlack(childNode[direction])) - { - var sibling = parent[!lastDirection]; - - if (sibling != null) - { - if ((IsBlack(sibling.Left)) && (IsBlack(sibling.Right))) - { - parent.Color = NodeColor.Black; - sibling.Color = NodeColor.Red; - childNode.Color = NodeColor.Red; - } - else - { - var parentDirection = grandParent.Right == parent; - - if (IsRed(sibling[lastDirection])) - { - grandParent[parentDirection] = DoubleRotation(parent, lastDirection); - } - else if (IsRed(sibling[!lastDirection])) - { - grandParent[parentDirection] = SingleRotation(parent, lastDirection); - } - - childNode.Color = grandParent[parentDirection].Color = NodeColor.Red; - grandParent[parentDirection].Left.Color = NodeColor.Black; - grandParent[parentDirection].Right.Color = NodeColor.Black; - } - } - } - } - } - - if (foundNode != null) - { - foundNode.Data = childNode.Data; - parent[parent.Right == childNode] = childNode[childNode.Left == null]; - } - - Tree = startNode.Right; - - if (Tree != null) - { - ((RedBlackTreeNode)Tree).Color = NodeColor.Black; - } - - if (foundNode != null) - { - return true; - } - } - - return false; - } - - #endregion - - #region Private Members - - /// - /// Determines whether the specified node is red. - /// - /// The node. - /// - /// true if the specified node is red; otherwise, false. - /// - private static bool IsRed(RedBlackTreeNode node) - { - return (node != null) && (node.Color == NodeColor.Red); - } - - /// - /// Determines whether the specified node is black. - /// - /// The node. - /// - /// true if the specified node is black; otherwise, false. - /// - private static bool IsBlack(RedBlackTreeNode node) - { - return (node == null) || (node.Color == NodeColor.Black); - } - - /// - /// A recursive implementation of insertion of a node into the tree. - /// - /// The start node. - /// The item. - /// The node created in the insertion. - private RedBlackTreeNode InsertNode(RedBlackTreeNode node, T item) - { - if (node == null) - { - node = new RedBlackTreeNode(item); - } - else if (Comparer.Compare(item, node.Data) != 0) - { - var direction = Comparer.Compare(node.Data, item) < 0; - - node[direction] = InsertNode(node[direction], item); - - if (IsRed(node[direction])) - { - if (IsRed(node[!direction])) - { - node.Color = NodeColor.Red; - node.Left.Color = NodeColor.Black; - node.Right.Color = NodeColor.Black; - } - else - { - if (IsRed(node[direction][direction])) - { - node = SingleRotation(node, !direction); - } - else if (IsRed(node[direction][!direction])) - { - node = DoubleRotation(node, !direction); - } - } - } - } - else - { - throw new ArgumentException(alreadyContainedInTheTree); - } - - return node; - } - - /// - /// Perform a single rotation on the node provided.. - /// - /// The node on which to focus the rotation. - /// The direction of the rotation. If direction is equal to true, a right rotation is performed. Other wise, a left rotation. - /// The new root of the cluster. - private static RedBlackTreeNode SingleRotation(RedBlackTreeNode node, bool direction) - { - var childSibling = node[!direction]; - - node[!direction] = childSibling[direction]; - childSibling[direction] = node; - - node.Color = NodeColor.Red; - childSibling.Color = NodeColor.Black; - - return childSibling; - } - - /// - /// Perform a double rotation on the node provided.. - /// - /// The node on which to focus the rotation. - /// The direction of the rotation. If direction is equal to true, a right rotation is performed. Other wise, a left rotation. - /// The new root of the cluster. - private static RedBlackTreeNode DoubleRotation(RedBlackTreeNode node, bool direction) - { - node[!direction] = SingleRotation(node[!direction], !direction); - return SingleRotation(node, direction); - } - - #endregion - } -} diff --git a/src/NGenerics/DataStructures/Trees/RedBlackTreeDictionary.cs b/src/NGenerics/DataStructures/Trees/RedBlackTreeDictionary.cs deleted file mode 100644 index 812fb0fa8b..0000000000 --- a/src/NGenerics/DataStructures/Trees/RedBlackTreeDictionary.cs +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -/* - * The insertion and deletion code is based on the code found at http://eternallyconfuzzled.com/tuts/redblack.htm. - * It's an excellent tutorial - if you want to understand Red Black trees, look there first. - */ - -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics.CodeAnalysis; -using NGenerics.Comparers; -using NGenerics.Patterns.Visitor; - -namespace NGenerics.DataStructures.Trees -{ - /// - /// An implementation of a Red-Black tree. - /// - /// The type of the keys in the . - /// The type of the values in the . - [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] -#if (!SILVERLIGHT && !WINDOWSPHONE) - //[Serializable] -#endif - public class RedBlackTree : RedBlackTree>, IDictionary // BinarySearchTreeBase - { - #region Construction - /// - public RedBlackTree() : base(new KeyValuePairComparer()) - { - // Do nothing - the default Comparer will be used by the base class. - } - - - /// - public RedBlackTree(IComparer comparer) - : base(new KeyValuePairComparer(comparer)) - { - // Do nothing else. - } - - /// - public RedBlackTree(Comparison comparison) - : base(new KeyValuePairComparer(comparison)) - { - // Do nothing else. - } - - #endregion - - #region Private Members - - private RedBlackTreeNode> FindNode(TKey key) - { - return base.FindNode(new KeyValuePair(key, default(TValue))) as RedBlackTreeNode>; - } - - private bool Contains(KeyValuePair item, bool checkValue) - { - var node = FindNode(item); - - if ((node != null) && !checkValue) - { - return true; - } - - return node != null && Equals(item.Value, node.Data.Value); - } - - #endregion - - #region IDictionary Members - - /// - /// Removes the element with the specified key from the . - /// - /// The key of the element to remove. - /// - /// true if the element is successfully removed; otherwise, false. This method also returns false if was not found in the original . - /// - /// - /// is null. - /// - /// - /// The is read-only. - /// - public bool Remove(TKey key) - { - return Remove(new KeyValuePair(key, default(TValue))); - } - - /// - /// Adds an element with the provided key and value to the . - /// - /// The object to use as the key of the element to add. - /// The object to use as the value of the element to add. - /// - /// is null. - /// - /// - /// An element with the same key already exists in the . - /// - /// - /// The is read-only. - /// - public void Add(TKey key, TValue value) - { - if (Equals(key, null)) - { - throw new ArgumentNullException("key"); - } - - Add(new KeyValuePair(key, value)); - } - - /// - /// Determines whether the contains an element with the specified key. - /// - /// The key to locate in the . - /// - /// true if the contains an element with the key; otherwise, false. - /// - /// - /// is null. - /// - public bool ContainsKey(TKey key) - { - return Contains(new KeyValuePair(key, default(TValue)), false); - } - - /// - /// Gets an containing the keys of the . - /// - /// - /// - /// - /// - /// - public ICollection Keys - { - get - { - // Get the keys in sorted order - var visitor = new KeyTrackingVisitor(); - var inOrderVisitor = new InOrderVisitor>(visitor); - DepthFirstTraversal(inOrderVisitor); - return new ReadOnlyCollection(visitor.TrackingList); - } - } - - - /// - /// - /// - /// - /// - public bool TryGetValue(TKey key, out TValue value) - { - var node = FindNode(new KeyValuePair(key, default(TValue))); - - if (node == null) - { - value = default(TValue); - return false; - } - - value = node.Data.Value; - return true; - } - - /// - /// Gets an containing the values in the . - /// - /// - /// - /// - /// - /// - public ICollection Values - { - get - { - var visitor = new ValueTrackingVisitor(); - var inOrderVisitor = new InOrderVisitor>(visitor); - - DepthFirstTraversal(inOrderVisitor); - - return new ReadOnlyCollection(visitor.TrackingList); - } - } - - - /// - /// Gets or sets the value with the specified key. - /// - /// The key of the item to set or get. - public TValue this[TKey key] - { - get - { - var node = FindNode(key); - - if (node == null) - { - throw new KeyNotFoundException("key"); - } - - return node.Data.Value; - } - set - { - var node = FindNode(key); - - if (node == null) - { - throw new KeyNotFoundException("key"); - } - - node.Data = new KeyValuePair(key, value); - } - } - - #endregion - - #region ICollection> Members - - /// - /// - /// - /// - /// - public override bool Contains(KeyValuePair item) - { - return Contains(item, true); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/DataStructures/Trees/RedBlackTreeList.cs b/src/NGenerics/DataStructures/Trees/RedBlackTreeList.cs deleted file mode 100644 index 7a4c64168d..0000000000 --- a/src/NGenerics/DataStructures/Trees/RedBlackTreeList.cs +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - -namespace NGenerics.DataStructures.Trees -{ - /// - /// A RedBlack Tree list variant. Equivalent to where TValue is a . - /// - /// The type of the key. - /// The type of the value. - //[Serializable] - internal class RedBlackTreeList : RedBlackTree> - { - #region Delegates - - private delegate bool NodeAction(TKey key, LinkedList values); - - #endregion - - #region Construction - - /// - /// Initializes a new instance of the class. - /// - /// - public RedBlackTreeList() - { - // Do nothing else. - } - - /// - public RedBlackTreeList(IComparer comparer) - : base(comparer) - { - // Do nothing else. - } - - /// - public RedBlackTreeList(Comparison comparison) - : base(comparison) - { - // Do nothing else. - } - - #endregion - - #region Public Members - - /// - /// Determines whether the specified value contains value. - /// - /// The value. - /// - /// true if the specified value contains value; otherwise, false. - /// - public bool ContainsValue(TValue value) - { - return TraverseItems((key, list) => list.Contains(value)); - } - - /// - /// Gets the value enumerator. - /// - /// An enumerator to enumerate through the values contained in this instance. - public IEnumerator GetValueEnumerator() - { - var stack = new Stack>>>(); - - if (Tree != null) - { - stack.Push(Tree); - } - - while (stack.Count > 0) - { - var currentNode = stack.Pop(); - - var list = currentNode.Data.Value; - - foreach (var item in list) - { - yield return item; - } - - if (currentNode.Left != null) - { - stack.Push(currentNode.Left); - } - - if (currentNode.Right != null) - { - stack.Push(currentNode.Right); - } - } - } - - /// - /// Returns an enumerator that iterates through the collection. - /// - /// - /// A that can be used to iterate through the collection. - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] - public IEnumerator> GetKeyEnumerator() - { - var stack = new Stack>>>(); - - if (Tree != null) - { - stack.Push(Tree); - } - - while (stack.Count > 0) - { - var currentNode = stack.Pop(); - - var list = currentNode.Data.Value; - - foreach (var item in list) - { - yield return new KeyValuePair(currentNode.Data.Key, item); - } - - if (currentNode.Left != null) - { - stack.Push(currentNode.Left); - } - - if (currentNode.Right != null) - { - stack.Push(currentNode.Right); - } - } - } - - /// - /// Removes the specified value. - /// - /// The value. - /// The key under which the item was found. - /// A value indicating whether the item was found or not. - public bool Remove(TValue value, out TKey key) - { - var foundKey = default(TKey); - - var ret = TraverseItems( - delegate (TKey itemKey, LinkedList list) - { - if (list.Remove(value)) - { - if (list.Count == 0) - { - Remove(itemKey); - } - - foundKey = itemKey; - return true; - } - - return false; - } - ); - - key = foundKey; - return ret; - } - - #endregion - - #region Private Members - - /// - /// Traverses the items. - /// - /// A predicate that performs an action on the list, and indicates whether the enumeration of items should stop or not. - /// An indication of whether the enumeration was stopped prematurely. - private bool TraverseItems(NodeAction shouldStop) - { - #region Validation - - Debug.Assert(shouldStop != null); - - #endregion - - var stack = new Stack>>>(); - - if (Tree != null) - { - stack.Push(Tree); - } - - while (stack.Count > 0) - { - var currentNode = stack.Pop(); - - if (shouldStop(currentNode.Data.Key, currentNode.Data.Value)) - { - return true; - } - - if (currentNode.Left != null) - { - stack.Push(currentNode.Left); - } - - if (currentNode.Right != null) - { - stack.Push(currentNode.Right); - } - } - - return false; - } - - #endregion - } -} diff --git a/src/NGenerics/DataStructures/Trees/RedBlackTreeNode.cs b/src/NGenerics/DataStructures/Trees/RedBlackTreeNode.cs deleted file mode 100644 index 02d6cf837a..0000000000 --- a/src/NGenerics/DataStructures/Trees/RedBlackTreeNode.cs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - - -using System; -using System.Diagnostics.CodeAnalysis; - -namespace NGenerics.DataStructures.Trees -{ - /// - /// A container class, used for the RedBlackTree. - /// - /// The type of element. - //[Serializable] - [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] - internal class RedBlackTreeNode : BinaryTree - { - #region Construction - - /// - /// Initializes a new instance of the class. - /// - /// The data contained in this node. - internal RedBlackTreeNode(T data) - : base(data) - { - Color = NodeColor.Red; - } - - #endregion - - #region Properties - - /// - /// Gets or sets the color of the current node. - /// - /// The color of the node. - internal NodeColor Color { get; set; } - - /// - /// Gets or sets the with the specified direction. - /// - /// - internal RedBlackTreeNode this[bool direction] - { - get - { - return direction ? Right : Left; - } - set - { - if (direction) - { - Right = value; - } - else - { - Left = value; - } - } - } - - /// - /// Gets or sets the left subtree. - /// - /// The left subtree. - internal new RedBlackTreeNode Left - { - get - { - return (RedBlackTreeNode)base.Left; - } - set - { - base.Left = value; - } - } - - /// - /// Gets or sets the right subtree. - /// - /// The right subtree. - internal new RedBlackTreeNode Right - { - get - { - return (RedBlackTreeNode)base.Right; - } - set - { - base.Right = value; - } - } - - #endregion - } -} diff --git a/src/NGenerics/NGenerics.csproj b/src/NGenerics/NGenerics.csproj deleted file mode 100644 index beba06a3c5..0000000000 --- a/src/NGenerics/NGenerics.csproj +++ /dev/null @@ -1,76 +0,0 @@ - - - - - 11.0 - Debug - AnyCPU - {415E048E-4611-4815-9CF2-D774E29079AC} - Library - Properties - NGenerics - NGenerics - en-US - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Profile7 - v4.5 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/NGenerics/Patterns/Visitor/IVisitor.cs b/src/NGenerics/Patterns/Visitor/IVisitor.cs deleted file mode 100644 index acaf2ff110..0000000000 --- a/src/NGenerics/Patterns/Visitor/IVisitor.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -namespace NGenerics.Patterns.Visitor -{ - /// - /// Provides an interface for visitors. - /// - /// The type of objects to be visited. - public interface IVisitor - { - /// - /// Gets a value indicating whether this instance is done performing it's work.. - /// - /// true if this instance is done; otherwise, false. - bool HasCompleted { get; } - - /// - /// Visits the specified object. - /// - /// The object to visit. - void Visit(T obj); - } -} \ No newline at end of file diff --git a/src/NGenerics/Patterns/Visitor/InOrderVisitor.cs b/src/NGenerics/Patterns/Visitor/InOrderVisitor.cs deleted file mode 100644 index de65c9cd92..0000000000 --- a/src/NGenerics/Patterns/Visitor/InOrderVisitor.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -namespace NGenerics.Patterns.Visitor -{ - /// - /// An in order implementation of the class. - /// - /// The type of objects to be visited. - public sealed class InOrderVisitor : OrderedVisitor - { - #region Construction - - /// The visitor. - public InOrderVisitor(IVisitor visitor) : base(visitor) { } - - #endregion - - #region OrderedVisitor Members - - /// - /// Visits the object in post order. - /// - /// The obj. - public override void VisitPostOrder(T obj) - { - // Do nothing. - } - - /// - /// Visits the object in pre order. - /// - /// The obj. - public override void VisitPreOrder(T obj) - { - // Do nothing. - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/Patterns/Visitor/KeyTrackingVisitor.cs b/src/NGenerics/Patterns/Visitor/KeyTrackingVisitor.cs deleted file mode 100644 index df17b4396c..0000000000 --- a/src/NGenerics/Patterns/Visitor/KeyTrackingVisitor.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System.Collections.Generic; - -namespace NGenerics.Patterns.Visitor -{ - /// - /// A visitor that tracks (stores) keys from KeyValuePAirs in the order they were visited. - /// - /// The type of the keys for the items to be visited. - /// The type of the values for the items to be visited. - public sealed class KeyTrackingVisitor : IVisitor> - { - #region Globals - - private readonly List _tracks; - - #endregion - - #region Construction - - /// - public KeyTrackingVisitor() - { - _tracks = new List(); - } - - #endregion - - #region Public Members - - /// - /// Gets the tracking list. - /// - /// The tracking list. - public IList TrackingList => _tracks; - - #endregion - - #region IVisitor> Members - - - /// - public void Visit(KeyValuePair obj) - { - _tracks.Add(obj.Key); - } - - /// - public bool HasCompleted => false; - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/Patterns/Visitor/OrderedVisitor.cs b/src/NGenerics/Patterns/Visitor/OrderedVisitor.cs deleted file mode 100644 index beeef6a8ac..0000000000 --- a/src/NGenerics/Patterns/Visitor/OrderedVisitor.cs +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; -using System.Diagnostics.CodeAnalysis; -using NGenerics.Util; - -namespace NGenerics.Patterns.Visitor -{ - /// - /// A visitor that visits objects in order (PreOrder, PostOrder, or InOrder). - /// Used primarily as a base class for Visitors specializing in a specific order type. - /// - /// The type of objects to be visited. - public class OrderedVisitor : IVisitor - { - #region Globals - - private readonly IVisitor _visitorToUse; - - #endregion - - #region Construction - - /// The visitor to use when visiting the object. - /// is a null reference (Nothing in Visual Basic). - public OrderedVisitor(IVisitor visitorToUse) - { - Guard.ArgumentNotNull(visitorToUse, "visitorToUse"); - - _visitorToUse = visitorToUse; - } - - #endregion - - #region IOrderedVisitor Members - - /// - /// Determines whether this visitor is done. - /// - /// - /// - /// true if this visitor is done; otherwise, false. - /// - public bool HasCompleted => _visitorToUse.HasCompleted; - - /// - /// Visits the object in pre order. - /// - /// The obj. - [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "PreOrder")] - public virtual void VisitPreOrder(T obj) - { - _visitorToUse.Visit(obj); - } - - /// - /// Visits the object in post order. - /// - /// The obj. - public virtual void VisitPostOrder(T obj) - { - _visitorToUse.Visit(obj); - } - - /// - /// Visits the object in order. - /// - /// The obj. - public virtual void VisitInOrder(T obj) - { - _visitorToUse.Visit(obj); - } - /// - public void Visit(T obj) - { - _visitorToUse.Visit(obj); - } - - #endregion - - #region Public Members - - /// - /// Gets the visitor to use. - /// - /// The visitor to use. - public IVisitor VisitorToUse => _visitorToUse; - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/Patterns/Visitor/TrackingVisitor.cs b/src/NGenerics/Patterns/Visitor/TrackingVisitor.cs deleted file mode 100644 index aa747df54d..0000000000 --- a/src/NGenerics/Patterns/Visitor/TrackingVisitor.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System.Collections.Generic; - -namespace NGenerics.Patterns.Visitor -{ - /// - /// A visitor that tracks (stores) objects in the order they were visited. - /// Handy for demonstrating and testing different ordered visits implementations on - /// data structures. - /// - /// The type of objects to be visited. - public sealed class TrackingVisitor : IVisitor - { - #region Globals - - private readonly List _tracks; - - #endregion - - #region Construction - - - /// - public TrackingVisitor() - { - _tracks = new List(); - } - - #endregion - - #region IVisitor Members - /// - public void Visit(T obj) - { - _tracks.Add(obj); - } - - /// - public bool HasCompleted => false; - - #endregion - - #region Public Members - - /// - /// Gets the tracking list. - /// - /// The tracking list. - public IList TrackingList => _tracks; - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/Patterns/Visitor/ValueTrackingVisitor.cs b/src/NGenerics/Patterns/Visitor/ValueTrackingVisitor.cs deleted file mode 100644 index e6dde77695..0000000000 --- a/src/NGenerics/Patterns/Visitor/ValueTrackingVisitor.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System.Collections.Generic; - -namespace NGenerics.Patterns.Visitor -{ - /// - /// A visitor that tracks (stores) keys from KeyValuePairs in the order they were visited. - /// - /// The type of key of the KeyValuePair. - /// The type of value of the KeyValuePair. - public sealed class ValueTrackingVisitor : IVisitor> - { - #region Globals - - private readonly List _tracks; - - #endregion - - #region Construction - - - /// - public ValueTrackingVisitor() - { - _tracks = new List(); - } - - #endregion - - #region Public Members - - /// - /// Gets the tracking list. - /// - /// The tracking list. - public IList TrackingList => _tracks; - - #endregion - - #region IVisitor> Members - - - /// - public void Visit(KeyValuePair obj) - { - _tracks.Add(obj.Value); - } - - /// - public bool HasCompleted => false; - - #endregion - } -} \ No newline at end of file diff --git a/src/NGenerics/Properties/AssemblyInfo.cs b/src/NGenerics/Properties/AssemblyInfo.cs deleted file mode 100644 index 5bd5019cf6..0000000000 --- a/src/NGenerics/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("NGenerics")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("NGenerics")] -[assembly: AssemblyCopyright("Copyright \u00A9 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/NGenerics/Util/Guard.cs b/src/NGenerics/Util/Guard.cs deleted file mode 100644 index 20bccf4a58..0000000000 --- a/src/NGenerics/Util/Guard.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) The Perspex Project. All rights reserved. -// Licensed under the MIT license. See licence.md file in the project root for full license information. - -/* - Copyright 2007-2013 The NGenerics Team - (https://github.com/ngenerics/ngenerics/wiki/Team) - - This program is licensed under the GNU Lesser General Public License (LGPL). You should - have received a copy of the license along with the source code. If not, an online copy - of the license can be found at http://www.gnu.org/copyleft/lesser.html. -*/ - - -using System; - -namespace NGenerics.Util -{ - /// - /// Performs common argument validation. - /// - public static class Guard - { - #region Methods - - /// - /// Checks a string argument to ensure it isn't null or empty. - /// - /// The argument value to check. - /// The name of the argument. - /// is a null reference. - /// is . - public static void ArgumentNotNullOrEmptyString(string argumentValue, string argumentName) - { - ArgumentNotNull(argumentValue, argumentName); - - if (argumentValue.Length == 0) - { - throw new ArgumentException("String cannot be empty.", argumentName); - } - } - - - /// - /// Checks an argument to ensure it isn't null. - /// - /// The argument value to check. - /// The name of the argument. - /// is a null reference. - public static void ArgumentNotNull(object argumentValue, string argumentName) - { - if (argumentValue == null) - { - throw new ArgumentNullException(argumentName); - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Perspex.Base/Perspex.Base.csproj b/src/Perspex.Base/Perspex.Base.csproj index 2adf2545a2..f6fdace315 100644 --- a/src/Perspex.Base/Perspex.Base.csproj +++ b/src/Perspex.Base/Perspex.Base.csproj @@ -101,12 +101,6 @@ - - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - - - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation diff --git a/tests/Perspex.Interactivity.UnitTests/Perspex.Interactivity.UnitTests.csproj b/tests/Perspex.Interactivity.UnitTests/Perspex.Interactivity.UnitTests.csproj index 64ff11dc9d..3ea7c3f38c 100644 --- a/tests/Perspex.Interactivity.UnitTests/Perspex.Interactivity.UnitTests.csproj +++ b/tests/Perspex.Interactivity.UnitTests/Perspex.Interactivity.UnitTests.csproj @@ -64,10 +64,6 @@ - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation diff --git a/tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj b/tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj index fd31d43a43..e558a11fd5 100644 --- a/tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj +++ b/tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj @@ -76,10 +76,6 @@ - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation diff --git a/tests/Perspex.Markup.Xaml.UnitTests/Perspex.Markup.Xaml.UnitTests.csproj b/tests/Perspex.Markup.Xaml.UnitTests/Perspex.Markup.Xaml.UnitTests.csproj index 85aa11a0b2..3d489dd682 100644 --- a/tests/Perspex.Markup.Xaml.UnitTests/Perspex.Markup.Xaml.UnitTests.csproj +++ b/tests/Perspex.Markup.Xaml.UnitTests/Perspex.Markup.Xaml.UnitTests.csproj @@ -113,10 +113,6 @@ {3E53A01A-B331-47F3-B828-4A5717E77A24} Perspex.Markup.Xaml - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation From 685765bafd6e01602b544ad3bb85e1e49c5f6d7d Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 23 Sep 2015 19:29:52 +0200 Subject: [PATCH 05/24] Removed NGenerics from nuget script. --- nuget/build-version.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/nuget/build-version.ps1 b/nuget/build-version.ps1 index d046f34888..1cce68564d 100644 --- a/nuget/build-version.ps1 +++ b/nuget/build-version.ps1 @@ -32,7 +32,6 @@ Copy-Item ..\src\Markup\Perspex.Markup.Xaml\bin\Release\Perspex.Markup.Xaml.dll Copy-Item ..\src\Markup\Perspex.Markup.Xaml\bin\Release\Perspex.Markup.Xaml.xml $lib Copy-Item ..\src\Perspex.HtmlRenderer\bin\Release\Perspex.HtmlRenderer.dll $lib Copy-Item ..\src\Perspex.ReactiveUI\bin\Release\Perspex.ReactiveUI.dll $lib -Copy-Item ..\src\NGenerics\bin\Release\NGenerics.dll $lib Copy-Item ..\src\Windows\Perspex.Direct2D1\bin\Release\Perspex.Direct2D1.dll $build Copy-Item ..\src\Windows\Perspex.Direct2D1\bin\Release\SharpDX.dll $build From 4f8e496f73a271ae85755c45a3f42e74a8aa2f63 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 24 Sep 2015 00:21:51 +0200 Subject: [PATCH 06/24] Updated OmniXaml. --- src/Markup/Perspex.Markup.Xaml/OmniXAML | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Markup/Perspex.Markup.Xaml/OmniXAML b/src/Markup/Perspex.Markup.Xaml/OmniXAML index 7b13ebcde0..1461be589a 160000 --- a/src/Markup/Perspex.Markup.Xaml/OmniXAML +++ b/src/Markup/Perspex.Markup.Xaml/OmniXAML @@ -1 +1 @@ -Subproject commit 7b13ebcde030df9f8d538917e57b3a34ea9edf32 +Subproject commit 1461be589a5d39d378fd177648c61a780271c742 From 5a27ecf2642e73d3c218304564d74d25ad36cd63 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 24 Sep 2015 01:58:27 +0200 Subject: [PATCH 07/24] Add IAssetLoader.Exists Closes #181. --- .../Perspex.Markup.Xaml/PerspexXamlLoader.cs | 14 +++++--------- .../Platform/IAssetLoader.cs | 7 +++++++ src/Shared/PlatformSupport/AssetLoader.cs | 19 +++++++++++++++---- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs b/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs index e69bcfdf81..65e1ce4f71 100644 --- a/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs +++ b/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs @@ -65,17 +65,13 @@ namespace Perspex.Markup.Xaml } foreach (var uri in GetUrisFor(type)) { - Stream stream; - try + if (assetLocator.Exists(uri)) { - stream= assetLocator.Open(uri); + using (var stream = assetLocator.Open(uri)) + { + return Load(stream, rootInstance); + } } - catch (FileNotFoundException) - { - continue; - } - using (stream) - return Load(stream, rootInstance); } throw new FileNotFoundException("Unable to find view for " + type.FullName); } diff --git a/src/Perspex.Application/Platform/IAssetLoader.cs b/src/Perspex.Application/Platform/IAssetLoader.cs index 96e0aad475..9594e7e021 100644 --- a/src/Perspex.Application/Platform/IAssetLoader.cs +++ b/src/Perspex.Application/Platform/IAssetLoader.cs @@ -11,6 +11,13 @@ namespace Perspex.Platform /// public interface IAssetLoader { + /// + /// Checks if an asset with the specified URI exists. + /// + /// The URI. + /// True if the asset could be found; otherwise false. + bool Exists(Uri uri); + /// /// Opens the resource with the requested URI. /// diff --git a/src/Shared/PlatformSupport/AssetLoader.cs b/src/Shared/PlatformSupport/AssetLoader.cs index 3be0509ef4..229cefb8b2 100644 --- a/src/Shared/PlatformSupport/AssetLoader.cs +++ b/src/Shared/PlatformSupport/AssetLoader.cs @@ -3,11 +3,9 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Linq; using System.Reflection; -using System.Resources; using Perspex.Platform; namespace Perspex.Shared.PlatformSupport @@ -20,7 +18,6 @@ namespace Perspex.Shared.PlatformSupport private static readonly Dictionary AssemblyNameCache = new Dictionary(); - static Assembly GetAssembly(string name) { Assembly rv; @@ -31,6 +28,20 @@ namespace Perspex.Shared.PlatformSupport return rv; } + /// + /// Checks if an asset with the specified URI exists. + /// + /// The URI. + /// True if the asset could be found; otherwise false. + public bool Exists(Uri uri) + { + var parts = uri.AbsolutePath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); + var asm = parts.Length == 1 ? Assembly.GetEntryAssembly() : GetAssembly(parts[0]); + var typeName = parts[parts.Length == 1 ? 0 : 1]; + var rv = asm.GetManifestResourceStream(typeName); + return rv != null; + } + /// /// Opens the resource with the requested URI. /// @@ -46,7 +57,7 @@ namespace Perspex.Shared.PlatformSupport var typeName = parts[parts.Length == 1 ? 0 : 1]; var rv = asm.GetManifestResourceStream(typeName); if (rv == null) - throw new FileNotFoundException(uri.ToString()); + throw new FileNotFoundException($"The resource {uri} could not be found."); return rv; } } From ef65e09b2d674efc49079713ad23ad1b3a01e2fd Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 24 Sep 2015 16:59:50 +0300 Subject: [PATCH 08/24] Implemented Win32 version of file dialog --- src/Perspex.Controls/CommonDialog.cs | 34 +++++ src/Perspex.Controls/Perspex.Controls.csproj | 2 + .../Platform/ICommonDialogImpl.cs | 14 +++ src/Windows/Perspex.Win32/CommonDialogImpl.cs | 117 ++++++++++++++++++ .../Perspex.Win32/Interop/UnmanagedMethods.cs | 52 ++++++++ .../Perspex.Win32/Perspex.Win32.csproj | 3 + src/Windows/Perspex.Win32/Win32Platform.cs | 2 + 7 files changed, 224 insertions(+) create mode 100644 src/Perspex.Controls/CommonDialog.cs create mode 100644 src/Perspex.Controls/Platform/ICommonDialogImpl.cs create mode 100644 src/Windows/Perspex.Win32/CommonDialogImpl.cs diff --git a/src/Perspex.Controls/CommonDialog.cs b/src/Perspex.Controls/CommonDialog.cs new file mode 100644 index 0000000000..cc81ee0122 --- /dev/null +++ b/src/Perspex.Controls/CommonDialog.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Perspex.Controls.Platform; +using Splat; + +namespace Perspex.Controls +{ + public class CommonDialog + { + public string Title { get; set; } + public List Filters { get; set; } = new List(); + public string InitialFileName { get; set; } + public string InitialDirectory { get; set; } + public bool AllowMultiple { get; set; } + public string DefaultExtension { get; set; } + public CommonDialogAction Action { get; set; } + + + public Task ShowAsync(Window window = null) + => Locator.Current.GetService().ShowAsync(this, window?.PlatformImpl); + } + + public enum CommonDialogAction + { + OpenFile, + SaveFile + } + + public class CommonDialogFilter + { + public string Name { get; set; } + public List Extensions { get; set; } = new List(); + } +} diff --git a/src/Perspex.Controls/Perspex.Controls.csproj b/src/Perspex.Controls/Perspex.Controls.csproj index 38d5486118..117a683330 100644 --- a/src/Perspex.Controls/Perspex.Controls.csproj +++ b/src/Perspex.Controls/Perspex.Controls.csproj @@ -41,6 +41,7 @@ Properties\SharedAssemblyInfo.cs + @@ -64,6 +65,7 @@ + diff --git a/src/Perspex.Controls/Platform/ICommonDialogImpl.cs b/src/Perspex.Controls/Platform/ICommonDialogImpl.cs new file mode 100644 index 0000000000..89f817a675 --- /dev/null +++ b/src/Perspex.Controls/Platform/ICommonDialogImpl.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Perspex.Platform; + +namespace Perspex.Controls.Platform +{ + public interface ICommonDialogImpl + { + Task ShowAsync(CommonDialog dialog, IWindowImpl parent); + } +} diff --git a/src/Windows/Perspex.Win32/CommonDialogImpl.cs b/src/Windows/Perspex.Win32/CommonDialogImpl.cs new file mode 100644 index 0000000000..d0cce7be95 --- /dev/null +++ b/src/Windows/Perspex.Win32/CommonDialogImpl.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using Perspex.Controls; +using Perspex.Controls.Platform; +using Perspex.Platform; +using Perspex.Win32.Interop; + +namespace Perspex.Win32 +{ + class CommonDialogImpl : ICommonDialogImpl + { + public unsafe Task ShowAsync(CommonDialog dialog, IWindowImpl parent) + { + var hWnd = parent?.Handle?.Handle ?? IntPtr.Zero; + return Task.Factory.StartNew(() => + { + var filters = new StringBuilder(); + foreach (var filter in dialog.Filters) + { + var extMask = string.Join(";", filter.Extensions.Select(e => "*." + e)); + filters.Append(filter.Name); + filters.Append(" ("); + filters.Append(extMask); + filters.Append(")"); + filters.Append('\0'); + filters.Append(extMask); + filters.Append('\0'); + } + if (filters.Length == 0) + filters.Append("All files\0*.*\0"); + filters.Append('\0'); + + var filterBuffer = new char[filters.Length]; + filters.CopyTo(0, filterBuffer, 0, filterBuffer.Length); + + + var buffer = new char[256]; + fixed (char* pBuffer = buffer) + fixed (char* pFilterBuffer = filterBuffer) + fixed (char* pDefExt = dialog.DefaultExtension) + fixed (char* pInitDir = dialog.InitialDirectory) + fixed (char* pTitle = dialog.Title) + { + + var ofn = new UnmanagedMethods.OpenFileName() + { + hwndOwner = hWnd, + hInstance = IntPtr.Zero, + lCustData = IntPtr.Zero, + nFilterIndex = 0, + Flags = + UnmanagedMethods.OpenFileNameFlags.OFN_EXPLORER | + UnmanagedMethods.OpenFileNameFlags.OFN_HIDEREADONLY, + nMaxCustFilter = 0, + nMaxFile = buffer.Length - 1, + nMaxFileTitle = 0, + lpTemplateName = IntPtr.Zero, + lpfnHook = IntPtr.Zero, + lpstrCustomFilter = IntPtr.Zero, + lpstrDefExt = new IntPtr(pDefExt), + lpstrFile = new IntPtr(pBuffer), + lpstrFileTitle = IntPtr.Zero, + lpstrFilter = new IntPtr(pFilterBuffer), + lpstrInitialDir = new IntPtr(pInitDir), + lpstrTitle = new IntPtr(pTitle), + + }; + ofn.lStructSize = Marshal.SizeOf(ofn); + if (dialog.AllowMultiple && dialog.Action == CommonDialogAction.OpenFile) + ofn.Flags |= UnmanagedMethods.OpenFileNameFlags.OFN_ALLOWMULTISELECT; + + if (dialog.Action == CommonDialogAction.SaveFile) + ofn.Flags |= UnmanagedMethods.OpenFileNameFlags.OFN_NOREADONLYRETURN | + UnmanagedMethods.OpenFileNameFlags.OFN_OVERWRITEPROMPT; + + var pofn = &ofn; + + var res = dialog.Action == CommonDialogAction.OpenFile + ? UnmanagedMethods.GetOpenFileName(new IntPtr(pofn)) + : UnmanagedMethods.GetSaveFileName(new IntPtr(pofn)); + if (!res) + return null; + + } + var cStart = 0; + string dir = null; + var files = new List(); + for (var c = 0; c < buffer.Length; c++) + { + if (buffer[c] == 0) + { + //Encountered double zero char + if (cStart == c) + break; + + var s = new string(buffer, cStart, c - cStart); + if (dir == null) + dir = s; + else + files.Add(s); + cStart = c + 1; + } + } + if (files.Count == 0) + return new[] {dir}; + + return files.Select(f => Path.Combine(dir, f)).ToArray(); + }); + } + } +} diff --git a/src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs b/src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs index feb033005d..8b5f0223ba 100644 --- a/src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs +++ b/src/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs @@ -6,6 +6,7 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Text; // ReSharper disable InconsistentNaming +#pragma warning disable 169 namespace Perspex.Win32.Interop { @@ -677,7 +678,14 @@ namespace Perspex.Win32.Interop [DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GlobalFree(IntPtr hMem); + [DllImport("comdlg32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetSaveFileNameW")] + public static extern bool GetSaveFileName(IntPtr lpofn); + [DllImport("comdlg32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetOpenFileNameW")] + public static extern bool GetOpenFileName(IntPtr lpofn); + + [DllImport("comdlg32.dll")] + public static extern int CommDlgExtendedError(); public enum ClipboardFormat { @@ -745,5 +753,49 @@ namespace Perspex.Win32.Interop public string lpszClassName; public IntPtr hIconSm; } + + [Flags] + public enum OpenFileNameFlags + { + + OFN_ALLOWMULTISELECT = 0x00000200, + + OFN_EXPLORER = 0x00080000, + + OFN_HIDEREADONLY = 0x00000004, + + OFN_NOREADONLYRETURN = 0x00008000, + + OFN_OVERWRITEPROMPT = 0x00000002 + + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct OpenFileName + { + public int lStructSize; + public IntPtr hwndOwner; + public IntPtr hInstance; + public IntPtr lpstrFilter; + public IntPtr lpstrCustomFilter; + public int nMaxCustFilter; + public int nFilterIndex; + public IntPtr lpstrFile; + public int nMaxFile; + public IntPtr lpstrFileTitle; + public int nMaxFileTitle; + public IntPtr lpstrInitialDir; + public IntPtr lpstrTitle; + public OpenFileNameFlags Flags; + private ushort Unused; + private ushort Unused2; + public IntPtr lpstrDefExt; + public IntPtr lCustData; + public IntPtr lpfnHook; + public IntPtr lpTemplateName; + public IntPtr reservedPtr; + public int reservedInt; + public int flagsEx; + } } } diff --git a/src/Windows/Perspex.Win32/Perspex.Win32.csproj b/src/Windows/Perspex.Win32/Perspex.Win32.csproj index ce70610233..befa17488a 100644 --- a/src/Windows/Perspex.Win32/Perspex.Win32.csproj +++ b/src/Windows/Perspex.Win32/Perspex.Win32.csproj @@ -23,6 +23,7 @@ prompt 4 bin\Debug\Perspex.Win32.XML + true pdbonly @@ -32,6 +33,7 @@ prompt 4 bin\Release\Perspex.Win32.XML + true @@ -65,6 +67,7 @@ Properties\SharedAssemblyInfo.cs + diff --git a/src/Windows/Perspex.Win32/Win32Platform.cs b/src/Windows/Perspex.Win32/Win32Platform.cs index e0fa7d9d5b..0eb0c80bd9 100644 --- a/src/Windows/Perspex.Win32/Win32Platform.cs +++ b/src/Windows/Perspex.Win32/Win32Platform.cs @@ -8,6 +8,7 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Reactive.Disposables; using System.Runtime.InteropServices; +using Perspex.Controls.Platform; using Perspex.Input; using Perspex.Platform; using Perspex.Shared.PlatformSupport; @@ -41,6 +42,7 @@ namespace Perspex.Win32 private static void InitializeInternal() { var locator = Locator.CurrentMutable; + locator.Register(() => new CommonDialogImpl(), typeof (ICommonDialogImpl)); locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); locator.Register(() => new ClipboardImpl(), typeof(IClipboard)); locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice)); From be3ab98ef4efaf27d22bb85fec4575d5794fe696 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 24 Sep 2015 17:20:47 +0300 Subject: [PATCH 09/24] Added GTK support for common dialogs --- src/Gtk/Perspex.Gtk/CommonDialogImpl.cs | 57 +++++++++++++++++++++++++ src/Gtk/Perspex.Gtk/GtkPlatform.cs | 2 + src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj | 1 + 3 files changed, 60 insertions(+) create mode 100644 src/Gtk/Perspex.Gtk/CommonDialogImpl.cs diff --git a/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs b/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs new file mode 100644 index 0000000000..ed194420c5 --- /dev/null +++ b/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Perspex.Controls; +using Perspex.Controls.Platform; +using Perspex.Platform; + +namespace Perspex.Gtk +{ + using global::Gtk; + class CommonDialogImpl : ICommonDialogImpl + { + public Task ShowAsync(CommonDialog dialog, IWindowImpl parent) + { + var tcs = new TaskCompletionSource(); + var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl) parent), + dialog.Action == CommonDialogAction.OpenFile + ? FileChooserAction.Open + : FileChooserAction.Save, + "Cancel", ResponseType.Cancel, + "Open", ResponseType.Accept) + { + SelectMultiple = dialog.AllowMultiple, + }; + foreach (var filter in dialog.Filters) + { + var ffilter = new FileFilter() + { + Name = filter.Name + " (" + string.Join(";", filter.Extensions.Select(e => "*." + e)) + ")" + }; + foreach (var ext in filter.Extensions) + ffilter.AddPattern("*." + ext); + dlg.AddFilter(ffilter); + } + dlg.SetFilename(dialog.InitialFileName); + dlg.Modal = true; + + dlg.Response += (_, args) => + { + if (args.ResponseId == ResponseType.Accept) + tcs.TrySetResult(dlg.Filenames); + dlg.Hide(); + dlg.Dispose(); + }; + + dlg.Close += delegate + { + tcs.TrySetResult(null); + dlg.Dispose(); + }; + dlg.Show(); + return tcs.Task; + } + } +} diff --git a/src/Gtk/Perspex.Gtk/GtkPlatform.cs b/src/Gtk/Perspex.Gtk/GtkPlatform.cs index f6aa72ba5b..dc37708981 100644 --- a/src/Gtk/Perspex.Gtk/GtkPlatform.cs +++ b/src/Gtk/Perspex.Gtk/GtkPlatform.cs @@ -3,6 +3,7 @@ using System; using System.Reactive.Disposables; +using Perspex.Controls.Platform; using Perspex.Input.Platform; using Perspex.Input; using Perspex.Platform; @@ -36,6 +37,7 @@ namespace Perspex.Gtk locator.Register(() => GtkKeyboardDevice.Instance, typeof(IKeyboardDevice)); locator.Register(() => s_instance, typeof(IPlatformSettings)); locator.Register(() => s_instance, typeof(IPlatformThreadingInterface)); + locator.Register(() => new CommonDialogImpl(), typeof (ICommonDialogImpl)); SharedPlatform.Register(); } diff --git a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj index 828c09d532..fa548b7882 100644 --- a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj +++ b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj @@ -50,6 +50,7 @@ + From b4db6600b3fbdc7bf3bc63a85318c9226592fc5a Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 24 Sep 2015 18:42:16 +0300 Subject: [PATCH 10/24] SetPoinerOver should fallback to the root element --- src/Perspex.Input/MouseDevice.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Perspex.Input/MouseDevice.cs b/src/Perspex.Input/MouseDevice.cs index 90c5a52666..9b0fb17ea6 100644 --- a/src/Perspex.Input/MouseDevice.cs +++ b/src/Perspex.Input/MouseDevice.cs @@ -261,7 +261,7 @@ namespace Perspex.Input control.RaiseEvent(e); } - root.PointerOverElement = elements.FirstOrDefault(); + root.PointerOverElement = elements.FirstOrDefault() ?? root; return root.PointerOverElement; } } From b2edd73f093ac779de870528090b8b79e247612f Mon Sep 17 00:00:00 2001 From: Nelson Carrillo Date: Thu, 24 Sep 2015 11:44:56 -0400 Subject: [PATCH 11/24] Update DrawingContext.cs --- src/Gtk/Perspex.Cairo/Media/DrawingContext.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs b/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs index c7bbb5aeec..03e5ab6879 100644 --- a/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs +++ b/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs @@ -287,6 +287,7 @@ namespace Perspex.Cairo.Media _context.SetSource(impl.PlatformBrush); return Disposable.Create(() => { + impl.Dispose(); _context.Restore(); }); } From 1d44aa0b8c81ca656b33610feeda0a231b614bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Karlas=CC=8C?= Date: Thu, 24 Sep 2015 14:40:03 +0200 Subject: [PATCH 12/24] Issue #158: Text input is broken on MacOS X --- src/Gtk/Perspex.Gtk/WindowImpl.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Gtk/Perspex.Gtk/WindowImpl.cs b/src/Gtk/Perspex.Gtk/WindowImpl.cs index a844a3a5dd..debfb57397 100644 --- a/src/Gtk/Perspex.Gtk/WindowImpl.cs +++ b/src/Gtk/Perspex.Gtk/WindowImpl.cs @@ -51,6 +51,12 @@ namespace Perspex.Gtk _imContext.Commit += ImContext_Commit; } + protected override void OnRealized () + { + base.OnRealized (); + _imContext.ClientWindow = this.GdkWindow; + } + public Size ClientSize { get; From 0cb2158e308d052805f85fd61fcb2319b1933b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Karlas=CC=8C?= Date: Thu, 24 Sep 2015 14:41:01 +0200 Subject: [PATCH 13/24] [Gtk] Fix letters mapping when not holding Shift --- .../Perspex.Gtk/Input/GtkKeyboardDevice.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs b/src/Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs index 462fdd1fc6..3ccec97656 100644 --- a/src/Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs +++ b/src/Gtk/Perspex.Gtk/Input/GtkKeyboardDevice.cs @@ -83,6 +83,32 @@ namespace Perspex.Gtk { Gdk.Key.X, Key.X }, { Gdk.Key.Y, Key.Y }, { Gdk.Key.Z, Key.Z }, + { Gdk.Key.a, Key.A }, + { Gdk.Key.b, Key.B }, + { Gdk.Key.c, Key.C }, + { Gdk.Key.d, Key.D }, + { Gdk.Key.e, Key.E }, + { Gdk.Key.f, Key.F }, + { Gdk.Key.g, Key.G }, + { Gdk.Key.h, Key.H }, + { Gdk.Key.i, Key.I }, + { Gdk.Key.j, Key.J }, + { Gdk.Key.k, Key.K }, + { Gdk.Key.l, Key.L }, + { Gdk.Key.m, Key.M }, + { Gdk.Key.n, Key.N }, + { Gdk.Key.o, Key.O }, + { Gdk.Key.p, Key.P }, + { Gdk.Key.q, Key.Q }, + { Gdk.Key.r, Key.R }, + { Gdk.Key.s, Key.S }, + { Gdk.Key.t, Key.T }, + { Gdk.Key.u, Key.U }, + { Gdk.Key.v, Key.V }, + { Gdk.Key.w, Key.W }, + { Gdk.Key.x, Key.X }, + { Gdk.Key.y, Key.Y }, + { Gdk.Key.z, Key.Z }, //{ Gdk.Key.?, Key.LWin } //{ Gdk.Key.?, Key.RWin } //{ Gdk.Key.?, Key.Apps } From 18da630e6fcd520514535c178e6eb1f601f8110a Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 24 Sep 2015 19:45:09 +0300 Subject: [PATCH 14/24] Introduced common dialog class hierarchy --- src/Gtk/Perspex.Gtk/CommonDialogImpl.cs | 6 ++-- src/Perspex.Controls/CommonDialog.cs | 33 ++++++++++++------- .../Platform/ICommonDialogImpl.cs | 2 +- src/Windows/Perspex.Win32/CommonDialogImpl.cs | 12 +++---- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs b/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs index ed194420c5..27da2af14d 100644 --- a/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs +++ b/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs @@ -12,17 +12,17 @@ namespace Perspex.Gtk using global::Gtk; class CommonDialogImpl : ICommonDialogImpl { - public Task ShowAsync(CommonDialog dialog, IWindowImpl parent) + public Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) { var tcs = new TaskCompletionSource(); var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl) parent), - dialog.Action == CommonDialogAction.OpenFile + dialog is OpenFileDialog ? FileChooserAction.Open : FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept) { - SelectMultiple = dialog.AllowMultiple, + SelectMultiple = (dialog as OpenFileDialog)?.AllowMultiple ?? false, }; foreach (var filter in dialog.Filters) { diff --git a/src/Perspex.Controls/CommonDialog.cs b/src/Perspex.Controls/CommonDialog.cs index cc81ee0122..67f5882907 100644 --- a/src/Perspex.Controls/CommonDialog.cs +++ b/src/Perspex.Controls/CommonDialog.cs @@ -1,32 +1,43 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Perspex.Controls.Platform; using Splat; namespace Perspex.Controls { - public class CommonDialog + public abstract class FileDialog : CommonDialog { - public string Title { get; set; } - public List Filters { get; set; } = new List(); + public List Filters { get; set; } = new List(); public string InitialFileName { get; set; } public string InitialDirectory { get; set; } - public bool AllowMultiple { get; set; } + } + + + public class SaveFileDialog : FileDialog + { public string DefaultExtension { get; set; } - public CommonDialogAction Action { get; set; } + public async Task ShowAsync(Window window = null) + => + ((await Locator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl)) ?? + new string[0]).FirstOrDefault(); + } - public Task ShowAsync(Window window = null) - => Locator.Current.GetService().ShowAsync(this, window?.PlatformImpl); + public class OpenFileDialog : FileDialog + { + public bool AllowMultiple { get; set; } + + public Task ShowAsync(Window window = null) + => Locator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl); } - public enum CommonDialogAction + public abstract class CommonDialog { - OpenFile, - SaveFile + public string Title { get; set; } } - public class CommonDialogFilter + public class FileDialogFilter { public string Name { get; set; } public List Extensions { get; set; } = new List(); diff --git a/src/Perspex.Controls/Platform/ICommonDialogImpl.cs b/src/Perspex.Controls/Platform/ICommonDialogImpl.cs index 89f817a675..ad7ebf1550 100644 --- a/src/Perspex.Controls/Platform/ICommonDialogImpl.cs +++ b/src/Perspex.Controls/Platform/ICommonDialogImpl.cs @@ -9,6 +9,6 @@ namespace Perspex.Controls.Platform { public interface ICommonDialogImpl { - Task ShowAsync(CommonDialog dialog, IWindowImpl parent); + Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent); } } diff --git a/src/Windows/Perspex.Win32/CommonDialogImpl.cs b/src/Windows/Perspex.Win32/CommonDialogImpl.cs index d0cce7be95..09ccd2bd9d 100644 --- a/src/Windows/Perspex.Win32/CommonDialogImpl.cs +++ b/src/Windows/Perspex.Win32/CommonDialogImpl.cs @@ -15,7 +15,7 @@ namespace Perspex.Win32 { class CommonDialogImpl : ICommonDialogImpl { - public unsafe Task ShowAsync(CommonDialog dialog, IWindowImpl parent) + public unsafe Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) { var hWnd = parent?.Handle?.Handle ?? IntPtr.Zero; return Task.Factory.StartNew(() => @@ -39,11 +39,11 @@ namespace Perspex.Win32 var filterBuffer = new char[filters.Length]; filters.CopyTo(0, filterBuffer, 0, filterBuffer.Length); - + var defExt = (dialog as SaveFileDialog)?.DefaultExtension; var buffer = new char[256]; fixed (char* pBuffer = buffer) fixed (char* pFilterBuffer = filterBuffer) - fixed (char* pDefExt = dialog.DefaultExtension) + fixed (char* pDefExt = defExt) fixed (char* pInitDir = dialog.InitialDirectory) fixed (char* pTitle = dialog.Title) { @@ -72,16 +72,16 @@ namespace Perspex.Win32 }; ofn.lStructSize = Marshal.SizeOf(ofn); - if (dialog.AllowMultiple && dialog.Action == CommonDialogAction.OpenFile) + if ((dialog as OpenFileDialog)?.AllowMultiple == true) ofn.Flags |= UnmanagedMethods.OpenFileNameFlags.OFN_ALLOWMULTISELECT; - if (dialog.Action == CommonDialogAction.SaveFile) + if (dialog is SaveFileDialog) ofn.Flags |= UnmanagedMethods.OpenFileNameFlags.OFN_NOREADONLYRETURN | UnmanagedMethods.OpenFileNameFlags.OFN_OVERWRITEPROMPT; var pofn = &ofn; - var res = dialog.Action == CommonDialogAction.OpenFile + var res = dialog is OpenFileDialog ? UnmanagedMethods.GetOpenFileName(new IntPtr(pofn)) : UnmanagedMethods.GetSaveFileName(new IntPtr(pofn)); if (!res) From 9e16d0f1634c503221afbc27a4f18b49acda69e9 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 24 Sep 2015 19:49:08 +0300 Subject: [PATCH 15/24] comdlg rename --- src/Gtk/Perspex.Gtk/GtkPlatform.cs | 2 +- src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj | 2 +- .../{CommonDialogImpl.cs => SystemDialogImpl.cs} | 2 +- src/Perspex.Controls/Perspex.Controls.csproj | 4 ++-- .../{ICommonDialogImpl.cs => ISystemDialogImpl.cs} | 2 +- src/Perspex.Controls/{CommonDialog.cs => SystemDialog.cs} | 8 ++++---- src/Windows/Perspex.Win32/Perspex.Win32.csproj | 2 +- .../{CommonDialogImpl.cs => SystemDialogImpl.cs} | 2 +- src/Windows/Perspex.Win32/Win32Platform.cs | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) rename src/Gtk/Perspex.Gtk/{CommonDialogImpl.cs => SystemDialogImpl.cs} (97%) rename src/Perspex.Controls/Platform/{ICommonDialogImpl.cs => ISystemDialogImpl.cs} (87%) rename src/Perspex.Controls/{CommonDialog.cs => SystemDialog.cs} (83%) rename src/Windows/Perspex.Win32/{CommonDialogImpl.cs => SystemDialogImpl.cs} (98%) diff --git a/src/Gtk/Perspex.Gtk/GtkPlatform.cs b/src/Gtk/Perspex.Gtk/GtkPlatform.cs index dc37708981..543cba012b 100644 --- a/src/Gtk/Perspex.Gtk/GtkPlatform.cs +++ b/src/Gtk/Perspex.Gtk/GtkPlatform.cs @@ -37,7 +37,7 @@ namespace Perspex.Gtk locator.Register(() => GtkKeyboardDevice.Instance, typeof(IKeyboardDevice)); locator.Register(() => s_instance, typeof(IPlatformSettings)); locator.Register(() => s_instance, typeof(IPlatformThreadingInterface)); - locator.Register(() => new CommonDialogImpl(), typeof (ICommonDialogImpl)); + locator.Register(() => new SystemDialogImpl(), typeof (ISystemDialogImpl)); SharedPlatform.Register(); } diff --git a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj index fa548b7882..20b96380b4 100644 --- a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj +++ b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj @@ -50,7 +50,7 @@ - + diff --git a/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs b/src/Gtk/Perspex.Gtk/SystemDialogImpl.cs similarity index 97% rename from src/Gtk/Perspex.Gtk/CommonDialogImpl.cs rename to src/Gtk/Perspex.Gtk/SystemDialogImpl.cs index 27da2af14d..869bd2eb70 100644 --- a/src/Gtk/Perspex.Gtk/CommonDialogImpl.cs +++ b/src/Gtk/Perspex.Gtk/SystemDialogImpl.cs @@ -10,7 +10,7 @@ using Perspex.Platform; namespace Perspex.Gtk { using global::Gtk; - class CommonDialogImpl : ICommonDialogImpl + class SystemDialogImpl : ISystemDialogImpl { public Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) { diff --git a/src/Perspex.Controls/Perspex.Controls.csproj b/src/Perspex.Controls/Perspex.Controls.csproj index 117a683330..f4d1332994 100644 --- a/src/Perspex.Controls/Perspex.Controls.csproj +++ b/src/Perspex.Controls/Perspex.Controls.csproj @@ -41,7 +41,7 @@ Properties\SharedAssemblyInfo.cs - + @@ -65,7 +65,7 @@ - + diff --git a/src/Perspex.Controls/Platform/ICommonDialogImpl.cs b/src/Perspex.Controls/Platform/ISystemDialogImpl.cs similarity index 87% rename from src/Perspex.Controls/Platform/ICommonDialogImpl.cs rename to src/Perspex.Controls/Platform/ISystemDialogImpl.cs index ad7ebf1550..4e8f51427e 100644 --- a/src/Perspex.Controls/Platform/ICommonDialogImpl.cs +++ b/src/Perspex.Controls/Platform/ISystemDialogImpl.cs @@ -7,7 +7,7 @@ using Perspex.Platform; namespace Perspex.Controls.Platform { - public interface ICommonDialogImpl + public interface ISystemDialogImpl { Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent); } diff --git a/src/Perspex.Controls/CommonDialog.cs b/src/Perspex.Controls/SystemDialog.cs similarity index 83% rename from src/Perspex.Controls/CommonDialog.cs rename to src/Perspex.Controls/SystemDialog.cs index 67f5882907..ce424f31fa 100644 --- a/src/Perspex.Controls/CommonDialog.cs +++ b/src/Perspex.Controls/SystemDialog.cs @@ -6,7 +6,7 @@ using Splat; namespace Perspex.Controls { - public abstract class FileDialog : CommonDialog + public abstract class FileDialog : SystemDialog { public List Filters { get; set; } = new List(); public string InitialFileName { get; set; } @@ -20,7 +20,7 @@ namespace Perspex.Controls public async Task ShowAsync(Window window = null) => - ((await Locator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl)) ?? + ((await Locator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl)) ?? new string[0]).FirstOrDefault(); } @@ -29,10 +29,10 @@ namespace Perspex.Controls public bool AllowMultiple { get; set; } public Task ShowAsync(Window window = null) - => Locator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl); + => Locator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl); } - public abstract class CommonDialog + public abstract class SystemDialog { public string Title { get; set; } } diff --git a/src/Windows/Perspex.Win32/Perspex.Win32.csproj b/src/Windows/Perspex.Win32/Perspex.Win32.csproj index befa17488a..8c84a7a307 100644 --- a/src/Windows/Perspex.Win32/Perspex.Win32.csproj +++ b/src/Windows/Perspex.Win32/Perspex.Win32.csproj @@ -67,7 +67,7 @@ Properties\SharedAssemblyInfo.cs - + diff --git a/src/Windows/Perspex.Win32/CommonDialogImpl.cs b/src/Windows/Perspex.Win32/SystemDialogImpl.cs similarity index 98% rename from src/Windows/Perspex.Win32/CommonDialogImpl.cs rename to src/Windows/Perspex.Win32/SystemDialogImpl.cs index 09ccd2bd9d..71b0b58e87 100644 --- a/src/Windows/Perspex.Win32/CommonDialogImpl.cs +++ b/src/Windows/Perspex.Win32/SystemDialogImpl.cs @@ -13,7 +13,7 @@ using Perspex.Win32.Interop; namespace Perspex.Win32 { - class CommonDialogImpl : ICommonDialogImpl + class SystemDialogImpl : ISystemDialogImpl { public unsafe Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) { diff --git a/src/Windows/Perspex.Win32/Win32Platform.cs b/src/Windows/Perspex.Win32/Win32Platform.cs index 0eb0c80bd9..34a0cda13a 100644 --- a/src/Windows/Perspex.Win32/Win32Platform.cs +++ b/src/Windows/Perspex.Win32/Win32Platform.cs @@ -42,7 +42,7 @@ namespace Perspex.Win32 private static void InitializeInternal() { var locator = Locator.CurrentMutable; - locator.Register(() => new CommonDialogImpl(), typeof (ICommonDialogImpl)); + locator.Register(() => new SystemDialogImpl(), typeof (ISystemDialogImpl)); locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); locator.Register(() => new ClipboardImpl(), typeof(IClipboard)); locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice)); From 6ba8592c0d6c23891edf9ac5b6deff2b48bc7e6e Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 24 Sep 2015 20:16:00 +0300 Subject: [PATCH 16/24] Added MonoDevelopProperties to solution --- Perspex.sln | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) diff --git a/Perspex.sln b/Perspex.sln index 22b196d2c8..28d399b57b 100644 --- a/Perspex.sln +++ b/Perspex.sln @@ -260,5 +260,203 @@ Global {54F237D5-A70A-4752-9656-0C70B1A7B047} = {B9894058-278A-46B5-B6ED-AD613FCC03B3} {FB05AC90-89BA-4F2F-A924-F37875FB547C} = {B9894058-278A-46B5-B6ED-AD613FCC03B3} {E4D9629C-F168-4224-3F51-A5E482FFBC42} = {A689DEF5-D50F-4975-8B72-124C9EB54066} + GlobalSection(MonoDevelopProperties) = preSolution + Policies = $0 + $0.DotNetNamingPolicy = $1 + $1.DirectoryNamespaceAssociation = None + $1.ResourceNamePolicy = FileFormatDefault + $0.TextStylePolicy = $2 + $2.inheritsSet = VisualStudio + $2.inheritsScope = text/plain + $2.scope = text/x-csharp + $0.CSharpFormattingPolicy = $3 + $3.IndentSwitchBody = True + $3.IndentBlocksInsideExpressions = True + $3.AnonymousMethodBraceStyle = NextLine + $3.PropertyBraceStyle = NextLine + $3.PropertyGetBraceStyle = NextLine + $3.PropertySetBraceStyle = NextLine + $3.EventBraceStyle = NextLine + $3.EventAddBraceStyle = NextLine + $3.EventRemoveBraceStyle = NextLine + $3.StatementBraceStyle = NextLine + $3.ElseNewLinePlacement = NewLine + $3.CatchNewLinePlacement = NewLine + $3.FinallyNewLinePlacement = NewLine + $3.WhileNewLinePlacement = DoNotCare + $3.ArrayInitializerWrapping = DoNotChange + $3.ArrayInitializerBraceStyle = NextLine + $3.BeforeMethodDeclarationParentheses = False + $3.BeforeMethodCallParentheses = False + $3.BeforeConstructorDeclarationParentheses = False + $3.NewLineBeforeConstructorInitializerColon = NewLine + $3.NewLineAfterConstructorInitializerColon = SameLine + $3.BeforeDelegateDeclarationParentheses = False + $3.NewParentheses = False + $3.SpacesBeforeBrackets = False + $3.inheritsSet = Mono + $3.inheritsScope = text/x-csharp + $3.scope = text/x-csharp + $0.TextStylePolicy = $4 + $4.inheritsSet = VisualStudio + $4.inheritsScope = text/plain + $4.scope = text/plain + $0.TextStylePolicy = $5 + $5.FileWidth = 120 + $5.inheritsSet = VisualStudio + $5.inheritsScope = text/plain + $5.scope = application/config+xml + $0.XmlFormattingPolicy = $6 + $6.inheritsSet = null + $6.scope = application/config+xml + $0.TextStylePolicy = $7 + $7.FileWidth = 120 + $7.inheritsSet = VisualStudio + $7.inheritsScope = text/plain + $7.scope = application/xml + $0.XmlFormattingPolicy = $8 + $8.inheritsSet = Mono + $8.inheritsScope = application/xml + $8.scope = application/xml + $0.TextStylePolicy = $9 + $9.FileWidth = 120 + $9.inheritsSet = VisualStudio + $9.inheritsScope = text/plain + $9.scope = text/html + $0.StandardHeader = $10 + $10.Text = @// Copyright (c) The Perspex Project. All rights reserved.\n// Licensed under the MIT license. See licence.md file in the project root for full license information.\n + $10.IncludeInNewFiles = True + $0.NameConventionPolicy = $11 + $11.Rules = $12 + $12.NamingRule = $13 + $13.Name = Namespaces + $13.AffectedEntity = Namespace + $13.VisibilityMask = VisibilityMask + $13.NamingStyle = PascalCase + $13.IncludeInstanceMembers = True + $13.IncludeStaticEntities = True + $12.NamingRule = $14 + $14.Name = Types + $14.AffectedEntity = Class, Struct, Enum, Delegate + $14.VisibilityMask = Public + $14.NamingStyle = PascalCase + $14.IncludeInstanceMembers = True + $14.IncludeStaticEntities = True + $12.NamingRule = $15 + $15.Name = Interfaces + $15.RequiredPrefixes = $16 + $16.String = I + $15.AffectedEntity = Interface + $15.VisibilityMask = Public + $15.NamingStyle = PascalCase + $15.IncludeInstanceMembers = True + $15.IncludeStaticEntities = True + $12.NamingRule = $17 + $17.Name = Attributes + $17.RequiredSuffixes = $18 + $18.String = Attribute + $17.AffectedEntity = CustomAttributes + $17.VisibilityMask = Public + $17.NamingStyle = PascalCase + $17.IncludeInstanceMembers = True + $17.IncludeStaticEntities = True + $12.NamingRule = $19 + $19.Name = Event Arguments + $19.RequiredSuffixes = $20 + $20.String = EventArgs + $19.AffectedEntity = CustomEventArgs + $19.VisibilityMask = Public + $19.NamingStyle = PascalCase + $19.IncludeInstanceMembers = True + $19.IncludeStaticEntities = True + $12.NamingRule = $21 + $21.Name = Exceptions + $21.RequiredSuffixes = $22 + $22.String = Exception + $21.AffectedEntity = CustomExceptions + $21.VisibilityMask = VisibilityMask + $21.NamingStyle = PascalCase + $21.IncludeInstanceMembers = True + $21.IncludeStaticEntities = True + $12.NamingRule = $23 + $23.Name = Methods + $23.AffectedEntity = Methods + $23.VisibilityMask = Protected, Public + $23.NamingStyle = PascalCase + $23.IncludeInstanceMembers = True + $23.IncludeStaticEntities = True + $12.NamingRule = $24 + $24.Name = Static Readonly Fields + $24.AffectedEntity = ReadonlyField + $24.VisibilityMask = Protected, Public + $24.NamingStyle = PascalCase + $24.IncludeInstanceMembers = False + $24.IncludeStaticEntities = True + $12.NamingRule = $25 + $25.Name = Fields + $25.AffectedEntity = Field + $25.VisibilityMask = Protected, Public + $25.NamingStyle = PascalCase + $25.IncludeInstanceMembers = True + $25.IncludeStaticEntities = True + $12.NamingRule = $26 + $26.Name = ReadOnly Fields + $26.AffectedEntity = ReadonlyField + $26.VisibilityMask = Protected, Public + $26.NamingStyle = PascalCase + $26.IncludeInstanceMembers = True + $26.IncludeStaticEntities = False + $12.NamingRule = $27 + $27.Name = Constant Fields + $27.AffectedEntity = ConstantField + $27.VisibilityMask = Protected, Public + $27.NamingStyle = PascalCase + $27.IncludeInstanceMembers = True + $27.IncludeStaticEntities = True + $12.NamingRule = $28 + $28.Name = Properties + $28.AffectedEntity = Property + $28.VisibilityMask = Protected, Public + $28.NamingStyle = PascalCase + $28.IncludeInstanceMembers = True + $28.IncludeStaticEntities = True + $12.NamingRule = $29 + $29.Name = Events + $29.AffectedEntity = Event + $29.VisibilityMask = Protected, Public + $29.NamingStyle = PascalCase + $29.IncludeInstanceMembers = True + $29.IncludeStaticEntities = True + $12.NamingRule = $30 + $30.Name = Enum Members + $30.AffectedEntity = EnumMember + $30.VisibilityMask = VisibilityMask + $30.NamingStyle = PascalCase + $30.IncludeInstanceMembers = True + $30.IncludeStaticEntities = True + $12.NamingRule = $31 + $31.Name = Parameters + $31.AffectedEntity = Parameter + $31.VisibilityMask = VisibilityMask + $31.NamingStyle = CamelCase + $31.IncludeInstanceMembers = True + $31.IncludeStaticEntities = True + $12.NamingRule = $32 + $32.Name = Type Parameters + $32.RequiredPrefixes = $33 + $33.String = T + $32.AffectedEntity = TypeParameter + $32.VisibilityMask = VisibilityMask + $32.NamingStyle = PascalCase + $32.IncludeInstanceMembers = True + $32.IncludeStaticEntities = True + EndGlobalSection + GlobalSection(SharedMSBuildProjectFiles) = preSolution + src\Shared\PlatformSupport\PlatformSupport.projitems*{e4d9629c-f168-4224-3f51-a5e482ffbc42}*SharedItemsImports = 13 + src\Shared\PlatformSupport\PlatformSupport.projitems*{54f237d5-a70a-4752-9656-0c70b1a7b047}*SharedItemsImports = 4 + src\Shared\PlatformSupport\PlatformSupport.projitems*{811a76cf-1cf6-440f-963b-bbe31bd72a82}*SharedItemsImports = 4 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal From 0431dba574fe559ff748bcac22063d0b0f8fdfd4 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 24 Sep 2015 21:17:49 +0300 Subject: [PATCH 17/24] Revert "Added MonoDevelopProperties to solution" This reverts commit 6ba8592c0d6c23891edf9ac5b6deff2b48bc7e6e. --- Perspex.sln | 198 ---------------------------------------------------- 1 file changed, 198 deletions(-) diff --git a/Perspex.sln b/Perspex.sln index 28d399b57b..22b196d2c8 100644 --- a/Perspex.sln +++ b/Perspex.sln @@ -260,203 +260,5 @@ Global {54F237D5-A70A-4752-9656-0C70B1A7B047} = {B9894058-278A-46B5-B6ED-AD613FCC03B3} {FB05AC90-89BA-4F2F-A924-F37875FB547C} = {B9894058-278A-46B5-B6ED-AD613FCC03B3} {E4D9629C-F168-4224-3F51-A5E482FFBC42} = {A689DEF5-D50F-4975-8B72-124C9EB54066} - GlobalSection(MonoDevelopProperties) = preSolution - Policies = $0 - $0.DotNetNamingPolicy = $1 - $1.DirectoryNamespaceAssociation = None - $1.ResourceNamePolicy = FileFormatDefault - $0.TextStylePolicy = $2 - $2.inheritsSet = VisualStudio - $2.inheritsScope = text/plain - $2.scope = text/x-csharp - $0.CSharpFormattingPolicy = $3 - $3.IndentSwitchBody = True - $3.IndentBlocksInsideExpressions = True - $3.AnonymousMethodBraceStyle = NextLine - $3.PropertyBraceStyle = NextLine - $3.PropertyGetBraceStyle = NextLine - $3.PropertySetBraceStyle = NextLine - $3.EventBraceStyle = NextLine - $3.EventAddBraceStyle = NextLine - $3.EventRemoveBraceStyle = NextLine - $3.StatementBraceStyle = NextLine - $3.ElseNewLinePlacement = NewLine - $3.CatchNewLinePlacement = NewLine - $3.FinallyNewLinePlacement = NewLine - $3.WhileNewLinePlacement = DoNotCare - $3.ArrayInitializerWrapping = DoNotChange - $3.ArrayInitializerBraceStyle = NextLine - $3.BeforeMethodDeclarationParentheses = False - $3.BeforeMethodCallParentheses = False - $3.BeforeConstructorDeclarationParentheses = False - $3.NewLineBeforeConstructorInitializerColon = NewLine - $3.NewLineAfterConstructorInitializerColon = SameLine - $3.BeforeDelegateDeclarationParentheses = False - $3.NewParentheses = False - $3.SpacesBeforeBrackets = False - $3.inheritsSet = Mono - $3.inheritsScope = text/x-csharp - $3.scope = text/x-csharp - $0.TextStylePolicy = $4 - $4.inheritsSet = VisualStudio - $4.inheritsScope = text/plain - $4.scope = text/plain - $0.TextStylePolicy = $5 - $5.FileWidth = 120 - $5.inheritsSet = VisualStudio - $5.inheritsScope = text/plain - $5.scope = application/config+xml - $0.XmlFormattingPolicy = $6 - $6.inheritsSet = null - $6.scope = application/config+xml - $0.TextStylePolicy = $7 - $7.FileWidth = 120 - $7.inheritsSet = VisualStudio - $7.inheritsScope = text/plain - $7.scope = application/xml - $0.XmlFormattingPolicy = $8 - $8.inheritsSet = Mono - $8.inheritsScope = application/xml - $8.scope = application/xml - $0.TextStylePolicy = $9 - $9.FileWidth = 120 - $9.inheritsSet = VisualStudio - $9.inheritsScope = text/plain - $9.scope = text/html - $0.StandardHeader = $10 - $10.Text = @// Copyright (c) The Perspex Project. All rights reserved.\n// Licensed under the MIT license. See licence.md file in the project root for full license information.\n - $10.IncludeInNewFiles = True - $0.NameConventionPolicy = $11 - $11.Rules = $12 - $12.NamingRule = $13 - $13.Name = Namespaces - $13.AffectedEntity = Namespace - $13.VisibilityMask = VisibilityMask - $13.NamingStyle = PascalCase - $13.IncludeInstanceMembers = True - $13.IncludeStaticEntities = True - $12.NamingRule = $14 - $14.Name = Types - $14.AffectedEntity = Class, Struct, Enum, Delegate - $14.VisibilityMask = Public - $14.NamingStyle = PascalCase - $14.IncludeInstanceMembers = True - $14.IncludeStaticEntities = True - $12.NamingRule = $15 - $15.Name = Interfaces - $15.RequiredPrefixes = $16 - $16.String = I - $15.AffectedEntity = Interface - $15.VisibilityMask = Public - $15.NamingStyle = PascalCase - $15.IncludeInstanceMembers = True - $15.IncludeStaticEntities = True - $12.NamingRule = $17 - $17.Name = Attributes - $17.RequiredSuffixes = $18 - $18.String = Attribute - $17.AffectedEntity = CustomAttributes - $17.VisibilityMask = Public - $17.NamingStyle = PascalCase - $17.IncludeInstanceMembers = True - $17.IncludeStaticEntities = True - $12.NamingRule = $19 - $19.Name = Event Arguments - $19.RequiredSuffixes = $20 - $20.String = EventArgs - $19.AffectedEntity = CustomEventArgs - $19.VisibilityMask = Public - $19.NamingStyle = PascalCase - $19.IncludeInstanceMembers = True - $19.IncludeStaticEntities = True - $12.NamingRule = $21 - $21.Name = Exceptions - $21.RequiredSuffixes = $22 - $22.String = Exception - $21.AffectedEntity = CustomExceptions - $21.VisibilityMask = VisibilityMask - $21.NamingStyle = PascalCase - $21.IncludeInstanceMembers = True - $21.IncludeStaticEntities = True - $12.NamingRule = $23 - $23.Name = Methods - $23.AffectedEntity = Methods - $23.VisibilityMask = Protected, Public - $23.NamingStyle = PascalCase - $23.IncludeInstanceMembers = True - $23.IncludeStaticEntities = True - $12.NamingRule = $24 - $24.Name = Static Readonly Fields - $24.AffectedEntity = ReadonlyField - $24.VisibilityMask = Protected, Public - $24.NamingStyle = PascalCase - $24.IncludeInstanceMembers = False - $24.IncludeStaticEntities = True - $12.NamingRule = $25 - $25.Name = Fields - $25.AffectedEntity = Field - $25.VisibilityMask = Protected, Public - $25.NamingStyle = PascalCase - $25.IncludeInstanceMembers = True - $25.IncludeStaticEntities = True - $12.NamingRule = $26 - $26.Name = ReadOnly Fields - $26.AffectedEntity = ReadonlyField - $26.VisibilityMask = Protected, Public - $26.NamingStyle = PascalCase - $26.IncludeInstanceMembers = True - $26.IncludeStaticEntities = False - $12.NamingRule = $27 - $27.Name = Constant Fields - $27.AffectedEntity = ConstantField - $27.VisibilityMask = Protected, Public - $27.NamingStyle = PascalCase - $27.IncludeInstanceMembers = True - $27.IncludeStaticEntities = True - $12.NamingRule = $28 - $28.Name = Properties - $28.AffectedEntity = Property - $28.VisibilityMask = Protected, Public - $28.NamingStyle = PascalCase - $28.IncludeInstanceMembers = True - $28.IncludeStaticEntities = True - $12.NamingRule = $29 - $29.Name = Events - $29.AffectedEntity = Event - $29.VisibilityMask = Protected, Public - $29.NamingStyle = PascalCase - $29.IncludeInstanceMembers = True - $29.IncludeStaticEntities = True - $12.NamingRule = $30 - $30.Name = Enum Members - $30.AffectedEntity = EnumMember - $30.VisibilityMask = VisibilityMask - $30.NamingStyle = PascalCase - $30.IncludeInstanceMembers = True - $30.IncludeStaticEntities = True - $12.NamingRule = $31 - $31.Name = Parameters - $31.AffectedEntity = Parameter - $31.VisibilityMask = VisibilityMask - $31.NamingStyle = CamelCase - $31.IncludeInstanceMembers = True - $31.IncludeStaticEntities = True - $12.NamingRule = $32 - $32.Name = Type Parameters - $32.RequiredPrefixes = $33 - $33.String = T - $32.AffectedEntity = TypeParameter - $32.VisibilityMask = VisibilityMask - $32.NamingStyle = PascalCase - $32.IncludeInstanceMembers = True - $32.IncludeStaticEntities = True - EndGlobalSection - GlobalSection(SharedMSBuildProjectFiles) = preSolution - src\Shared\PlatformSupport\PlatformSupport.projitems*{e4d9629c-f168-4224-3f51-a5e482ffbc42}*SharedItemsImports = 13 - src\Shared\PlatformSupport\PlatformSupport.projitems*{54f237d5-a70a-4752-9656-0c70b1a7b047}*SharedItemsImports = 4 - src\Shared\PlatformSupport\PlatformSupport.projitems*{811a76cf-1cf6-440f-963b-bbe31bd72a82}*SharedItemsImports = 4 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE EndGlobalSection EndGlobal From 2b55af700f575f49a524847ceab9ea0dbf512abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Karlas=CC=8C?= Date: Thu, 24 Sep 2015 21:24:29 +0200 Subject: [PATCH 18/24] [Cairo] Fixed wrong index calculation of text in case text contains Unicode chars --- .../Perspex.Cairo/Media/FormattedTextImpl.cs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs index 0cbfc50097..45987973b5 100644 --- a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs +++ b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using Perspex.Media; using Perspex.Platform; using Splat; @@ -13,6 +14,7 @@ namespace Perspex.Cairo.Media public class FormattedTextImpl : IFormattedTextImpl { private Size _size; + private string _text; public FormattedTextImpl( Pango.Context context, @@ -26,6 +28,7 @@ namespace Perspex.Cairo.Media Contract.Requires(context != null); Layout = new Pango.Layout(context); + _text = text; Layout.SetText(text); Layout.FontDescription = new Pango.FontDescription { @@ -49,7 +52,7 @@ namespace Perspex.Cairo.Media set { _size = value; - Layout.Width = double.IsPositiveInfinity(value.Width) ? + Layout.Width = double.IsPositiveInfinity(value.Width) ? -1 : Pango.Units.FromDouble(value.Width); } } @@ -80,6 +83,8 @@ namespace Perspex.Cairo.Media out textPosition, out trailing); + textPosition = PangoIndexToTextIndex(textPosition); + return new TextHitTestResult { IsInside = isInside, @@ -88,9 +93,19 @@ namespace Perspex.Cairo.Media }; } + int PangoIndexToTextIndex(int pangoIndex) + { + return Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(_text), 0, Math.Min(pangoIndex, _text.Length)).Length; + } + public Rect HitTestTextPosition(int index) { - return Layout.IndexToPos(index).ToPerspex(); + return Layout.IndexToPos(TextIndexToPangoIndex(index)).ToPerspex(); + } + + int TextIndexToPangoIndex(int textIndex) + { + return Encoding.UTF8.GetByteCount(textIndex < _text.Length ? _text.Remove(textIndex) : _text); } public IEnumerable HitTestTextRange(int index, int length) @@ -124,8 +139,8 @@ namespace Perspex.Cairo.Media color.Parse(string.Format("#{0}", scb.Color.ToString().Substring(3))); var brushAttr = new Pango.AttrForeground(color); - brushAttr.StartIndex = (uint)startIndex; - brushAttr.EndIndex = (uint)(startIndex + count); + brushAttr.StartIndex = (uint)TextIndexToPangoIndex(startIndex); + brushAttr.EndIndex = (uint)TextIndexToPangoIndex(startIndex + count); Layout.Attributes.Insert(brushAttr); } From 323c1a49c1aeb1ccd0511f55e1575d29ef9cbf93 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 24 Sep 2015 23:50:11 +0300 Subject: [PATCH 19/24] Removed core dependency on Splat --- samples/TestApplication/App.config | 4 + .../TestApplication/TestApplication.csproj | 3 - samples/TestApplication/packages.config | 15 ++- .../XamlTestApplication.csproj | 7 +- samples/XamlTestApplication/packages.config | 2 +- src/Gtk/Perspex.Cairo/CairoPlatform.cs | 7 +- .../Perspex.Cairo/Media/FormattedTextImpl.cs | 1 - .../Perspex.Cairo/Media/StreamGeometryImpl.cs | 1 - src/Gtk/Perspex.Cairo/Perspex.Cairo.csproj | 3 - src/Gtk/Perspex.Cairo/packages.config | 7 +- src/Gtk/Perspex.Gtk/GtkPlatform.cs | 20 +-- src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj | 3 - src/Gtk/Perspex.Gtk/packages.config | 7 +- .../Context/PerspexWiringContext.cs | 3 +- .../Perspex.Markup.Xaml.csproj | 3 - .../Perspex.Markup.Xaml/PerspexXamlLoader.cs | 5 +- .../Perspex.Markup.Xaml/packages.config | 1 - src/Perspex.Application/Application.cs | 22 ++-- .../Perspex.Application.csproj | 3 - src/Perspex.Application/packages.config | 1 - src/Perspex.Base/Perspex.Base.csproj | 4 +- src/Perspex.Base/PerspexLocator.cs | 119 ++++++++++++++++++ src/Perspex.Base/Threading/DispatcherTimer.cs | 5 +- src/Perspex.Base/Threading/MainLoop.cs | 3 +- src/Perspex.Base/packages.config | 1 - src/Perspex.Controls/Control.cs | 3 +- src/Perspex.Controls/MenuItem.cs | 18 +-- src/Perspex.Controls/Perspex.Controls.csproj | 3 - src/Perspex.Controls/Primitives/Popup.cs | 3 +- src/Perspex.Controls/Primitives/PopupRoot.cs | 5 +- src/Perspex.Controls/SystemDialog.cs | 5 +- .../Templates/DataTemplateExtensions.cs | 3 +- src/Perspex.Controls/TextBox.cs | 5 +- src/Perspex.Controls/TopLevel.cs | 11 +- src/Perspex.Controls/Window.cs | 3 +- src/Perspex.Controls/packages.config | 1 - .../Adapters/PerspexAdapter.cs | 3 +- .../Perspex.HtmlRenderer.csproj | 3 - src/Perspex.HtmlRenderer/packages.config | 1 - src/Perspex.Input/Cursors.cs | 3 +- src/Perspex.Input/FocusManager.cs | 3 +- src/Perspex.Input/InputManager.cs | 3 +- src/Perspex.Input/KeyboardDevice.cs | 7 +- src/Perspex.Input/MouseDevice.cs | 7 +- src/Perspex.Input/Perspex.Input.csproj | 3 - src/Perspex.Input/packages.config | 1 - .../Perspex.Interactivity.csproj | 3 - src/Perspex.Interactivity/packages.config | 1 - src/Perspex.Layout/Perspex.Layout.csproj | 3 - src/Perspex.Layout/packages.config | 1 - .../Media/EllipseGeometry.cs | 3 +- src/Perspex.SceneGraph/Media/FormattedText.cs | 3 +- .../Media/Imaging/Bitmap.cs | 7 +- .../Media/Imaging/RenderTargetBitmap.cs | 3 +- .../Media/RectangleGeometry.cs | 3 +- .../Media/StreamGeometry.cs | 3 +- .../Perspex.SceneGraph.csproj | 3 - src/Perspex.SceneGraph/packages.config | 1 - src/Perspex.Styling/Perspex.Styling.csproj | 3 - src/Perspex.Styling/Styling/Styler.cs | 3 +- .../Perspex.Themes.Default.csproj | 3 - src/Perspex.Themes.Default/packages.config | 1 - src/Shared/PlatformSupport/SharedPlatform.cs | 7 +- .../Perspex.Direct2D1/Direct2D1Platform.cs | 14 +-- .../Media/FormattedTextImpl.cs | 3 +- .../Perspex.Direct2D1/Media/GeometryImpl.cs | 3 +- .../Media/StreamGeometryImpl.cs | 5 +- .../Perspex.Direct2D1.csproj | 3 - src/Windows/Perspex.Direct2D1/Renderer.cs | 9 +- src/Windows/Perspex.Direct2D1/packages.config | 1 - .../Perspex.Win32/Perspex.Win32.csproj | 3 - src/Windows/Perspex.Win32/Win32Platform.cs | 26 ++-- src/Windows/Perspex.Win32/packages.config | 1 - .../Perspex.Base.UnitTests.csproj | 3 - tests/Perspex.Base.UnitTests/packages.config | 1 - .../ContentControlTests.cs | 8 +- .../ControlTests.cs | 9 +- .../DropDownTests.cs | 6 +- .../Perspex.Controls.UnitTests.csproj | 3 - .../Primitives/PopupTests.cs | 16 +-- .../TemplatedControlTests.cs | 6 +- .../TopLevelTests.cs | 57 ++++----- .../packages.config | 1 - .../Controls/Shapes/PathTests.cs | 5 +- .../Media/GeometryTests.cs | 5 +- .../Perspex.Direct2D1.UnitTests.csproj | 3 - .../packages.config | 1 - .../Perspex.Input.UnitTests.csproj | 3 - tests/Perspex.Input.UnitTests/packages.config | 1 - .../Perspex.Interactivity.UnitTests.csproj | 3 - .../packages.config | 1 - .../FullLayoutTests.cs | 24 ++-- .../Perspex.Layout.UnitTests.csproj | 3 - .../Perspex.Layout.UnitTests/packages.config | 1 - .../Perspex.Cairo.RenderTests.csproj | 3 - tests/Perspex.RenderTests/packages.config | 1 - .../Perspex.SceneGraph.UnitTests.csproj | 3 - .../packages.config | 1 - .../Perspex.Styling.UnitTests.csproj | 3 - .../Perspex.Styling.UnitTests/packages.config | 1 - 100 files changed, 303 insertions(+), 332 deletions(-) create mode 100644 src/Perspex.Base/PerspexLocator.cs diff --git a/samples/TestApplication/App.config b/samples/TestApplication/App.config index 95bd940b8f..e354378dad 100644 --- a/samples/TestApplication/App.config +++ b/samples/TestApplication/App.config @@ -21,6 +21,10 @@ + + + + \ No newline at end of file diff --git a/samples/TestApplication/TestApplication.csproj b/samples/TestApplication/TestApplication.csproj index 4ccecb2cd0..b56417d523 100644 --- a/samples/TestApplication/TestApplication.csproj +++ b/samples/TestApplication/TestApplication.csproj @@ -66,9 +66,6 @@ ..\..\packages\Serilog.1.5.9\lib\net45\Serilog.FullNetFx.dll - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - diff --git a/samples/TestApplication/packages.config b/samples/TestApplication/packages.config index a1bddc832f..16c00246fc 100644 --- a/samples/TestApplication/packages.config +++ b/samples/TestApplication/packages.config @@ -1,11 +1,10 @@  - - - - - - - - + + + + + + + \ No newline at end of file diff --git a/samples/XamlTestApplication/XamlTestApplication.csproj b/samples/XamlTestApplication/XamlTestApplication.csproj index 5e99700b38..d70e2e3297 100644 --- a/samples/XamlTestApplication/XamlTestApplication.csproj +++ b/samples/XamlTestApplication/XamlTestApplication.csproj @@ -36,6 +36,10 @@ 4 + + ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll + True + @@ -55,9 +59,6 @@ ..\..\packages\Serilog.1.5.9\lib\net45\Serilog.FullNetFx.dll - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\Sprache.2.0.0.47\lib\portable-net4+netcore45+win8+wp8+sl5+MonoAndroid1+MonoTouch1\Sprache.dll diff --git a/samples/XamlTestApplication/packages.config b/samples/XamlTestApplication/packages.config index 0fafe14cb6..e4f85a244e 100644 --- a/samples/XamlTestApplication/packages.config +++ b/samples/XamlTestApplication/packages.config @@ -7,6 +7,6 @@ - + \ No newline at end of file diff --git a/src/Gtk/Perspex.Cairo/CairoPlatform.cs b/src/Gtk/Perspex.Cairo/CairoPlatform.cs index f25aadda95..55da932a59 100644 --- a/src/Gtk/Perspex.Cairo/CairoPlatform.cs +++ b/src/Gtk/Perspex.Cairo/CairoPlatform.cs @@ -6,7 +6,6 @@ using Perspex.Cairo.Media; using Perspex.Cairo.Media.Imaging; using Perspex.Media; using Perspex.Platform; -using Splat; namespace Perspex.Cairo { @@ -19,11 +18,7 @@ namespace Perspex.Cairo private static Pango.Context s_pangoContext = CreatePangoContext(); - public static void Initialize() - { - var locator = Locator.CurrentMutable; - locator.Register(() => s_instance, typeof(IPlatformRenderInterface)); - } + public static void Initialize() => PerspexLocator.CurrentMutable.Bind().ToConstant(s_instance); public IBitmapImpl CreateBitmap(int width, int height) { diff --git a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs index 0cbfc50097..082506c153 100644 --- a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs +++ b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using Perspex.Media; using Perspex.Platform; -using Splat; namespace Perspex.Cairo.Media { diff --git a/src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs b/src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs index 7e7f520f02..a408cba039 100644 --- a/src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs +++ b/src/Gtk/Perspex.Cairo/Media/StreamGeometryImpl.cs @@ -4,7 +4,6 @@ using System; using Perspex.Media; using Perspex.Platform; -using Splat; using System.Collections.Generic; namespace Perspex.Cairo.Media diff --git a/src/Gtk/Perspex.Cairo/Perspex.Cairo.csproj b/src/Gtk/Perspex.Cairo/Perspex.Cairo.csproj index 6e4155d610..e389fac5b2 100644 --- a/src/Gtk/Perspex.Cairo/Perspex.Cairo.csproj +++ b/src/Gtk/Perspex.Cairo/Perspex.Cairo.csproj @@ -51,9 +51,6 @@ ..\..\..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll - - ..\..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - diff --git a/src/Gtk/Perspex.Cairo/packages.config b/src/Gtk/Perspex.Cairo/packages.config index b554ddfc08..d26f4b6d2a 100644 --- a/src/Gtk/Perspex.Cairo/packages.config +++ b/src/Gtk/Perspex.Cairo/packages.config @@ -1,6 +1,5 @@  - - - - + + + \ No newline at end of file diff --git a/src/Gtk/Perspex.Gtk/GtkPlatform.cs b/src/Gtk/Perspex.Gtk/GtkPlatform.cs index 543cba012b..e6c2db7c9c 100644 --- a/src/Gtk/Perspex.Gtk/GtkPlatform.cs +++ b/src/Gtk/Perspex.Gtk/GtkPlatform.cs @@ -8,7 +8,6 @@ using Perspex.Input.Platform; using Perspex.Input; using Perspex.Platform; using Perspex.Shared.PlatformSupport; -using Splat; namespace Perspex.Gtk { @@ -29,15 +28,16 @@ namespace Perspex.Gtk public static void Initialize() { - var locator = Locator.CurrentMutable; - locator.Register(() => new WindowImpl(), typeof(IWindowImpl)); - locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); - locator.Register(() => new ClipboardImpl(), typeof(IClipboard)); - locator.Register(() => CursorFactory.Instance, typeof(IStandardCursorFactory)); - locator.Register(() => GtkKeyboardDevice.Instance, typeof(IKeyboardDevice)); - locator.Register(() => s_instance, typeof(IPlatformSettings)); - locator.Register(() => s_instance, typeof(IPlatformThreadingInterface)); - locator.Register(() => new SystemDialogImpl(), typeof (ISystemDialogImpl)); + PerspexLocator.CurrentMutable + .Bind().ToTransient() + .Bind().ToTransient() + .Bind().ToSingleton() + .Bind().ToConstant(CursorFactory.Instance) + .Bind().ToConstant(GtkKeyboardDevice.Instance) + .Bind().ToConstant(GtkMouseDevice.Instance) + .Bind().ToConstant(s_instance) + .Bind().ToConstant(s_instance) + .Bind().ToSingleton(); SharedPlatform.Register(); } diff --git a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj index 20b96380b4..1d286b3bf0 100644 --- a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj +++ b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj @@ -44,9 +44,6 @@ ..\..\..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll - - ..\..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - diff --git a/src/Gtk/Perspex.Gtk/packages.config b/src/Gtk/Perspex.Gtk/packages.config index a530073d85..e54889bccb 100644 --- a/src/Gtk/Perspex.Gtk/packages.config +++ b/src/Gtk/Perspex.Gtk/packages.config @@ -1,7 +1,6 @@  - - - - + + + \ No newline at end of file diff --git a/src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs b/src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs index b75b07b289..4da18ba27f 100644 --- a/src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs +++ b/src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs @@ -20,7 +20,6 @@ using Perspex.Media.Imaging; using Perspex.Metadata; using Perspex.Platform; using Perspex.Styling; -using Splat; namespace Perspex.Markup.Xaml.Context { @@ -52,7 +51,7 @@ namespace Perspex.Markup.Xaml.Context foreach (var nsa in forcedAssemblies - .Concat(Locator.Current.GetService().GetLoadedAssemblies()) + .Concat(PerspexLocator.Current.GetService().GetLoadedAssemblies()) .Distinct() .SelectMany(asm => asm.GetCustomAttributes().Select(attr => new {asm, attr})) diff --git a/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj b/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj index 6da087ac13..243e7b5e5a 100644 --- a/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj +++ b/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj @@ -291,9 +291,6 @@ ..\..\..\packages\Serilog.1.5.9\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Serilog.dll - - ..\..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - ..\..\..\packages\Sprache.2.0.0.47\lib\portable-net4+netcore45+win8+wp8+sl5+MonoAndroid1+MonoTouch1\Sprache.dll diff --git a/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs b/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs index 65e1ce4f71..db54e08cc5 100644 --- a/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs +++ b/src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs @@ -8,7 +8,6 @@ using System.Reflection; using OmniXaml; using Perspex.Markup.Xaml.Context; using Perspex.Platform; -using Splat; namespace Perspex.Markup.Xaml { @@ -57,7 +56,7 @@ namespace Perspex.Markup.Xaml // HACK: Currently Visual Studio is forcing us to change the extension of xaml files // in certain situations, so we try to load .xaml and if that's not found we try .paml. // Ideally we'd be able to use .xaml everywhere - var assetLocator = Locator.Current.GetService(); + var assetLocator = PerspexLocator.Current.GetService(); if (assetLocator == null) { throw new InvalidOperationException( @@ -86,7 +85,7 @@ namespace Perspex.Markup.Xaml /// The loaded object. public object Load(Uri uri, object rootInstance = null) { - var assetLocator = Locator.Current.GetService(); + var assetLocator = PerspexLocator.Current.GetService(); if (assetLocator == null) { diff --git a/src/Markup/Perspex.Markup.Xaml/packages.config b/src/Markup/Perspex.Markup.Xaml/packages.config index ffb9a430bf..7576d65eac 100644 --- a/src/Markup/Perspex.Markup.Xaml/packages.config +++ b/src/Markup/Perspex.Markup.Xaml/packages.config @@ -6,6 +6,5 @@ - \ No newline at end of file diff --git a/src/Perspex.Application/Application.cs b/src/Perspex.Application/Application.cs index 09ab0a892a..ac93f82fec 100644 --- a/src/Perspex.Application/Application.cs +++ b/src/Perspex.Application/Application.cs @@ -12,7 +12,6 @@ using Perspex.Layout; using Perspex.Rendering; using Perspex.Styling; using Perspex.Threading; -using Splat; namespace Perspex { @@ -40,7 +39,7 @@ namespace Perspex private DataTemplates _dataTemplates; private readonly Lazy _clipboard = - new Lazy(() => (IClipboard)Locator.Current.GetService(typeof(IClipboard))); + new Lazy(() => (IClipboard)PerspexLocator.Current.GetService(typeof(IClipboard))); /// /// The styler that will be used to apply styles to controls. @@ -157,15 +156,16 @@ namespace Perspex FocusManager = new FocusManager(); InputManager = new InputManager(); - Locator.CurrentMutable.Register(() => new AccessKeyHandler(), typeof(IAccessKeyHandler)); - Locator.CurrentMutable.Register(() => this, typeof(IGlobalDataTemplates)); - Locator.CurrentMutable.Register(() => this, typeof(IGlobalStyles)); - Locator.CurrentMutable.Register(() => FocusManager, typeof(IFocusManager)); - Locator.CurrentMutable.Register(() => InputManager, typeof(IInputManager)); - Locator.CurrentMutable.Register(() => new KeyboardNavigationHandler(), typeof(IKeyboardNavigationHandler)); - Locator.CurrentMutable.Register(() => _styler, typeof(IStyler)); - Locator.CurrentMutable.Register(() => new LayoutManager(), typeof(ILayoutManager)); - Locator.CurrentMutable.Register(() => new RenderManager(), typeof(IRenderManager)); + PerspexLocator.CurrentMutable + .Bind().ToTransient() + .Bind().ToConstant(this) + .Bind().ToConstant(this) + .Bind().ToConstant(FocusManager) + .Bind().ToConstant(InputManager) + .Bind().ToTransient() + .Bind().ToConstant(_styler) + .Bind().ToTransient() + .Bind().ToTransient(); } /// diff --git a/src/Perspex.Application/Perspex.Application.csproj b/src/Perspex.Application/Perspex.Application.csproj index 9a16f9130b..c5fe995636 100644 --- a/src/Perspex.Application/Perspex.Application.csproj +++ b/src/Perspex.Application/Perspex.Application.csproj @@ -89,9 +89,6 @@ ..\..\packages\Rx-PlatformServices.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.PlatformServices.dll - - ..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - diff --git a/src/Perspex.Application/packages.config b/src/Perspex.Application/packages.config index 0913700f2d..d5af0dcd81 100644 --- a/src/Perspex.Application/packages.config +++ b/src/Perspex.Application/packages.config @@ -5,5 +5,4 @@ - \ No newline at end of file diff --git a/src/Perspex.Base/Perspex.Base.csproj b/src/Perspex.Base/Perspex.Base.csproj index f6fdace315..d90087add4 100644 --- a/src/Perspex.Base/Perspex.Base.csproj +++ b/src/Perspex.Base/Perspex.Base.csproj @@ -46,6 +46,7 @@ + @@ -93,9 +94,6 @@ ..\..\packages\Serilog.1.5.9\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Serilog.dll - - ..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - diff --git a/src/Perspex.Base/PerspexLocator.cs b/src/Perspex.Base/PerspexLocator.cs new file mode 100644 index 0000000000..262ffda8d8 --- /dev/null +++ b/src/Perspex.Base/PerspexLocator.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; + +#pragma warning disable CS1591 // Enable me later + +namespace Perspex +{ + public class PerspexLocator : IPerspexDependencyResolver + { + private readonly IPerspexDependencyResolver _parentScope; + public static IPerspexDependencyResolver Current { get; set; } + public static PerspexLocator CurrentMutable { get; set; } + private readonly Dictionary> _registry = new Dictionary>(); + + static PerspexLocator() + { + Current = CurrentMutable = new PerspexLocator(); + } + + public PerspexLocator() + { + + } + + public PerspexLocator(IPerspexDependencyResolver parentScope) + { + _parentScope = parentScope; + } + + public object GetService(Type t) + { + Func rv; + if (_registry.TryGetValue(t, out rv)) + return rv(); + var parentRv = _parentScope?.GetService(t); + if (parentRv != null) + return parentRv; + throw new TypeLoadException("Unable to find registrations for service " + t); + } + + public class RegistrationHelper + { + private PerspexLocator _locator; + + public RegistrationHelper(PerspexLocator locator) + { + _locator = locator; + } + + public PerspexLocator ToConstant(TImpl constant) where TImpl : TService + { + _locator._registry[typeof (TService)] = () => constant; + return _locator; + } + + public PerspexLocator ToFunc(Func func) where TImlp : TService + { + _locator._registry[typeof (TService)] = () => func(); + return _locator; + } + + public PerspexLocator ToSingleton() where TImpl : class, TService, new() + { + TImpl instance = null; + return ToFunc(() => instance ?? (instance = new TImpl())); + } + + public PerspexLocator ToTransient() where TImpl : class, TService, new() => ToFunc(() => new TImpl()); + } + + public RegistrationHelper Bind() => new RegistrationHelper(this); + + + public PerspexLocator BindToSelf(T constant) + => Bind().ToConstant(constant); + + public PerspexLocator BindToSelfSingleton() where T : class, new() => Bind().ToSingleton(); + + class ResolverDisposable : IDisposable + { + private readonly IPerspexDependencyResolver _resolver; + private readonly PerspexLocator _mutable; + + public ResolverDisposable(IPerspexDependencyResolver resolver, PerspexLocator mutable) + { + _resolver = resolver; + _mutable = mutable; + } + + public void Dispose() + { + Current = _resolver; + CurrentMutable = _mutable; + } + } + + public static IDisposable EnterScope() + { + var d = new ResolverDisposable(Current, CurrentMutable); + Current = CurrentMutable = new PerspexLocator(Current); + return d; + + } + } + + public interface IPerspexDependencyResolver + { + object GetService(Type t); + } + + public static class LocatorExtensions + { + public static T GetService(this IPerspexDependencyResolver resolver) + { + return (T) resolver.GetService(typeof (T)); + } + } +} + diff --git a/src/Perspex.Base/Threading/DispatcherTimer.cs b/src/Perspex.Base/Threading/DispatcherTimer.cs index 21c3da0f8d..27b1a8cb36 100644 --- a/src/Perspex.Base/Threading/DispatcherTimer.cs +++ b/src/Perspex.Base/Threading/DispatcherTimer.cs @@ -4,7 +4,6 @@ using System; using System.Reactive.Disposables; using Perspex.Platform; -using Splat; namespace Perspex.Threading { @@ -175,7 +174,7 @@ namespace Perspex.Threading { if (!IsEnabled) { - IPlatformThreadingInterface threading = Locator.Current.GetService(); + IPlatformThreadingInterface threading = PerspexLocator.Current.GetService(); _timer = threading.StartTimer(Interval, InternalTick); } } @@ -187,7 +186,7 @@ namespace Perspex.Threading { if (IsEnabled) { - IPlatformThreadingInterface threading = Locator.Current.GetService(); + IPlatformThreadingInterface threading = PerspexLocator.Current.GetService(); _timer.Dispose(); _timer = null; } diff --git a/src/Perspex.Base/Threading/MainLoop.cs b/src/Perspex.Base/Threading/MainLoop.cs index c38de6e26b..b9d21d5ab5 100644 --- a/src/Perspex.Base/Threading/MainLoop.cs +++ b/src/Perspex.Base/Threading/MainLoop.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Perspex.Platform; using Perspex.Threading; -using Splat; namespace Perspex.Win32.Threading { @@ -25,7 +24,7 @@ namespace Perspex.Win32.Threading /// static MainLoop() { - s_platform = Locator.Current.GetService(); + s_platform = PerspexLocator.Current.GetService(); } /// diff --git a/src/Perspex.Base/packages.config b/src/Perspex.Base/packages.config index e901739010..7d2a813bf7 100644 --- a/src/Perspex.Base/packages.config +++ b/src/Perspex.Base/packages.config @@ -6,5 +6,4 @@ - \ No newline at end of file diff --git a/src/Perspex.Controls/Control.cs b/src/Perspex.Controls/Control.cs index 12ae649f91..901b744451 100644 --- a/src/Perspex.Controls/Control.cs +++ b/src/Perspex.Controls/Control.cs @@ -12,7 +12,6 @@ using Perspex.Interactivity; using Perspex.LogicalTree; using Perspex.Rendering; using Perspex.Styling; -using Splat; namespace Perspex.Controls { @@ -397,7 +396,7 @@ namespace Perspex.Controls { base.OnAttachedToVisualTree(root); - IStyler styler = Locator.Current.GetService(); + IStyler styler = PerspexLocator.Current.GetService(); styler.ApplyStyles(this); } diff --git a/src/Perspex.Controls/MenuItem.cs b/src/Perspex.Controls/MenuItem.cs index 2c9b7eaaba..99bb5cad01 100644 --- a/src/Perspex.Controls/MenuItem.cs +++ b/src/Perspex.Controls/MenuItem.cs @@ -14,7 +14,6 @@ using Perspex.Input; using Perspex.Interactivity; using Perspex.Threading; using Perspex.VisualTree; -using Splat; namespace Perspex.Controls { @@ -489,7 +488,7 @@ namespace Perspex.Controls /// /// A dependency resolver which returns a . /// - private class DependencyResolver : IDependencyResolver + private class DependencyResolver : IPerspexDependencyResolver { /// /// Gets the default instance of . @@ -509,7 +508,7 @@ namespace Perspex.Controls /// The service type. /// An optional contract. /// A service of the requested type. - public object GetService(Type serviceType, string contract = null) + public object GetService(Type serviceType) { if (serviceType == typeof(IAccessKeyHandler)) { @@ -517,20 +516,9 @@ namespace Perspex.Controls } else { - return Locator.Current.GetService(serviceType, contract); + return PerspexLocator.Current.GetService(serviceType); } } - - /// - /// Gets collection of services of the specified type. - /// - /// The service type. - /// An optional contract. - /// A collection of services of the requested type. - public IEnumerable GetServices(Type serviceType, string contract = null) - { - return Locator.Current.GetServices(serviceType, contract); - } } } } diff --git a/src/Perspex.Controls/Perspex.Controls.csproj b/src/Perspex.Controls/Perspex.Controls.csproj index f4d1332994..59267be10f 100644 --- a/src/Perspex.Controls/Perspex.Controls.csproj +++ b/src/Perspex.Controls/Perspex.Controls.csproj @@ -187,9 +187,6 @@ ..\..\packages\Serilog.1.5.9\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Serilog.dll - - ..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - diff --git a/src/Perspex.Controls/Primitives/Popup.cs b/src/Perspex.Controls/Primitives/Popup.cs index 2a2917ace3..af28f72a39 100644 --- a/src/Perspex.Controls/Primitives/Popup.cs +++ b/src/Perspex.Controls/Primitives/Popup.cs @@ -5,7 +5,6 @@ using System; using Perspex.Interactivity; using Perspex.Rendering; using Perspex.VisualTree; -using Splat; namespace Perspex.Controls.Primitives { @@ -94,7 +93,7 @@ namespace Perspex.Controls.Primitives /// This property allows a client to customize the behaviour of the popup by injecting /// a specialized dependency resolver into the 's constructor. /// - public IDependencyResolver DependencyResolver + public IPerspexDependencyResolver DependencyResolver { get; set; diff --git a/src/Perspex.Controls/Primitives/PopupRoot.cs b/src/Perspex.Controls/Primitives/PopupRoot.cs index ee2db7dc0e..4e628f79f0 100644 --- a/src/Perspex.Controls/Primitives/PopupRoot.cs +++ b/src/Perspex.Controls/Primitives/PopupRoot.cs @@ -8,7 +8,6 @@ using Perspex.Interactivity; using Perspex.Media; using Perspex.Platform; using Perspex.VisualTree; -using Splat; namespace Perspex.Controls.Primitives { @@ -41,8 +40,8 @@ namespace Perspex.Controls.Primitives /// /// The dependency resolver to use. If null the default dependency resolver will be used. /// - public PopupRoot(IDependencyResolver dependencyResolver) - : base(Locator.Current.GetService(), dependencyResolver) + public PopupRoot(IPerspexDependencyResolver dependencyResolver) + : base(PerspexLocator.Current.GetService(), dependencyResolver) { GetObservable(ParentProperty).Subscribe(x => InheritanceParent = (PerspexObject)x); } diff --git a/src/Perspex.Controls/SystemDialog.cs b/src/Perspex.Controls/SystemDialog.cs index ce424f31fa..6eae1e9e9d 100644 --- a/src/Perspex.Controls/SystemDialog.cs +++ b/src/Perspex.Controls/SystemDialog.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Threading.Tasks; using Perspex.Controls.Platform; -using Splat; namespace Perspex.Controls { @@ -20,7 +19,7 @@ namespace Perspex.Controls public async Task ShowAsync(Window window = null) => - ((await Locator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl)) ?? + ((await PerspexLocator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl)) ?? new string[0]).FirstOrDefault(); } @@ -29,7 +28,7 @@ namespace Perspex.Controls public bool AllowMultiple { get; set; } public Task ShowAsync(Window window = null) - => Locator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl); + => PerspexLocator.Current.GetService().ShowFileDialogAsync(this, window?.PlatformImpl); } public abstract class SystemDialog diff --git a/src/Perspex.Controls/Templates/DataTemplateExtensions.cs b/src/Perspex.Controls/Templates/DataTemplateExtensions.cs index 3fd09024cf..f99fe41d26 100644 --- a/src/Perspex.Controls/Templates/DataTemplateExtensions.cs +++ b/src/Perspex.Controls/Templates/DataTemplateExtensions.cs @@ -3,7 +3,6 @@ using System.Linq; using Perspex.LogicalTree; -using Splat; namespace Perspex.Controls.Templates { @@ -63,7 +62,7 @@ namespace Perspex.Controls.Templates } } - IGlobalDataTemplates global = Locator.Current.GetService(); + IGlobalDataTemplates global = PerspexLocator.Current.GetService(); if (global != null) { diff --git a/src/Perspex.Controls/TextBox.cs b/src/Perspex.Controls/TextBox.cs index fc3bc91585..e8eaf70a73 100644 --- a/src/Perspex.Controls/TextBox.cs +++ b/src/Perspex.Controls/TextBox.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using Perspex.Input.Platform; -using Splat; using System; using System.Collections.Generic; using System.Linq; @@ -150,13 +149,13 @@ namespace Perspex.Controls private async void Copy() { - await ((IClipboard)Locator.Current.GetService(typeof(IClipboard))) + await ((IClipboard)PerspexLocator.Current.GetService(typeof(IClipboard))) .SetTextAsync(GetSelection()); } private async void Paste() { - var text = await ((IClipboard)Locator.Current.GetService(typeof(IClipboard))).GetTextAsync(); + var text = await ((IClipboard)PerspexLocator.Current.GetService(typeof(IClipboard))).GetTextAsync(); if (text == null) { return; diff --git a/src/Perspex.Controls/TopLevel.cs b/src/Perspex.Controls/TopLevel.cs index 47e13e41ff..33a7eca9a2 100644 --- a/src/Perspex.Controls/TopLevel.cs +++ b/src/Perspex.Controls/TopLevel.cs @@ -12,7 +12,6 @@ using Perspex.Platform; using Perspex.Rendering; using Perspex.Styling; using Perspex.Threading; -using Splat; namespace Perspex.Controls { @@ -87,7 +86,7 @@ namespace Perspex.Controls /// /// The platform-specific window implementation. public TopLevel(ITopLevelImpl impl) - : this(impl, Locator.Current) + : this(impl, PerspexLocator.Current) { } @@ -98,7 +97,7 @@ namespace Perspex.Controls /// /// The dependency resolver to use. If null the default dependency resolver will be used. /// - public TopLevel(ITopLevelImpl impl, IDependencyResolver dependencyResolver) + public TopLevel(ITopLevelImpl impl, IPerspexDependencyResolver dependencyResolver) { if (impl == null) { @@ -108,7 +107,7 @@ namespace Perspex.Controls PlatformImpl = impl; - dependencyResolver = dependencyResolver ?? Locator.Current; + dependencyResolver = dependencyResolver ?? PerspexLocator.Current; var renderInterface = TryGetService(dependencyResolver); var styler = TryGetService(dependencyResolver); _accessKeyHandler = TryGetService(dependencyResolver); @@ -327,13 +326,13 @@ namespace Perspex.Controls } /// - /// Tries to get a service from an , throwing an + /// Tries to get a service from an , throwing an /// exception if not found. /// /// The service type. /// The resolver. /// The service. - private static T TryGetService(IDependencyResolver resolver) where T : class + private static T TryGetService(IPerspexDependencyResolver resolver) where T : class { var result = resolver.GetService(); diff --git a/src/Perspex.Controls/Window.cs b/src/Perspex.Controls/Window.cs index fb3fee2587..5b01d6c63b 100644 --- a/src/Perspex.Controls/Window.cs +++ b/src/Perspex.Controls/Window.cs @@ -8,7 +8,6 @@ using Perspex.Input; using Perspex.Media; using Perspex.Platform; using Perspex.Styling; -using Splat; namespace Perspex.Controls { @@ -72,7 +71,7 @@ namespace Perspex.Controls /// Initializes a new instance of the class. /// public Window() - : base(Locator.Current.GetService()) + : base(PerspexLocator.Current.GetService()) { _maxPlatformClientSize = this.PlatformImpl.MaxClientSize; } diff --git a/src/Perspex.Controls/packages.config b/src/Perspex.Controls/packages.config index e901739010..7d2a813bf7 100644 --- a/src/Perspex.Controls/packages.config +++ b/src/Perspex.Controls/packages.config @@ -6,5 +6,4 @@ - \ No newline at end of file diff --git a/src/Perspex.HtmlRenderer/Adapters/PerspexAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/PerspexAdapter.cs index 26dcaeb442..0411c7e26e 100644 --- a/src/Perspex.HtmlRenderer/Adapters/PerspexAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/PerspexAdapter.cs @@ -9,7 +9,6 @@ using Perspex; using Perspex.Input.Platform; using Perspex.Media; using Perspex.Media.Imaging; -using Splat; using TheArtOfDev.HtmlRenderer.Adapters; using TheArtOfDev.HtmlRenderer.Adapters.Entities; using TheArtOfDev.HtmlRenderer.Perspex.Utilities; @@ -118,7 +117,7 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters protected override void SetToClipboardInt(string text) { - Locator.Current.GetService().SetTextAsync(text); + PerspexLocator.Current.GetService().SetTextAsync(text); } protected override void SetToClipboardInt(RImage image) diff --git a/src/Perspex.HtmlRenderer/Perspex.HtmlRenderer.csproj b/src/Perspex.HtmlRenderer/Perspex.HtmlRenderer.csproj index ef8f2edb78..7167ab0a7f 100644 --- a/src/Perspex.HtmlRenderer/Perspex.HtmlRenderer.csproj +++ b/src/Perspex.HtmlRenderer/Perspex.HtmlRenderer.csproj @@ -172,9 +172,6 @@ - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\Rx-Core.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.Core.dll diff --git a/src/Perspex.HtmlRenderer/packages.config b/src/Perspex.HtmlRenderer/packages.config index c5594cb5ab..f23358716a 100644 --- a/src/Perspex.HtmlRenderer/packages.config +++ b/src/Perspex.HtmlRenderer/packages.config @@ -4,5 +4,4 @@ - \ No newline at end of file diff --git a/src/Perspex.Input/Cursors.cs b/src/Perspex.Input/Cursors.cs index 2c4367d5c0..889cc68774 100644 --- a/src/Perspex.Input/Cursors.cs +++ b/src/Perspex.Input/Cursors.cs @@ -1,7 +1,6 @@ // Copyright (c) The Perspex Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. -using Splat; using System; using System.Collections.Generic; using System.Linq; @@ -50,7 +49,7 @@ namespace Perspex.Input public Cursor(StandardCursorType cursorType) : this( - ((IStandardCursorFactory)Locator.Current.GetService(typeof(IStandardCursorFactory))).GetCursor( + ((IStandardCursorFactory)PerspexLocator.Current.GetService(typeof(IStandardCursorFactory))).GetCursor( cursorType)) { } diff --git a/src/Perspex.Input/FocusManager.cs b/src/Perspex.Input/FocusManager.cs index 74fb29e683..945e9ad782 100644 --- a/src/Perspex.Input/FocusManager.cs +++ b/src/Perspex.Input/FocusManager.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using Perspex.Interactivity; using Perspex.VisualTree; -using Splat; namespace Perspex.Input { @@ -35,7 +34,7 @@ namespace Perspex.Input /// /// Gets the instance of the . /// - public static IFocusManager Instance => Locator.Current.GetService(); + public static IFocusManager Instance => PerspexLocator.Current.GetService(); /// /// Gets the currently focused . diff --git a/src/Perspex.Input/InputManager.cs b/src/Perspex.Input/InputManager.cs index 5b6338b084..eb25850d3d 100644 --- a/src/Perspex.Input/InputManager.cs +++ b/src/Perspex.Input/InputManager.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using System.Reactive.Subjects; using Perspex.Input.Raw; -using Splat; namespace Perspex.Input { @@ -16,7 +15,7 @@ namespace Perspex.Input private readonly Subject _postProcess = new Subject(); - public static IInputManager Instance => Locator.Current.GetService(); + public static IInputManager Instance => PerspexLocator.Current.GetService(); public IObservable RawEventReceived => _rawEventReceived; diff --git a/src/Perspex.Input/KeyboardDevice.cs b/src/Perspex.Input/KeyboardDevice.cs index 8aff90bae4..390e925ce5 100644 --- a/src/Perspex.Input/KeyboardDevice.cs +++ b/src/Perspex.Input/KeyboardDevice.cs @@ -8,7 +8,6 @@ using System.Reactive.Linq; using System.Runtime.CompilerServices; using Perspex.Input.Raw; using Perspex.Interactivity; -using Splat; namespace Perspex.Input { @@ -26,11 +25,11 @@ namespace Perspex.Input public event PropertyChangedEventHandler PropertyChanged; - public static IKeyboardDevice Instance => Locator.Current.GetService(); + public static IKeyboardDevice Instance => PerspexLocator.Current.GetService(); - public IInputManager InputManager => Locator.Current.GetService(); + public IInputManager InputManager => PerspexLocator.Current.GetService(); - public IFocusManager FocusManager => Locator.Current.GetService(); + public IFocusManager FocusManager => PerspexLocator.Current.GetService(); public IInputElement FocusedElement { diff --git a/src/Perspex.Input/MouseDevice.cs b/src/Perspex.Input/MouseDevice.cs index 9b0fb17ea6..6cde0d8faf 100644 --- a/src/Perspex.Input/MouseDevice.cs +++ b/src/Perspex.Input/MouseDevice.cs @@ -9,7 +9,6 @@ using Perspex.Input.Raw; using Perspex.Interactivity; using Perspex.Platform; using Perspex.VisualTree; -using Splat; namespace Perspex.Input { @@ -31,7 +30,7 @@ namespace Perspex.Input .Subscribe(ProcessRawEvent); } - public static IMouseDevice Instance => Locator.Current.GetService(); + public static IMouseDevice Instance => PerspexLocator.Current.GetService(); public IInputElement Captured { @@ -39,7 +38,7 @@ namespace Perspex.Input protected set; } - public IInputManager InputManager => Locator.Current.GetService(); + public IInputManager InputManager => PerspexLocator.Current.GetService(); public Point Position { @@ -107,7 +106,7 @@ namespace Perspex.Input if (source != null) { - var settings = Locator.Current.GetService(); + var settings = PerspexLocator.Current.GetService(); var doubleClickTime = settings.DoubleClickTime.TotalMilliseconds; if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime) diff --git a/src/Perspex.Input/Perspex.Input.csproj b/src/Perspex.Input/Perspex.Input.csproj index e9233cbf25..366d7c4711 100644 --- a/src/Perspex.Input/Perspex.Input.csproj +++ b/src/Perspex.Input/Perspex.Input.csproj @@ -126,9 +126,6 @@ ..\..\packages\Rx-PlatformServices.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.PlatformServices.dll - - ..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - diff --git a/src/Perspex.Input/packages.config b/src/Perspex.Input/packages.config index 0913700f2d..d5af0dcd81 100644 --- a/src/Perspex.Input/packages.config +++ b/src/Perspex.Input/packages.config @@ -5,5 +5,4 @@ - \ No newline at end of file diff --git a/src/Perspex.Interactivity/Perspex.Interactivity.csproj b/src/Perspex.Interactivity/Perspex.Interactivity.csproj index 1f18564d89..c67efb6c11 100644 --- a/src/Perspex.Interactivity/Perspex.Interactivity.csproj +++ b/src/Perspex.Interactivity/Perspex.Interactivity.csproj @@ -81,9 +81,6 @@ ..\..\packages\Rx-PlatformServices.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.PlatformServices.dll - - ..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - diff --git a/src/Perspex.Interactivity/packages.config b/src/Perspex.Interactivity/packages.config index 0913700f2d..d5af0dcd81 100644 --- a/src/Perspex.Interactivity/packages.config +++ b/src/Perspex.Interactivity/packages.config @@ -5,5 +5,4 @@ - \ No newline at end of file diff --git a/src/Perspex.Layout/Perspex.Layout.csproj b/src/Perspex.Layout/Perspex.Layout.csproj index f20320f026..50c6338217 100644 --- a/src/Perspex.Layout/Perspex.Layout.csproj +++ b/src/Perspex.Layout/Perspex.Layout.csproj @@ -80,9 +80,6 @@ ..\..\packages\Serilog.1.5.9\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Serilog.dll - - ..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - diff --git a/src/Perspex.Layout/packages.config b/src/Perspex.Layout/packages.config index e901739010..7d2a813bf7 100644 --- a/src/Perspex.Layout/packages.config +++ b/src/Perspex.Layout/packages.config @@ -6,5 +6,4 @@ - \ No newline at end of file diff --git a/src/Perspex.SceneGraph/Media/EllipseGeometry.cs b/src/Perspex.SceneGraph/Media/EllipseGeometry.cs index 142b8b7f6b..d8887ac035 100644 --- a/src/Perspex.SceneGraph/Media/EllipseGeometry.cs +++ b/src/Perspex.SceneGraph/Media/EllipseGeometry.cs @@ -3,7 +3,6 @@ using System; using Perspex.Platform; -using Splat; namespace Perspex.Media { @@ -18,7 +17,7 @@ namespace Perspex.Media /// The rectangle that the ellipse should fill. public EllipseGeometry(Rect rect) { - IPlatformRenderInterface factory = Locator.Current.GetService(); + IPlatformRenderInterface factory = PerspexLocator.Current.GetService(); IStreamGeometryImpl impl = factory.CreateStreamGeometry(); using (IStreamGeometryContextImpl ctx = impl.Open()) diff --git a/src/Perspex.SceneGraph/Media/FormattedText.cs b/src/Perspex.SceneGraph/Media/FormattedText.cs index 0d8b4eb298..b8e8c5ddee 100644 --- a/src/Perspex.SceneGraph/Media/FormattedText.cs +++ b/src/Perspex.SceneGraph/Media/FormattedText.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Perspex.Platform; -using Splat; namespace Perspex.Media { @@ -37,7 +36,7 @@ namespace Perspex.Media FontWeight = fontWeight; TextAlignment = textAlignment; - var platform = Locator.Current.GetService(); + var platform = PerspexLocator.Current.GetService(); PlatformImpl = platform.CreateFormattedText( text, diff --git a/src/Perspex.SceneGraph/Media/Imaging/Bitmap.cs b/src/Perspex.SceneGraph/Media/Imaging/Bitmap.cs index 92ec2ac1b9..55b25738ad 100644 --- a/src/Perspex.SceneGraph/Media/Imaging/Bitmap.cs +++ b/src/Perspex.SceneGraph/Media/Imaging/Bitmap.cs @@ -3,7 +3,6 @@ using System.IO; using Perspex.Platform; -using Splat; namespace Perspex.Media.Imaging { @@ -18,7 +17,7 @@ namespace Perspex.Media.Imaging /// The filename of the bitmap. public Bitmap(string fileName) { - IPlatformRenderInterface factory = Locator.Current.GetService(); + IPlatformRenderInterface factory = PerspexLocator.Current.GetService(); PlatformImpl = factory.LoadBitmap(fileName); } @@ -28,7 +27,7 @@ namespace Perspex.Media.Imaging /// The stream to read the bitmap from. public Bitmap(Stream stream) { - IPlatformRenderInterface factory = Locator.Current.GetService(); + IPlatformRenderInterface factory = PerspexLocator.Current.GetService(); PlatformImpl = factory.LoadBitmap(stream); } @@ -39,7 +38,7 @@ namespace Perspex.Media.Imaging /// The height of the bitmap, in pixels. public Bitmap(int width, int height) { - IPlatformRenderInterface factory = Locator.Current.GetService(); + IPlatformRenderInterface factory = PerspexLocator.Current.GetService(); PlatformImpl = factory.CreateBitmap(width, height); } diff --git a/src/Perspex.SceneGraph/Media/Imaging/RenderTargetBitmap.cs b/src/Perspex.SceneGraph/Media/Imaging/RenderTargetBitmap.cs index 6637ffc5d4..90b83dff6b 100644 --- a/src/Perspex.SceneGraph/Media/Imaging/RenderTargetBitmap.cs +++ b/src/Perspex.SceneGraph/Media/Imaging/RenderTargetBitmap.cs @@ -3,7 +3,6 @@ using System; using Perspex.Platform; -using Splat; namespace Perspex.Media.Imaging { @@ -55,7 +54,7 @@ namespace Perspex.Media.Imaging /// The platform-specific implementation. private static IBitmapImpl CreateImpl(int width, int height) { - IPlatformRenderInterface factory = Locator.Current.GetService(); + IPlatformRenderInterface factory = PerspexLocator.Current.GetService(); return factory.CreateRenderTargetBitmap(width, height); } } diff --git a/src/Perspex.SceneGraph/Media/RectangleGeometry.cs b/src/Perspex.SceneGraph/Media/RectangleGeometry.cs index fabc354cdf..190d467127 100644 --- a/src/Perspex.SceneGraph/Media/RectangleGeometry.cs +++ b/src/Perspex.SceneGraph/Media/RectangleGeometry.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using Perspex.Platform; -using Splat; namespace Perspex.Media { @@ -17,7 +16,7 @@ namespace Perspex.Media /// The rectangle bounds. public RectangleGeometry(Rect rect) { - IPlatformRenderInterface factory = Locator.Current.GetService(); + IPlatformRenderInterface factory = PerspexLocator.Current.GetService(); IStreamGeometryImpl impl = factory.CreateStreamGeometry(); using (IStreamGeometryContextImpl context = impl.Open()) diff --git a/src/Perspex.SceneGraph/Media/StreamGeometry.cs b/src/Perspex.SceneGraph/Media/StreamGeometry.cs index 8d61d2c31a..4d0b353f5d 100644 --- a/src/Perspex.SceneGraph/Media/StreamGeometry.cs +++ b/src/Perspex.SceneGraph/Media/StreamGeometry.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using Perspex.Platform; -using Splat; namespace Perspex.Media { @@ -16,7 +15,7 @@ namespace Perspex.Media /// public StreamGeometry() { - IPlatformRenderInterface factory = Locator.Current.GetService(); + IPlatformRenderInterface factory = PerspexLocator.Current.GetService(); PlatformImpl = factory.CreateStreamGeometry(); } diff --git a/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj b/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj index 4cf3651824..4b8c5c3778 100644 --- a/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj +++ b/src/Perspex.SceneGraph/Perspex.SceneGraph.csproj @@ -143,9 +143,6 @@ ..\..\packages\Serilog.1.5.9\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Serilog.dll - - ..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - diff --git a/src/Perspex.SceneGraph/packages.config b/src/Perspex.SceneGraph/packages.config index e901739010..7d2a813bf7 100644 --- a/src/Perspex.SceneGraph/packages.config +++ b/src/Perspex.SceneGraph/packages.config @@ -6,5 +6,4 @@ - \ No newline at end of file diff --git a/src/Perspex.Styling/Perspex.Styling.csproj b/src/Perspex.Styling/Perspex.Styling.csproj index cd9816f9fc..c0776e27c2 100644 --- a/src/Perspex.Styling/Perspex.Styling.csproj +++ b/src/Perspex.Styling/Perspex.Styling.csproj @@ -77,9 +77,6 @@ ..\..\packages\Rx-PlatformServices.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.PlatformServices.dll - - ..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - diff --git a/src/Perspex.Styling/Styling/Styler.cs b/src/Perspex.Styling/Styling/Styler.cs index 67f8bc537f..d9780de6e6 100644 --- a/src/Perspex.Styling/Styling/Styler.cs +++ b/src/Perspex.Styling/Styling/Styler.cs @@ -4,7 +4,6 @@ using System; using System.Linq; using Perspex.VisualTree; -using Splat; namespace Perspex.Styling { @@ -17,7 +16,7 @@ namespace Perspex.Styling .GetSelfAndVisualAncestors() .OfType() .FirstOrDefault(); - IGlobalStyles global = Locator.Current.GetService(); + IGlobalStyles global = PerspexLocator.Current.GetService(); if (global != null) { diff --git a/src/Perspex.Themes.Default/Perspex.Themes.Default.csproj b/src/Perspex.Themes.Default/Perspex.Themes.Default.csproj index 3b8d4114a6..4c6218f1b9 100644 --- a/src/Perspex.Themes.Default/Perspex.Themes.Default.csproj +++ b/src/Perspex.Themes.Default/Perspex.Themes.Default.csproj @@ -118,9 +118,6 @@ ..\..\packages\Rx-PlatformServices.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.PlatformServices.dll - - ..\..\packages\Splat.1.6.2\lib\Portable-net45+win+wpa81+wp80\Splat.dll - diff --git a/src/Perspex.Themes.Default/packages.config b/src/Perspex.Themes.Default/packages.config index 0913700f2d..d5af0dcd81 100644 --- a/src/Perspex.Themes.Default/packages.config +++ b/src/Perspex.Themes.Default/packages.config @@ -5,5 +5,4 @@ - \ No newline at end of file diff --git a/src/Shared/PlatformSupport/SharedPlatform.cs b/src/Shared/PlatformSupport/SharedPlatform.cs index 3a6680e64d..33f8b54332 100644 --- a/src/Shared/PlatformSupport/SharedPlatform.cs +++ b/src/Shared/PlatformSupport/SharedPlatform.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Text; using Perspex.Platform; -using Splat; namespace Perspex.Shared.PlatformSupport { @@ -10,9 +9,9 @@ namespace Perspex.Shared.PlatformSupport { public static void Register() { - var locator = Locator.CurrentMutable; - locator.Register(() => new PclPlatformWrapper(), typeof(IPclPlatformWrapper)); - locator.RegisterConstant(new AssetLoader(), typeof(IAssetLoader)); + PerspexLocator.CurrentMutable + .Bind().ToSingleton() + .Bind().ToSingleton(); } } } diff --git a/src/Windows/Perspex.Direct2D1/Direct2D1Platform.cs b/src/Windows/Perspex.Direct2D1/Direct2D1Platform.cs index 31b0ff34a1..9005a9ffe3 100644 --- a/src/Windows/Perspex.Direct2D1/Direct2D1Platform.cs +++ b/src/Windows/Perspex.Direct2D1/Direct2D1Platform.cs @@ -6,7 +6,6 @@ using System.IO; using Perspex.Direct2D1.Media; using Perspex.Media; using Perspex.Platform; -using Splat; namespace Perspex.Direct2D1 { @@ -20,14 +19,11 @@ namespace Perspex.Direct2D1 private static readonly SharpDX.WIC.ImagingFactory s_imagingFactory = new SharpDX.WIC.ImagingFactory(); - public static void Initialize() - { - var locator = Locator.CurrentMutable; - locator.Register(() => s_instance, typeof(IPlatformRenderInterface)); - locator.Register(() => s_d2D1Factory, typeof(SharpDX.Direct2D1.Factory)); - locator.Register(() => s_dwfactory, typeof(SharpDX.DirectWrite.Factory)); - locator.Register(() => s_imagingFactory, typeof(SharpDX.WIC.ImagingFactory)); - } + public static void Initialize() => PerspexLocator.CurrentMutable + .Bind().ToConstant(s_instance) + .BindToSelf(s_d2D1Factory) + .BindToSelf(s_dwfactory) + .BindToSelf(s_imagingFactory); public IBitmapImpl CreateBitmap(int width, int height) { diff --git a/src/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs b/src/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs index dd40e507b5..6ace607107 100644 --- a/src/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs +++ b/src/Windows/Perspex.Direct2D1/Media/FormattedTextImpl.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using Perspex.Media; using Perspex.Platform; -using Splat; using DWrite = SharpDX.DirectWrite; namespace Perspex.Direct2D1.Media @@ -21,7 +20,7 @@ namespace Perspex.Direct2D1.Media TextAlignment textAlignment, FontWeight fontWeight) { - var factory = Locator.Current.GetService(); + var factory = PerspexLocator.Current.GetService(); var format = new DWrite.TextFormat( factory, diff --git a/src/Windows/Perspex.Direct2D1/Media/GeometryImpl.cs b/src/Windows/Perspex.Direct2D1/Media/GeometryImpl.cs index 2d1665b27b..79df8d3f67 100644 --- a/src/Windows/Perspex.Direct2D1/Media/GeometryImpl.cs +++ b/src/Windows/Perspex.Direct2D1/Media/GeometryImpl.cs @@ -3,7 +3,6 @@ using Perspex.Platform; using SharpDX.Direct2D1; -using Splat; namespace Perspex.Direct2D1.Media { @@ -59,7 +58,7 @@ namespace Perspex.Direct2D1.Media if (!value.IsIdentity) { - Factory factory = Locator.Current.GetService(); + Factory factory = PerspexLocator.Current.GetService(); _transformed = new TransformedGeometry( factory, DefiningGeometry, diff --git a/src/Windows/Perspex.Direct2D1/Media/StreamGeometryImpl.cs b/src/Windows/Perspex.Direct2D1/Media/StreamGeometryImpl.cs index 022a53f8c4..0b91d561b0 100644 --- a/src/Windows/Perspex.Direct2D1/Media/StreamGeometryImpl.cs +++ b/src/Windows/Perspex.Direct2D1/Media/StreamGeometryImpl.cs @@ -4,7 +4,6 @@ using Perspex.Media; using Perspex.Platform; using SharpDX.Direct2D1; -using Splat; using D2DGeometry = SharpDX.Direct2D1.Geometry; namespace Perspex.Direct2D1.Media @@ -21,7 +20,7 @@ namespace Perspex.Direct2D1.Media /// public StreamGeometryImpl() { - Factory factory = Locator.Current.GetService(); + Factory factory = PerspexLocator.Current.GetService(); _path = new PathGeometry(factory); } @@ -46,7 +45,7 @@ namespace Perspex.Direct2D1.Media /// A cloned geometry. public IStreamGeometryImpl Clone() { - Factory factory = Locator.Current.GetService(); + Factory factory = PerspexLocator.Current.GetService(); var result = new PathGeometry(factory); var sink = result.Open(); _path.Stream(sink); diff --git a/src/Windows/Perspex.Direct2D1/Perspex.Direct2D1.csproj b/src/Windows/Perspex.Direct2D1/Perspex.Direct2D1.csproj index 9a981c3bf1..f352a6d7a8 100644 --- a/src/Windows/Perspex.Direct2D1/Perspex.Direct2D1.csproj +++ b/src/Windows/Perspex.Direct2D1/Perspex.Direct2D1.csproj @@ -64,9 +64,6 @@ ..\..\..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll - - ..\..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - diff --git a/src/Windows/Perspex.Direct2D1/Renderer.cs b/src/Windows/Perspex.Direct2D1/Renderer.cs index ca628b08a6..b112dfea65 100644 --- a/src/Windows/Perspex.Direct2D1/Renderer.cs +++ b/src/Windows/Perspex.Direct2D1/Renderer.cs @@ -8,7 +8,6 @@ using Perspex.Platform; using Perspex.Rendering; using SharpDX; using SharpDX.Direct2D1; -using Splat; using DwFactory = SharpDX.DirectWrite.Factory; namespace Perspex.Direct2D1 @@ -28,8 +27,8 @@ namespace Perspex.Direct2D1 /// The height of the window. public Renderer(IntPtr hwnd, double width, double height) { - Direct2DFactory = Locator.Current.GetService(); - DirectWriteFactory = Locator.Current.GetService(); + Direct2DFactory = PerspexLocator.Current.GetService(); + DirectWriteFactory = PerspexLocator.Current.GetService(); RenderTargetProperties renderTargetProperties = new RenderTargetProperties { @@ -54,8 +53,8 @@ namespace Perspex.Direct2D1 /// The render target. public Renderer(RenderTarget renderTarget) { - Direct2DFactory = Locator.Current.GetService(); - DirectWriteFactory = Locator.Current.GetService(); + Direct2DFactory = PerspexLocator.Current.GetService(); + DirectWriteFactory = PerspexLocator.Current.GetService(); _renderTarget = renderTarget; } diff --git a/src/Windows/Perspex.Direct2D1/packages.config b/src/Windows/Perspex.Direct2D1/packages.config index cbf7015309..0c1b74e828 100644 --- a/src/Windows/Perspex.Direct2D1/packages.config +++ b/src/Windows/Perspex.Direct2D1/packages.config @@ -6,5 +6,4 @@ - \ No newline at end of file diff --git a/src/Windows/Perspex.Win32/Perspex.Win32.csproj b/src/Windows/Perspex.Win32/Perspex.Win32.csproj index 8c84a7a307..29adac0267 100644 --- a/src/Windows/Perspex.Win32/Perspex.Win32.csproj +++ b/src/Windows/Perspex.Win32/Perspex.Win32.csproj @@ -58,9 +58,6 @@ ..\..\..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll - - ..\..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - diff --git a/src/Windows/Perspex.Win32/Win32Platform.cs b/src/Windows/Perspex.Win32/Win32Platform.cs index 34a0cda13a..c513fbf97e 100644 --- a/src/Windows/Perspex.Win32/Win32Platform.cs +++ b/src/Windows/Perspex.Win32/Win32Platform.cs @@ -14,7 +14,6 @@ using Perspex.Platform; using Perspex.Shared.PlatformSupport; using Perspex.Win32.Input; using Perspex.Win32.Interop; -using Splat; namespace Perspex.Win32 { @@ -41,29 +40,28 @@ namespace Perspex.Win32 private static void InitializeInternal() { - var locator = Locator.CurrentMutable; - locator.Register(() => new SystemDialogImpl(), typeof (ISystemDialogImpl)); - locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); - locator.Register(() => new ClipboardImpl(), typeof(IClipboard)); - locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice)); - locator.Register(() => WindowsMouseDevice.Instance, typeof(IMouseDevice)); - locator.Register(() => CursorFactory.Instance, typeof(IStandardCursorFactory)); - locator.Register(() => s_instance, typeof(IPlatformSettings)); - locator.Register(() => s_instance, typeof(IPlatformThreadingInterface)); + PerspexLocator.CurrentMutable + .Bind().ToTransient() + .Bind().ToSingleton() + .Bind().ToConstant(CursorFactory.Instance) + .Bind().ToConstant(WindowsKeyboardDevice.Instance) + .Bind().ToConstant(WindowsMouseDevice.Instance) + .Bind().ToConstant(s_instance) + .Bind().ToConstant(s_instance) + .Bind().ToSingleton(); + SharedPlatform.Register(); } public static void Initialize() { - var locator = Locator.CurrentMutable; - locator.Register(() => new WindowImpl(), typeof(IWindowImpl)); + PerspexLocator.CurrentMutable.Bind().ToTransient(); InitializeInternal(); } public static void InitializeEmbedded() { - var locator = Locator.CurrentMutable; - locator.Register(() => new EmbeddedWindowImpl(), typeof(IWindowImpl)); + PerspexLocator.CurrentMutable.Bind().ToTransient(); InitializeInternal(); } diff --git a/src/Windows/Perspex.Win32/packages.config b/src/Windows/Perspex.Win32/packages.config index db96d1825a..571e4fe023 100644 --- a/src/Windows/Perspex.Win32/packages.config +++ b/src/Windows/Perspex.Win32/packages.config @@ -5,5 +5,4 @@ - \ No newline at end of file diff --git a/tests/Perspex.Base.UnitTests/Perspex.Base.UnitTests.csproj b/tests/Perspex.Base.UnitTests/Perspex.Base.UnitTests.csproj index e4f9b39569..fe60b3f768 100644 --- a/tests/Perspex.Base.UnitTests/Perspex.Base.UnitTests.csproj +++ b/tests/Perspex.Base.UnitTests/Perspex.Base.UnitTests.csproj @@ -47,9 +47,6 @@ ..\..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll diff --git a/tests/Perspex.Base.UnitTests/packages.config b/tests/Perspex.Base.UnitTests/packages.config index 4f02ad6cd2..b87bf5fff7 100644 --- a/tests/Perspex.Base.UnitTests/packages.config +++ b/tests/Perspex.Base.UnitTests/packages.config @@ -3,7 +3,6 @@ - diff --git a/tests/Perspex.Controls.UnitTests/ContentControlTests.cs b/tests/Perspex.Controls.UnitTests/ContentControlTests.cs index 6c5b6bc59f..a946e91d5b 100644 --- a/tests/Perspex.Controls.UnitTests/ContentControlTests.cs +++ b/tests/Perspex.Controls.UnitTests/ContentControlTests.cs @@ -13,7 +13,6 @@ using Perspex.Styling; using Perspex.VisualTree; using Ploeh.AutoFixture; using Ploeh.AutoFixture.AutoMoq; -using Splat; using Xunit; namespace Perspex.Controls.UnitTests @@ -49,7 +48,7 @@ namespace Perspex.Controls.UnitTests var target = new ContentControl(); var styler = new Mock(); - Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler)); + PerspexLocator.CurrentMutable.Bind().ToConstant(styler.Object); target.Content = "Foo"; target.Template = GetTemplate(); root.Child = target; @@ -281,10 +280,11 @@ namespace Perspex.Controls.UnitTests private IDisposable RegisterServices() { - var result = Locator.CurrentMutable.WithResolver(); + var result = PerspexLocator.EnterScope(); var fixture = new Fixture().Customize(new AutoMoqCustomization()); var renderInterface = fixture.Create(); - Locator.CurrentMutable.RegisterConstant(renderInterface, typeof(IPlatformRenderInterface)); + PerspexLocator.CurrentMutable + .Bind().ToConstant(renderInterface); return result; } } diff --git a/tests/Perspex.Controls.UnitTests/ControlTests.cs b/tests/Perspex.Controls.UnitTests/ControlTests.cs index 202226a67d..4a801fc0e9 100644 --- a/tests/Perspex.Controls.UnitTests/ControlTests.cs +++ b/tests/Perspex.Controls.UnitTests/ControlTests.cs @@ -7,7 +7,6 @@ using Perspex.Layout; using Perspex.Platform; using Perspex.Rendering; using Perspex.Styling; -using Splat; using Xunit; namespace Perspex.Controls.UnitTests @@ -25,13 +24,13 @@ namespace Perspex.Controls.UnitTests [Fact] public void Adding_Control_To_IRenderRoot_Should_Style_Control() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { var root = new TestRoot(); var target = new Control(); var styler = new Mock(); - Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler)); + PerspexLocator.CurrentMutable.Bind().ToConstant(styler.Object); root.Child = target; @@ -42,7 +41,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Adding_Tree_To_ILayoutRoot_Should_Style_Controls() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { var root = new TestRoot(); var parent = new Border(); @@ -50,7 +49,7 @@ namespace Perspex.Controls.UnitTests var grandchild = new Control(); var styler = new Mock(); - Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler)); + PerspexLocator.CurrentMutable.Bind().ToConstant(styler.Object); parent.Child = child; child.Child = grandchild; diff --git a/tests/Perspex.Controls.UnitTests/DropDownTests.cs b/tests/Perspex.Controls.UnitTests/DropDownTests.cs index ed5bebdcf7..a60f0fe86a 100644 --- a/tests/Perspex.Controls.UnitTests/DropDownTests.cs +++ b/tests/Perspex.Controls.UnitTests/DropDownTests.cs @@ -9,7 +9,6 @@ using Perspex.Controls.Templates; using Perspex.Platform; using Ploeh.AutoFixture; using Ploeh.AutoFixture.AutoMoq; -using Splat; using Xunit; namespace Perspex.Controls.UnitTests @@ -58,10 +57,11 @@ namespace Perspex.Controls.UnitTests private IDisposable RegisterServices() { - var result = Locator.CurrentMutable.WithResolver(); + var result = PerspexLocator.EnterScope(); var fixture = new Fixture().Customize(new AutoMoqCustomization()); var renderInterface = fixture.Create(); - Locator.CurrentMutable.RegisterConstant(renderInterface, typeof(IPlatformRenderInterface)); + PerspexLocator.CurrentMutable.Bind().ToConstant(renderInterface); + return result; } } diff --git a/tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj b/tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj index 3389497951..6e31a61a8e 100644 --- a/tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj +++ b/tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj @@ -59,9 +59,6 @@ ..\..\packages\AutoFixture.AutoMoq.3.31.1\lib\net40\Ploeh.AutoFixture.AutoMoq.dll - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll diff --git a/tests/Perspex.Controls.UnitTests/Primitives/PopupTests.cs b/tests/Perspex.Controls.UnitTests/Primitives/PopupTests.cs index 229f31c1f2..30ed62dca0 100644 --- a/tests/Perspex.Controls.UnitTests/Primitives/PopupTests.cs +++ b/tests/Perspex.Controls.UnitTests/Primitives/PopupTests.cs @@ -13,7 +13,6 @@ using Perspex.LogicalTree; using Perspex.Platform; using Perspex.Styling; using Perspex.VisualTree; -using Splat; using Xunit; namespace Perspex.Controls.UnitTests.Primitives @@ -248,7 +247,7 @@ namespace Perspex.Controls.UnitTests.Primitives private static IDisposable CreateServices() { - var result = Locator.Current.WithResolver(); + var result = PerspexLocator.EnterScope(); var styles = new Styles { @@ -264,11 +263,14 @@ namespace Perspex.Controls.UnitTests.Primitives var globalStyles = new Mock(); globalStyles.Setup(x => x.Styles).Returns(styles); - Locator.CurrentMutable.Register(() => globalStyles.Object, typeof(IGlobalStyles)); - Locator.CurrentMutable.Register(() => new LayoutManager(), typeof(ILayoutManager)); - Locator.CurrentMutable.Register(() => new Mock().Object, typeof(IPlatformThreadingInterface)); - Locator.CurrentMutable.Register(() => new Mock().Object, typeof(IPopupImpl)); - Locator.CurrentMutable.Register(() => new Styler(), typeof(IStyler)); + + PerspexLocator.CurrentMutable + .Bind().ToTransient() + .Bind().ToFunc(() => globalStyles.Object) + .Bind().ToConstant(new Mock().Object) + .Bind().ToConstant(new Mock().Object) + .Bind().ToTransient(); + return result; } diff --git a/tests/Perspex.Controls.UnitTests/TemplatedControlTests.cs b/tests/Perspex.Controls.UnitTests/TemplatedControlTests.cs index 7654531089..6177574dc0 100644 --- a/tests/Perspex.Controls.UnitTests/TemplatedControlTests.cs +++ b/tests/Perspex.Controls.UnitTests/TemplatedControlTests.cs @@ -9,7 +9,6 @@ using Perspex.Controls.Primitives; using Perspex.Controls.Templates; using Perspex.Styling; using Perspex.VisualTree; -using Splat; using Xunit; namespace Perspex.Controls.UnitTests @@ -143,10 +142,11 @@ namespace Perspex.Controls.UnitTests [Fact] public void Templated_Children_Should_Be_Styled() { - using (Locator.Current.WithResolver()) + using (PerspexLocator.EnterScope()) { var styler = new Mock(); - Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler)); + + PerspexLocator.CurrentMutable.Bind().ToConstant(styler.Object); TestTemplatedControl target; diff --git a/tests/Perspex.Controls.UnitTests/TopLevelTests.cs b/tests/Perspex.Controls.UnitTests/TopLevelTests.cs index 5e7a7531fb..899d5da151 100644 --- a/tests/Perspex.Controls.UnitTests/TopLevelTests.cs +++ b/tests/Perspex.Controls.UnitTests/TopLevelTests.cs @@ -14,7 +14,6 @@ using Perspex.Rendering; using Perspex.Styling; using Ploeh.AutoFixture; using Ploeh.AutoFixture.AutoMoq; -using Splat; using Xunit; namespace Perspex.Controls.UnitTests @@ -24,7 +23,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void ClientSize_Should_Be_Set_On_Construction() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -40,7 +39,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Width_Should_Not_Be_Set_On_Construction() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -56,7 +55,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Height_Should_Not_Be_Set_On_Construction() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -72,7 +71,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Layout_Pass_Should_Not_Be_Automatically_Scheduled() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -88,10 +87,10 @@ namespace Perspex.Controls.UnitTests [Fact] public void Bounds_Should_Be_Set_After_Layout_Pass() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); - Locator.CurrentMutable.RegisterConstant(new LayoutManager(), typeof(ILayoutManager)); + PerspexLocator.CurrentMutable.Bind().ToConstant(new LayoutManager()); var impl = new Mock(); impl.SetupProperty(x => x.ClientSize); @@ -120,10 +119,10 @@ namespace Perspex.Controls.UnitTests [Fact] public void Impl_ClientSize_Should_Be_Set_After_Layout_Pass() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); - Locator.CurrentMutable.RegisterConstant(new LayoutManager(), typeof(ILayoutManager)); + PerspexLocator.CurrentMutable.Bind().ToConstant(new LayoutManager()); var impl = new Mock(); @@ -150,7 +149,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Width_And_Height_Should_Not_Be_Set_After_Layout_Pass() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -168,11 +167,11 @@ namespace Perspex.Controls.UnitTests [Fact] public void Render_Should_Be_Scheduled_After_Layout_Pass() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); var completed = new Subject(); - var layoutManagerMock = Mock.Get(Locator.Current.GetService()); + var layoutManagerMock = Mock.Get(PerspexLocator.Current.GetService()); layoutManagerMock.Setup(x => x.LayoutCompleted).Returns(completed); var impl = new Mock(); @@ -181,7 +180,7 @@ namespace Perspex.Controls.UnitTests var target = new TestTopLevel(impl.Object); completed.OnNext(Unit.Default); - var renderManagerMock = Mock.Get(Locator.Current.GetService()); + var renderManagerMock = Mock.Get(PerspexLocator.Current.GetService()); renderManagerMock.Verify(x => x.InvalidateRender(target)); } } @@ -189,7 +188,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Width_And_Height_Should_Be_Set_After_Window_Resize_Notification() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -209,7 +208,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Activate_Should_Call_Impl_Activate() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -225,7 +224,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Impl_Activate_Should_Call_Raise_Activated_Event() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -245,7 +244,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Impl_Close_Should_Call_Raise_Closed_Event() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -265,7 +264,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Impl_Deactivate_Should_Call_Raise_Activated_Event() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -285,7 +284,7 @@ namespace Perspex.Controls.UnitTests [Fact] public void Impl_Input_Should_Pass_Input_To_InputManager() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { RegisterServices(); @@ -308,7 +307,7 @@ namespace Perspex.Controls.UnitTests private void RegisterServices() { var fixture = new Fixture().Customize(new AutoMoqCustomization()); - var l = Locator.CurrentMutable; + var l = PerspexLocator.CurrentMutable; var formattedText = fixture.Create(); var globalStyles = new Mock(); @@ -320,14 +319,16 @@ namespace Perspex.Controls.UnitTests globalStyles.Setup(x => x.Styles).Returns(theme); - l.RegisterConstant(new Mock().Object, typeof(IInputManager)); - l.RegisterConstant(new Mock().Object, typeof(IFocusManager)); - l.RegisterConstant(globalStyles.Object, typeof(IGlobalStyles)); - l.RegisterConstant(layoutManager, typeof(ILayoutManager)); - l.RegisterConstant(new Mock().Object, typeof(IPlatformThreadingInterface)); - l.RegisterConstant(renderInterface, typeof(IPlatformRenderInterface)); - l.RegisterConstant(renderManager, typeof(IRenderManager)); - l.RegisterConstant(new Styler(), typeof(IStyler)); + + PerspexLocator.CurrentMutable + .Bind().ToConstant(new Mock().Object) + .Bind().ToConstant(new Mock().Object) + .Bind().ToConstant(globalStyles.Object) + .Bind().ToConstant(layoutManager) + .Bind().ToConstant(renderInterface) + .Bind().ToConstant(new Mock().Object) + .Bind().ToConstant(renderManager) + .Bind().ToConstant(new Styler()); } private class TestTopLevel : TopLevel diff --git a/tests/Perspex.Controls.UnitTests/packages.config b/tests/Perspex.Controls.UnitTests/packages.config index b0d4f14c88..3c8dccc01e 100644 --- a/tests/Perspex.Controls.UnitTests/packages.config +++ b/tests/Perspex.Controls.UnitTests/packages.config @@ -8,7 +8,6 @@ - diff --git a/tests/Perspex.Direct2D1.UnitTests/Controls/Shapes/PathTests.cs b/tests/Perspex.Direct2D1.UnitTests/Controls/Shapes/PathTests.cs index cd5d318117..11747e7f04 100644 --- a/tests/Perspex.Direct2D1.UnitTests/Controls/Shapes/PathTests.cs +++ b/tests/Perspex.Direct2D1.UnitTests/Controls/Shapes/PathTests.cs @@ -4,7 +4,6 @@ using Perspex.Controls.Shapes; using Perspex.Layout; using Perspex.Media; -using Splat; using Xunit; namespace Perspex.Direct2D1.UnitTests.Controls.Shapes @@ -16,7 +15,7 @@ namespace Perspex.Direct2D1.UnitTests.Controls.Shapes [Fact] public void Should_Measure_Expander_Triangle_Correctly() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { Direct2D1Platform.Initialize(); @@ -39,7 +38,7 @@ namespace Perspex.Direct2D1.UnitTests.Controls.Shapes [Fact] public void Should_Measure_Expander_Triangle_With_Stroke_Correctly() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { Direct2D1Platform.Initialize(); diff --git a/tests/Perspex.Direct2D1.UnitTests/Media/GeometryTests.cs b/tests/Perspex.Direct2D1.UnitTests/Media/GeometryTests.cs index de46378d00..e87c15eb19 100644 --- a/tests/Perspex.Direct2D1.UnitTests/Media/GeometryTests.cs +++ b/tests/Perspex.Direct2D1.UnitTests/Media/GeometryTests.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using Perspex.Media; -using Splat; using Xunit; namespace Perspex.Direct2D1.UnitTests.Media @@ -14,7 +13,7 @@ namespace Perspex.Direct2D1.UnitTests.Media [Fact] public void Should_Measure_Expander_Triangle_Correctly() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { Direct2D1Platform.Initialize(); @@ -27,7 +26,7 @@ namespace Perspex.Direct2D1.UnitTests.Media [Fact] public void Should_Measure_Expander_Triangle_With_Stroke_Correctly() { - using (Locator.CurrentMutable.WithResolver()) + using (PerspexLocator.EnterScope()) { Direct2D1Platform.Initialize(); diff --git a/tests/Perspex.Direct2D1.UnitTests/Perspex.Direct2D1.UnitTests.csproj b/tests/Perspex.Direct2D1.UnitTests/Perspex.Direct2D1.UnitTests.csproj index 24ad4cca75..2e5748bf0f 100644 --- a/tests/Perspex.Direct2D1.UnitTests/Perspex.Direct2D1.UnitTests.csproj +++ b/tests/Perspex.Direct2D1.UnitTests/Perspex.Direct2D1.UnitTests.csproj @@ -44,9 +44,6 @@ - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll diff --git a/tests/Perspex.Direct2D1.UnitTests/packages.config b/tests/Perspex.Direct2D1.UnitTests/packages.config index 979ca3a8ef..ce1d9d0407 100644 --- a/tests/Perspex.Direct2D1.UnitTests/packages.config +++ b/tests/Perspex.Direct2D1.UnitTests/packages.config @@ -1,6 +1,5 @@  - diff --git a/tests/Perspex.Input.UnitTests/Perspex.Input.UnitTests.csproj b/tests/Perspex.Input.UnitTests/Perspex.Input.UnitTests.csproj index ddfa8ad1a7..e63ccac17e 100644 --- a/tests/Perspex.Input.UnitTests/Perspex.Input.UnitTests.csproj +++ b/tests/Perspex.Input.UnitTests/Perspex.Input.UnitTests.csproj @@ -44,9 +44,6 @@ - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll diff --git a/tests/Perspex.Input.UnitTests/packages.config b/tests/Perspex.Input.UnitTests/packages.config index 979ca3a8ef..ce1d9d0407 100644 --- a/tests/Perspex.Input.UnitTests/packages.config +++ b/tests/Perspex.Input.UnitTests/packages.config @@ -1,6 +1,5 @@  - diff --git a/tests/Perspex.Interactivity.UnitTests/Perspex.Interactivity.UnitTests.csproj b/tests/Perspex.Interactivity.UnitTests/Perspex.Interactivity.UnitTests.csproj index 3ea7c3f38c..fee8683fa4 100644 --- a/tests/Perspex.Interactivity.UnitTests/Perspex.Interactivity.UnitTests.csproj +++ b/tests/Perspex.Interactivity.UnitTests/Perspex.Interactivity.UnitTests.csproj @@ -49,9 +49,6 @@ ..\..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll diff --git a/tests/Perspex.Interactivity.UnitTests/packages.config b/tests/Perspex.Interactivity.UnitTests/packages.config index 979ca3a8ef..ce1d9d0407 100644 --- a/tests/Perspex.Interactivity.UnitTests/packages.config +++ b/tests/Perspex.Interactivity.UnitTests/packages.config @@ -1,6 +1,5 @@  - diff --git a/tests/Perspex.Layout.UnitTests/FullLayoutTests.cs b/tests/Perspex.Layout.UnitTests/FullLayoutTests.cs index 97b4d97805..fb714e5278 100644 --- a/tests/Perspex.Layout.UnitTests/FullLayoutTests.cs +++ b/tests/Perspex.Layout.UnitTests/FullLayoutTests.cs @@ -17,7 +17,6 @@ using Perspex.Styling; using Perspex.Themes.Default; using Ploeh.AutoFixture; using Ploeh.AutoFixture.AutoMoq; -using Splat; using Xunit; namespace Perspex.Layout.UnitTests @@ -27,7 +26,7 @@ namespace Perspex.Layout.UnitTests [Fact] public void Grandchild_Size_Changed() { - using (var context = Locator.CurrentMutable.WithResolver()) + using (var context = PerspexLocator.EnterScope()) { RegisterServices(); @@ -66,7 +65,7 @@ namespace Perspex.Layout.UnitTests [Fact] public void Test_ScrollViewer_With_TextBlock() { - using (var context = Locator.CurrentMutable.WithResolver()) + using (var context = PerspexLocator.EnterScope()) { RegisterServices(); @@ -130,7 +129,7 @@ namespace Perspex.Layout.UnitTests private void RegisterServices() { var fixture = new Fixture().Customize(new AutoMoqCustomization()); - var l = Locator.CurrentMutable; + var formattedText = fixture.Create(); var globalStyles = new Mock(); @@ -143,14 +142,15 @@ namespace Perspex.Layout.UnitTests windowImpl.Setup(x => x.MaxClientSize).Returns(new Size(1024, 1024)); globalStyles.Setup(x => x.Styles).Returns(theme); - l.RegisterConstant(new Mock().Object, typeof(IInputManager)); - l.RegisterConstant(globalStyles.Object, typeof(IGlobalStyles)); - l.RegisterConstant(new LayoutManager(), typeof(ILayoutManager)); - l.RegisterConstant(renderInterface, typeof(IPlatformRenderInterface)); - l.RegisterConstant(new Mock().Object, typeof(IPlatformThreadingInterface)); - l.RegisterConstant(renderManager, typeof(IRenderManager)); - l.RegisterConstant(new Styler(), typeof(IStyler)); - l.RegisterConstant(windowImpl.Object, typeof(IWindowImpl)); + PerspexLocator.CurrentMutable + .Bind().ToConstant(new Mock().Object) + .Bind().ToConstant(globalStyles.Object) + .Bind().ToConstant(new LayoutManager()) + .Bind().ToConstant(renderInterface) + .Bind().ToConstant(new Mock().Object) + .Bind().ToConstant(renderManager) + .Bind().ToConstant(new Styler()) + .Bind().ToConstant(windowImpl.Object); } } } diff --git a/tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj b/tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj index e558a11fd5..e849ae0b25 100644 --- a/tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj +++ b/tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj @@ -56,9 +56,6 @@ ..\..\packages\AutoFixture.AutoMoq.3.31.1\lib\net40\Ploeh.AutoFixture.AutoMoq.dll - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll diff --git a/tests/Perspex.Layout.UnitTests/packages.config b/tests/Perspex.Layout.UnitTests/packages.config index 8190084b07..a031cf84fd 100644 --- a/tests/Perspex.Layout.UnitTests/packages.config +++ b/tests/Perspex.Layout.UnitTests/packages.config @@ -3,7 +3,6 @@ - diff --git a/tests/Perspex.RenderTests/Perspex.Cairo.RenderTests.csproj b/tests/Perspex.RenderTests/Perspex.Cairo.RenderTests.csproj index ac99be3bdf..60b3b02b11 100644 --- a/tests/Perspex.RenderTests/Perspex.Cairo.RenderTests.csproj +++ b/tests/Perspex.RenderTests/Perspex.Cairo.RenderTests.csproj @@ -53,9 +53,6 @@ ..\..\packages\Magick.NET-Q16-AnyCPU.7.0.0.0018\lib\net40-client\Magick.NET.Core.dll - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll diff --git a/tests/Perspex.RenderTests/packages.config b/tests/Perspex.RenderTests/packages.config index 1ae00bc4cd..c447f9c0e9 100644 --- a/tests/Perspex.RenderTests/packages.config +++ b/tests/Perspex.RenderTests/packages.config @@ -1,7 +1,6 @@  - diff --git a/tests/Perspex.SceneGraph.UnitTests/Perspex.SceneGraph.UnitTests.csproj b/tests/Perspex.SceneGraph.UnitTests/Perspex.SceneGraph.UnitTests.csproj index 4e49c5c307..e48d6ac73b 100644 --- a/tests/Perspex.SceneGraph.UnitTests/Perspex.SceneGraph.UnitTests.csproj +++ b/tests/Perspex.SceneGraph.UnitTests/Perspex.SceneGraph.UnitTests.csproj @@ -47,9 +47,6 @@ ..\..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll diff --git a/tests/Perspex.SceneGraph.UnitTests/packages.config b/tests/Perspex.SceneGraph.UnitTests/packages.config index a2ad2a99ca..8cbc4ec26f 100644 --- a/tests/Perspex.SceneGraph.UnitTests/packages.config +++ b/tests/Perspex.SceneGraph.UnitTests/packages.config @@ -5,7 +5,6 @@ - diff --git a/tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj b/tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj index 180f5f313d..4099319b5a 100644 --- a/tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj +++ b/tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj @@ -50,9 +50,6 @@ ..\..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll - - ..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - ..\..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll diff --git a/tests/Perspex.Styling.UnitTests/packages.config b/tests/Perspex.Styling.UnitTests/packages.config index 3be7c908b3..3cf2b984d5 100644 --- a/tests/Perspex.Styling.UnitTests/packages.config +++ b/tests/Perspex.Styling.UnitTests/packages.config @@ -6,7 +6,6 @@ - From bed653012fd871f17cf7bdfb6e3460dbf3fae51d Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 25 Sep 2015 00:10:48 +0300 Subject: [PATCH 20/24] Revert to original Splat's behavior --- src/Perspex.Base/PerspexLocator.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Perspex.Base/PerspexLocator.cs b/src/Perspex.Base/PerspexLocator.cs index 262ffda8d8..8a9038c13e 100644 --- a/src/Perspex.Base/PerspexLocator.cs +++ b/src/Perspex.Base/PerspexLocator.cs @@ -30,12 +30,7 @@ namespace Perspex public object GetService(Type t) { Func rv; - if (_registry.TryGetValue(t, out rv)) - return rv(); - var parentRv = _parentScope?.GetService(t); - if (parentRv != null) - return parentRv; - throw new TypeLoadException("Unable to find registrations for service " + t); + return _registry.TryGetValue(t, out rv) ? rv() : _parentScope?.GetService(t); } public class RegistrationHelper @@ -94,11 +89,24 @@ namespace Perspex } } + class NullDisposable : IDisposable + { + public void Dispose() + { + + } + } + public static IDisposable EnterScope() { + return new NullDisposable(); + + //Switch to that code when we are ready to fix tests + /* var d = new ResolverDisposable(Current, CurrentMutable); Current = CurrentMutable = new PerspexLocator(Current); return d; + */ } } From 2d0e4ae0c7bdd7fe2b9e833a40017af8b90e3801 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 25 Sep 2015 00:21:43 +0300 Subject: [PATCH 21/24] Removed NullDisposable --- src/Perspex.Base/PerspexLocator.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Perspex.Base/PerspexLocator.cs b/src/Perspex.Base/PerspexLocator.cs index 8a9038c13e..521cb263db 100644 --- a/src/Perspex.Base/PerspexLocator.cs +++ b/src/Perspex.Base/PerspexLocator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Reactive.Disposables; #pragma warning disable CS1591 // Enable me later @@ -89,25 +90,17 @@ namespace Perspex } } - class NullDisposable : IDisposable - { - public void Dispose() - { - - } - } public static IDisposable EnterScope() { - return new NullDisposable(); - + return Disposable.Empty; //Switch to that code when we are ready to fix tests /* var d = new ResolverDisposable(Current, CurrentMutable); Current = CurrentMutable = new PerspexLocator(Current); return d; */ - + } } From 8309adf6dac298b5c78b754f064bfdeb40e47933 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 25 Sep 2015 00:35:11 +0100 Subject: [PATCH 22/24] Implemented caret inverting background colour. --- src/Perspex.Controls/Presenters/TextPresenter.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Perspex.Controls/Presenters/TextPresenter.cs b/src/Perspex.Controls/Presenters/TextPresenter.cs index d594d6495b..4d1dccfb52 100644 --- a/src/Perspex.Controls/Presenters/TextPresenter.cs +++ b/src/Perspex.Controls/Presenters/TextPresenter.cs @@ -93,7 +93,17 @@ namespace Perspex.Controls.Presenters if (selectionStart == selectionEnd) { var charPos = FormattedText.HitTestTextPosition(CaretIndex); - Brush caretBrush = Brushes.Black; + + var background = this.GetVisualAncestors() + .OfType() + .FirstOrDefault(x => x.IsSet(BackgroundProperty)) + ?.GetValue(BackgroundProperty) as SolidColorBrush; + + byte red = (byte)~(background.Color.R); + byte green = (byte)~(background.Color.G); + byte blue = (byte)~(background.Color.B); + + var caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); if (_caretBlink) { From c56b7bd0ed3e7f10bdb7106e53a250aaf1caf893 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 25 Sep 2015 00:50:45 +0100 Subject: [PATCH 23/24] Implemented Caret inverting background colour, by finding templated parent. --- src/Perspex.Controls/Presenters/TextPresenter.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Perspex.Controls/Presenters/TextPresenter.cs b/src/Perspex.Controls/Presenters/TextPresenter.cs index 4d1dccfb52..6aed45893e 100644 --- a/src/Perspex.Controls/Presenters/TextPresenter.cs +++ b/src/Perspex.Controls/Presenters/TextPresenter.cs @@ -94,14 +94,11 @@ namespace Perspex.Controls.Presenters { var charPos = FormattedText.HitTestTextPosition(CaretIndex); - var background = this.GetVisualAncestors() - .OfType() - .FirstOrDefault(x => x.IsSet(BackgroundProperty)) - ?.GetValue(BackgroundProperty) as SolidColorBrush; - - byte red = (byte)~(background.Color.R); - byte green = (byte)~(background.Color.G); - byte blue = (byte)~(background.Color.B); + var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush).Color; + + byte red = (byte)~(backgroundColor.R); + byte green = (byte)~(backgroundColor.G); + byte blue = (byte)~(backgroundColor.B); var caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); From 65a133a440f772bad8604b0418ae892f942a702e Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 25 Sep 2015 01:02:30 +0100 Subject: [PATCH 24/24] Implemented caret inverting background color. --- src/Perspex.Controls/Presenters/TextPresenter.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Perspex.Controls/Presenters/TextPresenter.cs b/src/Perspex.Controls/Presenters/TextPresenter.cs index 6aed45893e..9679ba78a1 100644 --- a/src/Perspex.Controls/Presenters/TextPresenter.cs +++ b/src/Perspex.Controls/Presenters/TextPresenter.cs @@ -93,15 +93,19 @@ namespace Perspex.Controls.Presenters if (selectionStart == selectionEnd) { var charPos = FormattedText.HitTestTextPosition(CaretIndex); - - var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush).Color; - byte red = (byte)~(backgroundColor.R); - byte green = (byte)~(backgroundColor.G); - byte blue = (byte)~(backgroundColor.B); + var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush)?.Color; + var caretBrush = Brushes.Black; - var caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); + if(backgroundColor.HasValue) + { + byte red = (byte)~(backgroundColor.Value.R); + byte green = (byte)~(backgroundColor.Value.G); + byte blue = (byte)~(backgroundColor.Value.B); + caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); + } + if (_caretBlink) { var x = Math.Floor(charPos.X) + 0.5;