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

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/LanguageItemTooltipProvider.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
 
// LanguageItemTooltipProvider.cs
2
 
//
3
 
// Author:
4
 
//   Lluis Sanchez Gual <lluis@novell.com>
5
 
//
6
 
// Copyright (c) 2008 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
 
//
27
 
 
28
 
using System;
29
 
using Mono.TextEditor;
30
 
using MonoDevelop.Ide.TypeSystem;
31
 
using ICSharpCode.NRefactory.Semantics;
32
 
 
33
 
namespace MonoDevelop.SourceEditor
34
 
{
35
 
        public class LanguageItemTooltipProvider: ITooltipProvider
36
 
        {
37
 
                public LanguageItemTooltipProvider()
38
 
                {
39
 
                }
40
 
 
41
 
                #region ITooltipProvider implementation 
42
 
                
43
 
                public TooltipItem GetItem (Mono.TextEditor.TextEditor editor, int offset)
44
 
                {
45
 
                        ExtensibleTextEditor ed = (ExtensibleTextEditor)editor;
46
 
                        ICSharpCode.NRefactory.TypeSystem.DomRegion region;
47
 
                        var resolveResult = ed.GetLanguageItem (offset, out region);
48
 
                        if (resolveResult == null)
49
 
                                return null;
50
 
                        int startOffset = offset;
51
 
                        int endOffset = offset;
52
 
                        return new TooltipItem (resolveResult, startOffset, endOffset - startOffset);
53
 
                }
54
 
                
55
 
                ResolveResult lastResult = null;
56
 
                LanguageItemWindow lastWindow = null;
57
 
                
58
 
                public Gtk.Window CreateTooltipWindow (Mono.TextEditor.TextEditor editor, int offset, Gdk.ModifierType modifierState, TooltipItem item)
59
 
                {
60
 
                        var ed = (ExtensibleTextEditor)editor;
61
 
                        var doc = ed.ParsedDocument;
62
 
                        if (doc == null)
63
 
                                return null;
64
 
                        
65
 
                        var resolveResult = (ResolveResult)item.Item;
66
 
                        if (lastResult != null && lastWindow.IsRealized && 
67
 
                            resolveResult != null && lastResult.Type.Equals (resolveResult.Type))
68
 
                                return lastWindow;
69
 
                        var result = new LanguageItemWindow (ed, modifierState, resolveResult, null, doc.ParsedFile);
70
 
                        lastWindow = result;
71
 
                        lastResult = resolveResult;
72
 
                        if (result.IsEmpty)
73
 
                                return null;
74
 
                        return result;
75
 
                }
76
 
                
77
 
                public void GetRequiredPosition (Mono.TextEditor.TextEditor editor, Gtk.Window tipWindow, out int requiredWidth, out double xalign)
78
 
                {
79
 
                        LanguageItemWindow win = (LanguageItemWindow) tipWindow;
80
 
                        requiredWidth = win.SetMaxWidth (win.Screen.Width);
81
 
                        xalign = 0.5;
82
 
                }
83
 
                
84
 
                public bool IsInteractive (Mono.TextEditor.TextEditor editor, Gtk.Window tipWindow)
85
 
                {
86
 
                        return false;
87
 
                }
88
 
                
89
 
                #endregion 
90
 
                
91
 
        }
92
 
}