Browse Source

WPF Design Addin

- allow use of Controls from referenced Assemblys
- don't show Designer on app.xaml
pull/52/head
jkuehner 12 years ago
parent
commit
5e6212274f
  1. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs
  2. 54
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs
  3. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs

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

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

54
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs

@ -2,11 +2,18 @@ @@ -2,11 +2,18 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Windows;
using System.Windows.Forms;
using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Widgets.SideBar;
using WPF = System.Windows.Controls;
@ -48,6 +55,53 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -48,6 +55,53 @@ namespace ICSharpCode.WpfDesign.AddIn
sideBar.ActiveTab = sideTab;
}
static bool IsControl(Type t)
{
return !t.IsAbstract && !t.IsGenericTypeDefinition && t.IsSubclassOf(typeof(FrameworkElement));
}
private static HashSet<string> addedAssemblys = new HashSet<string>();
public void AddProjectDlls(OpenedFile file)
{
var pc = MyTypeFinder.GetProjectContent(file);
foreach (ReflectionProjectContent referencedProjectContent in pc.ThreadSafeGetReferencedContents().Where(x=> x is ReflectionProjectContent))
{
if (!addedAssemblys.Contains(referencedProjectContent.AssemblyLocation))
{
try
{
var assembly = Assembly.LoadFrom(referencedProjectContent.AssemblyLocation);
SideTab sideTab = new SideTab(sideBar, assembly.FullName.Split(new[] {','})[0]);
sideTab.DisplayName = StringParser.Parse(sideTab.Name);
sideTab.CanBeDeleted = false;
sideTab.ChoosedItemChanged += OnChoosedItemChanged;
sideTab.Items.Add(new WpfSideTabItem());
foreach (var t in assembly.GetExportedTypes())
{
if (IsControl(t))
{
sideTab.Items.Add(new WpfSideTabItem(t));
}
}
if (sideTab.Items.Count > 1)
sideBar.Tabs.Add(sideTab);
addedAssemblys.Add(referencedProjectContent.AssemblyLocation);
}
catch (Exception ex)
{
WpfViewContent.DllLoadErrors.Add(
new Task(new BuildError(referencedProjectContent.AssemblyLocation, ex.Message)));
}
}
}
}
void OnChoosedItemChanged(object sender, EventArgs e)
{
if (toolService != null) {

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

@ -36,6 +36,8 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -36,6 +36,8 @@ namespace ICSharpCode.WpfDesign.AddIn
{
BasicMetadata.Register();
WpfToolbox.Instance.AddProjectDlls(file);
this.TabPageText = "${res:FormsDesigner.DesignTabPages.DesignTabPage}";
this.IsActiveViewContentChanged += OnIsActiveViewContentChanged;
}
@ -131,6 +133,7 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -131,6 +133,7 @@ namespace ICSharpCode.WpfDesign.AddIn
}
}
public static List<Task> DllLoadErrors = new List<Task>();
void UpdateTasks(XamlErrorService xamlErrorService)
{
Debug.Assert(xamlErrorService != null);
@ -146,6 +149,8 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -146,6 +149,8 @@ namespace ICSharpCode.WpfDesign.AddIn
TaskService.Add(task);
}
TaskService.AddRange(DllLoadErrors);
if (xamlErrorService.Errors.Count != 0) {
WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad)).BringPadToFront();
}

Loading…
Cancel
Save