Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3655 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
285 changed files with 227 additions and 28097 deletions
@ -1,197 +0,0 @@
@@ -1,197 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using NUnit.Framework; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Media; |
||||
using System.Windows.Data; |
||||
using System.Windows; |
||||
using System.Windows.Documents; |
||||
using System.Xml.Linq; |
||||
using System.Windows.Markup; |
||||
using ICSharpCode.WpfDesign.Designer.XamlBackend; |
||||
|
||||
namespace ICSharpCode.Xaml.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class EditingTests |
||||
{ |
||||
DefaultWpfProject project = new DefaultWpfProject(); |
||||
XamlDocument document; |
||||
|
||||
void Check(string s) |
||||
{ |
||||
var doc1 = XDocument.Parse(EasyDocument(s)); |
||||
foreach (var e in doc1.Root.DescendantsAndSelf()) { |
||||
e.Name = XamlConstants.Presentation2007Namespace + e.Name.LocalName; |
||||
} |
||||
|
||||
Assert.IsTrue(XNode.DeepEquals(doc1, document.XmlDocument)); |
||||
|
||||
// some tests incorrect from instance point of view
|
||||
object officialInstance = null; |
||||
try { |
||||
officialInstance = XamlReader.Parse(document.XmlDocument.ToString()); |
||||
} |
||||
catch { |
||||
return; |
||||
} |
||||
|
||||
var myResult = XamlWriter.Save(document.Root.Instance); |
||||
var officialResult = XamlWriter.Save(officialInstance); |
||||
|
||||
Assert.AreEqual(myResult, officialResult); |
||||
} |
||||
|
||||
string EasyDocument(string s) |
||||
{ |
||||
var index = s.IndexOfAny(new[] { ' ', '/', '>' }); |
||||
return s.Insert(index, string.Format(" xmlns='{0}' xmlns:x='{1}' ", |
||||
XamlConstants.Presentation2007Namespace, XamlConstants.XamlNamespace)); |
||||
} |
||||
|
||||
[Test] |
||||
public void Test1() |
||||
{ |
||||
document = project.CreateDocument(new Button()); |
||||
ObjectNode button = document.Root; |
||||
|
||||
Check("<Button/>"); |
||||
|
||||
button.Property("Width").Set(100); |
||||
Check("<Button Width='100'/>"); |
||||
|
||||
button.Property("Width").Reset(); |
||||
Check("<Button/>"); |
||||
|
||||
button.Property(Button.WidthProperty).Set(100); |
||||
Check("<Button Width='100'/>"); |
||||
|
||||
button.Property(Button.WidthProperty).Reset(); |
||||
Check("<Button/>"); |
||||
|
||||
button.Content.Set("Label"); |
||||
Check("<Button Content='Label'/>"); |
||||
|
||||
button.Content.Set(new Border()); |
||||
Check("<Button><Border/></Button>"); |
||||
button.Content.Reset(); |
||||
|
||||
button.Property(Button.BackgroundProperty).Set(new LinearGradientBrush()); |
||||
Check("<Button><Button.Background><LinearGradientBrush/></Button.Background></Button>"); |
||||
button.Property(Button.BackgroundProperty).Reset(); |
||||
|
||||
button.Property(Canvas.LeftProperty).Set(100); |
||||
Check("<Button Canvas.Left='100'/>"); |
||||
button.Property(Canvas.LeftProperty).Reset(); |
||||
|
||||
var binding = button.Content.SetObject(new Binding()); |
||||
Check("<Button Content='{Binding}'/>"); |
||||
|
||||
binding.Property("ElementName").Set("e1"); |
||||
Check("<Button Content='{Binding ElementName=e1}'/>"); |
||||
|
||||
binding.Property("Mode").Set(BindingMode.TwoWay); |
||||
Check("<Button Content='{Binding ElementName=e1, Mode=TwoWay}'/>"); |
||||
|
||||
var staticResource = binding.Property("Converter").SetObject(new StaticResourceExtension()); |
||||
staticResource.Property("ResourceKey").Set("Converter1"); |
||||
Check("<Button Content='{Binding ElementName=e1, Mode=TwoWay, Converter={StaticResource Converter1}}'/>"); |
||||
button.Content.Reset(); |
||||
|
||||
binding = button.Content.SetObject("{Binding Some1}"); |
||||
Check("<Button Content='{Binding Some1}'/>"); |
||||
|
||||
binding.Property("Source").Set(new Button()); |
||||
Check("<Button><Binding Path='Some1'><Binding.Source><Button/></Binding.Source></Binding></Button>"); |
||||
|
||||
binding.Property("Source").Reset(); |
||||
Check("<Button Content='{Binding Some1}'/>"); |
||||
|
||||
binding.Remove(); |
||||
Check("<Button/>"); |
||||
|
||||
button.Property("Resources").Add("brush1", Brushes.Red); |
||||
Check("<Button><Button.Resources><Brush x:Key='brush1'>Red</Brush></Button.Resources></Button>"); |
||||
|
||||
button.Property("Resources").Reset(); |
||||
Check("<Button/>"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Test2() |
||||
{ |
||||
document = project.CreateDocument(new TextBlock()); |
||||
ObjectNode textBlock = document.Root; |
||||
|
||||
Check("<TextBlock/>"); |
||||
|
||||
textBlock.Content.Add("text1"); |
||||
Check("<TextBlock>text1</TextBlock>"); |
||||
|
||||
textBlock.Content.Add("text2"); |
||||
Check("<TextBlock>text1text2</TextBlock>"); |
||||
|
||||
var bold = textBlock.Content.AddObject(new Bold()); |
||||
bold.Content.Set("bold1"); |
||||
textBlock.Content.Add("text3"); |
||||
Check("<TextBlock>text1text2<Bold>bold1</Bold>text3</TextBlock>"); |
||||
|
||||
//var bold = textBlock.Content.AddObject(new Bold());
|
||||
//bold.Content.Set("bold1");
|
||||
//textBlock.Content.Add(" text3 ");
|
||||
//Check("<TextBlock xml:space='preserve'>text1text2<Bold>bold1</Bold> text3 </TextBlock>");
|
||||
|
||||
//bold.Remove();
|
||||
//Check("<TextBlock>text1text2 text3 </TextBlock>");
|
||||
|
||||
//textBlock.Content.Reset();
|
||||
//Check("<TextBlock/>");
|
||||
} |
||||
|
||||
[Test] |
||||
public void Test3() |
||||
{ |
||||
document = project.CreateDocument(new CheckBox()); |
||||
var checkBox = document.Root; |
||||
document.Root = null; |
||||
Assert.IsTrue(document.XmlDocument.Root == null); |
||||
|
||||
document.Root = checkBox; |
||||
Check("<CheckBox/>"); |
||||
|
||||
document.Parse(EasyDocument("<Slider/>")); |
||||
Check("<Slider/>"); |
||||
|
||||
var canvas = document.CreateObject(new Canvas()); |
||||
canvas.Property("Width").Set(100); |
||||
document.Root = canvas; |
||||
Check("<Canvas Width='100'/>"); |
||||
canvas.Property("Width").Reset(); |
||||
|
||||
var button1 = canvas.Content.AddObject(new Button()); |
||||
canvas.Content.Add(new Button()); |
||||
button1.Remove(); |
||||
Check("<Canvas><Button/></Canvas>"); |
||||
} |
||||
|
||||
//[Test]
|
||||
//public void Test4()
|
||||
//{
|
||||
// document = project.CreateDocument(new Style());
|
||||
// var style = document.Root;
|
||||
// var setter = style.Content.AddObject(new Setter());
|
||||
// setter.Property("Property").Set("Background");
|
||||
//}
|
||||
|
||||
[Test] |
||||
public void Test5() |
||||
{ |
||||
document = project.CreateDocument(new Button()); |
||||
var button = document.Root; |
||||
Assert.AreEqual(button.Property(Button.HorizontalAlignmentProperty).ValueOnInstance, |
||||
new Button().HorizontalAlignment); |
||||
} |
||||
} |
||||
} |
@ -1 +0,0 @@
@@ -1 +0,0 @@
|
||||
|
@ -1,85 +0,0 @@
@@ -1,85 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProductVersion>9.0.30729</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{EDF67E30-F45F-40C5-8B68-4A22FFD02A2E}</ProjectGuid> |
||||
<OutputType>Library</OutputType> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
<RootNamespace>ICSharpCode.Xaml.Tests</RootNamespace> |
||||
<AssemblyName>ICSharpCode.Xaml.Tests</AssemblyName> |
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> |
||||
<FileAlignment>512</FileAlignment> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>..\..\..\..\..\bin\UnitTests\</OutputPath> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugType>pdbonly</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>..\..\..\..\..\bin\UnitTests\</OutputPath> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" /> |
||||
<Reference Include="PresentationCore"> |
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="PresentationFramework"> |
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Xml.Linq"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Data.DataSetExtensions"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="WindowsBase"> |
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs"> |
||||
<Link>Properties\GlobalAssemblyInfo.cs</Link> |
||||
</Compile> |
||||
<Compile Include="EditingTests.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<None Include="app.config" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\..\..\DisplayBindings\WpfDesign\WpfDesign.Designer\WpfDesign.Designer.csproj"> |
||||
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project> |
||||
<Name>WpfDesign.Designer</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\Xaml\Xaml.csproj"> |
||||
<Project>{B4E5C965-7BB9-4AE9-85FB-C47480B879AD}</Project> |
||||
<Name>Xaml</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||
Other similar extension points exist, see Microsoft.Common.targets. |
||||
<Target Name="BeforeBuild"> |
||||
</Target> |
||||
<Target Name="AfterBuild"> |
||||
</Target> |
||||
--> |
||||
</Project> |
@ -1,13 +0,0 @@
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?> |
||||
<configuration> |
||||
<configSections> |
||||
<sectionGroup name="NUnit"> |
||||
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/> |
||||
</sectionGroup> |
||||
</configSections> |
||||
<NUnit> |
||||
<TestRunner> |
||||
<add key="ApartmentState" value="STA" /> |
||||
</TestRunner> |
||||
</NUnit> |
||||
</configuration> |
@ -1,12 +0,0 @@
@@ -1,12 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public enum AllowedLocation |
||||
{ |
||||
Any, AttributeOnly, None |
||||
} |
||||
} |
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 3509 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Collections; |
||||
using System.ComponentModel; |
||||
using System.Globalization; |
||||
using System.Reflection; |
||||
using System.Windows; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
/// <summary>
|
||||
/// Static class containing helper methods to work with collections (like the XamlParser does)
|
||||
/// </summary>
|
||||
public static class CollectionSupport |
||||
{ |
||||
/// <summary>
|
||||
/// Gets if the type is considered a collection in XAML.
|
||||
/// </summary>
|
||||
public static bool IsCollectionType(Type type) |
||||
{ |
||||
return typeof(IList).IsAssignableFrom(type) |
||||
|| type.IsArray |
||||
|| typeof(IAddChild).IsAssignableFrom(type) |
||||
|| typeof(ResourceDictionary).IsAssignableFrom(type); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets if the collection type <paramref name="col"/> can accepts items of type
|
||||
/// <paramref name="item"/>.
|
||||
/// </summary>
|
||||
public static bool CanCollectionAdd(Type col, Type item) |
||||
{ |
||||
var e = col.GetInterface("IEnumerable`1"); |
||||
if (e != null && e.IsGenericType) { |
||||
var a = e.GetGenericArguments()[0]; |
||||
return a.IsAssignableFrom(item); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets if the collection type <paramref name="col"/> can accept the specified items.
|
||||
/// </summary>
|
||||
public static bool CanCollectionAdd(Type col, IEnumerable items) |
||||
{ |
||||
foreach (var item in items) { |
||||
if (!CanCollectionAdd(col, item.GetType())) return false; |
||||
} |
||||
return true; |
||||
} |
||||
} |
||||
} |
@ -1,13 +0,0 @@
@@ -1,13 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class Constructor |
||||
{ |
||||
public XamlType[] Arguments; |
||||
public XamlMember[] CorrespondingMembers; |
||||
} |
||||
} |
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class DefaultXamlMember : XamlMember |
||||
{ |
||||
public override string Name |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlType OwnerType |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlType ValueType |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsReadOnly |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsStatic |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsAttachable |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlType TargetType |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override AllowedLocation AllowedLocation |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsEvent |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsDirective |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override T GetAttribute<T>() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override bool HasTextSyntax |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
} |
||||
} |
@ -1,140 +0,0 @@
@@ -1,140 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class DefaultXamlType : XamlType |
||||
{ |
||||
public override string Name |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsDefaultConstructible |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsNullable |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<XamlMember> Members |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember ContentProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember DictionaryKeyProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember NameProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember XmlLangProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool TrimSurroundingWhitespace |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsWhitespaceSignificantCollection |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsCollection |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsDictionary |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<XamlType> AllowedTypes |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<XamlType> AllowedKeyTypes |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsXData |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsNameScope |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<Constructor> Constructors |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlType ReturnValueType |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override string Namespace |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlAssembly Assembly |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember Member(string name) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override IEnumerable<XamlType> ContentWrappers |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool HasTextSyntax |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override Type SystemType |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsAssignableFrom(XamlType type) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override T GetAttribute<T>() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -1,68 +0,0 @@
@@ -1,68 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml.Linq; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class Directive |
||||
{ |
||||
static Directive() |
||||
{ |
||||
Name = CreateXamlDirective("Name"); |
||||
Key = CreateXamlDirective("Key"); |
||||
Uid = CreateXamlDirective("Uid"); |
||||
Class = CreateXamlDirective("Class"); |
||||
ClassModifier = CreateXamlDirective("ClassModifier"); |
||||
FieldModifier = CreateXamlDirective("FieldModifier"); |
||||
TypeArguments = CreateXamlDirective("TypeArguments"); |
||||
XmlLang = CreateDirective(XNamespace.Xml + "lang"); |
||||
XmlSpace = CreateDirective(XNamespace.Xml + "space"); |
||||
} |
||||
|
||||
public static XamlMember Name; |
||||
public static XamlMember Key; |
||||
public static XamlMember Uid; |
||||
public static XamlMember Class; |
||||
public static XamlMember ClassModifier; |
||||
public static XamlMember FieldModifier; |
||||
public static XamlMember TypeArguments; |
||||
public static XamlMember XmlLang; |
||||
public static XamlMember XmlSpace; |
||||
|
||||
static XamlMember CreateXamlDirective(string name) |
||||
{ |
||||
return CreateDirective(XamlConstants.XamlNamespace + name); |
||||
} |
||||
|
||||
static XamlMember CreateDirective(XName name) |
||||
{ |
||||
var result = new IntristicMember(name.LocalName); |
||||
directiveFromName[name] = result; |
||||
nameFromDirective[result] = name; |
||||
return result; |
||||
} |
||||
|
||||
static Dictionary<XName, XamlMember> directiveFromName = new Dictionary<XName, XamlMember>(); |
||||
static Dictionary<XamlMember, XName> nameFromDirective = new Dictionary<XamlMember, XName>(); |
||||
|
||||
public static XamlMember GetDirective(XName name) |
||||
{ |
||||
XamlMember result; |
||||
if (directiveFromName.TryGetValue(name, out result)) { |
||||
return result; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static XName GetDirectiveName(XamlMember member) |
||||
{ |
||||
XName result; |
||||
if (nameFromDirective.TryGetValue(member, out result)) { |
||||
return result; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -1,20 +0,0 @@
@@ -1,20 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public static class ExtensionMethods |
||||
{ |
||||
public static V FindOrCreate<K, V>(this Dictionary<K, V> dict, K key) where V : new() |
||||
{ |
||||
V value; |
||||
if (!dict.TryGetValue(key, out value)) { |
||||
value = new V(); |
||||
dict[key] = value; |
||||
} |
||||
return value; |
||||
} |
||||
} |
||||
} |
@ -1,13 +0,0 @@
@@ -1,13 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public interface IHasAnnotations |
||||
{ |
||||
void AnnotateWith<T>(T annotation) where T : class; |
||||
T GetAnnotation<T>() where T : class; |
||||
} |
||||
} |
@ -1,238 +0,0 @@
@@ -1,238 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.ComponentModel; |
||||
using System.Windows.Markup; |
||||
using System.Windows; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
class InstanceTracker : Tracker |
||||
{ |
||||
public override void Add(MemberNode memberNode) |
||||
{ |
||||
foreach (var valueNode in memberNode.Values) { |
||||
Add(valueNode); |
||||
} |
||||
} |
||||
|
||||
public override void Add(ObjectNode objectNode) |
||||
{ |
||||
if (objectNode.Instance == null) { |
||||
Instantiate(objectNode); |
||||
} |
||||
var parentMember = objectNode.ParentMember; |
||||
if (parentMember != null) { |
||||
if (parentMember.Member == IntristicMember.Items) { |
||||
var collectionObjectNode = parentMember.ParentObject; |
||||
if (collectionObjectNode.Type.IsDictionary) { |
||||
//var keyValue = objectNode.Key.Value;
|
||||
//if (keyValue != null) {
|
||||
// Runtime.Add(collectionObjectNode.Instance,
|
||||
// keyValue.Instance, objectNode.Instance);
|
||||
//}
|
||||
} |
||||
else { |
||||
Runtime.Add(collectionObjectNode.Instance, objectNode.Instance); |
||||
} |
||||
} |
||||
else { |
||||
if (!objectNode.IsRetrieved) { |
||||
object valueInstance; |
||||
if (objectNode.Type.IsMarkupExtension) { |
||||
valueInstance = ProvideValue(objectNode); |
||||
} |
||||
else { |
||||
valueInstance = objectNode.Instance; |
||||
} |
||||
Runtime.SetValue(parentMember, valueInstance); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public override void Add(TextNode textNode) |
||||
{ |
||||
var parentMember = textNode.ParentMember; |
||||
if (parentMember != null) { |
||||
textNode.Instance = Runtime.ConvertFromText( |
||||
parentMember.Property.XamlContext, |
||||
textNode.Text); |
||||
|
||||
if (parentMember.Member == IntristicMember.Items) { |
||||
// IAddChild support.
|
||||
// Instance could differ without it (e.g. TextBlock.Inlines vs TextBlock.Text)
|
||||
var grandParentMember = parentMember.ParentObject.ParentMember; |
||||
if (grandParentMember != null) { |
||||
var addChild = grandParentMember.ParentObject.Instance as IAddChild; |
||||
if (addChild != null) { |
||||
addChild.AddText(textNode.Text); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
Runtime.Add(parentMember.ParentObject.Instance, textNode.Instance); |
||||
} |
||||
else { |
||||
Runtime.SetValue(parentMember, textNode.Instance); |
||||
if (parentMember.Member == Directive.Key) { |
||||
Runtime.Add(parentMember.ParentObject.ParentObject.Instance, |
||||
textNode.Instance, parentMember.ParentObject.Instance); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public override void Remove(MemberNode node, ObjectNode parent) |
||||
{ |
||||
Runtime.ResetValue(parent.Instance, node.Member); |
||||
} |
||||
|
||||
public override void Remove(ObjectNode node, MemberNode parent) |
||||
{ |
||||
if (parent != null && parent.Member == IntristicMember.Items) { |
||||
Runtime.Remove(parent.ParentObject.Instance, node.Instance); |
||||
} |
||||
} |
||||
|
||||
void Instantiate(ObjectNode objectNode) |
||||
{ |
||||
var parentMember = objectNode.ParentMember; |
||||
ISupportInitialize supportInitialize = null; |
||||
|
||||
if (objectNode.IsRetrieved) { |
||||
objectNode.Instance = Runtime.GetValue(parentMember); |
||||
} |
||||
else { |
||||
if (objectNode.InitializationText.IsSet) { |
||||
objectNode.Instance = Runtime.ConvertFromText( |
||||
objectNode.InitializationText.XamlContext, |
||||
objectNode.InitializationText.ValueText); |
||||
} |
||||
else { |
||||
var ctorNode = objectNode.FindMemberNode(IntristicMember.ConsructorArgs); |
||||
if (ctorNode != null) { |
||||
objectNode.Instance = Construct(ctorNode); |
||||
} |
||||
else { |
||||
objectNode.Instance = Runtime.CreateInstance(objectNode.Type, null); |
||||
} |
||||
} |
||||
|
||||
supportInitialize = objectNode.Instance as ISupportInitialize; |
||||
if (supportInitialize != null) { |
||||
supportInitialize.BeginInit(); |
||||
} |
||||
} |
||||
|
||||
foreach (var memberNode in objectNode.MemberNodes) { |
||||
if (memberNode.Member == IntristicMember.ConsructorArgs) continue; |
||||
Add(memberNode); |
||||
} |
||||
|
||||
if (supportInitialize != null) { |
||||
supportInitialize.EndInit(); |
||||
} |
||||
} |
||||
|
||||
object Construct(MemberNode ctorNode) |
||||
{ |
||||
var objectNode = ctorNode.ParentObject; |
||||
var args = new List<object>(); |
||||
var ctor = objectNode.Type.Constructors.First( |
||||
c => c.Arguments.Count() == ctorNode.Values.Count); |
||||
|
||||
for (int i = 0; i < ctorNode.Values.Count; i++) { |
||||
var ctorArgValue = ctorNode.Values[i]; |
||||
Add(ctorArgValue); |
||||
|
||||
var value = ctorArgValue.Instance; |
||||
var targetType = ctor.Arguments[i]; |
||||
if (!targetType.SystemType.IsAssignableFrom(value.GetType())) { |
||||
var text = value as string; |
||||
if (text != null) { |
||||
value = Runtime.ConvertFromText(ctorNode.Property.XamlContext, targetType, text); |
||||
} |
||||
else { |
||||
throw new XamlException("Cannot convert"); |
||||
} |
||||
} |
||||
args.Add(value); |
||||
} |
||||
return Runtime.CreateInstance(objectNode.Type, args.ToArray()); |
||||
} |
||||
|
||||
object ProvideValue(ObjectNode node) |
||||
{ |
||||
var me = node.Instance as MarkupExtension; |
||||
|
||||
Instantiate(node); |
||||
|
||||
if (me is StaticResourceExtension) { |
||||
return FindResource(node, (me as StaticResourceExtension).ResourceKey); |
||||
} |
||||
else if (me is DynamicResourceExtension) { |
||||
return FindResource(node, (me as DynamicResourceExtension).ResourceKey); |
||||
} |
||||
|
||||
return me.ProvideValue(node.ParentMember.Property.XamlContext); |
||||
} |
||||
|
||||
object FindResource(ObjectNode node, object key) |
||||
{ |
||||
if (key == null) return null; |
||||
|
||||
var current = node; |
||||
while (current != null) { |
||||
var result = GetResource(current.Instance, key); |
||||
if (result != Runtime.UnsetValue) { |
||||
return result; |
||||
} |
||||
current = current.ParentObject; |
||||
} |
||||
|
||||
var appDefinition = node.Document.Project.ApplicationDefinition; |
||||
if (appDefinition != null) { |
||||
var app = appDefinition.Root.Instance as Application; |
||||
if (app != null) { |
||||
var result = GetResource(app, key); |
||||
if (result != Runtime.UnsetValue) { |
||||
return result; |
||||
} |
||||
} |
||||
} |
||||
//if (key is ComponentResourceKey)
|
||||
//{
|
||||
// fore
|
||||
//}
|
||||
return null; |
||||
} |
||||
|
||||
public static object GetResource(object container, object key) |
||||
{ |
||||
var resources = GetResources(container); |
||||
if (resources != null && resources.Contains(key)) { |
||||
return resources[key]; |
||||
} |
||||
return Runtime.UnsetValue; |
||||
} |
||||
|
||||
public static ResourceDictionary GetResources(object container) |
||||
{ |
||||
if (container is FrameworkElement) { |
||||
return (container as FrameworkElement).Resources; |
||||
} |
||||
if (container is FrameworkTemplate) { |
||||
return (container as FrameworkTemplate).Resources; |
||||
} |
||||
if (container is Style) { |
||||
return (container as Style).Resources; |
||||
} |
||||
if (container is Application) { |
||||
return (container as Application).Resources; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -1,83 +0,0 @@
@@ -1,83 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml.Linq; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class IntristicMember : XamlMember |
||||
{ |
||||
public IntristicMember(string name) |
||||
{ |
||||
this.name = name; |
||||
} |
||||
|
||||
public static XamlMember Items = new IntristicMember("Items"); |
||||
public static XamlMember ConsructorArgs = new IntristicMember("ConsructorArgs"); |
||||
public static XamlMember InitializationText = new IntristicMember("InitializationText"); |
||||
public static XamlMember DirectiveChildren = new IntristicMember("DirectiveChildren"); |
||||
|
||||
string name; |
||||
|
||||
public override string Name |
||||
{ |
||||
get { return name; } |
||||
} |
||||
|
||||
public override XamlType OwnerType |
||||
{ |
||||
get { return null; } |
||||
} |
||||
|
||||
public override XamlType ValueType |
||||
{ |
||||
get { return ReflectionMapper.GetXamlType(typeof(object)); } |
||||
} |
||||
|
||||
public override XamlType TargetType |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override AllowedLocation AllowedLocation |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsEvent |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsDirective |
||||
{ |
||||
get { return true; } |
||||
} |
||||
|
||||
public override bool IsReadOnly |
||||
{ |
||||
get { return false; } |
||||
} |
||||
|
||||
public override bool IsStatic |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsAttachable |
||||
{ |
||||
get { return false; } |
||||
} |
||||
|
||||
public override T GetAttribute<T>() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override bool HasTextSyntax |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
} |
||||
} |
@ -1,151 +0,0 @@
@@ -1,151 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml.Linq; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class IntristicType : XamlType |
||||
{ |
||||
public static XName CodeName = XamlConstants.XamlNamespace + "Code"; |
||||
public static XName XDataName = XamlConstants.XamlNamespace + "XData"; |
||||
|
||||
public static XamlType Code = new IntristicType(); |
||||
public static XamlType XData = new IntristicType(); |
||||
|
||||
public static XamlType String = ReflectionMapper.GetXamlType(typeof(string)); |
||||
public static XamlType MarkupExtension = ReflectionMapper.GetXamlType(typeof(MarkupExtension)); |
||||
|
||||
public override string Name |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsDefaultConstructible |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsNullable |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<XamlMember> Members |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember ContentProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember DictionaryKeyProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember NameProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember XmlLangProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool TrimSurroundingWhitespace |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsWhitespaceSignificantCollection |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsCollection |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsDictionary |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<XamlType> AllowedTypes |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<XamlType> AllowedKeyTypes |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsXData |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsNameScope |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<Constructor> Constructors |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlType ReturnValueType |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override string Namespace |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlAssembly Assembly |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember Member(string name) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override bool IsAssignableFrom(XamlType type) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override IEnumerable<XamlType> ContentWrappers |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool HasTextSyntax |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override Type SystemType |
||||
{ |
||||
get { return null; } |
||||
} |
||||
|
||||
public override T GetAttribute<T>() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -1,209 +0,0 @@
@@ -1,209 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
class MarkupExtensionParser |
||||
{ |
||||
public static MarkupExtensionAst Parse(string text) |
||||
{ |
||||
var tokens = MarkupExtensionTokenizer.Tokenize(text); |
||||
|
||||
if (tokens.Count < 3 || |
||||
tokens[0].Kind != MarkupExtensionTokenKind.OpenBrace || |
||||
tokens[1].Kind != MarkupExtensionTokenKind.TypeName || |
||||
tokens[tokens.Count - 1].Kind != MarkupExtensionTokenKind.CloseBrace) { |
||||
throw new XamlException("Invalid markup extension"); |
||||
} |
||||
|
||||
var result = new MarkupExtensionAst(); |
||||
result.TypeName = tokens[1].Value; |
||||
|
||||
for (int i = 2; i < tokens.Count - 1; i++) { |
||||
if (tokens[i].Kind == MarkupExtensionTokenKind.String) { |
||||
result.PositionalArgs.Add(tokens[i].Value); |
||||
} |
||||
else if (tokens[i].Kind == MarkupExtensionTokenKind.Membername) { |
||||
if (tokens[i + 1].Kind != MarkupExtensionTokenKind.Equals || |
||||
tokens[i + 2].Kind != MarkupExtensionTokenKind.String) { |
||||
throw new XamlException("Invalid markup extension"); |
||||
} |
||||
var namedArg = new KeyValuePair<string, string>(tokens[i].Value, tokens[i + 2].Value); |
||||
result.NamedArgs.Add(namedArg); |
||||
i += 2; |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
class MarkupExtensionAst |
||||
{ |
||||
public string TypeName; |
||||
public List<string> PositionalArgs = new List<string>(); |
||||
public List<KeyValuePair<string, string>> NamedArgs = new List<KeyValuePair<string, string>>(); |
||||
} |
||||
|
||||
class MarkupExtensionTokenizer |
||||
{ |
||||
private MarkupExtensionTokenizer() { } |
||||
|
||||
string text; |
||||
int pos; |
||||
List<MarkupExtensionToken> tokens = new List<MarkupExtensionToken>(); |
||||
|
||||
public static List<MarkupExtensionToken> Tokenize(string text) |
||||
{ |
||||
MarkupExtensionTokenizer t = new MarkupExtensionTokenizer(); |
||||
t.text = text; |
||||
t.Parse(); |
||||
return t.tokens; |
||||
} |
||||
|
||||
void AddToken(MarkupExtensionTokenKind kind, string val) |
||||
{ |
||||
tokens.Add(new MarkupExtensionToken(kind, val)); |
||||
} |
||||
|
||||
void Parse() |
||||
{ |
||||
AddToken(MarkupExtensionTokenKind.OpenBrace, "{"); |
||||
Expect('{'); |
||||
ConsumeWhitespace(); |
||||
CheckNotEOF(); |
||||
|
||||
StringBuilder b = new StringBuilder(); |
||||
while (pos < text.Length && !char.IsWhiteSpace(text, pos) && text[pos] != '}') |
||||
b.Append(text[pos++]); |
||||
AddToken(MarkupExtensionTokenKind.TypeName, b.ToString()); |
||||
|
||||
ConsumeWhitespace(); |
||||
while (pos < text.Length) { |
||||
switch (text[pos]) { |
||||
case '}': |
||||
AddToken(MarkupExtensionTokenKind.CloseBrace, "}"); |
||||
pos++; |
||||
break; |
||||
case '=': |
||||
AddToken(MarkupExtensionTokenKind.Equals, "="); |
||||
pos++; |
||||
break; |
||||
case ',': |
||||
AddToken(MarkupExtensionTokenKind.Comma, ","); |
||||
pos++; |
||||
break; |
||||
default: |
||||
MembernameOrString(); |
||||
break; |
||||
} |
||||
ConsumeWhitespace(); |
||||
} |
||||
} |
||||
|
||||
void MembernameOrString() |
||||
{ |
||||
StringBuilder b = new StringBuilder(); |
||||
if (text[pos] == '"' || text[pos] == '\'') { |
||||
char quote = text[pos++]; |
||||
CheckNotEOF(); |
||||
while (!(text[pos] == quote && text[pos - 1] != '\\')) { |
||||
char c = text[pos++]; |
||||
if (c != '\\') |
||||
b.Append(c); |
||||
CheckNotEOF(); |
||||
} |
||||
pos++; // consume closing quote
|
||||
ConsumeWhitespace(); |
||||
} |
||||
else { |
||||
int braceTotal = 0; |
||||
while (true) { |
||||
CheckNotEOF(); |
||||
switch (text[pos]) { |
||||
case '\\': |
||||
pos++; |
||||
CheckNotEOF(); |
||||
b.Append(text[pos++]); |
||||
break; |
||||
case '{': |
||||
b.Append(text[pos++]); |
||||
braceTotal++; |
||||
break; |
||||
case '}': |
||||
if (braceTotal == 0) goto stop; |
||||
b.Append(text[pos++]); |
||||
braceTotal--; |
||||
break; |
||||
case ',': |
||||
case '=': |
||||
if (braceTotal == 0) goto stop; |
||||
b.Append(text[pos++]); |
||||
break; |
||||
default: |
||||
b.Append(text[pos++]); |
||||
break; |
||||
} |
||||
} |
||||
stop: ; |
||||
} |
||||
CheckNotEOF(); |
||||
string valueText = b.ToString(); |
||||
if (text[pos] == '=') { |
||||
AddToken(MarkupExtensionTokenKind.Membername, valueText.Trim()); |
||||
} |
||||
else { |
||||
AddToken(MarkupExtensionTokenKind.String, valueText); |
||||
} |
||||
} |
||||
|
||||
void Expect(char c) |
||||
{ |
||||
CheckNotEOF(); |
||||
if (text[pos] != c) |
||||
throw new XamlException("Expected '" + c + "'"); |
||||
pos++; |
||||
} |
||||
|
||||
void ConsumeWhitespace() |
||||
{ |
||||
while (pos < text.Length && char.IsWhiteSpace(text, pos)) |
||||
pos++; |
||||
} |
||||
|
||||
void CheckNotEOF() |
||||
{ |
||||
if (pos >= text.Length) |
||||
throw new XamlException("Unexpected end of markup extension"); |
||||
} |
||||
} |
||||
|
||||
class MarkupExtensionToken |
||||
{ |
||||
public MarkupExtensionToken(MarkupExtensionTokenKind kind, string value) |
||||
{ |
||||
this.Kind = kind; |
||||
this.Value = value; |
||||
} |
||||
|
||||
public readonly MarkupExtensionTokenKind Kind; |
||||
public readonly string Value; |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return "[" + Kind + " " + Value + "]"; |
||||
} |
||||
} |
||||
|
||||
enum MarkupExtensionTokenKind |
||||
{ |
||||
OpenBrace, |
||||
CloseBrace, |
||||
Equals, |
||||
Comma, |
||||
TypeName, |
||||
Membername, |
||||
String |
||||
} |
||||
} |
@ -1,45 +0,0 @@
@@ -1,45 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Xaml |
||||
{ |
||||
public static class MarkupExtensionPrinter |
||||
{ |
||||
public static bool CanPrint(XamlObject obj) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
public static string Print(XamlObject obj) |
||||
{ |
||||
StringBuilder sb = new StringBuilder(); |
||||
sb.Append("{"); |
||||
sb.Append(obj.GetNameForMarkupExtension()); |
||||
|
||||
bool first = true; |
||||
foreach (var property in obj.Properties) { |
||||
if (!property.IsSet) continue; |
||||
|
||||
if (first) |
||||
sb.Append(" "); |
||||
else |
||||
sb.Append(", "); |
||||
first = false; |
||||
|
||||
sb.Append(property.GetNameForMarkupExtension()); |
||||
sb.Append("="); |
||||
|
||||
var value = property.PropertyValue; |
||||
if (value is XamlTextValue) { |
||||
sb.Append((value as XamlTextValue).Text); |
||||
} else if (value is XamlObject) { |
||||
sb.Append(Print(value as XamlObject)); |
||||
} |
||||
} |
||||
sb.Append("}"); |
||||
return sb.ToString(); |
||||
} |
||||
} |
||||
} |
@ -1,71 +0,0 @@
@@ -1,71 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class MemberNode : XamlNode |
||||
{ |
||||
internal MemberNode() |
||||
{ |
||||
Values = new NodeCollection<XamlValue>(this); |
||||
} |
||||
|
||||
public XamlMember Member; |
||||
public NodeCollection<XamlValue> Values; |
||||
|
||||
public ObjectNode ParentObject |
||||
{ |
||||
get { return ParentNode as ObjectNode; } |
||||
} |
||||
|
||||
public XamlProperty Property |
||||
{ |
||||
get |
||||
{ |
||||
if (ParentObject != null) { |
||||
return ParentObject.Property(Member); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public XamlValue SingleValue |
||||
{ |
||||
get |
||||
{ |
||||
if (Values.Count == 1) { |
||||
return Values[0]; |
||||
} |
||||
return null; |
||||
} |
||||
set |
||||
{ |
||||
if (Values.Count == 1) { |
||||
Values[0] = value; |
||||
} |
||||
else { |
||||
Values.Clear(); |
||||
Values.Add(value); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return GetType().Name + ": " + Member.Name; |
||||
} |
||||
|
||||
public override IEnumerable<XamlNode> Nodes() |
||||
{ |
||||
return Values.Cast<XamlNode>(); |
||||
} |
||||
|
||||
protected override void RemoveChild(XamlNode node) |
||||
{ |
||||
Values.Remove(node as XamlValue); |
||||
} |
||||
} |
||||
} |
@ -1,68 +0,0 @@
@@ -1,68 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Collections.ObjectModel; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class NodeCollection<T> : Collection<T> where T : XamlNode |
||||
{ |
||||
public NodeCollection(XamlNode parent) |
||||
{ |
||||
this.parent = parent; |
||||
} |
||||
|
||||
XamlNode parent; |
||||
|
||||
protected override void InsertItem(int index, T item) |
||||
{ |
||||
base.InsertItem(index, item); |
||||
item.ParentNode = parent; |
||||
if (item.Document != null) { |
||||
var e = new DocumentChangedEventArgs() { NewNode = item }; |
||||
item.Document.RaiseDocumentChanged(e); |
||||
} |
||||
} |
||||
|
||||
protected override void RemoveItem(int index) |
||||
{ |
||||
var item = this[index]; |
||||
base.RemoveItem(index); |
||||
if (item.Document != null) { |
||||
var e = new DocumentChangedEventArgs() { OldNode = item, OldParent = item.ParentNode }; |
||||
item.ParentNode = null; |
||||
item.Document.RaiseDocumentChanged(e); |
||||
} |
||||
else { |
||||
item.ParentNode = null; |
||||
} |
||||
} |
||||
|
||||
protected override void SetItem(int index, T item) |
||||
{ |
||||
var oldItem = this[index]; |
||||
base.SetItem(index, item); |
||||
if (item.Document != null) { |
||||
var e = new DocumentChangedEventArgs() { |
||||
OldNode = oldItem, |
||||
OldParent = oldItem.ParentNode, |
||||
NewNode = item |
||||
}; |
||||
oldItem.ParentNode = null; |
||||
item.ParentNode = parent; |
||||
item.Document.RaiseDocumentChanged(e); |
||||
} |
||||
else { |
||||
oldItem.ParentNode = null; |
||||
} |
||||
} |
||||
|
||||
protected override void ClearItems() |
||||
{ |
||||
while (Count > 0) { |
||||
RemoveItem(Count - 1); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,154 +0,0 @@
@@ -1,154 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Diagnostics; |
||||
using System.Collections.ObjectModel; |
||||
using System.Windows; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class ObjectNode : XamlValue |
||||
{ |
||||
internal ObjectNode() |
||||
{ |
||||
MemberNodes = new NodeCollection<MemberNode>(this); |
||||
} |
||||
|
||||
internal ObjectNode(XamlDocument doc, object instance) |
||||
: this() |
||||
{ |
||||
Document = doc; |
||||
Instance = instance; |
||||
Type = ReflectionMapper.GetXamlType(instance.GetType()); |
||||
} |
||||
|
||||
public XamlType Type; |
||||
public bool IsRetrieved; |
||||
public NodeCollection<MemberNode> MemberNodes; |
||||
Dictionary<XamlMember, XamlProperty> properties = new Dictionary<XamlMember, XamlProperty>(); |
||||
|
||||
public bool IsDocumentRoot |
||||
{ |
||||
get { return Document.Root == this; } |
||||
} |
||||
|
||||
public XamlProperty Content |
||||
{ |
||||
get |
||||
{ |
||||
if (Type.ContentProperty != null) { |
||||
return Property(Type.ContentProperty); |
||||
} |
||||
if (Type.IsCollection) { |
||||
return Property(IntristicMember.Items); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public XamlProperty InitializationText |
||||
{ |
||||
get { return Property(IntristicMember.InitializationText); } |
||||
} |
||||
|
||||
public string Name |
||||
{ |
||||
get |
||||
{ |
||||
var nameProperty = Property(Type.NameProperty); |
||||
if (nameProperty != null && nameProperty.IsSet) { |
||||
return nameProperty.ValueText; |
||||
} |
||||
var xNameProperty = Property(Directive.Name); |
||||
return xNameProperty.ValueText; |
||||
} |
||||
set |
||||
{ |
||||
var nameProperty = Property(Type.NameProperty); |
||||
var xNameProperty = Property(Directive.Name); |
||||
|
||||
if (nameProperty != null) { |
||||
nameProperty.Reset(); |
||||
} |
||||
|
||||
xNameProperty.Set(value); |
||||
} |
||||
} |
||||
|
||||
public XamlProperty Key |
||||
{ |
||||
get { return Property(Directive.Key); } |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return GetType().Name + ": " + Type.Name; |
||||
} |
||||
|
||||
public override IEnumerable<XamlNode> Nodes() |
||||
{ |
||||
return MemberNodes.Cast<XamlNode>(); |
||||
} |
||||
|
||||
protected override void RemoveChild(XamlNode node) |
||||
{ |
||||
MemberNodes.Remove(node as MemberNode); |
||||
} |
||||
|
||||
public MemberNode FindMemberNode(XamlMember member) |
||||
{ |
||||
foreach (var memberNode in MemberNodes) { |
||||
if (memberNode.Member == member) { |
||||
return memberNode; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public MemberNode EnsureMemberNode(XamlMember member) |
||||
{ |
||||
var memberNode = FindMemberNode(member); |
||||
if (memberNode == null) { |
||||
memberNode = new MemberNode() { Document = Document, Member = member }; |
||||
MemberNodes.Add(memberNode); |
||||
|
||||
if (member.IsReadOnly) { |
||||
var collection = new ObjectNode() { |
||||
Document = Document, |
||||
Type = member.ValueType, |
||||
IsRetrieved = true |
||||
}; |
||||
memberNode.SingleValue = collection; |
||||
} |
||||
} |
||||
return memberNode; |
||||
} |
||||
|
||||
public XamlProperty Property(string name) |
||||
{ |
||||
return Property(Type.Member(name)); |
||||
} |
||||
|
||||
public XamlProperty Property(DependencyProperty dp) |
||||
{ |
||||
return Property(dp.Name) ?? Property(dp.OwnerType, dp.Name); |
||||
} |
||||
|
||||
public XamlProperty Property(Type type, string name) |
||||
{ |
||||
return Property(ReflectionMapper.GetXamlType(type).Member(name)); |
||||
} |
||||
|
||||
public XamlProperty Property(XamlMember member) |
||||
{ |
||||
if (member == null) return null; |
||||
XamlProperty property; |
||||
if (!properties.TryGetValue(member, out property)) { |
||||
property = new XamlProperty(this, member); |
||||
properties[member] = property; |
||||
} |
||||
return property; |
||||
} |
||||
} |
||||
} |
@ -1 +0,0 @@
@@ -1 +0,0 @@
|
||||
|
@ -1,38 +0,0 @@
@@ -1,38 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Reflection; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class ReflectionAssembly : XamlAssembly |
||||
{ |
||||
internal ReflectionAssembly(Assembly assembly) |
||||
{ |
||||
Assembly = assembly; |
||||
} |
||||
|
||||
public Assembly Assembly; |
||||
|
||||
public override string Name |
||||
{ |
||||
get { return Assembly.GetName().Name; } |
||||
} |
||||
|
||||
public override IEnumerable<XmlnsDefinitionAttribute> XmlnsDefinitions |
||||
{ |
||||
get { return Assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), false) as XmlnsDefinitionAttribute[]; } |
||||
} |
||||
|
||||
public override XamlType GetType(string fullName) |
||||
{ |
||||
var type = Assembly.GetType(fullName); |
||||
if (type != null) { |
||||
return ReflectionMapper.GetXamlType(type); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -1,45 +0,0 @@
@@ -1,45 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Reflection; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public static class ReflectionMapper |
||||
{ |
||||
static Dictionary<object, XamlAssembly> assemblies = new Dictionary<object, XamlAssembly>(); |
||||
static Dictionary<object, XamlType> types = new Dictionary<object, XamlType>(); |
||||
static Dictionary<object, XamlMember> members = new Dictionary<object, XamlMember>(); |
||||
|
||||
public static XamlAssembly GetXamlAssembly(Assembly key) |
||||
{ |
||||
XamlAssembly result; |
||||
if (!assemblies.TryGetValue(key, out result)) { |
||||
result = new ReflectionAssembly(key); |
||||
assemblies[key] = result; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
public static XamlType GetXamlType(Type key) |
||||
{ |
||||
XamlType result; |
||||
if (!types.TryGetValue(key, out result)) { |
||||
result = new ReflectionType(key); |
||||
types[key] = result; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
public static XamlMember GetXamlMember(ReflectionMemberInfo key) |
||||
{ |
||||
XamlMember result; |
||||
if (!members.TryGetValue(key, out result)) { |
||||
result = new ReflectionMember(key); |
||||
members[key] = result; |
||||
} |
||||
return result; |
||||
} |
||||
} |
||||
} |
@ -1,87 +0,0 @@
@@ -1,87 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Reflection; |
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class ReflectionMember : XamlMember |
||||
{ |
||||
internal ReflectionMember(ReflectionMemberInfo info) |
||||
{ |
||||
this.info = info; |
||||
} |
||||
|
||||
ReflectionMemberInfo info; |
||||
|
||||
public ReflectionMemberInfo Info |
||||
{ |
||||
get { return info; } |
||||
} |
||||
|
||||
public override string Name |
||||
{ |
||||
get { return info.Name; } |
||||
} |
||||
|
||||
public override XamlType OwnerType |
||||
{ |
||||
get { return ReflectionMapper.GetXamlType(info.OwnerType); } |
||||
} |
||||
|
||||
public override XamlType ValueType |
||||
{ |
||||
get |
||||
{ |
||||
return ReflectionMapper.GetXamlType(info.ValueType); |
||||
} |
||||
} |
||||
|
||||
public override XamlType TargetType |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override AllowedLocation AllowedLocation |
||||
{ |
||||
get { return AllowedLocation.Any; } |
||||
} |
||||
|
||||
public override bool IsEvent |
||||
{ |
||||
get { return Info is ReflectionEventInfo; } |
||||
} |
||||
|
||||
public override bool IsDirective |
||||
{ |
||||
get { return false; } |
||||
} |
||||
|
||||
public override bool IsReadOnly |
||||
{ |
||||
get { return Info.IsReadOnly; } |
||||
} |
||||
|
||||
public override bool IsStatic |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsAttachable |
||||
{ |
||||
get { return Info is ReflectionAttachedPropertyInfo || Info is DependencyPropertyInfo; } |
||||
} |
||||
|
||||
public override T GetAttribute<T>() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override bool HasTextSyntax |
||||
{ |
||||
get { return Runtime.GetValueSerializer(this) != null; } |
||||
} |
||||
} |
||||
} |
@ -1,284 +0,0 @@
@@ -1,284 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Reflection; |
||||
using System.ComponentModel; |
||||
using System.Windows; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public abstract class ReflectionMemberInfo |
||||
{ |
||||
public abstract string Name { get; } |
||||
public abstract Type ValueType { get; } |
||||
public abstract Type OwnerType { get; } |
||||
public abstract object GetValue(object instance); |
||||
public abstract void SetValue(object instance, object value); |
||||
public abstract void ResetValue(object instance); |
||||
public abstract bool IsReadOnly { get; } |
||||
public abstract PropertyDescriptor PropertyDescriptor { get; } |
||||
protected abstract object EqualiltyCore { get; } |
||||
|
||||
public DependencyProperty DependencyProperty |
||||
{ |
||||
get |
||||
{ |
||||
var dpd = DependencyPropertyDescriptor.FromProperty(PropertyDescriptor); |
||||
if (dpd != null) { |
||||
return dpd.DependencyProperty; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
var other = obj as ReflectionMemberInfo; |
||||
if (other != null) { |
||||
return EqualiltyCore == other.EqualiltyCore; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return EqualiltyCore.GetHashCode(); |
||||
} |
||||
} |
||||
|
||||
class ReflectionPropertyInfo : ReflectionMemberInfo |
||||
{ |
||||
public ReflectionPropertyInfo(PropertyDescriptor pd) |
||||
{ |
||||
this.pd = pd; |
||||
} |
||||
|
||||
PropertyDescriptor pd; |
||||
|
||||
public override string Name |
||||
{ |
||||
get { return pd.Name; } |
||||
} |
||||
|
||||
public override Type ValueType |
||||
{ |
||||
get { return pd.PropertyType; } |
||||
} |
||||
|
||||
public override Type OwnerType |
||||
{ |
||||
get { return pd.ComponentType; } |
||||
} |
||||
|
||||
public override object GetValue(object instance) |
||||
{ |
||||
return pd.GetValue(instance); |
||||
} |
||||
|
||||
public override void SetValue(object instance, object value) |
||||
{ |
||||
pd.SetValue(instance, value); |
||||
} |
||||
|
||||
public override void ResetValue(object instance) |
||||
{ |
||||
if (pd.CanResetValue(instance)) { |
||||
pd.ResetValue(instance); |
||||
} |
||||
else { |
||||
pd.SetValue(instance, null); |
||||
} |
||||
} |
||||
|
||||
protected override object EqualiltyCore |
||||
{ |
||||
get { return pd; } |
||||
} |
||||
|
||||
public override bool IsReadOnly |
||||
{ |
||||
get { return pd.IsReadOnly; } |
||||
} |
||||
|
||||
public override PropertyDescriptor PropertyDescriptor |
||||
{ |
||||
get { return pd; } |
||||
} |
||||
} |
||||
|
||||
class ReflectionAttachedPropertyInfo : ReflectionMemberInfo |
||||
{ |
||||
public ReflectionAttachedPropertyInfo(MethodInfo getter, MethodInfo setter) |
||||
{ |
||||
this.getter = getter; |
||||
this.setter = setter; |
||||
} |
||||
|
||||
MethodInfo getter; |
||||
MethodInfo setter; |
||||
|
||||
public override string Name |
||||
{ |
||||
get { return setter.Name.Substring(3); } |
||||
} |
||||
|
||||
public override Type ValueType |
||||
{ |
||||
get { return setter.GetParameters()[1].ParameterType; } |
||||
} |
||||
|
||||
public override Type OwnerType |
||||
{ |
||||
get { return setter.DeclaringType; } |
||||
} |
||||
|
||||
public override object GetValue(object instance) |
||||
{ |
||||
if (getter != null) { |
||||
return getter.Invoke(instance, null); |
||||
} |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override void SetValue(object instance, object value) |
||||
{ |
||||
setter.Invoke(instance, new[] { instance, value }); |
||||
} |
||||
|
||||
public override void ResetValue(object instance) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
protected override object EqualiltyCore |
||||
{ |
||||
get { return setter; } |
||||
} |
||||
|
||||
public override bool IsReadOnly |
||||
{ |
||||
get { return false; } |
||||
} |
||||
|
||||
public override PropertyDescriptor PropertyDescriptor |
||||
{ |
||||
get { return null; } |
||||
} |
||||
} |
||||
|
||||
class DependencyPropertyInfo : ReflectionMemberInfo |
||||
{ |
||||
public DependencyPropertyInfo(DependencyProperty dp) |
||||
{ |
||||
this.dp = dp; |
||||
if (typeof(DependencyObject).IsAssignableFrom(dp.OwnerType)) { |
||||
this.dpd = DependencyPropertyDescriptor.FromProperty(dp, dp.OwnerType); |
||||
} |
||||
} |
||||
|
||||
DependencyProperty dp; |
||||
DependencyPropertyDescriptor dpd; |
||||
|
||||
public override string Name |
||||
{ |
||||
get { return dp.Name; } |
||||
} |
||||
|
||||
public override Type ValueType |
||||
{ |
||||
get { return dp.PropertyType; } |
||||
} |
||||
|
||||
public override Type OwnerType |
||||
{ |
||||
get { return dp.OwnerType; } |
||||
} |
||||
|
||||
public override object GetValue(object instance) |
||||
{ |
||||
var d = instance as DependencyObject; |
||||
return d.GetValue(dp); |
||||
} |
||||
|
||||
public override void SetValue(object instance, object value) |
||||
{ |
||||
var d = instance as DependencyObject; |
||||
d.SetValue(dp, value); |
||||
} |
||||
|
||||
public override void ResetValue(object instance) |
||||
{ |
||||
var d = instance as DependencyObject; |
||||
d.ClearValue(dp); |
||||
} |
||||
|
||||
protected override object EqualiltyCore |
||||
{ |
||||
get { return dp; } |
||||
} |
||||
|
||||
public override bool IsReadOnly |
||||
{ |
||||
get { return dp.ReadOnly; } |
||||
} |
||||
|
||||
public override PropertyDescriptor PropertyDescriptor |
||||
{ |
||||
get { return dpd; } |
||||
} |
||||
} |
||||
|
||||
class ReflectionEventInfo : ReflectionMemberInfo |
||||
{ |
||||
public ReflectionEventInfo(EventInfo eventInfo) |
||||
{ |
||||
this.eventInfo = eventInfo; |
||||
} |
||||
|
||||
EventInfo eventInfo; |
||||
|
||||
public override string Name |
||||
{ |
||||
get { return eventInfo.Name; } |
||||
} |
||||
|
||||
public override Type ValueType |
||||
{ |
||||
get { return eventInfo.EventHandlerType; } |
||||
} |
||||
|
||||
public override Type OwnerType |
||||
{ |
||||
get { return eventInfo.DeclaringType; } |
||||
} |
||||
|
||||
public override object GetValue(object instance) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override void SetValue(object instance, object value) |
||||
{ |
||||
} |
||||
|
||||
public override void ResetValue(object instance) |
||||
{ |
||||
} |
||||
|
||||
protected override object EqualiltyCore |
||||
{ |
||||
get { return eventInfo; } |
||||
} |
||||
|
||||
public override bool IsReadOnly |
||||
{ |
||||
get { return false; } |
||||
} |
||||
|
||||
public override PropertyDescriptor PropertyDescriptor |
||||
{ |
||||
get { return null; } |
||||
} |
||||
} |
||||
} |
@ -1,265 +0,0 @@
@@ -1,265 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows.Markup; |
||||
using System.Reflection; |
||||
using System.Collections; |
||||
using System.ComponentModel; |
||||
using System.Windows; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class ReflectionType : XamlType |
||||
{ |
||||
internal ReflectionType(Type type) |
||||
{ |
||||
this.type = type; |
||||
this.propertyDescriptors = TypeDescriptor.GetProperties(type); |
||||
} |
||||
|
||||
Type type; |
||||
PropertyDescriptorCollection propertyDescriptors; |
||||
|
||||
public Type Type |
||||
{ |
||||
get { return type; } |
||||
} |
||||
|
||||
public override string Name |
||||
{ |
||||
get { return type.Name; } |
||||
} |
||||
|
||||
public override bool IsDefaultConstructible |
||||
{ |
||||
get { return type.GetConstructor(Type.EmptyTypes) != null; } |
||||
} |
||||
|
||||
public override bool IsNullable |
||||
{ |
||||
get { return !type.IsValueType; } |
||||
} |
||||
|
||||
public override IEnumerable<XamlMember> Members |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember ContentProperty |
||||
{ |
||||
get |
||||
{ |
||||
foreach (ContentPropertyAttribute a in type.GetCustomAttributes(typeof(ContentPropertyAttribute), true)) { |
||||
return Member(a.Name); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public override XamlMember DictionaryKeyProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override XamlMember NameProperty |
||||
{ |
||||
get |
||||
{ |
||||
foreach (RuntimeNamePropertyAttribute a in type.GetCustomAttributes(typeof(RuntimeNamePropertyAttribute), true)) { |
||||
return Member(a.Name); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public override XamlMember XmlLangProperty |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool TrimSurroundingWhitespace |
||||
{ |
||||
get |
||||
{ |
||||
foreach (var a in type.GetCustomAttributes(typeof(TrimSurroundingWhitespaceAttribute), true)) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public override bool IsWhitespaceSignificantCollection |
||||
{ |
||||
get |
||||
{ |
||||
foreach (var a in type.GetCustomAttributes(typeof(WhitespaceSignificantCollectionAttribute), true)) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public override bool IsCollection |
||||
{ |
||||
get { return typeof(ICollection).IsAssignableFrom(type); } |
||||
} |
||||
|
||||
public override bool IsDictionary |
||||
{ |
||||
get { return typeof(IDictionary).IsAssignableFrom(type); } |
||||
} |
||||
|
||||
public override IEnumerable<XamlType> AllowedTypes |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<XamlType> AllowedKeyTypes |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsXData |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override bool IsNameScope |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override IEnumerable<Constructor> Constructors |
||||
{ |
||||
get |
||||
{ |
||||
Dictionary<int, Constructor> ctors = new Dictionary<int, Constructor>(); |
||||
foreach (var ctorInfo in type.GetConstructors()) { |
||||
var parameters = ctorInfo.GetParameters(); |
||||
if (parameters.Length > 0 && !ctors.ContainsKey(parameters.Length)) { |
||||
var ctor = new Constructor(); |
||||
ctor.Arguments = parameters |
||||
.Select(p => ReflectionMapper.GetXamlType(p.ParameterType)).ToArray(); |
||||
|
||||
List<XamlMember> members = new List<XamlMember>(); |
||||
foreach (var p in parameters) { |
||||
var member = MemberCaseInsensetive(p.Name); |
||||
if (member == null) { |
||||
members = null; |
||||
break; |
||||
} |
||||
members.Add(member); |
||||
} |
||||
if (members != null) { |
||||
ctor.CorrespondingMembers = members.ToArray(); |
||||
} |
||||
|
||||
ctors[parameters.Length] = ctor; |
||||
} |
||||
} |
||||
return ctors.Values; |
||||
} |
||||
} |
||||
|
||||
public override XamlType ReturnValueType |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public override string Namespace |
||||
{ |
||||
get { return type.Namespace; } |
||||
} |
||||
|
||||
public override XamlAssembly Assembly |
||||
{ |
||||
get { return ReflectionMapper.GetXamlAssembly(type.Assembly); } |
||||
} |
||||
|
||||
public override XamlMember Member(string name) |
||||
{ |
||||
ReflectionMemberInfo info = null; |
||||
|
||||
var pd = propertyDescriptors[name]; |
||||
if (pd != null) { |
||||
info = new ReflectionPropertyInfo(pd); |
||||
} |
||||
else { |
||||
var eventInfo = type.GetEvent(name, BindingFlags.Public | BindingFlags.Instance); |
||||
if (eventInfo != null) { |
||||
info = new ReflectionEventInfo(eventInfo); |
||||
} |
||||
else { |
||||
// attached dp better than getter/setter cause we have DependencyObject.ClearValue(dp)
|
||||
var field = type.GetField(name + "Property", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); |
||||
if (field != null) { |
||||
var dp = (DependencyProperty)field.GetValue(null); |
||||
if (dp != null) { |
||||
info = new DependencyPropertyInfo(dp); |
||||
} |
||||
} |
||||
if (info == null) { |
||||
var getter = type.GetMethod("Get" + name, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); |
||||
var setter = type.GetMethod("Set" + name, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); |
||||
if (setter != null) { |
||||
info = new ReflectionAttachedPropertyInfo(getter, setter); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (info != null) { |
||||
return ReflectionMapper.GetXamlMember(info); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
XamlMember MemberCaseInsensetive(string name) |
||||
{ |
||||
foreach (PropertyDescriptor pd in propertyDescriptors) { |
||||
if (pd.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)) { |
||||
return ReflectionMapper.GetXamlMember(new ReflectionPropertyInfo(pd)); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public override IEnumerable<XamlType> ContentWrappers |
||||
{ |
||||
get |
||||
{ |
||||
foreach (ContentWrapperAttribute a in type.GetCustomAttributes(typeof(ContentWrapperAttribute), true)) { |
||||
yield return ReflectionMapper.GetXamlType(a.ContentWrapper); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public override bool IsAssignableFrom(XamlType other) |
||||
{ |
||||
var r = other as ReflectionType; |
||||
if (r != null) { |
||||
return type.IsAssignableFrom(r.Type); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public override bool HasTextSyntax |
||||
{ |
||||
get { return Runtime.GetValueSerializer(this) != null; } |
||||
} |
||||
|
||||
public override Type SystemType |
||||
{ |
||||
get { return type; } |
||||
} |
||||
|
||||
public override T GetAttribute<T>() |
||||
{ |
||||
var usageAttribute = (AttributeUsageAttribute)typeof(T).GetCustomAttributes(typeof(AttributeUsageAttribute), true)[0]; |
||||
foreach (T attr in type.GetCustomAttributes(typeof(T), usageAttribute.Inherited)) { |
||||
return attr; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -1,236 +0,0 @@
@@ -1,236 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Collections; |
||||
using System.ComponentModel; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public static class Runtime |
||||
{ |
||||
public static object UnsetValue = new object(); |
||||
|
||||
static Dictionary<Type, Type> typeReplacers = new Dictionary<Type, Type>(); |
||||
|
||||
public static void AddTypeReplacer(Type type, Type replacer) |
||||
{ |
||||
lock (typeReplacers) { |
||||
typeReplacers[type] = replacer; |
||||
} |
||||
} |
||||
|
||||
public static Type GetTypeReplacer(Type type) |
||||
{ |
||||
Type replacer; |
||||
lock (typeReplacers) { |
||||
typeReplacers.TryGetValue(type, out replacer); |
||||
return replacer; |
||||
} |
||||
} |
||||
|
||||
public static object CreateInstance(XamlType type, object[] args) |
||||
{ |
||||
if (type.SystemType != null) { |
||||
var finalType = GetTypeReplacer(type.SystemType) ?? type.SystemType; |
||||
return Activator.CreateInstance(finalType, args); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static object GetValue(MemberNode memberNode) |
||||
{ |
||||
return GetValue(memberNode.ParentObject.Instance, memberNode.Member); |
||||
} |
||||
|
||||
public static void SetValue(MemberNode memberNode, object value) |
||||
{ |
||||
SetValue(memberNode.ParentObject.Instance, memberNode.Member, value); |
||||
} |
||||
|
||||
public static void ResetValue(MemberNode memberNode) |
||||
{ |
||||
ResetValue(memberNode.ParentObject.Instance, memberNode.Member); |
||||
} |
||||
|
||||
public static object GetValue(object instance, XamlMember member) |
||||
{ |
||||
var info = GetFinalMemberInfo(instance, member); |
||||
if (info != null) { |
||||
return info.GetValue(instance); |
||||
} |
||||
return Runtime.UnsetValue; |
||||
} |
||||
|
||||
public static void SetValue(object instance, XamlMember member, object value) |
||||
{ |
||||
var info = GetFinalMemberInfo(instance, member); |
||||
if (info != null) { |
||||
info.SetValue(instance, value); |
||||
} |
||||
} |
||||
|
||||
public static void ResetValue(object instance, XamlMember member) |
||||
{ |
||||
var info = GetFinalMemberInfo(instance, member); |
||||
if (info != null) { |
||||
info.ResetValue(instance); |
||||
} |
||||
} |
||||
|
||||
static ReflectionMemberInfo GetFinalMemberInfo(object instance, XamlMember member) |
||||
{ |
||||
var result = member as ReflectionMember; |
||||
if (result != null) { |
||||
if (!result.IsAttachable) { |
||||
var designTimeType = instance.GetType(); |
||||
var ownerType = member.OwnerType.SystemType; |
||||
|
||||
if (!ownerType.IsAssignableFrom(designTimeType)) { |
||||
result = ReflectionMapper.GetXamlType(designTimeType) |
||||
.Member(member.Name) as ReflectionMember; |
||||
} |
||||
} |
||||
return result.Info; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static void Add(object collection, object item) |
||||
{ |
||||
IList list = collection as IList; |
||||
list.Add(item); |
||||
} |
||||
|
||||
public static void Add(object collection, object key, object item) |
||||
{ |
||||
IDictionary dict = collection as IDictionary; |
||||
dict.Add(key, item); |
||||
} |
||||
|
||||
public static void Insert(object collection, int index, object item) |
||||
{ |
||||
IList list = collection as IList; |
||||
list.Insert(index, item); |
||||
} |
||||
|
||||
public static void Remove(object collection, object item) |
||||
{ |
||||
IList list = collection as IList; |
||||
if (list != null) { |
||||
list.Remove(item); |
||||
} |
||||
else { |
||||
IDictionary dict = collection as IDictionary; |
||||
object key = null; |
||||
foreach (DictionaryEntry pair in dict) { |
||||
if (pair.Value == item) { |
||||
key = pair.Key; |
||||
break; |
||||
} |
||||
} |
||||
dict.Remove(key); |
||||
} |
||||
} |
||||
|
||||
public static bool TryConvertToText(XamlContext context, object value, out string text) |
||||
{ |
||||
text = null; |
||||
if (value != null) { |
||||
text = ConvertToText(context, value); |
||||
} |
||||
return text != null; |
||||
} |
||||
|
||||
public static string ConvertToText(XamlContext context, object value) |
||||
{ |
||||
var text = StandardValues.GetStandardValueText(value); |
||||
if (text != null) { |
||||
return text; |
||||
} |
||||
var targetType = context.XamlProperty.ValueType.SystemType; |
||||
if (targetType != null) { |
||||
TryConvert(ref value, targetType); |
||||
} |
||||
var valueSerializer = GetValueSerializer(context); |
||||
if (valueSerializer != null && valueSerializer.CanConvertToString(value, context)) { |
||||
return valueSerializer.ConvertToString(value, context); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
static void TryConvert(ref object value, Type targetType) |
||||
{ |
||||
if (!targetType.IsAssignableFrom(value.GetType())) { |
||||
if (value is IConvertible && typeof(IConvertible).IsAssignableFrom(targetType)) { |
||||
value = Convert.ChangeType(value, targetType); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static object ConvertFromText(XamlContext context, string text) |
||||
{ |
||||
var valueSerializer = GetValueSerializer(context); |
||||
if (valueSerializer != null && valueSerializer.CanConvertFromString(text, context)) { |
||||
return valueSerializer.ConvertFromString(text, context); |
||||
} |
||||
return text; |
||||
} |
||||
|
||||
public static object ConvertFromText(XamlContext context, XamlType targetType, string text) |
||||
{ |
||||
var valueSerializer = GetValueSerializer(targetType); |
||||
if (valueSerializer != null && valueSerializer.CanConvertFromString(text, context)) { |
||||
return valueSerializer.ConvertFromString(text, context); |
||||
} |
||||
return text; |
||||
} |
||||
|
||||
public static ValueSerializer GetValueSerializer(XamlContext context) |
||||
{ |
||||
var valueSerializer = GetValueSerializer(context.XamlProperty.Member); |
||||
if (valueSerializer == null) { |
||||
valueSerializer = GetValueSerializer(context.XamlProperty.ValueType); |
||||
} |
||||
return valueSerializer; |
||||
} |
||||
|
||||
public static ValueSerializer GetValueSerializer(XamlType type) |
||||
{ |
||||
if (type.SystemType != null) { |
||||
return ValueSerializer.GetSerializerFor(type.SystemType); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static ValueSerializer GetValueSerializer(XamlMember member) |
||||
{ |
||||
var reflectionMember = member as ReflectionMember; |
||||
if (reflectionMember != null && reflectionMember.Info.PropertyDescriptor != null) { |
||||
return ValueSerializer.GetSerializerFor(reflectionMember.Info.PropertyDescriptor); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static XamlType GetWrapperTypeForInitializationText(object value) |
||||
{ |
||||
var type = value.GetType(); |
||||
Type prev = null; |
||||
|
||||
while (true) { |
||||
if (type == null || ValueSerializer.GetSerializerFor(type) == null) { |
||||
break; |
||||
} |
||||
prev = type; |
||||
type = type.BaseType; |
||||
} |
||||
|
||||
if (prev != null) { |
||||
return ReflectionMapper.GetXamlType(prev); |
||||
} |
||||
|
||||
throw new XamlException("ValueSerializer not found"); |
||||
} |
||||
} |
||||
} |
@ -1,135 +0,0 @@
@@ -1,135 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Collections; |
||||
using System.Reflection; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using System.Windows; |
||||
using System.Windows.Documents; |
||||
using System.ComponentModel; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public static class StandardValues |
||||
{ |
||||
static Dictionary<Type, List<StandardValue>> standardValues = new Dictionary<Type, List<StandardValue>>(); |
||||
static Dictionary<object, StandardValue> standardValueFromInstance = new Dictionary<object, StandardValue>(); |
||||
|
||||
public static void AddStandardValues(Type type, Type valuesContainer) |
||||
{ |
||||
AddStandardValues(type, valuesContainer |
||||
.GetProperties(BindingFlags.Public | BindingFlags.Static) |
||||
.Select(p => new StandardValue() { |
||||
Instance = p.GetValue(null, null), |
||||
Text = p.Name |
||||
})); |
||||
} |
||||
|
||||
public static void AddStandardValue(Type type, string text, object value) |
||||
{ |
||||
AddStandardValues(type, new[] { new StandardValue() { Text = text, Instance = value } }); |
||||
} |
||||
|
||||
public static void AddStandardValues(Type type, IEnumerable<StandardValue> values) |
||||
{ |
||||
List<StandardValue> list; |
||||
lock (standardValues) { |
||||
lock (standardValueFromInstance) { |
||||
if (!standardValues.TryGetValue(type, out list)) { |
||||
list = new List<StandardValue>(); |
||||
standardValues[type] = list; |
||||
} |
||||
foreach (var v in values) { |
||||
list.Add(v); |
||||
standardValueFromInstance[v.Instance] = v; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static IEnumerable<StandardValue> GetStandardValues(Type type) |
||||
{ |
||||
if (type.IsEnum) { |
||||
var enumValues = Enum.GetValues(type); |
||||
var enumNames = Enum.GetNames(type); |
||||
|
||||
for (int i = 0; i < enumValues.Length; i++) { |
||||
yield return new StandardValue() { |
||||
Instance = enumValues.GetValue(i), |
||||
Text = enumNames[i], |
||||
}; |
||||
} |
||||
} |
||||
List<StandardValue> values; |
||||
lock (standardValues) { |
||||
if (standardValues.TryGetValue(type, out values)) { |
||||
foreach (var value in values) { |
||||
if (value.Text == null) { |
||||
if (Runtime.TryConvertToText(null, value.Instance, out value.Text)) { |
||||
yield return value; |
||||
} |
||||
} |
||||
else { |
||||
yield return value; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
var converter = TypeDescriptor.GetConverter(type); |
||||
if (converter.GetStandardValuesSupported()) { |
||||
foreach (var value in converter.GetStandardValues()) { |
||||
string text; |
||||
if (Runtime.TryConvertToText(null, value, out text)) { |
||||
yield return new StandardValue() { |
||||
Instance = value, |
||||
Text = text |
||||
}; |
||||
} |
||||
} |
||||
} |
||||
yield break; |
||||
} |
||||
|
||||
public static string GetStandardValueText(object value) |
||||
{ |
||||
lock (standardValueFromInstance) { |
||||
StandardValue standardValue; |
||||
if (standardValueFromInstance.TryGetValue(value, out standardValue)) { |
||||
return standardValue.Text; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
//static Dictionary<Type, Type> designTimeTypes = new Dictionary<Type, Type>();
|
||||
|
||||
//public static void AddDesignTimeType(Type type, Type designTimeType)
|
||||
//{
|
||||
// lock (designTimeTypes)
|
||||
// {
|
||||
// designTimeTypes[type] = designTimeType;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public static Type GetDesignTimeType(Type type)
|
||||
//{
|
||||
// lock (designTimeTypes)
|
||||
// {
|
||||
// Type result;
|
||||
// if (designTimeTypes.TryGetValue(type, out result))
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
// return type;
|
||||
//}
|
||||
} |
||||
|
||||
public class StandardValue |
||||
{ |
||||
public object Instance; |
||||
public string Text; |
||||
} |
||||
} |
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class TextNode : XamlValue |
||||
{ |
||||
internal TextNode() |
||||
{ |
||||
} |
||||
|
||||
public string Text; |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return GetType().Name + ": " + Text; |
||||
} |
||||
|
||||
public override IEnumerable<XamlNode> Nodes() |
||||
{ |
||||
yield break; |
||||
} |
||||
|
||||
protected override void RemoveChild(XamlNode node) |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -1,66 +0,0 @@
@@ -1,66 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class Tracker |
||||
{ |
||||
public virtual void Process(DocumentChangedEventArgs e) |
||||
{ |
||||
Remove(e.OldNode, e.OldParent); |
||||
Add(e.NewNode); |
||||
} |
||||
|
||||
public virtual void Add(XamlNode node) |
||||
{ |
||||
if (node is MemberNode) { |
||||
Add(node as MemberNode); |
||||
} |
||||
else if (node is ObjectNode) { |
||||
Add(node as ObjectNode); |
||||
} |
||||
else if (node is TextNode) { |
||||
Add(node as TextNode); |
||||
} |
||||
} |
||||
|
||||
public virtual void Add(MemberNode node) |
||||
{ |
||||
} |
||||
|
||||
public virtual void Add(ObjectNode node) |
||||
{ |
||||
} |
||||
|
||||
public virtual void Add(TextNode node) |
||||
{ |
||||
} |
||||
|
||||
public virtual void Remove(XamlNode node, XamlNode parent) |
||||
{ |
||||
if (node is MemberNode) { |
||||
Remove(node as MemberNode, parent as ObjectNode); |
||||
} |
||||
else if (node is ObjectNode) { |
||||
Remove(node as ObjectNode, parent as MemberNode); |
||||
} |
||||
else if (node is TextNode) { |
||||
Remove(node as TextNode, parent as MemberNode); |
||||
} |
||||
} |
||||
|
||||
public virtual void Remove(MemberNode node, ObjectNode parent) |
||||
{ |
||||
} |
||||
|
||||
public virtual void Remove(ObjectNode node, MemberNode parent) |
||||
{ |
||||
} |
||||
|
||||
public virtual void Remove(TextNode node, MemberNode parent) |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -1,11 +0,0 @@
@@ -1,11 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Xaml |
||||
{ |
||||
class XamlValueCollection |
||||
{ |
||||
} |
||||
} |
@ -1,14 +0,0 @@
@@ -1,14 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using ICSharpCode.Xaml; |
||||
using System.Windows; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class WpfTracker : Tracker |
||||
{ |
||||
} |
||||
} |
@ -1,118 +0,0 @@
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProductVersion>9.0.30729</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{B4E5C965-7BB9-4AE9-85FB-C47480B879AD}</ProjectGuid> |
||||
<OutputType>Library</OutputType> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
<RootNamespace>ICSharpCode.Xaml</RootNamespace> |
||||
<AssemblyName>ICSharpCode.Xaml</AssemblyName> |
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> |
||||
<FileAlignment>512</FileAlignment> |
||||
<OutputPath>..\..\..\..\..\AddIns\AddIns\BackendBindings\XamlBinding\</OutputPath> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugType>none</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="PresentationCore"> |
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="PresentationFramework"> |
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Xml.Linq"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Data.DataSetExtensions"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="WindowsBase"> |
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs"> |
||||
<Link>Properties\GlobalAssemblyInfo.cs</Link> |
||||
</Compile> |
||||
<Compile Include="AllowedLocation.cs" /> |
||||
<Compile Include="CollectionSupport.cs" /> |
||||
<Compile Include="Constructor.cs" /> |
||||
<Compile Include="DefaultXamlMember.cs" /> |
||||
<Compile Include="DefaultXamlType.cs" /> |
||||
<Compile Include="Directive.cs" /> |
||||
<Compile Include="InstanceTracker.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="Runtime.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="StandardValues.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="Tracker.cs" /> |
||||
<Compile Include="ExtensionMethods.cs" /> |
||||
<Compile Include="IHasAnnotations.cs" /> |
||||
<Compile Include="IntristicMember.cs" /> |
||||
<Compile Include="IntristicType.cs" /> |
||||
<Compile Include="MarkupExtensionParser.cs" /> |
||||
<Compile Include="MemberNode.cs" /> |
||||
<Compile Include="NodeCollection.cs" /> |
||||
<Compile Include="ObjectNode.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
<Compile Include="ReflectionAssembly.cs" /> |
||||
<Compile Include="ReflectionMember.cs" /> |
||||
<Compile Include="ReflectionMemberInfo.cs" /> |
||||
<Compile Include="ReflectionMapper.cs" /> |
||||
<Compile Include="ReflectionType.cs" /> |
||||
<Compile Include="XamlContext.cs" /> |
||||
<Compile Include="TextNode.cs" /> |
||||
<Compile Include="XamlFormatter.cs" /> |
||||
<Compile Include="XamlProject.cs" /> |
||||
<Compile Include="XamlAssembly.cs" /> |
||||
<Compile Include="XamlConstants.cs" /> |
||||
<Compile Include="XamlDocument.cs" /> |
||||
<Compile Include="XamlDocumentError.cs" /> |
||||
<Compile Include="XamlException.cs" /> |
||||
<Compile Include="XamlMember.cs" /> |
||||
<Compile Include="XamlNode.cs" /> |
||||
<Compile Include="XamlParser.cs" /> |
||||
<Compile Include="XamlProperty.cs" /> |
||||
<Compile Include="XamlType.cs" /> |
||||
<Compile Include="XamlTypeFinder.cs" /> |
||||
<Compile Include="XamlValue.cs" /> |
||||
<Compile Include="XmlnsDefinition.cs" /> |
||||
<Compile Include="XmlTracker.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||
Other similar extension points exist, see Microsoft.Common.targets. |
||||
<Target Name="BeforeBuild"> |
||||
</Target> |
||||
<Target Name="AfterBuild"> |
||||
</Target> |
||||
--> |
||||
</Project> |
@ -1,18 +0,0 @@
@@ -1,18 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows.Markup; |
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
[DebuggerDisplay("{Name}")] |
||||
public abstract class XamlAssembly |
||||
{ |
||||
//public abstract XamlType[] Types;
|
||||
public abstract IEnumerable<XmlnsDefinitionAttribute> XmlnsDefinitions { get; } |
||||
public abstract string Name { get; } |
||||
public abstract XamlType GetType(string fullName); |
||||
} |
||||
} |
@ -1,30 +0,0 @@
@@ -1,30 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml.Linq; |
||||
using System.Reflection; |
||||
using System.Windows; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class XamlConstants |
||||
{ |
||||
public static XNamespace XamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml"; |
||||
public static XNamespace Presentation2006Namespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"; |
||||
public static XNamespace Presentation2007Namespace = "http://schemas.microsoft.com/netfx/2007/xaml/presentation"; |
||||
|
||||
public static Assembly MscorlibAssembly = typeof(object).Assembly; |
||||
public static Assembly WindowsBaseAssembly = typeof(DependencyObject).Assembly; |
||||
public static Assembly PresentationCoreAssembly = typeof(UIElement).Assembly; |
||||
public static Assembly PresentationFrameworkAssembly = typeof(FrameworkElement).Assembly; |
||||
|
||||
public static XName XmlSpaceName = XNamespace.Xml.GetName("space"); |
||||
|
||||
public static bool HasXamlExtension(string filePath) |
||||
{ |
||||
return Path.GetExtension(filePath).Equals(".xaml", StringComparison.InvariantCultureIgnoreCase); |
||||
} |
||||
} |
||||
} |
@ -1,130 +0,0 @@
@@ -1,130 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.ComponentModel; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class XamlContext : IServiceProvider, ITypeDescriptorContext, IXamlTypeResolver, IUriContext, IProvideValueTarget, IValueSerializerContext |
||||
{ |
||||
internal XamlContext(XamlProperty property) |
||||
{ |
||||
this.property = property; |
||||
} |
||||
|
||||
XamlProperty property; |
||||
|
||||
public XamlProperty XamlProperty |
||||
{ |
||||
get { return property; } |
||||
} |
||||
|
||||
#region IServiceProvider Members
|
||||
|
||||
public object GetService(Type serviceType) |
||||
{ |
||||
if (serviceType == typeof(ITypeDescriptorContext)) return this; |
||||
if (serviceType == typeof(IXamlTypeResolver)) return this; |
||||
if (serviceType == typeof(IUriContext)) return this; |
||||
if (serviceType == typeof(IProvideValueTarget)) return this; |
||||
if (serviceType == typeof(IValueSerializerContext)) return this; |
||||
return null; |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region ITypeDescriptorContext Members
|
||||
|
||||
public IContainer Container |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public object Instance |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public void OnComponentChanged() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool OnComponentChanging() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public PropertyDescriptor PropertyDescriptor |
||||
{ |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IXamlTypeResolver Members
|
||||
|
||||
public Type Resolve(string qualifiedTypeName) |
||||
{ |
||||
var namespaceProvider = XmlTracker.GetNamespaceProvider(property.Object); |
||||
var typeName = XamlParser.GetTypeName(qualifiedTypeName, namespaceProvider); |
||||
var type = property.Object.Document.Project.TypeFinder.FindType(typeName); |
||||
return type.SystemType; |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IUriContext Members
|
||||
|
||||
public Uri BaseUri |
||||
{ |
||||
get |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
set |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IProvideValueTarget Members
|
||||
|
||||
public object TargetObject |
||||
{ |
||||
get { return property.Object.Instance; } |
||||
} |
||||
|
||||
public object TargetProperty |
||||
{ |
||||
get |
||||
{ |
||||
var reflectionMember = property.Member as ReflectionMember; |
||||
if (reflectionMember != null) { |
||||
return reflectionMember.Info.DependencyProperty; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IValueSerializerContext Members
|
||||
|
||||
public ValueSerializer GetValueSerializerFor(PropertyDescriptor descriptor) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public ValueSerializer GetValueSerializerFor(Type type) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -1,153 +0,0 @@
@@ -1,153 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml; |
||||
using System.Xml.Linq; |
||||
using System.Diagnostics; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class XamlDocument : IUriContext |
||||
{ |
||||
internal XamlDocument(XamlProject project) |
||||
{ |
||||
Project = project; |
||||
Parser = new XamlParser(this); |
||||
Trackers.Add(new InstanceTracker()); |
||||
Trackers.Add(new XmlTracker()); |
||||
} |
||||
|
||||
public XamlParser Parser { get; private set; } |
||||
public XamlProject Project { get; private set; } |
||||
public List<XamlDocument> Dependencies = new List<XamlDocument>(); |
||||
public List<XamlDocumentError> Errors = new List<XamlDocumentError>(); |
||||
public List<Tracker> Trackers = new List<Tracker>(); |
||||
public XDocument XmlDocument; |
||||
|
||||
public event EventHandler RootChanged; |
||||
public event DocumentChangedEventHandler DocumentChanged; |
||||
|
||||
bool parsing; |
||||
|
||||
ObjectNode root; |
||||
|
||||
public ObjectNode Root |
||||
{ |
||||
get |
||||
{ |
||||
return root; |
||||
} |
||||
set |
||||
{ |
||||
var e = new DocumentChangedEventArgs() { OldNode = root, NewNode = value }; |
||||
root = value; |
||||
RaiseDocumentChanged(e); |
||||
|
||||
if (RootChanged != null) { |
||||
RootChanged(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public ObjectNode ParseObject(string text) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ObjectNode CreateObject(object instance) |
||||
{ |
||||
return new ObjectNode(this, instance); |
||||
} |
||||
|
||||
public void Parse(string text) |
||||
{ |
||||
ObjectNode result = null; |
||||
Errors.Clear(); |
||||
parsing = true; |
||||
|
||||
try { |
||||
XmlDocument = XDocument.Parse(text); |
||||
result = Parser.CreateObjectNodeFromXmlElement(XmlDocument.Root, false); |
||||
foreach (var node in result.DescendantsAndSelf()) { |
||||
node.Document = this; |
||||
} |
||||
} |
||||
catch (Exception x) { |
||||
Errors.Add(new XamlDocumentError { Message = x.ToString() }); |
||||
} |
||||
|
||||
parsing = false; |
||||
Root = result; |
||||
} |
||||
|
||||
public bool CanSave |
||||
{ |
||||
get { return XmlDocument != null; } |
||||
} |
||||
|
||||
public string Save() |
||||
{ |
||||
//return XamlFormatter.Format(XmlDocument.ToString());
|
||||
|
||||
var settings = new XmlWriterSettings() { |
||||
Indent = true, |
||||
IndentChars = " ", |
||||
NewLineOnAttributes = true, |
||||
OmitXmlDeclaration = true |
||||
}; |
||||
var sb = new StringBuilder(); |
||||
using (var writer = XmlWriter.Create(sb, settings)) { |
||||
XmlDocument.WriteTo(writer); |
||||
} |
||||
|
||||
return sb.ToString(); |
||||
} |
||||
|
||||
internal void RaiseDocumentChanged(DocumentChangedEventArgs e) |
||||
{ |
||||
if (!parsing) { |
||||
foreach (var t in Trackers) { |
||||
t.Process(e); |
||||
} |
||||
if (DocumentChanged != null) { |
||||
DocumentChanged(this, e); |
||||
} |
||||
} |
||||
} |
||||
|
||||
#region IUriContext Members
|
||||
|
||||
Uri baseUri; |
||||
|
||||
public Uri BaseUri |
||||
{ |
||||
get |
||||
{ |
||||
return baseUri; |
||||
} |
||||
set |
||||
{ |
||||
if (baseUri != null) { |
||||
Project.Documents.Remove(baseUri); |
||||
} |
||||
baseUri = value; |
||||
if (baseUri != null) { |
||||
Project.Documents[baseUri] = this; |
||||
} |
||||
} |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
|
||||
public delegate void DocumentChangedEventHandler(object sender, DocumentChangedEventArgs e); |
||||
|
||||
public class DocumentChangedEventArgs : EventArgs |
||||
{ |
||||
public XamlNode OldNode; |
||||
public XamlNode OldParent; |
||||
public XamlNode NewNode; |
||||
} |
||||
} |
@ -1,15 +0,0 @@
@@ -1,15 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class XamlDocumentError |
||||
{ |
||||
public string Message { get; set; } |
||||
public int LineNumber { get; set; } |
||||
public int LinePosition { get; set; } |
||||
public XamlDocument Document { get; set; } |
||||
} |
||||
} |
@ -1,35 +0,0 @@
@@ -1,35 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Runtime.Serialization; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
[Serializable] |
||||
public class XamlException : Exception |
||||
{ |
||||
public XamlException() |
||||
{ |
||||
} |
||||
|
||||
public XamlException(string message) |
||||
: base(message) |
||||
{ |
||||
} |
||||
|
||||
public XamlException(string message, Exception innerException) |
||||
: base(message, innerException) |
||||
{ |
||||
} |
||||
|
||||
protected XamlException(SerializationInfo info, StreamingContext context) |
||||
: base(info, context) |
||||
{ |
||||
} |
||||
|
||||
public int LineNumber { get; set; } |
||||
public int LinePosition { get; set; } |
||||
public Uri BaseUri { get; set; } |
||||
} |
||||
} |
@ -1,210 +0,0 @@
@@ -1,210 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml.Linq; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
//TODO: formatter should be based on XamlDocument
|
||||
public static class XamlFormatter |
||||
{ |
||||
public static char IndentChar = ' '; |
||||
public static int Indenation = 2; |
||||
public static int LengthBeforeNewLine = 60; |
||||
|
||||
static StringBuilder sb; |
||||
static int currentColumn; |
||||
static int nextColumn; |
||||
|
||||
public static string Format(string xaml) |
||||
{ |
||||
sb = new StringBuilder(); |
||||
currentColumn = 0; |
||||
nextColumn = 0; |
||||
|
||||
try { |
||||
var doc = XDocument.Parse(xaml); |
||||
WalkContainer(doc); |
||||
return sb.ToString(); |
||||
} |
||||
catch { |
||||
return xaml; |
||||
} |
||||
} |
||||
|
||||
static void WalkContainer(XContainer node) |
||||
{ |
||||
foreach (var c in node.Nodes()) { |
||||
if (c is XElement) { |
||||
WalkElement(c as XElement); |
||||
} |
||||
else { |
||||
NewLine(); |
||||
Append(c.ToString().Trim()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void WalkElement(XElement e) |
||||
{ |
||||
NewLine(); |
||||
string prefix1 = e.GetPrefixOfNamespace(e.Name.Namespace); |
||||
string name1 = prefix1 == null ? e.Name.LocalName : prefix1 + ":" + e.Name.LocalName; |
||||
Append("<" + name1); |
||||
|
||||
List<AttributeString> list = new List<AttributeString>(); |
||||
int length = name1.Length; |
||||
|
||||
foreach (var a in e.Attributes()) { |
||||
string prefix2 = e.GetPrefixOfNamespace(a.Name.Namespace); |
||||
var g = new AttributeString() { Name = a.Name, Prefix = prefix2, Value = a.Value }; |
||||
list.Add(g); |
||||
length += g.FinalString.Length; |
||||
} |
||||
|
||||
list.Sort(AttributeComparrer.Instance); |
||||
|
||||
if (length > LengthBeforeNewLine) { |
||||
nextColumn = currentColumn + 1; |
||||
for (int i = 0; i < list.Count; i++) { |
||||
if (i > 0) { |
||||
NewLine(); |
||||
} |
||||
else { |
||||
Append(" "); |
||||
} |
||||
Append(list[i].FinalString); |
||||
} |
||||
nextColumn -= name1.Length + 2; |
||||
} |
||||
else { |
||||
foreach (var a in list) { |
||||
Append(" " + a.FinalString); |
||||
} |
||||
} |
||||
|
||||
if (e.Nodes().Count() > 0) { |
||||
Append(">"); |
||||
nextColumn += Indenation; |
||||
|
||||
WalkContainer(e); |
||||
|
||||
nextColumn -= Indenation; |
||||
NewLine(); |
||||
Append("</" + name1 + ">"); |
||||
} |
||||
else { |
||||
Append(" />"); |
||||
} |
||||
} |
||||
|
||||
static void NewLine() |
||||
{ |
||||
if (sb.Length > 0) { |
||||
sb.AppendLine(); |
||||
sb.Append(new string(' ', nextColumn)); |
||||
currentColumn = nextColumn; |
||||
} |
||||
} |
||||
|
||||
static void Append(string s) |
||||
{ |
||||
sb.Append(s); |
||||
currentColumn += s.Length; |
||||
} |
||||
|
||||
enum AttributeLayout |
||||
{ |
||||
X, |
||||
XmlnsMicrosoft, |
||||
Xmlns, |
||||
XmlnsWithClr, |
||||
SpecialOrder, |
||||
ByName, |
||||
Attached, |
||||
WithPrefix |
||||
} |
||||
|
||||
class AttributeString |
||||
{ |
||||
public XName Name; |
||||
public string Prefix; |
||||
public string Value; |
||||
|
||||
public string LocalName |
||||
{ |
||||
get { return Name.LocalName; } |
||||
} |
||||
|
||||
public string FinalName |
||||
{ |
||||
get |
||||
{ |
||||
return Prefix == null ? Name.LocalName : Prefix + ":" + Name.LocalName; |
||||
} |
||||
} |
||||
|
||||
public string FinalString |
||||
{ |
||||
get |
||||
{ |
||||
return FinalName + "=\"" + Value + "\""; |
||||
} |
||||
} |
||||
|
||||
public AttributeLayout GetAttributeLayout() |
||||
{ |
||||
if (Prefix == "xmlns" || LocalName == "xmlns") { |
||||
if (Value.StartsWith("http://schemas.microsoft.com")) return AttributeLayout.XmlnsMicrosoft; |
||||
if (Value.StartsWith("clr")) return AttributeLayout.XmlnsWithClr; |
||||
return AttributeLayout.Xmlns; |
||||
} |
||||
if (Prefix == "x") return AttributeLayout.X; |
||||
if (Prefix != null) return AttributeLayout.WithPrefix; |
||||
if (LocalName.Contains(".")) return AttributeLayout.Attached; |
||||
if (AttributeComparrer.SpecialOrder.Contains(LocalName)) return AttributeLayout.SpecialOrder; |
||||
return AttributeLayout.ByName; |
||||
} |
||||
} |
||||
|
||||
class AttributeComparrer : IComparer<AttributeString> |
||||
{ |
||||
public static AttributeComparrer Instance = new AttributeComparrer(); |
||||
|
||||
public int Compare(AttributeString a1, AttributeString a2) |
||||
{ |
||||
var y1 = a1.GetAttributeLayout(); |
||||
var y2 = a2.GetAttributeLayout(); |
||||
if (y1 == y2) { |
||||
if (y1 == AttributeLayout.SpecialOrder) { |
||||
return |
||||
Array.IndexOf(SpecialOrder, a1.LocalName).CompareTo( |
||||
Array.IndexOf(SpecialOrder, a2.LocalName)); |
||||
} |
||||
return a1.FinalName.CompareTo(a2.FinalName); |
||||
} |
||||
return y1.CompareTo(y2); |
||||
} |
||||
|
||||
public static string[] SpecialOrder = new string[] { |
||||
"Name", |
||||
"Content", |
||||
"Command", |
||||
"Executed", |
||||
"CanExecute", |
||||
"Width", |
||||
"Height", |
||||
"Margin", |
||||
"HorizontalAlignment", |
||||
"VerticalAlignment", |
||||
"HorizontalContentAlignment", |
||||
"VerticalContentAlignment", |
||||
"StartPoint", |
||||
"EndPoint", |
||||
"Offset", |
||||
"Color" |
||||
}; |
||||
} |
||||
} |
||||
} |
@ -1,38 +0,0 @@
@@ -1,38 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public abstract class XamlMember |
||||
{ |
||||
public abstract string Name { get; } |
||||
public abstract XamlType OwnerType { get; } |
||||
public abstract XamlType ValueType { get; } |
||||
public abstract bool IsReadOnly { get; } |
||||
public abstract bool IsStatic { get; } |
||||
public abstract bool IsAttachable { get; } |
||||
public abstract XamlType TargetType { get; } |
||||
public abstract AllowedLocation AllowedLocation { get; } |
||||
public abstract bool IsEvent { get; } |
||||
public abstract bool IsDirective { get; } |
||||
public abstract bool HasTextSyntax { get; } |
||||
|
||||
public bool IsNameProperty |
||||
{ |
||||
get |
||||
{ |
||||
return this == Directive.Name || this == OwnerType.NameProperty; |
||||
} |
||||
} |
||||
|
||||
public abstract T GetAttribute<T>() where T : Attribute; |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return GetType().Name + ": " + Name; |
||||
} |
||||
} |
||||
} |
@ -1,77 +0,0 @@
@@ -1,77 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml.Linq; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public abstract class XamlNode : IHasAnnotations |
||||
{ |
||||
public XamlNode ParentNode; |
||||
public XamlDocument Document; |
||||
public XObject XmlObject; |
||||
|
||||
public abstract IEnumerable<XamlNode> Nodes(); |
||||
protected abstract void RemoveChild(XamlNode node); |
||||
|
||||
public bool InDocument |
||||
{ |
||||
get { return FindAncestor(n => Document.Root == n) != null; } |
||||
} |
||||
|
||||
public IEnumerable<XamlNode> Descendants() |
||||
{ |
||||
foreach (var node in Nodes()) { |
||||
foreach (var node2 in node.DescendantsAndSelf()) { |
||||
yield return node2; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public IEnumerable<XamlNode> DescendantsAndSelf() |
||||
{ |
||||
foreach (var node in Descendants()) { |
||||
yield return node; |
||||
} |
||||
yield return this; |
||||
} |
||||
|
||||
public XamlNode FindAncestor(Predicate<XamlNode> predicate) |
||||
{ |
||||
var node = this; |
||||
while (node != null) { |
||||
if (predicate(node)) { |
||||
return node; |
||||
} |
||||
node = node.ParentNode; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public void Remove() |
||||
{ |
||||
ParentNode.RemoveChild(this); |
||||
} |
||||
|
||||
#region IHasAnnotations Members
|
||||
|
||||
Dictionary<Type, object> annotations = new Dictionary<Type, object>(); |
||||
|
||||
public void AnnotateWith<T>(T annotation) where T : class |
||||
{ |
||||
annotations[typeof(T)] = annotation; |
||||
} |
||||
|
||||
public T GetAnnotation<T>() where T : class |
||||
{ |
||||
object result; |
||||
if (annotations.TryGetValue(typeof(T), out result)) { |
||||
return (T)result; |
||||
} |
||||
return default(T); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -1,637 +0,0 @@
@@ -1,637 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml.Linq; |
||||
using System.Text.RegularExpressions; |
||||
using System.Windows.Data; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class XamlParser |
||||
{ |
||||
public XamlParser(XamlDocument doc) |
||||
{ |
||||
Document = doc; |
||||
} |
||||
|
||||
public XamlDocument Document { get; private set; } |
||||
|
||||
public XamlTypeFinder TypeFinder |
||||
{ |
||||
get { return Document.Project.TypeFinder; } |
||||
} |
||||
|
||||
public ObjectNode CreateObjectNodeFromXmlElement(XElement xmlObjectElement, |
||||
bool parentPreservesXmlSpace) |
||||
{ |
||||
//type
|
||||
XamlType objectType = TypeFinder.FindType(xmlObjectElement.Name); |
||||
if (objectType == null) { |
||||
objectType = TypeFinder.FindExtensionType(xmlObjectElement.Name); |
||||
} |
||||
if (objectType == null) { |
||||
throw new XamlException("Unknown element type"); |
||||
} |
||||
|
||||
//xml:space
|
||||
bool preserveChildXmlSpace = parentPreservesXmlSpace; |
||||
var spaceAttribute = xmlObjectElement.Attribute(XamlConstants.XmlSpaceName); |
||||
if (spaceAttribute != null) { |
||||
preserveChildXmlSpace = spaceAttribute.Value == "preserve"; |
||||
} |
||||
|
||||
//x:Code, x:XData
|
||||
if (objectType == IntristicType.Code || objectType == IntristicType.XData) { |
||||
ObjectNode literalResult = new ObjectNode(); |
||||
literalResult.Type = objectType; |
||||
var textNode = new TextNode() { Text = xmlObjectElement.Value }; |
||||
var memberNode = new MemberNode(); |
||||
memberNode.Values.Add(textNode); |
||||
literalResult.MemberNodes.Add(memberNode); |
||||
literalResult.XmlObject = xmlObjectElement; |
||||
return literalResult; |
||||
} |
||||
|
||||
List<XamlNode> convertedChildNodes = new List<XamlNode>(); |
||||
List<ObjectNode> codeItems = new List<ObjectNode>(); |
||||
|
||||
//conversion
|
||||
|
||||
foreach (var node in xmlObjectElement.Nodes()) { |
||||
var childElement = node as XElement; |
||||
if (childElement != null) { |
||||
if (IsXamlName(childElement.Name)) { |
||||
var convertedObject = CreateObjectNodeFromXmlElement(childElement, preserveChildXmlSpace); |
||||
if (convertedObject.Type == IntristicType.Code) { |
||||
codeItems.Add(convertedObject); |
||||
} |
||||
else { |
||||
convertedChildNodes.Add(convertedObject); |
||||
} |
||||
} |
||||
else if (GetDottedXamlName(childElement.Name) != null) { |
||||
var convertedMember = CreateMemberNodeFromXmlElement(childElement, objectType, preserveChildXmlSpace); |
||||
foreach (var objectNode in convertedMember.Values.OfType<ObjectNode>().ToArray()) { |
||||
if (objectNode.Type == IntristicType.Code) { |
||||
codeItems.Add(objectNode); |
||||
convertedMember.Values.Remove(objectNode); |
||||
} |
||||
} |
||||
convertedChildNodes.Add(convertedMember); |
||||
} |
||||
else { |
||||
throw new XamlException("Invalid element name syntax"); |
||||
} |
||||
} |
||||
else { |
||||
AddText(convertedChildNodes, node); |
||||
} |
||||
} |
||||
|
||||
if (codeItems.Count > 0) { |
||||
MemberNode directiveChildren = new MemberNode(); |
||||
directiveChildren.Member = IntristicMember.DirectiveChildren; |
||||
foreach (var item in codeItems) { |
||||
directiveChildren.Values.Add(item); |
||||
//item.ParentMember = directiveChildren;
|
||||
} |
||||
|
||||
} |
||||
|
||||
//whitespace removal
|
||||
|
||||
List<XamlNode> strippedChildNodes = new List<XamlNode>(); |
||||
int n = convertedChildNodes.Count; |
||||
bool hasTextNodes = false; |
||||
bool hasContent = false; |
||||
|
||||
for (int i = 0; i < n; i++) { |
||||
var node = convertedChildNodes[i]; |
||||
var textNode = node as TextNode; |
||||
if (textNode != null && IsCollapsibleString(textNode.Text)) { |
||||
bool prevMember = i - 1 > 0 && convertedChildNodes[i - 1] is MemberNode; |
||||
bool nextMember = i + 1 < n && convertedChildNodes[i + 1] is MemberNode; |
||||
if (i == 0 && nextMember) continue; |
||||
if (prevMember && nextMember) continue; |
||||
if (i == n - 1 && prevMember && (hasTextNodes || hasContent)) continue; |
||||
} |
||||
|
||||
strippedChildNodes.Add(convertedChildNodes[i]); |
||||
|
||||
if (textNode != null) { |
||||
hasTextNodes = true; |
||||
} |
||||
var memberNode = node as MemberNode; |
||||
if (memberNode != null && memberNode.Member == objectType.ContentProperty) { |
||||
hasContent = true; |
||||
} |
||||
} |
||||
|
||||
//content wrapping
|
||||
|
||||
XamlMember contentMember = null; |
||||
XamlType contentMemberType = null; |
||||
if (objectType.ContentProperty != null) { |
||||
contentMember = objectType.ContentProperty; |
||||
contentMemberType = contentMember.ValueType; |
||||
} |
||||
else { |
||||
contentMember = IntristicMember.Items; |
||||
contentMemberType = objectType; |
||||
} |
||||
|
||||
List<MemberNode> attributeMembers = new List<MemberNode>(); |
||||
foreach (var xmlAttribute in xmlObjectElement.Attributes()) { |
||||
if (xmlAttribute.IsNamespaceDeclaration) continue; |
||||
var memberNode = CreateMemberNodeFromXmlAttribute(xmlAttribute, objectType, xmlObjectElement); |
||||
attributeMembers.Add(memberNode); |
||||
} |
||||
|
||||
List<MemberNode> members = new List<MemberNode>(); |
||||
|
||||
bool initFromText = |
||||
strippedChildNodes.Count(node => node is TextNode) == 1 && |
||||
strippedChildNodes.All(node => node is TextNode || |
||||
node is MemberNode && (node as MemberNode).Member == IntristicMember.DirectiveChildren) && |
||||
attributeMembers.All(node => node.Member == Directive.Key || |
||||
node.Member == Directive.Uid) && |
||||
|
||||
// differ from spec (spec bug?)
|
||||
//(contentMember.HasTextSyntax || objectType.HasTextSyntax);
|
||||
objectType.HasTextSyntax; |
||||
|
||||
if (initFromText) { |
||||
var initTextMember = new MemberNode(); |
||||
initTextMember.Member = IntristicMember.InitializationText; |
||||
initTextMember.Values.Add(strippedChildNodes.OfType<TextNode>().First()); |
||||
members.Add(initTextMember); |
||||
} |
||||
else { |
||||
members.AddRange(attributeMembers); |
||||
List<XamlValue> npChildren = new List<XamlValue>(); |
||||
|
||||
foreach (var node in strippedChildNodes) { |
||||
if (node is MemberNode) { |
||||
if (npChildren.Count > 0) { |
||||
var memberNode = CreateMemberNodeFromContent(contentMember, contentMemberType, npChildren, preserveChildXmlSpace); |
||||
members.Add(memberNode); |
||||
npChildren.Clear(); |
||||
} |
||||
members.Add(node as MemberNode); |
||||
} |
||||
else { |
||||
npChildren.Add(node as XamlValue); |
||||
} |
||||
} |
||||
|
||||
if (npChildren.Count > 0) { |
||||
var memberNode = CreateMemberNodeFromContent(contentMember, contentMemberType, npChildren, preserveChildXmlSpace); |
||||
members.Add(memberNode); |
||||
} |
||||
} |
||||
|
||||
ObjectNode result = new ObjectNode(); |
||||
result.Type = objectType; |
||||
foreach (var memberNode in members) { |
||||
result.MemberNodes.Add(memberNode); |
||||
//memberNode.ParentObject = result;
|
||||
} |
||||
result.XmlObject = xmlObjectElement; |
||||
return result; |
||||
} |
||||
|
||||
public MemberNode CreateMemberNodeFromXmlAttribute(XAttribute xmlAttribute, |
||||
XamlType objectType, XElement namespaceProvider) |
||||
{ |
||||
XamlMember member; |
||||
if (IsXamlName(xmlAttribute.Name)) { |
||||
member = objectType.Member(xmlAttribute.Name.LocalName); |
||||
if (member == null) { |
||||
member = Directive.GetDirective(xmlAttribute.Name); |
||||
} |
||||
if (member == null) { |
||||
throw new XamlException("Unknown member"); |
||||
} |
||||
} |
||||
else { |
||||
var dottedName = GetDottedXamlName(xmlAttribute.Name); |
||||
if (dottedName != null) { |
||||
var attributeNamespace = |
||||
xmlAttribute.Name.Namespace != XNamespace.None ? |
||||
xmlAttribute.Name.Namespace : |
||||
namespaceProvider.Name.Namespace; |
||||
|
||||
var definingType = TypeFinder.FindType(attributeNamespace + dottedName.TypeName); |
||||
if (definingType == null) { |
||||
throw new XamlException("Unknown type"); |
||||
} |
||||
member = definingType.Member(dottedName.MemberName); |
||||
if (member == null) { |
||||
throw new XamlException("Unknown member"); |
||||
} |
||||
} |
||||
else { |
||||
throw new XamlException("Invalid attribute syntax"); |
||||
} |
||||
} |
||||
|
||||
XamlValue attributeValue = CreateValueFromAttributeText(xmlAttribute.Value, namespaceProvider); |
||||
|
||||
MemberNode result = new MemberNode(); |
||||
result.Member = member; |
||||
result.Values.Add(attributeValue); |
||||
//attributeValue.ParentMember = result;
|
||||
result.XmlObject = xmlAttribute; |
||||
return result; |
||||
} |
||||
|
||||
public XamlValue CreateValueFromAttributeText(string valueText, XElement namespaceProvider) |
||||
{ |
||||
if (valueText.StartsWith("{}")) { |
||||
return new TextNode() { Text = valueText.Substring(2) }; |
||||
} |
||||
else if (valueText.StartsWith("{")) { |
||||
return CreateObjectNodeFromMarkupExtensionInAttribute(valueText, namespaceProvider); |
||||
} |
||||
return new TextNode() { Text = valueText }; |
||||
} |
||||
|
||||
public MemberNode CreateMemberNodeFromXmlElement(XElement xmlMemberElement, |
||||
XamlType containingType, bool parentPreservesXmlSpace) |
||||
{ |
||||
if (xmlMemberElement.HasAttributes) { |
||||
if (xmlMemberElement.Attributes().Count() > 1 || |
||||
Directive.GetDirective(xmlMemberElement.FirstAttribute.Name) != |
||||
Directive.Uid) { |
||||
throw new XamlException("Member elements cannot contain attributes"); |
||||
} |
||||
} |
||||
|
||||
var dottedName = GetDottedXamlName(xmlMemberElement.Name); |
||||
XamlType ownerType = TypeFinder.FindType(xmlMemberElement.Name.Namespace + dottedName.TypeName); |
||||
if (ownerType == null) { |
||||
throw new XamlException("Unknown element type"); |
||||
} |
||||
|
||||
XamlMember resolvedMember = ownerType.Member(dottedName.MemberName); |
||||
if (resolvedMember == null || resolvedMember.AllowedLocation != AllowedLocation.Any) { |
||||
throw new XamlException("Member not found"); |
||||
} |
||||
|
||||
List<XamlValue> convertedChildNodes = new List<XamlValue>(); |
||||
|
||||
foreach (var node in xmlMemberElement.Nodes()) { |
||||
var childElement = node as XElement; |
||||
if (childElement != null) { |
||||
if (IsXamlName(childElement.Name)) { |
||||
var convertedObject = CreateObjectNodeFromXmlElement(childElement, parentPreservesXmlSpace); |
||||
convertedChildNodes.Add(convertedObject); |
||||
} |
||||
else if (GetDottedXamlName(childElement.Name) != null) { |
||||
throw new XamlException("Member elements may not be nested directly inside of another member element"); |
||||
} |
||||
else { |
||||
throw new XamlException("Invalid element name syntax"); |
||||
} |
||||
} |
||||
else { |
||||
AddText(convertedChildNodes, node); |
||||
} |
||||
} |
||||
|
||||
var result = CreateMemberNodeFromContent(resolvedMember, resolvedMember.ValueType, convertedChildNodes, parentPreservesXmlSpace); |
||||
result.XmlObject = xmlMemberElement; |
||||
return result; |
||||
} |
||||
|
||||
public MemberNode CreateMemberNodeFromContent(XamlMember containingMember, |
||||
XamlType memberType, List<XamlValue> childNodes, bool preserveXmlSpace) |
||||
{ |
||||
if (!preserveXmlSpace) { |
||||
if (memberType.IsWhitespaceSignificantCollection) { |
||||
TextNode prevTextNode = null; |
||||
for (int i = 0; i < childNodes.Count; i++) { |
||||
var node = childNodes[i]; |
||||
var textNode = node as TextNode; |
||||
if (textNode != null) { |
||||
textNode.Text = CollapseWhitespace(textNode.Text); |
||||
if (prevTextNode == null) { |
||||
textNode.Text = textNode.Text.TrimStart(); |
||||
prevTextNode = textNode; |
||||
} |
||||
} |
||||
else { |
||||
var objectNode = node as ObjectNode; |
||||
if (objectNode != null && objectNode.Type.TrimSurroundingWhitespace) { |
||||
var afterTextNode = i + 1 < childNodes.Count ? childNodes[i + 1] as TextNode : null; |
||||
if (prevTextNode != null) { |
||||
prevTextNode.Text = prevTextNode.Text.TrimEnd(); |
||||
} |
||||
if (afterTextNode != null) { |
||||
afterTextNode.Text = afterTextNode.Text.TrimStart(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (prevTextNode != null) { |
||||
prevTextNode.Text = prevTextNode.Text.TrimEnd(); |
||||
} |
||||
} |
||||
// differ from spec (spec bug?)
|
||||
else { |
||||
foreach (var textNode in childNodes.OfType<TextNode>()) { |
||||
textNode.Text = CollapseWhitespace(textNode.Text).Trim(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
childNodes = childNodes.Where(node => node is ObjectNode || (node as TextNode).Text.Length > 0).ToList(); |
||||
|
||||
List<XamlValue> outputValues = new List<XamlValue>(); |
||||
var singleObjectNode = childNodes.FirstOrDefault() as ObjectNode; |
||||
var useSingleObjectNode = singleObjectNode != null && memberType.IsAssignableFrom(singleObjectNode.Type); |
||||
|
||||
if (memberType.IsCollection && !useSingleObjectNode) { |
||||
var retrievedContentMember = new MemberNode(); |
||||
retrievedContentMember.Member = IntristicMember.Items; |
||||
foreach (var value in childNodes) { |
||||
retrievedContentMember.Values.Add(value); |
||||
} |
||||
|
||||
var retrievedValue = new ObjectNode(); |
||||
retrievedValue.Type = memberType; |
||||
retrievedValue.MemberNodes.Add(retrievedContentMember); |
||||
retrievedValue.IsRetrieved = true; |
||||
|
||||
outputValues.Add(retrievedValue); |
||||
} |
||||
else { |
||||
outputValues.AddRange(childNodes); |
||||
} |
||||
|
||||
MemberNode result = new MemberNode(); |
||||
result.Member = containingMember; |
||||
foreach (var value in outputValues) { |
||||
result.Values.Add(value); |
||||
//value.ParentMember = result;
|
||||
} |
||||
return result; |
||||
} |
||||
|
||||
public static XName GetTypeName(string typeNameWithPrefix, XElement namespaceProvider) |
||||
{ |
||||
var prefixedName = GetPrefixedName(typeNameWithPrefix); |
||||
if (prefixedName == null) { |
||||
throw new XamlException("Bad type extension name"); |
||||
} |
||||
|
||||
XNamespace typeNamespace = null; |
||||
if (prefixedName.Prefix == null) { |
||||
typeNamespace = namespaceProvider.Name.Namespace; |
||||
} |
||||
else { |
||||
typeNamespace = namespaceProvider.GetNamespaceOfPrefix(prefixedName.Prefix); |
||||
if (typeNamespace == null) { |
||||
throw new XamlException("Unrecognized namespace prefix"); |
||||
} |
||||
} |
||||
|
||||
return typeNamespace + prefixedName.LocalName; |
||||
} |
||||
|
||||
public ObjectNode CreateObjectNodeFromMarkupExtensionInAttribute(string attributeText, |
||||
XElement namespaceProvider) |
||||
{ |
||||
var ast = MarkupExtensionParser.Parse(attributeText); |
||||
|
||||
var prefixedName = GetPrefixedName(ast.TypeName); |
||||
if (prefixedName == null) { |
||||
throw new XamlException("Bad type extension name"); |
||||
} |
||||
|
||||
XNamespace typeNamespace = null; |
||||
if (prefixedName.Prefix == null) { |
||||
typeNamespace = namespaceProvider.Name.Namespace; |
||||
} |
||||
else { |
||||
typeNamespace = namespaceProvider.GetNamespaceOfPrefix(prefixedName.Prefix); |
||||
if (typeNamespace == null) { |
||||
throw new XamlException("Unrecognized namespace prefix"); |
||||
} |
||||
} |
||||
|
||||
XName typeName = typeNamespace + prefixedName.LocalName; |
||||
XamlType extensionType = TypeFinder.FindExtensionType(typeName); |
||||
if (extensionType == null || !IntristicType.MarkupExtension.IsAssignableFrom(extensionType)) { |
||||
extensionType = TypeFinder.FindType(typeName); |
||||
} |
||||
if (extensionType == null || !IntristicType.MarkupExtension.IsAssignableFrom(extensionType)) { |
||||
throw new XamlException("Unknown markup extension"); |
||||
} |
||||
|
||||
List<MemberNode> namedMembers = new List<MemberNode>(); |
||||
foreach (var namedArg in ast.NamedArgs) { |
||||
var memberName = GetPrefixedName(namedArg.Key); |
||||
if (memberName == null) { |
||||
throw new XamlException("Bad member name"); |
||||
} |
||||
|
||||
XNamespace memberNamespace; |
||||
if (prefixedName.Prefix == null) { |
||||
memberNamespace = namespaceProvider.Name.Namespace; |
||||
} |
||||
else { |
||||
memberNamespace = namespaceProvider.GetNamespaceOfPrefix(prefixedName.Prefix); |
||||
if (typeNamespace == null) { |
||||
throw new XamlException("Unrecognized namespace prefix"); |
||||
} |
||||
} |
||||
|
||||
XamlMember member = null; |
||||
if (IsXamlName(memberName.LocalName)) { |
||||
if (memberNamespace != typeNamespace) { |
||||
throw new XamlException("Unknown member"); |
||||
} |
||||
member = extensionType.Member(memberName.LocalName); |
||||
} |
||||
else { |
||||
var dottedName = GetDottedXamlName(memberNamespace + memberName.LocalName); |
||||
if (dottedName != null) { |
||||
var ownerType = TypeFinder.FindType(memberNamespace + dottedName.TypeName); |
||||
if (ownerType == null) { |
||||
throw new XamlException("Unknown type"); |
||||
} |
||||
member = ownerType.Member(dottedName.MemberName); |
||||
} |
||||
} |
||||
|
||||
if (member == null) { |
||||
throw new XamlException("Unknown member"); |
||||
} |
||||
|
||||
var memberValue = CreateValueFromAttributeText(namedArg.Value, namespaceProvider); |
||||
|
||||
var namedMember = new MemberNode(); |
||||
namedMember.Member = member; |
||||
namedMember.Values.Add(memberValue); |
||||
namedMembers.Add(namedMember); |
||||
} |
||||
|
||||
List<string> positionalArgs = ast.PositionalArgs; |
||||
MemberNode positionalArgsMember = null; |
||||
|
||||
if (positionalArgs.Count > 0) { |
||||
Constructor constructorInfo = null; |
||||
foreach (var extensionConstructor in extensionType.Constructors) { |
||||
if (extensionConstructor.Arguments.Length == positionalArgs.Count) { |
||||
constructorInfo = extensionConstructor; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (constructorInfo == null) { |
||||
throw new XamlException( |
||||
string.Format("No constructor for type '{0}' has {1} parameters", extensionType.Name, positionalArgs.Count)); |
||||
} |
||||
|
||||
List<XamlValue> positionalArgValues = new List<XamlValue>(); |
||||
|
||||
for (int i = 0; i < positionalArgs.Count; i++) { |
||||
var positionalArg = positionalArgs[i]; |
||||
var argumentType = constructorInfo.Arguments.ElementAt(i); |
||||
var argValue = CreateValueFromAttributeText(positionalArg, namespaceProvider); |
||||
positionalArgValues.Add(argValue); |
||||
} |
||||
|
||||
if (!MapPositionalArgsToNamedMembers(constructorInfo, positionalArgValues, namedMembers)) { |
||||
positionalArgsMember = new MemberNode(); |
||||
positionalArgsMember.Member = IntristicMember.ConsructorArgs; |
||||
foreach (var value in positionalArgValues) { |
||||
positionalArgsMember.Values.Add(value); |
||||
//value.ParentMember = positionalArgsMember;
|
||||
} |
||||
} |
||||
} |
||||
|
||||
List<MemberNode> allArgs = new List<MemberNode>(); |
||||
allArgs.AddRange(namedMembers); |
||||
if (positionalArgsMember != null) { |
||||
allArgs.Add(positionalArgsMember); |
||||
} |
||||
|
||||
ObjectNode result = new ObjectNode(); |
||||
result.Type = extensionType; |
||||
foreach (var arg in allArgs) { |
||||
result.MemberNodes.Add(arg); |
||||
//arg.ParentObject = result;
|
||||
} |
||||
return result; |
||||
} |
||||
|
||||
static bool MapPositionalArgsToNamedMembers(Constructor ctor, List<XamlValue> positionalArgValues, List<MemberNode> namedMembers) |
||||
{ |
||||
if (ctor.CorrespondingMembers != null) { |
||||
for (int i = 0; i < positionalArgValues.Count; i++) { |
||||
var memberNode = new MemberNode(); |
||||
memberNode.Member = ctor.CorrespondingMembers[i]; |
||||
memberNode.Values.Add(positionalArgValues[i]); |
||||
namedMembers.Add(memberNode); |
||||
} |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
static Regex XamlNameRegex = new Regex(@"^[\w]*$"); |
||||
static Regex DottedXamlNameRegex = new Regex(@"^([\w]*)\.([\w]*)$"); |
||||
|
||||
static bool IsXamlName(XName name) |
||||
{ |
||||
return XamlNameRegex.IsMatch(name.LocalName); |
||||
} |
||||
|
||||
static DottedXamlName GetDottedXamlName(XName name) |
||||
{ |
||||
var m = DottedXamlNameRegex.Match(name.LocalName); |
||||
if (m.Success) { |
||||
return new DottedXamlName() { |
||||
TypeName = m.Groups[1].Value, |
||||
MemberName = m.Groups[2].Value |
||||
}; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
static PrefixedName GetPrefixedName(string s) |
||||
{ |
||||
var result = new PrefixedName(); |
||||
var parts = s.Split(':'); |
||||
if (parts.Length == 1) { |
||||
result.LocalName = parts[0]; |
||||
} |
||||
else { |
||||
result.Prefix = parts[0]; |
||||
result.LocalName = parts[1]; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
public static bool IsCollapsibleChar(char c) |
||||
{ |
||||
return char.IsWhiteSpace(c); |
||||
} |
||||
|
||||
public static bool IsCollapsibleString(string s) |
||||
{ |
||||
return s == null || s.Trim().Length == 0; |
||||
} |
||||
|
||||
public static string CollapseWhitespace(string s) |
||||
{ |
||||
StringBuilder b = new StringBuilder(s.Length); |
||||
bool firstSpace = true; |
||||
foreach (var c in s) { |
||||
if (char.IsWhiteSpace(c)) { |
||||
if (firstSpace) b.Append(" "); |
||||
firstSpace = false; |
||||
continue; |
||||
} |
||||
b.Append(c); |
||||
firstSpace = true; |
||||
} |
||||
return b.ToString(); |
||||
} |
||||
|
||||
static void AddText(IList convertedChildNodes, XNode node) |
||||
{ |
||||
var xmlTextNode = node as XText; |
||||
if (xmlTextNode != null) { |
||||
TextNode textNode = null; |
||||
if (convertedChildNodes.Count > 0) { |
||||
textNode = convertedChildNodes[convertedChildNodes.Count - 1] as TextNode; |
||||
} |
||||
if (textNode != null) { |
||||
textNode.Text += xmlTextNode.Value; |
||||
} |
||||
else { |
||||
textNode = new TextNode() { Text = xmlTextNode.Value }; |
||||
convertedChildNodes.Add(textNode); |
||||
} |
||||
} |
||||
} |
||||
|
||||
class DottedXamlName |
||||
{ |
||||
public string TypeName; |
||||
public string MemberName; |
||||
} |
||||
|
||||
class PrefixedName |
||||
{ |
||||
public string Prefix; |
||||
public string LocalName; |
||||
} |
||||
} |
||||
} |
@ -1,91 +0,0 @@
@@ -1,91 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Reflection; |
||||
using System.Xml.Linq; |
||||
using System.Xml; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public abstract class XamlProject |
||||
{ |
||||
public XamlProject() |
||||
{ |
||||
TypeFinder = new XamlTypeFinder(this); |
||||
} |
||||
|
||||
public XamlTypeFinder TypeFinder; |
||||
public XamlAssembly ProjectAssembly; |
||||
public XamlDocument ApplicationDefinition; |
||||
public List<XamlAssembly> References = new List<XamlAssembly>(); |
||||
public List<XamlDocument> Themes = new List<XamlDocument>(); |
||||
public Dictionary<Uri, XamlDocument> Documents = new Dictionary<Uri, XamlDocument>(); |
||||
|
||||
XmlResolver xmlResolver = new XmlUrlResolver(); |
||||
|
||||
public IEnumerable<XamlAssembly> AllAssemblies |
||||
{ |
||||
get |
||||
{ |
||||
if (ProjectAssembly != null) { |
||||
yield return ProjectAssembly; |
||||
} |
||||
foreach (var a in References) { |
||||
yield return a; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public XamlDocument LoadDocument(string uri) |
||||
{ |
||||
var absoluteUri = xmlResolver.ResolveUri(null, uri); |
||||
XamlDocument doc; |
||||
if (!Documents.TryGetValue(absoluteUri, out doc)) { |
||||
doc = new XamlDocument(this); |
||||
var stream = (Stream)xmlResolver.GetEntity(absoluteUri, null, typeof(Stream)); |
||||
var text = new StreamReader(stream).ReadToEnd(); |
||||
doc.Parse(text); |
||||
doc.BaseUri = absoluteUri; |
||||
} |
||||
return doc; |
||||
} |
||||
|
||||
public XamlDocument ParseDocument(string text) |
||||
{ |
||||
var doc = new XamlDocument(this); |
||||
doc.Parse(text); |
||||
return doc; |
||||
} |
||||
|
||||
public XamlDocument CreateDocument() |
||||
{ |
||||
return new XamlDocument(this); |
||||
} |
||||
|
||||
public XamlDocument CreateDocument(object root) |
||||
{ |
||||
var doc = new XamlDocument(this); |
||||
doc.Root = doc.CreateObject(root); |
||||
return doc; |
||||
} |
||||
|
||||
public void AddReference(Assembly assembly) |
||||
{ |
||||
AddReference(ReflectionMapper.GetXamlAssembly(assembly)); |
||||
} |
||||
|
||||
public void AddReference(XamlAssembly xamlAssembly) |
||||
{ |
||||
References.Add(xamlAssembly); |
||||
TypeFinder.RegisterAssembly(xamlAssembly); |
||||
} |
||||
|
||||
public void RemoveReference(Assembly assembly) |
||||
{ |
||||
var xamlAssembly = ReflectionMapper.GetXamlAssembly(assembly); |
||||
References.Remove(xamlAssembly); |
||||
} |
||||
} |
||||
} |
@ -1,268 +0,0 @@
@@ -1,268 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml.Linq; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class XamlProperty : IHasAnnotations |
||||
{ |
||||
internal XamlProperty(ObjectNode objectNode, XamlMember member) |
||||
{ |
||||
this.objectNode = objectNode; |
||||
this.member = member; |
||||
this.context = new XamlContext(this); |
||||
} |
||||
|
||||
ObjectNode objectNode; |
||||
XamlMember member; |
||||
XamlContext context; |
||||
|
||||
public event EventHandler IsSetChanged; |
||||
public event EventHandler ValueChanged; |
||||
|
||||
public ObjectNode Object |
||||
{ |
||||
get { return objectNode; } |
||||
} |
||||
|
||||
public XamlMember Member |
||||
{ |
||||
get { return member; } |
||||
} |
||||
|
||||
public XamlContext XamlContext |
||||
{ |
||||
get { return context; } |
||||
} |
||||
|
||||
public bool IsSet |
||||
{ |
||||
get { return FindMemberNode() != null; } |
||||
} |
||||
|
||||
public XamlValue Value |
||||
{ |
||||
get |
||||
{ |
||||
var memberNode = FindMemberNode(); |
||||
if (memberNode != null) { |
||||
return memberNode.SingleValue; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public XamlType ValueType |
||||
{ |
||||
get |
||||
{ |
||||
if (member == IntristicMember.InitializationText) { |
||||
return Object.Type; |
||||
} |
||||
return member.ValueType; |
||||
} |
||||
} |
||||
|
||||
public string ValueText |
||||
{ |
||||
get |
||||
{ |
||||
var textValue = Value as TextNode; |
||||
if (textValue != null) { |
||||
return textValue.Text; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public object ValueOnInstance |
||||
{ |
||||
get |
||||
{ |
||||
// TODO: return real value
|
||||
if (Member.IsEvent) { |
||||
return ValueText; |
||||
} |
||||
return Runtime.GetValue(Object.Instance, Member); |
||||
} |
||||
set |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public NodeCollection<XamlValue> Collection |
||||
{ |
||||
get |
||||
{ |
||||
var items = EnsureItems(); |
||||
if (items != null) { |
||||
return items.Values; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public ObjectNode Add(object key, object value) |
||||
{ |
||||
var newObject = AddObject(value); |
||||
newObject.Property(Directive.Key).Set(key); |
||||
return newObject; |
||||
} |
||||
|
||||
public ObjectNode AddObject(object value) |
||||
{ |
||||
return Add(value) as ObjectNode; |
||||
} |
||||
|
||||
public XamlValue Add(object value) |
||||
{ |
||||
var newValue = PrepareValueForCollection(value); |
||||
EnsureItems().Values.Add(newValue); |
||||
return newValue; |
||||
} |
||||
|
||||
public XamlValue Insert(int index, object value) |
||||
{ |
||||
var newValue = PrepareValueForCollection(value); |
||||
EnsureItems().Values.Insert(index, newValue); |
||||
return newValue; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return GetType().Name + ": " + Member.Name; |
||||
} |
||||
|
||||
public ObjectNode SetObject(object value) |
||||
{ |
||||
return Set(value) as ObjectNode; |
||||
} |
||||
|
||||
public TextNode SetText(object value) |
||||
{ |
||||
return Set(value) as TextNode; |
||||
} |
||||
|
||||
public XamlValue Set(object value) |
||||
{ |
||||
if (member.ValueType.IsCollection && !member.ValueType.HasTextSyntax) { |
||||
return AddObject(value); |
||||
} |
||||
else { |
||||
var newValue = PrepareValue(value); |
||||
EnsureMemberNode().SingleValue = newValue; |
||||
return newValue; |
||||
} |
||||
} |
||||
|
||||
public void Reset() |
||||
{ |
||||
var memberNode = FindMemberNode(); |
||||
if (memberNode != null) { |
||||
memberNode.Remove(); |
||||
} |
||||
} |
||||
|
||||
public XamlValue PrepareValue(object value) |
||||
{ |
||||
if (value is XamlValue) { |
||||
return value as XamlValue; |
||||
} |
||||
if (value == null) { |
||||
return new ObjectNode(objectNode.Document, new NullExtension()); |
||||
} |
||||
|
||||
string text = value as string; |
||||
if (text == null) { |
||||
Runtime.TryConvertToText(context, value, out text); |
||||
} |
||||
if (text != null) { |
||||
var namespaceProvider = XmlTracker.GetNamespaceProvider(objectNode); |
||||
var valueNode = objectNode.Document.Parser.CreateValueFromAttributeText(text, namespaceProvider); |
||||
valueNode.Document = objectNode.Document; |
||||
return valueNode; |
||||
} |
||||
|
||||
return new ObjectNode(objectNode.Document, value); |
||||
} |
||||
|
||||
public XamlValue PrepareValueForCollection(object value) |
||||
{ |
||||
var valueNode = PrepareValue(value); |
||||
var textNode = valueNode as TextNode; |
||||
if (textNode != null) { |
||||
var itemsNode = EnsureItems(); |
||||
if (itemsNode.ParentObject != null && |
||||
itemsNode.ParentObject.Type.ContentWrappers.Where( |
||||
t => t.ContentProperty != null && |
||||
t.ContentProperty.ValueType == IntristicType.String).Any()) { |
||||
return textNode; |
||||
} |
||||
|
||||
var wrapperType = Runtime.GetWrapperTypeForInitializationText(value); |
||||
var wrapperNode = new ObjectNode() { |
||||
Document = objectNode.Document, |
||||
Type = wrapperType, |
||||
Instance = value |
||||
}; |
||||
wrapperNode.InitializationText.Set(textNode); |
||||
return wrapperNode; |
||||
} |
||||
return valueNode; |
||||
} |
||||
|
||||
public MemberNode FindMemberNode() |
||||
{ |
||||
return objectNode.FindMemberNode(member); |
||||
} |
||||
|
||||
public MemberNode EnsureMemberNode() |
||||
{ |
||||
return objectNode.EnsureMemberNode(member); |
||||
} |
||||
|
||||
MemberNode EnsureItems() |
||||
{ |
||||
if (member == IntristicMember.Items || |
||||
member == IntristicMember.ConsructorArgs || |
||||
member == IntristicMember.DirectiveChildren) { |
||||
return EnsureMemberNode(); |
||||
} |
||||
|
||||
var memberNode = EnsureMemberNode(); |
||||
if (memberNode.SingleValue == null) { |
||||
var collection = new ObjectNode() { |
||||
Document = objectNode.Document, |
||||
Type = member.ValueType, |
||||
IsRetrieved = true |
||||
}; |
||||
memberNode.SingleValue = collection; |
||||
} |
||||
return (memberNode.SingleValue as ObjectNode).EnsureMemberNode(IntristicMember.Items); |
||||
} |
||||
|
||||
#region IHasAnnotations Members
|
||||
|
||||
Dictionary<Type, object> annotations = new Dictionary<Type, object>(); |
||||
|
||||
public void AnnotateWith<T>(T annotation) where T : class |
||||
{ |
||||
annotations[typeof(T)] = annotation; |
||||
} |
||||
|
||||
public T GetAnnotation<T>() where T : class |
||||
{ |
||||
object result; |
||||
if (annotations.TryGetValue(typeof(T), out result)) { |
||||
return (T)result; |
||||
} |
||||
return default(T); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -1,51 +0,0 @@
@@ -1,51 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Diagnostics; |
||||
using System.Windows.Markup; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public abstract class XamlType |
||||
{ |
||||
public abstract string Name { get; } |
||||
public abstract bool IsDefaultConstructible { get; } |
||||
public abstract bool IsNullable { get; } |
||||
public abstract IEnumerable<XamlMember> Members { get; } |
||||
public abstract XamlMember ContentProperty { get; } |
||||
public abstract XamlMember DictionaryKeyProperty { get; } |
||||
public abstract XamlMember NameProperty { get; } |
||||
public abstract XamlMember XmlLangProperty { get; } |
||||
public abstract bool TrimSurroundingWhitespace { get; } |
||||
public abstract bool IsWhitespaceSignificantCollection { get; } |
||||
public abstract bool IsCollection { get; } |
||||
public abstract bool IsDictionary { get; } |
||||
public abstract IEnumerable<XamlType> AllowedTypes { get; } |
||||
public abstract IEnumerable<XamlType> AllowedKeyTypes { get; } |
||||
public abstract bool IsXData { get; } |
||||
public abstract bool IsNameScope { get; } |
||||
public abstract IEnumerable<Constructor> Constructors { get; } |
||||
public abstract XamlType ReturnValueType { get; } |
||||
public abstract bool HasTextSyntax { get; } |
||||
|
||||
public abstract string Namespace { get; } |
||||
public abstract XamlAssembly Assembly { get; } |
||||
public abstract XamlMember Member(string name); |
||||
public abstract IEnumerable<XamlType> ContentWrappers { get; } |
||||
public abstract Type SystemType { get; } |
||||
|
||||
public abstract bool IsAssignableFrom(XamlType type); |
||||
public abstract T GetAttribute<T>() where T : Attribute; |
||||
|
||||
public bool IsMarkupExtension |
||||
{ |
||||
get { return IntristicType.MarkupExtension.IsAssignableFrom(this); } |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return GetType().Name + ": " + Name; |
||||
} |
||||
} |
||||
} |
@ -1,188 +0,0 @@
@@ -1,188 +0,0 @@
|
||||
using System; |
||||
using System.Linq; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Reflection; |
||||
using System.Windows.Markup; |
||||
using System.Xml.Linq; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public class XamlTypeFinder |
||||
{ |
||||
public XamlTypeFinder(XamlProject project) |
||||
{ |
||||
Project = project; |
||||
} |
||||
|
||||
public XamlProject Project { get; private set; } |
||||
|
||||
Dictionary<XNamespace, XamlNamespace> xamlNamespaces = new Dictionary<XNamespace, XamlNamespace>(); |
||||
Dictionary<Mapping, XNamespace> xmlNamespaces = new Dictionary<Mapping, XNamespace>(); |
||||
|
||||
public XamlType FindType(XName name) |
||||
{ |
||||
if (name == IntristicType.CodeName) return IntristicType.Code; |
||||
if (name == IntristicType.XDataName) return IntristicType.XData; |
||||
|
||||
return FindType(name, null); |
||||
} |
||||
|
||||
public XamlType FindExtensionType(XName name) |
||||
{ |
||||
return FindType(name, "Extension"); |
||||
} |
||||
|
||||
XamlType FindType(XName name, string suffix) |
||||
{ |
||||
XamlNamespace ns; |
||||
if (!xamlNamespaces.TryGetValue(name.Namespace, out ns)) { |
||||
var mapping = ParseMappingString(name.Namespace); |
||||
if (mapping != null) { |
||||
ns = new XamlNamespace() { XmlNamespace = name.Namespace }; |
||||
AddMapping(ns, mapping); |
||||
xamlNamespaces[name.Namespace] = ns; |
||||
} |
||||
else { |
||||
return null; |
||||
} |
||||
} |
||||
foreach (var mapping in ns.Mappings) { |
||||
var type = mapping.Assembly.GetType(mapping.ClrNamespace + "." + name.LocalName + suffix); |
||||
if (type != null) return type; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public XNamespace GetXmlNamespaceForType(XamlType type) |
||||
{ |
||||
Mapping mapping = new Mapping() { Assembly = type.Assembly, ClrNamespace = type.Namespace }; |
||||
XNamespace ns; |
||||
if (xmlNamespaces.TryGetValue(mapping, out ns)) { |
||||
return ns; |
||||
} |
||||
if (mapping.Assembly == null || mapping.Assembly == Project.ProjectAssembly) { |
||||
return "clr-namespace:" + mapping.ClrNamespace; |
||||
} |
||||
return "clr-namespace:" + mapping.ClrNamespace + ";assembly=" + mapping.Assembly.Name; |
||||
} |
||||
|
||||
public void RegisterAssembly(XamlAssembly assembly) |
||||
{ |
||||
foreach (var def in assembly.XmlnsDefinitions) { |
||||
XamlNamespace ns; |
||||
if (!xamlNamespaces.TryGetValue(def.XmlNamespace, out ns)) { |
||||
ns = new XamlNamespace() { XmlNamespace = def.XmlNamespace }; |
||||
xamlNamespaces[ns.XmlNamespace] = ns; |
||||
} |
||||
//TODO def.AssemblyName
|
||||
AddMapping(ns, new Mapping() { Assembly = assembly, ClrNamespace = def.ClrNamespace }); |
||||
} |
||||
} |
||||
|
||||
public void UnregisterAssembly(XamlAssembly assembly) |
||||
{ |
||||
foreach (var ns in xamlNamespaces.Values) { |
||||
foreach (var mapping in ns.Mappings.ToArray()) { |
||||
if (mapping.Assembly == assembly) { |
||||
RemoveMapping(ns, mapping); |
||||
} |
||||
} |
||||
if (ns.Mappings.Count == 0) { |
||||
xamlNamespaces.Remove(ns.XmlNamespace); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void AddMapping(XamlNamespace ns, Mapping mapping) |
||||
{ |
||||
ns.Mappings.Add(mapping); |
||||
|
||||
// XamlWriter compares prefixes lengths (av < wpf, av < xps)
|
||||
// but we want Presentation2007Namespace as default
|
||||
XNamespace xmlns; |
||||
xmlNamespaces.TryGetValue(mapping, out xmlns); |
||||
if (xmlns != XamlConstants.Presentation2007Namespace) { |
||||
xmlNamespaces[mapping] = ns.XmlNamespace; |
||||
} |
||||
} |
||||
|
||||
void RemoveMapping(XamlNamespace ns, Mapping mapping) |
||||
{ |
||||
ns.Mappings.Remove(mapping); |
||||
xmlNamespaces.Remove(mapping); |
||||
} |
||||
|
||||
Mapping ParseMappingString(XNamespace ns) |
||||
{ |
||||
var text = ns.NamespaceName; |
||||
if (text.StartsWith("clr-namespace:")) { |
||||
var mapping = new Mapping(); |
||||
text = text.Substring("clr-namespace:".Length); |
||||
|
||||
int pos = text.IndexOf(';'); |
||||
if (pos < 0) { |
||||
mapping.ClrNamespace = text; |
||||
mapping.Assembly = FindAssembly(null); |
||||
} |
||||
else { |
||||
mapping.ClrNamespace = text.Substring(0, pos); |
||||
text = text.Substring(pos + 1).Trim(); |
||||
if (!text.StartsWith("assembly=")) { |
||||
throw new XamlException("Expected: 'assembly='"); |
||||
} |
||||
var assemblyName = text.Substring("assembly=".Length); |
||||
mapping.Assembly = FindAssembly(assemblyName); |
||||
} |
||||
return mapping; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
XamlAssembly FindAssembly(string name) |
||||
{ |
||||
XamlAssembly result = null; |
||||
if (string.IsNullOrEmpty(name)) { |
||||
result = Project.ProjectAssembly; |
||||
} |
||||
else { |
||||
foreach (var a in Project.References) { |
||||
if (a.Name == name) { |
||||
result = a; |
||||
} |
||||
} |
||||
} |
||||
if (result != null) { |
||||
return result; |
||||
} |
||||
throw new XamlException(string.Format("Assembly '{0}' not found in project.", name)); |
||||
} |
||||
|
||||
class XamlNamespace |
||||
{ |
||||
public XNamespace XmlNamespace; |
||||
public List<Mapping> Mappings = new List<Mapping>(); |
||||
} |
||||
|
||||
class Mapping : IEquatable<Mapping> |
||||
{ |
||||
public XamlAssembly Assembly; |
||||
public string ClrNamespace; |
||||
|
||||
public override int GetHashCode() |
||||
{ |
||||
return Assembly.GetHashCode() ^ ClrNamespace.GetHashCode(); |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
return Equals(obj as Mapping); |
||||
} |
||||
|
||||
public bool Equals(Mapping other) |
||||
{ |
||||
return other != null && other.Assembly == this.Assembly && other.ClrNamespace == this.ClrNamespace; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Xml.Linq; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
public abstract class XamlValue : XamlNode |
||||
{ |
||||
public object Instance; |
||||
|
||||
public MemberNode ParentMember |
||||
{ |
||||
get { return ParentNode as MemberNode; } |
||||
} |
||||
|
||||
public ObjectNode ParentObject |
||||
{ |
||||
get { return ParentMember != null ? ParentMember.ParentObject : null; } |
||||
} |
||||
} |
||||
} |
@ -1,448 +0,0 @@
@@ -1,448 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Diagnostics; |
||||
using System.Xml.Linq; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
class XmlTracker : Tracker |
||||
{ |
||||
public override void Process(DocumentChangedEventArgs e) |
||||
{ |
||||
if (e.OldNode != null) { |
||||
if (!TryUpdateMarkupExtension(e.OldParent)) { |
||||
Detach(e.OldNode, e.OldParent); |
||||
} |
||||
RemoveEmptyBranch(e.OldParent); |
||||
} |
||||
if (e.NewNode != null) { |
||||
if (!TryUpdateMarkupExtension(e.OldParent)) { |
||||
Attach(e.NewNode); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void Attach(XamlNode node) |
||||
{ |
||||
var value = node as XamlValue; |
||||
if (value == null) return; |
||||
if (!node.InDocument) return; |
||||
|
||||
var objectNode = node as ObjectNode; |
||||
if (objectNode != null && objectNode.IsDocumentRoot) { |
||||
var doc = objectNode.Document; |
||||
if (doc.XmlDocument == null) { |
||||
doc.XmlDocument = new XDocument(); |
||||
} |
||||
PrintObject(objectNode, doc.XmlDocument, null, null); |
||||
return; |
||||
} |
||||
|
||||
if (!TryAttachUsingSiblings(value)) { |
||||
AttachUsingPrint(value); |
||||
} |
||||
} |
||||
|
||||
static void Detach(XamlNode node, XamlNode nodeParent) |
||||
{ |
||||
if (node.XmlObject != null) { |
||||
RemoveXmlObject(node); |
||||
} |
||||
else { |
||||
if (nodeParent.InDocument) { |
||||
var currentXmlElement = nodeParent.FindAncestor(n => n.XmlObject != null).XmlObject as XElement; |
||||
if (currentXmlElement != null) { |
||||
currentXmlElement.RemoveNodes(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
static bool TryAttachUsingSiblings(XamlValue value) |
||||
{ |
||||
var values = value.ParentMember.Values; |
||||
if (values.Count > 1) { |
||||
var index = values.IndexOf(value); |
||||
if (index + 1 < values.Count) { |
||||
var before = values[index + 1].XmlObject as XNode; |
||||
PrintValue(value, null, null, before); |
||||
} |
||||
else { |
||||
var after = values[index - 1].XmlObject as XNode; |
||||
PrintValue(value, null, after, null); |
||||
} |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
static void AttachUsingPrint(XamlValue value) |
||||
{ |
||||
var memberNode = value.FindAncestor(n => n is MemberNode && |
||||
(n as MemberNode).ParentObject.XmlObject != null) as MemberNode; |
||||
// TODO: XamlNode.IsAttached
|
||||
if (memberNode != null) { |
||||
PrintMember(memberNode, memberNode.ParentObject.XmlObject as XElement, null, null); |
||||
} |
||||
} |
||||
|
||||
static void RemoveEmptyBranch(XamlNode part) |
||||
{ |
||||
XamlNode prev = null; |
||||
while (IsEmpty(part)) { |
||||
prev = part; |
||||
part = part.ParentNode; |
||||
} |
||||
if (prev != null) { |
||||
prev.Remove(); |
||||
} |
||||
} |
||||
|
||||
static bool IsEmpty(XamlNode node) |
||||
{ |
||||
var objectNode = node as ObjectNode; |
||||
if (objectNode != null) { |
||||
if (objectNode.MemberNodes.Count == 0 && objectNode.IsRetrieved) { |
||||
return true; |
||||
} |
||||
} |
||||
else { |
||||
var memberNode = node as MemberNode; |
||||
if (memberNode != null) { |
||||
if (memberNode.Values.Count == 0) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
static XName CreateMemberName(MemberNode node, bool forAttribute) |
||||
{ |
||||
if (node.Member.IsDirective) { |
||||
return Directive.GetDirectiveName(node.Member); |
||||
} |
||||
var type = node.Member.OwnerType; |
||||
if (type.IsAssignableFrom(node.ParentObject.Type)) { |
||||
if (forAttribute) { |
||||
return node.Member.Name; |
||||
} |
||||
type = node.ParentObject.Type; |
||||
} |
||||
var dottedName = type.Name + "." + node.Member.Name; |
||||
var typeNamespace = node.Document.Project.TypeFinder.GetXmlNamespaceForType(type); |
||||
if (forAttribute) { |
||||
var xmlElement = node.FindAncestor(n => n.XmlObject is XElement).XmlObject as XElement; |
||||
if (typeNamespace == xmlElement.Name.Namespace) { |
||||
return dottedName; |
||||
} |
||||
} |
||||
return typeNamespace + dottedName; |
||||
} |
||||
|
||||
static XName CreateTypeName(ObjectNode node) |
||||
{ |
||||
var typeNamespace = node.Document.Project.TypeFinder.GetXmlNamespaceForType(node.Type); |
||||
var typeName = node.Type.Name; |
||||
if (node.Type.IsMarkupExtension && typeName.EndsWith("Extension")) { |
||||
typeName = typeName.Substring(0, typeName.Length - "Extension".Length); |
||||
} |
||||
return typeNamespace + typeName; |
||||
} |
||||
|
||||
static bool TryPrintMarkupExtension(ObjectNode node, out string text) |
||||
{ |
||||
text = null; |
||||
if (!node.Type.IsMarkupExtension) { |
||||
return false; |
||||
} |
||||
|
||||
StringBuilder sb = new StringBuilder(); |
||||
sb.Append("{"); |
||||
|
||||
var typeName = CreateTypeName(node); |
||||
//TODO
|
||||
//var typePrefix = GetPrefixOfNamespace(node, typeName.Namespace);
|
||||
//sb.Append(typePrefix + ":" + typeName.LocalName);
|
||||
sb.Append(typeName.LocalName); |
||||
|
||||
List<XamlValue> positionalValues = new List<XamlValue>(); |
||||
var ctorArgs = node.FindMemberNode(IntristicMember.ConsructorArgs); |
||||
|
||||
if (ctorArgs != null) { |
||||
positionalValues.AddRange(ctorArgs.Values); |
||||
} |
||||
else { |
||||
var ctor = node.Type.Constructors.FirstOrDefault(); |
||||
if (ctor != null && ctor.CorrespondingMembers != null) { |
||||
foreach (var ctorMember in ctor.CorrespondingMembers) { |
||||
var ctorMemberNode = node.FindMemberNode(ctorMember); |
||||
if (ctorMemberNode == null || ctorMemberNode.SingleValue == null) { |
||||
positionalValues.Clear(); |
||||
break; |
||||
} |
||||
positionalValues.Add(ctorMemberNode.SingleValue); |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool first = true; |
||||
HashSet<MemberNode> printed = new HashSet<MemberNode>(); |
||||
|
||||
if (positionalValues.Count > 0) { |
||||
foreach (var value in positionalValues) { |
||||
if (first) { |
||||
sb.Append(" "); |
||||
first = false; |
||||
} |
||||
else { |
||||
sb.Append(", "); |
||||
} |
||||
|
||||
string valueText; |
||||
if (!TryPrintMarkupExtensionValue(value, out valueText)) { |
||||
return false; |
||||
} |
||||
sb.Append(valueText); |
||||
|
||||
printed.Add(value.ParentMember); |
||||
} |
||||
} |
||||
|
||||
foreach (var memberNode in node.MemberNodes) { |
||||
if (printed.Contains(memberNode)) { |
||||
continue; |
||||
} |
||||
|
||||
if (first) { |
||||
sb.Append(" "); |
||||
first = false; |
||||
} |
||||
else { |
||||
sb.Append(", "); |
||||
} |
||||
|
||||
var memberName = CreateMemberName(memberNode, true); |
||||
sb.Append(memberName.LocalName); |
||||
|
||||
sb.Append("="); |
||||
|
||||
string valueText; |
||||
if (!TryPrintMarkupExtensionValue(memberNode.SingleValue, out valueText)) { |
||||
return false; |
||||
} |
||||
sb.Append(valueText); |
||||
} |
||||
|
||||
sb.Append("}"); |
||||
text = sb.ToString(); |
||||
return true; |
||||
} |
||||
|
||||
static bool TryPrintMarkupExtensionValue(XamlValue value, out string text) |
||||
{ |
||||
text = null; |
||||
if (value is TextNode) { |
||||
text = (value as TextNode).Text; |
||||
} |
||||
else if (value is ObjectNode) { |
||||
if (!TryPrintMarkupExtension(value as ObjectNode, out text)) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
static XNamespace GetPrefixOfNamespace(XamlNode node, XNamespace ns) |
||||
{ |
||||
var xmlElement = node.FindAncestor(n => n.XmlObject is XElement).XmlObject as XElement; |
||||
return xmlElement.GetPrefixOfNamespace(ns); |
||||
} |
||||
|
||||
static bool TryUpdateMarkupExtension(XamlNode node) |
||||
{ |
||||
MemberNode root = null; |
||||
while (node != null) { |
||||
MemberNode memberNode = node as MemberNode; |
||||
if (memberNode != null) { |
||||
var markupExtensionNode = memberNode.SingleValue as ObjectNode; |
||||
if (markupExtensionNode != null && markupExtensionNode.Type.IsMarkupExtension) { |
||||
root = memberNode; |
||||
} |
||||
} |
||||
node = node.ParentNode; |
||||
} |
||||
|
||||
if (root != null) { |
||||
string text; |
||||
if (TryPrintMarkupExtension(root.SingleValue as ObjectNode, out text)) { |
||||
EnsureXmlAttribute(root, root.ParentObject.XmlObject as XElement).Value = text; |
||||
foreach (var descendant in root.Descendants()) { |
||||
descendant.XmlObject = null; |
||||
} |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
static void PrintObject(ObjectNode node, XContainer currentXmlContainer, XNode after, XNode before) |
||||
{ |
||||
if (node.IsRetrieved) { |
||||
foreach (var memberNode in node.MemberNodes) { |
||||
PrintMember(memberNode, currentXmlContainer as XElement, after, before); |
||||
} |
||||
} |
||||
else { |
||||
if (node.XmlObject == null) { |
||||
var typeFinder = node.Document.Project.TypeFinder; |
||||
var xmlElement = new XElement(typeFinder.GetXmlNamespaceForType(node.Type) + node.Type.Name); |
||||
node.XmlObject = xmlElement; |
||||
|
||||
// preserve usual namespaces
|
||||
if (node.IsDocumentRoot) { |
||||
xmlElement.Add(new XAttribute("xmlns", xmlElement.Name.Namespace)); |
||||
xmlElement.Add(new XAttribute(XNamespace.Xmlns + "x", XamlConstants.XamlNamespace)); |
||||
} |
||||
|
||||
AddXmlObject(node, currentXmlContainer, after, before); |
||||
|
||||
foreach (var memberNode in node.MemberNodes) { |
||||
PrintMember(memberNode, xmlElement, after, before); |
||||
} |
||||
} |
||||
else { |
||||
AddXmlObject(node, currentXmlContainer, after, before); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void PrintMember(MemberNode node, XElement currentXmlElement, XNode after, XNode before) |
||||
{ |
||||
if (node.SingleValue is TextNode && node.Member != IntristicMember.Items) { |
||||
if (node.Member == IntristicMember.InitializationText) { |
||||
PrintValue(node.SingleValue, currentXmlElement, after, before); |
||||
} |
||||
else { |
||||
EnsureXmlAttribute(node, currentXmlElement).Value = (node.SingleValue as TextNode).Text; |
||||
} |
||||
} |
||||
else { |
||||
var me = node.SingleValue as ObjectNode; |
||||
if (me != null && me.Type.IsMarkupExtension) { |
||||
string text; |
||||
if (TryPrintMarkupExtension(me, out text)) { |
||||
EnsureXmlAttribute(node, currentXmlElement).Value = text; |
||||
return; |
||||
} |
||||
} |
||||
var xmlElement = EnsureXmlElement(node, currentXmlElement); |
||||
foreach (var value in node.Values) { |
||||
PrintValue(value, xmlElement, after, before); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void PrintValue(XamlValue value, XElement currentXmlElement, XNode after, XNode before) |
||||
{ |
||||
var textNode = value as TextNode; |
||||
if (textNode != null) { |
||||
var text = textNode.Text; |
||||
textNode.XmlObject = new XText(text); |
||||
AddXmlObject(textNode, currentXmlElement, after, before); |
||||
|
||||
if (text.StartsWith(" ") || text.EndsWith(" ")) { |
||||
var xmlElement = currentXmlElement ?? (after != null ? after.Parent : null) ?? before.Parent; |
||||
xmlElement.SetAttributeValue(XamlConstants.XmlSpaceName, "preserve"); |
||||
} |
||||
} |
||||
else { |
||||
PrintObject(value as ObjectNode, currentXmlElement, after, before); |
||||
} |
||||
} |
||||
|
||||
static void AddXmlObject(XamlNode node, XContainer currentXmlContainer, XNode after, XNode before) |
||||
{ |
||||
if (after != null) { |
||||
after.AddAfterSelf(node.XmlObject); |
||||
} |
||||
else if (before != null) { |
||||
before.AddBeforeSelf(node.XmlObject); |
||||
} |
||||
else if (node.XmlObject.Document == null) { |
||||
currentXmlContainer.Add(node.XmlObject); |
||||
} |
||||
} |
||||
|
||||
static void RemoveXmlObject(XamlNode node) |
||||
{ |
||||
if (node.XmlObject is XAttribute) { |
||||
(node.XmlObject as XAttribute).Remove(); |
||||
node.XmlObject = null; |
||||
} |
||||
else if (node.XmlObject is XNode) { |
||||
(node.XmlObject as XNode).Remove(); |
||||
} |
||||
//node.XmlObject = null;
|
||||
} |
||||
|
||||
static XAttribute EnsureXmlAttribute(MemberNode node, XElement currentXmlElement) |
||||
{ |
||||
var xmlAttribute = node.XmlObject as XAttribute; |
||||
if (xmlAttribute == null) { |
||||
if (node.XmlObject != null) { |
||||
RemoveXmlObject(node); |
||||
} |
||||
else if (IsContent(node)) { |
||||
currentXmlElement.RemoveNodes(); |
||||
} |
||||
|
||||
xmlAttribute = new XAttribute(CreateMemberName(node, true), ""); |
||||
currentXmlElement.Add(xmlAttribute); |
||||
node.XmlObject = xmlAttribute; |
||||
} |
||||
return xmlAttribute; |
||||
} |
||||
|
||||
static XElement EnsureXmlElement(MemberNode node, XElement currentXmlElement) |
||||
{ |
||||
var xmlElement = node.XmlObject as XElement; |
||||
if (xmlElement == null) { |
||||
if (node.XmlObject != null) { |
||||
RemoveXmlObject(node); |
||||
} |
||||
if (IsContent(node)) { |
||||
return currentXmlElement; |
||||
} |
||||
|
||||
xmlElement = new XElement(CreateMemberName(node, false)); |
||||
currentXmlElement.AddFirst(xmlElement); |
||||
node.XmlObject = xmlElement; |
||||
} |
||||
return xmlElement; |
||||
} |
||||
|
||||
static bool IsContent(MemberNode node) |
||||
{ |
||||
return |
||||
node.Member == node.ParentObject.Type.ContentProperty || |
||||
node.Member == IntristicMember.Items || |
||||
node.Member == IntristicMember.InitializationText; |
||||
} |
||||
|
||||
public static XElement GetNamespaceProvider(ObjectNode node) |
||||
{ |
||||
var nodeWithXmlElement = node.FindAncestor(n => n.XmlObject is XElement); |
||||
if (nodeWithXmlElement != null) { |
||||
return (nodeWithXmlElement.XmlObject as XElement); |
||||
} |
||||
if (node.Document.XmlDocument != null && node.Document.XmlDocument.Root != null) { |
||||
return node.Document.XmlDocument.Root; |
||||
} |
||||
return new XElement("Empty"); |
||||
} |
||||
} |
||||
} |
@ -1,11 +0,0 @@
@@ -1,11 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.Xaml |
||||
{ |
||||
class XmlnsDefinition |
||||
{ |
||||
} |
||||
} |
@ -1,115 +0,0 @@
@@ -1,115 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 2667$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.IO; |
||||
using System.Windows.Controls; |
||||
|
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.WpfDesign.Designer.XamlBackend; |
||||
using ICSharpCode.Xaml; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
abstract class AbstractEventHandlerService : IEventHandlerService |
||||
{ |
||||
WpfPrimaryViewContent viewContent; |
||||
|
||||
protected AbstractEventHandlerService(WpfPrimaryViewContent viewContent) |
||||
{ |
||||
if (viewContent == null) |
||||
throw new ArgumentNullException("viewContent"); |
||||
this.viewContent = viewContent; |
||||
} |
||||
|
||||
protected IProjectContent GetProjectContent() |
||||
{ |
||||
IProject p = ProjectService.OpenSolution.FindProjectContainingFile(viewContent.PrimaryFileName); |
||||
if (p != null) |
||||
return ParserService.GetProjectContent(p) ?? ParserService.DefaultProjectContent; |
||||
else |
||||
return ParserService.DefaultProjectContent; |
||||
} |
||||
|
||||
protected IClass GetDesignedClass() |
||||
{ |
||||
var model = viewContent.Context.ModelService as XamlModelService; |
||||
if (model != null) { |
||||
string className = model.ClassName; |
||||
if (!string.IsNullOrEmpty(className)) { |
||||
return GetProjectContent().GetClass(className, 0); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected IClass GetDesignedClassCodeBehindPart(IClass c) |
||||
{ |
||||
CompoundClass compound = c as CompoundClass; |
||||
if (compound != null) { |
||||
c = null; |
||||
foreach (IClass part in compound.Parts) { |
||||
if (string.IsNullOrEmpty(part.CompilationUnit.FileName)) |
||||
continue; |
||||
if (XamlConstants.HasXamlExtension(part.CompilationUnit.FileName)) |
||||
continue; |
||||
if (c == null || c.CompilationUnit.FileName.Length > part.CompilationUnit.FileName.Length) |
||||
c = part; |
||||
} |
||||
} |
||||
return c; |
||||
} |
||||
|
||||
protected abstract void CreateEventHandlerInternal(Type eventHandlerType, string handlerName); |
||||
|
||||
public void CreateEventHandler(DesignItemProperty eventProperty) |
||||
{ |
||||
var item = eventProperty.DesignItem; |
||||
string handlerName = (string)eventProperty.ValueOnInstance; |
||||
|
||||
if (string.IsNullOrEmpty(handlerName)) { |
||||
if (string.IsNullOrEmpty(item.Name)) { |
||||
GenerateName(eventProperty.DesignItem); |
||||
} |
||||
handlerName = item.Name + "_" + eventProperty.Name; |
||||
eventProperty.SetValue(handlerName); |
||||
} |
||||
CreateEventHandlerInternal(eventProperty.ReturnType, handlerName); |
||||
} |
||||
|
||||
public DesignItemProperty GetDefaultEvent(DesignItem item) |
||||
{ |
||||
object[] attributes = item.ComponentType.GetCustomAttributes(typeof(DefaultEventAttribute), true); |
||||
if (attributes.Length == 1) { |
||||
DefaultEventAttribute dae = (DefaultEventAttribute)attributes[0]; |
||||
DesignItemProperty property = item.Properties.GetProperty(dae.Name); |
||||
if (property != null && property.IsEvent) { |
||||
return property; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
void GenerateName(DesignItem item) |
||||
{ |
||||
for (int i = 1; ; i++) { |
||||
try { |
||||
string name = item.ComponentType.Name + i; |
||||
name = char.ToLower(name[0]) + name.Substring(1); |
||||
item.Name = name; |
||||
break; |
||||
} |
||||
catch { |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,48 +0,0 @@
@@ -1,48 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 2667$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
sealed class CSharpEventHandlerService : AbstractEventHandlerService |
||||
{ |
||||
public CSharpEventHandlerService(WpfPrimaryViewContent viewContent) |
||||
: base(viewContent) |
||||
{ |
||||
} |
||||
|
||||
protected override void CreateEventHandlerInternal(Type eventHandlerType, string handlerName) |
||||
{ |
||||
IClass c = GetDesignedClass(); |
||||
if (c != null) { |
||||
foreach (IMethod m in c.Methods) { |
||||
if (m.Name == handlerName) { |
||||
FileService.JumpToFilePosition(m.DeclaringType.CompilationUnit.FileName, |
||||
m.Region.BeginLine - 1, m.Region.BeginColumn - 1); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
c = GetDesignedClassCodeBehindPart(c); |
||||
if (c != null) { |
||||
ITextEditorControlProvider tecp = FileService.OpenFile(c.CompilationUnit.FileName) as ITextEditorControlProvider; |
||||
if (tecp != null) { |
||||
int lineNumber; |
||||
FormsDesigner.CSharpDesignerGenerator.CreateComponentEvent( |
||||
c, tecp.TextEditorControl.Document, eventHandlerType, handlerName, null, |
||||
out lineNumber); |
||||
tecp.TextEditorControl.ActiveTextAreaControl.JumpTo(lineNumber - 1); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,16 +0,0 @@
@@ -1,16 +0,0 @@
|
||||
#region Using directives
|
||||
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("WpfDesign.AddIn")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
@ -1,39 +0,0 @@
@@ -1,39 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 2577 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Windows.Markup; |
||||
|
||||
using ICSharpCode.SharpDevelop; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Used to support loading Image.ImageSource.
|
||||
/// </summary>
|
||||
public class FileUriContext : IUriContext |
||||
{ |
||||
OpenedFile file; |
||||
|
||||
public FileUriContext(OpenedFile file) |
||||
{ |
||||
if (file == null) |
||||
throw new ArgumentNullException("file"); |
||||
this.file = file; |
||||
} |
||||
|
||||
public Uri BaseUri { |
||||
get { |
||||
return new Uri(file.FileName); |
||||
} |
||||
set { |
||||
throw new NotSupportedException(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using System.Windows; |
||||
using System.Windows.Interop; |
||||
using System.Windows.Markup; |
||||
using System.Windows.Media.Imaging; |
||||
|
||||
using ICSharpCode.Core.WinForms; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
class GetBitmapExtension : MarkupExtension |
||||
{ |
||||
public GetBitmapExtension(string key) |
||||
{ |
||||
this.key = key; |
||||
} |
||||
|
||||
static Dictionary<string, BitmapSource> cache = new Dictionary<string, BitmapSource>(); |
||||
|
||||
protected string key; |
||||
|
||||
public override object ProvideValue(IServiceProvider sp) |
||||
{ |
||||
lock (cache) { |
||||
BitmapSource result; |
||||
if (!cache.TryGetValue(key, out result)) { |
||||
result = GetBitmapSource(); |
||||
result.Freeze(); |
||||
cache[key] = result; |
||||
} |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
BitmapSource GetBitmapSource() |
||||
{ |
||||
Bitmap bitmap = WinFormsResourceService.GetBitmap(key); |
||||
return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, |
||||
Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); |
||||
} |
||||
} |
||||
} |
@ -1,29 +0,0 @@
@@ -1,29 +0,0 @@
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using System.Reflection; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.WpfDesign.Designer.Services; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class IdeChooseClassService : ChooseClassServiceBase |
||||
{ |
||||
public override IEnumerable<Assembly> GetAssemblies() |
||||
{ |
||||
var pc = ParserService.CurrentProjectContent; |
||||
if (pc != null) { |
||||
var a = XamlMapper.TypeResolutionServiceInstance.LoadAssembly(pc); |
||||
if (a != null) yield return a; |
||||
foreach (var r in pc.ReferencedContents) { |
||||
a = XamlMapper.TypeResolutionServiceInstance.LoadAssembly(r); |
||||
if (a != null) yield return a; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,62 +0,0 @@
@@ -1,62 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 2577 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using ICSharpCode.WpfDesign.XamlDom; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using TypeResolutionService = ICSharpCode.FormsDesigner.Services.TypeResolutionService; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class MyTypeFinder : XamlTypeFinder |
||||
{ |
||||
OpenedFile file; |
||||
|
||||
public static MyTypeFinder Create(OpenedFile file) |
||||
{ |
||||
MyTypeFinder f = new MyTypeFinder(); |
||||
f.file = file; |
||||
f.ImportFrom(CreateWpfTypeFinder()); |
||||
return f; |
||||
} |
||||
|
||||
public override Assembly LoadAssembly(string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) { |
||||
IProjectContent pc = GetProjectContent(file); |
||||
if (pc != null) { |
||||
return TypeResolutionService.LoadAssembly(pc); |
||||
} |
||||
return null; |
||||
} else { |
||||
return base.LoadAssembly(name); |
||||
} |
||||
} |
||||
|
||||
public override XamlTypeFinder Clone() |
||||
{ |
||||
MyTypeFinder copy = new MyTypeFinder(); |
||||
copy.file = this.file; |
||||
copy.ImportFrom(this); |
||||
return copy; |
||||
} |
||||
|
||||
internal static IProjectContent GetProjectContent(OpenedFile file) |
||||
{ |
||||
if (ProjectService.OpenSolution != null && file != null) { |
||||
IProject p = ProjectService.OpenSolution.FindProjectContainingFile(file.FileName); |
||||
if (p != null) { |
||||
return ParserService.GetProjectContent(p); |
||||
} |
||||
} |
||||
return ParserService.DefaultProjectContent; |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
@@ -1,8 +0,0 @@
|
||||
<Button |
||||
x:Class="ICSharpCode.WpfDesign.AddIn.ObjectEditor" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
Content="New..." |
||||
HorizontalAlignment="Right" |
||||
> |
||||
</Button> |
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
using System; |
||||
using System.Windows; |
||||
using ICSharpCode.WpfDesign.PropertyGrid; |
||||
using ICSharpCode.WpfDesign.Designer.Services; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
[PropertyEditor(typeof(FrameworkElement), "DataContext")] |
||||
public partial class ObjectEditor |
||||
{ |
||||
public ObjectEditor() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
public PropertyNode PropertyNode { |
||||
get { return DataContext as PropertyNode; } |
||||
} |
||||
|
||||
protected override void OnClick() |
||||
{ |
||||
var s = PropertyNode.Services.GetService<ChooseClassServiceBase>(); |
||||
if (s != null) { |
||||
var c = s.ChooseClass(); |
||||
if (c != null) { |
||||
PropertyNode.Value = Activator.CreateInstance(c); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,66 +0,0 @@
@@ -1,66 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 3519 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class OutlineViewPad : AbstractPadContent |
||||
{ |
||||
public override System.Windows.Forms.Control Control |
||||
{ |
||||
get { return WpfTools.OutlineHost; } |
||||
} |
||||
|
||||
//SharpDevelopElementHost host = new SharpDevelopElementHost();
|
||||
|
||||
//TextBlock notAvailableTextBlock = new TextBlock {
|
||||
// Text = StringParser.Parse("${res:ICSharpCode.SharpDevelop.Gui.OutlinePad.NotAvailable}"),
|
||||
// TextWrapping = TextWrapping.Wrap
|
||||
//};
|
||||
|
||||
//public OutlineViewPad()
|
||||
//{
|
||||
// WorkbenchSingleton.Workbench.ActiveViewContentChanged += WorkbenchActiveViewContentChanged;
|
||||
// WorkbenchActiveViewContentChanged(null, null);
|
||||
//}
|
||||
|
||||
//void WorkbenchActiveViewContentChanged(object sender, EventArgs e)
|
||||
//{
|
||||
// WpfSecondaryViewContent wpfView = WorkbenchSingleton.Workbench.ActiveViewContent as WpfSecondaryViewContent;
|
||||
// host.ViewContent = wpfView;
|
||||
// if (wpfView != null) {
|
||||
// host.Child = wpfView.Outline;
|
||||
// } else {
|
||||
// host.Child = notAvailableTextBlock;
|
||||
// }
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// The <see cref="System.Windows.Forms.Control"/> representing the pad
|
||||
///// </summary>
|
||||
//public override System.Windows.Forms.Control Control {
|
||||
// get {
|
||||
// return host;
|
||||
// }
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// Cleans up all used resources
|
||||
///// </summary>
|
||||
//public override void Dispose()
|
||||
//{
|
||||
// host.Dispose();
|
||||
// base.Dispose();
|
||||
//}
|
||||
} |
||||
} |
@ -1 +0,0 @@
@@ -1 +0,0 @@
|
||||
|
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 3506 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.WpfDesign.Designer.XamlBackend; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class PropertyDescriptionService : IPropertyDescriptionService |
||||
{ |
||||
public object GetDescription(DesignItemProperty property) |
||||
{ |
||||
var p = property as XamlDesignItemProperty; |
||||
var m = XamlMapper.GetDomMember(p.XamlProperty.Member); |
||||
return CodeCompletionData.GetDocumentation(m.Documentation); |
||||
} |
||||
} |
||||
} |
@ -1,123 +0,0 @@
@@ -1,123 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 3519 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Forms.Integration; |
||||
using System.Windows.Input; |
||||
using System.Windows.Threading; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.WpfDesign.Designer; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Hosts a WPF element inside a Windows.Forms application.
|
||||
/// </summary>
|
||||
public class SharpDevelopElementHost : ElementHost, IUndoHandler, IClipboardHandler |
||||
{ |
||||
public SharpDevelopElementHost(UIElement child) |
||||
{ |
||||
Child = child; |
||||
|
||||
if (!registeredErrorHandler) { |
||||
registeredErrorHandler = true; |
||||
Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException; |
||||
} |
||||
} |
||||
|
||||
[ThreadStatic] |
||||
static bool registeredErrorHandler; |
||||
|
||||
static void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) |
||||
{ |
||||
ICSharpCode.Core.MessageService.ShowError(e.Exception, "Unhandled WPF exception"); |
||||
e.Handled = true; |
||||
} |
||||
|
||||
ICommandService CurrentCommandService |
||||
{ |
||||
get |
||||
{ |
||||
if (WpfTools.ActiveContext != null) { |
||||
return WpfTools.ActiveContext.CommandService; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public bool EnableUndo |
||||
{ |
||||
get { return CurrentCommandService != null && CurrentCommandService.CanUndo(); } |
||||
} |
||||
|
||||
public bool EnableRedo |
||||
{ |
||||
get { return CurrentCommandService != null && CurrentCommandService.CanRedo(); } |
||||
} |
||||
|
||||
public bool EnableCopy |
||||
{ |
||||
get { return CurrentCommandService != null && CurrentCommandService.CanCopy(); } |
||||
} |
||||
|
||||
public bool EnablePaste |
||||
{ |
||||
get { return CurrentCommandService != null && CurrentCommandService.CanPaste(); } |
||||
} |
||||
|
||||
public bool EnableCut |
||||
{ |
||||
get { return CurrentCommandService != null && CurrentCommandService.CanCut(); } |
||||
} |
||||
|
||||
public bool EnableSelectAll |
||||
{ |
||||
get { return CurrentCommandService != null && CurrentCommandService.CanSelectAll(); } |
||||
} |
||||
|
||||
public bool EnableDelete |
||||
{ |
||||
get { return CurrentCommandService != null && CurrentCommandService.CanDelete(); } |
||||
} |
||||
|
||||
public void Undo() |
||||
{ |
||||
CurrentCommandService.Undo(); |
||||
} |
||||
|
||||
public void Redo() |
||||
{ |
||||
CurrentCommandService.Redo(); |
||||
} |
||||
|
||||
public void Copy() |
||||
{ |
||||
CurrentCommandService.Copy(); |
||||
} |
||||
|
||||
public void Paste() |
||||
{ |
||||
CurrentCommandService.Paste(); |
||||
} |
||||
|
||||
public void Cut() |
||||
{ |
||||
CurrentCommandService.Cut(); |
||||
} |
||||
|
||||
public void SelectAll() |
||||
{ |
||||
CurrentCommandService.SelectAll(); |
||||
} |
||||
|
||||
public void Delete() |
||||
{ |
||||
CurrentCommandService.Delete(); |
||||
} |
||||
} |
||||
} |
@ -1,112 +0,0 @@
@@ -1,112 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 2667$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.IO; |
||||
using System.Windows.Controls; |
||||
|
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
abstract class AbstractEventHandlerService : IEventHandlerService |
||||
{ |
||||
WpfViewContent viewContent; |
||||
|
||||
protected AbstractEventHandlerService(WpfViewContent viewContent) |
||||
{ |
||||
if (viewContent == null) |
||||
throw new ArgumentNullException("viewContent"); |
||||
this.viewContent = viewContent; |
||||
} |
||||
|
||||
protected IProjectContent GetProjectContent() |
||||
{ |
||||
IProject p = ProjectService.OpenSolution.FindProjectContainingFile(viewContent.PrimaryFileName); |
||||
if (p != null) |
||||
return ParserService.GetProjectContent(p) ?? ParserService.DefaultProjectContent; |
||||
else |
||||
return ParserService.DefaultProjectContent; |
||||
} |
||||
|
||||
protected IClass GetDesignedClass() |
||||
{ |
||||
Designer.Xaml.XamlDesignContext xamlContext = viewContent.DesignContext as Designer.Xaml.XamlDesignContext; |
||||
if (xamlContext != null) { |
||||
string className = xamlContext.ClassName; |
||||
if (!string.IsNullOrEmpty(className)) { |
||||
return GetProjectContent().GetClass(className, 0); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected IClass GetDesignedClassCodeBehindPart(IClass c) |
||||
{ |
||||
CompoundClass compound = c as CompoundClass; |
||||
if (compound != null) { |
||||
c = null; |
||||
foreach (IClass part in compound.Parts) { |
||||
if (string.IsNullOrEmpty(part.CompilationUnit.FileName)) |
||||
continue; |
||||
if (".xaml".Equals(Path.GetExtension(part.CompilationUnit.FileName), StringComparison.OrdinalIgnoreCase)) |
||||
continue; |
||||
if (c == null || c.CompilationUnit.FileName.Length > part.CompilationUnit.FileName.Length) |
||||
c = part; |
||||
} |
||||
} |
||||
return c; |
||||
} |
||||
|
||||
protected abstract void CreateEventHandlerInternal(Type eventHandlerType, string handlerName); |
||||
|
||||
public void CreateEventHandler(DesignItemProperty eventProperty) |
||||
{ |
||||
var item = eventProperty.DesignItem; |
||||
string handlerName = (string)eventProperty.ValueOnInstance; |
||||
|
||||
if (string.IsNullOrEmpty(handlerName)) { |
||||
if (string.IsNullOrEmpty(item.Name)) { |
||||
GenerateName(eventProperty.DesignItem); |
||||
} |
||||
handlerName = item.Name + "_" + eventProperty.Name; |
||||
eventProperty.SetValue(handlerName); |
||||
} |
||||
CreateEventHandlerInternal(eventProperty.ReturnType, handlerName); |
||||
} |
||||
|
||||
public DesignItemProperty GetDefaultEvent(DesignItem item) |
||||
{ |
||||
object[] attributes = item.ComponentType.GetCustomAttributes(typeof(DefaultEventAttribute), true); |
||||
if (attributes.Length == 1) { |
||||
DefaultEventAttribute dae = (DefaultEventAttribute)attributes[0]; |
||||
DesignItemProperty property = item.Properties.GetProperty(dae.Name); |
||||
if (property != null && property.IsEvent) { |
||||
return property; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
void GenerateName(DesignItem item) |
||||
{ |
||||
for (int i = 1;; i++) { |
||||
try { |
||||
string name = item.ComponentType.Name + i; |
||||
name = char.ToLower(name[0]) + name.Substring(1); |
||||
item.Name = name; |
||||
break; |
||||
} catch { |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,47 +0,0 @@
@@ -1,47 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 2667$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
sealed class CSharpEventHandlerService : AbstractEventHandlerService |
||||
{ |
||||
public CSharpEventHandlerService(WpfViewContent viewContent) : base(viewContent) |
||||
{ |
||||
} |
||||
|
||||
protected override void CreateEventHandlerInternal(Type eventHandlerType, string handlerName) |
||||
{ |
||||
IClass c = GetDesignedClass(); |
||||
if (c != null) { |
||||
foreach (IMethod m in c.Methods) { |
||||
if (m.Name == handlerName) { |
||||
FileService.JumpToFilePosition(m.DeclaringType.CompilationUnit.FileName, |
||||
m.Region.BeginLine - 1, m.Region.BeginColumn - 1); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
c = GetDesignedClassCodeBehindPart(c); |
||||
if (c != null) { |
||||
ITextEditorControlProvider tecp = FileService.OpenFile(c.CompilationUnit.FileName) as ITextEditorControlProvider; |
||||
if (tecp != null) { |
||||
int lineNumber; |
||||
FormsDesigner.CSharpDesignerGenerator.CreateComponentEvent( |
||||
c, tecp.TextEditorControl.Document, eventHandlerType, handlerName, null, |
||||
out lineNumber); |
||||
tecp.TextEditorControl.ActiveTextAreaControl.JumpTo(lineNumber - 1); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,39 +0,0 @@
@@ -1,39 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Windows.Markup; |
||||
|
||||
using ICSharpCode.SharpDevelop; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Used to support loading Image.ImageSource.
|
||||
/// </summary>
|
||||
public class FileUriContext : IUriContext |
||||
{ |
||||
OpenedFile file; |
||||
|
||||
public FileUriContext(OpenedFile file) |
||||
{ |
||||
if (file == null) |
||||
throw new ArgumentNullException("file"); |
||||
this.file = file; |
||||
} |
||||
|
||||
public Uri BaseUri { |
||||
get { |
||||
return new Uri(file.FileName); |
||||
} |
||||
set { |
||||
throw new NotSupportedException(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using System.Windows; |
||||
using System.Windows.Interop; |
||||
using System.Windows.Markup; |
||||
using System.Windows.Media.Imaging; |
||||
|
||||
using ICSharpCode.Core.WinForms; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
class GetBitmapExtension : MarkupExtension |
||||
{ |
||||
public GetBitmapExtension(string key) |
||||
{ |
||||
this.key = key; |
||||
} |
||||
|
||||
static Dictionary<string, BitmapSource> cache = new Dictionary<string, BitmapSource>(); |
||||
|
||||
protected string key; |
||||
|
||||
public override object ProvideValue(IServiceProvider sp) |
||||
{ |
||||
lock (cache) { |
||||
BitmapSource result; |
||||
if (!cache.TryGetValue(key, out result)) { |
||||
result = GetBitmapSource(); |
||||
result.Freeze(); |
||||
cache[key] = result; |
||||
} |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
BitmapSource GetBitmapSource() |
||||
{ |
||||
Bitmap bitmap = WinFormsResourceService.GetBitmap(key); |
||||
return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, |
||||
Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); |
||||
} |
||||
} |
||||
} |
@ -1,49 +0,0 @@
@@ -1,49 +0,0 @@
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using System.Reflection; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.WpfDesign.Designer.Services; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
//TODO
|
||||
public class IdeChooseClassService : ChooseClassServiceBase |
||||
{ |
||||
static string GetAssemblyPath(IProjectContent projectContent) |
||||
{ |
||||
var r = projectContent as ReflectionProjectContent; |
||||
if (r != null) { |
||||
return r.AssemblyLocation; |
||||
} |
||||
var p = projectContent.Project as IProject; |
||||
if (p != null) { |
||||
return p.OutputAssemblyFullPath; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
static Assembly GetAssembly(IProjectContent projectContent) |
||||
{ |
||||
var path = GetAssemblyPath(projectContent); |
||||
if (path != null && File.Exists(path)) { |
||||
return Assembly.LoadFile(path); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public override IEnumerable<Assembly> GetAssemblies() |
||||
{ |
||||
var pc = ParserService.CurrentProjectContent; |
||||
var a = GetAssembly(pc); |
||||
if (a != null) yield return a; |
||||
foreach (var r in pc.ReferencedContents) { |
||||
a = GetAssembly(r); |
||||
if (a != null) yield return a; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,63 +0,0 @@
@@ -1,63 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using ICSharpCode.WpfDesign.XamlDom; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using TypeResolutionService = ICSharpCode.FormsDesigner.Services.TypeResolutionService; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class MyTypeFinder : XamlTypeFinder |
||||
{ |
||||
OpenedFile file; |
||||
readonly TypeResolutionService typeResolutionService = new TypeResolutionService(); |
||||
|
||||
public static MyTypeFinder Create(OpenedFile file) |
||||
{ |
||||
MyTypeFinder f = new MyTypeFinder(); |
||||
f.file = file; |
||||
f.ImportFrom(CreateWpfTypeFinder()); |
||||
return f; |
||||
} |
||||
|
||||
public override Assembly LoadAssembly(string name) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) { |
||||
IProjectContent pc = GetProjectContent(file); |
||||
if (pc != null) { |
||||
return this.typeResolutionService.LoadAssembly(pc); |
||||
} |
||||
return null; |
||||
} else { |
||||
return base.LoadAssembly(name); |
||||
} |
||||
} |
||||
|
||||
public override XamlTypeFinder Clone() |
||||
{ |
||||
MyTypeFinder copy = new MyTypeFinder(); |
||||
copy.file = this.file; |
||||
copy.ImportFrom(this); |
||||
return copy; |
||||
} |
||||
|
||||
internal static IProjectContent GetProjectContent(OpenedFile file) |
||||
{ |
||||
if (ProjectService.OpenSolution != null && file != null) { |
||||
IProject p = ProjectService.OpenSolution.FindProjectContainingFile(file.FileName); |
||||
if (p != null) { |
||||
return ParserService.GetProjectContent(p); |
||||
} |
||||
} |
||||
return ParserService.DefaultProjectContent; |
||||
} |
||||
} |
||||
} |
@ -1,8 +0,0 @@
@@ -1,8 +0,0 @@
|
||||
<Button |
||||
x:Class="ICSharpCode.WpfDesign.AddIn.ObjectEditor" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
Content="New..." |
||||
HorizontalAlignment="Right" |
||||
> |
||||
</Button> |
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
using System; |
||||
using System.Windows; |
||||
using ICSharpCode.WpfDesign.PropertyGrid; |
||||
using ICSharpCode.WpfDesign.Designer.Services; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
[PropertyEditor(typeof(FrameworkElement), "DataContext")] |
||||
public partial class ObjectEditor |
||||
{ |
||||
public ObjectEditor() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
public PropertyNode PropertyNode { |
||||
get { return DataContext as PropertyNode; } |
||||
} |
||||
|
||||
protected override void OnClick() |
||||
{ |
||||
var s = PropertyNode.Services.GetService<ChooseClassServiceBase>(); |
||||
if (s != null) { |
||||
var c = s.ChooseClass(); |
||||
if (c != null) { |
||||
PropertyNode.Value = Activator.CreateInstance(c); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,60 +0,0 @@
@@ -1,60 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class OutlineViewPad : AbstractPadContent |
||||
{ |
||||
SharpDevelopElementHost host = new SharpDevelopElementHost(); |
||||
TextBlock notAvailableTextBlock = new TextBlock { |
||||
Text = StringParser.Parse("${res:ICSharpCode.SharpDevelop.Gui.OutlinePad.NotAvailable}"), |
||||
TextWrapping = TextWrapping.Wrap |
||||
}; |
||||
|
||||
public OutlineViewPad() |
||||
{ |
||||
WorkbenchSingleton.Workbench.ActiveViewContentChanged += WorkbenchActiveViewContentChanged; |
||||
WorkbenchActiveViewContentChanged(null, null); |
||||
} |
||||
|
||||
void WorkbenchActiveViewContentChanged(object sender, EventArgs e) |
||||
{ |
||||
WpfViewContent wpfView = WorkbenchSingleton.Workbench.ActiveViewContent as WpfViewContent; |
||||
host.ViewContent = wpfView; |
||||
if (wpfView != null) { |
||||
host.Child = wpfView.Outline; |
||||
} else { |
||||
host.Child = notAvailableTextBlock; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The <see cref="System.Windows.Forms.Control"/> representing the pad
|
||||
/// </summary>
|
||||
public override System.Windows.Forms.Control Control { |
||||
get { |
||||
return host; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Cleans up all used resources
|
||||
/// </summary>
|
||||
public override void Dispose() |
||||
{ |
||||
host.Dispose(); |
||||
base.Dispose(); |
||||
} |
||||
} |
||||
} |
@ -1,41 +0,0 @@
@@ -1,41 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class PropertyDescriptionService : IPropertyDescriptionService |
||||
{ |
||||
OpenedFile file; |
||||
|
||||
public PropertyDescriptionService(OpenedFile file) |
||||
{ |
||||
if (file == null) |
||||
throw new ArgumentNullException("file"); |
||||
this.file = file; |
||||
} |
||||
|
||||
public object GetDescription(DesignItemProperty property) |
||||
{ |
||||
IProjectContent pc = MyTypeFinder.GetProjectContent(file); |
||||
if (pc != null) { |
||||
IClass c = pc.GetClassByReflectionName(property.DeclaringType.FullName, true); |
||||
if (c != null) { |
||||
IMember m = DefaultProjectContent.GetMemberByReflectionName(c, property.Name); |
||||
if (m != null) |
||||
return CodeCompletionData.GetDocumentation(m.Documentation); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -1,124 +0,0 @@
@@ -1,124 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Forms.Integration; |
||||
using System.Windows.Input; |
||||
using System.Windows.Threading; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Hosts a WPF element inside a Windows.Forms application.
|
||||
/// </summary>
|
||||
public class SharpDevelopElementHost : ElementHost, IUndoHandler, IClipboardHandler |
||||
{ |
||||
[ThreadStatic] |
||||
static bool registeredErrorHandler; |
||||
|
||||
public SharpDevelopElementHost() |
||||
{ |
||||
if (!registeredErrorHandler) { |
||||
registeredErrorHandler = true; |
||||
Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException; |
||||
} |
||||
} |
||||
|
||||
//needed for command routing (SharpDevelopElementHost -> DesignSurface)
|
||||
internal WpfViewContent ViewContent; |
||||
|
||||
static void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) |
||||
{ |
||||
ICSharpCode.Core.MessageService.ShowError(e.Exception, "Unhandled WPF exception"); |
||||
e.Handled = true; |
||||
} |
||||
|
||||
bool IsEnabled(RoutedCommand command) |
||||
{ |
||||
if (command.CanExecute(null, null)) |
||||
return true; |
||||
else if (ViewContent != null) |
||||
return command.CanExecute(null, ViewContent.DesignSurface); |
||||
else |
||||
return false; |
||||
} |
||||
|
||||
void Run(RoutedCommand command) |
||||
{ |
||||
if (command.CanExecute(null, null)) { |
||||
command.Execute(null, null); |
||||
} else if (ViewContent != null) { |
||||
command.Execute(null, ViewContent.DesignSurface); |
||||
} |
||||
} |
||||
|
||||
public bool EnableUndo { |
||||
get { return IsEnabled(ApplicationCommands.Undo); } |
||||
} |
||||
|
||||
public bool EnableRedo { |
||||
get { return IsEnabled(ApplicationCommands.Redo); } |
||||
} |
||||
|
||||
public void Undo() |
||||
{ |
||||
Run(ApplicationCommands.Undo); |
||||
} |
||||
|
||||
public void Redo() |
||||
{ |
||||
Run(ApplicationCommands.Redo); |
||||
} |
||||
|
||||
public bool EnableCut { |
||||
get { return IsEnabled(ApplicationCommands.Undo); } |
||||
} |
||||
|
||||
public bool EnableCopy { |
||||
get { return IsEnabled(ApplicationCommands.Copy); } |
||||
} |
||||
|
||||
public bool EnablePaste { |
||||
get { return IsEnabled(ApplicationCommands.Paste); } |
||||
} |
||||
|
||||
public bool EnableDelete { |
||||
get { return IsEnabled(ApplicationCommands.Delete); } |
||||
} |
||||
|
||||
public bool EnableSelectAll { |
||||
get { return IsEnabled(ApplicationCommands.SelectAll); } |
||||
} |
||||
|
||||
public void Cut() |
||||
{ |
||||
Run(ApplicationCommands.Cut); |
||||
} |
||||
|
||||
public void Copy() |
||||
{ |
||||
Run(ApplicationCommands.Copy); |
||||
} |
||||
|
||||
public void Paste() |
||||
{ |
||||
Run(ApplicationCommands.Paste); |
||||
} |
||||
|
||||
public void Delete() |
||||
{ |
||||
Run(ApplicationCommands.Delete); |
||||
} |
||||
|
||||
public void SelectAll() |
||||
{ |
||||
Run(ApplicationCommands.SelectAll); |
||||
} |
||||
} |
||||
} |
@ -1,77 +0,0 @@
@@ -1,77 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 2667$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Interop; |
||||
using System.Windows.Media; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
sealed class WpfAndWinFormsTopLevelWindowService : ITopLevelWindowService |
||||
{ |
||||
public ITopLevelWindow GetTopLevelWindow(UIElement element) |
||||
{ |
||||
Window window = Window.GetWindow(element); |
||||
if (window != null) { |
||||
return new WpfTopLevelWindow(window); |
||||
} |
||||
HwndSource hwndSource = PresentationSource.FromVisual(element) as HwndSource; |
||||
if (hwndSource != null) { |
||||
Control ctl = Control.FromChildHandle(hwndSource.Handle); |
||||
if (ctl != null) { |
||||
Form form = ctl.FindForm(); |
||||
if (form != null) { |
||||
return new WindowsFormsTopLevelWindow(form); |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
sealed class WpfTopLevelWindow : ITopLevelWindow |
||||
{ |
||||
Window window; |
||||
|
||||
public WpfTopLevelWindow(Window window) |
||||
{ |
||||
this.window = window; |
||||
} |
||||
|
||||
public void SetOwner(Window child) |
||||
{ |
||||
child.Owner = window; |
||||
} |
||||
|
||||
public bool Activate() |
||||
{ |
||||
return window.Activate(); |
||||
} |
||||
} |
||||
|
||||
sealed class WindowsFormsTopLevelWindow : ITopLevelWindow |
||||
{ |
||||
Form form; |
||||
|
||||
public WindowsFormsTopLevelWindow(Form form) |
||||
{ |
||||
this.form = form; |
||||
} |
||||
|
||||
public void SetOwner(Window child) |
||||
{ |
||||
(new WindowInteropHelper(child)).Owner = form.Handle; |
||||
} |
||||
|
||||
public bool Activate() |
||||
{ |
||||
return form.Focus(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,64 +0,0 @@
@@ -1,64 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class WpfPrimaryDisplayBinding : IDisplayBinding |
||||
{ |
||||
public bool CanCreateContentForFile(string fileName) |
||||
{ |
||||
return Path.GetExtension(fileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase); |
||||
} |
||||
|
||||
public IViewContent CreateContentForFile(OpenedFile file) |
||||
{ |
||||
return new WpfViewContent(file); |
||||
} |
||||
} |
||||
|
||||
public class WpfSecondaryDisplayBinding : ISecondaryDisplayBinding |
||||
{ |
||||
public bool ReattachWhenParserServiceIsReady { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool CanAttachTo(IViewContent content) |
||||
{ |
||||
if (Path.GetExtension(content.PrimaryFileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase)) { |
||||
IEditable editable = content as IEditable; |
||||
if (editable != null) { |
||||
try { |
||||
XmlTextReader r = new XmlTextReader(new StringReader(editable.Text)); |
||||
r.XmlResolver = null; |
||||
r.WhitespaceHandling = WhitespaceHandling.None; |
||||
while (r.NodeType != XmlNodeType.Element && r.Read()); |
||||
|
||||
if (r.LocalName == "Window" || r.LocalName == "UserControl") |
||||
return true; |
||||
} catch (XmlException) { |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public IViewContent[] CreateSecondaryViewContent(IViewContent viewContent) |
||||
{ |
||||
return new IViewContent[] { new WpfViewContent(viewContent.PrimaryFile) }; |
||||
} |
||||
} |
||||
} |
@ -1,37 +0,0 @@
@@ -1,37 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.WpfDesign.Designer.Services; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Description of WpfSideTabItem.
|
||||
/// </summary>
|
||||
public class WpfSideTabItem : SharpDevelopSideTabItem |
||||
{ |
||||
public WpfSideTabItem(Type componentType) : base(componentType.Name, new CreateComponentTool(componentType)) |
||||
{ |
||||
CanBeRenamed = false; |
||||
// this.Icon = tag.Bitmap;
|
||||
} |
||||
|
||||
///<summary>create a default tabitem : a pointer icon with an empty toolboxitem</summary>
|
||||
public WpfSideTabItem() : base("Pointer") |
||||
{ |
||||
CanBeRenamed = false; |
||||
CanBeDeleted = false; |
||||
Bitmap pointerBitmap = new Bitmap(IconService.GetBitmap("Icons.16x16.FormsDesigner.PointerIcon"), 16, 16); |
||||
this.Icon = pointerBitmap; |
||||
this.Tag = null; |
||||
} |
||||
} |
||||
} |
@ -1,128 +0,0 @@
@@ -1,128 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Widgets.SideBar; |
||||
using WPF = System.Windows.Controls; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Manages the WpfToolbox.
|
||||
/// </summary>
|
||||
public class WpfToolbox |
||||
{ |
||||
static WpfToolbox instance; |
||||
|
||||
public static WpfToolbox Instance { |
||||
get { |
||||
WorkbenchSingleton.AssertMainThread(); |
||||
if (instance == null) { |
||||
instance = new WpfToolbox(); |
||||
} |
||||
return instance; |
||||
} |
||||
} |
||||
|
||||
IToolService toolService; |
||||
WpfSideBar sideBar; |
||||
|
||||
public WpfToolbox() |
||||
{ |
||||
sideBar = new WpfSideBar(); |
||||
SideTab sideTab = new SideTab(sideBar, "Windows Presentation Foundation"); |
||||
sideTab.DisplayName = StringParser.Parse(sideTab.Name); |
||||
sideTab.CanBeDeleted = false; |
||||
sideTab.ChoosedItemChanged += OnChoosedItemChanged; |
||||
|
||||
sideTab.Items.Add(new WpfSideTabItem()); |
||||
foreach (Type t in Metadata.GetPopularControls()) |
||||
sideTab.Items.Add(new WpfSideTabItem(t)); |
||||
|
||||
sideBar.Tabs.Add(sideTab); |
||||
sideBar.ActiveTab = sideTab; |
||||
} |
||||
|
||||
void OnChoosedItemChanged(object sender, EventArgs e) |
||||
{ |
||||
if (toolService != null) { |
||||
ITool newTool = null; |
||||
if (sideBar.ActiveTab != null && sideBar.ActiveTab.ChoosedItem != null) { |
||||
newTool = sideBar.ActiveTab.ChoosedItem.Tag as ITool; |
||||
} |
||||
toolService.CurrentTool = newTool ?? toolService.PointerTool; |
||||
} |
||||
} |
||||
|
||||
public Control ToolboxControl { |
||||
get { return sideBar; } |
||||
} |
||||
|
||||
public IToolService ToolService { |
||||
get { return toolService; } |
||||
set { |
||||
if (toolService != null) { |
||||
toolService.CurrentToolChanged -= OnCurrentToolChanged; |
||||
} |
||||
toolService = value; |
||||
if (toolService != null) { |
||||
toolService.CurrentToolChanged += OnCurrentToolChanged; |
||||
OnCurrentToolChanged(null, null); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void OnCurrentToolChanged(object sender, EventArgs e) |
||||
{ |
||||
object tagToFind; |
||||
if (toolService.CurrentTool == toolService.PointerTool) { |
||||
tagToFind = null; |
||||
} else { |
||||
tagToFind = toolService.CurrentTool; |
||||
} |
||||
if (sideBar.ActiveTab.ChoosedItem != null) { |
||||
if (sideBar.ActiveTab.ChoosedItem.Tag == tagToFind) |
||||
return; |
||||
} |
||||
foreach (SideTabItem item in sideBar.ActiveTab.Items) { |
||||
if (item.Tag == tagToFind) { |
||||
sideBar.ActiveTab.ChoosedItem = item; |
||||
sideBar.Refresh(); |
||||
return; |
||||
} |
||||
} |
||||
foreach (SideTab tab in sideBar.Tabs) { |
||||
foreach (SideTabItem item in tab.Items) { |
||||
if (item.Tag == tagToFind) { |
||||
sideBar.ActiveTab = tab; |
||||
sideBar.ActiveTab.ChoosedItem = item; |
||||
sideBar.Refresh(); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
sideBar.ActiveTab.ChoosedItem = null; |
||||
sideBar.Refresh(); |
||||
} |
||||
|
||||
sealed class WpfSideBar : SharpDevelopSideBar |
||||
{ |
||||
protected override object StartItemDrag(SideTabItem draggedItem) |
||||
{ |
||||
if (this.ActiveTab.ChoosedItem != draggedItem && this.ActiveTab.Items.Contains(draggedItem)) { |
||||
this.ActiveTab.ChoosedItem = draggedItem; |
||||
} |
||||
return new System.Windows.DataObject(draggedItem.Tag); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,217 +0,0 @@
@@ -1,217 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.WpfDesign.Designer.OutlineView; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Integration; |
||||
using System.Windows.Markup; |
||||
using System.Xml; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.WpfDesign.Designer; |
||||
using ICSharpCode.WpfDesign.Designer.PropertyGrid; |
||||
using ICSharpCode.WpfDesign.Designer.Services; |
||||
using ICSharpCode.WpfDesign.Designer.Xaml; |
||||
using ICSharpCode.WpfDesign.PropertyGrid; |
||||
using System.Windows.Input; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// IViewContent implementation that hosts the WPF designer.
|
||||
/// </summary>
|
||||
public class WpfViewContent : AbstractViewContentHandlingLoadErrors, IHasPropertyContainer, IToolsHost |
||||
{ |
||||
public WpfViewContent(OpenedFile file) : base(file) |
||||
{ |
||||
BasicMetadata.Register(); |
||||
|
||||
this.TabPageText = "${res:FormsDesigner.DesignTabPages.DesignTabPage}"; |
||||
this.IsActiveViewContentChanged += OnIsActiveViewContentChanged; |
||||
this.editor = file.RegisteredViewContents[0] as TextEditorDisplayBindingWrapper; |
||||
} |
||||
|
||||
ElementHost wpfHost; |
||||
DesignSurface designer; |
||||
List<Task> tasks = new List<Task>(); |
||||
|
||||
// save text from editor when designer cannot be saved (e.g. invalid xml)
|
||||
TextEditorDisplayBindingWrapper editor; |
||||
|
||||
public DesignSurface DesignSurface { |
||||
get { return designer; } |
||||
} |
||||
|
||||
public DesignContext DesignContext { |
||||
get { return designer.DesignContext; } |
||||
} |
||||
|
||||
protected override void LoadInternal(OpenedFile file, System.IO.Stream stream) |
||||
{ |
||||
Debug.Assert(file == this.PrimaryFile); |
||||
|
||||
if (designer == null) { |
||||
// initialize designer on first load
|
||||
DragDropExceptionHandler.HandleException = ICSharpCode.Core.MessageService.ShowError; |
||||
designer = new DesignSurface(); |
||||
wpfHost = new SharpDevelopElementHost() { ViewContent = this, Child = designer }; |
||||
this.UserControl = wpfHost; |
||||
InitPropertyEditor(); |
||||
} |
||||
if (outline != null) { |
||||
outline.Root = null; |
||||
} |
||||
using (XmlTextReader r = new XmlTextReader(stream)) { |
||||
XamlLoadSettings settings = new XamlLoadSettings(); |
||||
settings.DesignerAssemblies.Add(typeof(WpfViewContent).Assembly); |
||||
settings.CustomServiceRegisterFunctions.Add( |
||||
delegate(XamlDesignContext context) { |
||||
context.Services.AddService(typeof(IUriContext), new FileUriContext(this.PrimaryFile)); |
||||
context.Services.AddService(typeof(IPropertyDescriptionService), new PropertyDescriptionService(this.PrimaryFile)); |
||||
context.Services.AddService(typeof(IEventHandlerService), new CSharpEventHandlerService(this)); |
||||
context.Services.AddService(typeof(ITopLevelWindowService), new WpfAndWinFormsTopLevelWindowService()); |
||||
context.Services.AddService(typeof(ChooseClassServiceBase), new IdeChooseClassService()); |
||||
}); |
||||
settings.TypeFinder = MyTypeFinder.Create(this.PrimaryFile); |
||||
|
||||
designer.LoadDesigner(r, settings); |
||||
|
||||
UpdateTasks(); |
||||
|
||||
if (outline != null && designer.DesignContext != null && designer.DesignContext.RootItem != null) { |
||||
outline.Root = OutlineNode.Create(designer.DesignContext.RootItem); |
||||
} |
||||
|
||||
propertyGridView.PropertyGrid.SelectedItems = null; |
||||
designer.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged; |
||||
designer.DesignContext.Services.GetService<UndoService>().UndoStackChanged += OnUndoStackChanged; |
||||
} |
||||
} |
||||
|
||||
protected override void SaveInternal(OpenedFile file, System.IO.Stream stream) |
||||
{ |
||||
if (designer.DesignContext.CanSave) { |
||||
XmlWriterSettings settings = new XmlWriterSettings(); |
||||
settings.Encoding = Encoding.UTF8; |
||||
settings.Indent = true; |
||||
settings.IndentChars = ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor.SharpDevelopTextEditorProperties.Instance.IndentationString; |
||||
settings.NewLineOnAttributes = true; |
||||
using (XmlWriter xmlWriter = XmlTextWriter.Create(stream, settings)) { |
||||
designer.SaveDesigner(xmlWriter); |
||||
} |
||||
} else { |
||||
editor.Save(file, stream); |
||||
} |
||||
} |
||||
|
||||
public override bool SupportsSwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView) |
||||
{ |
||||
return newView == editor && !designer.DesignContext.CanSave; |
||||
} |
||||
|
||||
void UpdateTasks() |
||||
{ |
||||
foreach (var task in tasks) { |
||||
TaskService.Remove(task); |
||||
} |
||||
|
||||
tasks.Clear(); |
||||
|
||||
var xamlErrorService = designer.DesignContext.Services.GetService<XamlErrorService>(); |
||||
foreach (var error in xamlErrorService.Errors) { |
||||
var task = new Task(PrimaryFile.FileName, error.Message, error.Column - 1, error.Line - 1, TaskType.Error); |
||||
tasks.Add(task); |
||||
TaskService.Add(task); |
||||
} |
||||
} |
||||
|
||||
void OnUndoStackChanged(object sender, EventArgs e) |
||||
{ |
||||
this.PrimaryFile.MakeDirty(); |
||||
} |
||||
|
||||
#region Property editor / SelectionChanged
|
||||
|
||||
ElementHost propertyEditorHost; |
||||
PropertyGridView propertyGridView; |
||||
|
||||
void InitPropertyEditor() |
||||
{ |
||||
propertyGridView = new PropertyGridView(); |
||||
propertyEditorHost = new SharpDevelopElementHost() { ViewContent = this, Child = propertyGridView}; |
||||
propertyContainer.PropertyGridReplacementControl = propertyEditorHost; |
||||
} |
||||
|
||||
void OnSelectionChanged(object sender, DesignItemCollectionEventArgs e) |
||||
{ |
||||
propertyGridView.PropertyGrid.SelectedItems = DesignContext.Services.Selection.SelectedItems; |
||||
} |
||||
|
||||
static bool IsCollectionWithSameElements(ICollection<DesignItem> a, ICollection<DesignItem> b) |
||||
{ |
||||
return ContainsAll(a, b) && ContainsAll(b, a); |
||||
} |
||||
|
||||
static bool ContainsAll(ICollection<DesignItem> a, ICollection<DesignItem> b) |
||||
{ |
||||
foreach (DesignItem item in a) { |
||||
if (!b.Contains(item)) |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
PropertyContainer propertyContainer = new PropertyContainer(); |
||||
|
||||
public PropertyContainer PropertyContainer { |
||||
get { return propertyContainer; } |
||||
} |
||||
#endregion
|
||||
|
||||
public Control ToolsControl { |
||||
get { return WpfToolbox.Instance.ToolboxControl; } |
||||
} |
||||
|
||||
public override void Dispose() |
||||
{ |
||||
propertyContainer.Clear(); |
||||
base.Dispose(); |
||||
} |
||||
|
||||
void OnIsActiveViewContentChanged(object sender, EventArgs e) |
||||
{ |
||||
if (IsActiveViewContent) { |
||||
if (designer != null && designer.DesignContext != null) { |
||||
WpfToolbox.Instance.ToolService = designer.DesignContext.Services.Tool; |
||||
} |
||||
} |
||||
} |
||||
|
||||
Outline outline; |
||||
|
||||
public Outline Outline { |
||||
get { |
||||
if (outline == null) { |
||||
outline = new Outline(); |
||||
if (DesignSurface != null && DesignSurface.DesignContext != null && DesignSurface.DesignContext.RootItem != null) { |
||||
outline.Root = OutlineNode.Create(DesignSurface.DesignContext.RootItem); |
||||
} |
||||
// see 3522
|
||||
outline.AddCommandHandler(ApplicationCommands.Delete, |
||||
() => ApplicationCommands.Delete.Execute(null, designer)); |
||||
} |
||||
return outline; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,77 +0,0 @@
@@ -1,77 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 2667$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Interop; |
||||
using System.Windows.Media; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
sealed class WpfAndWinFormsTopLevelWindowService : ITopLevelWindowService |
||||
{ |
||||
public ITopLevelWindow GetTopLevelWindow(UIElement element) |
||||
{ |
||||
Window window = Window.GetWindow(element); |
||||
if (window != null) { |
||||
return new WpfTopLevelWindow(window); |
||||
} |
||||
HwndSource hwndSource = PresentationSource.FromVisual(element) as HwndSource; |
||||
if (hwndSource != null) { |
||||
Control ctl = Control.FromChildHandle(hwndSource.Handle); |
||||
if (ctl != null) { |
||||
Form form = ctl.FindForm(); |
||||
if (form != null) { |
||||
return new WindowsFormsTopLevelWindow(form); |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
sealed class WpfTopLevelWindow : ITopLevelWindow |
||||
{ |
||||
Window window; |
||||
|
||||
public WpfTopLevelWindow(Window window) |
||||
{ |
||||
this.window = window; |
||||
} |
||||
|
||||
public void SetOwner(Window child) |
||||
{ |
||||
child.Owner = window; |
||||
} |
||||
|
||||
public bool Activate() |
||||
{ |
||||
return window.Activate(); |
||||
} |
||||
} |
||||
|
||||
sealed class WindowsFormsTopLevelWindow : ITopLevelWindow |
||||
{ |
||||
Form form; |
||||
|
||||
public WindowsFormsTopLevelWindow(Form form) |
||||
{ |
||||
this.form = form; |
||||
} |
||||
|
||||
public void SetOwner(Window child) |
||||
{ |
||||
(new WindowInteropHelper(child)).Owner = form.Handle; |
||||
} |
||||
|
||||
public bool Activate() |
||||
{ |
||||
return form.Focus(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,124 +0,0 @@
@@ -1,124 +0,0 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> |
||||
<PropertyGroup> |
||||
<ProjectGuid>{9A9D6FD4-6A2E-455D-ACC3-DDA775FE9865}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<OutputType>Library</OutputType> |
||||
<RootNamespace>ICSharpCode.WpfDesign.AddIn</RootNamespace> |
||||
<AssemblyName>ICSharpCode.WpfDesign.AddIn</AssemblyName> |
||||
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\WpfDesign\</OutputPath> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<NoStdLib>False</NoStdLib> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<Optimize>False</Optimize> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<PlatformTarget>AnyCPU</PlatformTarget> |
||||
<FileAlignment>4096</FileAlignment> |
||||
</PropertyGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
<ItemGroup> |
||||
<Reference Include="PresentationCore" /> |
||||
<Reference Include="PresentationFramework" /> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Drawing" /> |
||||
<Reference Include="System.Windows.Forms" /> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="WindowsBase" /> |
||||
<Reference Include="WindowsFormsIntegration" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<None Include="WpfDesign.addin"> |
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
||||
</None> |
||||
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs"> |
||||
<Link>Properties\GlobalAssemblyInfo.cs</Link> |
||||
</Compile> |
||||
<Compile Include="AbstractEventHandlerService.cs" /> |
||||
<Compile Include="WpfPrimaryDisplayBinding.cs" /> |
||||
<Compile Include="CSharpEventHandlerService.cs" /> |
||||
<Compile Include="IdeChooseClassService.cs" /> |
||||
<Compile Include="OutlineViewPad.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
<Compile Include="PropertyDescriptionService.cs" /> |
||||
<Compile Include="SharpDevelopElementHost.cs" /> |
||||
<Compile Include="WpfAndWinFormsTopLevelWindowService.cs" /> |
||||
<Compile Include="WpfPrimaryViewContent.cs" /> |
||||
<Compile Include="WpfSecondaryDisplayBinding.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="WpfSecondaryViewContent.cs" /> |
||||
<Compile Include="WpfTools.cs" /> |
||||
<Compile Include="XamlMapper.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj"> |
||||
<Project>{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}</Project> |
||||
<Name>ICSharpCode.TextEditor</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> |
||||
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> |
||||
<Name>ICSharpCode.SharpDevelop</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj"> |
||||
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project> |
||||
<Name>ICSharpCode.Core</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj"> |
||||
<Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project> |
||||
<Name>ICSharpCode.Core.WinForms</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj"> |
||||
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project> |
||||
<Name>ICSharpCode.SharpDevelop.Dom</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj"> |
||||
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project> |
||||
<Name>ICSharpCode.SharpDevelop.Widgets</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\BackendBindings\Xaml\Xaml\Xaml.csproj"> |
||||
<Project>{B4E5C965-7BB9-4AE9-85FB-C47480B879AD}</Project> |
||||
<Name>Xaml</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\FormsDesigner\Project\FormsDesigner.csproj"> |
||||
<Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project> |
||||
<Name>FormsDesigner</Name> |
||||
<Private>False</Private> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\WpfDesign.Designer\WpfDesign.Designer.csproj"> |
||||
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project> |
||||
<Name>WpfDesign.Designer</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\WpfDesign\WpfDesign.csproj"> |
||||
<Project>{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}</Project> |
||||
<Name>WpfDesign</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
</Project> |
@ -1,38 +0,0 @@
@@ -1,38 +0,0 @@
|
||||
<AddIn name = "WPF Designer AddIn" |
||||
author = "Daniel Grunwald" |
||||
copyright = "prj:///doc/copyright.txt" |
||||
description = "WPF Designer"> |
||||
|
||||
<Manifest> |
||||
<Identity name="ICSharpCode.WpfDesigner"/> |
||||
<Dependency addin = "ICSharpCode.FormsDesigner" requirePreload = "true"/> |
||||
</Manifest> |
||||
|
||||
<Runtime> |
||||
<Import assembly = "ICSharpCode.WpfDesign.AddIn.dll"/> |
||||
</Runtime> |
||||
|
||||
<Path name = "/SharpDevelop/Workbench/DisplayBindings"> |
||||
<DisplayBinding id = "WPFEditor" |
||||
insertbefore = "Text" |
||||
type = "Primary" |
||||
class = "ICSharpCode.WpfDesign.AddIn.WpfPrimaryDisplayBinding" |
||||
fileNamePattern = "\.xaml$"/> |
||||
</Path> |
||||
|
||||
<Path name = "/SharpDevelop/Workbench/DisplayBindings"> |
||||
<DisplayBinding id = "WPFDesigner" |
||||
type = "Secondary" |
||||
class = "ICSharpCode.WpfDesign.AddIn.WpfSecondaryDisplayBinding" |
||||
fileNamePattern = "\.xaml$"/> |
||||
</Path> |
||||
|
||||
<Path name = "/SharpDevelop/Workbench/Pads"> |
||||
<Pad id = "OutlineViewPad" |
||||
category = "Tools" |
||||
title = "${res:ICSharpCode.SharpDevelop.Gui.OutlinePad}" |
||||
icon = "PadIcons.BreakPoints" |
||||
shortcut = "Control|Alt|I" |
||||
class = "ICSharpCode.WpfDesign.AddIn.OutlineViewPad"/> |
||||
</Path> |
||||
</AddIn> |
@ -1,22 +0,0 @@
@@ -1,22 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 3497 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class WpfPrimaryDisplayBinding : TextEditorDisplayBinding |
||||
{ |
||||
protected override TextEditorDisplayBindingWrapper CreateWrapper(OpenedFile file) |
||||
{ |
||||
return new WpfPrimaryViewContent(file); |
||||
} |
||||
} |
||||
} |
@ -1,105 +0,0 @@
@@ -1,105 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.WpfDesign.Designer.XamlBackend; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.WpfDesign.Designer.Services; |
||||
using System.Windows.Threading; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class WpfPrimaryViewContent : TextEditorDisplayBindingWrapper, IWpfViewContent, IHasPropertyContainer, IUndoHandler, IToolsHost, IParseInformationListener |
||||
{ |
||||
public WpfPrimaryViewContent(OpenedFile file) |
||||
: base(file) |
||||
{ |
||||
} |
||||
|
||||
List<Task> tasks = new List<Task>(); |
||||
|
||||
public override void Load(OpenedFile file, Stream stream) |
||||
{ |
||||
base.Load(file, stream); |
||||
var doc = XamlMapper.GetXamlDocument(file.FileName); |
||||
Context = new XamlDesignContext(doc); |
||||
Context.AddService(typeof(IPropertyDescriptionService), new PropertyDescriptionService()); |
||||
Context.AddService(typeof(IEventHandlerService), new CSharpEventHandlerService(this)); |
||||
Context.AddService(typeof(ITopLevelWindowService), new WpfAndWinFormsTopLevelWindowService()); |
||||
Context.AddService(typeof(ChooseClassServiceBase), new IdeChooseClassService()); |
||||
Context.UndoService.UndoStackChanged += new EventHandler(Undo_UndoStackChanged); |
||||
Context.Parse(Text); |
||||
} |
||||
|
||||
void Undo_UndoStackChanged(object sender, EventArgs e) |
||||
{ |
||||
this.PrimaryFile.MakeDirty(); |
||||
} |
||||
|
||||
//public new void ParseInformationUpdated(ParseInformation parseInfo)
|
||||
//{
|
||||
// base.ParseInformationUpdated(parseInfo);
|
||||
|
||||
// Dispatcher.CurrentDispatcher.Invoke(new Action(delegate {
|
||||
// Context.Load(Text);
|
||||
// }));
|
||||
|
||||
// UpdateTasks();
|
||||
//}
|
||||
|
||||
void UpdateTasks() |
||||
{ |
||||
foreach (var task in tasks) { |
||||
TaskService.Remove(task); |
||||
} |
||||
|
||||
tasks.Clear(); |
||||
|
||||
foreach (var error in Context.Document.Errors) { |
||||
var task = new Task(PrimaryFile.FileName, error.Message, error.LinePosition - 1, error.LineNumber - 1, TaskType.Error); |
||||
tasks.Add(task); |
||||
TaskService.Add(task); |
||||
} |
||||
} |
||||
|
||||
#region WpfViewContent Implementation
|
||||
|
||||
public XamlDesignContext Context { get; private set; } |
||||
|
||||
public PropertyContainer PropertyContainer |
||||
{ |
||||
get { return WpfTools.PropertyContainer; } |
||||
} |
||||
|
||||
public System.Windows.Forms.Control ToolsControl |
||||
{ |
||||
get { return WpfTools.ToolboxHost; } |
||||
} |
||||
|
||||
public bool EnableRedo |
||||
{ |
||||
get { return Context.UndoService.CanRedo; } |
||||
} |
||||
|
||||
public bool EnableUndo |
||||
{ |
||||
get { return Context.UndoService.CanUndo; } |
||||
} |
||||
|
||||
public void Redo() |
||||
{ |
||||
Context.UndoService.Redo(); |
||||
} |
||||
|
||||
public void Undo() |
||||
{ |
||||
Context.UndoService.Undo(); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -1,38 +0,0 @@
@@ -1,38 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 3497 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using System.Xml; |
||||
using ICSharpCode.Xaml; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class WpfSecondaryDisplayBinding : ISecondaryDisplayBinding |
||||
{ |
||||
public bool ReattachWhenParserServiceIsReady |
||||
{ |
||||
get |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool CanAttachTo(IViewContent content) |
||||
{ |
||||
return XamlConstants.HasXamlExtension(content.PrimaryFileName); |
||||
} |
||||
|
||||
public IViewContent[] CreateSecondaryViewContent(IViewContent viewContent) |
||||
{ |
||||
return new IViewContent[] { new WpfSecondaryViewContent(viewContent as WpfPrimaryViewContent) }; |
||||
} |
||||
} |
||||
} |
@ -1,108 +0,0 @@
@@ -1,108 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 3528 $</version>
|
||||
// </file>
|
||||
|
||||
using ICSharpCode.WpfDesign.Designer.OutlineView; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Integration; |
||||
using System.Windows.Markup; |
||||
using System.Xml; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.WpfDesign.Designer; |
||||
using ICSharpCode.WpfDesign.Designer.PropertyGrid; |
||||
using ICSharpCode.WpfDesign.Designer.Services; |
||||
using ICSharpCode.WpfDesign.PropertyGrid; |
||||
using System.Windows.Input; |
||||
using ICSharpCode.WpfDesign.Designer.XamlBackend; |
||||
using ICSharpCode.Xaml; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// IViewContent implementation that hosts the WPF designer.
|
||||
/// </summary>
|
||||
public class WpfSecondaryViewContent : AbstractViewContent, IWpfViewContent, IHasPropertyContainer, IUndoHandler, IToolsHost |
||||
{ |
||||
public WpfSecondaryViewContent(WpfPrimaryViewContent primaryViewContent) |
||||
{ |
||||
this.primaryViewContent = primaryViewContent; |
||||
this.TabPageText = "${res:FormsDesigner.DesignTabPages.DesignTabPage}"; |
||||
} |
||||
|
||||
WpfPrimaryViewContent primaryViewContent; |
||||
|
||||
public override Control Control |
||||
{ |
||||
get { return WpfTools.DesignerHost; } |
||||
} |
||||
|
||||
public override void Load(OpenedFile file, Stream stream) |
||||
{ |
||||
Context.Parse(new StreamReader(stream).ReadToEnd()); |
||||
} |
||||
|
||||
public override void Save(OpenedFile file, Stream stream) |
||||
{ |
||||
if (Context.CanSave) { |
||||
new StreamWriter(stream).Write(Context.Save()); |
||||
} |
||||
else { |
||||
primaryViewContent.Save(file, stream); |
||||
} |
||||
} |
||||
|
||||
public override bool SupportsSwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView) |
||||
{ |
||||
return newView == primaryViewContent && !Context.CanSave; |
||||
} |
||||
|
||||
#region WpfViewContent Implementation
|
||||
|
||||
public XamlDesignContext Context |
||||
{ |
||||
get { return primaryViewContent.Context; } |
||||
} |
||||
|
||||
public PropertyContainer PropertyContainer |
||||
{ |
||||
get { return WpfTools.PropertyContainer; } |
||||
} |
||||
|
||||
public System.Windows.Forms.Control ToolsControl |
||||
{ |
||||
get { return WpfTools.ToolboxHost; } |
||||
} |
||||
|
||||
public bool EnableRedo |
||||
{ |
||||
get { return Context.UndoService.CanRedo; } |
||||
} |
||||
|
||||
public bool EnableUndo |
||||
{ |
||||
get { return Context.UndoService.CanUndo; } |
||||
} |
||||
|
||||
public void Redo() |
||||
{ |
||||
Context.UndoService.Redo(); |
||||
} |
||||
|
||||
public void Undo() |
||||
{ |
||||
Context.UndoService.Undo(); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -1,37 +0,0 @@
@@ -1,37 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 2573 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.WpfDesign.Designer.Services; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Description of WpfSideTabItem.
|
||||
/// </summary>
|
||||
public class WpfSideTabItem : SharpDevelopSideTabItem |
||||
{ |
||||
public WpfSideTabItem(Type componentType) : base(componentType.Name, new CreateComponentTool(componentType)) |
||||
{ |
||||
CanBeRenamed = false; |
||||
// this.Icon = tag.Bitmap;
|
||||
} |
||||
|
||||
///<summary>create a default tabitem : a pointer icon with an empty toolboxitem</summary>
|
||||
public WpfSideTabItem() : base("Pointer") |
||||
{ |
||||
CanBeRenamed = false; |
||||
CanBeDeleted = false; |
||||
Bitmap pointerBitmap = new Bitmap(IconService.GetBitmap("Icons.16x16.FormsDesigner.PointerIcon"), 16, 16); |
||||
this.Icon = pointerBitmap; |
||||
this.Tag = null; |
||||
} |
||||
} |
||||
} |
@ -1,128 +0,0 @@
@@ -1,128 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 3435 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Widgets.SideBar; |
||||
using WPF = System.Windows.Controls; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Manages the WpfToolbox.
|
||||
/// </summary>
|
||||
public class WpfToolbox |
||||
{ |
||||
static WpfToolbox instance; |
||||
|
||||
public static WpfToolbox Instance { |
||||
get { |
||||
WorkbenchSingleton.AssertMainThread(); |
||||
if (instance == null) { |
||||
instance = new WpfToolbox(); |
||||
} |
||||
return instance; |
||||
} |
||||
} |
||||
|
||||
IToolService toolService; |
||||
WpfSideBar sideBar; |
||||
|
||||
public WpfToolbox() |
||||
{ |
||||
sideBar = new WpfSideBar(); |
||||
SideTab sideTab = new SideTab(sideBar, "Windows Presentation Foundation"); |
||||
sideTab.DisplayName = StringParser.Parse(sideTab.Name); |
||||
sideTab.CanBeDeleted = false; |
||||
sideTab.ChoosedItemChanged += OnChoosedItemChanged; |
||||
|
||||
sideTab.Items.Add(new WpfSideTabItem()); |
||||
//foreach (Type t in Metadata.GetPopularControls())
|
||||
// sideTab.Items.Add(new WpfSideTabItem(t));
|
||||
|
||||
sideBar.Tabs.Add(sideTab); |
||||
sideBar.ActiveTab = sideTab; |
||||
} |
||||
|
||||
void OnChoosedItemChanged(object sender, EventArgs e) |
||||
{ |
||||
if (toolService != null) { |
||||
ITool newTool = null; |
||||
if (sideBar.ActiveTab != null && sideBar.ActiveTab.ChoosedItem != null) { |
||||
newTool = sideBar.ActiveTab.ChoosedItem.Tag as ITool; |
||||
} |
||||
toolService.CurrentTool = newTool ?? toolService.PointerTool; |
||||
} |
||||
} |
||||
|
||||
public Control ToolboxControl { |
||||
get { return sideBar; } |
||||
} |
||||
|
||||
public IToolService ToolService { |
||||
get { return toolService; } |
||||
set { |
||||
if (toolService != null) { |
||||
toolService.CurrentToolChanged -= OnCurrentToolChanged; |
||||
} |
||||
toolService = value; |
||||
if (toolService != null) { |
||||
toolService.CurrentToolChanged += OnCurrentToolChanged; |
||||
OnCurrentToolChanged(null, null); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void OnCurrentToolChanged(object sender, EventArgs e) |
||||
{ |
||||
object tagToFind; |
||||
if (toolService.CurrentTool == toolService.PointerTool) { |
||||
tagToFind = null; |
||||
} else { |
||||
tagToFind = toolService.CurrentTool; |
||||
} |
||||
if (sideBar.ActiveTab.ChoosedItem != null) { |
||||
if (sideBar.ActiveTab.ChoosedItem.Tag == tagToFind) |
||||
return; |
||||
} |
||||
foreach (SideTabItem item in sideBar.ActiveTab.Items) { |
||||
if (item.Tag == tagToFind) { |
||||
sideBar.ActiveTab.ChoosedItem = item; |
||||
sideBar.Refresh(); |
||||
return; |
||||
} |
||||
} |
||||
foreach (SideTab tab in sideBar.Tabs) { |
||||
foreach (SideTabItem item in tab.Items) { |
||||
if (item.Tag == tagToFind) { |
||||
sideBar.ActiveTab = tab; |
||||
sideBar.ActiveTab.ChoosedItem = item; |
||||
sideBar.Refresh(); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
sideBar.ActiveTab.ChoosedItem = null; |
||||
sideBar.Refresh(); |
||||
} |
||||
|
||||
sealed class WpfSideBar : SharpDevelopSideBar |
||||
{ |
||||
protected override object StartItemDrag(SideTabItem draggedItem) |
||||
{ |
||||
if (this.ActiveTab.ChoosedItem != draggedItem && this.ActiveTab.Items.Contains(draggedItem)) { |
||||
this.ActiveTab.ChoosedItem = draggedItem; |
||||
} |
||||
return new System.Windows.DataObject(draggedItem.Tag); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,94 +0,0 @@
@@ -1,94 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using ICSharpCode.WpfDesign.Designer; |
||||
using ICSharpCode.WpfDesign.Designer.OutlineView; |
||||
using ICSharpCode.WpfDesign.Designer.PropertyGrid; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.WpfDesign.Designer.XamlBackend; |
||||
using System.Windows.Input; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public static class WpfTools |
||||
{ |
||||
static WpfTools() |
||||
{ |
||||
CreateToolbox(); |
||||
CreateOutline(); |
||||
CreatePropertyGrid(); |
||||
CreateDesigner(); |
||||
|
||||
WorkbenchSingleton.Workbench.ActiveViewContentChanged += new EventHandler(Workbench_ActiveViewContentChanged); |
||||
} |
||||
|
||||
public static Toolbox Toolbox; |
||||
public static Outline Outline; |
||||
public static PropertyGridView PropertyGridView; |
||||
public static DesignSurface Designer; |
||||
|
||||
public static SharpDevelopElementHost ToolboxHost; |
||||
public static SharpDevelopElementHost OutlineHost; |
||||
public static SharpDevelopElementHost PropertyGridViewHost; |
||||
public static SharpDevelopElementHost DesignerHost; |
||||
|
||||
public static PropertyContainer PropertyContainer; |
||||
|
||||
public static DesignContext ActiveContext |
||||
{ |
||||
get |
||||
{ |
||||
var wpfViewContent = WorkbenchSingleton.Workbench.ActiveViewContent as IWpfViewContent; |
||||
if (wpfViewContent != null) { |
||||
return wpfViewContent.Context; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
static void CreateToolbox() |
||||
{ |
||||
Toolbox = new Toolbox(); |
||||
ToolboxHost = new SharpDevelopElementHost(Toolbox); |
||||
} |
||||
|
||||
static void CreateOutline() |
||||
{ |
||||
Outline = new Outline(); |
||||
OutlineHost = new SharpDevelopElementHost(Outline); |
||||
|
||||
// see 3522
|
||||
Outline.AddCommandHandler(ApplicationCommands.Delete, |
||||
() => ApplicationCommands.Delete.Execute(null, Designer)); |
||||
} |
||||
|
||||
static void CreatePropertyGrid() |
||||
{ |
||||
PropertyGridView = new PropertyGridView(); |
||||
PropertyGridViewHost = new SharpDevelopElementHost(PropertyGridView); |
||||
PropertyContainer = new PropertyContainer(); |
||||
PropertyContainer.PropertyGridReplacementControl = PropertyGridViewHost; |
||||
} |
||||
|
||||
static void CreateDesigner() |
||||
{ |
||||
Designer = new DesignSurface(); |
||||
DesignerHost = new SharpDevelopElementHost(Designer); |
||||
DragDropExceptionHandler.HandleException = ICSharpCode.Core.MessageService.ShowError; |
||||
} |
||||
|
||||
static void Workbench_ActiveViewContentChanged(object sender, EventArgs e) |
||||
{ |
||||
Toolbox.Context = ActiveContext; |
||||
Outline.Context = ActiveContext; |
||||
PropertyGridView.Context = ActiveContext; |
||||
Designer.Context = ActiveContext; |
||||
} |
||||
} |
||||
|
||||
public interface IWpfViewContent |
||||
{ |
||||
XamlDesignContext Context { get; } |
||||
} |
||||
} |
@ -1,201 +0,0 @@
@@ -1,201 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.Xaml; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using System.IO; |
||||
using System.Windows.Markup; |
||||
using ICSharpCode.SharpDevelop; |
||||
using System.Reflection; |
||||
using ICSharpCode.FormsDesigner.Services; |
||||
using ICSharpCode.WpfDesign.Designer.XamlBackend; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class XamlMapper |
||||
{ |
||||
static XamlMapper() |
||||
{ |
||||
ProjectService.SolutionLoaded += new EventHandler<SolutionEventArgs>(ProjectService_SolutionLoaded); |
||||
} |
||||
|
||||
static void ProjectService_SolutionLoaded(object sender, SolutionEventArgs e) |
||||
{ |
||||
//throw new NotImplementedException();
|
||||
} |
||||
|
||||
//TODO xamlDocs
|
||||
static Dictionary<IProject, XamlProject> xamlProjects = new Dictionary<IProject, XamlProject>(); |
||||
|
||||
public static TypeResolutionService TypeResolutionServiceInstance = new TypeResolutionService(); |
||||
|
||||
public static XamlProject GetXamlProject(IProject p) |
||||
{ |
||||
XamlProject result; |
||||
if (!xamlProjects.TryGetValue(p, out result)) { |
||||
result = CreateXamlProject(p); |
||||
xamlProjects[p] = result; |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
static XamlProject CreateXamlProject(IProject domProject) |
||||
{ |
||||
var result = new WpfProject(); |
||||
|
||||
var projectContent = ParserService.GetProjectContent(domProject); |
||||
result.ProjectAssembly = GetXamlAssembly(projectContent); |
||||
|
||||
foreach (var referenceContent in projectContent.ReferencedContents) { |
||||
result.AddReference(GetXamlAssembly(referenceContent)); |
||||
} |
||||
|
||||
foreach (var item in domProject.Items) { |
||||
if (item.ItemType == ItemType.Page) { |
||||
if (XamlConstants.HasXamlExtension(item.FileName)) { |
||||
result.LoadDocument(item.FileName); |
||||
} |
||||
} |
||||
//else if (item.ItemType == ItemType.ApplicationDefinition) {
|
||||
// result.ApplicationDefinition = result.LoadDocument(item.FileName);
|
||||
//}
|
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
public static XamlAssembly GetXamlAssembly(IProjectContent projectContent) |
||||
{ |
||||
if (projectContent is ReflectionProjectContent) { |
||||
var assembly = TypeResolutionServiceInstance.LoadAssembly(projectContent); |
||||
return ReflectionMapper.GetXamlAssembly(assembly); |
||||
} |
||||
return new IdeXamlAssembly(projectContent); |
||||
} |
||||
|
||||
public static XamlDocument GetXamlDocument(string filePath) |
||||
{ |
||||
if (ProjectService.OpenSolution != null) { |
||||
var domProject = ProjectService.OpenSolution.FindProjectContainingFile(filePath); |
||||
if (domProject != null) { |
||||
var xamlProject = GetXamlProject(domProject); |
||||
if (xamlProject != null) { |
||||
return xamlProject.LoadDocument(filePath); |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static XamlType GetXamlType(IClass c) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
//return c.UserData as XamlType;
|
||||
} |
||||
|
||||
public static XamlMember GetXamlMember(IMember m) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public static IProject GetDomProject(XamlProject p) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public static IClass GetDomClass(XamlType t) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public static IMember GetDomMember(XamlMember m) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
//static IProjectContent GetProjectContent(OpenedFile file)
|
||||
//{
|
||||
// if ((ProjectService.OpenSolution != null) && (file != null))
|
||||
// {
|
||||
// IProject p = ProjectService.OpenSolution.FindProjectContainingFile(file.FileName);
|
||||
// if (p != null)
|
||||
// {
|
||||
// return ParserService.GetProjectContent(p);
|
||||
// }
|
||||
// }
|
||||
// return ParserService.DefaultProjectContent;
|
||||
//}
|
||||
|
||||
//IProjectContent pc = GetProjectContent(file);
|
||||
//if (pc != null) {
|
||||
// IClass c = pc.GetClassByReflectionName(property.DeclaringType.FullName, true);
|
||||
// if (c != null) {
|
||||
// IMember m = DefaultProjectContent.GetMemberByReflectionName(c, property.Name);
|
||||
// if (m != null)
|
||||
// return CodeCompletionData.GetDocumentation(m.Documentation);
|
||||
// }
|
||||
//}
|
||||
//return null;
|
||||
} |
||||
|
||||
class IdeXamlAssembly : XamlAssembly |
||||
{ |
||||
public IdeXamlAssembly(IProjectContent projectContent) |
||||
{ |
||||
this.ProjectContent = projectContent; |
||||
} |
||||
|
||||
public IProjectContent ProjectContent { get; private set; } |
||||
|
||||
public override IEnumerable<XmlnsDefinitionAttribute> XmlnsDefinitions |
||||
{ |
||||
get { yield break; } |
||||
} |
||||
|
||||
public override string Name |
||||
{ |
||||
get { return GetName(ProjectContent); } |
||||
} |
||||
|
||||
public override XamlType GetType(string fullName) |
||||
{ |
||||
var domClass = ProjectContent.GetClass(fullName, 0); |
||||
return new IdeXamlType(domClass); |
||||
} |
||||
|
||||
static string GetName(IProjectContent projectContent) |
||||
{ |
||||
var reflection = projectContent as ReflectionProjectContent; |
||||
if (reflection != null) { |
||||
return new AssemblyName(reflection.AssemblyFullName).Name; |
||||
} |
||||
var project = projectContent.Project as IProject; |
||||
if (project != null) { |
||||
return project.Name; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
class IdeXamlType : DefaultXamlType |
||||
{ |
||||
public IdeXamlType(IClass domClass) |
||||
{ |
||||
this.Class = domClass; |
||||
} |
||||
|
||||
public IClass Class { get; private set; } |
||||
} |
||||
|
||||
class IdeXamlMember : DefaultXamlMember |
||||
{ |
||||
public IdeXamlMember(IMember domMember) |
||||
{ |
||||
this.Member = domMember; |
||||
} |
||||
|
||||
public IMember Member { get; private set; } |
||||
} |
||||
} |
@ -1,256 +0,0 @@
@@ -1,256 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows.Media; |
||||
using System.Windows; |
||||
using System.Windows.Input; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Controls.Primitives; |
||||
using System.Windows.Media.Imaging; |
||||
using System.Windows.Media.Media3D; |
||||
using System.Windows.Shapes; |
||||
using System.Windows.Media.Animation; |
||||
using System.Windows.Data; |
||||
using System.Windows.Automation; |
||||
using System.Windows.Media.Effects; |
||||
using System.Windows.Navigation; |
||||
using ICSharpCode.Xaml; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer |
||||
{ |
||||
public class BasicMetadata : IRegisterMetadata |
||||
{ |
||||
public void Register() |
||||
{ |
||||
Metadata.StandardValueAdded += new EventHandler<StandardValueEventArgs>(Metadata_StandardValueAdded); |
||||
Metadata.TypeReplacerAdded += new EventHandler<TypeEventArgs>(Metadata_TypeReplacerAdded); |
||||
|
||||
Metadata.AddStandardValues(typeof(Brush), typeof(Brushes)); |
||||
Metadata.AddStandardValues(typeof(Color), typeof(Colors)); |
||||
Metadata.AddStandardValues(typeof(FontStretch), typeof(FontStretches)); |
||||
Metadata.AddStandardValues(typeof(FontWeight), typeof(FontWeights)); |
||||
Metadata.AddStandardValues(typeof(FontStyle), typeof(FontStyles)); |
||||
Metadata.AddStandardValues(typeof(Cursor), typeof(Cursors)); |
||||
Metadata.AddStandardValues(typeof(PixelFormat), typeof(PixelFormats)); |
||||
Metadata.AddStandardValues(typeof(TextDecorationCollection), typeof(TextDecorations)); |
||||
|
||||
Metadata.AddStandardValues(typeof(ICommand), typeof(ApplicationCommands)); |
||||
Metadata.AddStandardValues(typeof(ICommand), typeof(EditingCommands)); |
||||
Metadata.AddStandardValues(typeof(ICommand), typeof(NavigationCommands)); |
||||
Metadata.AddStandardValues(typeof(ICommand), typeof(ComponentCommands)); |
||||
Metadata.AddStandardValues(typeof(ICommand), typeof(MediaCommands)); |
||||
|
||||
Metadata.AddStandardValues(typeof(FontFamily), Fonts.SystemFontFamilies |
||||
.Select(f => new StandardValue() { Instance = f, Text = f.Source })); |
||||
|
||||
Metadata.AddPopularProperty(Line.Y2Property); |
||||
Metadata.AddPopularProperty(NavigationWindow.ShowsNavigationUIProperty); |
||||
Metadata.AddPopularProperty(FlowDocumentScrollViewer.DocumentProperty); |
||||
Metadata.AddPopularProperty(GridViewRowPresenterBase.ColumnsProperty); |
||||
Metadata.AddPopularProperty(ListView.ViewProperty); |
||||
Metadata.AddPopularProperty(DocumentPageView.PageNumberProperty); |
||||
Metadata.AddPopularProperty(Popup.PlacementProperty); |
||||
Metadata.AddPopularProperty(Popup.PopupAnimationProperty); |
||||
Metadata.AddPopularProperty(ScrollBar.ViewportSizeProperty); |
||||
Metadata.AddPopularProperty(UniformGrid.RowsProperty); |
||||
Metadata.AddPopularProperty(TabControl.TabStripPlacementProperty); |
||||
Metadata.AddPopularProperty(Line.X1Property); |
||||
Metadata.AddPopularProperty(Line.Y1Property); |
||||
Metadata.AddPopularProperty(Line.X2Property); |
||||
Metadata.AddPopularProperty(Polygon.PointsProperty); |
||||
Metadata.AddPopularProperty(Polyline.PointsProperty); |
||||
Metadata.AddPopularProperty(Path.DataProperty); |
||||
Metadata.AddPopularProperty(HeaderedContentControl.HeaderProperty); |
||||
Metadata.AddPopularProperty(MediaElement.UnloadedBehaviorProperty); |
||||
Metadata.AddPopularProperty(Shape.FillProperty); |
||||
Metadata.AddPopularProperty(Page.TitleProperty); |
||||
Metadata.AddPopularProperty(ItemsControl.ItemsSourceProperty); |
||||
Metadata.AddPopularProperty(Image.SourceProperty); |
||||
Metadata.AddPopularProperty(TextBlock.TextProperty); |
||||
Metadata.AddPopularProperty(DockPanel.LastChildFillProperty); |
||||
Metadata.AddPopularProperty(Expander.IsExpandedProperty); |
||||
Metadata.AddPopularProperty(Shape.StrokeProperty); |
||||
Metadata.AddPopularProperty(RangeBase.ValueProperty); |
||||
Metadata.AddPopularProperty(ItemsControl.ItemContainerStyleProperty); |
||||
Metadata.AddPopularProperty(ToggleButton.IsCheckedProperty); |
||||
Metadata.AddPopularProperty(Window.TitleProperty); |
||||
Metadata.AddPopularProperty(Viewport3DVisual.CameraProperty); |
||||
Metadata.AddPopularProperty(Frame.SourceProperty); |
||||
Metadata.AddPopularProperty(Rectangle.RadiusXProperty); |
||||
Metadata.AddPopularProperty(Rectangle.RadiusYProperty); |
||||
Metadata.AddPopularProperty(FrameworkElement.HeightProperty); |
||||
Metadata.AddPopularProperty(FrameworkElement.WidthProperty); |
||||
Metadata.AddPopularProperty(UniformGrid.ColumnsProperty); |
||||
Metadata.AddPopularProperty(RangeBase.MinimumProperty); |
||||
Metadata.AddPopularProperty(RangeBase.MaximumProperty); |
||||
Metadata.AddPopularProperty(ScrollBar.OrientationProperty); |
||||
Metadata.AddPopularProperty(ContentControl.ContentProperty); |
||||
Metadata.AddPopularProperty(Popup.IsOpenProperty); |
||||
Metadata.AddPopularProperty(TextElement.FontSizeProperty); |
||||
Metadata.AddPopularProperty(FrameworkElement.NameProperty); |
||||
Metadata.AddPopularProperty(Popup.HorizontalOffsetProperty); |
||||
Metadata.AddPopularProperty(Popup.VerticalOffsetProperty); |
||||
Metadata.AddPopularProperty(Window.WindowStyleProperty); |
||||
Metadata.AddPopularProperty(Shape.StrokeThicknessProperty); |
||||
Metadata.AddPopularProperty(TextElement.ForegroundProperty); |
||||
Metadata.AddPopularProperty(FrameworkElement.VerticalAlignmentProperty); |
||||
Metadata.AddPopularProperty(Button.IsDefaultProperty); |
||||
Metadata.AddPopularProperty(UIElement.RenderTransformOriginProperty); |
||||
Metadata.AddPopularProperty(TextElement.FontFamilyProperty); |
||||
Metadata.AddPopularProperty(FrameworkElement.HorizontalAlignmentProperty); |
||||
Metadata.AddPopularProperty(ToolBar.BandProperty); |
||||
Metadata.AddPopularProperty(ToolBar.BandIndexProperty); |
||||
Metadata.AddPopularProperty(ItemsControl.ItemTemplateProperty); |
||||
Metadata.AddPopularProperty(TextBlock.TextWrappingProperty); |
||||
Metadata.AddPopularProperty(FrameworkElement.MarginProperty); |
||||
Metadata.AddPopularProperty(RangeBase.LargeChangeProperty); |
||||
Metadata.AddPopularProperty(RangeBase.SmallChangeProperty); |
||||
Metadata.AddPopularProperty(Panel.BackgroundProperty); |
||||
Metadata.AddPopularProperty(Shape.StrokeMiterLimitProperty); |
||||
Metadata.AddPopularProperty(TextElement.FontWeightProperty); |
||||
Metadata.AddPopularProperty(StackPanel.OrientationProperty); |
||||
Metadata.AddPopularProperty(ListBox.SelectionModeProperty); |
||||
Metadata.AddPopularProperty(FrameworkElement.StyleProperty); |
||||
Metadata.AddPopularProperty(TextBox.TextProperty); |
||||
Metadata.AddPopularProperty(Window.SizeToContentProperty); |
||||
Metadata.AddPopularProperty(Window.ResizeModeProperty); |
||||
Metadata.AddPopularProperty(TextBlock.TextTrimmingProperty); |
||||
Metadata.AddPopularProperty(Window.ShowInTaskbarProperty); |
||||
Metadata.AddPopularProperty(Window.IconProperty); |
||||
Metadata.AddPopularProperty(UIElement.RenderTransformProperty); |
||||
Metadata.AddPopularProperty(Button.IsCancelProperty); |
||||
Metadata.AddPopularProperty(Border.BorderBrushProperty); |
||||
Metadata.AddPopularProperty(Block.TextAlignmentProperty); |
||||
Metadata.AddPopularProperty(Border.CornerRadiusProperty); |
||||
Metadata.AddPopularProperty(Border.BorderThicknessProperty); |
||||
Metadata.AddPopularProperty(TreeViewItem.IsSelectedProperty); |
||||
Metadata.AddPopularProperty(Border.PaddingProperty); |
||||
Metadata.AddPopularProperty(Shape.StretchProperty); |
||||
|
||||
Metadata.AddPopularProperty(typeof(Binding), "Path"); |
||||
Metadata.AddPopularProperty(typeof(Binding), "Source"); |
||||
Metadata.AddPopularProperty(typeof(Binding), "Mode"); |
||||
Metadata.AddPopularProperty(typeof(Binding), "RelativeSource"); |
||||
Metadata.AddPopularProperty(typeof(Binding), "ElementName"); |
||||
Metadata.AddPopularProperty(typeof(Binding), "Converter"); |
||||
Metadata.AddPopularProperty(typeof(Binding), "XPath"); |
||||
|
||||
Metadata.AddValueRange(Block.LineHeightProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(Canvas.BottomProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Canvas.LeftProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Canvas.TopProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Canvas.RightProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(ColumnDefinition.MaxWidthProperty, 0, double.PositiveInfinity); |
||||
Metadata.AddValueRange(DocumentViewer.MaxPagesAcrossProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(Figure.HorizontalOffsetProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Figure.VerticalOffsetProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(FlowDocument.MaxPageWidthProperty, 0, double.PositiveInfinity); |
||||
Metadata.AddValueRange(FlowDocument.MaxPageHeightProperty, 0, double.PositiveInfinity); |
||||
Metadata.AddValueRange(FlowDocumentPageViewer.ZoomProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(FlowDocumentPageViewer.ZoomIncrementProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(FlowDocumentPageViewer.MinZoomProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(FlowDocumentPageViewer.MaxZoomProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(FrameworkElement.MaxHeightProperty, 0, double.PositiveInfinity); |
||||
Metadata.AddValueRange(FrameworkElement.MaxWidthProperty, 0, double.PositiveInfinity); |
||||
Metadata.AddValueRange(Grid.ColumnSpanProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(Grid.RowSpanProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(GridSplitter.KeyboardIncrementProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(GridSplitter.DragIncrementProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(InkCanvas.BottomProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(InkCanvas.TopProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(InkCanvas.RightProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(InkCanvas.LeftProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Line.Y2Property, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Line.X1Property, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Line.Y1Property, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Line.X2Property, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(List.MarkerOffsetProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(List.StartIndexProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(Paragraph.TextIndentProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(RangeBase.ValueProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(RangeBase.MaximumProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(RangeBase.MinimumProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(RepeatButton.IntervalProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(RowDefinition.MaxHeightProperty, 0, double.PositiveInfinity); |
||||
Metadata.AddValueRange(Selector.SelectedIndexProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Slider.TickFrequencyProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Slider.SelectionStartProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(Slider.SelectionEndProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(TableCell.RowSpanProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(TableCell.ColumnSpanProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(TextBox.MinLinesProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(TextBox.MaxLinesProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(TextBoxBase.UndoLimitProperty, double.MinValue, double.MaxValue); |
||||
Metadata.AddValueRange(TextElement.FontSizeProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(Timeline.SpeedRatioProperty, double.Epsilon, double.MaxValue); |
||||
Metadata.AddValueRange(Timeline.DecelerationRatioProperty, 0, 1); |
||||
Metadata.AddValueRange(Timeline.AccelerationRatioProperty, 0, 1); |
||||
Metadata.AddValueRange(Track.ViewportSizeProperty, 0, double.PositiveInfinity); |
||||
Metadata.AddValueRange(UIElement.OpacityProperty, 0, 1); |
||||
|
||||
Metadata.HideProperty(typeof(UIElement), "RenderSize"); |
||||
Metadata.HideProperty(FrameworkElement.NameProperty); |
||||
Metadata.HideProperty(typeof(FrameworkElement), "Resources"); |
||||
Metadata.HideProperty(typeof(Window), "Owner"); |
||||
|
||||
//Metadata.DisablePlacement(typeof(Button));
|
||||
|
||||
//Metadata.AddPopularControl(typeof(Button));
|
||||
//Metadata.AddPopularControl(typeof(CheckBox));
|
||||
//Metadata.AddPopularControl(typeof(ComboBox));
|
||||
//Metadata.AddPopularControl(typeof(Label));
|
||||
//Metadata.AddPopularControl(typeof(TextBox));
|
||||
//Metadata.AddPopularControl(typeof(RadioButton));
|
||||
//Metadata.AddPopularControl(typeof(Canvas));
|
||||
//Metadata.AddPopularControl(typeof(Grid));
|
||||
//Metadata.AddPopularControl(typeof(Border));
|
||||
//Metadata.AddPopularControl(typeof(DockPanel));
|
||||
//Metadata.AddPopularControl(typeof(Expander));
|
||||
//Metadata.AddPopularControl(typeof(GroupBox));
|
||||
//Metadata.AddPopularControl(typeof(Image));
|
||||
//Metadata.AddPopularControl(typeof(InkCanvas));
|
||||
//Metadata.AddPopularControl(typeof(ListBox));
|
||||
//Metadata.AddPopularControl(typeof(ListView));
|
||||
//Metadata.AddPopularControl(typeof(Menu));
|
||||
//Metadata.AddPopularControl(typeof(PasswordBox));
|
||||
//Metadata.AddPopularControl(typeof(ProgressBar));
|
||||
//Metadata.AddPopularControl(typeof(RichTextBox));
|
||||
//Metadata.AddPopularControl(typeof(ScrollViewer));
|
||||
//Metadata.AddPopularControl(typeof(Slider));
|
||||
//Metadata.AddPopularControl(typeof(StackPanel));
|
||||
//Metadata.AddPopularControl(typeof(TabControl));
|
||||
//Metadata.AddPopularControl(typeof(ToolBar));
|
||||
//Metadata.AddPopularControl(typeof(TreeView));
|
||||
//Metadata.AddPopularControl(typeof(Viewbox));
|
||||
//Metadata.AddPopularControl(typeof(Viewport3D));
|
||||
//Metadata.AddPopularControl(typeof(WrapPanel));
|
||||
|
||||
Metadata.AddDefaultSize(typeof(UIElement), new Size(120, 100)); |
||||
Metadata.AddDefaultSize(typeof(ContentControl), new Size(double.NaN, double.NaN)); |
||||
Metadata.AddDefaultSize(typeof(Button), new Size(75, 23)); |
||||
|
||||
var s1 = new Size(120, double.NaN); |
||||
Metadata.AddDefaultSize(typeof(Slider), s1); |
||||
Metadata.AddDefaultSize(typeof(TextBox), s1); |
||||
Metadata.AddDefaultSize(typeof(PasswordBox), s1); |
||||
Metadata.AddDefaultSize(typeof(ComboBox), s1); |
||||
Metadata.AddDefaultSize(typeof(ProgressBar), s1); |
||||
|
||||
var s2 = new Size(120, 20); |
||||
Metadata.AddDefaultSize(typeof(ToolBar), s2); |
||||
Metadata.AddDefaultSize(typeof(Menu), s2); |
||||
} |
||||
|
||||
void Metadata_TypeReplacerAdded(object sender, TypeEventArgs e) |
||||
{ |
||||
Runtime.AddTypeReplacer(e.Type, Metadata.GetTypeReplacer(e.Type)); |
||||
} |
||||
|
||||
void Metadata_StandardValueAdded(object sender, StandardValueEventArgs e) |
||||
{ |
||||
StandardValues.AddStandardValue(e.Type, e.StandardValue.Text, e.StandardValue.Instance); |
||||
} |
||||
} |
||||
} |
@ -1,111 +0,0 @@
@@ -1,111 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows.Markup; |
||||
using System.Windows; |
||||
using System.Windows.Data; |
||||
using System.Windows.Input; |
||||
using System.Reflection; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer |
||||
{ |
||||
public class CallExtension : MarkupExtension |
||||
{ |
||||
public CallExtension(string methodName) |
||||
{ |
||||
this.methodName = methodName; |
||||
} |
||||
|
||||
string methodName; |
||||
|
||||
public override object ProvideValue(IServiceProvider sp) |
||||
{ |
||||
var t = (IProvideValueTarget)sp.GetService(typeof(IProvideValueTarget)); |
||||
return new CallCommand(t.TargetObject as FrameworkElement, methodName); |
||||
} |
||||
} |
||||
|
||||
public class CallCommand : DependencyObject, ICommand |
||||
{ |
||||
public CallCommand(FrameworkElement element, string methodName) |
||||
{ |
||||
this.element = element; |
||||
this.methodName = methodName; |
||||
element.DataContextChanged += target_DataContextChanged; |
||||
|
||||
BindingOperations.SetBinding(this, CanCallProperty, new Binding("DataContext.Can" + methodName) { |
||||
Source = element |
||||
}); |
||||
|
||||
GetMethod(); |
||||
} |
||||
|
||||
FrameworkElement element; |
||||
string methodName; |
||||
MethodInfo method; |
||||
|
||||
public static readonly DependencyProperty CanCallProperty = |
||||
DependencyProperty.Register("CanCall", typeof(bool), typeof(CallCommand), |
||||
new PropertyMetadata(true)); |
||||
|
||||
public bool CanCall |
||||
{ |
||||
get { return (bool)GetValue(CanCallProperty); } |
||||
set { SetValue(CanCallProperty, value); } |
||||
} |
||||
|
||||
public object DataContext |
||||
{ |
||||
get { return element.DataContext; } |
||||
} |
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
base.OnPropertyChanged(e); |
||||
|
||||
if (e.Property == CanCallProperty) { |
||||
RaiseCanExecuteChanged(); |
||||
} |
||||
} |
||||
|
||||
void GetMethod() |
||||
{ |
||||
if (DataContext == null) { |
||||
method = null; |
||||
} |
||||
else { |
||||
method = DataContext.GetType().GetMethod(methodName, Type.EmptyTypes); |
||||
} |
||||
} |
||||
|
||||
void target_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
GetMethod(); |
||||
RaiseCanExecuteChanged(); |
||||
} |
||||
|
||||
void RaiseCanExecuteChanged() |
||||
{ |
||||
if (CanExecuteChanged != null) { |
||||
CanExecuteChanged(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
|
||||
#region ICommand Members
|
||||
|
||||
public event EventHandler CanExecuteChanged; |
||||
|
||||
public bool CanExecute(object parameter) |
||||
{ |
||||
return method != null && CanCall; |
||||
} |
||||
|
||||
public void Execute(object parameter) |
||||
{ |
||||
method.Invoke(DataContext, null); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -1,298 +0,0 @@
@@ -1,298 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 3077 $</version>
|
||||
// </file>
|
||||
|
||||
//#define DEBUG_ADORNERLAYER
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Media; |
||||
|
||||
using ICSharpCode.WpfDesign.Adorners; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Controls |
||||
{ |
||||
/// <summary>
|
||||
/// A control that displays adorner panels.
|
||||
/// </summary>
|
||||
sealed class AdornerLayer : Panel |
||||
{ |
||||
#region AdornerPanelCollection
|
||||
internal sealed class AdornerPanelCollection : ICollection<AdornerPanel> |
||||
{ |
||||
readonly AdornerLayer _layer; |
||||
|
||||
public AdornerPanelCollection(AdornerLayer layer) |
||||
{ |
||||
this._layer = layer; |
||||
} |
||||
|
||||
public int Count { |
||||
get { return _layer.Children.Count; } |
||||
} |
||||
|
||||
public bool IsReadOnly { |
||||
get { return false; } |
||||
} |
||||
|
||||
public void Add(AdornerPanel item) |
||||
{ |
||||
if (item == null) |
||||
throw new ArgumentNullException("item"); |
||||
|
||||
_layer.AddAdorner(item); |
||||
} |
||||
|
||||
public void Clear() |
||||
{ |
||||
_layer.ClearAdorners(); |
||||
} |
||||
|
||||
public bool Contains(AdornerPanel item) |
||||
{ |
||||
if (item == null) |
||||
throw new ArgumentNullException("item"); |
||||
|
||||
return VisualTreeHelper.GetParent(item) == _layer; |
||||
} |
||||
|
||||
public void CopyTo(AdornerPanel[] array, int arrayIndex) |
||||
{ |
||||
foreach (AdornerPanel panel in this) |
||||
array[arrayIndex++] = panel; |
||||
} |
||||
|
||||
public bool Remove(AdornerPanel item) |
||||
{ |
||||
if (item == null) |
||||
throw new ArgumentNullException("item"); |
||||
|
||||
return _layer.RemoveAdorner(item); |
||||
} |
||||
|
||||
public IEnumerator<AdornerPanel> GetEnumerator() |
||||
{ |
||||
foreach (AdornerPanel panel in _layer.Children) { |
||||
yield return panel; |
||||
} |
||||
} |
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
||||
{ |
||||
return this.GetEnumerator(); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
AdornerPanelCollection _adorners; |
||||
readonly UIElement _designPanel; |
||||
|
||||
#if DEBUG_ADORNERLAYER
|
||||
int _totalAdornerCount; |
||||
#endif
|
||||
|
||||
|
||||
internal AdornerLayer(UIElement designPanel) |
||||
{ |
||||
this._designPanel = designPanel; |
||||
|
||||
this.LayoutUpdated += OnLayoutUpdated; |
||||
|
||||
_adorners = new AdornerPanelCollection(this); |
||||
} |
||||
|
||||
void OnLayoutUpdated(object sender, EventArgs e) |
||||
{ |
||||
UpdateAllAdorners(false); |
||||
#if DEBUG_ADORNERLAYER
|
||||
Debug.WriteLine("Adorner LayoutUpdated. AdornedElements=" + _dict.Count + |
||||
", visible adorners=" + VisualChildrenCount + ", total adorners=" + (_totalAdornerCount)); |
||||
#endif
|
||||
} |
||||
|
||||
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) |
||||
{ |
||||
base.OnRenderSizeChanged(sizeInfo); |
||||
UpdateAllAdorners(true); |
||||
} |
||||
|
||||
internal AdornerPanelCollection Adorners { |
||||
get { |
||||
return _adorners; |
||||
} |
||||
} |
||||
|
||||
sealed class AdornerInfo |
||||
{ |
||||
internal readonly List<AdornerPanel> adorners = new List<AdornerPanel>(); |
||||
internal bool isVisible; |
||||
internal Rect position; |
||||
} |
||||
|
||||
// adorned element => AdornerInfo
|
||||
Dictionary<UIElement, AdornerInfo> _dict = new Dictionary<UIElement, AdornerInfo>(); |
||||
|
||||
void ClearAdorners() |
||||
{ |
||||
if (_dict.Count == 0) |
||||
return; // already empty
|
||||
|
||||
this.Children.Clear(); |
||||
_dict = new Dictionary<UIElement, AdornerInfo>(); |
||||
|
||||
#if DEBUG_ADORNERLAYER
|
||||
_totalAdornerCount = 0; |
||||
Debug.WriteLine("AdornerLayer cleared."); |
||||
#endif
|
||||
} |
||||
|
||||
AdornerInfo GetOrCreateAdornerInfo(UIElement adornedElement) |
||||
{ |
||||
AdornerInfo info; |
||||
if (!_dict.TryGetValue(adornedElement, out info)) { |
||||
info = _dict[adornedElement] = new AdornerInfo(); |
||||
info.isVisible = adornedElement.IsDescendantOf(_designPanel); |
||||
} |
||||
return info; |
||||
} |
||||
|
||||
AdornerInfo GetExistingAdornerInfo(UIElement adornedElement) |
||||
{ |
||||
AdornerInfo info; |
||||
_dict.TryGetValue(adornedElement, out info); |
||||
return info; |
||||
} |
||||
|
||||
void AddAdorner(AdornerPanel adornerPanel) |
||||
{ |
||||
if (adornerPanel.AdornedElement == null) |
||||
throw new DesignerException("adornerPanel.AdornedElement must be set"); |
||||
|
||||
AdornerInfo info = GetOrCreateAdornerInfo(adornerPanel.AdornedElement); |
||||
info.adorners.Add(adornerPanel); |
||||
|
||||
if (info.isVisible) { |
||||
AddAdornerToChildren(adornerPanel); |
||||
} |
||||
|
||||
#if DEBUG_ADORNERLAYER
|
||||
Debug.WriteLine("Adorner added. AdornedElements=" + _dict.Count + |
||||
", visible adorners=" + VisualChildrenCount + ", total adorners=" + (++_totalAdornerCount)); |
||||
#endif
|
||||
} |
||||
|
||||
void AddAdornerToChildren(AdornerPanel adornerPanel) |
||||
{ |
||||
UIElementCollection children = this.Children; |
||||
int i = 0; |
||||
for (i = 0; i < children.Count; i++) { |
||||
AdornerPanel p = (AdornerPanel)children[i]; |
||||
if (p.Order.CompareTo(adornerPanel.Order) > 0) { |
||||
break; |
||||
} |
||||
} |
||||
children.Insert(i, adornerPanel); |
||||
} |
||||
|
||||
protected override Size MeasureOverride(Size availableSize) |
||||
{ |
||||
Size infiniteSize = new Size(double.PositiveInfinity, double.PositiveInfinity); |
||||
foreach (AdornerPanel adorner in this.Children) { |
||||
adorner.Measure(infiniteSize); |
||||
} |
||||
return new Size(0, 0); |
||||
} |
||||
|
||||
protected override Size ArrangeOverride(Size finalSize) |
||||
{ |
||||
foreach (AdornerPanel adorner in this.Children) { |
||||
adorner.Arrange(new Rect(new Point(0, 0), adorner.DesiredSize)); |
||||
if (adorner.AdornedElement.IsDescendantOf(_designPanel)) { |
||||
adorner.RenderTransform = (Transform)adorner.AdornedElement.TransformToAncestor(_designPanel); |
||||
} |
||||
} |
||||
return finalSize; |
||||
} |
||||
|
||||
bool RemoveAdorner(AdornerPanel adornerPanel) |
||||
{ |
||||
if (adornerPanel.AdornedElement == null) |
||||
return false; |
||||
|
||||
AdornerInfo info = GetExistingAdornerInfo(adornerPanel.AdornedElement); |
||||
if (info == null) |
||||
return false; |
||||
|
||||
if (info.adorners.Remove(adornerPanel)) { |
||||
if (info.isVisible) { |
||||
this.Children.Remove(adornerPanel); |
||||
} |
||||
|
||||
if (info.adorners.Count == 0) { |
||||
_dict.Remove(adornerPanel.AdornedElement); |
||||
} |
||||
|
||||
#if DEBUG_ADORNERLAYER
|
||||
Debug.WriteLine("Adorner removed. AdornedElements=" + _dict.Count + |
||||
", visible adorners=" + VisualChildrenCount + ", total adorners=" + (--_totalAdornerCount)); |
||||
#endif
|
||||
|
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public void UpdateAdornersForElement(UIElement element, bool forceInvalidate) |
||||
{ |
||||
AdornerInfo info = GetExistingAdornerInfo(element); |
||||
if (info != null) { |
||||
UpdateAdornersForElement(element, info, forceInvalidate); |
||||
} |
||||
} |
||||
|
||||
Rect GetPositionCache(UIElement element) |
||||
{ |
||||
Transform t = (Transform)element.TransformToAncestor(_designPanel); |
||||
return new Rect(new Point(t.Value.OffsetX, t.Value.OffsetY), element.RenderSize); |
||||
} |
||||
|
||||
void UpdateAdornersForElement(UIElement element, AdornerInfo info, bool forceInvalidate) |
||||
{ |
||||
if (element.IsDescendantOf(_designPanel)) { |
||||
if (!info.isVisible) { |
||||
info.isVisible = true; |
||||
// make adorners visible:
|
||||
info.adorners.ForEach(AddAdornerToChildren); |
||||
} |
||||
Rect c = GetPositionCache(element); |
||||
if (forceInvalidate || !info.position.Equals(c)) { |
||||
info.position = c; |
||||
foreach (AdornerPanel p in info.adorners) { |
||||
p.InvalidateMeasure(); |
||||
} |
||||
this.InvalidateArrange(); |
||||
} |
||||
} else { |
||||
if (info.isVisible) { |
||||
info.isVisible = false; |
||||
// make adorners invisible:
|
||||
info.adorners.ForEach(this.Children.Remove); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void UpdateAllAdorners(bool forceInvalidate) |
||||
{ |
||||
foreach (KeyValuePair<UIElement, AdornerInfo> pair in _dict) { |
||||
UpdateAdornersForElement(pair.Key, pair.Value, forceInvalidate); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision: 2243 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows.Controls; |
||||
using System.Windows; |
||||
using System.Windows.Media; |
||||
using System.Windows.Shapes; |
||||
using System.Windows.Controls.Primitives; |
||||
using ICSharpCode.WpfDesign.Adorners; |
||||
using ICSharpCode.WpfDesign.Extensions; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Controls |
||||
{ |
||||
/// <summary>
|
||||
/// A thumb where the look can depend on the IsPrimarySelection property.
|
||||
/// Used by UIElementSelectionRectangle.
|
||||
/// </summary>
|
||||
public class ContainerDragHandle : Control |
||||
{ |
||||
static ContainerDragHandle() |
||||
{ |
||||
//This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
|
||||
//This style is defined in themes\generic.xaml
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(ContainerDragHandle), new FrameworkPropertyMetadata(typeof(ContainerDragHandle))); |
||||
} |
||||
} |
||||
} |
@ -1,416 +0,0 @@
@@ -1,416 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls"> |
||||
<!-- |
||||
This file contains the default styles used by the Controls in ICSharpCode.WpfDesign.Designer.Controls |
||||
--> |
||||
|
||||
<ResourceDictionary.MergedDictionaries> |
||||
<ResourceDictionary Source="NumericUpDown.xaml" /> |
||||
</ResourceDictionary.MergedDictionaries> |
||||
|
||||
<Style x:Key="ZoomButtonStyle" |
||||
TargetType="RepeatButton"> |
||||
<Setter Property="Delay" |
||||
Value="0" /> |
||||
<Setter Property="Focusable" |
||||
Value="False" /> |
||||
<Setter Property="Opacity" |
||||
Value="0.5" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="RepeatButton"> |
||||
<ContentPresenter Margin="5"/> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="IsMouseOver" |
||||
Value="True"> |
||||
<Setter Property="Opacity" |
||||
Value="1" /> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:ZoomControl}"> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:ZoomControl}"> |
||||
<Border Background="{TemplateBinding Background}" |
||||
BorderBrush="{TemplateBinding BorderBrush}" |
||||
BorderThickness="{TemplateBinding BorderThickness}"> |
||||
<Grid> |
||||
<ScrollViewer x:Name="scrollViewer" |
||||
HorizontalScrollBarVisibility="Visible" |
||||
VerticalScrollBarVisibility="Visible"> |
||||
<Border x:Name="container" |
||||
VerticalAlignment="Center" |
||||
HorizontalAlignment="Center"> |
||||
<ContentPresenter /> |
||||
</Border> |
||||
</ScrollViewer> |
||||
<StackPanel Orientation="Vertical" |
||||
HorizontalAlignment="Left" |
||||
VerticalAlignment="Bottom" |
||||
Margin="3 0 0 20" |
||||
Background="#3000"> |
||||
<RepeatButton x:Name="uxPlus" |
||||
Style="{StaticResource ZoomButtonStyle}"> |
||||
<Image Source="../Images/ZoomIn.png" |
||||
Stretch="None"/> |
||||
</RepeatButton> |
||||
<RepeatButton x:Name="uxMinus" |
||||
Style="{StaticResource ZoomButtonStyle}"> |
||||
<Image Source="../Images/ZoomOut.png" |
||||
Stretch="None" /> |
||||
</RepeatButton> |
||||
<RepeatButton x:Name="uxReset" |
||||
Style="{StaticResource ZoomButtonStyle}"> |
||||
<Border Background="#5000" |
||||
Width="16" |
||||
Height="16"> |
||||
<TextBlock Foreground="White" |
||||
HorizontalAlignment="Center" |
||||
VerticalAlignment="Center">1</TextBlock> |
||||
</Border> |
||||
</RepeatButton> |
||||
</StackPanel> |
||||
</Grid> |
||||
</Border> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:PanelMoveAdorner}"> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:PanelMoveAdorner}"> |
||||
<Border BorderThickness="4" |
||||
Margin="-2" |
||||
BorderBrush="Transparent" |
||||
Cursor="SizeAll" /> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:EnumButton}" |
||||
BasedOn="{StaticResource {x:Type ToggleButton}}"> |
||||
<Setter Property="Margin" |
||||
Value="3 3 0 3" /> |
||||
<Setter Property="MinWidth" |
||||
Value="50" /> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:ResizeThumb}"> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:ResizeThumb}"> |
||||
<Rectangle Name="thumbRectangle" |
||||
Width="7" |
||||
Height="7" |
||||
SnapsToDevicePixels="True" |
||||
Stroke="Black" |
||||
Fill="White" |
||||
RadiusX="1.414" |
||||
RadiusY="1.414" /> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="IsPrimarySelection" |
||||
Value="False"> |
||||
<Setter TargetName="thumbRectangle" |
||||
Property="Stroke" |
||||
Value="White" /> |
||||
<Setter TargetName="thumbRectangle" |
||||
Property="Fill" |
||||
Value="Black" /> |
||||
</Trigger> |
||||
<Trigger Property="IsEnabled" |
||||
Value="False"> |
||||
<Setter TargetName="thumbRectangle" |
||||
Property="Fill" |
||||
Value="Gray" /> |
||||
</Trigger> |
||||
<Trigger Property="ResizeThumbVisible" |
||||
Value="False"> |
||||
<Setter TargetName="thumbRectangle" |
||||
Property="Visibility" |
||||
Value="Hidden" /> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:SelectionFrame}"> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:SelectionFrame}"> |
||||
<Rectangle Fill="#519ABFE5" |
||||
Stroke="#FF7A8787" |
||||
StrokeThickness="1" /> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:ContainerDragHandle}"> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:ContainerDragHandle}"> |
||||
<Canvas Height="13" |
||||
Width="13" |
||||
Name="Canvas" |
||||
SnapsToDevicePixels="True"> |
||||
<Rectangle Height="13" |
||||
Width="13" |
||||
RadiusX="2" |
||||
RadiusY="2" |
||||
Fill="#889ABFE5" |
||||
Name="BorderRectangle" |
||||
Stroke="#FF7A8FB5" |
||||
StrokeThickness="1" /> |
||||
<Path Fill="#FF748EAA" |
||||
Canvas.Left="1" |
||||
Canvas.Top="1"> |
||||
<Path.Data> |
||||
<GeometryGroup> |
||||
<PathGeometry Figures="M5.5,0L3,3L8,3 M11,5.5L8,3L8,8 M5.5,11L3,8L8,8 M0,5.5L3,3L3,8" /> |
||||
<RectangleGeometry Rect="3,5,5,1" /> |
||||
<RectangleGeometry Rect="5,3,1,5" /> |
||||
<RectangleGeometry Rect="5,5,1,1" /> |
||||
</GeometryGroup> |
||||
</Path.Data> |
||||
</Path> |
||||
</Canvas> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:WindowClone}"> |
||||
<Setter Property="Width" |
||||
Value="640" /> |
||||
<Setter Property="Height" |
||||
Value="480" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:WindowClone}"> |
||||
<Border Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" |
||||
BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" |
||||
BorderThickness="1,1,1,1" |
||||
CornerRadius="5,5,5,5"> |
||||
<DockPanel Margin="4,0,4,4"> |
||||
<DockPanel Height="26" |
||||
DockPanel.Dock="Top"> |
||||
<Image Width="16" |
||||
Height="16" |
||||
Margin="1,0,0,0" |
||||
Source="{TemplateBinding Window.Icon}" /> |
||||
<Button Name="CloseButton" |
||||
VerticalAlignment="Top" |
||||
Width="43" |
||||
Height="17" |
||||
DockPanel.Dock="Right"> |
||||
<Path Fill="#FFF6F2F2" |
||||
Stretch="Uniform" |
||||
Margin="1" |
||||
Stroke="#FF808080" |
||||
Data="M160,400 L176,400 192,384 208,400 224,400 200,376 224,352 208,352 192,368 176,352 160,352 184,376 z" /> |
||||
</Button> |
||||
<Button Name="MaximiseButton" |
||||
VerticalAlignment="Top" |
||||
Width="25" |
||||
Height="17" |
||||
DockPanel.Dock="Right" /> |
||||
<Button Name="MinimizeButton" |
||||
VerticalAlignment="Top" |
||||
Width="25" |
||||
Height="17" |
||||
DockPanel.Dock="Right"> |
||||
<!--<Rectangle Fill="#FFF6F2F2" RadiusX="0.5" RadiusY="0.5" Width="12" Height="5" Stroke="#FF808080" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>--> |
||||
</Button> |
||||
<Label Margin="4,0,0,0" |
||||
Content="{TemplateBinding Window.Title}" /> |
||||
</DockPanel> |
||||
<Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"> |
||||
<Border BorderBrush="{TemplateBinding Border.BorderBrush}" |
||||
BorderThickness="{TemplateBinding Border.BorderThickness}" |
||||
Background="{TemplateBinding Panel.Background}"> |
||||
<AdornerDecorator> |
||||
<ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" |
||||
Content="{TemplateBinding ContentControl.Content}" /> |
||||
</AdornerDecorator> |
||||
</Border> |
||||
</Border> |
||||
</DockPanel> |
||||
</Border> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:ErrorBalloon}"> |
||||
<Setter Property="WindowStyle" |
||||
Value="None" /> |
||||
<Setter Property="AllowsTransparency" |
||||
Value="True" /> |
||||
<Setter Property="SizeToContent" |
||||
Value="WidthAndHeight" /> |
||||
<Setter Property="ShowInTaskbar" |
||||
Value="False" /> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:ErrorBalloon}"> |
||||
<Grid x:Name="LayoutRoot"> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="*" /> |
||||
</Grid.ColumnDefinitions> |
||||
<Rectangle RadiusX="10" |
||||
RadiusY="10" |
||||
Margin="12,36,4,4"> |
||||
<Rectangle.Fill> |
||||
<SolidColorBrush Color="#41626262" /> |
||||
</Rectangle.Fill> |
||||
</Rectangle> |
||||
<Border Margin="8,32,8,8" |
||||
Background="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" |
||||
BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" |
||||
BorderThickness="1,1,1,1" |
||||
CornerRadius="10,10,10,10" |
||||
Padding="10,10,10,10"> |
||||
<Border BorderBrush="{TemplateBinding Border.BorderBrush}" |
||||
BorderThickness="{TemplateBinding Border.BorderThickness}" |
||||
Background="{TemplateBinding Panel.Background}"> |
||||
<AdornerDecorator> |
||||
<ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" |
||||
Content="{TemplateBinding ContentControl.Content}" /> |
||||
</AdornerDecorator> |
||||
</Border> |
||||
</Border> |
||||
<Path Fill="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" |
||||
Stretch="Fill" |
||||
HorizontalAlignment="Left" |
||||
Margin="34.75,9.25,0,0" |
||||
VerticalAlignment="Top" |
||||
Width="15.25" |
||||
Height="24.5" |
||||
Data="M34.75,33.75 L40.5,9.25 50,33.5 z" /> |
||||
<Path Stretch="Fill" |
||||
Stroke="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" |
||||
HorizontalAlignment="Left" |
||||
Margin="34.5,9.25,0,0" |
||||
VerticalAlignment="Top" |
||||
Width="16" |
||||
Height="24" |
||||
Data="M35,32.75 L40.5,9.25 50,32.75" /> |
||||
</Grid> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:GridRailAdorner}"> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:GridRailAdorner}"> |
||||
<Rectangle Fill="#302020ff" /> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:GridRowSplitterAdorner}"> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:GridRowSplitterAdorner}"> |
||||
<Grid Height="{x:Static Controls:GridRailAdorner.SplitterWidth}"> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="10" /> |
||||
<!-- 10=RailSize --> |
||||
<ColumnDefinition Width="*" /> |
||||
</Grid.ColumnDefinitions> |
||||
<!-- put a transparent rectangle in the rail so the user does not have to hit the small railHandle --> |
||||
<Rectangle Fill="Transparent" /> |
||||
<Path Name="railHandle" |
||||
Fill="#FFE6E6FF" |
||||
Stretch="Fill" |
||||
Stroke="#FF584FFF" |
||||
Data="M0,0 L0,1 1,0.5 z" /> |
||||
<Path Name="line" |
||||
Stretch="Fill" |
||||
Stroke="#FF584FFF" |
||||
Grid.Column="2" |
||||
Margin="-1 0 0 0" |
||||
Data="M0,0.5 L1,0.5" /> |
||||
</Grid> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="IsMouseOver" |
||||
Value="True"> |
||||
<Setter TargetName="railHandle" |
||||
Property="Fill" |
||||
Value="#FFFFB74F" /> |
||||
</Trigger> |
||||
<Trigger Property="IsPreview" |
||||
Value="True"> |
||||
<Setter TargetName="railHandle" |
||||
Property="Stroke" |
||||
Value="#D0FFB74F" /> |
||||
<Setter TargetName="line" |
||||
Property="Stroke" |
||||
Value="#D0FFB74F" /> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type Controls:GridColumnSplitterAdorner}"> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type Controls:GridColumnSplitterAdorner}"> |
||||
<Grid Width="{x:Static Controls:GridRailAdorner.SplitterWidth}"> |
||||
<Grid.RowDefinitions> |
||||
<RowDefinition Height="10" /> |
||||
<!-- 10=RailSize --> |
||||
<RowDefinition Height="*" /> |
||||
</Grid.RowDefinitions> |
||||
<!-- put a transparent rectangle in the rail so the user does not have to hit the small railHandle --> |
||||
<Rectangle Fill="Transparent" /> |
||||
<Path Name="railHandle" |
||||
Fill="#FFE6E6FF" |
||||
Stretch="Fill" |
||||
Stroke="#FF584FFF" |
||||
Data="M0,0 L1,0 0.5,1 z" /> |
||||
<Path Name="line" |
||||
Stretch="Fill" |
||||
Stroke="#FF584FFF" |
||||
Grid.Row="2" |
||||
Margin="0 -1 0 0" |
||||
Data="M0.5,0 L0.5,1" /> |
||||
</Grid> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="IsMouseOver" |
||||
Value="True"> |
||||
<Setter TargetName="railHandle" |
||||
Property="Fill" |
||||
Value="#FFFFB74F" /> |
||||
</Trigger> |
||||
<Trigger Property="IsPreview" |
||||
Value="True"> |
||||
<Setter TargetName="railHandle" |
||||
Property="Stroke" |
||||
Value="#D0FFB74F" /> |
||||
<Setter TargetName="line" |
||||
Property="Stroke" |
||||
Value="#D0FFB74F" /> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
</ResourceDictionary> |
@ -1,111 +0,0 @@
@@ -1,111 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Input; |
||||
using System.Diagnostics; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Controls |
||||
{ |
||||
public delegate void DragHandler(DragListener drag); |
||||
|
||||
public class DragListener |
||||
{ |
||||
static DragListener() |
||||
{ |
||||
InputManager.Current.PostProcessInput += new ProcessInputEventHandler(PostProcessInput); |
||||
} |
||||
|
||||
public DragListener(IInputElement target) |
||||
{ |
||||
Target = target; |
||||
|
||||
Target.PreviewMouseLeftButtonDown += Target_MouseDown; |
||||
Target.PreviewMouseMove += Target_MouseMove; |
||||
Target.PreviewMouseLeftButtonUp += Target_MouseUp; |
||||
} |
||||
|
||||
static DragListener CurrentListener; |
||||
|
||||
static void PostProcessInput(object sender, ProcessInputEventArgs e) |
||||
{ |
||||
if (CurrentListener != null) { |
||||
var a = e.StagingItem.Input as KeyEventArgs; |
||||
if (a != null && a.Key == Key.Escape) { |
||||
Mouse.Capture(null); |
||||
CurrentListener.IsDown = false; |
||||
CurrentListener.IsCanceled = true; |
||||
CurrentListener.Complete(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void Target_MouseDown(object sender, MouseButtonEventArgs e) |
||||
{ |
||||
StartPoint = Mouse.GetPosition(null); |
||||
CurrentPoint = StartPoint; |
||||
DeltaDelta = new Vector(); |
||||
IsDown = true; |
||||
IsCanceled = false; |
||||
} |
||||
|
||||
void Target_MouseMove(object sender, MouseEventArgs e) |
||||
{ |
||||
if (IsDown) { |
||||
DeltaDelta = e.GetPosition(null) - CurrentPoint; |
||||
CurrentPoint += DeltaDelta; |
||||
|
||||
if (!IsActive) { |
||||
if (Math.Abs(Delta.X) >= SystemParameters.MinimumHorizontalDragDistance || |
||||
Math.Abs(Delta.Y) >= SystemParameters.MinimumVerticalDragDistance) { |
||||
IsActive = true; |
||||
CurrentListener = this; |
||||
|
||||
if (Started != null) { |
||||
Started(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (IsActive && Changed != null) { |
||||
Changed(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void Target_MouseUp(object sender, MouseButtonEventArgs e) |
||||
{ |
||||
IsDown = false; |
||||
if (IsActive) { |
||||
Complete(); |
||||
} |
||||
} |
||||
|
||||
void Complete() |
||||
{ |
||||
IsActive = false; |
||||
CurrentListener = null; |
||||
|
||||
if (Completed != null) { |
||||
Completed(this); |
||||
} |
||||
} |
||||
|
||||
public event DragHandler Started; |
||||
public event DragHandler Changed; |
||||
public event DragHandler Completed; |
||||
|
||||
public IInputElement Target { get; private set; } |
||||
public Point StartPoint { get; private set; } |
||||
public Point CurrentPoint { get; private set; } |
||||
public Vector DeltaDelta { get; private set; } |
||||
public bool IsActive { get; private set; } |
||||
public bool IsDown { get; private set; } |
||||
public bool IsCanceled { get; private set; } |
||||
|
||||
public Vector Delta { |
||||
get { return CurrentPoint - StartPoint; } |
||||
} |
||||
} |
||||
} |
@ -1,33 +0,0 @@
@@ -1,33 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision: 3246 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Media; |
||||
using System.Windows.Shapes; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Controls |
||||
{ |
||||
/// <summary>
|
||||
/// A button with a drop-down arrow.
|
||||
/// </summary>
|
||||
public class DropDownButton : Button |
||||
{ |
||||
static readonly Geometry triangle = (Geometry)new GeometryConverter().ConvertFromInvariantString("M0,0 L1,0 0.5,1 z"); |
||||
|
||||
public DropDownButton() |
||||
{ |
||||
Content = new Path { |
||||
Fill = Brushes.Black, |
||||
Data = triangle, |
||||
Width = 7, |
||||
Height = 3.5, |
||||
Stretch = Stretch.Fill |
||||
}; |
||||
} |
||||
} |
||||
} |
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Input; |
||||
using System.Windows.Data; |
||||
using System.Windows; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Controls |
||||
{ |
||||
public class EnterTextBox : TextBox |
||||
{ |
||||
protected override void OnKeyDown(KeyEventArgs e) |
||||
{ |
||||
if (e.Key == Key.Enter) { |
||||
var b = BindingOperations.GetBindingExpressionBase(this, TextProperty); |
||||
if (b != null) { |
||||
b.UpdateSource(); |
||||
} |
||||
SelectAll(); |
||||
} |
||||
else if (e.Key == Key.Escape) { |
||||
var b = BindingOperations.GetBindingExpressionBase(this, TextProperty); |
||||
if (b != null) { |
||||
b.UpdateTarget(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,7 +0,0 @@
@@ -1,7 +0,0 @@
|
||||
<UserControl |
||||
x:Class="ICSharpCode.WpfDesign.Designer.Controls.EnumBar" |
||||
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<StackPanel x:Name="uxPanel" |
||||
Orientation="Horizontal" /> |
||||
</UserControl> |
@ -1,112 +0,0 @@
@@ -1,112 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using System.Windows.Media.Imaging; |
||||
using System.Windows.Navigation; |
||||
using System.Windows.Shapes; |
||||
using System.Windows.Controls.Primitives; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Controls |
||||
{ |
||||
public partial class EnumBar |
||||
{ |
||||
public EnumBar() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
Type currentEnumType; |
||||
|
||||
public static readonly DependencyProperty ValueProperty = |
||||
DependencyProperty.Register("Value", typeof(object), typeof(EnumBar), |
||||
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); |
||||
|
||||
public object Value { |
||||
get { return (object)GetValue(ValueProperty); } |
||||
set { SetValue(ValueProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty ContainerProperty = |
||||
DependencyProperty.Register("Container", typeof(Panel), typeof(EnumBar)); |
||||
|
||||
public Panel Container { |
||||
get { return (Panel)GetValue(ContainerProperty); } |
||||
set { SetValue(ContainerProperty, value); } |
||||
} |
||||
|
||||
public static readonly DependencyProperty ButtonStyleProperty = |
||||
DependencyProperty.Register("ButtonStyle", typeof(Style), typeof(EnumBar)); |
||||
|
||||
public Style ButtonStyle { |
||||
get { return (Style)GetValue(ButtonStyleProperty); } |
||||
set { SetValue(ButtonStyleProperty, value); } |
||||
} |
||||
|
||||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
base.OnPropertyChanged(e); |
||||
|
||||
if (e.Property == ValueProperty) { |
||||
|
||||
var type = e.NewValue.GetType(); |
||||
|
||||
if (currentEnumType != type) { |
||||
currentEnumType = type; |
||||
uxPanel.Children.Clear(); |
||||
foreach (var v in Enum.GetValues(type)) { |
||||
var b = new EnumButton(); |
||||
b.Value = v; |
||||
b.Content = Enum.GetName(type, v); |
||||
b.SetBinding(StyleProperty, new Binding("ButtonStyle") { Source = this }); |
||||
b.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(button_PreviewMouseLeftButtonDown); |
||||
uxPanel.Children.Add(b); |
||||
} |
||||
} |
||||
|
||||
UpdateButtons(); |
||||
UpdateContainer(); |
||||
|
||||
} else if (e.Property == ContainerProperty) { |
||||
UpdateContainer(); |
||||
} |
||||
} |
||||
|
||||
void UpdateButtons() |
||||
{ |
||||
foreach (EnumButton c in uxPanel.Children) { |
||||
if (c.Value.Equals(Value)) { |
||||
c.IsChecked = true; |
||||
} |
||||
else { |
||||
c.IsChecked = false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void UpdateContainer() |
||||
{ |
||||
if (Container != null) { |
||||
for (int i = 0; i < uxPanel.Children.Count; i++) { |
||||
var c = uxPanel.Children[i] as EnumButton; |
||||
if (c.IsChecked.Value) |
||||
Container.Children[i].Visibility = Visibility.Visible; |
||||
else |
||||
Container.Children[i].Visibility = Visibility.Collapsed; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void button_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
||||
{ |
||||
Value = (sender as EnumButton).Value; |
||||
e.Handled = true; |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue