~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/EventCreationCompletionData.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
                IMember callingMember;
47
47
                TextEditorData editor;
48
48
                int initialOffset;
 
49
                public bool AddSemicolon = true;
49
50
                
50
51
                public EventCreationCompletionData (TextEditorData editor, string varName, IType delegateType, IEvent evt, string parameterList, IMember callingMember, IType declaringType) : base (null)
51
52
                {
52
53
                        if (string.IsNullOrEmpty (varName)) {
53
 
                                this.DisplayText   = "Handle" + evt.Name;
 
54
                                this.DisplayText   = "Handle" + (evt != null ? evt.Name : "");
54
55
                        } else {
55
 
                                this.DisplayText   = "Handle" + Char.ToUpper (varName[0]) + varName.Substring (1) + evt.Name;
 
56
                                this.DisplayText   = "Handle" + Char.ToUpper (varName[0]) + varName.Substring (1) + (evt != null ? evt.Name : "");
56
57
                        }
57
58
                        
58
 
                        if (declaringType.SearchMember (this.DisplayText, true).Count > 0) {
 
59
                        if (declaringType != null && declaringType.SearchMember (this.DisplayText, true).Count > 0) {
59
60
                                for (int i = 1; i < 10000; i++) {
60
61
                                        if (declaringType.SearchMember (this.DisplayText + i.ToString (), true).Count == 0) {
61
62
                                                this.DisplayText = this.DisplayText + i.ToString ();
73
74
                public override void InsertCompletionText (CompletionListWindow window)
74
75
                {
75
76
                        // insert add/remove event handler code after +=/-=
76
 
                        editor.Replace (initialOffset, editor.Caret.Offset - initialOffset, this.DisplayText + ";");
 
77
                        editor.Replace (initialOffset, editor.Caret.Offset - initialOffset, this.DisplayText + (AddSemicolon ? ";" : ""));
77
78
                        
78
79
                        // Search opening bracket of member
79
 
                        int pos = callingMember != null ? editor.Document.LocationToOffset (callingMember.BodyRegion.Start.Line - 1, callingMember.BodyRegion.Start.Column - 1) : initialOffset;
 
80
                        int pos = callingMember != null ? editor.Document.LocationToOffset (callingMember.BodyRegion.Start.Line, callingMember.BodyRegion.Start.Column) : initialOffset;
80
81
                        while (pos < editor.Document.Length && editor.Document.GetCharAt (pos) != '{') {
81
82
                                pos++;
82
83
                        }
90
91
                        string indent = editor.Document.GetLine (callingMember.Location.Line).GetIndentation (editor.Document);
91
92
                        
92
93
                        StringBuilder sb = new StringBuilder ();
93
 
                        sb.AppendLine ();
94
 
                        sb.AppendLine ();
 
94
                        sb.Append (editor.EolMarker);
 
95
                        sb.Append (editor.EolMarker);
95
96
                        sb.Append (indent);
96
97
                        if (callingMember.IsStatic)
97
98
                                sb.Append ("static ");
98
99
                        sb.Append ("void ");
99
100
                        int pos2 = sb.Length;
100
 
                        sb.Append (this.DisplayText);sb.Append (' ');sb.Append (this.parameterList);sb.AppendLine ();
101
 
                        sb.Append (indent);sb.Append ("{");sb.AppendLine ();
 
101
                        sb.Append (this.DisplayText);sb.Append (' ');sb.Append (this.parameterList);sb.Append (editor.EolMarker);
 
102
                        sb.Append (indent);sb.Append ("{");sb.Append (editor.EolMarker);
102
103
                        sb.Append (indent);sb.Append (TextEditorProperties.IndentString);
103
104
                        int cursorPos = pos + sb.Length;
104
 
                        sb.AppendLine ();
 
105
                        sb.Append (editor.EolMarker);
105
106
                        sb.Append (indent);sb.Append ("}");
106
107
                        editor.Insert (pos, sb.ToString ());
107
108
                        editor.Caret.Offset = cursorPos;
111
112
                        TextLink link = new TextLink ("name");
112
113
                        
113
114
                        link.AddLink (new Segment (0, this.DisplayText.Length));
114
 
                        link.AddLink (new Segment (pos + pos2 - initialOffset, this.DisplayText.Length));
 
115
                        link.AddLink (new Segment (pos - initialOffset + pos2, this.DisplayText.Length));
115
116
                        links.Add (link);
116
117
                        
117
118
                        CompletionTextLinkMode tle = new CompletionTextLinkMode (editor.Parent, initialOffset, links);