From aededd6a35fd4ad2afcb98038c147fddceac2646 Mon Sep 17 00:00:00 2001 From: gumme Date: Mon, 23 Jun 2014 12:10:38 +0200 Subject: [PATCH 1/2] Moving controls several steps by holding down arrow keys is now working again. Removed canvas special handling in DesignPanel and instead letting each placement behavior handle its own special needs, and handling the Canvas issue by overriding GetPosition in CanvasPlacementSupport instead. Fixed SetPosition in CanvasPlacementSupport so Left/Top properties have priority over Right/Bottom, as this is the priority that the runtime uses. --- .../WpfDesign.Designer/Project/DesignPanel.cs | 41 +++++++++------- .../Extensions/CanvasPlacementSupport.cs | 48 ++++++++++++++----- 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index 48fee4dbe8..85d3229f24 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -377,28 +377,35 @@ namespace ICSharpCode.WpfDesign.Designer placementOp = PlacementOperation.Start(Context.Services.Selection.SelectedItems, PlacementType.Move); } + switch (e.Key) { + case Key.Left: + dx += Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1; + break; + case Key.Up: + dy += Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1; + break; + case Key.Right: + dx += Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1; + break; + case Key.Down: + dy += Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1; + break; + } - dx = (e.Key == Key.Left) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0; - dy = (e.Key == Key.Up) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0; - dx = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : (dx != 0 ? dx : 0); - dy = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : (dy != 0 ? dy : 0); - double left, top; foreach (PlacementInformation info in placementOp.PlacedItems) { - //Let canvas position preceed bounds definition since there can be a discrepancy between them. - left = IsPropertySet(info.Item.View,Canvas.LeftProperty)?(double)info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance: info.OriginalBounds.Left; - - top = IsPropertySet(info.Item.View, Canvas.TopProperty) ? (double)info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance : info.OriginalBounds.Top; + var bounds = info.OriginalBounds; + if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { - info.Bounds = new Rect(left + dx, - top + dy, - info.OriginalBounds.Width, - info.OriginalBounds.Height); + info.Bounds = new Rect(bounds.Left + dx, + bounds.Top + dy, + bounds.Width, + bounds.Height); } else { - info.Bounds = new Rect(left, - top, - info.OriginalBounds.Width + dx, - info.OriginalBounds.Height + dy); + info.Bounds = new Rect(bounds.Left, + bounds.Top, + bounds.Width + dx, + bounds.Height + dy); } placementOp.CurrentContainerBehavior.SetPosition(info); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs index 206796fda3..bc776c99ca 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs @@ -58,6 +58,32 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions extendedView = (FrameworkElement)this.ExtendedItem.View; } + public override Rect GetPosition(PlacementOperation operation, DesignItem item) + { + UIElement child = item.View; + + if (child == null) + return Rect.Empty; + + double x, y; + + if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty)) { + x = GetCanvasProperty(child, Canvas.LeftProperty); + } else { + x = extendedComponent.ActualWidth - GetCanvasProperty(child, Canvas.RightProperty) - child.RenderSize.Width; + } + + + if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty)) { + y = GetCanvasProperty(child, Canvas.TopProperty); + } else { + y = extendedComponent.ActualHeight - GetCanvasProperty(child, Canvas.BottomProperty) - child.RenderSize.Height; + } + + var p = new Point(x, y); + return new Rect(p, child.RenderSize); + } + public override void SetPosition(PlacementInformation info) { base.SetPosition(info); @@ -66,28 +92,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions UIElement child = info.Item.View; Rect newPosition = info.Bounds; - if (IsPropertySet(child, Canvas.RightProperty)) - { + if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty)) { + if (newPosition.Left != GetCanvasProperty(child, Canvas.LeftProperty)) { + info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left); + } + } else { var newR = extendedComponent.ActualWidth - newPosition.Right; if (newR != GetCanvasProperty(child, Canvas.RightProperty)) info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR); } - else if (newPosition.Left != GetCanvasProperty(child, Canvas.LeftProperty)) - { - info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left); - } - if (IsPropertySet(child, Canvas.BottomProperty)) - { + if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty)) { + if (newPosition.Top != GetCanvasProperty(child, Canvas.TopProperty)) { + info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top); + } + } else { var newB = extendedComponent.ActualHeight - newPosition.Bottom; if (newB != GetCanvasProperty(child, Canvas.BottomProperty)) info.Item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(newB); } - else if (newPosition.Top != GetCanvasProperty(child, Canvas.TopProperty)) - { - info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top); - } if (info.Item == Services.Selection.PrimarySelection) { From 82e98ec949bc57b01c5fe1468285077298bea587 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 23 Jun 2014 21:29:49 +0100 Subject: [PATCH 2/2] Support custom NuGet package directory. NuGet allows a solution to override the standard packages directory with a repositoryPath setting in the NuGet.config file at the solution level in the .nuget directory. This is now supported by SharpDevelop. --- .../Project/Src/Design/FakeSettings.cs | 17 ++++++++++++- .../Project/Src/PackageManagementOptions.cs | 5 ++++ .../Src/RegisteredPackageSourceSettings.cs | 4 ++++ .../Src/SharpDevelopPackageManagerFactory.cs | 2 +- .../Src/SolutionPackageRepositoryPath.cs | 15 +++++++----- .../Src/SolutionPackageRepositoryPathTests.cs | 24 ++++++++++++++++++- 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/Design/FakeSettings.cs b/src/AddIns/Misc/PackageManagement/Project/Src/Design/FakeSettings.cs index bc37ce523f..0c1980b65c 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/Design/FakeSettings.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/Design/FakeSettings.cs @@ -18,6 +18,8 @@ using System; using System.Collections.Generic; +using System.Linq; + using NuGet; namespace ICSharpCode.PackageManagement.Design @@ -36,6 +38,8 @@ namespace ICSharpCode.PackageManagement.Design public Dictionary>> Sections = new Dictionary>>(); + public const string ConfigSectionName = "config"; + public FakeSettings() { Sections.Add(RegisteredPackageSourceSettings.PackageSourcesSectionName, PackageSources); @@ -200,7 +204,11 @@ namespace ICSharpCode.PackageManagement.Design public string GetValue(string section, string key, bool isPath) { - throw new NotImplementedException(); + if (Sections.ContainsKey(section)) { + var matchedSection = Sections[section]; + return matchedSection.FirstOrDefault(item => item.Key == key).Value; + } + return null; } public IList> GetValues(string section, bool isPath) @@ -212,5 +220,12 @@ namespace ICSharpCode.PackageManagement.Design { throw new NotImplementedException(); } + + public void SetRepositoryPathSetting(string fullPath) + { + var items = new List> (); + items.Add (new KeyValuePair("repositoryPath", fullPath)); + Sections.Add(ConfigSectionName, items); + } } } diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs b/src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs index 655d9be0d1..4ae99a301d 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs @@ -95,5 +95,10 @@ namespace ICSharpCode.PackageManagement { properties.SetList(RecentPackagesPropertyName, recentPackages); } + + public string GetCustomPackagesDirectory() + { + return registeredPackageSourceSettings.Settings.GetRepositoryPath(); + } } } diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs b/src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs index 2a6aae2c30..829c1bef8d 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs @@ -204,5 +204,9 @@ namespace ICSharpCode.PackageManagement packageSources = null; } } + + public ISettings Settings { + get { return settings; } + } } } diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/SharpDevelopPackageManagerFactory.cs b/src/AddIns/Misc/PackageManagement/Project/Src/SharpDevelopPackageManagerFactory.cs index dc79c7c396..92d31f3a12 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/SharpDevelopPackageManagerFactory.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/SharpDevelopPackageManagerFactory.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.PackageManagement : this( new SharpDevelopPackageRepositoryFactory(), new SharpDevelopProjectSystemFactory(), - new PackageManagementOptions()) + PackageManagementServices.Options) { } diff --git a/src/AddIns/Misc/PackageManagement/Project/Src/SolutionPackageRepositoryPath.cs b/src/AddIns/Misc/PackageManagement/Project/Src/SolutionPackageRepositoryPath.cs index 9be3cb7e0b..b188e91669 100644 --- a/src/AddIns/Misc/PackageManagement/Project/Src/SolutionPackageRepositoryPath.cs +++ b/src/AddIns/Misc/PackageManagement/Project/Src/SolutionPackageRepositoryPath.cs @@ -25,12 +25,11 @@ namespace ICSharpCode.PackageManagement { public class SolutionPackageRepositoryPath { - string packagesRelativeDirectory; ISolution solution; DefaultPackagePathResolver pathResolver; public SolutionPackageRepositoryPath(IProject project) - : this(project, new PackageManagementOptions()) + : this(project, PackageManagementServices.Options) { } @@ -41,14 +40,18 @@ namespace ICSharpCode.PackageManagement public SolutionPackageRepositoryPath(ISolution solution, PackageManagementOptions options) { - packagesRelativeDirectory = options.PackagesDirectory; this.solution = solution; - GetSolutionPackageRepositoryPath(); + PackageRepositoryPath = GetSolutionPackageRepositoryPath(options); } - void GetSolutionPackageRepositoryPath() + string GetSolutionPackageRepositoryPath(PackageManagementOptions options) { - PackageRepositoryPath = Path.Combine(solution.Directory, packagesRelativeDirectory); + string customPath = options.GetCustomPackagesDirectory (); + if (!String.IsNullOrEmpty (customPath)) { + return customPath; + } + + return Path.Combine (solution.Directory, options.PackagesDirectory); } public string PackageRepositoryPath { get; private set; } diff --git a/src/AddIns/Misc/PackageManagement/Test/Src/SolutionPackageRepositoryPathTests.cs b/src/AddIns/Misc/PackageManagement/Test/Src/SolutionPackageRepositoryPathTests.cs index 6623b8e461..5e55e9cef6 100644 --- a/src/AddIns/Misc/PackageManagement/Test/Src/SolutionPackageRepositoryPathTests.cs +++ b/src/AddIns/Misc/PackageManagement/Test/Src/SolutionPackageRepositoryPathTests.cs @@ -32,8 +32,9 @@ namespace PackageManagement.Tests { SolutionPackageRepositoryPath repositoryPath; IProject testProject; - PackageManagementOptions options; + TestablePackageManagementOptions options; ISolution solution; + FakeSettings settings; void CreateSolutionPackageRepositoryPath() { @@ -61,6 +62,12 @@ namespace PackageManagement.Tests void CreateOptions() { options = new TestablePackageManagementOptions(); + settings = options.FakeSettings; + } + + void SolutionNuGetConfigFileHasCustomPackagesPath(string fullPath) + { + settings.SetRepositoryPathSetting(fullPath); } [Test] @@ -109,5 +116,20 @@ namespace PackageManagement.Tests Assert.AreEqual(expectedInstallPath, installPath); } + + [Test] + public void PackageRepositoryPath_SolutionHasNuGetFileThatOverridesDefaultPackagesRepositoryPath_OverriddenPathReturned() + { + CreateOptions(); + CreateSolution(@"d:\projects\MySolution\MySolution.sln"); + options.PackagesDirectory = "Packages"; + SolutionNuGetConfigFileHasCustomPackagesPath(@"d:\Team\MyPackages"); + CreateSolutionPackageRepositoryPath(solution); + string expectedPath = @"d:\Team\MyPackages"; + + string path = repositoryPath.PackageRepositoryPath; + + Assert.AreEqual(expectedPath, path); + } } }