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/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 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` 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 52030934a1..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 @@ -85,10 +86,6 @@ - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation 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/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(); }); } diff --git a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs index 0cbfc50097..160e6e04b4 100644 --- a/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs +++ b/src/Gtk/Perspex.Cairo/Media/FormattedTextImpl.cs @@ -4,15 +4,16 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using Perspex.Media; using Perspex.Platform; -using Splat; namespace Perspex.Cairo.Media { public class FormattedTextImpl : IFormattedTextImpl { private Size _size; + private string _text; public FormattedTextImpl( Pango.Context context, @@ -26,6 +27,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 +51,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 +82,8 @@ namespace Perspex.Cairo.Media out textPosition, out trailing); + textPosition = PangoIndexToTextIndex(textPosition); + return new TextHitTestResult { IsInside = isInside, @@ -88,9 +92,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 +138,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); } 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 f6aa72ba5b..e6c2db7c9c 100644 --- a/src/Gtk/Perspex.Gtk/GtkPlatform.cs +++ b/src/Gtk/Perspex.Gtk/GtkPlatform.cs @@ -3,11 +3,11 @@ using System; using System.Reactive.Disposables; +using Perspex.Controls.Platform; using Perspex.Input.Platform; using Perspex.Input; using Perspex.Platform; using Perspex.Shared.PlatformSupport; -using Splat; namespace Perspex.Gtk { @@ -28,14 +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)); + 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/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 } diff --git a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj index 828c09d532..1d286b3bf0 100644 --- a/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj +++ b/src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj @@ -44,12 +44,10 @@ ..\..\..\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/SystemDialogImpl.cs b/src/Gtk/Perspex.Gtk/SystemDialogImpl.cs new file mode 100644 index 0000000000..869bd2eb70 --- /dev/null +++ b/src/Gtk/Perspex.Gtk/SystemDialogImpl.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 SystemDialogImpl : ISystemDialogImpl + { + public Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) + { + var tcs = new TaskCompletionSource(); + var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl) parent), + dialog is OpenFileDialog + ? FileChooserAction.Open + : FileChooserAction.Save, + "Cancel", ResponseType.Cancel, + "Open", ResponseType.Accept) + { + SelectMultiple = (dialog as OpenFileDialog)?.AllowMultiple ?? false, + }; + 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/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; 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/OmniXAML b/src/Markup/Perspex.Markup.Xaml/OmniXAML index 586e2e521c..1461be589a 160000 --- a/src/Markup/Perspex.Markup.Xaml/OmniXAML +++ b/src/Markup/Perspex.Markup.Xaml/OmniXAML @@ -1 +1 @@ -Subproject commit 586e2e521c85a4b111c394e8aee178bbdfc9c1df +Subproject commit 1461be589a5d39d378fd177648c61a780271c742 diff --git a/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj b/src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj index 4fe8fda36a..243e7b5e5a 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 @@ + @@ -289,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 e69bcfdf81..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( @@ -65,17 +64,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); } @@ -90,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/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.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/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/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 2adf2545a2..d90087add4 100644 --- a/src/Perspex.Base/Perspex.Base.csproj +++ b/src/Perspex.Base/Perspex.Base.csproj @@ -46,6 +46,7 @@ + @@ -93,20 +94,11 @@ ..\..\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 - - - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - - - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation @@ -84,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/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), 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/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; } } 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/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..29adac0267 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 @@ -56,15 +58,13 @@ ..\..\..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll - - ..\..\..\packages\Splat.1.6.2\lib\Net45\Splat.dll - Properties\SharedAssemblyInfo.cs + diff --git a/src/Windows/Perspex.Win32/SystemDialogImpl.cs b/src/Windows/Perspex.Win32/SystemDialogImpl.cs new file mode 100644 index 0000000000..71b0b58e87 --- /dev/null +++ b/src/Windows/Perspex.Win32/SystemDialogImpl.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 SystemDialogImpl : ISystemDialogImpl + { + public unsafe Task ShowFileDialogAsync(FileDialog 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 defExt = (dialog as SaveFileDialog)?.DefaultExtension; + var buffer = new char[256]; + fixed (char* pBuffer = buffer) + fixed (char* pFilterBuffer = filterBuffer) + fixed (char* pDefExt = defExt) + 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 as OpenFileDialog)?.AllowMultiple == true) + ofn.Flags |= UnmanagedMethods.OpenFileNameFlags.OFN_ALLOWMULTISELECT; + + if (dialog is SaveFileDialog) + ofn.Flags |= UnmanagedMethods.OpenFileNameFlags.OFN_NOREADONLYRETURN | + UnmanagedMethods.OpenFileNameFlags.OFN_OVERWRITEPROMPT; + + var pofn = &ofn; + + var res = dialog is OpenFileDialog + ? 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/Win32Platform.cs b/src/Windows/Perspex.Win32/Win32Platform.cs index e0fa7d9d5b..c513fbf97e 100644 --- a/src/Windows/Perspex.Win32/Win32Platform.cs +++ b/src/Windows/Perspex.Win32/Win32Platform.cs @@ -8,12 +8,12 @@ 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; using Perspex.Win32.Input; using Perspex.Win32.Interop; -using Splat; namespace Perspex.Win32 { @@ -40,28 +40,28 @@ namespace Perspex.Win32 private static void InitializeInternal() { - var locator = Locator.CurrentMutable; - 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 c326093c84..ac46237a33 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 64ff11dc9d..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 @@ -64,10 +61,6 @@ - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation 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 fd31d43a43..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 @@ -76,10 +73,6 @@ - - {415E048E-4611-4815-9CF2-D774E29079AC} - NGenerics - {D211E587-D8BC-45B9-95A4-F297C8FA5200} Perspex.Animation 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.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 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 @@ -