Browse Source

- Hide the exceptions show by AbstractViewContentHandlingLoadErrors, instead show a friendly error window.

- Display errors in Xaml Document in the Error list pad.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6399 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Kumar Devvrat 15 years ago
parent
commit
6b249a878d
  1. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Images/Icons.32x32.Error.png
  2. 55
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml
  3. 30
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml.cs
  4. 73
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  5. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj
  6. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  7. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlLoadSettings.cs

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Images/Icons.32x32.Error.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

55
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<UserControl
x:Class="ICSharpCode.WpfDesign.AddIn.WpfDocumentError" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="#888">
<Border
Background="#DDD"
BorderBrush="#999"
BorderThickness="2"
Height="150"
Width="500">
<Border.Effect>
<DropShadowEffect
BlurRadius="15"
Color="#777"
ShadowDepth="2" />
</Border.Effect>
<Grid>
<Image
Name="ErrorIcon"
Width="32"
Height="32"
Margin="10,10,0,0"
Source="../Images/Icons.32x32.Error.png"
HorizontalAlignment="Left"
VerticalAlignment="Top" />
<TextBlock
Text="Problem Loading"
Foreground="#333"
Margin="50,10,0,0"
FontSize="16" />
<Line
X1="50"
X2="450"
Y1="40"
Y2="40"
Stroke="#444"
StrokeThickness="0.5" />
<TextBlock
TextWrapping="Wrap"
Text="The document contains errors which should be fixed so that the designer can load. Switch to XAML Tab to fix the errors."
Margin="50,50,20,0"
VerticalAlignment="Top"
FontSize="14"
Foreground="#333" />
<TextBlock
Margin="50,0,0,20"
HorizontalAlignment="Left"
VerticalAlignment="Bottom">
<Hyperlink
Foreground="Black"
Click="ViewXaml">View XAML</Hyperlink>
</TextBlock>
</Grid>
</Border>
</UserControl>

30
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Kumar Devvrat"/>
// <version>$Revision: $</version>
// </file>
using System;
using System.Windows;
using System.Windows.Controls;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WpfDesign.AddIn
{
/// <summary>
/// A friendly error window displayed when the WPF document does not parse correctly.
/// </summary>
public partial class WpfDocumentError : UserControl
{
public WpfDocumentError()
{
InitializeComponent();
}
void ViewXaml(object sender,RoutedEventArgs e)
{
WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.SwitchView(0);
}
}
}

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

@ -6,14 +6,16 @@ @@ -6,14 +6,16 @@
// </file>
using System;
using System.Windows;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using System.Windows.Markup;
using System.Xml;
using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
@ -23,8 +25,6 @@ using ICSharpCode.WpfDesign.Designer.PropertyGrid; @@ -23,8 +25,6 @@ using ICSharpCode.WpfDesign.Designer.PropertyGrid;
using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.Core.Presentation;
namespace ICSharpCode.WpfDesign.AddIn
{
/// <summary>
@ -62,12 +62,17 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -62,12 +62,17 @@ namespace ICSharpCode.WpfDesign.AddIn
{
Debug.Assert(file == this.PrimaryFile);
_stream = new MemoryStream();
stream.CopyTo(_stream);
stream.Position = 0;
if (designer == null) {
// initialize designer on first load
designer = new DesignSurface();
this.UserContent = designer;
InitPropertyEditor();
}
this.UserContent=designer;
if (outline != null) {
outline.Root = null;
}
@ -83,52 +88,72 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -83,52 +88,72 @@ namespace ICSharpCode.WpfDesign.AddIn
context.Services.AddService(typeof(ChooseClassServiceBase), new IdeChooseClassService());
});
settings.TypeFinder = MyTypeFinder.Create(this.PrimaryFile);
try{
settings.ReportErrors=UpdateTasks;
designer.LoadDesigner(r, settings);
designer.LoadDesigner(r, settings);
designer.ContextMenuOpening += (sender, e) => MenuService.ShowContextMenu(e.OriginalSource as UIElement, designer, "/Addins/WpfDesign/Designer/ContextMenu");
designer.ContextMenuOpening += (sender, e) => MenuService.ShowContextMenu(e.OriginalSource as UIElement, designer, "/Addins/WpfDesign/Designer/ContextMenu");
if (outline != null && designer.DesignContext != null && designer.DesignContext.RootItem != null) {
outline.Root = OutlineNode.Create(designer.DesignContext.RootItem);
}
UpdateTasks();
var outlineContent = GetService(typeof(IOutlineContentHost));
if(outlineContent==null)
this.Services.AddService(typeof(IOutlineContentHost),Outline);
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;
}
catch
{
this.UserContent=new WpfDocumentError();
}
var outlineContent = GetService(typeof(IOutlineContentHost));
if(outlineContent==null)
this.Services.AddService(typeof(IOutlineContentHost),Outline);
propertyGridView.PropertyGrid.SelectedItems = null;
designer.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged;
designer.DesignContext.Services.GetService<UndoService>().UndoStackChanged += OnUndoStackChanged;
}
}
private MemoryStream _stream;
protected override void SaveInternal(OpenedFile file, System.IO.Stream stream)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = EditorControlService.GlobalOptions.IndentationString;
settings.NewLineOnAttributes = true;
using (XmlWriter xmlWriter = XmlTextWriter.Create(stream, settings)) {
designer.SaveDesigner(xmlWriter);
if(designer.DesignContext!=null){
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = EditorControlService.GlobalOptions.IndentationString;
settings.NewLineOnAttributes = true;
using (XmlWriter xmlWriter = XmlTextWriter.Create(stream, settings)) {
designer.SaveDesigner(xmlWriter);
}
}
else{
_stream.Position = 0;
using (var reader = new StreamReader(_stream))
using (var writer = new StreamWriter(stream)) {
writer.Write(reader.ReadToEnd());
}
}
}
void UpdateTasks()
void UpdateTasks(XamlErrorService xamlErrorService)
{
Debug.Assert(xamlErrorService!=null);
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);
}
if (xamlErrorService.Errors.Count != 0) {
WorkbenchSingleton.Workbench.GetPad(typeof (ErrorListPad)).BringPadToFront();
}
}
void OnUndoStackChanged(object sender, EventArgs e)

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

@ -52,6 +52,7 @@ @@ -52,6 +52,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Icons.32x32.Error.png" />
<None Include="WpfDesign.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
@ -85,11 +86,16 @@ @@ -85,11 +86,16 @@
<Compile Include="Src\PropertyDescriptionService.cs" />
<Compile Include="Src\WpfAndWinFormsTopLevelWindowService.cs" />
<Compile Include="Src\WpfDisplayBinding.cs" />
<Compile Include="Src\WpfDocumentError.xaml.cs">
<DependentUpon>WpfDocumentError.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\WpfSideTabItem.cs" />
<Compile Include="Src\WpfToolbox.cs" />
<Compile Include="Src\WpfViewContent.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="Src\WpfDocumentError.xaml" />
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>
@ -145,6 +151,7 @@ @@ -145,6 +151,7 @@
<Page Include="Src\ObjectEditor.xaml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Images" />
<Folder Include="Src\ImageSourceEditor" />
<Folder Include="Src\Commands" />
</ItemGroup>

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

@ -90,9 +90,12 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -90,9 +90,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)
loadSettings.ReportErrors(xamlErrorService);
_xamlEditOperations=new XamlEditOperations(this,parserSettings);
_rootItem = _componentService.RegisterXamlComponentRecursive(_doc.RootElement);
_xamlEditOperations=new XamlEditOperations(this,parserSettings);
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlLoadSettings.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer.Xaml
@ -19,6 +20,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -19,6 +20,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
{
public readonly ICollection<Assembly> DesignerAssemblies = new List<Assembly>();
public readonly List<Action<XamlDesignContext>> CustomServiceRegisterFunctions = new List<Action<XamlDesignContext>>();
public Action<XamlErrorService> ReportErrors;
XamlTypeFinder typeFinder = XamlTypeFinder.CreateWpfTypeFinder();
public XamlTypeFinder TypeFinder {

Loading…
Cancel
Save