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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.WelcomePage/WelcomePageLinkButton.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:
31
31
 
32
32
namespace MonoDevelop.Ide.WelcomePage
33
33
{
34
 
        class WelcomePageLinkButton : Gtk.Button
 
34
        public class WelcomePageLinkButton : Gtk.Button
35
35
        {
36
 
                static readonly string linkUnderlinedFormat = "<span underline=\"single\" foreground=\"" + WelcomePageBranding.LinkColor + "\">{0}</span>";
37
 
                static readonly string linkFormat = "<span foreground=\"" + WelcomePageBranding.LinkColor + "\">{0}</span>";
38
 
                static readonly string descFormat = "<span size=\"small\" foreground=\"" + WelcomePageBranding.TextColor + "\">{0}</span>";
 
36
                static readonly string linkUnderlinedFormat = "<span underline=\"single\" foreground=\"" + Styles.WelcomeScreen.Links.Color + "\">{0}</span>";
 
37
                static readonly string linkFormat = "<span foreground=\"" + Styles.WelcomeScreen.Links.Color + "\">{0}</span>";
 
38
                static readonly string descFormat = "<span size=\"small\" foreground=\"" + Styles.WelcomeScreen.Pad.TextColor + "\">{0}</span>";
39
39
                
40
40
                Label label;
41
41
                Image image;
43
43
                Gtk.IconSize iconSize = IconSize.Menu;
44
44
                HBox box;
45
45
                
46
 
                public WelcomePageLinkButton (XElement el)
47
 
                        : this (el, Gtk.IconSize.Menu)
48
 
                {
49
 
                }
50
 
                
51
 
                public WelcomePageLinkButton (XElement el, Gtk.IconSize iconSize)
 
46
                public WelcomePageLinkButton (string title, string href, Gtk.IconSize iconSize = Gtk.IconSize.Menu, string icon = null, string desc = null, string tooltip = null)
52
47
                        : this ()
53
48
                {
54
49
                        this.iconSize = iconSize;
55
50
                        
56
 
                        string title = (string) (el.Attribute ("title") ?? el.Attribute ("_title"));
57
51
                        if (string.IsNullOrEmpty (title))
58
52
                                throw new InvalidOperationException ("Link is missing title");
59
53
                        this.text = GettextCatalog.GetString (title);
60
54
                        
61
 
                        string href = (string) el.Attribute ("href");
62
55
                        if (string.IsNullOrEmpty (href))
63
56
                                throw new InvalidOperationException ("Link is missing href");
64
57
                        this.LinkUrl = href;
65
58
                        
66
 
                        string desc = (string) (el.Attribute ("desc") ?? el.Attribute ("_desc"));
67
59
                        if (!string.IsNullOrEmpty (desc))
68
60
                                this.desc = GettextCatalog.GetString (desc);
69
61
                        
70
 
                        string tooltip = (string) (el.Attribute ("tooltip") ?? el.Attribute ("_tooltip"));
71
62
                        if (!string.IsNullOrEmpty (tooltip))
72
63
                                this.TooltipText = GettextCatalog.GetString (tooltip);
 
64
                        else
 
65
                                this.TooltipText = GetLinkTooltip (href);
73
66
                        
74
 
                        string icon = (string) el.Attribute ("icon");
75
67
                        if (!string.IsNullOrEmpty (icon))
76
68
                                this.icon = icon;
77
69
                        
102
94
                        Add (box);
103
95
                }
104
96
                
105
 
                protected override void OnDestroyed ()
106
 
                {
107
 
                        base.OnDestroyed ();
108
 
                        DestroyStatusBar ();
109
 
                }
110
 
                
111
97
                public string LinkUrl { get; private set; }
112
98
                
113
99
                public new string Label {
181
167
                
182
168
                protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
183
169
                {
184
 
                        SetLinkStatus (LinkUrl);
185
170
                        UpdateLabel (true);
186
171
                        return base.OnEnterNotifyEvent (evnt);
187
172
                }
189
174
                protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
190
175
                {
191
176
                        UpdateLabel (false);
192
 
                        DestroyStatusBar ();
193
177
                        return base.OnLeaveNotifyEvent (evnt);
194
178
                }
195
179
                
219
203
                        }
220
204
                }
221
205
                
222
 
                static StatusBarContext statusBar;
223
 
                
224
 
                void DestroyStatusBar ()
225
 
                {
226
 
                        if (statusBar != null) {
227
 
                                statusBar.Dispose ();
228
 
                                statusBar = null;
229
 
                        }
230
 
                }
231
 
                
232
 
                void SetLinkStatus (string link)
233
 
                {
234
 
                        if (link == null) {
235
 
                                DestroyStatusBar ();
236
 
                                return;
237
 
                        }
 
206
                string GetLinkTooltip (string link)
 
207
                {
 
208
                        if (link == null)
 
209
                                return "";
238
210
                        if (link.IndexOf ("monodevelop://") != -1)
239
 
                                return;
 
211
                                return "";
240
212
                                
241
 
                        if (statusBar == null)
242
 
                                statusBar = IdeApp.Workbench.StatusBar.CreateContext ();
243
 
                        
244
213
                        if (link.IndexOf ("project://") != -1) {
245
214
                                string message = link;
246
215
                                message = message.Substring (10);
247
216
                                string msg = GettextCatalog.GetString ("Open solution {0}", message);
248
217
                                if (IdeApp.Workspace.IsOpen)
249
218
                                        msg += " - " + GettextCatalog.GetString ("Hold Control key to open in current workspace.");
250
 
                                statusBar.ShowMessage (msg);
 
219
                                return msg;
251
220
                        } else {
252
 
                                string msg = GettextCatalog.GetString ("Open {0}", link);
253
 
                                statusBar.ShowMessage (msg);
 
221
                                return GettextCatalog.GetString ("Open {0}", link);
254
222
                        }
255
223
                }
256
224
        }