Browse Source

Merge branch 'master' of github.com:icsharpcode/SharpDevelop

pull/484/head
Peter Forstmeier 12 years ago
parent
commit
dfd1c1e17a
  1. 2
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpDesignerGenerator.cs
  2. 10
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs
  3. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/RotateThumb.cs
  4. 40
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/SizeDisplay.cs
  5. 74
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs
  6. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml
  7. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml.cs
  8. 37
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs
  9. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs
  10. 172
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  11. 18
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs
  12. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  13. 253
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
  14. 51
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/MarkupExtensionTests.cs
  15. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionElementsCollection.cs
  16. 15
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
  17. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionParser.cs
  18. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  19. 30
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/SelectionExtensionServer.cs
  20. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementInformation.cs
  21. 50
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs
  22. 4
      src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  23. 1
      src/AddIns/Misc/PackageManagement/Project/Src/Design/FakePackageManagementProjectService.cs
  24. 28
      src/AddIns/Misc/PackageManagement/Project/Src/ISettingsFactory.cs
  25. 14
      src/AddIns/Misc/PackageManagement/Project/Src/ISettingsProvider.cs
  26. 10
      src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs
  27. 2
      src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementServices.cs
  28. 41
      src/AddIns/Misc/PackageManagement/Project/Src/PackageRepositoryCache.cs
  29. 36
      src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs
  30. 62
      src/AddIns/Misc/PackageManagement/Project/Src/SettingsProvider.cs
  31. 2
      src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj
  32. 12
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakePackageRepositoryFactory.cs
  33. 8
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/OneRegisteredPackageSourceHelper.cs
  34. 24
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/TestablePackageManagementOptions.cs
  35. 115
      src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementOptionsTests.cs
  36. 4
      src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementOptionsViewModelTests.cs
  37. 38
      src/AddIns/Misc/PackageManagement/Test/Src/PackageRepositoryCacheTests.cs
  38. 80
      src/AddIns/Misc/PackageManagement/Test/Src/SettingsProviderTests.cs
  39. 2
      src/Main/GlobalAssemblyInfo.cs.template

2
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpDesignerGenerator.cs

@ -182,7 +182,7 @@ namespace CSharpBinding.FormsDesigner @@ -182,7 +182,7 @@ namespace CSharpBinding.FormsDesigner
string newline = DocumentUtilities.GetLineTerminator(script.OriginalDocument, bodyRegion.BeginLine);
string indentation = DocumentUtilities.GetIndentation(script.OriginalDocument, bodyRegion.BeginLine);
string code = "{" + newline + GenerateInitializeComponents(codeMethod, indentation, newline) + indentation + "}";
string code = "{" + newline + GenerateInitializeComponents(codeMethod, indentation, newline) + newline + indentation + "}";
int startOffset = script.GetCurrentOffset(bodyRegion.Begin);
int endOffset = script.GetCurrentOffset(bodyRegion.End);

10
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs

@ -83,10 +83,12 @@ namespace ICSharpCode.XamlBinding @@ -83,10 +83,12 @@ namespace ICSharpCode.XamlBinding
XamlCompletionItem cItem = item as XamlCompletionItem;
if (xamlContext.Description == XamlContextDescription.InTag) {
context.Editor.Document.Insert(context.EndOffset, "=\"\"");
context.CompletionCharHandled = context.CompletionChar == '=';
context.Editor.Caret.Offset--;
new XamlCodeCompletionBinding().CtrlSpace(context.Editor);
if (cItem.Entity.SymbolKind == SymbolKind.Property || cItem.Entity.SymbolKind == SymbolKind.Event) {
context.Editor.Document.Insert(context.EndOffset, "=\"\"");
context.CompletionCharHandled = context.CompletionChar == '=';
context.Editor.Caret.Offset--;
new XamlCodeCompletionBinding().CtrlSpace(context.Editor);
}
} else if (xamlContext.Description == XamlContextDescription.InMarkupExtension && !string.IsNullOrEmpty(xamlContext.RawAttributeValue)) {
string valuePart = xamlContext.RawAttributeValue.Substring(0, xamlContext.ValueStartOffset);
AttributeValue value = MarkupExtensionParser.ParseValue(valuePart);

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/RotateThumb.cs

@ -32,14 +32,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -32,14 +32,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
{
public class RotateThumb : ResizeThumb
{
// private double initialAngle;
// private RotateTransform rotateTransform;
// private Vector startVector;
// private Point centerPoint;
// private Control designerItem;
// private Panel canvas;
// private AdornerPanel parent;
static RotateThumb()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(RotateThumb), new FrameworkPropertyMetadata(typeof(RotateThumb)));

40
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/SizeDisplay.cs

@ -26,25 +26,25 @@ using System.Windows.Controls; @@ -26,25 +26,25 @@ using System.Windows.Controls;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Display height of the element.
/// </summary>
class HeightDisplay : Control
{
static HeightDisplay()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(HeightDisplay), new FrameworkPropertyMetadata(typeof(HeightDisplay)));
}
}
/// <summary>
/// Display height of the element.
/// </summary>
class HeightDisplay : Control
{
static HeightDisplay()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(HeightDisplay), new FrameworkPropertyMetadata(typeof(HeightDisplay)));
}
}
/// <summary>
/// Display width of the element.
/// </summary>
class WidthDisplay : Control
{
static WidthDisplay()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(WidthDisplay), new FrameworkPropertyMetadata(typeof(WidthDisplay)));
}
}
/// <summary>
/// Display width of the element.
/// </summary>
class WidthDisplay : Control
{
static WidthDisplay()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(WidthDisplay), new FrameworkPropertyMetadata(typeof(WidthDisplay)));
}
}
}

74
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs

@ -30,55 +30,55 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers @@ -30,55 +30,55 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers
{
public override void InitializeDefaults(DesignItem item)
{
//Not every Content Control can have a text as Content (e.g. ZoomBox of WPF Toolkit)
if (item.Component is Button)
{
//Not every Content Control can have a text as Content (e.g. ZoomBox of WPF Toolkit)
if (item.Component is Button)
{
DesignItemProperty contentProperty = item.Properties["Content"];
if (contentProperty.ValueOnInstance == null)
{
if (contentProperty.ValueOnInstance == null)
{
contentProperty.SetValue(item.ComponentType.Name);
}
}
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
if (verticalAlignmentProperty.ValueOnInstance == null)
{
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
}
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
if (verticalAlignmentProperty.ValueOnInstance == null)
{
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
}
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
if (horizontalAlignmentProperty.ValueOnInstance == null)
{
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
}
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
if (horizontalAlignmentProperty.ValueOnInstance == null)
{
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
}
}
}
[ExtensionFor(typeof(TextBlock))]
public class TextBlockInitializer : DefaultInitializer
{
public override void InitializeDefaults(DesignItem item)
{
DesignItemProperty textProperty = item.Properties["Text"];
if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "")
{
textProperty.SetValue(item.ComponentType.Name);
}
public class TextBlockInitializer : DefaultInitializer
{
public override void InitializeDefaults(DesignItem item)
{
DesignItemProperty textProperty = item.Properties["Text"];
if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "")
{
textProperty.SetValue(item.ComponentType.Name);
}
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
if (verticalAlignmentProperty.ValueOnInstance == null)
{
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
}
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
if (verticalAlignmentProperty.ValueOnInstance == null)
{
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
}
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
if (horizontalAlignmentProperty.ValueOnInstance == null)
{
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
}
}
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
if (horizontalAlignmentProperty.ValueOnInstance == null)
{
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
}
}
}
[ExtensionFor(typeof(HeaderedContentControl), OverrideExtension = typeof(ContentControlInitializer))]
public class HeaderedContentControlInitializer : DefaultInitializer
{
@ -96,7 +96,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers @@ -96,7 +96,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers
}
}
[ExtensionFor(typeof(Shape))]
[ExtensionFor(typeof(Shape))]
public class ShapeInitializer : DefaultInitializer
{
public override void InitializeDefaults(DesignItem item)

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.RightClickMultipleItemsContextMenu"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer"
>
<MenuItem Header="{Binding WrapInCanvas, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInCanvas" />
<MenuItem Header="{Binding WrapInGrid, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInGrid" />
</ContextMenu>

38
src/AddIns/Misc/PackageManagement/Project/Src/SettingsFactory.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml.cs

@ -17,16 +17,42 @@ @@ -17,16 +17,42 @@
// DEALINGS IN THE SOFTWARE.
using System;
using NuGet;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.PropertyGrid;
using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.PackageManagement
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class SettingsFactory : ISettingsFactory
public partial class RightClickMultipleItemsContextMenu
{
public ISettings CreateSettings(string directory)
private DesignItem designItem;
public RightClickMultipleItemsContextMenu(DesignItem designItem)
{
var fileSystem = new PhysicalFileSystem(directory);
return new Settings(fileSystem);
this.designItem = designItem;
InitializeComponent();
}
void Click_WrapInCanvas(object sender, System.Windows.RoutedEventArgs e)
{
ModelTools.WrapItemsNewContainer(this.designItem.Services.Selection.SelectedItems, typeof(Canvas));
}
void Click_WrapInGrid(object sender, System.Windows.RoutedEventArgs e)
{
ModelTools.WrapItemsNewContainer(this.designItem.Services.Selection.SelectedItems, typeof(Grid));
}
}
}

37
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakeSettingsFactory.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs

@ -17,21 +17,38 @@ @@ -17,21 +17,38 @@
// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.PackageManagement;
using ICSharpCode.PackageManagement.Design;
using NuGet;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
namespace PackageManagement.Tests.Helpers
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class FakeSettingsFactory : ISettingsFactory
/// <summary>
///
/// </summary>
[ExtensionServer(typeof(MultipleSelectedExtensionServer))]
[ExtensionFor(typeof(UIElement))]
public class RightClickMultipleItemsContextMenuExtension : SelectionAdornerProvider
{
public FakeSettings FakeSettings = new FakeSettings();
public string DirectoryPassedToCreateSettings;
DesignPanel panel;
protected override void OnInitialized()
{
base.OnInitialized();
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
panel.ContextMenu = new RightClickMultipleItemsContextMenu(ExtendedItem);
}
public ISettings CreateSettings(string directory)
protected override void OnRemove()
{
DirectoryPassedToCreateSettings = directory;
return FakeSettings;
panel.ContextMenu = null;
base.OnRemove();
}
}
}

16
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs

@ -115,12 +115,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -115,12 +115,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (Snap(horizontalInput, horizontalMap, Accuracy, out drawLines, out delta)) {
if (operation.Type == PlacementType.Resize) {
if (info.ResizeThumbAlignment.Vertical == VerticalAlignment.Top) {
bounds.Y += delta;
bounds.Height = Math.Max(0, bounds.Height - delta);
} else {
bounds.Height = Math.Max(0, bounds.Height + delta);
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Vertical == VerticalAlignment.Top) {
bounds.Y += delta;
}
bounds.Height = Math.Max(0, bounds.Height - delta);
info.Bounds = bounds;
} else {
foreach (var item in operation.PlacedItems) {
@ -138,12 +136,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -138,12 +136,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (Snap(verticalInput, verticalMap, Accuracy, out drawLines, out delta)) {
if (operation.Type == PlacementType.Resize) {
if (info.ResizeThumbAlignment.Horizontal == HorizontalAlignment.Left) {
bounds.X += delta;
bounds.Width = Math.Max(0, bounds.Width - delta);
} else {
bounds.Width = Math.Max(0, bounds.Width + delta);
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Horizontal == HorizontalAlignment.Left) {
bounds.X += delta;
}
bounds.Width = Math.Max(0, bounds.Width - delta);
info.Bounds = bounds;
} else {
foreach (var item in operation.PlacedItems) {

172
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs

@ -27,6 +27,7 @@ using System.Windows.Markup; @@ -27,6 +27,7 @@ using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Xps.Serialization;
using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.WpfDesign.Designer
{
@ -137,7 +138,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -137,7 +138,7 @@ namespace ICSharpCode.WpfDesign.Designer
catch (Exception)
{ }
}
internal static Size GetDefaultSize(DesignItem createdItem)
{
CreateVisualTree(createdItem.View);
@ -198,5 +199,174 @@ namespace ICSharpCode.WpfDesign.Designer @@ -198,5 +199,174 @@ namespace ICSharpCode.WpfDesign.Designer
item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight);
}
}
private class ItemPos
{
public HorizontalAlignment HorizontalAlignment{ get; set; }
public VerticalAlignment VerticalAlignment{ get; set; }
public double Xmin { get; set; }
public double Xmax { get; set; }
public double Ymin { get; set; }
public double Ymax { get; set; }
public DesignItem DesignItem { get; set; }
}
public static void WrapItemsNewContainer(IEnumerable<DesignItem> items, Type containerType)
{
var collection = items;
var _context = collection.First().Context as XamlDesignContext;
var oldContainer = collection.First().Parent;
if (collection.Any(x => x.Parent != oldContainer))
return;
var newInstance = Activator.CreateInstance(containerType);
DesignItem newPanel = _context.Services.Component.RegisterComponentForDesigner(newInstance);
var changeGroup = newPanel.OpenGroup("Wrap in Container");
List<ItemPos> itemList = new List<ItemPos>();
foreach (var item in collection) {
var itemPos = new ItemPos(){ DesignItem = item };
itemList.Add(itemPos);
if (oldContainer.Component is Canvas) {
var canvas = oldContainer.View as Canvas;
if (item.Properties.GetAttachedProperty(Canvas.RightProperty) != null && item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) {
itemPos.HorizontalAlignment = HorizontalAlignment.Right;
itemPos.Xmax = canvas.ActualWidth - (double)item.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance;
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement)item.View).ActualWidth;
}
else if (item.Properties.GetAttachedProperty(Canvas.LeftProperty) != null && item.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet) {
itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmin = (double)item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth;
} else {
itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth;
}
if (item.Properties.GetAttachedProperty(Canvas.BottomProperty) != null && item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) {
itemPos.VerticalAlignment = VerticalAlignment.Bottom;
itemPos.Ymax = canvas.ActualHeight - (double)item.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance;
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement)item.View).ActualHeight;
}
else if (item.Properties.GetAttachedProperty(Canvas.TopProperty) != null && item.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet) {
itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymin = (double)item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight;
} else {
itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight;
}
item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.BottomProperty).Reset();
} else if (oldContainer.Component is Grid) {
var grid = oldContainer.View as Grid;
if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance == HorizontalAlignment.Right) {
itemPos.HorizontalAlignment = HorizontalAlignment.Right;
itemPos.Xmax = grid.ActualWidth - ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Right;
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement)item.View).ActualWidth;
} else {
itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmin = ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Left;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth;
}
if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance == VerticalAlignment.Bottom) {
itemPos.VerticalAlignment = VerticalAlignment.Bottom;
itemPos.Ymax = grid.ActualHeight - ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Bottom;
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement)item.View).ActualHeight;
} else {
itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymin = ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Top;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight;
}
item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).Reset();
item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).Reset();
item.Properties.GetProperty(FrameworkElement.MarginProperty).Reset();
}
var parCol = item.ParentProperty.CollectionElements;
parCol.Remove(item);
}
var xmin = itemList.Min(x => x.Xmin);
var xmax = itemList.Max(x => x.Xmax);
var ymin = itemList.Min(x => x.Ymin);
var ymax = itemList.Max(x => x.Ymax);
if (oldContainer.Component is Canvas) {
newPanel.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(xmax - xmin);
newPanel.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(ymax - ymin);
newPanel.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin);
newPanel.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin);
} else if (oldContainer.Component is Grid) {
newPanel.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Left);
newPanel.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Top);
newPanel.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(new Thickness(xmin, ymin, 0, 0));
newPanel.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(xmax - xmin);
newPanel.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(ymax - ymin);
}
foreach (var item in itemList) {
newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
if (newPanel.Component is Canvas) {
if (item.HorizontalAlignment == HorizontalAlignment.Right) {
item.DesignItem.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(xmax - item.Xmax);
} else {
item.DesignItem.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(item.Xmin - xmin);
}
if (item.VerticalAlignment == VerticalAlignment.Bottom) {
item.DesignItem.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(ymax - item.Ymax);
} else {
item.DesignItem.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(item.Ymin - ymin);
}
} else if (newPanel.Component is Grid) {
Thickness thickness = new Thickness(0);
if (item.HorizontalAlignment == HorizontalAlignment.Right) {
item.DesignItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Right);
thickness.Right = xmax - item.Xmax;
} else {
item.DesignItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Left);
thickness.Left = item.Xmin - xmin;
}
if (item.VerticalAlignment == VerticalAlignment.Bottom) {
item.DesignItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Bottom);
thickness.Bottom = ymax - item.Ymax;
} else {
item.DesignItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Top);
thickness.Top = item.Ymin - ymin;
}
item.DesignItem.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(thickness);
}
}
oldContainer.ContentProperty.CollectionElements.Add(newPanel);
changeGroup.Commit();
_context.Services.Selection.SetSelectedComponents(new []{ newPanel });
}
}
}

18
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs

@ -65,5 +65,23 @@ namespace ICSharpCode.WpfDesign.Designer @@ -65,5 +65,23 @@ namespace ICSharpCode.WpfDesign.Designer
return "Press \"Alt\" to Enter Container";
}
}
public virtual string WrapInCanvas {
get {
return "Wrap in Canvas";
}
}
public virtual string WrapInGrid {
get {
return "Wrap in Grid";
}
}
public virtual string WrapInBorder {
get {
return "Wrap in Border";
}
}
}
}

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -90,6 +90,10 @@ @@ -90,6 +90,10 @@
</Compile>
<Compile Include="Extensions\RenderTransformOriginExtension.cs" />
<Compile Include="Extensions\RightClickContextMenuExtension.cs" />
<Compile Include="Extensions\RightClickMultipleItemsContextMenuExtension.cs" />
<Compile Include="Extensions\RightClickMultipleItemsContextMenu.xaml.cs">
<DependentUpon>RightClickMultipleItemsContextMenu.xaml</DependentUpon>
</Compile>
<Compile Include="Extensions\SkewThumbExtension.cs" />
<Compile Include="Extensions\TopLeftContainerDragHandleMultipleItems.cs" />
<Compile Include="PropertyGrid\Editors\ColorEditor.xaml.cs">
@ -263,6 +267,7 @@ @@ -263,6 +267,7 @@
</ItemGroup>
<ItemGroup>
<Page Include="Extensions\RightClickContextMenu.xaml" />
<Page Include="Extensions\RightClickMultipleItemsContextMenu.xaml" />
<Page Include="PropertyGrid\Editors\ColorEditor.xaml" />
<Page Include="PropertyGrid\Editors\FlatCollectionEditor.xaml" />
<Page Include="PropertyGrid\Editors\OpenCollectionEditor.xaml" />

253
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs

@ -149,6 +149,176 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -149,6 +149,176 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
AssertLog("");
}
[Test]
public void UndoRedoImplicitList()
{
UndoRedoListInternal(false);
}
[Test]
public void UndoRedoExplicitList()
{
UndoRedoListInternal(true);
}
void UndoRedoListInternal(bool useExplicitList)
{
DesignItem button = CreateCanvasContext("<Button/>");
UndoService s = button.Context.Services.GetService<UndoService>();
IComponentService component = button.Context.Services.Component;
string expectedXamlWithList;
DesignItemProperty otherListProp;
Assert.IsFalse(s.CanUndo);
Assert.IsFalse(s.CanRedo);
using (ChangeGroup g = button.OpenGroup("UndoRedoListInternal test")) {
DesignItem containerItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());
otherListProp = containerItem.Properties["OtherList"];
if(useExplicitList) {
otherListProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList());
expectedXamlWithList = @"<Button>
<Button.Tag>
<Controls0:ExampleClassContainer>
<Controls0:ExampleClassContainer.OtherList>
<Controls0:ExampleClassList>
<Controls0:ExampleClass StringProp=""String value"" />
</Controls0:ExampleClassList>
</Controls0:ExampleClassContainer.OtherList>
</Controls0:ExampleClassContainer>
</Button.Tag>
</Button>";
} else {
expectedXamlWithList = @"<Button>
<Button.Tag>
<Controls0:ExampleClassContainer>
<Controls0:ExampleClassContainer.OtherList>
<Controls0:ExampleClass StringProp=""String value"" />
</Controls0:ExampleClassContainer.OtherList>
</Controls0:ExampleClassContainer>
</Button.Tag>
</Button>";
}
DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
exampleClassItem.Properties["StringProp"].SetValue("String value");
otherListProp.CollectionElements.Add(exampleClassItem);
button.Properties["Tag"].SetValue(containerItem);
g.Commit();
}
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
otherListProp = button.Properties["Tag"].Value.Properties["OtherList"];
Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance).Count == otherListProp.CollectionElements.Count);
s.Undo();
Assert.IsFalse(s.CanUndo);
Assert.IsTrue(s.CanRedo);
AssertCanvasDesignerOutput("<Button>\n</Button>", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
s.Redo();
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
otherListProp = button.Properties["Tag"].Value.Properties["OtherList"];
Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance).Count == otherListProp.CollectionElements.Count);
AssertLog("");
}
[Test]
public void UndoRedoImplicitDictionary()
{
UndoRedoDictionaryInternal(false);
}
[Test]
public void UndoRedoExplicitDictionary()
{
UndoRedoDictionaryInternal(true);
}
void UndoRedoDictionaryInternal(bool useExplicitDictionary)
{
DesignItem button = CreateCanvasContext("<Button/>");
UndoService s = button.Context.Services.GetService<UndoService>();
IComponentService component = button.Context.Services.Component;
string expectedXamlWithDictionary;
DesignItemProperty dictionaryProp;
Assert.IsFalse(s.CanUndo);
Assert.IsFalse(s.CanRedo);
using (ChangeGroup g = button.OpenGroup("UndoRedoDictionaryInternal test")) {
DesignItem containerItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());
dictionaryProp = containerItem.Properties["Dictionary"];
if(useExplicitDictionary) {
dictionaryProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary());
expectedXamlWithDictionary = @"<Button>
<Button.Tag>
<Controls0:ExampleClassContainer>
<Controls0:ExampleClassContainer.Dictionary>
<Controls0:ExampleClassDictionary>
<Controls0:ExampleClass x:Key=""testKey"" StringProp=""String value"" />
</Controls0:ExampleClassDictionary>
</Controls0:ExampleClassContainer.Dictionary>
</Controls0:ExampleClassContainer>
</Button.Tag>
</Button>";
} else {
expectedXamlWithDictionary = @"<Button>
<Button.Tag>
<Controls0:ExampleClassContainer>
<Controls0:ExampleClassContainer.Dictionary>
<Controls0:ExampleClass x:Key=""testKey"" StringProp=""String value"" />
</Controls0:ExampleClassContainer.Dictionary>
</Controls0:ExampleClassContainer>
</Button.Tag>
</Button>";
}
DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
exampleClassItem.Key = "testKey";
exampleClassItem.Properties["StringProp"].SetValue("String value");
dictionaryProp.CollectionElements.Add(exampleClassItem);
button.Properties["Tag"].SetValue(containerItem);
g.Commit();
}
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"];
Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count);
s.Undo();
Assert.IsFalse(s.CanUndo);
Assert.IsTrue(s.CanRedo);
AssertCanvasDesignerOutput("<Button>\n</Button>", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
s.Redo();
Assert.IsTrue(s.CanUndo);
Assert.IsFalse(s.CanRedo);
AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"];
Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count);
AssertLog("");
}
[Test]
public void AddTextBoxToCanvas()
@ -254,6 +424,89 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -254,6 +424,89 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
AssertLog("");
}
[Test]
public void ClearExplicitList()
{
DesignItem button = CreateCanvasContext("<Button/>");
button.Properties["Tag"].SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());
var containerItem = button.Properties["Tag"].Value;
var otherListProp = containerItem.Properties["OtherList"];
otherListProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList());
DesignItem exampleClassItem = button.Context.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
exampleClassItem.Properties["StringProp"].SetValue("String value");
otherListProp.CollectionElements.Add(exampleClassItem);
var listInstance = (ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance;
Assert.AreEqual(1, listInstance.Count);
Assert.AreEqual(1, otherListProp.CollectionElements.Count);
button.Properties["Tag"].Value.Properties["OtherList"].CollectionElements.Clear();
Assert.AreEqual(0, listInstance.Count);
Assert.AreEqual(0, otherListProp.CollectionElements.Count);
AssertCanvasDesignerOutput(@"<Button>
<Button.Tag>
<Controls0:ExampleClassContainer>
<Controls0:ExampleClassContainer.OtherList>
<Controls0:ExampleClassList>
</Controls0:ExampleClassList>
</Controls0:ExampleClassContainer.OtherList>
</Controls0:ExampleClassContainer>
</Button.Tag>
</Button>", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
AssertLog("");
}
[Test]
public void ClearExplicitDictionary()
{
DesignItem button = CreateCanvasContext("<Button/>");
button.Properties["Tag"].SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer());
var containerItem = button.Properties["Tag"].Value;
var dictionaryProp = containerItem.Properties["Dictionary"];
dictionaryProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary());
DesignItem exampleClassItem = button.Context.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass());
exampleClassItem.Key = "testKey";
exampleClassItem.Properties["StringProp"].SetValue("String value");
dictionaryProp.CollectionElements.Add(exampleClassItem);
var dictionaryInstance = (ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance;
Assert.AreEqual(1, dictionaryInstance.Count);
Assert.AreEqual(1, dictionaryProp.CollectionElements.Count);
button.Properties["Tag"].Value.Properties["Dictionary"].CollectionElements.Clear();
Assert.AreEqual(0, dictionaryInstance.Count);
Assert.AreEqual(0, dictionaryProp.CollectionElements.Count);
dictionaryProp.CollectionElements.Add(exampleClassItem);
Assert.AreEqual(1, dictionaryInstance.Count);
Assert.AreEqual(1, dictionaryProp.CollectionElements.Count);
button.Properties["Tag"].Value.Properties["Dictionary"].CollectionElements.Clear();
Assert.AreEqual(0, dictionaryInstance.Count);
Assert.AreEqual(0, dictionaryProp.CollectionElements.Count);
AssertCanvasDesignerOutput(@"<Button>
<Button.Tag>
<Controls0:ExampleClassContainer>
<Controls0:ExampleClassContainer.Dictionary>
<Controls0:ExampleClassDictionary>
</Controls0:ExampleClassDictionary>
</Controls0:ExampleClassContainer.Dictionary>
</Controls0:ExampleClassContainer>
</Button.Tag>
</Button>", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\"");
AssertLog("");
}
[Test]
public void AddMultiBindingToTextBox()
{

51
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/MarkupExtensionTests.cs

@ -27,6 +27,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -27,6 +27,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
[TestFixture]
public class MarkupExtensionTests : TestHelper
{
private const string PathWithSpaces = @"C:\\Folder A\\SubFolder A\\SubFolder B\\file with spaces.txt";
private const string PathWithoutSpaces = @"C:\\FolderA\\SubFolderA\\SubFolderB\\file.txt";
private const string PathWithCommasAndSpaces = @"C:\\Folder A\\Sub,Folder,A\\SubFolderB\\file,with,commas and spaces.txt";
[Test]
public void Test1()
{
@ -84,6 +88,36 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -84,6 +88,36 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
TestMarkupExtension("Content=\"{x:Static t:MyStaticClass.StaticString}\"");
}
[Test]
public void TestPathWithSpaces()
{
TestMarkupExtension("Content=\"{t:String " + PathWithSpaces + "}\"");
}
[Test]
public void TestQuotedPathWithSpaces()
{
TestMarkupExtension("Content=\"{t:String '" + PathWithSpaces + "'}\"");
}
[Test]
public void TestPathWithoutSpaces()
{
TestMarkupExtension("Content=\"{t:String " + PathWithoutSpaces + "}\"");
}
[Test]
public void TestQuotedPathWithoutSpaces()
{
TestMarkupExtension("Content=\"{t:String '" + PathWithoutSpaces + "'}\"");
}
[Test]
public void TestQuotedPathWithCommasAndSpaces()
{
TestMarkupExtension("Content=\"{t:String '" + PathWithCommasAndSpaces + "'}\"");
}
// [Test]
// public void Test10()
@ -114,6 +148,23 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -114,6 +148,23 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
public static string StaticString = "a";
}
public class StringExtension : MarkupExtension
{
readonly string s;
public StringExtension(string s)
{
TestHelperLog.Log(this.GetType().Name + " " + s);
this.s = s;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return s;
}
}
public class MyExtension : MarkupExtension
{

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionElementsCollection.cs

@ -54,7 +54,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -54,7 +54,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlPropertyInfo info = property.propertyInfo;
object collection = info.GetValue(property.ParentObject.Instance);
if (!CollectionSupport.RemoveItemAt(info.ReturnType, collection, index)) {
CollectionSupport.RemoveItem(info.ReturnType, collection, this[index].GetValueFor(info));
var propertyValue = this[index];
CollectionSupport.RemoveItem(info.ReturnType, collection, propertyValue.GetValueFor(info), propertyValue);
}
this[index].RemoveNodeFromParent();

15
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

@ -154,5 +154,20 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -154,5 +154,20 @@ namespace ICSharpCode.WpfDesign.XamlDom
new object[] { item },
CultureInfo.InvariantCulture);
}
/// <summary>
/// Removes an item instance from the specified collection.
/// </summary>
internal static void RemoveItem(Type collectionType, object collectionInstance, object item, XamlPropertyValue element)
{
var dictionary = collectionInstance as IDictionary;
var xamlObject = element as XamlObject;
if (dictionary != null && xamlObject != null) {
dictionary.Remove(xamlObject.GetXamlAttribute("Key"));
} else {
RemoveItem(collectionType, collectionInstance, item);
}
}
}
}

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionParser.cs

@ -96,10 +96,17 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -96,10 +96,17 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (text[pos] == '"' || text[pos] == '\'') {
char quote = text[pos++];
CheckNotEOF();
int lastBackslashPos = -1;
while (!(text[pos] == quote && text[pos-1] != '\\')) {
int current = pos;
char c = text[pos++];
if (c != '\\')
//check if string is \\ and that the last backslash is not the previously saved char, ie that \\\\ does not become \\\ but just \\
bool isEscapedBackslash = string.Concat(text[current-1],c)=="\\\\" && current-1 != lastBackslashPos;
if (c != '\\' || isEscapedBackslash){
b.Append(c);
if(isEscapedBackslash)
lastBackslashPos = current;
}
CheckNotEOF();
}
pos++; // consume closing quote

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -254,13 +254,21 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -254,13 +254,21 @@ namespace ICSharpCode.WpfDesign.XamlDom
void ResetInternal()
{
bool isExplicitCollection = false;
if (propertyValue != null) {
isExplicitCollection = IsCollection;
propertyValue.RemoveNodeFromParent();
propertyValue.ParentProperty = null;
propertyValue = null;
}
if (_propertyElement != null) {
_propertyElement.ParentNode.RemoveChild(_propertyElement);
Debug.Assert(!isExplicitCollection || _propertyElement.ParentNode == null);
if (!isExplicitCollection) {
_propertyElement.ParentNode.RemoveChild(_propertyElement);
}
_propertyElement = null;
}
}

30
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/SelectionExtensionServer.cs

@ -118,7 +118,7 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -118,7 +118,7 @@ namespace ICSharpCode.WpfDesign.Extensions
void OnSelectionChanged(object sender, EventArgs e)
{
ReapplyExtensions(this.Services.Selection.SelectedItems);
ReapplyExtensions(this.Services.Selection.SelectedItems);
}
/// <summary>
@ -130,6 +130,34 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -130,6 +130,34 @@ namespace ICSharpCode.WpfDesign.Extensions
}
}
/// <summary>
/// Applies an extension only when multiple Items are selected!
/// </summary>
public class MultipleSelectedExtensionServer : DefaultExtensionServer
{
/// <summary>
/// Is called after the extension server is initialized and the Context property has been set.
/// </summary>
protected override void OnInitialized()
{
base.OnInitialized();
this.Services.Selection.SelectionChanged += OnSelectionChanged;
}
void OnSelectionChanged(object sender, EventArgs e)
{
ReapplyExtensions(this.Services.Selection.SelectedItems);
}
/// <summary>
/// Gets if the item is in the secondary selection.
/// </summary>
public override bool ShouldApplyExtensions(DesignItem extendedItem)
{
return Services.Selection.SelectionCount > 1;
}
}
/// <summary>
/// Applies an extension to the primary selection if Only One Item is Selected.
/// </summary>

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementInformation.cs

@ -75,7 +75,7 @@ namespace ICSharpCode.WpfDesign @@ -75,7 +75,7 @@ namespace ICSharpCode.WpfDesign
/// <summary>
/// Gets/sets the alignment of the resize thumb used to start the operation.
/// </summary>
public PlacementAlignment ResizeThumbAlignment { get; set; }
public PlacementAlignment? ResizeThumbAlignment { get; set; }
/// <inheritdoc/>
public override string ToString()

50
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs

@ -233,33 +233,33 @@ namespace ICSharpCode.WpfDesign @@ -233,33 +233,33 @@ namespace ICSharpCode.WpfDesign
#region IKeyBindingService
/// <summary>
/// Service that handles all the key bindings in the designer.
/// </summary>
public interface IKeyBindingService
{
/// <summary>
/// Gets the object to which the bindings are being applied
/// </summary>
object Owner { get; }
/// Service that handles all the key bindings in the designer.
/// </summary>
public interface IKeyBindingService
{
/// <summary>
/// Gets the object to which the bindings are being applied
/// </summary>
object Owner { get; }
/// <summary>
/// Register <paramref name="binding"/> with <see cref="Owner"/>.
/// </summary>
/// <param name="binding">The binding to be applied.</param>
void RegisterBinding(KeyBinding binding);
/// <summary>
/// Register <paramref name="binding"/> with <see cref="Owner"/>.
/// </summary>
/// <param name="binding">The binding to be applied.</param>
void RegisterBinding(KeyBinding binding);
/// <summary>
/// De-register <paramref name="binding"/> with <see cref="Owner"/>.
/// </summary>
/// <param name="binding">The binding to be applied.</param>
void DeregisterBinding(KeyBinding binding);
/// <summary>
/// De-register <paramref name="binding"/> with <see cref="Owner"/>.
/// </summary>
/// <param name="binding">The binding to be applied.</param>
void DeregisterBinding(KeyBinding binding);
/// <summary>
/// Gets binding for the corresponding gesture otherwise returns null.
/// </summary>
/// <param name="gesture">The keyboard gesture requested.</param>
KeyBinding GetBinding(KeyGesture gesture);
}
/// <summary>
/// Gets binding for the corresponding gesture otherwise returns null.
/// </summary>
/// <param name="gesture">The keyboard gesture requested.</param>
KeyBinding GetBinding(KeyGesture gesture);
}
#endregion
}

4
src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

@ -154,6 +154,7 @@ @@ -154,6 +154,7 @@
<Compile Include="Src\InstalledPackagesViewModel.cs" />
<Compile Include="Src\IPackageRepositoryFactoryEvents.cs" />
<Compile Include="Src\IPackageViewModelParent.cs" />
<Compile Include="Src\ISettingsProvider.cs" />
<Compile Include="Src\IUpdatePackagesAction.cs" />
<Compile Include="Src\IPackageExtensions.cs" />
<Compile Include="Src\IPackageAction.cs" />
@ -219,7 +220,6 @@ @@ -219,7 +220,6 @@
<Compile Include="Src\IPackageReferenceInstaller.cs" />
<Compile Include="Src\IPackageReferencesForProject.cs" />
<Compile Include="Src\IPropertyService.cs" />
<Compile Include="Src\ISettingsFactory.cs" />
<Compile Include="Src\IThreadSafePackageManagementEvents.cs" />
<Compile Include="Src\ManagePackagesUserPrompts.cs" />
<Compile Include="Src\ManagePackagesViewTitle.cs" />
@ -252,6 +252,7 @@ @@ -252,6 +252,7 @@
<Compile Include="Src\Scripting\NullGlobalMSBuildProjectCollection.cs" />
<Compile Include="Src\Scripting\RunAllProjectPackageScriptsAction.cs" />
<Compile Include="Src\ServiceWithWorkbenchOwner.cs" />
<Compile Include="Src\SettingsProvider.cs" />
<Compile Include="Src\SharpDevelopCredentialProvider.cs" />
<Compile Include="Src\SharpDevelopHttpUserAgent.cs" />
<Compile Include="Src\ThreadSafeCodeGenerator.cs" />
@ -400,7 +401,6 @@ @@ -400,7 +401,6 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\SelectProjectsViewModel.cs" />
<Compile Include="Src\SettingsFactory.cs" />
<Compile Include="Src\SolutionPackageRepositoryFactory.cs" />
<Compile Include="Src\SolutionPackageRepositoryPath.cs" />
<Compile Include="Src\PackageSourceConverter.cs" />

1
src/AddIns/Misc/PackageManagement/Project/Src/Design/FakePackageManagementProjectService.cs

@ -43,6 +43,7 @@ namespace ICSharpCode.PackageManagement.Design @@ -43,6 +43,7 @@ namespace ICSharpCode.PackageManagement.Design
public void FireSolutionClosedEvent(ISolution solution)
{
OpenSolution = null;
if (SolutionClosed != null) {
SolutionClosed(this, new SolutionEventArgs(solution));
}

28
src/AddIns/Misc/PackageManagement/Project/Src/ISettingsFactory.cs

@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using NuGet;
namespace ICSharpCode.PackageManagement
{
public interface ISettingsFactory
{
ISettings CreateSettings(string directory);
}
}

14
src/AddIns/Misc/PackageManagement/Project/Src/ISettingsProvider.cs

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using NuGet;
namespace ICSharpCode.PackageManagement
{
public interface ISettingsProvider
{
event EventHandler SettingsChanged;
ISettings LoadSettings();
}
}

10
src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementOptions.cs

@ -35,15 +35,17 @@ namespace ICSharpCode.PackageManagement @@ -35,15 +35,17 @@ namespace ICSharpCode.PackageManagement
ObservableCollection<RecentPackageInfo> recentPackages;
PackageRestoreConsent packageRestoreConsent;
public PackageManagementOptions(Properties properties, ISettings settings)
public PackageManagementOptions(
Properties properties,
ISettingsProvider settingsProvider)
{
this.properties = properties;
registeredPackageSourceSettings = new RegisteredPackageSourceSettings(settings);
packageRestoreConsent = new PackageRestoreConsent(settings);
registeredPackageSourceSettings = new RegisteredPackageSourceSettings(settingsProvider);
packageRestoreConsent = new PackageRestoreConsent(settingsProvider.LoadSettings());
}
public PackageManagementOptions(Properties properties)
: this(properties, Settings.LoadDefaultSettings(null, null, null))
: this(properties, new SettingsProvider())
{
}

2
src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementServices.cs

@ -42,7 +42,7 @@ namespace ICSharpCode.PackageManagement @@ -42,7 +42,7 @@ namespace ICSharpCode.PackageManagement
static PackageManagementServices()
{
options = new PackageManagementOptions();
packageRepositoryCache = new PackageRepositoryCache(options.PackageSources, options.RecentPackages);
packageRepositoryCache = new PackageRepositoryCache(options);
userAgentGenerator = new UserAgentGeneratorForRepositoryRequests(packageRepositoryCache);
registeredPackageRepositories = new RegisteredPackageRepositories(packageRepositoryCache, options);

41
src/AddIns/Misc/PackageManagement/Project/Src/PackageRepositoryCache.cs

@ -26,30 +26,36 @@ namespace ICSharpCode.PackageManagement @@ -26,30 +26,36 @@ namespace ICSharpCode.PackageManagement
public class PackageRepositoryCache : IPackageRepositoryCache, IPackageRepositoryFactoryEvents
{
ISharpDevelopPackageRepositoryFactory factory;
RegisteredPackageSources registeredPackageSources;
RegisteredPackageSources packageSources;
PackageManagementOptions options;
IList<RecentPackageInfo> recentPackages;
IRecentPackageRepository recentPackageRepository;
ConcurrentDictionary<string, IPackageRepository> repositories =
new ConcurrentDictionary<string, IPackageRepository>();
public PackageRepositoryCache(
ISharpDevelopPackageRepositoryFactory factory,
RegisteredPackageSources registeredPackageSources,
IList<RecentPackageInfo> recentPackages)
PackageManagementOptions options,
ISharpDevelopPackageRepositoryFactory factory)
{
this.options = options;
this.factory = factory;
this.registeredPackageSources = registeredPackageSources;
this.recentPackages = recentPackages;
this.recentPackages = options.RecentPackages;
}
public PackageRepositoryCache(PackageManagementOptions options)
: this(
options,
new SharpDevelopPackageRepositoryFactory())
{
}
public PackageRepositoryCache(
RegisteredPackageSources registeredPackageSources,
RegisteredPackageSources packageSources,
IList<RecentPackageInfo> recentPackages)
: this(
new SharpDevelopPackageRepositoryFactory(),
registeredPackageSources,
recentPackages)
{
this.factory = new SharpDevelopPackageRepositoryFactory();
this.recentPackages = recentPackages;
this.packageSources = packageSources;
}
public event EventHandler<PackageRepositoryFactoryEventArgs> RepositoryCreated;
@ -102,10 +108,19 @@ namespace ICSharpCode.PackageManagement @@ -102,10 +108,19 @@ namespace ICSharpCode.PackageManagement
IEnumerable<IPackageRepository> CreateAllEnabledRepositories()
{
foreach (PackageSource source in registeredPackageSources.GetEnabledPackageSources()) {
foreach (PackageSource source in PackageSources.GetEnabledPackageSources()) {
yield return CreateRepository(source.Source);
}
}
RegisteredPackageSources PackageSources {
get {
if (packageSources != null) {
return packageSources;
}
return options.PackageSources;
}
}
public IPackageRepository CreateAggregateRepository(IEnumerable<IPackageRepository> repositories)
{

36
src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs

@ -21,6 +21,7 @@ using System.Collections.Generic; @@ -21,6 +21,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using ICSharpCode.SharpDevelop.Project;
using NuGet;
namespace ICSharpCode.PackageManagement
@ -35,20 +36,32 @@ namespace ICSharpCode.PackageManagement @@ -35,20 +36,32 @@ namespace ICSharpCode.PackageManagement
new PackageSource("(Aggregate source)", "All");
ISettings settings;
ISettingsProvider settingsProvider;
PackageSource defaultPackageSource;
RegisteredPackageSources packageSources;
PackageSource activePackageSource;
public RegisteredPackageSourceSettings(ISettings settings)
: this(settings, RegisteredPackageSources.DefaultPackageSource)
public RegisteredPackageSourceSettings(ISettingsProvider settingsProvider)
: this(settingsProvider, RegisteredPackageSources.DefaultPackageSource)
{
}
public RegisteredPackageSourceSettings(ISettings settings, PackageSource defaultPackageSource)
public RegisteredPackageSourceSettings(
ISettingsProvider settingsProvider,
PackageSource defaultPackageSource)
{
this.settings = settings;
this.settingsProvider = settingsProvider;
this.defaultPackageSource = defaultPackageSource;
settings = settingsProvider.LoadSettings();
ReadActivePackageSource();
RegisterSolutionEvents();
}
void RegisterSolutionEvents()
{
settingsProvider.SettingsChanged += SettingsChanged;
}
void ReadActivePackageSource()
@ -176,5 +189,20 @@ namespace ICSharpCode.PackageManagement @@ -176,5 +189,20 @@ namespace ICSharpCode.PackageManagement
{
settings.SetValue(ActivePackageSourceSectionName, activePackageSource.Key, activePackageSource.Value);
}
void SettingsChanged(object sender, EventArgs e)
{
settings = settingsProvider.LoadSettings();
ReadActivePackageSource();
ResetPackageSources();
}
void ResetPackageSources()
{
if (packageSources != null) {
packageSources.CollectionChanged -= PackageSourcesChanged;
packageSources = null;
}
}
}
}

62
src/AddIns/Misc/PackageManagement/Project/Src/SettingsProvider.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.IO;
using ICSharpCode.SharpDevelop.Project;
using NuGet;
namespace ICSharpCode.PackageManagement
{
public class SettingsProvider : ISettingsProvider
{
public static Func<IFileSystem, string, IMachineWideSettings, ISettings> LoadDefaultSettings
= Settings.LoadDefaultSettings;
IPackageManagementProjectService projectService;
public SettingsProvider()
: this(PackageManagementServices.ProjectService)
{
}
public SettingsProvider(IPackageManagementProjectService projectService)
{
this.projectService = projectService;
projectService.SolutionOpened += OnSettingsChanged;
projectService.SolutionClosed += OnSettingsChanged;
}
public event EventHandler SettingsChanged;
void OnSettingsChanged(object sender, SolutionEventArgs e)
{
if (SettingsChanged != null) {
SettingsChanged(this, new EventArgs());
}
}
public ISettings LoadSettings()
{
return LoadSettings(GetSolutionDirectory());
}
string GetSolutionDirectory()
{
ISolution solution = projectService.OpenSolution;
if (solution != null) {
return Path.Combine(solution.Directory, ".nuget");
}
return null;
}
ISettings LoadSettings(string directory)
{
if (directory == null) {
return LoadDefaultSettings(null, null, null);
}
return LoadDefaultSettings(new PhysicalFileSystem(directory), null, null);
}
}
}

2
src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj

@ -176,7 +176,6 @@ @@ -176,7 +176,6 @@
<Compile Include="Src\Helpers\FakePowerShellDetection.cs" />
<Compile Include="Src\Helpers\FakePowerShellSession.cs" />
<Compile Include="Src\Helpers\FakePropertyService.cs" />
<Compile Include="Src\Helpers\FakeSettingsFactory.cs" />
<Compile Include="Src\Helpers\FakeSolutionPackageRepository.cs" />
<Compile Include="Src\Helpers\FakeTextEditorOptions.cs" />
<Compile Include="Src\Helpers\ProjectItemCollectionAssert.cs" />
@ -195,6 +194,7 @@ @@ -195,6 +194,7 @@
<Compile Include="Src\Scripting\ConsoleHostFileConflictResolverTests.cs" />
<Compile Include="Src\Scripting\MSBuildProjectImportsMergerTests.cs" />
<Compile Include="Src\Scripting\MSBuildProjectPropertiesMergerTests.cs" />
<Compile Include="Src\SettingsProviderTests.cs" />
<Compile Include="Src\UpdatedPackagesTests.cs" />
<Compile Include="Src\UpdatePackagesActionTests.cs" />
<Compile Include="Src\UpdateSolutionPackagesActionTests.cs" />

12
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakePackageRepositoryFactory.cs

@ -38,6 +38,13 @@ namespace PackageManagement.Tests.Helpers @@ -38,6 +38,13 @@ namespace PackageManagement.Tests.Helpers
public Dictionary<string, FakePackageRepository> FakePackageRepositories =
new Dictionary<string, FakePackageRepository>();
public FakePackageRepositoryFactory()
{
CreateAggregrateRepositoryAction = (repositories) => {
return FakeAggregateRepository;
};
}
public IPackageRepository CreateRepository(string packageSource)
{
PackageSourcesPassedToCreateRepository.Add(packageSource);
@ -84,16 +91,17 @@ namespace PackageManagement.Tests.Helpers @@ -84,16 +91,17 @@ namespace PackageManagement.Tests.Helpers
}
public IEnumerable<IPackageRepository> RepositoriesPassedToCreateAggregateRepository;
public Func<IEnumerable<IPackageRepository>, IPackageRepository> CreateAggregrateRepositoryAction;
public IPackageRepository CreateAggregateRepository(IEnumerable<IPackageRepository> repositories)
{
RepositoriesPassedToCreateAggregateRepository = repositories;
return FakeAggregateRepository;
return CreateAggregrateRepositoryAction(repositories);
}
public FakePackageRepository AddFakePackageRepositoryForPackageSource(string source)
{
var repository = new FakePackageRepository();
var repository = new FakePackageRepository();
FakePackageRepositories.Add(source, repository);
return repository;
}

8
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/OneRegisteredPackageSourceHelper.cs

@ -26,11 +26,14 @@ namespace PackageManagement.Tests.Helpers @@ -26,11 +26,14 @@ namespace PackageManagement.Tests.Helpers
{
public class OneRegisteredPackageSourceHelper
{
public RegisteredPackageSources RegisteredPackageSources;
public TestablePackageManagementOptions Options;
public FakeSettings FakeSettings;
public PackageSource PackageSource = new PackageSource("http://sharpdevelop.com", "Test Package Source");
public RegisteredPackageSources RegisteredPackageSources {
get { return Options.PackageSources; }
}
public OneRegisteredPackageSourceHelper()
{
CreateOneRegisteredPackageSource();
@ -41,7 +44,6 @@ namespace PackageManagement.Tests.Helpers @@ -41,7 +44,6 @@ namespace PackageManagement.Tests.Helpers
Properties properties = new Properties();
Options = new TestablePackageManagementOptions();
FakeSettings = Options.FakeSettings;
RegisteredPackageSources = Options.PackageSources;
AddOnePackageSource();
}
@ -58,7 +60,7 @@ namespace PackageManagement.Tests.Helpers @@ -58,7 +60,7 @@ namespace PackageManagement.Tests.Helpers
}
public void AddTwoPackageSources()
{
{
AddOnePackageSource();
var packageSource = new PackageSource("http://second.codeplex.com", "second");
RegisteredPackageSources.Add(packageSource);

24
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/TestablePackageManagementOptions.cs

@ -27,17 +27,35 @@ namespace PackageManagement.Tests.Helpers @@ -27,17 +27,35 @@ namespace PackageManagement.Tests.Helpers
{
public Properties Properties;
public FakeSettings FakeSettings;
public FakePackageManagementProjectService ProjectService;
public TestablePackageManagementOptions()
: this(new Properties(), new FakeSettings())
: this(new Properties(), new FakeSettings(), new FakePackageManagementProjectService())
{
}
public TestablePackageManagementOptions(Properties properties, FakeSettings fakeSettings)
: base(properties, fakeSettings)
public TestablePackageManagementOptions(
Properties properties,
FakeSettings fakeSettings,
FakePackageManagementProjectService projectService)
: base(properties, CreateSettingsProvider(fakeSettings, projectService))
{
this.Properties = properties;
this.FakeSettings = fakeSettings;
this.ProjectService = projectService;
}
public static void ChangeSettingsReturnedBySettingsProvider(FakeSettings settings)
{
SettingsProvider.LoadDefaultSettings = (fileSystem, configFile, machineSettings) => {
return settings;
};
}
public static SettingsProvider CreateSettingsProvider(FakeSettings fakeSettings, FakePackageManagementProjectService projectService)
{
ChangeSettingsReturnedBySettingsProvider(fakeSettings);
return new SettingsProvider(projectService);
}
}
}

115
src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementOptionsTests.cs

@ -36,6 +36,8 @@ namespace PackageManagement.Tests @@ -36,6 +36,8 @@ namespace PackageManagement.Tests
Properties properties;
PackageManagementOptions options;
FakeSettings fakeSettings;
SettingsProvider settingsProvider;
FakePackageManagementProjectService projectService;
void CreateOptions()
{
@ -63,12 +65,26 @@ namespace PackageManagement.Tests @@ -63,12 +65,26 @@ namespace PackageManagement.Tests
void CreateOptions(FakeSettings fakeSettings)
{
CreateProperties();
options = new PackageManagementOptions(properties, fakeSettings);
CreateSettingsProvider(fakeSettings);
options = new PackageManagementOptions(properties, settingsProvider);
}
void CreateSettingsProvider(FakeSettings fakeSettings)
{
projectService = new FakePackageManagementProjectService();
settingsProvider = TestablePackageManagementOptions.CreateSettingsProvider(fakeSettings, projectService);
}
void ChangeSettingsReturnedBySettingsProvider()
{
fakeSettings = new FakeSettings();
TestablePackageManagementOptions.ChangeSettingsReturnedBySettingsProvider(fakeSettings);
}
void CreateOptions(Properties properties, FakeSettings fakeSettings)
{
options = new PackageManagementOptions(properties, fakeSettings);
CreateSettingsProvider(fakeSettings);
options = new PackageManagementOptions(properties, settingsProvider);
}
void SaveOptions()
@ -88,6 +104,18 @@ namespace PackageManagement.Tests @@ -88,6 +104,18 @@ namespace PackageManagement.Tests
fakeSettings.SetPackageRestoreSetting(true);
}
void OpenSolution()
{
var helper = new SolutionHelper(@"d:\projects\MyProject\MySolution.sln");
projectService.FireSolutionOpenedEvent(helper.MSBuildSolution);
}
void CloseSolution()
{
var helper = new SolutionHelper(@"d:\projects\MyProject\MySolution.sln");
projectService.FireSolutionClosedEvent(helper.MSBuildSolution);
}
[Test]
public void PackageSources_OnePackageSourceInSettings_ContainsSinglePackageSourceFromSettings()
{
@ -465,5 +493,88 @@ namespace PackageManagement.Tests @@ -465,5 +493,88 @@ namespace PackageManagement.Tests
KeyValuePair<string, string> keyValuePair = fakeSettings.GetValuePassedToSetValueForPackageRestoreSection();
Assert.AreEqual("False", keyValuePair.Value);
}
[Test]
public void PackageSources_SolutionOpenedAfterInitialPackageSourcesLoaded_ContainsPackageSourceFromSolutionSpecificSettings()
{
CreateSettings();
var packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
CreateOptions(fakeSettings);
RegisteredPackageSources initialSources = options.PackageSources;
var expectedInitialSources = new List<PackageSource>();
expectedInitialSources.Add(packageSource);
ChangeSettingsReturnedBySettingsProvider();
packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
var expectedSources = new List<PackageSource>();
expectedSources.Add(packageSource);
packageSource = new PackageSource("http://nuget.org", "ProjectSource");
fakeSettings.AddFakePackageSource(packageSource);
expectedSources.Add(packageSource);
OpenSolution();
RegisteredPackageSources actualSources = options.PackageSources;
Assert.AreEqual(expectedInitialSources, initialSources);
Assert.AreEqual(expectedSources, actualSources);
}
[Test]
public void PackageSources_SolutionClosedAfterInitialPackageSourcesLoaded_PackageSourcesReloaded()
{
CreateSettings();
var packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
var expectedInitialSources = new List<PackageSource>();
expectedInitialSources.Add(packageSource);
packageSource = new PackageSource("http://nuget.org", "ProjectSource");
fakeSettings.AddFakePackageSource(packageSource);
expectedInitialSources.Add(packageSource);
OpenSolution();
CreateOptions(fakeSettings);
RegisteredPackageSources initialSources = options.PackageSources;
ChangeSettingsReturnedBySettingsProvider();
packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
var expectedSources = new List<PackageSource>();
expectedSources.Add(packageSource);
CloseSolution();
RegisteredPackageSources actualSources = options.PackageSources;
Assert.AreEqual(expectedInitialSources, initialSources);
Assert.AreEqual(expectedSources, actualSources);
}
[Test]
public void PackageSources_SolutionClosedAfterInitialPackageSourcesLoaded_ActivePackageSourceReloaded()
{
CreateSettings();
var packageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.AddFakePackageSource(packageSource);
var expectedInitialSources = new List<PackageSource>();
expectedInitialSources.Add(packageSource);
var initialActivePackageSource = new PackageSource("http://nuget.org", "ProjectSource");
fakeSettings.AddFakePackageSource(initialActivePackageSource);
fakeSettings.SetFakeActivePackageSource(initialActivePackageSource);
expectedInitialSources.Add(initialActivePackageSource);
OpenSolution();
CreateOptions(fakeSettings);
RegisteredPackageSources actualInitialPackageSources = options.PackageSources;
PackageSource actualInitialActivePackageSource = options.ActivePackageSource;
ChangeSettingsReturnedBySettingsProvider();
var expectedActivePackageSource = new PackageSource("http://codeplex.com", "Test");
fakeSettings.SetFakeActivePackageSource(expectedActivePackageSource);
fakeSettings.AddFakePackageSource(expectedActivePackageSource);
CloseSolution();
PackageSource actualSource = options.ActivePackageSource;
Assert.AreEqual(initialActivePackageSource, actualInitialActivePackageSource);
Assert.AreEqual(expectedActivePackageSource, actualSource);
Assert.AreEqual(expectedInitialSources, actualInitialPackageSources);
Assert.AreEqual(new PackageSource[] { expectedActivePackageSource }, options.PackageSources);
}
}
}

4
src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementOptionsViewModelTests.cs

@ -50,8 +50,10 @@ namespace PackageManagement.Tests @@ -50,8 +50,10 @@ namespace PackageManagement.Tests
void CreateOptions()
{
var properties = new Properties();
var projectService = new FakePackageManagementProjectService();
fakeSettings = new FakeSettings();
options = new PackageManagementOptions(properties, fakeSettings);
SettingsProvider settingsProvider = TestablePackageManagementOptions.CreateSettingsProvider(fakeSettings, projectService);
options = new PackageManagementOptions(properties, settingsProvider);
}
void EnablePackageRestoreInOptions()

38
src/AddIns/Misc/PackageManagement/Test/Src/PackageRepositoryCacheTests.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.IO.Packaging;
using System.Linq;
using ICSharpCode.PackageManagement;
using ICSharpCode.PackageManagement.Design;
using NuGet;
@ -52,9 +53,7 @@ namespace PackageManagement.Tests @@ -52,9 +53,7 @@ namespace PackageManagement.Tests
{
nuGetPackageSource = new PackageSource("http://nuget.org", "NuGet");
fakePackageRepositoryFactory = new FakePackageRepositoryFactory();
RegisteredPackageSources packageSources = packageSourcesHelper.Options.PackageSources;
IList<RecentPackageInfo> recentPackages = packageSourcesHelper.Options.RecentPackages;
cache = new PackageRepositoryCache(fakePackageRepositoryFactory, packageSources, recentPackages);
cache = new PackageRepositoryCache(packageSourcesHelper.Options, fakePackageRepositoryFactory);
}
FakePackageRepository AddFakePackageRepositoryForPackageSource(string source)
@ -395,5 +394,38 @@ namespace PackageManagement.Tests @@ -395,5 +394,38 @@ namespace PackageManagement.Tests
Assert.IsNull(eventArgs);
}
[Test]
public void CreateAggregateRepository_SolutionClosedAndEnabledPackageSourcesChangedAfterCacheCreated_AggregateRepositoryContainsCorrectEnabledPackageRepositories()
{
CreatePackageSources();
packageSourcesHelper.AddTwoPackageSources("Source1", "Source2");
CreateCacheUsingPackageSources();
FakePackageRepository source1Repo = AddFakePackageRepositoryForPackageSource("Source1");
FakePackageRepository source2Repo = AddFakePackageRepositoryForPackageSource("Source2");
fakePackageRepositoryFactory.CreateAggregrateRepositoryAction = (repositories) => {
return new AggregateRepository (repositories);
};
var initialAggregateRepository = cache.CreateAggregateRepository() as AggregateRepository;
var expectedInitialRepositories = new FakePackageRepository[] {
source1Repo,
source2Repo
};
List<IPackageRepository> actualInitialRepositories = initialAggregateRepository.Repositories.ToList();
var solution = new SolutionHelper().MSBuildSolution;
packageSourcesHelper.Options.ProjectService.FireSolutionClosedEvent(solution);
packageSourcesHelper.Options.PackageSources.Clear();
packageSourcesHelper.Options.PackageSources.Add(new PackageSource ("Source3"));
FakePackageRepository source3Repo = AddFakePackageRepositoryForPackageSource("Source3");
var expectedRepositories = new FakePackageRepository[] {
source3Repo
};
var aggregateRepository = cache.CreateAggregateRepository() as AggregateRepository;
List<IPackageRepository> actualRepositories = aggregateRepository.Repositories.ToList();
CollectionAssert.AreEqual(expectedInitialRepositories, actualInitialRepositories);
CollectionAssert.AreEqual(expectedRepositories, actualRepositories);
}
}
}

80
src/AddIns/Misc/PackageManagement/Test/Src/SettingsProviderTests.cs

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.PackageManagement;
using ICSharpCode.PackageManagement.Design;
using NuGet;
using NUnit.Framework;
using PackageManagement.Tests.Helpers;
namespace PackageManagement.Tests
{
[TestFixture]
public class SettingsProviderTests
{
SettingsProvider settingsProvider;
FakeSettings fakeSettings;
FakePackageManagementProjectService projectService;
IFileSystem fileSystemUsedToLoadSettings;
string configFileUsedToLoadSettings;
IMachineWideSettings machinesettingsUsedToLoadSettings;
[SetUp]
public void SetUp()
{
fakeSettings = new FakeSettings();
projectService = new FakePackageManagementProjectService();
SettingsProvider.LoadDefaultSettings = LoadDefaultSettings;
settingsProvider = new SettingsProvider(projectService);
}
ISettings LoadDefaultSettings(IFileSystem fileSystem, string configFile, IMachineWideSettings machineSettings)
{
fileSystemUsedToLoadSettings = fileSystem;
configFileUsedToLoadSettings = configFile;
machinesettingsUsedToLoadSettings = machineSettings;
return fakeSettings;
}
void OpenSolution(string fileName)
{
var helper = new SolutionHelper(fileName);
projectService.OpenSolution = helper.MSBuildSolution;
}
[TearDown]
public void TearDown()
{
// This resets SettingsProvider.LoadDefaultSettings.
TestablePackageManagementOptions.CreateSettingsProvider(fakeSettings, projectService);
}
[Test]
public void LoadSettings_NoSolutionOpen_NullFileSystemAndNullConfigFileAndNullMachineSettingsUsed()
{
fileSystemUsedToLoadSettings = new FakeFileSystem();
configFileUsedToLoadSettings = "configFile";
ISettings settings = settingsProvider.LoadSettings();
Assert.IsNull(fileSystemUsedToLoadSettings);
Assert.IsNull(configFileUsedToLoadSettings);
Assert.IsNull(machinesettingsUsedToLoadSettings);
Assert.AreEqual(fakeSettings, settings);
}
[Test]
public void LoadSettings_SolutionOpen_FileSystemWithRootSetToSolutionDotNuGetDirectoryUsedToLoadSettings()
{
string fileName = @"d:\projects\MyProject\MyProject.sln";
OpenSolution(fileName);
ISettings settings = settingsProvider.LoadSettings();
Assert.AreEqual(@"d:\projects\MyProject\.nuget", fileSystemUsedToLoadSettings.Root);
Assert.AreEqual(fakeSettings, settings);
}
}
}

2
src/Main/GlobalAssemblyInfo.cs.template

@ -46,7 +46,7 @@ internal static class RevisionClass @@ -46,7 +46,7 @@ internal static class RevisionClass
public const string Minor = "0";
public const string Build = "0";
public const string Revision = "$INSERTREVISION$";
public const string VersionName = "Beta 3"; // "" is not valid for no version name, you have to use null if you don't want a version name (eg "Beta 1")
public const string VersionName = "Beta 4"; // "" is not valid for no version name, you have to use null if you don't want a version name (eg "Beta 1")
public const string FullVersion = Major + "." + Minor + "." + Build + ".$INSERTREVISION$$INSERTBRANCHPOSTFIX$$INSERTVERSIONNAMEPOSTFIX$";
}

Loading…
Cancel
Save