Skip to content

Commit

Permalink
Merge pull request icsharpcode#593 from jogibear9988/master
Browse files Browse the repository at this point in the history
Support for {x:Refrence}, Template & Namescope fixes
  • Loading branch information
Rpinski committed Nov 17, 2014
2 parents 013a342 + a8bb555 commit a0eafb3
Show file tree
Hide file tree
Showing 38 changed files with 943 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;

namespace ICSharpCode.WpfDesign.Designer.Controls
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;

namespace ICSharpCode.WpfDesign.Designer.Controls
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;


namespace ICSharpCode.WpfDesign.Designer.Controls
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.EditStyleContextMenu"
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 EditStyle, Source={x:Static Translation:Translations.Instance}}" Click="Click_EditStyle">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/edit.png" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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 System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Xml;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.XamlDom;

namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public partial class EditStyleContextMenu
{
private DesignItem designItem;

public EditStyleContextMenu(DesignItem designItem)
{
this.designItem = designItem;

InitializeComponent();
}

void Click_EditStyle(object sender, RoutedEventArgs e)
{
var element = designItem.View;
object defaultStyleKey = element.GetValue(FrameworkElement.DefaultStyleKeyProperty);
Style style = Application.Current.TryFindResource(defaultStyleKey) as Style;

var service = ((XamlComponentService) designItem.Services.Component);

var ms = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
XamlWriter.Save(style, writer);

var rootItem = this.designItem.Context.RootItem as XamlDesignItem;

ms.Position = 0;
var sr = new StreamReader(ms);
var xaml = sr.ReadToEnd();

var xamlObject = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, ((XamlDesignContext)this.designItem.Context).ParserSettings);

var styleDesignItem=service.RegisterXamlComponentRecursive(xamlObject);
designItem.Properties.GetProperty("Resources").CollectionElements.Add(styleDesignItem);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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 System.Linq;
using System.Windows.Controls;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;

namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))]
[ExtensionFor(typeof (Control))]
[Extension(Order = 10)]
public class EditStyleContextMenuExtension : PrimarySelectionAdornerProvider
{
DesignPanel panel;
ContextMenu contextMenu;

protected override void OnInitialized()
{
base.OnInitialized();

contextMenu = new EditStyleContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
if (panel != null)
panel.AddContextMenu(contextMenu);
}

protected override void OnRemove()
{
if (panel != null)
panel.RemoveContextMenu(contextMenu);

base.OnRemove();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
using System.Collections.Generic;
using ICSharpCode.WpfDesign.Designer.UIExtensions;

namespace ICSharpCode.WpfDesign.Designer.Extensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using ICSharpCode.WpfDesign.Extensions;
using System.ComponentModel;
using ICSharpCode.WpfDesign.Adorners;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Automation.Peers;
using System.Windows.Controls.Primitives;
using System.Diagnostics;
using System.Windows.Input;

namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class SnaplinePlacementBehavior : RasterPlacementBehavior
{
public static bool GetDisableSnaplines(DependencyObject obj)
{
return (bool)obj.GetValue(DisableSnaplinesProperty);
}

public static void SetDisableSnaplines(DependencyObject obj, bool value)
{
obj.SetValue(DisableSnaplinesProperty, value);
}

public static readonly DependencyProperty DisableSnaplinesProperty =
DependencyProperty.RegisterAttached("DisableSnaplines", typeof(bool), typeof(SnaplinePlacementBehavior), new PropertyMetadata(false));


AdornerPanel adornerPanel;
Canvas surface;
List<Snapline> horizontalMap;
Expand Down Expand Up @@ -194,18 +203,18 @@ private IEnumerable<DesignItem> AllDesignItems(DesignItem designItem = null)

if (designItem != null && designItem.ContentProperty != null && designItem.ContentProperty.IsCollection)
foreach (var collectionElement in designItem.ContentProperty.CollectionElements)
{
if (collectionElement != null)
yield return collectionElement;

foreach (var el in AllDesignItems(collectionElement))
{
if (collectionElement != null)
yield return collectionElement;

foreach (var el in AllDesignItems(collectionElement))
{
if (el != null)
yield return el;
}
if (el != null)
yield return el;
}
}
}

void BuildMaps(PlacementOperation operation)
{
horizontalMap = new List<Snapline>();
Expand All @@ -217,10 +226,11 @@ void BuildMaps(PlacementOperation operation)
AddLines(containerRect, 0, false);

foreach (var item in AllDesignItems() /* ExtendedItem.ContentProperty.CollectionElements */
.Except(operation.PlacedItems.Select(f => f.Item))) {
.Except(operation.PlacedItems.Select(f => f.Item))
.Where(x=>!GetDisableSnaplines(x.View))) {
if (item != null) {
var bounds = GetPosition(operation, item);

AddLines(bounds, 0, false);
AddLines(bounds, Margin, true);
AddBaseline(item, bounds, horizontalMap);
Expand All @@ -235,26 +245,26 @@ void AddLines(Rect r, double inflate, bool requireOverlap)

void AddLines(Rect r, double inflate, bool requireOverlap, List<Snapline> h, List<Snapline> v, PlacementAlignment? filter)
{
if (r != Rect.Empty)
{
Rect r2 = r;
r2.Inflate(inflate, inflate);

if (filter == null || filter.Value.Vertical == VerticalAlignment.Top)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom });

if (filter == null)
{
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top + Math.Abs((r2.Top - r2.Bottom) / 2), Start = r.Left, End = r.Right });
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left + Math.Abs((r2.Left - r2.Right) / 2), Start = r.Top, End = r.Bottom });
}
}
if (r != Rect.Empty)
{
Rect r2 = r;
r2.Inflate(inflate, inflate);
if (filter == null || filter.Value.Vertical == VerticalAlignment.Top)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom });
if (filter == null)
{
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top + Math.Abs((r2.Top - r2.Bottom) / 2), Start = r.Left, End = r.Right });
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left + Math.Abs((r2.Left - r2.Right) / 2), Start = r.Top, End = r.Bottom });
}
}
}

void AddBaseline(DesignItem item, Rect bounds, List<Snapline> list)
Expand All @@ -279,9 +289,9 @@ void DeleteSurface()

void DrawLine(double x1, double y1, double x2, double y2)
{
if (double.IsInfinity(x1) || double.IsNaN(x1) || double.IsInfinity(y1) || double.IsNaN(y1) ||
double.IsInfinity(x2) || double.IsNaN(x2) || double.IsInfinity(y2) || double.IsNaN(y2))
return;
if (double.IsInfinity(x1) || double.IsNaN(x1) || double.IsInfinity(y1) || double.IsNaN(y1) ||
double.IsInfinity(x2) || double.IsNaN(x2) || double.IsInfinity(y2) || double.IsNaN(y2))
return;

var line1 = new Line() {
X1 = x1,
Expand Down Expand Up @@ -321,7 +331,7 @@ void DrawLine(double x1, double y1, double x2, double y2)
}

static bool Snap(List<Snapline> input, List<Snapline> map, double accuracy,
out List<Snapline> drawLines, out double delta)
out List<Snapline> drawLines, out double delta)
{
delta = double.MaxValue;
drawLines = null;
Expand All @@ -330,7 +340,7 @@ static bool Snap(List<Snapline> input, List<Snapline> map, double accuracy,
foreach (var mapLine in map) {
if (Math.Abs(mapLine.Offset - inputLine.Offset) <= accuracy) {
if (!inputLine.RequireOverlap && !mapLine.RequireOverlap ||
Math.Max(inputLine.Start, mapLine.Start) < Math.Min(inputLine.End, mapLine.End))
Math.Max(inputLine.Start, mapLine.Start) < Math.Min(inputLine.End, mapLine.End))
{
if (mapLine.Group == inputLine.Group)
delta = mapLine.Offset - inputLine.Offset;
Expand Down Expand Up @@ -376,4 +386,3 @@ class Snapline
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Linq;
using System.Windows;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
using ICSharpCode.WpfDesign.Designer.UIExtensions;

namespace ICSharpCode.WpfDesign.Designer.Extensions
{
Expand Down
Loading

0 comments on commit a0eafb3

Please sign in to comment.