Browse Source

-Add support for custom controls.

-Support having any item as the Root Item.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6403 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Kumar Devvrat 16 years ago
parent
commit
72f208e637
  1. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs
  2. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs
  3. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  4. 42
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs
  5. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  6. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  7. 57
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

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

@ -37,6 +37,15 @@ namespace ICSharpCode.WpfDesign.AddIn
} }
return null; return null;
} else { } else {
// Load any other assembly from the solution.
foreach(var project in ProjectService.OpenSolution.Projects) {
if(project.AssemblyName==name) {
var pc = ParserService.GetProjectContent(project);
if (pc != null)
return this.typeResolutionService.LoadAssembly(pc);
}
}
return base.LoadAssembly(name); return base.LoadAssembly(name);
} }
} }

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs

@ -45,12 +45,12 @@ namespace ICSharpCode.WpfDesign.AddIn
r.XmlResolver = null; r.XmlResolver = null;
r.WhitespaceHandling = WhitespaceHandling.None; r.WhitespaceHandling = WhitespaceHandling.None;
while (r.NodeType != XmlNodeType.Element && r.Read()); while (r.NodeType != XmlNodeType.Element && r.Read());
if(r.LocalName=="ResourceDictionary")
if (r.LocalName == "Window" || r.LocalName == "UserControl") return false;
return true;
} catch (XmlException) { } catch (XmlException) {
return false; return true;
} }
return true;
} }
} }
return false; return false;

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

@ -128,12 +128,15 @@ namespace ICSharpCode.WpfDesign.AddIn
} }
} }
else{ else{
_stream.Position = 0; if(_stream.CanRead){
using (var reader = new StreamReader(_stream)) _stream.Position = 0;
using (var reader = new StreamReader(_stream))
using (var writer = new StreamWriter(stream)) { using (var writer = new StreamWriter(stream)) {
writer.Write(reader.ReadToEnd()); writer.Write(reader.ReadToEnd());
}
} }
} }
} }
void UpdateTasks(XamlErrorService xamlErrorService) void UpdateTasks(XamlErrorService xamlErrorService)

42
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WindowResizeBehavior.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs

@ -1,30 +1,32 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt"/> // <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/> // <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/> // <author name="Kumar Devvrat"/>
// <version>$Revision$</version> // <version>$Revision: $</version>
// </file> // </file>
using System; using System;
using System.Collections.Generic;
using System.Windows; using System.Windows;
using ICSharpCode.WpfDesign.Extensions; using System.Collections.Generic;
using System.Diagnostics;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer
{ {
/// <summary> /// <summary>
/// Supports resizing a Window. /// Intializes different behaviors for the Root item.
/// <remarks>Could not be a extension since Root Item is can be of any type</remarks>
/// </summary> /// </summary>
[ExtensionFor(typeof(Window))] public class RootItemBehavior : IRootPlacementBehavior
public class WindowResizeBehavior : BehaviorExtension, IRootPlacementBehavior
{ {
protected override void OnInitialized() private DesignItem _rootItem;
public void Intialize(DesignContext context)
{ {
base.OnInitialized(); Debug.Assert(context.RootItem!=null);
this.ExtendedItem.AddBehavior(typeof(IRootPlacementBehavior), this); this._rootItem=context.RootItem;
_rootItem.AddBehavior(typeof(IRootPlacementBehavior),this);
} }
public bool CanPlace(ICollection<DesignItem> children, PlacementType type, PlacementAlignment position) public bool CanPlace(System.Collections.Generic.ICollection<DesignItem> childItems, PlacementType type, PlacementAlignment position)
{ {
return type == PlacementType.Resize && return type == PlacementType.Resize &&
(position == PlacementAlignment.Right (position == PlacementAlignment.Right
@ -32,23 +34,25 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
|| position == PlacementAlignment.Bottom); || position == PlacementAlignment.Bottom);
} }
public void BeginPlacement(PlacementOperation operation) public void BeginPlacement(PlacementOperation operation)
{ {
} }
public void EndPlacement(PlacementOperation operation) public void EndPlacement(PlacementOperation operation)
{ {
} }
public Rect GetPosition(PlacementOperation operation, DesignItem childItem) public System.Windows.Rect GetPosition(PlacementOperation operation, DesignItem childItem)
{ {
UIElement child = childItem.View; UIElement child = childItem.View;
return new Rect(0, 0, ModelTools.GetWidth(child), ModelTools.GetHeight(child)); return new Rect(0, 0, ModelTools.GetWidth(child), ModelTools.GetHeight(child));
} }
public void BeforeSetPosition(PlacementOperation operation) public void BeforeSetPosition(PlacementOperation operation)
{ {
throw new NotImplementedException();
} }
public void SetPosition(PlacementInformation info) public void SetPosition(PlacementInformation info)
@ -70,7 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public void LeaveContainer(PlacementOperation operation) public void LeaveContainer(PlacementOperation operation)
{ {
throw new NotSupportedException(); throw new NotImplementedException();
} }
public bool CanEnterContainer(PlacementOperation operation) public bool CanEnterContainer(PlacementOperation operation)
@ -80,7 +84,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public void EnterContainer(PlacementOperation operation) public void EnterContainer(PlacementOperation operation)
{ {
throw new NotSupportedException(); throw new NotImplementedException();
} }
} }
} }

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

@ -139,7 +139,6 @@
<Compile Include="Extensions\TabItemClickableExtension.cs" /> <Compile Include="Extensions\TabItemClickableExtension.cs" />
<Compile Include="Extensions\TopLeftContainerDragHandle.cs" /> <Compile Include="Extensions\TopLeftContainerDragHandle.cs" />
<Compile Include="Extensions\ResizeThumbExtension.cs" /> <Compile Include="Extensions\ResizeThumbExtension.cs" />
<Compile Include="Extensions\WindowResizeBehavior.cs" />
<Compile Include="BasicMetadata.cs" /> <Compile Include="BasicMetadata.cs" />
<Compile Include="OutlineView\DragListener.cs" /> <Compile Include="OutlineView\DragListener.cs" />
<Compile Include="OutlineView\DragTreeView.cs" /> <Compile Include="OutlineView\DragTreeView.cs" />
@ -197,6 +196,7 @@
<Compile Include="PropertyGrid\PropertyGridView.xaml.cs"> <Compile Include="PropertyGrid\PropertyGridView.xaml.cs">
<DependentUpon>PropertyGridView.xaml</DependentUpon> <DependentUpon>PropertyGridView.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="RootItemBehavior.cs" />
<Compile Include="Services\ChooseClass.cs" /> <Compile Include="Services\ChooseClass.cs" />
<Compile Include="Services\ChooseClassDialog.xaml.cs"> <Compile Include="Services\ChooseClassDialog.xaml.cs">
<DependentUpon>ChooseClassDialog.xaml</DependentUpon> <DependentUpon>ChooseClassDialog.xaml</DependentUpon>

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs

@ -95,6 +95,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
_rootItem = _componentService.RegisterXamlComponentRecursive(_doc.RootElement); _rootItem = _componentService.RegisterXamlComponentRecursive(_doc.RootElement);
if(_rootItem!=null){
var rootBehavior=new RootItemBehavior();
rootBehavior.Intialize(this);
}
_xamlEditOperations=new XamlEditOperations(this,parserSettings); _xamlEditOperations=new XamlEditOperations(this,parserSettings);
} }

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

@ -228,6 +228,21 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
foreach (XmlAttribute attribute in element.Attributes) { foreach (XmlAttribute attribute in element.Attributes) {
if (attribute.Value.StartsWith("clr-namespace", StringComparison.OrdinalIgnoreCase)) {
// the format is "clr-namespace:<Namespace here>;assembly=<Assembly name here>"
var clrNamespace = attribute.Value.Split(new[] {':', ';', '='});
if (clrNamespace.Length == 4) {
// get the assembly name
var assembly=settings.TypeFinder.LoadAssembly(clrNamespace[3]);
if(assembly!=null)
settings.TypeFinder.RegisterAssembly(assembly);
} else {
// if no assembly name is there, then load the assembly of the opened file.
var assembly=settings.TypeFinder.LoadAssembly(null);
if(assembly!=null)
settings.TypeFinder.RegisterAssembly(assembly);
}
}
if (attribute.NamespaceURI == XamlConstants.XmlnsNamespace) if (attribute.NamespaceURI == XamlConstants.XmlnsNamespace)
continue; continue;
if (attribute.Name == "xml:space") { if (attribute.Name == "xml:space") {
@ -586,27 +601,27 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// <param name="settings">Parser settings used by <see cref="XamlParser"/>.</param> /// <param name="settings">Parser settings used by <see cref="XamlParser"/>.</param>
/// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns> /// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns>
public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings) public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings)
{ {
XmlTextReader reader = new XmlTextReader(new StringReader(xaml)); XmlTextReader reader = new XmlTextReader(new StringReader(xaml));
var element = root.OwnerDocument.XmlDocument.ReadNode(reader); var element = root.OwnerDocument.XmlDocument.ReadNode(reader);
if (element != null) { if (element != null) {
XmlAttribute xmlnsAttribute=null; XmlAttribute xmlnsAttribute=null;
foreach (XmlAttribute attrib in element.Attributes) { foreach (XmlAttribute attrib in element.Attributes) {
if (attrib.Name == "xmlns") if (attrib.Name == "xmlns")
xmlnsAttribute = attrib; xmlnsAttribute = attrib;
} }
if(xmlnsAttribute!=null) if(xmlnsAttribute!=null)
element.Attributes.Remove(xmlnsAttribute); element.Attributes.Remove(xmlnsAttribute);
XamlParser parser = new XamlParser(); XamlParser parser = new XamlParser();
parser.settings = settings; parser.settings = settings;
parser.document = root.OwnerDocument; parser.document = root.OwnerDocument;
var xamlObject = parser.ParseObject(element as XmlElement); var xamlObject = parser.ParseObject(element as XmlElement);
if (xamlObject != null) if (xamlObject != null)
return xamlObject; return xamlObject;
} }
return null; return null;
} }
} }
} }

Loading…
Cancel
Save