~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeCompletion/TooltipInformationWindow.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// TooltipInformationWindow.cs
 
2
//
 
3
// Author:
 
4
//   Mike KrĆ¼ger <mkrueger@novell.com>
 
5
//
 
6
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
 
7
//
 
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
9
// of this software and associated documentation files (the "Software"), to deal
 
10
// in the Software without restriction, including without limitation the rights
 
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
12
// copies of the Software, and to permit persons to whom the Software is
 
13
// furnished to do so, subject to the following conditions:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
24
// THE SOFTWARE.
 
25
 
 
26
using System;
 
27
using Gtk;
 
28
using MonoDevelop.Components;
 
29
using System.Collections.Generic;
 
30
using MonoDevelop.Core;
 
31
using MonoDevelop.Ide.Fonts;
 
32
using System.Linq;
 
33
using Mono.TextEditor.PopupWindow;
 
34
 
 
35
namespace MonoDevelop.Ide.CodeCompletion
 
36
{
 
37
 
 
38
        public class TooltipInformationWindow : PopoverWindow
 
39
        {
 
40
                List<TooltipInformation> overloads = new List<TooltipInformation> ();
 
41
                int current_overload;
 
42
                
 
43
                public int CurrentOverload {
 
44
                        get {
 
45
                                return this.current_overload; 
 
46
                        }
 
47
                        set {
 
48
                                this.current_overload = value;
 
49
                                ShowOverload ();
 
50
                        }
 
51
                }
 
52
 
 
53
                public int Overloads {
 
54
                        get {
 
55
                                return overloads.Count;
 
56
                        }
 
57
                }
 
58
                
 
59
                MonoDevelop.Components.FixedWidthWrapLabel headlabel;
 
60
                public bool Multiple{
 
61
                        get {
 
62
                                return overloads.Count > 1;
 
63
                        }
 
64
                }
 
65
 
 
66
                public void AddOverload (TooltipInformation tooltipInformation)
 
67
                {
 
68
                        if (tooltipInformation == null || string.IsNullOrEmpty (tooltipInformation.SignatureMarkup))
 
69
                                return;
 
70
                        overloads.Add (tooltipInformation);
 
71
 
 
72
                        if (overloads.Count > 1) {
 
73
                                Theme.DrawPager = true;
 
74
                                Theme.NumPages = overloads.Count;
 
75
                        }
 
76
 
 
77
                        ShowOverload ();
 
78
                }
 
79
 
 
80
                public void AddOverload (CompletionData data)
 
81
                {
 
82
                        var tooltipInformation = data.CreateTooltipInformation (false);
 
83
                        if (string.IsNullOrEmpty (tooltipInformation.SignatureMarkup))
 
84
                                return;
 
85
 
 
86
                        using (var layout = new Pango.Layout (PangoContext)) {
 
87
                                var des = FontService.GetFontDescription ("Editor");
 
88
                                layout.FontDescription = des;
 
89
                                layout.SetMarkup (tooltipInformation.SignatureMarkup);
 
90
                                int w, h;
 
91
                                layout.GetPixelSize (out w, out h);
 
92
                                if (w >= Allocation.Width - 10) {
 
93
                                        tooltipInformation = data.CreateTooltipInformation (true);
 
94
                                }
 
95
                        }
 
96
                        AddOverload (tooltipInformation);
 
97
                }
 
98
 
 
99
                protected override void OnSizeRequested (ref Requisition requisition)
 
100
                {
 
101
                        base.OnSizeRequested (ref requisition);
 
102
                        var w = Math.Max (headlabel.WidthRequest, headlabel.RealWidth);
 
103
                        requisition.Width = (int)Math.Max (w + ContentBox.LeftPadding + ContentBox.RightPadding, requisition.Width);
 
104
                }
 
105
 
 
106
                void ShowOverload ()
 
107
                {
 
108
                        ClearDescriptions ();
 
109
 
 
110
                        if (current_overload >= 0 && current_overload < overloads.Count) {
 
111
                                var o = overloads[current_overload];
 
112
                                headlabel.Markup = o.SignatureMarkup;
 
113
                                headlabel.Visible = true;
 
114
                                if (Theme.DrawPager && overloads.Count > 1) {
 
115
                                        headlabel.WidthRequest = headlabel.RealWidth + 70;
 
116
                                } else {
 
117
                                        headlabel.WidthRequest = -1;
 
118
                                }
 
119
                                foreach (var cat in o.Categories) {
 
120
                                        descriptionBox.PackStart (CreateCategory (cat.Item1, cat.Item2), true, true, 4);
 
121
                                }
 
122
 
 
123
                                if (!string.IsNullOrEmpty (o.SummaryMarkup)) {
 
124
                                        descriptionBox.PackStart (CreateCategory (GettextCatalog.GetString ("Summary"), o.SummaryMarkup), true, true, 4);
 
125
                                }
 
126
                                if (!string.IsNullOrEmpty (o.FooterMarkup)) {
 
127
 
 
128
                                        var contentLabel = new MonoDevelop.Components.FixedWidthWrapLabel ();
 
129
                                        contentLabel.Wrap = Pango.WrapMode.WordChar;
 
130
                                        contentLabel.BreakOnCamelCasing = true;
 
131
                                        contentLabel.MaxWidth = 400;
 
132
                                        contentLabel.BreakOnPunctuation = true;
 
133
                                        contentLabel.Markup = o.FooterMarkup.Trim ();
 
134
                                        contentLabel.ModifyFg (StateType.Normal, (HslColor)foreColor);
 
135
 
 
136
                                        descriptionBox.PackEnd (contentLabel, true, true, 4);
 
137
                                }
 
138
 
 
139
                                if (string.IsNullOrEmpty (o.SummaryMarkup) && string.IsNullOrEmpty (o.FooterMarkup) && !o.Categories.Any ()) {
 
140
                                        descriptionBox.Hide ();
 
141
                                } else {
 
142
                                        descriptionBox.ShowAll ();
 
143
                                }
 
144
                                Theme.CurrentPage = current_overload;
 
145
                                QueueResize ();
 
146
                        }
 
147
                }
 
148
 
 
149
                public void OverloadLeft ()
 
150
                {
 
151
                        if (current_overload == 0) {
 
152
                                if (overloads.Count > 0)
 
153
                                        current_overload = overloads.Count - 1;
 
154
                        } else {
 
155
                                current_overload--;
 
156
                        }
 
157
                        ShowOverload ();
 
158
                }
 
159
 
 
160
                public void OverloadRight ()
 
161
                {
 
162
                        if (current_overload == overloads.Count - 1) {
 
163
                                current_overload = 0;
 
164
                        } else {
 
165
                                if (overloads.Count > 0)
 
166
                                        current_overload++;
 
167
                        }
 
168
                        ShowOverload ();
 
169
                }
 
170
 
 
171
                void ClearDescriptions ()
 
172
                {
 
173
                        while (descriptionBox.Children.Length > 0) {
 
174
                                var child = descriptionBox.Children [0];
 
175
                                descriptionBox.Remove (child);
 
176
                                child.Destroy ();
 
177
                        }
 
178
                }
 
179
 
 
180
                public void Clear ()
 
181
                {
 
182
                        ClearDescriptions ();
 
183
                        overloads.Clear ();
 
184
                        Theme.DrawPager = false;
 
185
                        headlabel.Markup = "";
 
186
                        current_overload = 0;
 
187
                }
 
188
                
 
189
                public void SetFixedWidth (int w)
 
190
                {
 
191
                        if (w != -1) {
 
192
                                headlabel.MaxWidth = w;
 
193
                        } else {
 
194
                                headlabel.MaxWidth = -1;
 
195
                        }
 
196
                        QueueResize ();
 
197
                }
 
198
 
 
199
                VBox CreateCategory (string categoryName, string categoryContentMarkup)
 
200
                {
 
201
                        var vbox = new VBox ();
 
202
 
 
203
                        vbox.Spacing = 2;
 
204
 
 
205
                        var catLabel = new MonoDevelop.Components.FixedWidthWrapLabel ();
 
206
                        catLabel.Text = categoryName;
 
207
                        catLabel.ModifyFg (StateType.Normal, (HslColor)foreColor);
 
208
 
 
209
                        vbox.PackStart (catLabel, false, true, 0);
 
210
 
 
211
                        var contentLabel = new MonoDevelop.Components.FixedWidthWrapLabel ();
 
212
                        contentLabel.Wrap = Pango.WrapMode.WordChar;
 
213
                        contentLabel.BreakOnCamelCasing = true;
 
214
                        contentLabel.MaxWidth = 400;
 
215
                        contentLabel.BreakOnPunctuation = true;
 
216
                        contentLabel.Markup = categoryContentMarkup.Trim ();
 
217
                        contentLabel.ModifyFg (StateType.Normal, (HslColor)foreColor);
 
218
 
 
219
                        vbox.PackStart (contentLabel, true, true, 0);
 
220
 
 
221
                        return vbox;
 
222
                }
 
223
 
 
224
                VBox descriptionBox = new VBox (false, 0);
 
225
                VBox vb2 = new VBox (false, 0);
 
226
                Cairo.Color foreColor;
 
227
                public TooltipInformationWindow () : base ()
 
228
                {
 
229
                        TypeHint = Gdk.WindowTypeHint.Tooltip;
 
230
                        this.SkipTaskbarHint = true;
 
231
                        this.SkipPagerHint = true;
 
232
                        if (IdeApp.Workbench != null)
 
233
                                this.TransientFor = IdeApp.Workbench.RootWindow;
 
234
                        this.AllowShrink = false;
 
235
                        this.AllowGrow = false;
 
236
                        this.CanFocus = false;
 
237
                        this.CanDefault = false;
 
238
                        this.Events |= Gdk.EventMask.EnterNotifyMask; 
 
239
                        
 
240
                        headlabel = new MonoDevelop.Components.FixedWidthWrapLabel ();
 
241
                        headlabel.Indent = -20;
 
242
                        var des = FontService.GetFontDescription ("Editor").Copy ();
 
243
                        des.Size = des.Size * 9 / 10;
 
244
                        headlabel.FontDescription = des;
 
245
//                      headlabel.MaxWidth = 400;
 
246
                        headlabel.Wrap = Pango.WrapMode.WordChar;
 
247
                        headlabel.BreakOnCamelCasing = true;
 
248
//                      headlabel.BreakOnPunctuation = true;
 
249
                        descriptionBox.Spacing = 4;
 
250
                        VBox vb = new VBox (false, 8);
 
251
                        vb.PackStart (headlabel, true, true, 0);
 
252
                        vb.PackStart (descriptionBox, true, true, 0);
 
253
 
 
254
                        HBox hb = new HBox (false, 0);
 
255
                        hb.PackStart (vb, true, true, 0);
 
256
                        WindowTransparencyDecorator.Attach (this);
 
257
 
 
258
                        vb2.Spacing = 4;
 
259
                        vb2.PackStart (hb, true, true, 0);
 
260
                        ContentBox.Add (vb2);
 
261
                        var scheme = Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle (IdeApp.Preferences.ColorScheme);
 
262
                        Theme.SetSchemeColors (scheme);
 
263
                        foreColor = scheme.PlainText.Foreground;
 
264
                        headlabel.ModifyFg (StateType.Normal, (HslColor)foreColor);
 
265
                        ShowAll ();
 
266
                        DesktopService.RemoveWindowShadow (this);
 
267
                }
 
268
        }
 
269
}