@ -6,7 +6,7 @@
@@ -6,7 +6,7 @@
// </file>
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Drawing ;
using System.IO ;
using System.ComponentModel.Design ;
@ -18,6 +18,7 @@ using System.Windows.Forms;
@@ -18,6 +18,7 @@ using System.Windows.Forms;
using System.Windows.Forms.Design ;
using ICSharpCode.Core ;
using ICSharpCode.SharpDevelop.Dom ;
using ICSharpCode.TextEditor ;
using ICSharpCode.TextEditor.Document ;
@ -86,7 +87,7 @@ namespace Grunwald.BooBinding.Designer
@@ -86,7 +87,7 @@ namespace Grunwald.BooBinding.Designer
base . BeginLoad ( host ) ;
}
protected override void OnEndLoad ( bool successful , ICollection errors )
protected override void OnEndLoad ( bool successful , System . Collections . ICollection errors )
{
this . loading = false ;
base . OnEndLoad ( successful , errors ) ;
@ -109,38 +110,89 @@ namespace Grunwald.BooBinding.Designer
@@ -109,38 +110,89 @@ namespace Grunwald.BooBinding.Designer
CodeCompileUnit ParseForm ( )
{
lastTextContent = TextContent ;
ParseInformation parseInfo = ParserService . GetParseInformation ( textEditorControl . FileName ) ;
// ensure that there are no syntax errors in the file:
Module mainModule = Parse ( textEditorControl . FileName , lastTextContent ) ;
IClass formClass ;
List < IClass > parts = NRefactoryDesignerLoader . FindFormClassParts ( parseInfo , out formClass ) ;
IMethod initMethod = FormsDesignerSecondaryDisplayBinding . GetInitializeComponents ( formClass ) ;
if ( initMethod = = null )
throw new FormsDesignerLoadException ( "The InitializeComponent method was not found. Designer cannot be loaded." ) ;
Module module = new Module ( ) ;
module . Namespace = new NamespaceDeclaration ( formClass . Namespace ) ;
ClassDefinition cld = new ClassDefinition ( ) ;
cld . Name = formClass . Name ;
module . Members . Add ( cld ) ;
if ( formClass . BaseClass = = null )
throw new FormsDesignerLoadException ( "formClass.BaseClass returned null." ) ;
cld . BaseTypes . Add ( new SimpleTypeReference ( formClass . BaseClass . FullyQualifiedName ) ) ;
foreach ( IField f in formClass . Fields ) {
if ( f . ReturnType . IsDefaultReturnType ) {
Field field = new Field ( ) ;
field . Name = f . Name ;
field . Type = new SimpleTypeReference ( f . ReturnType . FullyQualifiedName ) ;
cld . Members . Add ( field ) ;
}
}
string fileName = initMethod . DeclaringType . CompilationUnit . FileName ;
Module parsedModule ;
if ( FileUtility . IsEqualFileName ( fileName , textEditorControl . FileName ) )
parsedModule = mainModule ;
else
parsedModule = Parse ( fileName , ParserService . GetParseableFileContent ( fileName ) ) ;
// Now find InitializeComponent in parsed module and put it into our new module
foreach ( TypeMember m in parsedModule . Members ) {
TypeDefinition td = m as TypeDefinition ;
if ( td = = null )
continue ;
foreach ( TypeMember m2 in td . Members ) {
Method method = m2 as Method ;
if ( method ! = null
& & FormsDesignerSecondaryDisplayBinding . IsInitializeComponentsMethodName ( method . Name )
& & method . Parameters . Count = = 0 )
{
cld . Members . Add ( method ) ;
Console . WriteLine ( module . ToCodeString ( ) ) ;
CodeDomVisitor visitor = new CodeDomVisitor ( parseInfo . MostRecentCompilationUnit . ProjectContent ) ;
module . Accept ( visitor ) ;
// output generated CodeDOM to the console :
ICSharpCode . NRefactory . Parser . CodeDOMVerboseOutputGenerator outputGenerator = new ICSharpCode . NRefactory . Parser . CodeDOMVerboseOutputGenerator ( ) ;
outputGenerator . GenerateCodeFromMember ( visitor . OutputCompileUnit . Namespaces [ 0 ] . Types [ 0 ] , Console . Out , null ) ;
provider . GenerateCodeFromCompileUnit ( visitor . OutputCompileUnit , Console . Out , null ) ;
return visitor . OutputCompileUnit ;
}
}
}
throw new FormsDesignerLoadException ( "Could not find InitializeComponent in parsed module." ) ;
}
Module Parse ( string fileName , string fileContent )
{
BooParsingStep step = new BooParsingStep ( ) ;
StringBuilder errors = new StringBuilder ( ) ;
Module module = BooParser . ParseModule ( 4 , new CompileUnit ( ) , textEditorControl . FileName ,
new StringReader ( lastTextContent ) ,
new StringReader ( fi leContent) ,
delegate ( antlr . RecognitionException e ) {
errors . AppendLine ( e . ToString ( ) ) ;
} ) ;
if ( errors . Length > 0 ) {
throw new FormsDesignerLoadException ( errors . ToString ( ) ) ;
throw new FormsDesignerLoadException ( "Syntax errors in " + fileName + ":\r\n" + errors . ToString ( ) ) ;
}
// Try to fix the type names to fully qualified ones
ParseInformation parseInfo = ParserService . GetParseInformation ( textEditorControl . FileName ) ;
/ *
bool foundInitMethod = false ;
//FixTypeNames(p.CompilationUnit, parseInfo.BestCompilationUnit, ref foundInitMethod);
if ( ! foundInitMethod )
throw new FormsDesignerLoadException ( "The InitializeComponent method was not found. Designer cannot be loaded." ) ;
* /
CodeDomVisitor visitor = new CodeDomVisitor ( parseInfo . MostRecentCompilationUnit . ProjectContent ) ;
module . Accept ( visitor ) ;
// output generated CodeDOM to the console :
ICSharpCode . NRefactory . Parser . CodeDOMVerboseOutputGenerator outputGenerator = new ICSharpCode . NRefactory . Parser . CodeDOMVerboseOutputGenerator ( ) ;
outputGenerator . GenerateCodeFromMember ( visitor . OutputCompileUnit . Namespaces [ 0 ] . Types [ 0 ] , Console . Out , null ) ;
provider . GenerateCodeFromCompileUnit ( visitor . OutputCompileUnit , Console . Out , null ) ;
return visitor . OutputCompileUnit ;
return module ;
}
protected override void Write ( CodeCompileUnit unit )