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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeCompletion/DeclarationViewWindow.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
 
// DeclarationViewWindow.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
 
 
32
 
namespace MonoDevelop.Ide.CodeCompletion
33
 
{
34
 
        internal class DeclarationViewWindow : TooltipWindow
35
 
        {
36
 
                static char[] newline = {'\n'};
37
 
                
38
 
                List<string> overloads = new List<string> ();
39
 
                int current_overload;
40
 
                
41
 
                public int CurrentOverload {
42
 
                        get {
43
 
                                return this.current_overload; 
44
 
                        }
45
 
                        set {
46
 
                                this.current_overload = value;
47
 
                                ShowOverload ();
48
 
                        }
49
 
                }
50
 
                
51
 
                MonoDevelop.Components.FixedWidthWrapLabel headlabel, bodylabel;
52
 
                Label helplabel;
53
 
                Arrow left, right;
54
 
                VBox helpbox;
55
 
                
56
 
                public string DescriptionMarkup {
57
 
                        get {
58
 
                                if (string.IsNullOrEmpty (bodylabel.Text))
59
 
                                        return headlabel.Text;
60
 
                                return headlabel.Text + "\n" + bodylabel.Text;
61
 
                        }
62
 
                        set {
63
 
                                if (string.IsNullOrEmpty (value)) {
64
 
                                        headlabel.Markup = bodylabel.Markup = "";
65
 
                                        headlabel.Visible = bodylabel.Visible = false;
66
 
                                        return;
67
 
                                }
68
 
                                string[] parts = value.Split (newline, 2);
69
 
                                headlabel.Markup = "<b>" + parts[0].Trim () + "</b>";
70
 
                                bodylabel.Markup = parts.Length == 2 && !string.IsNullOrEmpty (parts[1].Trim ())? "<span size=\"smaller\">" + parts[1].Trim () + "</span>" : "";
71
 
                                headlabel.Visible = !string.IsNullOrEmpty (parts[0].Trim ());
72
 
                                bodylabel.Visible = parts.Length == 2 ;
73
 
                        }
74
 
                }
75
 
 
76
 
                public bool Multiple{
77
 
                        get {
78
 
                                return left.Visible;
79
 
                        }
80
 
                        set {
81
 
                                left.Visible = right.Visible = helpbox.Visible = value;
82
 
                                
83
 
                                //this could go somewhere better, as long as it's after realization
84
 
                                headlabel.Visible = !string.IsNullOrEmpty (headlabel.Text);
85
 
                                bodylabel.Visible = !string.IsNullOrEmpty (bodylabel.Text);
86
 
                        }
87
 
                }
88
 
 
89
 
                public void AddOverload (string desc)
90
 
                {
91
 
                        overloads.Add (desc);
92
 
                        if (overloads.Count == 2)
93
 
                                Multiple = overloads.Count > 1;
94
 
                        ShowOverload ();
95
 
                }
96
 
 
97
 
                void ShowOverload ()
98
 
                {
99
 
                        if (current_overload >= 0 && current_overload < overloads.Count) {
100
 
                                DescriptionMarkup = overloads[current_overload];
101
 
                                helplabel.Markup = string.Format ("<small>" + GettextCatalog.GetString ("{0} of {1} overloads") + "</small>", current_overload + 1, overloads.Count);
102
 
                        }
103
 
                }
104
 
 
105
 
                public void OverloadLeft ()
106
 
                {
107
 
                        if (current_overload == 0) {
108
 
                                if (overloads.Count > 0)
109
 
                                        current_overload = overloads.Count - 1;
110
 
                        } else {
111
 
                                current_overload--;
112
 
                        }
113
 
                        ShowOverload ();
114
 
                }
115
 
 
116
 
                public void OverloadRight ()
117
 
                {
118
 
                        if (current_overload == overloads.Count - 1) {
119
 
                                current_overload = 0;
120
 
                        } else {
121
 
                                if (overloads.Count > 0)
122
 
                                        current_overload++;
123
 
                        }
124
 
                        ShowOverload ();
125
 
                }
126
 
 
127
 
                public void Clear ()
128
 
                {
129
 
                        overloads.Clear ();
130
 
                        Multiple = false;
131
 
                        DescriptionMarkup = String.Empty;
132
 
                        current_overload = 0;
133
 
                }
134
 
                
135
 
                public void SetFixedWidth (int w)
136
 
                {
137
 
                        if (w != -1) {
138
 
                                w -= SizeRequest ().Width - headlabel.SizeRequest ().Width;
139
 
                                headlabel.MaxWidth = w > 0 ? w : 1;
140
 
                        } else {
141
 
                                headlabel.MaxWidth = -1;
142
 
                        }
143
 
                        bodylabel.MaxWidth = headlabel.RealWidth > 350 ? headlabel.RealWidth : 350;
144
 
                        QueueResize ();
145
 
                }
146
 
 
147
 
                public DeclarationViewWindow () : base ()
148
 
                {
149
 
                        this.AllowShrink = false;
150
 
                        this.AllowGrow = false;
151
 
                        
152
 
                        EnableTransparencyControl = true;
153
 
                        
154
 
                        headlabel = new MonoDevelop.Components.FixedWidthWrapLabel ();
155
 
                        headlabel.Indent = -20;
156
 
                        headlabel.Wrap = Pango.WrapMode.WordChar;
157
 
                        headlabel.BreakOnCamelCasing = true;
158
 
                        headlabel.BreakOnPunctuation = true;
159
 
                        
160
 
                        bodylabel = new MonoDevelop.Components.FixedWidthWrapLabel ();
161
 
                        bodylabel.Wrap = Pango.WrapMode.WordChar;
162
 
                        bodylabel.BreakOnCamelCasing = true;
163
 
                        bodylabel.BreakOnPunctuation = true;
164
 
                        
165
 
                        VBox vb = new VBox (false, 0);
166
 
                        vb.PackStart (headlabel, true, true, 0);
167
 
                        vb.PackStart (bodylabel, true, true, 3);
168
 
 
169
 
                        left = new Arrow (ArrowType.Left, ShadowType.None);
170
 
                        right = new Arrow (ArrowType.Right, ShadowType.None);
171
 
 
172
 
                        HBox hb = new HBox (false, 0);
173
 
                        hb.Spacing = 4;
174
 
                        hb.PackStart (left, false, true, 0);
175
 
                        hb.PackStart (vb, true, true, 0);
176
 
                        hb.PackStart (right, false, true, 0);
177
 
 
178
 
                        helplabel = new Label (string.Empty);
179
 
                        helplabel.Xalign = 1;
180
 
                        
181
 
                        helpbox = new VBox (false, 0);
182
 
                        helpbox.PackStart (new HSeparator (), false, true, 0);
183
 
                        helpbox.PackStart (helplabel, false, true, 0);
184
 
                        helpbox.BorderWidth = 2;
185
 
                        
186
 
                        VBox vb2 = new VBox (false, 0);
187
 
                        vb2.Spacing = 4;
188
 
                        vb2.PackStart (hb, true, true, 0);
189
 
                        vb2.PackStart (helpbox, false, true, 0);
190
 
                        
191
 
                        this.Add (vb2);
192
 
                        
193
 
                        ShowAll ();
194
 
                }
195
 
        }
196
 
}