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. 38
      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. 59
      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 @@ -37,6 +37,15 @@ namespace ICSharpCode.WpfDesign.AddIn
}
return null;
} 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);
}
}

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

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

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

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

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

@ -1,30 +1,32 @@ @@ -1,30 +1,32 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// <author name="Kumar Devvrat"/>
// <version>$Revision: $</version>
// </file>
using System;
using System.Collections.Generic;
using System.Windows;
using ICSharpCode.WpfDesign.Extensions;
using System.Collections.Generic;
using System.Diagnostics;
namespace ICSharpCode.WpfDesign.Designer.Extensions
namespace ICSharpCode.WpfDesign.Designer
{
/// <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>
[ExtensionFor(typeof(Window))]
public class WindowResizeBehavior : BehaviorExtension, IRootPlacementBehavior
public class RootItemBehavior : IRootPlacementBehavior
{
protected override void OnInitialized()
private DesignItem _rootItem;
public void Intialize(DesignContext context)
{
base.OnInitialized();
this.ExtendedItem.AddBehavior(typeof(IRootPlacementBehavior), this);
Debug.Assert(context.RootItem!=null);
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 &&
(position == PlacementAlignment.Right
@ -32,16 +34,17 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -32,16 +34,17 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
|| position == PlacementAlignment.Bottom);
}
public void BeginPlacement(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;
return new Rect(0, 0, ModelTools.GetWidth(child), ModelTools.GetHeight(child));
@ -49,6 +52,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -49,6 +52,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public void BeforeSetPosition(PlacementOperation operation)
{
throw new NotImplementedException();
}
public void SetPosition(PlacementInformation info)
@ -70,7 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -70,7 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public void LeaveContainer(PlacementOperation operation)
{
throw new NotSupportedException();
throw new NotImplementedException();
}
public bool CanEnterContainer(PlacementOperation operation)
@ -80,7 +84,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -80,7 +84,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
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 @@ @@ -139,7 +139,6 @@
<Compile Include="Extensions\TabItemClickableExtension.cs" />
<Compile Include="Extensions\TopLeftContainerDragHandle.cs" />
<Compile Include="Extensions\ResizeThumbExtension.cs" />
<Compile Include="Extensions\WindowResizeBehavior.cs" />
<Compile Include="BasicMetadata.cs" />
<Compile Include="OutlineView\DragListener.cs" />
<Compile Include="OutlineView\DragTreeView.cs" />
@ -197,6 +196,7 @@ @@ -197,6 +196,7 @@
<Compile Include="PropertyGrid\PropertyGridView.xaml.cs">
<DependentUpon>PropertyGridView.xaml</DependentUpon>
</Compile>
<Compile Include="RootItemBehavior.cs" />
<Compile Include="Services\ChooseClass.cs" />
<Compile Include="Services\ChooseClassDialog.xaml.cs">
<DependentUpon>ChooseClassDialog.xaml</DependentUpon>

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

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

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

@ -228,6 +228,21 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -228,6 +228,21 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
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)
continue;
if (attribute.Name == "xml:space") {
@ -586,27 +601,27 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -586,27 +601,27 @@ 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)
{
XmlTextReader reader = new XmlTextReader(new StringReader(xaml));
var element = root.OwnerDocument.XmlDocument.ReadNode(reader);
if (element != null) {
XmlAttribute xmlnsAttribute=null;
foreach (XmlAttribute attrib in element.Attributes) {
if (attrib.Name == "xmlns")
xmlnsAttribute = attrib;
}
if(xmlnsAttribute!=null)
element.Attributes.Remove(xmlnsAttribute);
XamlParser parser = new XamlParser();
parser.settings = settings;
parser.document = root.OwnerDocument;
var xamlObject = parser.ParseObject(element as XmlElement);
if (xamlObject != null)
return xamlObject;
}
return null;
}
{
XmlTextReader reader = new XmlTextReader(new StringReader(xaml));
var element = root.OwnerDocument.XmlDocument.ReadNode(reader);
if (element != null) {
XmlAttribute xmlnsAttribute=null;
foreach (XmlAttribute attrib in element.Attributes) {
if (attrib.Name == "xmlns")
xmlnsAttribute = attrib;
}
if(xmlnsAttribute!=null)
element.Attributes.Remove(xmlnsAttribute);
XamlParser parser = new XamlParser();
parser.settings = settings;
parser.document = root.OwnerDocument;
var xamlObject = parser.ParseObject(element as XmlElement);
if (xamlObject != null)
return xamlObject;
}
return null;
}
}
}

Loading…
Cancel
Save