~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do.Interface.Windows/src/Do.Interface/Do.Interface.Widgets/SymbolDisplayLabel.cs

  • Committer: Hardeep S
  • Date: 2009-06-23 03:53:12 UTC
  • Revision ID: ootz0rz@gmail.com-20090623035312-it8tb5wkha6nf31p
Added Do.Interface.Windows, and a bunch of cleanup with old MonoDevelop files elsewhere

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* SymbolDisplayLabel.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this source distribution.
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
using System;
 
21
 
 
22
using Gtk;
 
23
using Gdk;
 
24
 
 
25
using Do.Universe;
 
26
using Do.Interface;
 
27
 
 
28
namespace Do.Interface.Widgets
 
29
{
 
30
        public class SymbolDisplayLabel : Label
 
31
        {
 
32
                const string DisplayFormat = "<span size=\"medium\"> {1} </span>";
 
33
                
 
34
                string highlight;
 
35
                string name, description;
 
36
                
 
37
                public SymbolDisplayLabel ():
 
38
                        base ("")
 
39
                {
 
40
                        highlight = name = description = "";
 
41
                        Build ();
 
42
                }
 
43
                
 
44
                void Build ()
 
45
                {
 
46
                        UseMarkup = true;
 
47
                        Ellipsize = Pango.EllipsizeMode.Middle;
 
48
                        Justify = Justification.Center;
 
49
                        
 
50
                        ModifyFg (StateType.Normal,
 
51
                                new Gdk.Color (byte.MaxValue, byte.MaxValue, byte.MaxValue));
 
52
                }
 
53
                
 
54
                public Do.Universe.Item DisplayObject
 
55
                {
 
56
                        set {
 
57
                                Do.Universe.Item displayObject;
 
58
                                
 
59
                                displayObject = value;
 
60
                                name = description = highlight = "";
 
61
                                if (displayObject != null) {
 
62
                                        name = displayObject.Name;
 
63
                                        description = displayObject.Description;
 
64
                                }
 
65
                                SetDisplayLabel (name, description);
 
66
                        }
 
67
                }
 
68
                
 
69
                public void SetDisplayLabel (string name, string description)
 
70
                {
 
71
                        this.name = (name ?? "").Replace ("\n", " ");
 
72
                        this.description = (description ?? "").Replace ("\n", " ");
 
73
                        highlight = "";
 
74
                        UpdateText ();
 
75
                }
 
76
                
 
77
                public string Highlight
 
78
                {
 
79
                        get { return highlight; }
 
80
                        set {
 
81
                                highlight = value ?? "";
 
82
                                UpdateText ();
 
83
                        }
 
84
                }
 
85
                
 
86
                void UpdateText ()
 
87
                {
 
88
                        string highlighted, safe_name, safe_description;
 
89
 
 
90
                        safe_name = Util.Appearance.MarkupSafeString (name);
 
91
                        safe_description = Util.Appearance.MarkupSafeString (description);
 
92
                        highlighted = Util.FormatCommonSubstrings(safe_name, highlight, "<u>{0}</u>");
 
93
                        Markup = string.Format (DisplayFormat, highlighted, safe_description);
 
94
                }
 
95
                
 
96
        }
 
97
}