Browse Source

WPF Designer: Report loading errors (TaskService for integrated version, ErrorListView for standalone)

TODO (for v4):
1. Auto parse -> update errors
2. Design/Undo/Redo -> update errors
3. Jump to XmlNode (position tracking required)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3441 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Ivan Shumilin 17 years ago
parent
commit
74a952bdb5
  1. 46
      samples/XamlDesigner/Document.cs
  2. 16
      samples/XamlDesigner/DocumentView.xaml.cs
  3. 16
      samples/XamlDesigner/ErrorListView.xaml
  4. 33
      samples/XamlDesigner/ErrorListView.xaml.cs
  5. BIN
      samples/XamlDesigner/Images/Error.png
  6. 3
      samples/XamlDesigner/MainWindow.xaml
  7. 9
      samples/XamlDesigner/MainWindow.xaml.cs
  8. 1
      samples/XamlDesigner/MainWindow_Commands.cs
  9. 22
      samples/XamlDesigner/Shell.cs
  10. 50
      samples/XamlDesigner/TestFiles/2.xaml
  11. 16
      samples/XamlDesigner/TestFiles/4.xaml
  12. 13
      samples/XamlDesigner/XamlDesigner.csproj
  13. 51
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  14. 63
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj
  15. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs
  16. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml
  17. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml.cs
  18. 31
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/XamlErrorService.cs
  19. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  20. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  21. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/IXamlErrorSink.cs
  22. 94
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/PositionXmlDocument.cs
  23. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj
  24. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs
  25. 68
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  26. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  27. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignContext.cs
  28. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs

46
samples/XamlDesigner/Document.cs

@ -63,7 +63,6 @@ namespace ICSharpCode.XamlDesigner @@ -63,7 +63,6 @@ namespace ICSharpCode.XamlDesigner
RaisePropertyChanged("Mode");
RaisePropertyChanged("InXamlMode");
RaisePropertyChanged("InDesignMode");
RaisePropertyChanged("SelectionService");
}
}
@ -137,13 +136,19 @@ namespace ICSharpCode.XamlDesigner @@ -137,13 +136,19 @@ namespace ICSharpCode.XamlDesigner
public ISelectionService SelectionService {
get {
if (InDesignMode && DesignContext != null) {
if (InDesignMode) {
return DesignContext.Services.Selection;
}
return null;
}
}
public XamlErrorService XamlErrorService {
get {
return DesignContext.Services.GetService<XamlErrorService>();
}
}
OutlineNode outlineRoot;
public OutlineNode OutlineRoot {
@ -178,38 +183,35 @@ namespace ICSharpCode.XamlDesigner @@ -178,38 +183,35 @@ namespace ICSharpCode.XamlDesigner
Save();
}
public void Refresh()
{
UpdateXaml();
UpdateDesign();
}
void UpdateXaml()
{
var sb = new StringBuilder();
using (var xmlWriter = XmlWriter.Create(sb)) {
try {
if (DesignContext.CanSave && UndoService.CanUndo) {
var sb = new StringBuilder();
using (var xmlWriter = XmlWriter.Create(sb)) {
DesignSurface.SaveDesigner(xmlWriter);
Text = XamlFormatter.Format(sb.ToString());
}
catch (Exception x) {
Shell.ReportException(x);
}
}
}
void UpdateDesign()
{
try {
XamlLoadSettings settings = new XamlLoadSettings();
using (var xmlReader = XmlReader.Create(new StringReader(Text))) {
DesignSurface.LoadDesigner(xmlReader, settings);
}
if (DesignContext.RootItem == null) {
OutlineRoot = null;
}
else {
OutlineRoot = OutlineNode.Create(DesignContext.RootItem);
}
UndoService.UndoStackChanged += new EventHandler(UndoService_UndoStackChanged);
OutlineRoot = null;
using (var xmlReader = XmlReader.Create(new StringReader(Text))) {
DesignSurface.LoadDesigner(xmlReader, null);
}
catch (Exception x) {
Shell.ReportException(x);
if (DesignContext.RootItem != null) {
OutlineRoot = OutlineNode.Create(DesignContext.RootItem);
UndoService.UndoStackChanged += new EventHandler(UndoService_UndoStackChanged);
}
RaisePropertyChanged("SelectionService");
RaisePropertyChanged("XamlErrorService");
}
void UndoService_UndoStackChanged(object sender, EventArgs e)

16
samples/XamlDesigner/DocumentView.xaml.cs

@ -11,6 +11,8 @@ using System.Windows.Media; @@ -11,6 +11,8 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Windows.Threading;
namespace ICSharpCode.XamlDesigner
{
@ -19,8 +21,22 @@ namespace ICSharpCode.XamlDesigner @@ -19,8 +21,22 @@ namespace ICSharpCode.XamlDesigner
public DocumentView(Document doc)
{
InitializeComponent();
Document = doc;
Shell.Instance.Views[doc] = this;
uxTextEditor.SetHighlighting("XML");
uxTextEditor.DataBindings.Add("Text", doc, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
}
public Document Document { get; private set; }
public void JumpToError(XamlError error)
{
Document.Mode = DocumentMode.Xaml;
Dispatcher.BeginInvoke(new Action(delegate {
uxTextEditor.ActiveTextAreaControl.JumpTo(error.Line - 1, error.Column - 1);
}), DispatcherPriority.Background);
}
}
}

16
samples/XamlDesigner/ErrorListView.xaml

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
<ListBox x:Class="ICSharpCode.XamlDesigner.ErrorListView"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Services="clr-namespace:ICSharpCode.WpfDesign.Designer.Services;assembly=ICSharpCode.WpfDesign.Designer">
<Control.Resources>
<DataTemplate DataType="{x:Type Services:XamlError}">
<StackPanel Orientation="Horizontal">
<Image Source="Images/Error.png"
Stretch="None"
Margin="2"/>
<TextBlock Text="{Binding Message}"
VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</Control.Resources>
</ListBox>

33
samples/XamlDesigner/ErrorListView.xaml.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
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 ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.XamlDesigner
{
public partial class ErrorListView
{
public ErrorListView()
{
InitializeComponent();
}
protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
{
var error = e.GetDataContext() as XamlError;
if (error != null) {
Shell.Instance.JumpToError(error);
}
}
}
}

BIN
samples/XamlDesigner/Images/Error.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 701 B

3
samples/XamlDesigner/MainWindow.xaml

@ -74,6 +74,7 @@ @@ -74,6 +74,7 @@
<MenuItem Command="Delete" />
<MenuItem Command="SelectAll" />
<Separator />
<MenuItem Command="Default:MainWindow.RefreshCommand" />
<MenuItem Command="Find" />
</MenuItem>
</Menu>
@ -99,7 +100,7 @@ @@ -99,7 +100,7 @@
<AvalonDock:DockablePane>
<AvalonDock:DockableContent x:Name="content3" Title="Errors">
<!--<Default:ErrorListView />-->
<Default:ErrorListView ItemsSource="{Binding CurrentDocument.XamlErrorService.Errors}"/>
</AvalonDock:DockableContent>
</AvalonDock:DockablePane>

9
samples/XamlDesigner/MainWindow.xaml.cs

@ -16,6 +16,7 @@ using Microsoft.Win32; @@ -16,6 +16,7 @@ using Microsoft.Win32;
using AvalonDock;
using System.IO;
using System.Collections.Specialized;
using ICSharpCode.WpfDesign.Designer;
namespace ICSharpCode.XamlDesigner
{
@ -23,15 +24,19 @@ namespace ICSharpCode.XamlDesigner @@ -23,15 +24,19 @@ namespace ICSharpCode.XamlDesigner
{
public MainWindow()
{
RenameCommands();
Instance = this;
DataContext = Shell.Instance;
RenameCommands();
BasicMetadata.Register();
InitializeComponent();
Shell.Instance.PropertyGrid = uxPropertyGridView.PropertyGrid;
AvalonDockWorkaround();
RouteDesignSurfaceCommands();
this.AddCommandHandler(RefreshCommand, Shell.Instance.Refresh, Shell.Instance.CanRefresh);
LoadSettings();
ProcessPaths(App.Args);
}

1
samples/XamlDesigner/MainWindow_Commands.cs

@ -12,6 +12,7 @@ namespace ICSharpCode.XamlDesigner @@ -12,6 +12,7 @@ namespace ICSharpCode.XamlDesigner
public static SimpleCommand CloseAllCommand = new SimpleCommand("Close All");
public static SimpleCommand SaveAllCommand = new SimpleCommand("Save All", ModifierKeys.Control | ModifierKeys.Shift, Key.S);
public static SimpleCommand ExitCommand = new SimpleCommand("Exit");
public static SimpleCommand RefreshCommand = new SimpleCommand("Refresh", Key.F5);
static void RenameCommands()
{

22
samples/XamlDesigner/Shell.cs

@ -10,6 +10,7 @@ using System.Collections.Specialized; @@ -10,6 +10,7 @@ using System.Collections.Specialized;
using System.IO;
using System.Windows;
using System.Diagnostics;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.XamlDesigner
{
@ -19,6 +20,8 @@ namespace ICSharpCode.XamlDesigner @@ -19,6 +20,8 @@ namespace ICSharpCode.XamlDesigner
{
Documents = new ObservableCollection<Document>();
RecentFiles = new ObservableCollection<string>();
Views = new Dictionary<object, FrameworkElement>();
LoadSettings();
}
@ -32,6 +35,7 @@ namespace ICSharpCode.XamlDesigner @@ -32,6 +35,7 @@ namespace ICSharpCode.XamlDesigner
public ObservableCollection<Document> Documents { get; private set; }
public ObservableCollection<string> RecentFiles { get; private set; }
public Dictionary<object, FrameworkElement> Views { get; private set; }
Document currentDocument;
@ -80,6 +84,23 @@ namespace ICSharpCode.XamlDesigner @@ -80,6 +84,23 @@ namespace ICSharpCode.XamlDesigner
MessageBox.Show(x.ToString());
}
public void JumpToError(XamlError error)
{
if (CurrentDocument != null) {
(Views[CurrentDocument] as DocumentView).JumpToError(error);
}
}
public bool CanRefresh()
{
return CurrentDocument != null;
}
public void Refresh()
{
CurrentDocument.Refresh();
}
#region Files
bool IsSomethingDirty {
@ -173,6 +194,7 @@ namespace ICSharpCode.XamlDesigner @@ -173,6 +194,7 @@ namespace ICSharpCode.XamlDesigner
}
}
Documents.Remove(doc);
Views.Remove(doc);
return true;
}

50
samples/XamlDesigner/TestFiles/2.xaml

@ -1,21 +1,20 @@ @@ -1,21 +1,20 @@
<Window xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="524"
Height="385">
<Canvas>
<Button Content="bla-bla"
Width="110"
Height="76"
Canvas.Left="59"
Canvas.Top="158" />
<Ellipse Width="146"
Height="63"
Fill="#FF5DAF05"
Canvas.Left="50"
Canvas.Top="285" />
Stroke="#FF000000"
StrokeThickness="8"
Canvas.Left="8"
Canvas.Top="158.9" />
<Grid Width="279"
Height="233"
Height="336.99999999999989"
Background="#FFFFFFE1"
Canvas.Left="255"
Canvas.Top="167">
Canvas.Left="226.99999999999994"
Canvas.Top="8.0000000000000853">
<Panel.Children>
<TextBlock Width="59"
Height="39"
@ -28,14 +27,27 @@ @@ -28,14 +27,27 @@
Grid.Row="0" />
</Panel.Children>
</Grid>
<StackPanel Width="345"
Height="73"
Background="#FFEDEDED"
Canvas.Left="198"
Canvas.Top="51" />
<TextBlock FontSize="14"
<GroupBox Content="GroupBox"
Width="175.39666666666668"
Height="116"
Canvas.Left="8"
Canvas.Top="8" />
<TextBlock Width="66.710000000000008"
FontSize="14"
Text="StackPanel"
Canvas.Left="323"
Canvas.Top="28" />
Canvas.Left="8"
Canvas.Top="133" />
<StackPanel Width="209.99999999999994"
Height="114.09999999999991"
Background="#FFEDEDED"
Canvas.Left="8"
Canvas.Top="230.90000000000012">
<Panel.Children />
</StackPanel>
<Button Content="bla-blakjh"
Width="54.999999999999886"
Height="88.900000000000091"
Canvas.Left="163.00000000000006"
Canvas.Top="133.00000000000003" />
</Canvas>
</Window>

16
samples/XamlDesigner/TestFiles/4.xaml

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
<Window xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Name="root"
Title="Hydralisk">
<Window.Resources>
<sys:String1 x:Key="r1">Title</sys:String>
<sys:String x:Key="r2">Width</sys:String>
</Window.Resources>
<StackPanel>
<Button Name="b1"
Width="100"
Content="Button" />
<TextBlock Text="{Binding Path={StaticResource r1}, ElementName=root}" />
</StackPanel>
</Window>

13
samples/XamlDesigner/XamlDesigner.csproj

@ -111,6 +111,9 @@ @@ -111,6 +111,9 @@
<Compile Include="DragListener.cs" />
<Compile Include="DragTreeView.cs" />
<Compile Include="DragTreeViewItem.cs" />
<Compile Include="ErrorListView.xaml.cs">
<DependentUpon>ErrorListView.xaml</DependentUpon>
</Compile>
<Compile Include="ExtensionMethods.cs" />
<Compile Include="IconItem.cs" />
<Compile Include="MainWindow_Commands.cs" />
@ -144,6 +147,10 @@ @@ -144,6 +147,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ErrorListView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -161,6 +168,9 @@ @@ -161,6 +168,9 @@
<None Include="TestFiles\3.xaml">
<SubType>Designer</SubType>
</None>
<None Include="TestFiles\4.xaml">
<SubType>Designer</SubType>
</None>
<Page Include="Themes\Generic.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -188,6 +198,9 @@ @@ -188,6 +198,9 @@
<Name>WpfDesign.XamlDom</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Error.png" />
</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.

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

@ -21,6 +21,8 @@ using ICSharpCode.WpfDesign.Designer.Services; @@ -21,6 +21,8 @@ using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.PropertyGrid;
using ICSharpCode.WpfDesign.Designer.PropertyGrid;
using System.IO;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
namespace ICSharpCode.WpfDesign.AddIn
{
@ -31,12 +33,19 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -31,12 +33,19 @@ namespace ICSharpCode.WpfDesign.AddIn
{
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; }
@ -49,6 +58,7 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -49,6 +58,7 @@ namespace ICSharpCode.WpfDesign.AddIn
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;
@ -72,6 +82,8 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -72,6 +82,8 @@ namespace ICSharpCode.WpfDesign.AddIn
designer.LoadDesigner(r, settings);
UpdateTasks();
propertyGridView.PropertyGrid.SelectedItems = null;
designer.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged;
designer.DesignContext.Services.GetService<UndoService>().UndoStackChanged += OnUndoStackChanged;
@ -80,13 +92,38 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -80,13 +92,38 @@ namespace ICSharpCode.WpfDesign.AddIn
protected override void SaveInternal(OpenedFile file, System.IO.Stream stream)
{
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);
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);
}
}

63
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj

@ -35,6 +35,34 @@ @@ -35,6 +35,34 @@
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="FormsDesigner, Version=3.0.0.3434, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\FormsDesigner\FormsDesigner.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.Core, Version=3.0.0.3434, Culture=neutral, PublicKeyToken=f829da5c02be14ee, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\ICSharpCode.Core.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.Core.WinForms, Version=3.0.0.3434, Culture=neutral, PublicKeyToken=f829da5c02be14ee, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\ICSharpCode.Core.WinForms.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpDevelop, Version=3.0.0.3434, Culture=neutral, PublicKeyToken=f829da5c02be14ee, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\ICSharpCode.SharpDevelop.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpDevelop.Dom, Version=3.0.0.3434, Culture=neutral, PublicKeyToken=f829da5c02be14ee, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\ICSharpCode.SharpDevelop.Dom.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpDevelop.Widgets, Version=3.0.0.3434, Culture=neutral, PublicKeyToken=f829da5c02be14ee, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\ICSharpCode.SharpDevelop.Widgets.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.TextEditor, Version=3.0.0.3434, Culture=neutral, PublicKeyToken=4d61825e8dd49f1a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\bin\ICSharpCode.TextEditor.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
@ -74,41 +102,6 @@ @@ -74,41 +102,6 @@
<Compile Include="Src\WpfViewContent.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="..\..\FormsDesigner\Project\FormsDesigner.csproj">
<Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project>
<Name>FormsDesigner</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign.Designer\Project\WpfDesign.Designer.csproj">
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project>
<Name>WpfDesign.Designer</Name>

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

@ -19,10 +19,15 @@ using System.Windows.Navigation; @@ -19,10 +19,15 @@ using System.Windows.Navigation;
namespace ICSharpCode.WpfDesign.Designer
{
public class BasicMetadata : IMetadata
public static class BasicMetadata
{
public BasicMetadata()
static bool registered;
public static void Register()
{
if (registered) return;
registered = true;
Metadata.AddStandardValues(typeof(Brush), typeof(Brushes));
Metadata.AddStandardValues(typeof(Color), typeof(Colors));
Metadata.AddStandardValues(typeof(FontStretch), typeof(FontStretches));

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml

@ -4,12 +4,12 @@ @@ -4,12 +4,12 @@
xmlns:Default="clr-namespace:ICSharpCode.WpfDesign.Designer"
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls"
DataContext="{x:Null}"
Background="{x:Static SystemColors.AppWorkspaceBrush}">
Background="#888">
<Controls:ZoomControl x:Name="uxZoom">
<Default:DesignPanel x:Name="_designPanel">
<Border x:Name="_sceneContainer" />
</Default:DesignPanel>
</Controls:ZoomControl>
<Controls:ZoomControl x:Name="uxZoom">
<Default:DesignPanel x:Name="_designPanel">
<Border x:Name="_sceneContainer" />
</Default:DesignPanel>
</Controls:ZoomControl>
</UserControl>

14
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml.cs

@ -15,6 +15,9 @@ using System.Xml; @@ -15,6 +15,9 @@ using System.Xml;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Diagnostics;
using ICSharpCode.WpfDesign.XamlDom;
using System.Threading;
using System.Globalization;
namespace ICSharpCode.WpfDesign.Designer
{
@ -23,6 +26,12 @@ namespace ICSharpCode.WpfDesign.Designer @@ -23,6 +26,12 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary>
public partial class DesignSurface
{
static DesignSurface()
{
//TODO: this is for converters (see PropertyGrid)
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
}
public DesignSurface()
{
InitializeComponent();
@ -75,7 +84,10 @@ namespace ICSharpCode.WpfDesign.Designer @@ -75,7 +84,10 @@ namespace ICSharpCode.WpfDesign.Designer
_designContext = context;
_designPanel.Context = context;
_sceneContainer.Child = context.RootItem.View;
if (context.RootItem != null) {
_sceneContainer.Child = context.RootItem.View;
}
context.Services.RunWhenAvailable<UndoService>(
undoService => undoService.UndoStackChanged += delegate {

31
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/XamlErrorService.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.WpfDesign.XamlDom;
using System.Collections.ObjectModel;
namespace ICSharpCode.WpfDesign.Designer.Services
{
public class XamlErrorService : IXamlErrorSink
{
public XamlErrorService()
{
Errors = new ObservableCollection<XamlError>();
}
public ObservableCollection<XamlError> Errors { get; private set; }
public void ReportError(string message, int line, int column)
{
Errors.Add(new XamlError() { Message = message, Line = line, Column = column });
}
}
public class XamlError
{
public string Message { get; set; }
public int Line { get; set; }
public int Column { get; set; }
}
}

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

@ -177,6 +177,7 @@ @@ -177,6 +177,7 @@
<Compile Include="Services\UndoService.cs" />
<Compile Include="Services\ViewService.cs" />
<Compile Include="Services\WpfTopLevelWindowService.cs" />
<Compile Include="Services\XamlErrorService.cs" />
<Compile Include="SharedInstances.cs" />
<Compile Include="Xaml\XamlLoadSettings.cs" />
<Compile Include="Xaml\XamlModelCollectionElementsCollection.cs" />

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

@ -24,11 +24,6 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -24,11 +24,6 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
/// </summary>
public sealed class XamlDesignContext : DesignContext
{
static XamlDesignContext()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
}
readonly XamlDocument _doc;
readonly XamlDesignItem _rootItem;
internal readonly XamlComponentService _componentService;
@ -62,6 +57,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -62,6 +57,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
this.Services.AddService(typeof(ViewService), new DefaultViewService(this));
this.Services.AddService(typeof(OptionService), new OptionService());
var xamlErrorService = new XamlErrorService();
this.Services.AddService(typeof(XamlErrorService), xamlErrorService);
this.Services.AddService(typeof(IXamlErrorSink), xamlErrorService);
_componentService = new XamlComponentService(this);
this.Services.AddService(typeof(IComponentService), _componentService);
@ -85,7 +84,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -85,7 +84,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
parserSettings.CreateInstanceCallback = this.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory;
parserSettings.ServiceProvider = this.Services;
_doc = XamlParser.Parse(xamlReader, parserSettings);
_rootItem = _componentService.RegisterXamlComponentRecursive(_doc.RootElement);
if (_doc != null)
_rootItem = _componentService.RegisterXamlComponentRecursive(_doc.RootElement);
}
public override bool CanSave {
get { return Document != null; }
}
/// <summary>

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/IXamlErrorSink.cs

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.WpfDesign.XamlDom
{
public interface IXamlErrorSink
{
void ReportError(string message, int line, int column);
}
}

94
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/PositionXmlDocument.cs

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace ICSharpCode.WpfDesign.XamlDom
{
public class PositionXmlDocument : XmlDocument
{
IXmlLineInfo lineInfo;
public override XmlElement CreateElement (string prefix, string localName, string namespaceURI)
{
return new PositionXmlElement(prefix, localName, namespaceURI, this, lineInfo);
}
public override XmlAttribute CreateAttribute(string prefix, string localName, string namespaceURI)
{
return new PositionXmlAttribute(prefix, localName, namespaceURI, this, lineInfo);
}
public override void Load (XmlReader reader)
{
if (reader is IXmlLineInfo) lineInfo = (IXmlLineInfo)reader;
base.Load(reader);
lineInfo = null;
}
}
public class PositionXmlElement : XmlElement, IXmlLineInfo
{
public PositionXmlElement (string prefix, string localName, string namespaceURI, XmlDocument doc, IXmlLineInfo lineInfo)
: base(prefix, localName, namespaceURI, doc)
{
if (lineInfo != null) {
this.lineNumber = lineInfo.LineNumber;
this.linePosition = lineInfo.LinePosition;
this.hasLineInfo = true;
}
}
int lineNumber;
int linePosition;
bool hasLineInfo;
public bool HasLineInfo ()
{
return hasLineInfo;
}
public int LineNumber
{
get { return lineNumber; }
}
public int LinePosition
{
get { return linePosition; }
}
}
public class PositionXmlAttribute : XmlAttribute, IXmlLineInfo
{
public PositionXmlAttribute (string prefix, string localName, string namespaceURI, XmlDocument doc, IXmlLineInfo lineInfo)
: base(prefix, localName, namespaceURI, doc)
{
if (lineInfo != null) {
this.lineNumber = lineInfo.LineNumber;
this.linePosition = lineInfo.LinePosition;
this.hasLineInfo = true;
}
}
int lineNumber;
int linePosition;
bool hasLineInfo;
public bool HasLineInfo ()
{
return hasLineInfo;
}
public int LineNumber
{
get { return lineNumber; }
}
public int LinePosition
{
get { return linePosition; }
}
}
}

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

@ -65,8 +65,10 @@ @@ -65,8 +65,10 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="CollectionElementsCollection.cs" />
<Compile Include="CollectionSupport.cs" />
<Compile Include="IXamlErrorSink.cs" />
<Compile Include="MarkupExtensionParser.cs" />
<Compile Include="MarkupExtensionPrinter.cs" />
<Compile Include="PositionXmlDocument.cs" />
<Compile Include="XamlConstants.cs" />
<Compile Include="XamlDocument.cs" />
<Compile Include="XamlLoadException.cs" />

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

@ -201,6 +201,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -201,6 +201,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
get { return instance is MarkupExtension; }
}
public bool HasErrors { get; internal set; }
public DependencyObject DependencyObject {
get { return instance as DependencyObject; }
}

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

@ -55,9 +55,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -55,9 +55,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
if (stream == null)
throw new ArgumentNullException("stream");
XmlDocument doc = new XmlDocument();
doc.Load(stream);
return Parse(doc, settings);
return Parse(XmlReader.Create(stream), settings);
}
/// <summary>
@ -67,9 +65,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -67,9 +65,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
if (reader == null)
throw new ArgumentNullException("reader");
XmlDocument doc = new XmlDocument();
doc.Load(reader);
return Parse(doc, settings);
return Parse(XmlReader.Create(reader), settings);
}
/// <summary>
@ -79,9 +75,19 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -79,9 +75,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
if (reader == null)
throw new ArgumentNullException("reader");
XmlDocument doc = new XmlDocument();
doc.Load(reader);
return Parse(doc, settings);
XmlDocument doc = new PositionXmlDocument();
var errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink));
try {
doc.Load(reader);
return Parse(doc, settings);
} catch (XmlException x) {
if (errorSink != null)
errorSink.ReportError(x.Message, x.LineNumber, x.LinePosition);
}
return null;
}
/// <summary>
@ -95,8 +101,16 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -95,8 +101,16 @@ namespace ICSharpCode.WpfDesign.XamlDom
throw new ArgumentNullException("document");
XamlParser p = new XamlParser();
p.settings = settings;
p.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink));
p.document = new XamlDocument(document, settings);
p.document.ParseComplete(p.ParseObject(document.DocumentElement));
try {
var root = p.ParseObject(document.DocumentElement);
p.document.ParseComplete(root);
} catch (Exception x) {
p.ReportException(x, document.DocumentElement);
}
return p.document;
}
#endregion
@ -105,6 +119,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -105,6 +119,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlDocument document;
XamlParserSettings settings;
IXamlErrorSink errorSink;
Type FindType(string namespaceUri, string localName)
{
@ -131,6 +146,21 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -131,6 +146,21 @@ namespace ICSharpCode.WpfDesign.XamlDom
XmlSpace currentXmlSpace = XmlSpace.None;
XamlObject currentXamlObject;
void ReportException(Exception x, XmlNode node)
{
if (errorSink != null) {
var lineInfo = node as IXmlLineInfo;
if (lineInfo != null) {
errorSink.ReportError(x.Message, lineInfo.LineNumber, lineInfo.LinePosition);
} else {
errorSink.ReportError(x.Message, 0, 0);
}
if (currentXamlObject != null) {
currentXamlObject.HasErrors = true;
}
}
}
XamlObject ParseObject(XmlElement element)
{
Type elementType = settings.TypeFinder.GetType(element.NamespaceURI, element.LocalName);
@ -319,6 +349,16 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -319,6 +349,16 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
XamlPropertyValue ParseValue(XmlNode childNode)
{
try {
return ParseValueCore(childNode);
} catch (Exception x) {
ReportException(x, childNode);
}
return null;
}
XamlPropertyValue ParseValueCore(XmlNode childNode)
{
XmlText childText = childNode as XmlText;
if (childText != null) {
@ -426,9 +466,13 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -426,9 +466,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
propertyName = qualifiedName.Substring(pos + 1);
}
static void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute)
void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute)
{
ParseObjectAttribute(obj, attribute, true);
try {
ParseObjectAttribute(obj, attribute, true);
} catch (Exception x) {
ReportException(x, attribute);
}
}
internal static void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute, bool real)

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

@ -42,7 +42,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -42,7 +42,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
propertyValue.ParentProperty = this;
}
UpdateValueOnInstance();
ValueOnInstance = PropertyValue.GetValueFor(propertyInfo);
}
internal XamlProperty(XamlObject parentObject, XamlPropertyInfo propertyInfo)

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

@ -42,6 +42,8 @@ namespace ICSharpCode.WpfDesign @@ -42,6 +42,8 @@ namespace ICSharpCode.WpfDesign
get;
}
public abstract bool CanSave { get; }
/// <summary>
/// Save the designed elements as XML.
/// </summary>

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs

@ -12,23 +12,6 @@ namespace ICSharpCode.WpfDesign @@ -12,23 +12,6 @@ namespace ICSharpCode.WpfDesign
{
public static class Metadata
{
//TODO: Another way?
static Metadata()
{
foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
RegisterAssembly(a);
}
}
public static void RegisterAssembly(Assembly a)
{
foreach (var t in a.GetExportedTypes()) {
if (t.GetInterface("IMetadata") == typeof(IMetadata)) {
Activator.CreateInstance(t);
}
}
}
public static string GetFullName(this DependencyProperty p)
{
return p.OwnerType.FullName + "." + p.Name;
@ -240,10 +223,6 @@ namespace ICSharpCode.WpfDesign @@ -240,10 +223,6 @@ namespace ICSharpCode.WpfDesign
}
}
public interface IMetadata
{
}
public class NumberRange
{
public double Min;

Loading…
Cancel
Save