~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/VBNetDesignerGenerator.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Text;
 
6
using ICSharpCode.NRefactory.Ast;
 
7
using ICSharpCode.NRefactory.PrettyPrinter;
 
8
using ICSharpCode.SharpDevelop.Dom;
 
9
using ICSharpCode.SharpDevelop.Editor;
 
10
 
 
11
namespace ICSharpCode.FormsDesigner
 
12
{
 
13
        public class VBNetDesignerGenerator : AbstractDesignerGenerator
 
14
        {
 
15
                protected override System.CodeDom.Compiler.CodeDomProvider CreateCodeProvider()
 
16
                {
 
17
                        return new Microsoft.VisualBasic.VBCodeProvider();
 
18
                }
 
19
                
 
20
                protected override DomRegion GetReplaceRegion(IDocument document, IMethod method)
 
21
                {
 
22
                        DomRegion r = method.BodyRegion;
 
23
                        return new DomRegion(r.BeginLine + 1, 1, r.EndLine, 1);
 
24
                }
 
25
                
 
26
                protected override void RemoveFieldDeclaration(IDocument document, IField field)
 
27
                {
 
28
                        // In VB, the field region begins at the start of the declaration
 
29
                        // and ends on the first column of the line following the declaration.
 
30
                        int startOffset = document.PositionToOffset(field.Region.BeginLine, 1);
 
31
                        int endOffset   = document.PositionToOffset(field.Region.EndLine, 1);
 
32
                        document.Remove(startOffset, endOffset - startOffset);
 
33
                }
 
34
                
 
35
                protected override void ReplaceFieldDeclaration(IDocument document, IField oldField, string newFieldDeclaration)
 
36
                {
 
37
                        // In VB, the field region begins at the start of the declaration
 
38
                        // and ends on the first column of the line following the declaration.
 
39
                        int startOffset = document.PositionToOffset(oldField.Region.BeginLine, 1);
 
40
                        int endOffset   = document.PositionToOffset(oldField.Region.EndLine, 1);
 
41
                        document.Replace(startOffset, endOffset - startOffset, tabs + newFieldDeclaration + Environment.NewLine);
 
42
                }
 
43
                
 
44
                protected override string CreateEventHandler(Type eventType, string eventMethodName, string body, string indentation)
 
45
                {
 
46
                        string param = GenerateParams(eventType);
 
47
                        
 
48
                        StringBuilder b = new StringBuilder();
 
49
                        b.AppendLine(indentation);
 
50
                        b.AppendLine(indentation + "Sub " + eventMethodName + "(" + param + ")");
 
51
                        if (string.IsNullOrEmpty(body)) {
 
52
                                if (ICSharpCode.FormsDesigner.Gui.OptionPanels.GeneralOptionsPanel.InsertTodoComment) {
 
53
                                        body = "' TODO: Implement " + eventMethodName;
 
54
                                }
 
55
                        }
 
56
                        string singleIndent = EditorControlService.GlobalOptions.IndentationString;
 
57
                        b.AppendLine(indentation + singleIndent + body);
 
58
                        b.AppendLine(indentation + "End Sub");
 
59
                        return b.ToString();
 
60
                }
 
61
                
 
62
                protected string GenerateParams(Type eventType)
 
63
                {
 
64
                        VBNetOutputVisitor v = new VBNetOutputVisitor();
 
65
                        MethodDeclaration md = ConvertEventInvokeMethodToNRefactory(this.CurrentClassPart, eventType, "name");
 
66
                        if (md != null) {
 
67
                                v.AppendCommaSeparatedList(md.Parameters);
 
68
                        }
 
69
                        return v.Text;
 
70
                }
 
71
                
 
72
                protected override bool CompareMethodNames(string strA, string strB)
 
73
                {
 
74
                        return String.Equals(strA, strB, StringComparison.OrdinalIgnoreCase);
 
75
                }
 
76
        }
 
77
}