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

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/LanguageItemWindow.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-07-05 13:00:05 UTC
  • mfrom: (1.2.8 upstream) (1.3.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100705130005-d6hp4k5gcn1xkj8c
Tags: 2.4+dfsg-1ubuntu1
* debian/patches/remove_support_for_moonlight.patch,
  debian/patches/dont_add_moonlight_to_core_addins.patch,
  debian/control:
  + Enable support for Moonlight
* debian/rules:
  + Ensure Moonlight addin isn't shipped in main MonoDevelop package by
    mistake

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
{
41
41
        public class LanguageItemWindow: MonoDevelop.Components.TooltipWindow
42
42
        {
43
 
                OutputSettings settings;
44
 
                
45
 
                static string paramStr = GettextCatalog.GetString ("Parameter");
46
 
                static string localStr = GettextCatalog.GetString ("Local variable");
47
 
                static string fieldStr = GettextCatalog.GetString ("Field");
48
 
                static string propertyStr = GettextCatalog.GetString ("Property");
49
 
                static string methodStr = GettextCatalog.GetString ("Method");
50
 
                static string typeStr = GettextCatalog.GetString ("Type");
51
 
                static string namespaceStr = GettextCatalog.GetString ("Namespace");
52
 
                
53
 
                public bool IsEmpty {
54
 
                        get; 
55
 
                        set;
56
 
                }
57
 
                
58
 
                public LanguageItemWindow (ProjectDom dom, Gdk.ModifierType modifierState, Ambience ambience, ResolveResult result, string errorInformations, ICompilationUnit unit)
 
43
                Pango.FontDescription fontDescription;
 
44
                
 
45
                public bool IsEmpty { get; set; }
 
46
                
 
47
                public LanguageItemWindow (ExtensibleTextEditor ed, Gdk.ModifierType modifierState, ResolveResult result, string errorInformations, ICompilationUnit unit)
59
48
                {
60
 
                        settings = new OutputSettings (OutputFlags.ClassBrowserEntries | OutputFlags.IncludeParameterName | OutputFlags.IncludeKeywords | OutputFlags.IncludeMarkup | OutputFlags.UseFullName);
61
 
                        if ((Gdk.ModifierType.ShiftMask & modifierState) == Gdk.ModifierType.ShiftMask) {
62
 
                                settings.EmitNameCallback = delegate(INode domVisitable, ref string outString) {
63
 
                                        // crop used namespaces.
64
 
                                        if (unit != null) {
65
 
 
66
 
                                                int len = 0;
67
 
                                                foreach (IUsing u in unit.Usings) {
68
 
                                                        foreach (string ns in u.Namespaces) {
69
 
                                                                if (outString.StartsWith (ns + ".")) {
70
 
                                                                        len = Math.Max (len, ns.Length + 1);
71
 
                                                                }
72
 
                                                        }
73
 
                                                }
74
 
                                                string newName = outString.Substring (len);
75
 
                                                int count = 0;
76
 
                                                // check if there is a name clash.
77
 
                                                if (dom.GetType (newName) != null)
78
 
                                                        count++;
79
 
                                                foreach (IUsing u in unit.Usings) {
80
 
                                                        foreach (string ns in u.Namespaces) {
81
 
                                                                if (dom.GetType (ns + "." + newName) != null)
82
 
                                                                        count++;
83
 
                                                        }
84
 
                                                }
85
 
 
86
 
                                                if (len > 0 && count == 1)
87
 
                                                        outString = newName;
88
 
                                        }
89
 
                                };
90
 
                        }
91
 
 
92
 
                        // Approximate value for usual case
93
 
                        StringBuilder s = new StringBuilder (150);
94
 
                        string doc = null;
95
 
                        if (result != null) {
96
 
                                if (result is AggregatedResolveResult)
97
 
                                        result = ((AggregatedResolveResult)result).PrimaryResult;
98
 
                                if (result is ParameterResolveResult) {
99
 
                                        s.Append ("<small><i>");
100
 
                                        s.Append (paramStr);
101
 
                                        s.Append ("</i></small>\n");
102
 
                                        s.Append (ambience.GetString (((ParameterResolveResult)result).Parameter, settings));
103
 
                                } else if (result is LocalVariableResolveResult) {
104
 
                                        s.Append ("<small><i>");
105
 
                                        s.Append (localStr);
106
 
                                        s.Append ("</i></small>\n");
107
 
                                        s.Append (ambience.GetString (((LocalVariableResolveResult)result).ResolvedType, settings));
108
 
                                        s.Append (" ");
109
 
                                        s.Append (((LocalVariableResolveResult)result).LocalVariable.Name);
110
 
                                } else if (result is MemberResolveResult) {
111
 
                                        IMember member = ((MemberResolveResult)result).ResolvedMember;
112
 
                                        if (member == null) {
113
 
                                                IReturnType returnType = ((MemberResolveResult)result).ResolvedType;
114
 
                                                if (returnType != null) {
115
 
                                                        IType type = dom.GetType (returnType);
116
 
                                                        if (type != null) {
117
 
                                                                s.Append ("<small><i>");
118
 
                                                                s.Append (typeStr);
119
 
                                                                s.Append ("</i></small>\n");
120
 
                                                                s.Append (ambience.GetString (type, settings));
121
 
                                                                doc = AmbienceService.GetDocumentationSummary (type);
122
 
                                                        }
123
 
                                                }
124
 
                                        } else {
125
 
                                                if (member is IField) {
126
 
                                                        s.Append ("<small><i>");
127
 
                                                        s.Append (fieldStr);
128
 
                                                        s.Append ("</i></small>\n");
129
 
                                                } else if (member is IProperty) {
130
 
                                                        s.Append ("<small><i>");
131
 
                                                        s.Append (propertyStr);
132
 
                                                        s.Append ("</i></small>\n");
133
 
                                                }
134
 
                                                s.Append (ambience.GetString (member, settings));
135
 
                                                doc = AmbienceService.GetDocumentationSummary (member);
136
 
                                        }
137
 
                                } else if (result is NamespaceResolveResult) {
138
 
                                        s.Append ("<small><i>");
139
 
                                        s.Append (namespaceStr);
140
 
                                        s.Append ("</i></small>\n");
141
 
                                        s.Append (ambience.GetString (new Namespace (((NamespaceResolveResult)result).Namespace), settings));
142
 
                                } else if (result is MethodResolveResult) {
143
 
                                        MethodResolveResult mrr = (MethodResolveResult)result;
144
 
                                        s.Append ("<small><i>");
145
 
                                        s.Append (methodStr);
146
 
                                        s.Append ("</i></small>\n");
147
 
                                        s.Append (ambience.GetString (mrr.MostLikelyMethod, settings));
148
 
                                        if (mrr.Methods.Count > 1) {
149
 
                                                int overloadCount = mrr.Methods.Count - 1;
150
 
                                                s.Append (string.Format (GettextCatalog.GetPluralString (" (+{0} overload)", " (+{0} overloads)", overloadCount), overloadCount));
151
 
                                        }
152
 
 
153
 
                                        doc = AmbienceService.GetDocumentationSummary (((MethodResolveResult)result).MostLikelyMethod);
154
 
                                } else {
155
 
                                        s.Append (ambience.GetString (result.ResolvedType, settings));
156
 
                                }
157
 
 
158
 
 
159
 
                                if (!string.IsNullOrEmpty (doc)) {
160
 
                                        s.Append ("\n<small>");
161
 
                                        s.Append (AmbienceService.GetDocumentationMarkup ( "<summary>" + doc +  "</summary>"));
162
 
                                        s.Append ("</small>");
163
 
                                }
164
 
                        }
165
 
                        
166
 
                        if (!string.IsNullOrEmpty (errorInformations)) {
167
 
                                if (s.Length != 0)
168
 
                                        s.Append ("\n\n");
169
 
                                s.Append ("<small>");
170
 
                                s.Append (errorInformations);
171
 
                                s.Append ("</small>");
172
 
                        }
173
 
                        
174
 
                        if (s.ToString ().Trim ().Length == 0) {
 
49
                        ProjectDom dom = ed.ProjectDom;
 
50
                        Ambience ambience = AmbienceService.GetAmbience (ed.Document.MimeType);
 
51
                        
 
52
                        string tooltip = null;
 
53
                        if (result != null && ed.TextEditorResolverProvider != null) {
 
54
                                tooltip = ed.TextEditorResolverProvider.CreateTooltip (dom, unit, result, errorInformations, ambience, modifierState);
 
55
                                if (result.ResolveErrors.Count > 0) {
 
56
                                        StringBuilder sb = new StringBuilder ();
 
57
                                        sb.Append (tooltip);
 
58
                                        sb.AppendLine ();
 
59
                                        sb.AppendLine ();
 
60
                                        sb.AppendLine (GettextCatalog.GetPluralString ("Error:", "Errors:", result.ResolveErrors.Count));
 
61
                                        for (int i = 0; i < result.ResolveErrors.Count; i++) {
 
62
                                                sb.Append ('\t');
 
63
                                                sb.Append (result.ResolveErrors[i]);
 
64
                                                if (i + 1 < result.ResolveErrors.Count) 
 
65
                                                        sb.AppendLine ();
 
66
                                        }
 
67
                                        tooltip = sb.ToString ();
 
68
                                }
 
69
                        } else {
 
70
                                tooltip = errorInformations;
 
71
                        }
 
72
                        if (string.IsNullOrEmpty (tooltip)) {
175
73
                                IsEmpty = true;
176
74
                                return;
177
75
                        }
178
 
                        
179
 
                        MonoDevelop.Components.FixedWidthWrapLabel lab = new MonoDevelop.Components.FixedWidthWrapLabel ();
180
 
                        lab.Wrap = Pango.WrapMode.WordChar;
181
 
                        lab.Indent = -20;
182
 
                        lab.BreakOnCamelCasing = true;
183
 
                        lab.BreakOnPunctuation = true;
184
 
                        lab.Markup = s.ToString ();
 
76
 
 
77
                        var label = new MonoDevelop.Components.FixedWidthWrapLabel () {
 
78
                                Wrap = Pango.WrapMode.WordChar,
 
79
                                Indent = -20,
 
80
                                BreakOnCamelCasing = true,
 
81
                                BreakOnPunctuation = true,
 
82
                                Markup = tooltip,
 
83
                        };
185
84
                        this.BorderWidth = 3;
186
 
                        Add (lab);
 
85
                        Add (label);
 
86
                        UpdateFont (label);
187
87
                        
188
88
                        EnableTransparencyControl = true;
189
89
                }
191
91
                //return the real width
192
92
                public int SetMaxWidth (int maxWidth)
193
93
                {
194
 
                        MonoDevelop.Components.FixedWidthWrapLabel l = (MonoDevelop.Components.FixedWidthWrapLabel)Child;
195
 
                        l.MaxWidth = maxWidth;
196
 
                        return l.RealWidth;
 
94
                        var label = Child as MonoDevelop.Components.FixedWidthWrapLabel;
 
95
                        if (label == null)
 
96
                                return Allocation.Width;
 
97
                        label.MaxWidth = maxWidth;
 
98
                        return label.RealWidth;
 
99
                }
 
100
                
 
101
                protected override void OnStyleSet (Style previous_style)
 
102
                {
 
103
                        base.OnStyleSet (previous_style);
 
104
                        UpdateFont (Child as MonoDevelop.Components.FixedWidthWrapLabel);
 
105
                }
 
106
                
 
107
                void UpdateFont (MonoDevelop.Components.FixedWidthWrapLabel label)
 
108
                {
 
109
                        if (label == null)
 
110
                                return;
 
111
                        if (fontDescription != null) {
 
112
                                fontDescription.Dispose ();
 
113
                        }
 
114
                        fontDescription = new Gtk.Label ("").Style.FontDescription.Copy ();
 
115
                        fontDescription.Size = DefaultSourceEditorOptions.Instance.Font.Size;
 
116
                        label.FontDescription = fontDescription;
 
117
                }
 
118
                
 
119
                protected override void OnDestroyed ()
 
120
                {
 
121
                        base.OnDestroyed ();
 
122
                        
 
123
                        if (fontDescription != null) {
 
124
                                fontDescription.Dispose ();
 
125
                                fontDescription = null;
 
126
                        }
197
127
                }
198
128
                
199
129