From 6b249a878d6574d2babd157ae4d465f9ea53faad Mon Sep 17 00:00:00 2001 From: Kumar Devvrat Date: Tue, 10 Aug 2010 04:17:46 +0000 Subject: [PATCH] - 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 --- .../Images/Icons.32x32.Error.png | Bin 0 -> 2391 bytes .../WpfDesign.AddIn/Src/WpfDocumentError.xaml | 55 ++++++++++++ .../Src/WpfDocumentError.xaml.cs | 30 +++++++ .../WpfDesign.AddIn/Src/WpfViewContent.cs | 83 ++++++++++++------ .../WpfDesign.AddIn/WpfDesign.AddIn.csproj | 7 ++ .../Project/Xaml/XamlDesignContext.cs | 11 ++- .../Project/Xaml/XamlLoadSettings.cs | 2 + 7 files changed, 155 insertions(+), 33 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Images/Icons.32x32.Error.png create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Images/Icons.32x32.Error.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Images/Icons.32x32.Error.png new file mode 100644 index 0000000000000000000000000000000000000000..28ba9c4e13ed5d09058fa388b0a2ee6d86c23b43 GIT binary patch literal 2391 zcmV-d38?moP)Px#1ZP1_K>z@;j|==^1poj5AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy32;bRa{vGf5C8xR5CN?ty>$Qp2*621K~z{rjaLUyRc9K#nh0u) z#>8%nSdy#)qOi6k#zHg}EHlw$GZw(OF-{am1B zga~SctOMezJFDRdmUs4i_dXb&pyth-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(_4^V;!^!9cRpEgnlDy)m6h1NVg(ZT?K$En;yB|)5c`OOBwtDN>(>{- z0sc@fb1p`Z{3sF27pK@sY&=P<;l>i3o!ye08DH&dj4^ps=&3-^s&96j!*X&(Rlgg^T0+Gen}X zZz^}s@&^x4->h$GeLdoMQVM6E14J-M0~p_*=t|6)H3RAA&%|f~yxfsM0b-A+jUl4B zA*B}-#F#9@6DO(yCG$pz*jN$71*rVqJrlX{wzk;IcY%Z-1q3nvJYIWr?}qhmtF*nK z@o*45z(O4$``Gy~@uS!`WQba0`Q=TYjwn8hHzJOKP7-o2qU2qooQ{mYIBsaW`D_p2 zV-(=d{+-w!J9;Fd!uOjBNZKEwPLp5(JBg4VhznfZvU%hd8;^=J;t&G~qKRXKkc-vw zO%Bfir?@Ej3MsLj*v3BMz-YE5`;{w}@lcYXZO6@zM`7HdA}Jt%okh9W7es^*B0xwQ z5n*hLQ-_E!;$Os0Be4kZB(@l{pUbN`r~Bm3SjOmZ(*sF!5q^{H)v>UPBK-N0*eEp= zG2%$5@hXIkE(x)?CVeGqZ(^&FdhqU?qY$Lhl&>`^J_D_@Z;0ym5l@#SFTO8+Oy-XcK zf_ps&ArpwrLgsGFSlZHeHNP9qYkMy9w%qc!d2B*KUV4j!U;4jrm)~|c+E~Ml!M2MV zganr?8%c#&u+8|~g?+{o9XO-<@aQ#b=5%$%E7E1P%Js@Wr{{QPTo+H literal 0 HcmV?d00001 diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml new file mode 100644 index 0000000000..50a854975a --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + View XAML + + + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml.cs new file mode 100644 index 0000000000..e27d15f7cf --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDocumentError.xaml.cs @@ -0,0 +1,30 @@ +// +// +// +// +// $Revision: $ +// +using System; +using System.Windows; +using System.Windows.Controls; + +using ICSharpCode.SharpDevelop.Gui; + +namespace ICSharpCode.WpfDesign.AddIn +{ + /// + /// A friendly error window displayed when the WPF document does not parse correctly. + /// + public partial class WpfDocumentError : UserControl + { + public WpfDocumentError() + { + InitializeComponent(); + } + + void ViewXaml(object sender,RoutedEventArgs e) + { + WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.SwitchView(0); + } + } +} \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs index a597dfa744..c17d8dcf85 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs @@ -6,14 +6,16 @@ // 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; using ICSharpCode.WpfDesign.Designer.Services; using ICSharpCode.WpfDesign.Designer.Xaml; -using ICSharpCode.Core.Presentation; - namespace ICSharpCode.WpfDesign.AddIn { /// @@ -42,7 +42,7 @@ namespace ICSharpCode.WpfDesign.AddIn static WpfViewContent() { - DragDropExceptionHandler.UnhandledException += delegate(object sender, ThreadExceptionEventArgs e) { + DragDropExceptionHandler.UnhandledException += delegate(object sender, ThreadExceptionEventArgs e) { ICSharpCode.Core.MessageService.ShowException(e.Exception); }; } @@ -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 context.Services.AddService(typeof(ChooseClassServiceBase), new IdeChooseClassService()); }); settings.TypeFinder = MyTypeFinder.Create(this.PrimaryFile); - - designer.LoadDesigner(r, settings); - - designer.ContextMenuOpening += (sender, e) => MenuService.ShowContextMenu(e.OriginalSource as UIElement, designer, "/Addins/WpfDesign/Designer/ContextMenu"); - - UpdateTasks(); - - if (outline != null && designer.DesignContext != null && designer.DesignContext.RootItem != null) { - outline.Root = OutlineNode.Create(designer.DesignContext.RootItem); + try{ + settings.ReportErrors=UpdateTasks; + designer.LoadDesigner(r, settings); + + 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); + } + + 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().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().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(); 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) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj index 333781b053..89afcec4a7 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj @@ -52,6 +52,7 @@ + Always @@ -85,11 +86,16 @@ + + WpfDocumentError.xaml + Code + + {2748AD25-9C63-4E12-877B-4DCE96FBED54} ICSharpCode.SharpDevelop @@ -145,6 +151,7 @@ + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs index 9e81c2a4ce..54dc9f2342 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs @@ -25,7 +25,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml public sealed class XamlDesignContext : DesignContext { readonly XamlDocument _doc; - readonly XamlDesignItem _rootItem; + readonly XamlDesignItem _rootItem; internal readonly XamlComponentService _componentService; readonly XamlEditOperations _xamlEditOperations; @@ -90,11 +90,14 @@ 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); } - + /// /// Saves the XAML DOM into the XML writer. diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlLoadSettings.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlLoadSettings.cs index 281526a8f4..ed37263d1a 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlLoadSettings.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlLoadSettings.cs @@ -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 { public readonly ICollection DesignerAssemblies = new List(); public readonly List> CustomServiceRegisterFunctions = new List>(); + public Action ReportErrors; XamlTypeFinder typeFinder = XamlTypeFinder.CreateWpfTypeFinder(); public XamlTypeFinder TypeFinder {