Browse Source

Merge pull request #604 from jogibear9988/AppXamlParsing

WPF Designer Fixes (App.Xaml support, Load of AdditionalDlls,...)
pull/612/head
Siegfried Pammer 11 years ago
parent
commit
cdd6d8aca5
  1. 31
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs
  2. 64
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  3. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.addin
  4. 29
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  5. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
  6. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultCommandsContextMenu.xaml
  7. 43
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultCommandsContextMenu.xaml.cs
  8. 54
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultCommandsContextMenuExtension.cs
  9. 58
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs
  10. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/EditStyleContextMenuExtension.cs
  11. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs
  12. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs
  13. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs
  14. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs
  15. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.CopyIcon.png
  16. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.CutIcon.png
  17. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.DeleteIcon.png
  18. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.PasteIcon.png
  19. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.RedoIcon.png
  20. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.UndoIcon.png
  21. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineView.xaml
  22. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs
  23. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ClickOrDragMouseGesture.cs
  24. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs
  25. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs
  26. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  27. 125
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs
  28. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs
  29. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SamplesTests.cs
  30. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs
  31. 27
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/DesignInstanceExtension.cs
  32. 84
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/TemplateHelper.cs
  33. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj
  34. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
  35. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs
  36. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs
  37. 67
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  38. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  39. 33
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs
  40. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs
  41. 15
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/Extension.cs
  42. 17
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionManager.cs
  43. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionServer.cs
  44. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/SelectionExtensionServer.cs
  45. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs
  46. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs

31
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
@ -73,6 +74,36 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -73,6 +74,36 @@ namespace ICSharpCode.WpfDesign.AddIn
}
}
public override Uri ConvertUriToLocalUri(Uri uri)
{
if (!uri.IsAbsoluteUri)
{
var compilation = SD.ParserService.GetCompilationForFile(file.FileName);
var assembly = this.typeResolutionService.LoadAssembly(compilation.MainAssembly);
var prj = SD.ProjectService.CurrentProject;
if (uri.OriginalString.Contains(";"))
{
var parts = uri.OriginalString.Split(';');
if (prj.Name == parts[0].Substring(1))
{
var newUri = new Uri(("file://" + Path.Combine(prj.Directory, parts[1].Substring("component".Length + 1))).Replace("\\", "/"), UriKind.RelativeOrAbsolute);
return newUri;
}
}
else
{
var strg = uri.OriginalString;
if (strg.StartsWith("/"))
strg = strg.Substring(1);
var newUri = new Uri(("file://" + Path.Combine(prj.Directory, strg)).Replace("\\", "/"), UriKind.RelativeOrAbsolute);
return newUri;
}
}
return uri;
}
Assembly FindAssemblyInProjectReferences(string name)
{
IProject pc = GetProject(file);

64
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs

@ -22,16 +22,20 @@ using System.ComponentModel; @@ -22,16 +22,20 @@ using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Markup;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Designer;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
@ -44,6 +48,7 @@ using ICSharpCode.WpfDesign.Designer.OutlineView; @@ -44,6 +48,7 @@ using ICSharpCode.WpfDesign.Designer.OutlineView;
using ICSharpCode.WpfDesign.Designer.PropertyGrid;
using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.AddIn
{
@ -60,6 +65,10 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -60,6 +65,10 @@ namespace ICSharpCode.WpfDesign.AddIn
this.TabPageText = "${res:FormsDesigner.DesignTabPages.DesignTabPage}";
this.IsActiveViewContentChanged += OnIsActiveViewContentChanged;
var compilation = SD.ParserService.GetCompilationForFile(file.FileName);
_path = Path.GetDirectoryName(compilation.MainAssembly.UnresolvedAssembly.Location);
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
static WpfViewContent()
@ -101,6 +110,8 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -101,6 +110,8 @@ namespace ICSharpCode.WpfDesign.AddIn
if (outline != null) {
outline.Root = null;
}
using (XmlTextReader r = new XmlTextReader(stream)) {
XamlLoadSettings settings = new XamlLoadSettings();
settings.DesignerAssemblies.Add(typeof(WpfViewContent).Assembly);
@ -117,7 +128,20 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -117,7 +128,20 @@ namespace ICSharpCode.WpfDesign.AddIn
settings.ReportErrors = UpdateTasks;
designer.LoadDesigner(r, settings);
designer.ContextMenuOpening += (sender, e) => MenuService.ShowContextMenu(e.OriginalSource as UIElement, designer, "/AddIns/WpfDesign/Designer/ContextMenu");
designer.DesignPanel.ContextMenuHandler = (contextMenu) => {
var newContextmenu = new ContextMenu();
var sdContextMenuItems = MenuService.CreateMenuItems(newContextmenu, designer, "/AddIns/WpfDesign/Designer/ContextMenu", "ContextMenu");
foreach(var entry in sdContextMenuItems)
newContextmenu.Items.Add(entry);
newContextmenu.Items.Add(new Separator());
var items = contextMenu.Items.Cast<Object>().ToList();
contextMenu.Items.Clear();
foreach(var entry in items)
newContextmenu.Items.Add(entry);
designer.DesignPanel.ContextMenu = newContextmenu;
};
if (outline != null && designer.DesignContext != null && designer.DesignContext.RootItem != null) {
outline.Root = OutlineNode.Create(designer.DesignContext.RootItem);
@ -129,9 +153,46 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -129,9 +153,46 @@ namespace ICSharpCode.WpfDesign.AddIn
} catch (Exception e) {
this.UserContent = new WpfDocumentError(e);
}
try{
var appXaml = SD.ProjectService.CurrentProject.Items.FirstOrDefault(x=>x.FileName.GetFileName().ToLower() == ("app.xaml"));
if (appXaml!=null){
var f=appXaml as FileProjectItem;
OpenedFile a = SD.FileService.GetOrCreateOpenedFile(f.FileName);
var xml = XmlReader.Create(a.OpenRead());
var doc=new XmlDocument();
doc.Load(xml);
var node = doc.FirstChild.ChildNodes.Cast<XmlNode>().FirstOrDefault(x=>x.Name=="Application.Resources");
foreach (XmlAttribute att in doc.FirstChild.Attributes.Cast<XmlAttribute>().ToList())
{
if (att.Name.StartsWith("xmlns"))
node.Attributes.Append(att);
}
var appXamlXml = XmlReader.Create(new StringReader(node.InnerXml));
var parsed = XamlParser.Parse(appXamlXml, ((XamlDesignContext) designer.DesignContext).ParserSettings);
var dict = (ResourceDictionary)parsed.RootInstance;
designer.DesignPanel.Resources.MergedDictionaries.Add(dict);
}
} catch (Exception ex) {
LoggingService.Error("Error in loading app.xaml", ex);
}
}
}
System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var assemblyName = (new AssemblyName(args.Name));
string fileName = Path.Combine(_path, assemblyName.Name) + ".dll";
if (File.Exists(fileName))
return typeResolutionService.LoadAssembly(fileName);
return null;
}
private TypeResolutionService typeResolutionService = new TypeResolutionService();
private string _path;
private MemoryStream _stream;
bool wasChangedInDesigner;
@ -285,6 +346,7 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -285,6 +346,7 @@ namespace ICSharpCode.WpfDesign.AddIn
public override void Dispose()
{
AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
SD.ProjectService.ProjectItemAdded -= OnReferenceAdded;
propertyContainer.Clear();

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.addin

@ -49,7 +49,7 @@ @@ -49,7 +49,7 @@
-->
<Path name="/AddIns/WpfDesign/Designer/ContextMenu">
<MenuItem label="${res:ICSharpCode.WPFDesigner.ContextMenu.ViewXAML}" id="viewXaml" icon="Icons.16x16.XMLFileIcon" class="ICSharpCode.WpfDesign.AddIn.Commands.ViewXaml" />
<MenuItem label="seperator1" type="Separator" />
<!--<MenuItem label="seperator1" type="Separator" />
<Condition name="IsCutCopyEnabled" action="Disable">
<MenuItem id="cut" label="${res:ICSharpCode.WPFDesigner.ContextMenu.Cut}" icon="Icons.16x16.CutIcon" shortcut="Control|X" class="ICSharpCode.WpfDesign.AddIn.Commands.Cut" />
<MenuItem id="copy" label="${res:ICSharpCode.WPFDesigner.ContextMenu.Copy}" icon="Icons.16x16.CopyIcon" shortcut="Control|C" class="ICSharpCode.WpfDesign.AddIn.Commands.Copy" />
@ -66,7 +66,7 @@ @@ -66,7 +66,7 @@
</Condition>
<Condition name="IsRedoEnabled" action="Disable">
<MenuItem id="redo" label="${res:ICSharpCode.WPFDesigner.ContextMenu.Redo}" icon="Icons.16x16.RedoIcon" shortcut="Control|R" class="ICSharpCode.WpfDesign.AddIn.Commands.Redo" />
</Condition>
</Condition>-->
<MenuItem label="seperator3" type="Separator" />
<MenuItem id="tools" label="${res:ICSharpCode.WPFDesigner.ContextMenu.Tools}" icon="PadIcons.Toolbar" shortcut="Control|Alt|X" class="ICSharpCode.WpfDesign.AddIn.Commands.Tools" />
<MenuItem id="properties" label="${res:ICSharpCode.WPFDesigner.ContextMenu.Properties}" icon="Icons.16x16.PropertiesIcon" shortcut="F4" class="ICSharpCode.WpfDesign.AddIn.Commands.Properties" />

29
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

@ -32,6 +32,7 @@ using System.Windows.Threading; @@ -32,6 +32,7 @@ using System.Windows.Threading;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.WpfDesign.Designer
@ -468,6 +469,8 @@ namespace ICSharpCode.WpfDesign.Designer @@ -468,6 +469,8 @@ namespace ICSharpCode.WpfDesign.Designer
private Dictionary<ContextMenu, Tuple<int,List<object>>> contextMenusAndEntries = new Dictionary<ContextMenu, Tuple<int,List<object>>>();
public Action<ContextMenu> ContextMenuHandler { get; set; }
public void AddContextMenu(ContextMenu contextMenu)
{
contextMenusAndEntries.Add(contextMenu, new Tuple<int, List<object>>(contextMenusAndEntries.Count, new List<object>(contextMenu.Items.Cast<object>())));
@ -491,24 +494,32 @@ namespace ICSharpCode.WpfDesign.Designer @@ -491,24 +494,32 @@ namespace ICSharpCode.WpfDesign.Designer
private void UpdateContextMenu()
{
if (contextMenusAndEntries.Count == 0)
if (this.ContextMenu != null)
{
this.ContextMenu.Items.Clear();
this.ContextMenu = null;
if (this.ContextMenu == null)
this.ContextMenu = new ContextMenu();
}
var contextMenu = new ContextMenu();
this.ContextMenu.Items.Clear();
foreach (var entries in contextMenusAndEntries.Values.OrderBy(x => x.Item1).Select(x => x.Item2))
{
if (this.ContextMenu.Items.Count > 0)
this.ContextMenu.Items.Add(new Separator());
if (contextMenu.Items.Count > 0)
contextMenu.Items.Add(new Separator());
foreach (var entry in entries)
{
ContextMenu.Items.Add(entry);
var ctl = ((FrameworkElement)entry).TryFindParent<ItemsControl>();
if (ctl != null)
ctl.Items.Remove(entry);
contextMenu.Items.Add(entry);
}
}
if (ContextMenuHandler != null)
ContextMenuHandler(contextMenu);
else
this.ContextMenu = contextMenu;
}
#endregion

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

@ -70,21 +70,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -70,21 +70,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (IsPropertySet(child, Canvas.LeftProperty) || !IsPropertySet(child, Canvas.RightProperty)) {
x = GetCanvasProperty(child, Canvas.LeftProperty);
} else {
x = extendedComponent.ActualWidth - GetCanvasProperty(child, Canvas.RightProperty) - PlacementOperation.GetRealElementSize(child).Width;
x = extendedComponent.ActualWidth - GetCanvasProperty(child, Canvas.RightProperty) - PlacementOperation.GetRealElementSize(child).Width;
}
if (IsPropertySet(child, Canvas.TopProperty) || !IsPropertySet(child, Canvas.BottomProperty)) {
y = GetCanvasProperty(child, Canvas.TopProperty);
} else {
y = extendedComponent.ActualHeight - GetCanvasProperty(child, Canvas.BottomProperty) - PlacementOperation.GetRealElementSize(child).Height;
y = extendedComponent.ActualHeight - GetCanvasProperty(child, Canvas.BottomProperty) - PlacementOperation.GetRealElementSize(child).Height;
}
var p = new Point(x, y);
//Fixes, Empty Image Resized to 0
//return new Rect(p, child.RenderSize);
return new Rect(p, PlacementOperation.GetRealElementSize(item.View));
}
//Fixes, Empty Image Resized to 0
//return new Rect(p, child.RenderSize);
return new Rect(p, PlacementOperation.GetRealElementSize(item.View));
}
public override void SetPosition(PlacementInformation info)
{

38
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultCommandsContextMenu.xaml

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.DefaultCommandsContextMenu"
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 Command="ApplicationCommands.Cut">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Icons.16x16.CutIcon.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="ApplicationCommands.Copy">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Icons.16x16.CopyIcon.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="ApplicationCommands.Paste">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Icons.16x16.PasteIcon.png" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Command="ApplicationCommands.Delete">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Icons.16x16.DeleteIcon.png" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Command="ApplicationCommands.Undo">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Icons.16x16.UndoIcon.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="ApplicationCommands.Redo">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Icons.16x16.RedoIcon.png" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>

43
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultCommandsContextMenu.xaml.cs

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
// 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 DefaultCommandsContextMenu
{
private DesignItem designItem;
public DefaultCommandsContextMenu(DesignItem designItem)
{
this.designItem = designItem;
InitializeComponent();
}
}
}

54
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultCommandsContextMenuExtension.cs

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
// 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;
using System.Windows.Controls;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionServer(typeof(PrimarySelectionExtensionServer))]
[ExtensionFor(typeof (UIElement))]
[Extension(Order = 10)]
public class DefaultCommandsContextMenuExtension : SelectionAdornerProvider
{
DesignPanel panel;
ContextMenu contextMenu;
protected override void OnInitialized()
{
base.OnInitialized();
contextMenu = new DefaultCommandsContextMenu(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();
}
}
}

58
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs

@ -38,27 +38,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -38,27 +38,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
[ExtensionFor(typeof(Viewbox))]
public class DefaultPlacementBehavior : BehaviorExtension, IPlacementBehavior
{
static List<Type> _contentControlsNotAllowedToAdd;
static DefaultPlacementBehavior()
{
_contentControlsNotAllowedToAdd = new List<Type>();
_contentControlsNotAllowedToAdd.Add(typeof (Frame));
_contentControlsNotAllowedToAdd.Add(typeof (GroupItem));
_contentControlsNotAllowedToAdd.Add(typeof (HeaderedContentControl));
_contentControlsNotAllowedToAdd.Add(typeof (Label));
_contentControlsNotAllowedToAdd.Add(typeof (ListBoxItem));
//_contentControlsNotAllowedToAdd.Add(typeof (ButtonBase));
_contentControlsNotAllowedToAdd.Add(typeof (StatusBarItem));
_contentControlsNotAllowedToAdd.Add(typeof (ToolTip));
}
{ }
public static bool CanContentControlAdd(ContentControl control)
{
Debug.Assert(control != null);
return !_contentControlsNotAllowedToAdd.Any(type => type.IsAssignableFrom(control.GetType()));
}
protected override void OnInitialized()
{
base.OnInitialized();
@ -68,7 +50,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -68,7 +50,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
ExtendedItem.AddBehavior(typeof(IPlacementBehavior), this);
}
public virtual bool CanPlace(ICollection<DesignItem> childItems, PlacementType type, PlacementAlignment position)
public virtual bool CanPlace(IEnumerable<DesignItem> childItems, PlacementType type, PlacementAlignment position)
{
return true;
}
@ -81,27 +63,32 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -81,27 +63,32 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
InfoTextEnterArea.Stop(ref infoTextEnterArea);
this.ExtendedItem.Services.Selection.SetSelectedComponents(null);
this.ExtendedItem.Services.Selection.SetSelectedComponents(operation.PlacedItems.Select(x => x.Item).ToList());
}
this.ExtendedItem.Services.Selection.SetSelectedComponents(null);
this.ExtendedItem.Services.Selection.SetSelectedComponents(operation.PlacedItems.Select(x => x.Item).ToList());
}
public virtual Rect GetPosition(PlacementOperation operation, DesignItem item)
{
if (item.View == null)
return Rect.Empty;
var p = item.View.TranslatePoint(new Point(), operation.CurrentContainer.View);
return new Rect(p, PlacementOperation.GetRealElementSize(item.View));
return new Rect(p, PlacementOperation.GetRealElementSize(item.View));
}
public virtual void BeforeSetPosition(PlacementOperation operation)
{
}
public virtual bool CanPlaceItem(PlacementInformation info)
{
return true;
}
public virtual void SetPosition(PlacementInformation info)
{
if (info.Operation.Type != PlacementType.Move)
ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
if (info.Operation.Type != PlacementType.Move)
ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
}
public virtual bool CanLeaveContainer(PlacementOperation operation)
@ -129,7 +116,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -129,7 +116,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (canEnter && !shouldAlwaysEnter && !Keyboard.IsKeyDown(Key.LeftAlt) && !Keyboard.IsKeyDown(Key.RightAlt))
{
var b = new Rect(0, 0, ((FrameworkElement)this.ExtendedItem.View).ActualWidth, ((FrameworkElement)this.ExtendedItem.View).ActualHeight);
InfoTextEnterArea.Start(ref infoTextEnterArea, this.Services, this.ExtendedItem.View, b, Translations.Instance.PressAltText);
InfoTextEnterArea.Start(ref infoTextEnterArea, this.Services, this.ExtendedItem.View, b, Translations.Instance.PressAltText);
return false;
}
@ -139,7 +126,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -139,7 +126,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
private bool internalCanEnterContainer(PlacementOperation operation)
{
InfoTextEnterArea.Stop(ref infoTextEnterArea);
InfoTextEnterArea.Stop(ref infoTextEnterArea);
if (ExtendedItem.Component is Expander)
{
@ -158,14 +145,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -158,14 +145,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (ExtendedItem.ContentProperty.IsCollection)
return CollectionSupport.CanCollectionAdd(ExtendedItem.ContentProperty.ReturnType,
operation.PlacedItems.Select(p => p.Item.Component));
if (ExtendedItem.View is ContentControl) {
if (!CanContentControlAdd((ContentControl) ExtendedItem.View)) {
return false;
}
}
if (ExtendedItem.ContentProperty.ReturnType == typeof(string))
return false;
if (ExtendedItem.ContentProperty.ReturnType == typeof(string))
return false;
if (!ExtendedItem.ContentProperty.IsSet)
return true;
@ -188,7 +170,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -188,7 +170,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
foreach (var info in operation.PlacedItems) {
SetPosition(info);
}
}
}
}
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/EditStyleContextMenuExtension.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -26,7 +26,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))]
[ExtensionFor(typeof (Control))]
[Extension(Order = 10)]
[Extension(Order = 30)]
public class EditStyleContextMenuExtension : PrimarySelectionAdornerProvider
{
DesignPanel panel;

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

@ -63,9 +63,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers @@ -63,9 +63,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers
if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "")
{
textProperty.SetValue(item.ComponentType.Name);
item.Properties[FrameworkElement.WidthProperty].Reset();
item.Properties[FrameworkElement.HeightProperty].Reset();
}
item.Properties[FrameworkElement.WidthProperty].Reset();
item.Properties[FrameworkElement.HeightProperty].Reset();
}
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
if (verticalAlignmentProperty.ValueOnInstance == null)

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs

@ -30,6 +30,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -30,6 +30,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// </summary>
[ExtensionServer(typeof(OnlyOneItemSelectedExtensionServer))]
[ExtensionFor(typeof(UIElement))]
[Extension(Order = 20)]
public sealed class RightClickContextMenuExtension : PrimarySelectionAdornerProvider
{
DesignPanel panel;

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

@ -224,10 +224,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -224,10 +224,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
AddLines(containerRect, -Margin, false);
AddLines(containerRect, 0, false);
if (!CanPlace(operation.PlacedItems.Select(x => x.Item), operation.Type, PlacementAlignment.Center))
return;
foreach (var item in AllDesignItems() /* ExtendedItem.ContentProperty.CollectionElements */
.Except(operation.PlacedItems.Select(f => f.Item))
.Where(x=>!GetDisableSnaplines(x.View))) {
.Where(x=> x.View != null && !GetDisableSnaplines(x.View))) {
if (item != null) {
var bounds = GetPosition(operation, item);

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -26,7 +26,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))]
[ExtensionFor(typeof (TextBlock))]
[Extension(Order = 10)]
[Extension(Order = 40)]
public class TextBlockRightClickContextMenuExtension : PrimarySelectionAdornerProvider
{
DesignPanel panel;

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.CopyIcon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.CutIcon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.DeleteIcon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.PasteIcon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.RedoIcon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.16x16.UndoIcon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 631 B

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineView.xaml

@ -97,7 +97,7 @@ @@ -97,7 +97,7 @@
<Setter.Value>
<ControlTemplate TargetType="{x:Type Default:DragTreeViewItem}">
<DockPanel Background="White">
<DockPanel Background="White" ContextMenu="{Binding DesignItem.Services.DesignPanel.ContextMenu}">
<Grid x:Name="bg"
Margin="{TemplateBinding Level, Converter={StaticResource LevelConverter}}"
DockPanel.Dock="Top"
@ -112,8 +112,8 @@ @@ -112,8 +112,8 @@
ContentSource="Header" />
</Border>
</Grid>
<ItemsPresenter x:Name="itemsHost" />
<DockPanel.ContextMenu>
<ItemsPresenter x:Name="itemsHost" />
<!-- <DockPanel.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Cut" />
<MenuItem Command="ApplicationCommands.Copy" />
@ -121,7 +121,7 @@ @@ -121,7 +121,7 @@
<Separator />
<MenuItem Command="ApplicationCommands.Delete" />
</ContextMenu>
</DockPanel.ContextMenu>
</DockPanel.ContextMenu>-->
<DockPanel.ToolTip>
<ToolTip Background="White">
<Rectangle Width="50" Height="50">

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs

@ -37,13 +37,10 @@ namespace ICSharpCode.WpfDesign.Designer @@ -37,13 +37,10 @@ namespace ICSharpCode.WpfDesign.Designer
this._rootItem=context.RootItem;
_rootItem.AddBehavior(typeof(IRootPlacementBehavior),this);
}
public bool CanPlace(System.Collections.Generic.ICollection<DesignItem> childItems, PlacementType type, PlacementAlignment position)
public bool CanPlace(IEnumerable<DesignItem> childItems, PlacementType type, PlacementAlignment position)
{
return type == PlacementType.Resize &&
(position == PlacementAlignment.Right
|| position == PlacementAlignment.BottomRight
|| position == PlacementAlignment.Bottom);
return type == PlacementType.Resize && (position == PlacementAlignment.Right || position == PlacementAlignment.BottomRight || position == PlacementAlignment.Bottom);
}
public void BeginPlacement(PlacementOperation operation)

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ClickOrDragMouseGesture.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -26,7 +26,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
/// <summary>
/// Base class for mouse gestures that should start dragging only after a minimum drag distance.
/// </summary>
abstract class ClickOrDragMouseGesture : MouseGestureBase
public abstract class ClickOrDragMouseGesture : MouseGestureBase
{
protected Point startPoint;
protected bool hasDragStarted;

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs

@ -28,13 +28,13 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -28,13 +28,13 @@ namespace ICSharpCode.WpfDesign.Designer.Services
/// Mouse gesture for moving elements inside a container or between containers.
/// Belongs to the PointerTool.
/// </summary>
sealed class DragMoveMouseGesture : ClickOrDragMouseGesture
public sealed class DragMoveMouseGesture : ClickOrDragMouseGesture
{
bool isDoubleClick;
bool setSelectionIfNotMoving;
MoveLogic moveLogic;
internal DragMoveMouseGesture(DesignItem clickedOn, bool isDoubleClick, bool setSelectionIfNotMoving = false)
public DragMoveMouseGesture(DesignItem clickedOn, bool isDoubleClick, bool setSelectionIfNotMoving = false)
{
Debug.Assert(clickedOn != null);

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -25,7 +25,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
/// <summary>
/// Base class for classes handling mouse gestures on the design surface.
/// </summary>
abstract class MouseGestureBase
public abstract class MouseGestureBase
{
/// <summary>
/// Checks if <paramref name="button"/> is the only button that is currently pressed.

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

@ -86,6 +86,11 @@ @@ -86,6 +86,11 @@
<Compile Include="ArrangeDirection.cs" />
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Extensions\BorderForImageControl.cs" />
<Compile Include="Extensions\DefaultCommandsContextMenu.xaml.cs">
<DependentUpon>DefaultCommandsContextMenu.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Extensions\DefaultCommandsContextMenuExtension.cs" />
<Compile Include="Extensions\PartialPanelSelectionHandler.cs" />
<Compile Include="Extensions\EditStyleContextMenu.xaml.cs">
<DependentUpon>EditStyleContextMenu.xaml</DependentUpon>
@ -289,6 +294,7 @@ @@ -289,6 +294,7 @@
<Resource Include="Images\Tag.png" />
</ItemGroup>
<ItemGroup>
<Page Include="Extensions\DefaultCommandsContextMenu.xaml" />
<Page Include="Extensions\EditStyleContextMenu.xaml">
<SubType>Designer</SubType>
</Page>
@ -468,4 +474,12 @@ @@ -468,4 +474,12 @@
<ItemGroup>
<Resource Include="Images\Icons.32x32.EmptyProjectIcon.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Icons.16x16.CopyIcon.png" />
<Resource Include="Images\Icons.16x16.CutIcon.png" />
<Resource Include="Images\Icons.16x16.DeleteIcon.png" />
<Resource Include="Images\Icons.16x16.PasteIcon.png" />
<Resource Include="Images\Icons.16x16.RedoIcon.png" />
<Resource Include="Images\Icons.16x16.UndoIcon.png" />
</ItemGroup>
</Project>

125
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs

@ -20,8 +20,11 @@ @@ -20,8 +20,11 @@
//#define EventHandlerDebugging
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Windows.Markup;
@ -65,9 +68,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -65,9 +68,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
void SetNameInternal(string newName)
{
var oldName = Name;
_xamlObject.Name = newName;
FixDesignItemReferencesOnNameChange(oldName, Name);
}
public override string Name {
get { return _xamlObject.Name; }
set {
@ -75,10 +82,102 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -75,10 +82,102 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
if (undoService != null)
undoService.Execute(new SetNameAction(this, value));
else
{
SetNameInternal(value);
}
}
}
/// <summary>
/// Fixes {x:Reference and {Binding ElementName to this Element in XamlDocument
/// </summary>
/// <param name="oldName"></param>
/// <param name="newName"></param>
public void FixDesignItemReferencesOnNameChange(string oldName, string newName)
{
var root = GetRootXamlObject(this.XamlObject);
var references = GetAllChildXamlObjects(root).Where(x => x.ElementType == typeof(Reference) && Equals(x.FindOrCreateProperty("Name").ValueOnInstance, oldName));
foreach (var designItem in references)
{
var property = designItem.FindOrCreateProperty("Name");
var propertyValue = designItem.OwnerDocument.CreatePropertyValue(newName, property);
this.ComponentService.RegisterXamlComponentRecursive(propertyValue as XamlObject);
property.PropertyValue = propertyValue;
}
root = GetRootXamlObject(this.XamlObject, true);
var bindings = GetAllChildXamlObjects(root, true).Where(x => x.ElementType == typeof(Binding) && Equals(x.FindOrCreateProperty("ElementName").ValueOnInstance, oldName));
foreach (var designItem in bindings)
{
var property = designItem.FindOrCreateProperty("ElementName");
var propertyValue = designItem.OwnerDocument.CreatePropertyValue(newName, property);
this.ComponentService.RegisterXamlComponentRecursive(propertyValue as XamlObject);
property.PropertyValue = propertyValue;
}
}
/// <summary>
/// Find's the Root XamlObject (real Root, or Root Object in Namescope)
/// </summary>
/// <param name="item"></param>
/// <param name="onlyFromSameNamescope"></param>
/// <returns></returns>
private XamlObject GetRootXamlObject(XamlObject item, bool onlyFromSameNamescope = false)
{
var root = item;
while (root.ParentObject != null)
{
if (onlyFromSameNamescope && NameScopeHelper.GetNameScopeFromObject(root) != NameScopeHelper.GetNameScopeFromObject(root.ParentObject))
break;
root = root.ParentObject;
}
return root;
}
/// <summary>
/// Get's all Child XamlObject Instances
/// </summary>
/// <param name="item"></param>
/// <param name="onlyFromSameNamescope"></param>
/// <returns></returns>
private IEnumerable<XamlObject> GetAllChildXamlObjects(XamlObject item, bool onlyFromSameNamescope = false)
{
foreach (var prop in item.Properties)
{
if (prop.PropertyValue as XamlObject != null)
{
if (!onlyFromSameNamescope || NameScopeHelper.GetNameScopeFromObject(item) == NameScopeHelper.GetNameScopeFromObject(prop.PropertyValue as XamlObject))
yield return prop.PropertyValue as XamlObject;
foreach (var i in GetAllChildXamlObjects(prop.PropertyValue as XamlObject))
{
if (!onlyFromSameNamescope || NameScopeHelper.GetNameScopeFromObject(item) == NameScopeHelper.GetNameScopeFromObject(i))
yield return i;
}
}
if (prop.IsCollection)
{
foreach (var collectionElement in prop.CollectionElements)
{
if (collectionElement as XamlObject != null)
{
if (!onlyFromSameNamescope || NameScopeHelper.GetNameScopeFromObject(item) == NameScopeHelper.GetNameScopeFromObject(collectionElement as XamlObject))
yield return collectionElement as XamlObject;
foreach (var i in GetAllChildXamlObjects(collectionElement as XamlObject))
{
if (!onlyFromSameNamescope || NameScopeHelper.GetNameScopeFromObject(item) == NameScopeHelper.GetNameScopeFromObject(i))
yield return i;
}
}
}
}
}
}
public override string Key {
get { return XamlObject.GetXamlAttribute("Key"); }
set { XamlObject.SetXamlAttribute("Key", value); }
@ -167,14 +266,14 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -167,14 +266,14 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public override string ContentPropertyName {
get {
return XamlObject.ContentPropertyName;
return XamlObject.ContentPropertyName;
}
}
/// <summary>
/// Item is Locked at Design Time
/// </summary>
public bool IsDesignTimeLocked {
public bool IsDesignTimeLocked {
get {
var locked = Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).ValueOnInstance;
return (locked != null && (bool) locked == true);
@ -185,20 +284,20 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -185,20 +284,20 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
else
Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).Reset();
}
}
public override DesignItem Clone()
{
DesignItem item = null;
var xaml = XamlStaticTools.GetXaml(this.XamlObject);
XamlDesignItem rootItem = Context.RootItem as XamlDesignItem;
var obj = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, ((XamlDesignContext) Context).ParserSettings);
if (obj != null)
{
item = ((XamlDesignContext)Context)._componentService.RegisterXamlComponentRecursive(obj);
}
return item;
var xaml = XamlStaticTools.GetXaml(this.XamlObject);
XamlDesignItem rootItem = Context.RootItem as XamlDesignItem;
var obj = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, ((XamlDesignContext) Context).ParserSettings);
if (obj != null)
{
item = ((XamlDesignContext)Context)._componentService.RegisterXamlComponentRecursive(obj);
}
return item;
}
sealed class SetNameAction : ITransactionItem

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs

@ -131,7 +131,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -131,7 +131,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
AddInParent(parent, pastedItems);
pasted = true;
}
} else if (pastedItems.Count == 1 && parent.ContentProperty.Value == null && parent.ContentProperty.ValueOnInstance == null && parent.View is ContentControl && DefaultPlacementBehavior.CanContentControlAdd((ContentControl)parent.View)) {
} else if (pastedItems.Count == 1 && parent.ContentProperty.Value == null && parent.ContentProperty.ValueOnInstance == null && parent.View is ContentControl) {
AddInParent(parent, pastedItems);
pasted = true;
}

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SamplesTests.cs

@ -452,7 +452,6 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -452,7 +452,6 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
}
[Test]
[Ignore("Xaml writer creates different XAML")]
public void Style3()
{
TestLoading(@"<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
@ -504,6 +503,26 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -504,6 +503,26 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</Window>");
}
[Test]
public void Template2()
{
TestLoading(@"<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Window.Resources>
<ResourceDictionary>
<SolidColorBrush Color=""Blue"" x:Key=""bb"" />
<ControlTemplate x:Key=""aa"" TargetType=""Button"">
<Grid HorizontalAlignment=""Left"">
<Rectangle Fill=""{StaticResource bb}"" />
</Grid>
</ControlTemplate>
</ResourceDictionary>
</Window.Resources>
</Window>");
}
[Test]
public void ListBox1()

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SimpleLoadTests.cs

@ -293,7 +293,6 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -293,7 +293,6 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
}
[Test]
[Ignore("Own XamlParser should handle different namespaces pointing to same types, because builtin XamlReader does.")]
public void ResourceDictionaryExplicitNetfx2007()
{
// The reason this test case fails is because own XamlParser cannot always handle the case where multiple xmlns points to the same type.

27
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/DesignInstanceExtension.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;
namespace ICSharpCode.WpfDesign.XamlDom
{
public class DesignInstanceExtension : MarkupExtension
{
public DesignInstanceExtension(Type type)
{
this.Type = type;
}
public Type Type { get; set; }
public bool IsDesignTimeCreatable { get; set; }
public bool CreateList { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
return null;
}
}
}

84
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/TemplateHelper.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -24,6 +25,7 @@ using System.Reflection; @@ -24,6 +25,7 @@ using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Xaml;
using System.Xml;
using System.Xml.XPath;
@ -31,8 +33,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -31,8 +33,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
public static class TemplateHelper
{
public static FrameworkTemplate GetFrameworkTemplate(XmlElement xmlElement)
public static FrameworkTemplate GetFrameworkTemplate(XmlElement xmlElement, XamlObject parentObject)
{
var nav = xmlElement.CreateNavigator();
var ns = new Dictionary<string, string>();
@ -47,16 +50,89 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -47,16 +50,89 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (!nav.MoveToParent())
break;
}
xmlElement = (XmlElement)xmlElement.CloneNode(true);
foreach (var dictentry in ns)
foreach (var dictentry in ns.ToList())
{
xmlElement.SetAttribute("xmlns:" + dictentry.Key, dictentry.Value);
}
var keyAttrib = xmlElement.GetAttribute("Key", XamlConstants.XamlNamespace);
if (string.IsNullOrEmpty(keyAttrib)) {
xmlElement.SetAttribute("Key", XamlConstants.XamlNamespace, "$$temp&&§§%%__");
}
var xaml = xmlElement.OuterXml;
xaml = "<ResourceDictionary xmlns=\"http://schemas.microsoft.com/netfx/2007/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" + xaml + "</ResourceDictionary>";
StringReader stringReader = new StringReader(xaml);
XmlReader xmlReader = XmlReader.Create(stringReader);
return (FrameworkTemplate)XamlReader.Load(xmlReader);
var xamlReader = new XamlXmlReader(xmlReader, parentObject.ServiceProvider.SchemaContext);
var seti = new XamlObjectWriterSettings();
var resourceDictionary = new ResourceDictionary();
var obj = parentObject;
while (obj != null)
{
if (obj.Instance is ResourceDictionary)
{
var r = obj.Instance as ResourceDictionary;
foreach (var k in r.Keys)
{
if (!resourceDictionary.Contains(k))
resourceDictionary.Add(k, r[k]);
}
}
else if (obj.Instance is FrameworkElement)
{
var r = ((FrameworkElement)obj.Instance).Resources;
foreach (var k in r.Keys)
{
if (!resourceDictionary.Contains(k))
resourceDictionary.Add(k, r[k]);
}
}
obj = obj.ParentObject;
}
seti.BeforePropertiesHandler = (s, e) =>
{
if (seti.BeforePropertiesHandler != null)
{
var rr = e.Instance as ResourceDictionary;
rr.MergedDictionaries.Add(resourceDictionary);
seti.BeforePropertiesHandler = null;
}
};
var writer = new XamlObjectWriter(parentObject.ServiceProvider.SchemaContext, seti);
XamlServices.Transform(xamlReader, writer);
var result = (ResourceDictionary)writer.Result;
var enr = result.Keys.GetEnumerator();
enr.MoveNext();
var rdKey = enr.Current;
var template = result[rdKey] as FrameworkTemplate;
result.Remove(rdKey);
return template;
}
private static Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj

@ -69,6 +69,7 @@ @@ -69,6 +69,7 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="CollectionElementsCollection.cs" />
<Compile Include="CollectionSupport.cs" />
<Compile Include="DesignInstanceExtension.cs" />
<Compile Include="DesignTimeProperties.cs" />
<Compile Include="IXamlErrorSink.cs" />
<Compile Include="MarkupCompatibilityProperties.cs" />

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

@ -228,6 +228,16 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -228,6 +228,16 @@ namespace ICSharpCode.WpfDesign.XamlDom
return _typeFinder.GetXmlNamespaceFor(type.Assembly, type.Namespace, getClrNamespace);
}
internal List<string> GetNamespacesFor(Type type, bool getClrNamespace = false)
{
if (type == typeof (DesignTimeProperties))
return new List<string>(){XamlConstants.DesignTimeNamespace};
if (type == typeof (MarkupCompatibilityProperties))
return new List<string>(){XamlConstants.MarkupCompatibilityNamespace};
return _typeFinder.GetXmlNamespacesFor(type.Assembly, type.Namespace, getClrNamespace);
}
internal string GetPrefixForNamespace(string @namespace)
{

24
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

@ -426,11 +426,23 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -426,11 +426,23 @@ namespace ICSharpCode.WpfDesign.XamlDom
PropertyDescriptorCollection propertyDescriptors = TypeDescriptor.GetProperties(instance);
PropertyDescriptor propertyInfo = propertyDescriptors[propertyName];
XamlProperty newProperty;
if (propertyInfo == null) {
propertyDescriptors = TypeDescriptor.GetProperties(this.elementType);
propertyInfo = propertyDescriptors[propertyName];
}
if (propertyInfo != null) {
newProperty = new XamlProperty(this, new XamlNormalPropertyInfo(propertyInfo));
} else {
EventDescriptorCollection events = TypeDescriptor.GetEvents(instance);
EventDescriptor eventInfo = events[propertyName];
if (eventInfo == null) {
events = TypeDescriptor.GetEvents(this.elementType);
eventInfo = events[propertyName];
}
if (eventInfo != null) {
newProperty = new XamlProperty(this, new XamlEventPropertyInfo(eventInfo));
} else {
@ -503,7 +515,17 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -503,7 +515,17 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (value == null)
element.RemoveAttribute(name, XamlConstants.XamlNamespace);
else
element.SetAttribute(name, XamlConstants.XamlNamespace, value);
{
var prefix = element.GetPrefixOfNamespace(XamlConstants.XamlNamespace);
if (!string.IsNullOrEmpty(prefix))
{
var attribute = element.OwnerDocument.CreateAttribute(prefix, name, XamlConstants.XamlNamespace);
attribute.InnerText = value;
element.SetAttributeNode(attribute);
}
else
element.SetAttribute(name, XamlConstants.XamlNamespace, value);
}
if (isNameChange) {
bool nameChangedAlreadyRaised = false;

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs

@ -136,7 +136,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -136,7 +136,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
get
{
return iCsharpXamlSchemaContext = iCsharpXamlSchemaContext ?? new XamlSchemaContext();
return iCsharpXamlSchemaContext = iCsharpXamlSchemaContext ?? System.Windows.Markup.XamlReader.GetWpfSchemaContext(); // new XamlSchemaContext();
}
}

67
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -28,6 +28,7 @@ using System.Windows; @@ -28,6 +28,7 @@ using System.Windows;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Xml;
using System.Windows.Media;
namespace ICSharpCode.WpfDesign.XamlDom
{
@ -146,6 +147,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -146,6 +147,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
static Type FindType(XamlTypeFinder typeFinder, string namespaceUri, string localName)
{
Type elementType = typeFinder.GetType(namespaceUri, localName);
if (elementType == null)
elementType = typeFinder.GetType(namespaceUri, localName+"Extension");
if (elementType == null)
throw new XamlLoadException("Cannot find type " + localName + " in " + namespaceUri);
return elementType;
@ -195,7 +198,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -195,7 +198,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (typeof (FrameworkTemplate).IsAssignableFrom(elementType))
{
var xamlObj = new XamlObject(document, element, elementType, TemplateHelper.GetFrameworkTemplate(element));
var xamlObj = new XamlObject(document, element, elementType, TemplateHelper.GetFrameworkTemplate(element, currentXamlObject));
xamlObj.ParentObject = currentXamlObject;
return xamlObj;
}
@ -323,8 +326,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -323,8 +326,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (defaultProperty == null && obj.Instance != null && CollectionSupport.IsCollectionType(obj.Instance.GetType())) {
XamlObject parentObj = obj.ParentObject;
var parentElement = element.ParentNode;
XamlPropertyInfo propertyInfo = GetPropertyInfo(settings.TypeFinder, parentObj.Instance, parentObj.ElementType, parentElement.NamespaceURI, parentElement.LocalName);
collectionProperty = FindExistingXamlProperty(parentObj, propertyInfo);
XamlPropertyInfo propertyInfo;
if (parentObj != null) {
propertyInfo = GetPropertyInfo(settings.TypeFinder, parentObj.Instance, parentObj.ElementType, parentElement.NamespaceURI, parentElement.LocalName);
collectionProperty = FindExistingXamlProperty(parentObj, propertyInfo);
}
collectionInstance = obj.Instance;
collectionType = obj.ElementType;
collectionPropertyElement = element;
@ -500,6 +506,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -500,6 +506,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (eventInfo != null) {
return new XamlEventPropertyInfo(eventInfo);
}
throw new XamlLoadException("property " + propertyName + " not found");
}
@ -507,23 +514,42 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -507,23 +514,42 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
MethodInfo getMethod = elementType.GetMethod("Get" + propertyName, BindingFlags.Public | BindingFlags.Static);
MethodInfo setMethod = elementType.GetMethod("Set" + propertyName, BindingFlags.Public | BindingFlags.Static);
if (getMethod != null && setMethod != null) {
if (getMethod != null || setMethod != null) {
FieldInfo field = elementType.GetField(propertyName + "Property", BindingFlags.Public | BindingFlags.Static);
if (field != null && field.FieldType == typeof(DependencyProperty)) {
return new XamlDependencyPropertyInfo((DependencyProperty)field.GetValue(null), true);
}
}
if (elementType.BaseType != null) {
return TryFindAttachedProperty(elementType.BaseType, propertyName);
}
return null;
}
internal static XamlPropertyInfo TryFindAttachedEvent(Type elementType, string propertyName)
{
FieldInfo fieldEvent = elementType.GetField(propertyName + "Event", BindingFlags.Public | BindingFlags.Static);
if (fieldEvent != null && fieldEvent.FieldType == typeof(RoutedEvent))
{
return new XamlEventPropertyInfo(TypeDescriptor.GetEvents(elementType)[propertyName]);
}
if (elementType.BaseType != null)
{
return TryFindAttachedEvent(elementType.BaseType, propertyName);
}
return null;
}
static XamlPropertyInfo FindAttachedProperty(Type elementType, string propertyName)
{
XamlPropertyInfo pi = TryFindAttachedProperty(elementType, propertyName);
if (pi == null) {
pi = TryFindAttachedEvent(elementType, propertyName);
}
if (pi != null) {
return pi;
} else {
@ -555,7 +581,12 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -555,7 +581,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
return FindAttachedProperty(typeof(DesignTimeProperties), attribute.LocalName);
} else if (attribute.LocalName == "IsLocked" && attribute.NamespaceURI == XamlConstants.DesignTimeNamespace) {
return FindAttachedProperty(typeof(DesignTimeProperties), attribute.LocalName);
} else if (attribute.LocalName == "LayoutOverrides" && attribute.NamespaceURI == XamlConstants.DesignTimeNamespace) {
return FindAttachedProperty(typeof(DesignTimeProperties), attribute.LocalName);
} else if (attribute.LocalName == "LayoutRounding" && attribute.NamespaceURI == XamlConstants.DesignTimeNamespace) {
return FindAttachedProperty(typeof(DesignTimeProperties), attribute.LocalName);
}
return null;
}
@ -674,6 +705,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -674,6 +705,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
else {
collectionInstance = collectionProperty.propertyInfo.GetValue(obj.Instance);
collectionProperty.ParserSetPropertyElement(element);
collectionInstance = collectionInstance ?? Activator.CreateInstance(collectionProperty.propertyInfo.ReturnType);
}
}
@ -712,6 +744,13 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -712,6 +744,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
internal static object CreateObjectFromAttributeText(string valueText, XamlPropertyInfo targetProperty, XamlObject scope)
{
if (targetProperty.ReturnType == typeof(Uri)) {
return scope.OwnerDocument.TypeFinder.ConvertUriToLocalUri(new Uri(valueText, UriKind.RelativeOrAbsolute));
} else if (targetProperty.ReturnType == typeof(ImageSource)) {
var uri = scope.OwnerDocument.TypeFinder.ConvertUriToLocalUri(new Uri(valueText, UriKind.RelativeOrAbsolute));
return targetProperty.TypeConverter.ConvertFromString(scope.OwnerDocument.GetTypeDescriptorContext(scope), CultureInfo.InvariantCulture, uri.ToString());
}
return targetProperty.TypeConverter.ConvertFromString(
scope.OwnerDocument.GetTypeDescriptorContext(scope),
CultureInfo.InvariantCulture, valueText);
@ -759,7 +798,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -759,7 +798,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
}
/// <summary>
/// Method use to parse a piece of Xaml.
/// </summary>
@ -768,6 +807,19 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -768,6 +807,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// <param name="settings">Parser settings used by <see cref="XamlParser"/>.</param>
/// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns>
public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings)
{
return ParseSnippet(root, xaml, settings, null);
}
/// <summary>
/// Method use to parse a piece of Xaml.
/// </summary>
/// <param name="root">The Root XamlObject of the current document.</param>
/// <param name="xaml">The Xaml being parsed.</param>
/// <param name="settings">Parser settings used by <see cref="XamlParser"/>.</param>
/// <param name="parentObject">Parent Object, where the Parsed snippet will be inserted (Needed for Example for Bindings).</param>
/// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns>
public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings, XamlObject parentObject)
{
XmlTextReader reader = new XmlTextReader(new StringReader(xaml));
var element = root.OwnerDocument.XmlDocument.ReadNode(reader);
@ -785,6 +837,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -785,6 +837,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
parser.settings = settings;
parser.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink));
parser.document = root.OwnerDocument;
parser.currentXamlObject = parentObject;
var xamlObject = parser.ParseObject(element as XmlElement);
RemoveRootNamespacesFromNodeAndChildNodes(root, element);

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

@ -356,19 +356,19 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -356,19 +356,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
static XmlNode FindChildNode(XmlNode node, Type elementType, string propertyName, XamlDocument xamlDocument)
{
var localName = elementType.Name + "." + propertyName;
var namespaceURI = xamlDocument.GetNamespaceFor(elementType);
var namespacesURI = xamlDocument.GetNamespacesFor(elementType);
var clrNamespaceURI = xamlDocument.GetNamespaceFor(elementType, true);
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == localName && (childNode.NamespaceURI == namespaceURI || childNode.NamespaceURI == clrNamespaceURI))
if (childNode.LocalName == localName && (namespacesURI.Contains(childNode.NamespaceURI) || childNode.NamespaceURI == clrNamespaceURI))
{
return childNode;
}
}
var type = elementType.BaseType;
namespaceURI = xamlDocument.GetNamespaceFor(type);
namespacesURI = xamlDocument.GetNamespacesFor(type);
while (type != typeof(object))
{
@ -379,7 +379,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -379,7 +379,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI)
if (childNode.LocalName == localName && namespacesURI.Contains(childNode.NamespaceURI))
{
return childNode;
}
@ -556,7 +556,13 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -556,7 +556,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
set {
propertyInfo.SetValue(parentObject.Instance, value);
var setValue = value;
if (propertyInfo.ReturnType == typeof(Uri))
{
setValue = this.ParentObject.OwnerDocument.TypeFinder.ConvertUriToLocalUri((Uri)value);
}
propertyInfo.SetValue(parentObject.Instance, setValue);
if (ValueOnInstanceChanged != null)
ValueOnInstanceChanged(this, EventArgs.Empty);
}

33
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Windows.Markup;
using System.Xaml;
@ -82,6 +83,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -82,6 +83,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
Dictionary<string, XamlNamespace> namespaces = new Dictionary<string, XamlNamespace>();
Dictionary<AssemblyNamespaceMapping, string> reverseDict = new Dictionary<AssemblyNamespaceMapping, string>();
Dictionary<AssemblyNamespaceMapping, List<string>> reverseDictList = new Dictionary<AssemblyNamespaceMapping, List<string>>();
/// <summary>
/// Gets a type referenced in XAML.
@ -128,6 +130,20 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -128,6 +130,20 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
/// <summary>
/// Gets the XML namespaces that can be used for the specified assembly/namespace combination.
/// </summary>
public List<string> GetXmlNamespacesFor(Assembly assembly, string @namespace, bool getClrNamespace = false)
{
AssemblyNamespaceMapping mapping = new AssemblyNamespaceMapping(assembly, @namespace);
List<string> xmlNamespaces;
if (!getClrNamespace && reverseDictList.TryGetValue(mapping, out xmlNamespaces)) {
return xmlNamespaces;
} else {
return new List<string>() { "clr-namespace:" + mapping.Namespace + ";assembly=" + mapping.Assembly.GetName().Name };
}
}
/// <summary>
/// Gets the prefix to use for the specified XML namespace,
/// or null if no suitable prefix could be found.
@ -178,6 +194,14 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -178,6 +194,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
ns.ClrNamespaces.Add(mapping);
List<string> xmlNamespaceList;
if (reverseDictList.TryGetValue(mapping, out xmlNamespaceList)) {
if (!xmlNamespaceList.Contains(ns.XmlNamespace))
xmlNamespaceList.Add(ns.XmlNamespace);
}
else
reverseDictList.Add(mapping, new List<string>(){ ns.XmlNamespace });
string xmlNamespace;
if (reverseDict.TryGetValue(mapping, out xmlNamespace)) {
if (xmlNamespace == XamlConstants.PresentationNamespace) {
@ -262,6 +286,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -262,6 +286,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
foreach (KeyValuePair<AssemblyNamespaceMapping, string> pair in source.reverseDict) {
this.reverseDict.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<AssemblyNamespaceMapping, List<string>> pair in source.reverseDictList) {
this.reverseDictList.Add(pair.Key, pair.Value.ToList());
}
}
object ICloneable.Clone()
@ -277,6 +304,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -277,6 +304,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
return WpfTypeFinder.Instance.Clone();
}
public virtual Uri ConvertUriToLocalUri(Uri uri)
{
return uri;
}
static class WpfTypeFinder
{
internal static readonly XamlTypeFinder Instance;
@ -291,6 +323,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -291,6 +323,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
Instance.RegisterAssembly(typeof(IAddChild).Assembly); // PresentationCore
Instance.RegisterAssembly(typeof(XamlReader).Assembly); // PresentationFramework
Instance.RegisterAssembly(typeof(XamlType).Assembly); // System.Xaml
Instance.RegisterAssembly(typeof(Type).Assembly); // mscorelib
}
}
}

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs

@ -161,6 +161,13 @@ namespace ICSharpCode.WpfDesign @@ -161,6 +161,13 @@ namespace ICSharpCode.WpfDesign
for (int i = 0; i < _extensionServers.Length; i++) {
if (_extensionServers[i] == server) {
bool shouldApply = server.ShouldApplyExtensions(this);
if (server.ShouldBeReApplied() && shouldApply && shouldApply == _extensionServerIsApplied[i])
{
_extensionServerIsApplied[i] = false;
ApplyUnapplyExtensionServer(extensionManager, false, server);
}
if (shouldApply != _extensionServerIsApplied[i]) {
_extensionServerIsApplied[i] = shouldApply;
ApplyUnapplyExtensionServer(extensionManager, shouldApply, server);

15
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/Extension.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Diagnostics;
using System.Windows;
namespace ICSharpCode.WpfDesign.Extensions
{
@ -32,5 +33,19 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -32,5 +33,19 @@ namespace ICSharpCode.WpfDesign.Extensions
/// </remarks>
public abstract class Extension
{
public static string GetDisabledExtensions(DependencyObject obj)
{
return (string)obj.GetValue(DisabledExtensionsProperty);
}
public static void SetDisabledExtensions(DependencyObject obj, string value)
{
obj.SetValue(DisabledExtensionsProperty, value);
}
public static readonly DependencyProperty DisabledExtensionsProperty =
DependencyProperty.RegisterAttached("DisabledExtensions", typeof(string), typeof(Extension), new PropertyMetadata(null));
}
}

17
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionManager.cs

@ -65,14 +65,14 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -65,14 +65,14 @@ namespace ICSharpCode.WpfDesign.Extensions
internal readonly Type ExtensionType;
internal readonly ExtensionServer Server;
internal readonly Type OverriddenExtensionType;
internal readonly int Order;
internal readonly int Order;
public ExtensionEntry(Type extensionType, ExtensionServer server, Type overriddenExtensionType, int Order)
public ExtensionEntry(Type extensionType, ExtensionServer server, Type overriddenExtensionType, int Order)
{
this.ExtensionType = extensionType;
this.Server = server;
this.OverriddenExtensionType = overriddenExtensionType;
this.Order = Order;
this.Order = Order;
}
}
@ -106,7 +106,7 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -106,7 +106,7 @@ namespace ICSharpCode.WpfDesign.Extensions
result.Add(entry);
}
}
return result.OrderBy(x => x.Order).ToList();
return result.OrderBy(x => x.Order).ToList();
}
/// <summary>
@ -151,7 +151,10 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -151,7 +151,10 @@ namespace ICSharpCode.WpfDesign.Extensions
foreach (ExtensionEntry entry in GetExtensionEntries(item)) {
if (entry.Server == server) {
yield return server.CreateExtension(entry.ExtensionType, item);
var disabledExtensions = Extension.GetDisabledExtensions(item.View);
if (disabledExtensions == null || !disabledExtensions.Split(';').Contains(entry.ExtensionType.Name))
yield return server.CreateExtension(entry.ExtensionType, item);
}
}
}
@ -186,8 +189,8 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -186,8 +189,8 @@ namespace ICSharpCode.WpfDesign.Extensions
foreach (ExtensionForAttribute designerFor in extensionForAttributes) {
ExtensionServer server = GetServerForExtension(type);
ExtensionAttribute extensionAttribute = type.GetCustomAttributes(typeof(ExtensionAttribute), false).FirstOrDefault() as ExtensionAttribute;
AddExtensionEntry(designerFor.DesignedItemType, new ExtensionEntry(type, server, designerFor.OverrideExtension, extensionAttribute != null ? extensionAttribute.Order : 0));
ExtensionAttribute extensionAttribute = type.GetCustomAttributes(typeof(ExtensionAttribute), false).FirstOrDefault() as ExtensionAttribute;
AddExtensionEntry(designerFor.DesignedItemType, new ExtensionEntry(type, server, designerFor.OverrideExtension, extensionAttribute != null ? extensionAttribute.Order : 0));
}
}
}

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionServer.cs

@ -74,6 +74,14 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -74,6 +74,14 @@ namespace ICSharpCode.WpfDesign.Extensions
/// </summary>
public abstract bool ShouldApplyExtensions(DesignItem extendedItem);
// <summary>
/// Set if the Extension Server should be reaplied (For multiple Selection extension Server for Example!)
/// </summary>
public virtual bool ShouldBeReApplied()
{
return false;
}
/// <summary>
/// Create an extension of the specified type.
/// Is called by the ExtensionManager.

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

@ -121,6 +121,11 @@ namespace ICSharpCode.WpfDesign.Extensions @@ -121,6 +121,11 @@ namespace ICSharpCode.WpfDesign.Extensions
ReapplyExtensions(this.Services.Selection.SelectedItems);
}
public override bool ShouldBeReApplied()
{
return true;
}
/// <summary>
/// Gets if the item is in the secondary selection.
/// </summary>

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

@ -31,7 +31,7 @@ namespace ICSharpCode.WpfDesign @@ -31,7 +31,7 @@ namespace ICSharpCode.WpfDesign
/// <summary>
/// Gets if the child element can be resized.
/// </summary>
bool CanPlace(ICollection<DesignItem> childItems, PlacementType type, PlacementAlignment position);
bool CanPlace(IEnumerable<DesignItem> childItems, PlacementType type, PlacementAlignment position);
/// <summary>
/// Starts placement mode for this container.

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs

@ -102,7 +102,6 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -102,7 +102,6 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
}
else
{
var l=TypeDescriptor.GetProperties(element);
foreach(PropertyDescriptor p in TypeDescriptor.GetProperties(element)){
if (!p.IsBrowsable) continue;
if (p.IsReadOnly && !typeof(ICollection).IsAssignableFrom(p.PropertyType)) continue;
@ -111,7 +110,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -111,7 +110,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
}
}
}
/// <summary>
/// Gets common properties between <paramref name="elements"/>. Includes attached properties too.
/// </summary>
@ -119,32 +118,14 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -119,32 +118,14 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
/// <returns></returns>
public static IEnumerable<PropertyDescriptor> GetCommonAvailableProperties(IEnumerable<object> elements)
{
foreach (var pd1 in GetAvailableProperties(elements.First())) {
bool propertyOk = true;
foreach (var element in elements.Skip(1)) {
bool typeOk = false;
foreach (var pd2 in GetAvailableProperties(element)) {
if (pd1 == pd2) {
typeOk = true;
break;
}
/* Check if it is attached property.*/
if(pd1.Name.Contains(".") && pd2.Name.Contains(".")){
if(pd1.Name==pd2.Name){
typeOk=true;
break;
}
}
}
if (!typeOk) {
propertyOk = false;
break;
}
}
if (propertyOk) yield return pd1;
var properties = TypeDescriptor.GetProperties(elements.First()).Cast<PropertyDescriptor>();
foreach (var element in elements.Skip(1))
{
var currentProperties = TypeDescriptor.GetProperties(element).Cast<PropertyDescriptor>();
properties = Enumerable.Intersect(properties, currentProperties);
}
return properties;
}
}
}

Loading…
Cancel
Save