Browse Source

Show error message when going to designer mode in a file with syntax errors instead of displaying an empty form.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@463 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
9854f92d06
  1. 1
      src/AddIns/DisplayBindings/FormDesigner/Project/FormDesigner.csproj
  2. 11
      src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/DesignerGenerator/VBNetDesignerGenerator.cs
  3. 32
      src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/DesignerLoader/FormDesignerLoadException.cs
  4. 4
      src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/DesignerLoader/NRefactoryDesignerLoader.cs
  5. 18
      src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/FormDesignerViewContent.cs
  6. 8
      src/Libraries/NRefactory/Project/Src/Parser/Errors.cs
  7. 1
      src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

1
src/AddIns/DisplayBindings/FormDesigner/Project/FormDesigner.csproj

@ -107,6 +107,7 @@
</None> </None>
<Compile Include="Src\FormDesigner\DesignerGenerator\VBNetDesignerGenerator.cs" /> <Compile Include="Src\FormDesigner\DesignerGenerator\VBNetDesignerGenerator.cs" />
<Compile Include="Src\FormDesigner\DesignerLoader\DesignerLoaderProvider.cs" /> <Compile Include="Src\FormDesigner\DesignerLoader\DesignerLoaderProvider.cs" />
<Compile Include="Src\FormDesigner\DesignerLoader\FormDesignerLoadException.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj"> <ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj">

11
src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/DesignerGenerator/VBNetDesignerGenerator.cs

@ -158,7 +158,7 @@ namespace ICSharpCode.FormDesigner
return null; return null;
} }
protected static string GenerateParams(EventDescriptor edesc, bool paramNames) protected static string GenerateParams(EventDescriptor edesc)
{ {
System.Type type = edesc.EventType; System.Type type = edesc.EventType;
MethodInfo mInfo = type.GetMethod("Invoke"); MethodInfo mInfo = type.GetMethod("Invoke");
@ -173,15 +173,14 @@ namespace ICSharpCode.FormDesigner
for (int i = 0; i < mInfo.GetParameters().Length; ++i) { for (int i = 0; i < mInfo.GetParameters().Length; ++i) {
ParameterInfo pInfo = mInfo.GetParameters()[i]; ParameterInfo pInfo = mInfo.GetParameters()[i];
param += pInfo.Name;
param += " As ";
string typeStr = pInfo.ParameterType.ToString(); string typeStr = pInfo.ParameterType.ToString();
if (csa != null) { if (csa != null) {
typeStr = csa.GetIntrinsicTypeName(typeStr); typeStr = csa.GetIntrinsicTypeName(typeStr);
} }
param += typeStr; param += typeStr;
if (paramNames == true) {
param += " ";
param += pInfo.Name;
}
if (i + 1 < mInfo.GetParameters().Length) { if (i + 1 < mInfo.GetParameters().Length) {
param += ", "; param += ", ";
} }
@ -217,7 +216,7 @@ namespace ICSharpCode.FormDesigner
int offset = viewContent.Document.GetLineSegment(c.Region.EndLine - 1).Offset; int offset = viewContent.Document.GetLineSegment(c.Region.EndLine - 1).Offset;
string param = GenerateParams(edesc, true); string param = GenerateParams(edesc);
string text = "Sub " + eventMethodName + "(" + param + ")\n" + string text = "Sub " + eventMethodName + "(" + param + ")\n" +
body + body +

32
src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/DesignerLoader/FormDesignerLoadException.cs

@ -0,0 +1,32 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 08.09.2005
* Time: 17:25
*/
using System;
using System.Runtime.Serialization;
namespace ICSharpCode.FormDesigner
{
[Serializable()]
public class FormDesignerLoadException : ApplicationException
{
public FormDesignerLoadException() : base()
{
}
public FormDesignerLoadException(string message) : base(message)
{
}
public FormDesignerLoadException(string message, Exception innerException) : base(message, innerException)
{
}
protected FormDesignerLoadException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}

4
src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/DesignerLoader/NRefactoryDesignerLoader.cs

@ -113,6 +113,10 @@ namespace ICSharpCode.FormDesigner
ICSharpCode.NRefactory.Parser.IParser p = ICSharpCode.NRefactory.Parser.ParserFactory.CreateParser(language, new StringReader(lastTextContent)); ICSharpCode.NRefactory.Parser.IParser p = ICSharpCode.NRefactory.Parser.ParserFactory.CreateParser(language, new StringReader(lastTextContent));
p.Parse(); p.Parse();
if (p.Errors.count > 0) {
throw new FormDesignerLoadException(p.Errors.ErrorOutput);
}
// Try to fix the type names to fully qualified ones // Try to fix the type names to fully qualified ones
ParseInformation parseInfo = ParserService.GetParseInformation(textEditorControl.FileName); ParseInformation parseInfo = ParserService.GetParseInformation(textEditorControl.FileName);
FixTypeNames(p.CompilationUnit, parseInfo.BestCompilationUnit); FixTypeNames(p.CompilationUnit, parseInfo.BestCompilationUnit);

18
src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/FormDesignerViewContent.cs

@ -54,8 +54,6 @@ namespace ICSharpCode.FormDesigner
protected ITextEditorControlProvider textAreaControlProvider; protected ITextEditorControlProvider textAreaControlProvider;
protected string compilationErrors;
Panel p = new Panel(); Panel p = new Panel();
DesignSurface designSurface; DesignSurface designSurface;
@ -190,7 +188,21 @@ namespace ICSharpCode.FormDesigner
p.Controls.Add(designer); p.Controls.Add(designer);
} }
} catch (Exception e) { } catch (Exception e) {
MessageService.ShowError(e); failedDesignerInitialize = true;
TextBox errorText = new TextBox();
errorText.Multiline = true;
if (e.InnerException is FormDesignerLoadException)
errorText.Text = e.InnerException.Message;
else if (e is FormDesignerLoadException)
errorText.Text = e.Message;
else
errorText.Text = e.ToString();
errorText.Dock = DockStyle.Fill;
p.Controls.Add(errorText);
Control title = new Label();
title.Text = "Failed to load designer. Check the source code for syntax errors.";
title.Dock = DockStyle.Top;
p.Controls.Add(title);
} }
} }

8
src/Libraries/NRefactory/Project/Src/Parser/Errors.cs

@ -1,4 +1,4 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright> // <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license> // <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="none" email=""/> // <owner name="none" email=""/>
@ -42,14 +42,12 @@ namespace ICSharpCode.NRefactory.Parser
void DefaultCodeError(int line, int col, int n) void DefaultCodeError(int line, int col, int n)
{ {
errorText.Append(String.Format("-- line {0} col {1}: error {2}", line, col, n)); errorText.AppendLine(String.Format("-- line {0} col {1}: error {2}", line, col, n));
errorText.Append("\n");
count++; count++;
} }
void DefaultMsgError(int line, int col, string s) { void DefaultMsgError(int line, int col, string s) {
errorText.Append(String.Format("-- line {0} col {1}: {2}", line, col, s)); errorText.AppendLine(String.Format("-- line {0} col {1}: {2}", line, col, s));
errorText.Append("\n");
count++; count++;
} }
} // Errors } // Errors

1
src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs

@ -302,6 +302,7 @@ namespace ICSharpCode.SharpDevelop.Project
public static void CloseSolution() public static void CloseSolution()
{ {
if (openSolution != null) { if (openSolution != null) {
CurrentProject = null;
OnSolutionClosing(new SolutionEventArgs(openSolution)); OnSolutionClosing(new SolutionEventArgs(openSolution));
openSolution.Dispose(); openSolution.Dispose();

Loading…
Cancel
Save