~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Unused/ICSharpCode.TextEditor/src/Document/HighlightingStrategy/TextWord.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// <file>
 
2
//     <copyright see="prj:///doc/copyright.txt"/>
 
3
//     <license see="prj:///doc/license.txt"/>
 
4
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
 
5
//     <version value="$version"/>
 
6
// </file>
 
7
 
 
8
using System;
 
9
using System.Drawing;
 
10
using System.Diagnostics;
 
11
 
 
12
namespace MonoDevelop.TextEditor.Document
 
13
{
 
14
        
 
15
        public enum TextWordType {
 
16
                Word,
 
17
                Space,
 
18
                Tab
 
19
        }
 
20
        
 
21
        /// <summary>
 
22
        /// This class represents single words with color information, two special versions of a word are 
 
23
        /// spaces and tabs.
 
24
        /// </summary>
 
25
        public class TextWord
 
26
        {
 
27
                HighlightColor  color;
 
28
                LineSegment     word;
 
29
                IDocument       document;
 
30
                
 
31
                int          offset;
 
32
                int          length;
 
33
                TextWordType type;
 
34
                
 
35
                static TextWord spaceWord = new TextWord(TextWordType.Space);
 
36
                static TextWord tabWord   = new TextWord(TextWordType.Tab);
 
37
                
 
38
                public bool hasDefaultColor;
 
39
                
 
40
                static public TextWord Space {
 
41
                        get {
 
42
                                return spaceWord;
 
43
                        }
 
44
                }
 
45
                
 
46
                static public TextWord Tab {
 
47
                        get {
 
48
                                return tabWord;
 
49
                        }
 
50
                }
 
51
                
 
52
                public int  Length {
 
53
                        get {
 
54
                                if (type == TextWordType.Word) {
 
55
                                        return length;
 
56
                                } 
 
57
                                return 1;
 
58
                        }
 
59
                }
 
60
                
 
61
                public bool HasDefaultColor {
 
62
                        get {
 
63
                                return hasDefaultColor;
 
64
                        }
 
65
                }
 
66
                
 
67
                public TextWordType Type {
 
68
                        get {
 
69
                                return type;
 
70
                        }
 
71
                }
 
72
                
 
73
//              string       myword = null;
 
74
                public string Word {
 
75
                        get {
 
76
                                return document.GetText(word.Offset + offset, length);
 
77
//                              if (myword == null) {
 
78
//                                      myword = document.GetText(word.Offset + offset, length);
 
79
//                              }
 
80
//                              return myword;
 
81
                        }
 
82
                }
 
83
                
 
84
                public Pango.FontDescription Font {
 
85
                        get {
 
86
                                return color.Font;
 
87
                        }
 
88
                }
 
89
                
 
90
                public Color Color {
 
91
                        get {
 
92
                                return color.Color;
 
93
                        }
 
94
                }
 
95
                
 
96
                public HighlightColor SyntaxColor {
 
97
                        get {
 
98
                                return color;
 
99
                        }
 
100
                        set {
 
101
                                color = value;
 
102
                        }
 
103
                }
 
104
                
 
105
                public bool IsWhiteSpace {
 
106
                        get {
 
107
                                return type == TextWordType.Space || type == TextWordType.Tab;
 
108
                        }
 
109
                }
 
110
                
 
111
                // TAB
 
112
                private TextWord(TextWordType type)
 
113
                {
 
114
                        this.type = type;
 
115
                }
 
116
                
 
117
                public TextWord(IDocument document, LineSegment word, int offset, int length, HighlightColor color, bool hasDefaultColor)
 
118
                {
 
119
                        Debug.Assert(document != null);
 
120
                        Debug.Assert(word != null);
 
121
                        Debug.Assert(color != null);
 
122
                        
 
123
                        this.document = document;
 
124
                        this.word  = word;
 
125
                        this.offset = offset;
 
126
                        this.length = length;
 
127
                        this.color = color;
 
128
                        this.hasDefaultColor = hasDefaultColor;
 
129
                        this.type  = TextWordType.Word;
 
130
                }
 
131
                
 
132
                /// <summary>
 
133
                /// Converts a <see cref="TextWord"/> instance to string (for debug purposes)
 
134
                /// </summary>
 
135
                public override string ToString()
 
136
                {
 
137
                        return "[TextWord: Word = " + Word + ", Font = " + Font.Family + ", Color = " + Color + "]";
 
138
                }
 
139
        }
 
140
}