~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/Span.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
namespace Mono.TextEditor.Highlighting
34
34
{
 
35
        [Flags]
 
36
        public enum SpanBeginFlags
 
37
        {
 
38
                None = 0,
 
39
                StartsLine = 1,
 
40
                FirstNonWs = 2
 
41
        }
 
42
 
 
43
        [Flags]
 
44
        public enum SpanExitFlags
 
45
        {
 
46
                None = 0,
 
47
                CancelSpan = 1
 
48
        }
 
49
        
 
50
        [Flags]
 
51
        public enum SpanEndFlags
 
52
        {
 
53
                None = 0
 
54
        }
 
55
 
35
56
        public class Span
36
57
        {
37
58
                public Span ()
38
59
                {
39
60
                }
40
 
                
 
61
 
41
62
                public virtual bool GetIsValid (Style style)
42
63
                {
43
 
                        return (string.IsNullOrEmpty (Color) || style.GetChunkStyle (Color) != null) && 
44
 
                                (string.IsNullOrEmpty (TagColor) || style.GetChunkStyle (TagColor) != null) && 
 
64
                        return (string.IsNullOrEmpty (Color) || style.GetChunkStyle (Color) != null) &&
 
65
                                (string.IsNullOrEmpty (TagColor) || style.GetChunkStyle (TagColor) != null) &&
45
66
                                (string.IsNullOrEmpty (NextColor) || style.GetChunkStyle (NextColor) != null);
46
67
                }
47
 
                
 
68
 
48
69
                public const string Node    = "Span";
49
70
                public const string AltNode = "EolSpan";
50
 
                
 
71
 
51
72
                public Regex Begin {
52
73
                        get;
53
74
                        set;
54
75
                }
55
 
                
 
76
 
56
77
                public Regex Exit {
57
78
                        get;
58
79
                        set;
59
80
                }
60
 
                
 
81
 
61
82
                public Regex End {
62
83
                        get;
63
84
                        set;
67
88
                        get;
68
89
                        set;
69
90
                }
70
 
                
 
91
 
71
92
                public string TagColor {
72
93
                        get;
73
94
                        set;
92
113
                        get;
93
114
                        set;
94
115
                }
95
 
                
 
116
 
96
117
                public string Continuation {
97
118
                        get;
98
119
                        set;
99
120
                }
100
 
                
101
 
                HashSet<string> endFlags = new HashSet<string> ();
102
 
                public HashSet<string> EndFlags {
103
 
                        get {
104
 
                                return endFlags;
105
 
                        }
106
 
                }
107
 
                
108
 
                HashSet<string> beginFlags = new HashSet<string> ();
109
 
                public HashSet<string> BeginFlags {
110
 
                        get {
111
 
                                return beginFlags;
112
 
                        }
113
 
                }
114
 
                
115
 
                HashSet<string> exitFlags = new HashSet<string> ();
116
 
                public HashSet<string> ExitFlags {
117
 
                        get {
118
 
                                return exitFlags;
119
 
                        }
120
 
                }
121
 
                
 
121
 
 
122
                public SpanEndFlags EndFlags {
 
123
                        get;
 
124
                        set;
 
125
                }
 
126
 
 
127
                public SpanBeginFlags BeginFlags {
 
128
                        get;
 
129
                        set;
 
130
                }
 
131
 
 
132
                public SpanExitFlags ExitFlags {
 
133
                        get;
 
134
                        set;
 
135
                }
 
136
 
122
137
                public override string ToString ()
123
138
                {
124
139
                        return String.Format ("[Span: Color={0}, Rule={1}, Begin={2}, End={3}, Escape={4}, stopAtEol={5}]", Color, Rule, Begin, End, String.IsNullOrEmpty (Escape) ? "not set" : "'" + Escape +"'", StopAtEol);
125
140
                }
126
 
                
 
141
 
127
142
                static void AddFlags (HashSet<string> hashSet, string flags)
128
143
                {
129
144
                        if (String.IsNullOrEmpty (flags))
132
147
                                hashSet.Add (flag.Trim ());
133
148
                        }
134
149
                }
135
 
                
 
150
 
136
151
                public static Span Read (XmlReader reader)
137
152
                {
138
153
                        Span result = new Span ();
139
 
                        
 
154
 
140
155
                        result.Rule       = reader.GetAttribute ("rule");
141
156
                        result.Color      = reader.GetAttribute ("color");
142
157
                        result.TagColor   = reader.GetAttribute ("tagColor");
143
158
                        result.NextColor  = reader.GetAttribute ("nextColor");
144
 
                        
 
159
 
145
160
                        result.Escape = reader.GetAttribute ("escape");
146
 
                        
 
161
 
147
162
                        string stopateol = reader.GetAttribute ("stopateol");
148
163
                        if (!String.IsNullOrEmpty (stopateol)) {
149
164
                                result.StopAtEol = Boolean.Parse (stopateol);
150
165
                        }
151
 
                        
 
166
 
152
167
                        if (reader.LocalName == AltNode) {
153
 
                                AddFlags (result.BeginFlags, reader.GetAttribute ("flags"));
 
168
                                string beginFlags = reader.GetAttribute ("flags");
 
169
                                if (!string.IsNullOrEmpty (beginFlags))
 
170
                                        result.BeginFlags = (SpanBeginFlags)Enum.Parse (typeof(SpanBeginFlags), beginFlags);
154
171
                                result.Continuation = reader.GetAttribute ("continuation");
155
172
                                result.Begin        = new Regex (reader.ReadElementString ());
156
173
                                result.StopAtEol = true;
158
175
                                XmlReadHelper.ReadList (reader, Node, delegate () {
159
176
                                        switch (reader.LocalName) {
160
177
                                        case "Begin":
161
 
                                                AddFlags (result.BeginFlags, reader.GetAttribute ("flags"));
 
178
                                                string beginFlags = reader.GetAttribute ("flags");
 
179
                                                if (!string.IsNullOrEmpty (beginFlags))
 
180
                                                        result.BeginFlags = (SpanBeginFlags)Enum.Parse (typeof(SpanBeginFlags), beginFlags);
162
181
                                                result.Begin = new Regex (reader.ReadElementString ());
163
182
                                                return true;
164
183
                                        case "End":
165
 
                                                AddFlags (result.EndFlags, reader.GetAttribute ("flags"));
 
184
                                                string endFlags = reader.GetAttribute ("flags");
 
185
                                                if (!string.IsNullOrEmpty (endFlags))
 
186
                                                        result.EndFlags = (SpanEndFlags)Enum.Parse (typeof(SpanEndFlags), endFlags);
166
187
                                                result.End = new Regex (reader.ReadElementString ());
167
188
                                                return true;
168
189
                                        case "Exit":
169
 
                                                AddFlags (result.ExitFlags, reader.GetAttribute ("flags"));
 
190
                                                string exitFlags = reader.GetAttribute ("flags");
 
191
                                                if (!string.IsNullOrEmpty (exitFlags))
 
192
                                                        result.ExitFlags = (SpanExitFlags)Enum.Parse (typeof(SpanExitFlags), exitFlags);
170
193
                                                result.Exit = new Regex (reader.ReadElementString ());
171
194
                                                return true;
172
195
                                        }