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

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/ColorScheme.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
 
// Style.cs
 
1
//
 
2
// ColorScheme.cs
2
3
//
3
4
// Author:
4
 
//   Mike KrĆ¼ger <mkrueger@novell.com>
 
5
//       Mike KrĆ¼ger <mkrueger@xamarin.com>
5
6
//
6
 
// Copyright (c) 2007 Novell, Inc (http://www.novell.com)
 
7
// Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
7
8
//
8
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
10
// of this software and associated documentation files (the "Software"), to deal
22
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
25
// THE SOFTWARE.
25
 
//
26
 
//
27
 
 
28
26
using System;
 
27
using System.IO;
29
28
using System.Collections.Generic;
 
29
using System.Linq;
 
30
using System.Xml.Linq;
 
31
using System.Xml.XPath;
 
32
using System.Reflection;
 
33
using System.Text;
30
34
using System.Xml;
31
 
using Gdk;
32
 
using System.Globalization;
 
35
using Xwt.Drawing;
33
36
 
34
37
namespace Mono.TextEditor.Highlighting
35
38
{
36
39
        public class ColorScheme
37
40
        {
38
 
                public static ColorScheme Empty = new ColorScheme ();
39
 
                
40
 
                Dictionary<string, ChunkStyle> styleLookupTable = new Dictionary<string, ChunkStyle> (); 
41
 
                Dictionary<string, string> customPalette = new Dictionary<string, string> (); 
42
 
                
43
 
                public IEnumerable<string> ColorNames {
44
 
                        get {
45
 
                                return styleLookupTable.Keys;
46
 
                        }
47
 
                }
48
 
                
49
 
                public Cairo.Color GetColorFromDefinition (string colorName)
50
 
                {
51
 
                        return this.GetChunkStyle (colorName).CairoColor;
52
 
                }
53
 
                
54
 
                #region Named colors
55
 
                
56
 
                public const string DefaultString = "text";
57
 
                public virtual ChunkStyle Default {
58
 
                        get {
59
 
                                return GetChunkStyle (DefaultString);
60
 
                        }
61
 
                }
62
 
 
63
 
                public const string LineNumberString = "linenumber";
64
 
                public virtual ChunkStyle LineNumber {
65
 
                        get {
66
 
                                return GetChunkStyle (LineNumberString);
67
 
                        }
68
 
                }
69
 
 
70
 
                public const string LineNumberFgHighlightedString = "linenumber.highlight";
71
 
                public virtual Cairo.Color LineNumberFgHighlighted {
72
 
                        get {
73
 
                                return GetColorFromDefinition (LineNumberFgHighlightedString);
74
 
                        }
75
 
                }
76
 
 
77
 
                public const string IconBarBgString = "iconbar";
78
 
                public virtual Cairo.Color IconBarBg {
79
 
                        get {
80
 
                                return GetColorFromDefinition (IconBarBgString);
81
 
                        }
82
 
                }
83
 
 
84
 
                public const string IconBarSeperatorString = "iconbar.separator";
85
 
                public virtual Cairo.Color IconBarSeperator {
86
 
                        get {
87
 
                                return GetColorFromDefinition (IconBarSeperatorString);
88
 
                        }
89
 
                }
90
 
 
91
 
                public const string FoldLineString = "fold";
92
 
                public virtual ChunkStyle FoldLine {
93
 
                        get {
94
 
                                return GetChunkStyle (FoldLineString);
95
 
                        }
96
 
                }
97
 
 
98
 
                public const string FoldLineHighlightedString = "fold.highlight";
99
 
                public virtual Cairo.Color FoldLineHighlighted {
100
 
                        get {
101
 
                                return GetColorFromDefinition (FoldLineHighlightedString);
102
 
                        }
103
 
                }
104
 
                
105
 
                public const string LineChangedBgString = "marker.line.changed";
106
 
                public virtual Cairo.Color LineChangedBg {
107
 
                        get {
108
 
                                return GetColorFromDefinition (LineChangedBgString);
109
 
                        }
110
 
                }
111
 
                
112
 
                public const string LineDirtyBgString = "marker.line.dirty";
113
 
                public virtual Cairo.Color LineDirtyBg {
114
 
                        get {
115
 
                                return GetColorFromDefinition (LineDirtyBgString);
116
 
                        }
117
 
                }
118
 
 
119
 
                public const string SelectionString = "text.selection";
120
 
                public virtual ChunkStyle Selection {
121
 
                        get {
122
 
                                return GetChunkStyle (SelectionString);
123
 
                        }
124
 
                }
125
 
                
126
 
                public const string InactiveSelectionString = "text.selection.inactive";
127
 
                public virtual ChunkStyle InactiveSelection {
128
 
                        get {
129
 
                                return GetChunkStyle (InactiveSelectionString);
130
 
                        }
131
 
                }
132
 
 
133
 
                public const string LineMarkerString = "marker.line";
134
 
                public virtual Cairo.Color LineMarker {
135
 
                        get {
136
 
                                return GetColorFromDefinition (LineMarkerString);
137
 
                        }
138
 
                }
139
 
 
140
 
                public const string RulerString = "marker.ruler";
141
 
                public virtual Cairo.Color Ruler {
142
 
                        get {
143
 
                                return GetColorFromDefinition (RulerString);
144
 
                        }
145
 
                }
146
 
 
147
 
                public const string WhitespaceMarkerString = "marker.whitespace";
148
 
                public virtual Cairo.Color WhitespaceMarker {
149
 
                        get {
150
 
                                return GetColorFromDefinition (WhitespaceMarkerString);
151
 
                        }
152
 
                }
153
 
                
154
 
                public const string EolWhitespaceMarkerString = "marker.whitespace.eol";
155
 
                public virtual Cairo.Color EolWhitespaceMarker {
156
 
                        get {
157
 
                                return GetColorFromDefinition (EolWhitespaceMarkerString);
158
 
                        }
159
 
                }
160
 
 
161
 
                public const string InvalidLineMarkerString = "marker.invalidline";
162
 
                public virtual Cairo.Color InvalidLineMarker {
163
 
                        get {
164
 
                                return GetColorFromDefinition (InvalidLineMarkerString);
165
 
                        }
166
 
                }
167
 
                
168
 
                public const string FoldToggleMarkerString = "fold.togglemarker";
169
 
                public virtual Cairo.Color FoldToggleMarker {
170
 
                        get {
171
 
                                return GetColorFromDefinition (FoldToggleMarkerString);
172
 
                        }
173
 
                }
174
 
                
175
 
                public const string BracketHighlightRectangleString = "marker.bracket";
176
 
 
177
 
                public virtual ChunkStyle BracketHighlightRectangle {
178
 
                        get {
179
 
                                return GetChunkStyle (BracketHighlightRectangleString);
180
 
                        }
181
 
                }
182
 
                
183
 
                public const string UsagesHighlightRectangleString = "marker.usages";
184
 
                public virtual ChunkStyle UsagesHighlightRectangle {
185
 
                        get {
186
 
                                return GetChunkStyle (UsagesHighlightRectangleString);
187
 
                        }
188
 
                }
189
 
                
190
 
                public const string BookmarkColor2String = "marker.bookmark.color2";
191
 
                public virtual Cairo.Color BookmarkColor2 {
192
 
                        get {
193
 
                                return GetColorFromDefinition (BookmarkColor2String);
194
 
                        }
195
 
                }
196
 
                
197
 
                public const string BookmarkColor1String = "marker.bookmark.color1";
198
 
                public virtual Cairo.Color BookmarkColor1 {
199
 
                        get {
200
 
                                return GetColorFromDefinition (BookmarkColor1String);
201
 
                        }
202
 
                }
203
 
                
204
 
                public const string ReadOnlyTextBgString = "text.background.readonly";
205
 
                public Cairo.Color ReadOnlyTextBg {
206
 
                        get {
207
 
                                return GetColorFromDefinition (ReadOnlyTextBgString);
208
 
                        }
209
 
                }
210
 
                
211
 
                public const string SearchTextBgString = "text.background.searchresult";
212
 
                public Cairo.Color SearchTextBg {
213
 
                        get {
214
 
                                return GetColorFromDefinition (SearchTextBgString);
215
 
                        }
216
 
                }
217
 
                
218
 
                public const string SearchTextMainBgString = "text.background.searchresult-main";
219
 
                public Cairo.Color SearchTextMainBg {
220
 
                        get {
221
 
                                return GetColorFromDefinition (SearchTextMainBgString);
222
 
                        }
223
 
                }
224
 
 
225
 
                public const string BreakpointString = "marker.breakpoint";
226
 
                public Cairo.Color BreakpointFg {
227
 
                        get {
228
 
                                return GetChunkStyle (BreakpointString).CairoColor;
229
 
                        }
230
 
                }
231
 
                public Cairo.Color BreakpointBg {
232
 
                        get {
233
 
                                return GetChunkStyle (BreakpointString).CairoBackgroundColor;
234
 
                        }
235
 
                }
236
 
 
237
 
                public const string BreakpointMarkerColor2String = "marker.breakpoint.color2";
238
 
                public Cairo.Color BreakpointMarkerColor2 {
239
 
                        get {
240
 
                                return GetColorFromDefinition (BreakpointMarkerColor2String);
241
 
                        }
242
 
                }
243
 
 
244
 
                public const string BreakpointMarkerColor1String = "marker.breakpoint.color1";
245
 
                public Cairo.Color BreakpointMarkerColor1 {
246
 
                        get {
247
 
                                return GetColorFromDefinition (BreakpointMarkerColor1String);
248
 
                        }
249
 
                }
250
 
 
251
 
                public const string CurrentDebugLineString = "marker.debug.currentline";
252
 
                public Cairo.Color CurrentDebugLineFg {
253
 
                        get {
254
 
                                return GetChunkStyle (CurrentDebugLineString).CairoColor;
255
 
                        }
256
 
                }
257
 
                
258
 
                public Cairo.Color CurrentDebugLineBg {
259
 
                        get {
260
 
                                return GetChunkStyle (CurrentDebugLineString).CairoBackgroundColor;
261
 
                        }
262
 
                }
263
 
 
264
 
                public const string CurrentDebugLineMarkerColor2String = "marker.debug.currentline.color2";
265
 
                public Cairo.Color CurrentDebugLineMarkerColor2 {
266
 
                        get {
267
 
                                return GetColorFromDefinition (CurrentDebugLineMarkerColor2String);
268
 
                        }
269
 
                }
270
 
 
271
 
                public const string CurrentDebugLineMarkerColor1String = "marker.debug.currentline.color1";
272
 
                public Cairo.Color CurrentDebugLineMarkerColor1 {
273
 
                        get {
274
 
                                return GetColorFromDefinition (CurrentDebugLineMarkerColor1String);
275
 
                        }
276
 
                }
277
 
 
278
 
                public const string CurrentDebugLineMarkerBorderString = "marker.debug.currentline.border";
279
 
                public Cairo.Color CurrentDebugLineMarkerBorder {
280
 
                        get {
281
 
                                return GetColorFromDefinition (CurrentDebugLineMarkerBorderString);
282
 
                        }
283
 
                }
284
 
                
285
 
                public const string DebugStackLineString = "marker.debug.stackline";
286
 
                public Cairo.Color DebugStackLineFg {
287
 
                        get {
288
 
                                return GetChunkStyle (DebugStackLineString).CairoColor;
289
 
                        }
290
 
                }
291
 
                
292
 
                public Cairo.Color DebugStackLineBg {
293
 
                        get {
294
 
                                return GetChunkStyle (DebugStackLineString).CairoBackgroundColor;
295
 
                        }
296
 
                }
297
 
 
298
 
                public const string DebugStackLineMarkerColor2String = "marker.debug.stackline.color2";
299
 
                public Cairo.Color DebugStackLineMarkerColor2 {
300
 
                        get {
301
 
                                return GetColorFromDefinition (DebugStackLineMarkerColor2String);
302
 
                        }
303
 
                }
304
 
 
305
 
                public const string DebugStackLineMarkerColor1String = "marker.debug.stackline.color1";
306
 
                public Cairo.Color DebugStackLineMarkerColor1 {
307
 
                        get {
308
 
                                return GetColorFromDefinition (DebugStackLineMarkerColor1String);
309
 
                        }
310
 
                }
311
 
 
312
 
                public const string DebugStackLineMarkerBorderString = "marker.debug.stackline.border";
313
 
                public Cairo.Color DebugStackLineMarkerBorder {
314
 
                        get {
315
 
                                return GetColorFromDefinition (DebugStackLineMarkerBorderString);
316
 
                        }
317
 
                }
318
 
 
319
 
                public const string InvalidBreakpointBgString = "marker.breakpoint.invalid.background";
320
 
                public Cairo.Color InvalidBreakpointBg {
321
 
                        get {
322
 
                                return GetColorFromDefinition (InvalidBreakpointBgString);
323
 
                        }
324
 
                }
325
 
 
326
 
                public const string InvalidBreakpointMarkerColor1String = "marker.breakpoint.invalid.color1";
327
 
                public Cairo.Color InvalidBreakpointMarkerColor1 {
328
 
                        get {
329
 
                                return GetColorFromDefinition (InvalidBreakpointMarkerColor1String);
330
 
                        }
331
 
                }
332
 
 
333
 
                public const string DisabledBreakpointBgString = "marker.breakpoint.disabled.background";
334
 
                public Cairo.Color DisabledBreakpointBg {
335
 
                        get {
336
 
                                return GetColorFromDefinition (DisabledBreakpointBgString);
337
 
                        }
338
 
                }
339
 
 
340
 
                public const string InvalidBreakpointMarkerBorderString = "marker.breakpoint.invalid.border";
341
 
                public Cairo.Color InvalidBreakpointMarkerBorder {
342
 
                        get {
343
 
                                return GetColorFromDefinition (InvalidBreakpointMarkerBorderString);
344
 
                        }
345
 
                }
346
 
                
347
 
                public const string ErrorUnderlineString = "marker.underline.error";
348
 
                public Cairo.Color ErrorUnderline {
349
 
                        get {
350
 
                                return GetColorFromDefinition (ErrorUnderlineString);
351
 
                        }
352
 
                }
353
 
                
354
 
                public const string WarningUnderlineString = "marker.underline.warning";
355
 
                public Cairo.Color WarningUnderline {
356
 
                        get {
357
 
                                return GetColorFromDefinition (WarningUnderlineString);
358
 
                        }
359
 
                }
360
 
                
361
 
                public const string HintUnderlineString = "marker.underline.hint";
362
 
                public Cairo.Color HintUnderline {
363
 
                        get {
364
 
                                return GetColorFromDefinition (HintUnderlineString);
365
 
                        }
366
 
                }
367
 
                
368
 
                public const string SuggestionUnderlineString = "marker.underline.suggestion";
369
 
                public Cairo.Color SuggestionUnderline {
370
 
                        get {
371
 
                                return GetColorFromDefinition (SuggestionUnderlineString);
372
 
                        }
373
 
                }
374
 
                
375
 
                public const string PrimaryTemplateColorString = "marker.template.primary_template";
376
 
                public virtual ChunkStyle PrimaryTemplate {
377
 
                        get {
378
 
                                return GetChunkStyle (PrimaryTemplateColorString);
379
 
                        }
380
 
                }
381
 
                
382
 
                public const string PrimaryTemplateHighlightedColorString = "marker.template.primary_highlighted_template";
383
 
                public virtual ChunkStyle PrimaryTemplateHighlighted {
384
 
                        get {
385
 
                                return GetChunkStyle (PrimaryTemplateHighlightedColorString);
386
 
                        }
387
 
                }
388
 
                
389
 
                public const string SecondaryTemplateColorString = "marker.template.secondary_template";
390
 
                public virtual ChunkStyle SecondaryTemplate {
391
 
                        get {
392
 
                                return GetChunkStyle (SecondaryTemplateColorString);
393
 
                        }
394
 
                }
395
 
                
396
 
                public const string SecondaryTemplateHighlightedColorString = "marker.template.secondary_highlighted_template";
397
 
                public virtual ChunkStyle SecondaryTemplateHighlighted {
398
 
                        get {
399
 
                                return GetChunkStyle (SecondaryTemplateHighlightedColorString);
400
 
                        }
401
 
                }
402
 
                #endregion
403
 
                
404
 
                public string Name {
405
 
                        get;
406
 
                        set;
407
 
                }
408
 
                
409
 
                public string Description {
410
 
                        get;
411
 
                        set;
412
 
                }
413
 
                
414
 
                public static Cairo.Color ToCairoColor (Gdk.Color color)
415
 
                {
416
 
                        return new Cairo.Color ((double)color.Red / ushort.MaxValue,
417
 
                                                (double)color.Green / ushort.MaxValue,
418
 
                                                (double)color.Blue / ushort.MaxValue);
419
 
                }
420
 
                
421
 
                public static Gdk.Color ToGdkColor (Cairo.Color color)
422
 
                {
423
 
                        return new Gdk.Color ((byte)(color.R  * 255),
424
 
                                                (byte)(color.G * 255),
425
 
                                                (byte)(color.B * 255));
426
 
                }
427
 
                                
428
 
                public static Cairo.Color ToCairoColor (Gdk.Color color, double alpha)
429
 
                {
430
 
                        return new Cairo.Color ((double)color.Red / ushort.MaxValue,
431
 
                                                (double)color.Green / ushort.MaxValue,
432
 
                                                (double)color.Blue / ushort.MaxValue,
433
 
                                                alpha);
434
 
                }
435
 
                
436
 
                protected ColorScheme ()
437
 
                {
438
 
                        SetStyle (DefaultString, 0, 0, 0, 255, 255, 255);
439
 
                        SetStyle (ReadOnlyTextBgString, 0xFA, 0xFA, 0xF8);
440
 
                        
441
 
                        GetChunkStyle (DefaultString).ChunkProperties |= ChunkProperties.TransparentBackground;
442
 
 
443
 
                        SetStyle (LineNumberString, 172, 168, 153, 255, 255, 255);
444
 
                        SetStyle (LineNumberFgHighlightedString, 122, 118, 103);
445
 
                        
446
 
                        SetStyle (IconBarBgString, 255, 255, 255);
447
 
                        SetStyle (IconBarSeperatorString, 172, 168, 153);
448
 
                        
449
 
                        SetStyle (FoldLineString, LineNumberString);
450
 
                        SetStyle (FoldLineHighlightedString, IconBarSeperatorString);
451
 
                        SetStyle (FoldToggleMarkerString, DefaultString);
452
 
                        
453
 
                        SetStyle (LineDirtyBgString, 255, 238, 98);
454
 
                        SetStyle (LineChangedBgString, 108, 226, 108);
455
 
                        
456
 
                        SetStyle (SelectionString, 255, 255, 255, 96, 87, 210);
457
 
                        SetStyle (InactiveSelectionString, 255, 255, 255, 196, 196, 196);
458
 
                        
459
 
                        SetStyle (LineMarkerString, 200, 255, 255);
460
 
                        SetStyle (RulerString, 187, 187, 187);
461
 
                        SetStyle (WhitespaceMarkerString, RulerString);
462
 
                        
463
 
                        SetStyle (InvalidLineMarkerString, 210, 0, 0);
464
 
                        
465
 
                        SetStyle (BreakpointString, 255, 255, 255, 125, 0, 0);
466
 
                        
467
 
                        SetStyle (BreakpointMarkerColor1String, 255, 255, 255);
468
 
                        SetStyle (BreakpointMarkerColor2String, 125, 0, 0);
469
 
 
470
 
                        SetStyle (DisabledBreakpointBgString, 237, 220, 220);
471
 
                        
472
 
                        SetStyle (CurrentDebugLineString, 0, 0, 0, 255, 255, 0);
473
 
                        SetStyle (CurrentDebugLineMarkerColor1String, 255, 255, 0);
474
 
                        SetStyle (CurrentDebugLineMarkerColor2String, 255, 255, 204);
475
 
                        SetStyle (CurrentDebugLineMarkerBorderString, 102, 102, 0);
476
 
                        
477
 
                        SetStyle (DebugStackLineString, 0, 0, 0, 128, 255, 128);
478
 
                        SetStyle (DebugStackLineMarkerColor1String, 128, 255, 128);
479
 
                        SetStyle (DebugStackLineMarkerColor2String, 204, 255, 204);
480
 
                        SetStyle (DebugStackLineMarkerBorderString, 51, 102, 51); 
481
 
                        
482
 
                        SetStyle (InvalidBreakpointBgString, 237, 220, 220);
483
 
                        SetStyle (InvalidBreakpointMarkerColor1String, 237, 220, 220);
484
 
                        SetStyle (InvalidBreakpointMarkerBorderString, 125, 0, 0);
485
 
                        SetStyle (SearchTextBgString, 255, 226, 185);
486
 
                        SetStyle (SearchTextMainBgString, 243, 221, 72);
487
 
                        
488
 
                        SetStyle (BracketHighlightRectangleString, 0xd3, 0xd7, 0xcf, 0xee, 0xee, 0xec);
489
 
                        SetStyle (UsagesHighlightRectangleString, 0xd3, 0xd7, 0xcf, 0xee, 0xee, 0xec);
490
 
                        
491
 
                        SetStyle (BookmarkColor1String, 255, 255, 255);
492
 
                        SetStyle (BookmarkColor2String, 105, 156, 235);
493
 
                        
494
 
                        SetStyle (ErrorUnderlineString, 255, 0, 0);
495
 
                        SetStyle (WarningUnderlineString, 255, 165, 0);
496
 
                        SetStyle (SuggestionUnderlineString, 143, 198, 143);
497
 
                        SetStyle (HintUnderlineString, 143, 143, 198);
498
 
                        
499
 
                        SetStyle ("diff.line-added", 0, 0x8B, 0x8B, ChunkProperties.None);
500
 
                        SetStyle ("diff.line-removed", 0x6A, 0x5A, 0xCD, ChunkProperties.None);
501
 
                        SetStyle ("diff.line-changed", "text.preprocessor");
502
 
                        SetStyle ("diff.header", 0, 128, 0, BOLD);
503
 
                        SetStyle ("diff.header-seperator", 0, 0, 255);
504
 
                        SetStyle ("diff.header-oldfile", "diff.header");
505
 
                        SetStyle ("diff.header-newfile", "diff.header");
506
 
                        SetStyle ("diff.location", "keyword.misc");
507
 
                        
508
 
                        SetStyle (PrimaryTemplateColorString, 0xB4, 0xE4, 0xB4, 0xB4, 0xE4, 0xB4);
509
 
                        SetStyle (PrimaryTemplateHighlightedColorString, 0, 0, 0, 0xB4, 0xE4, 0xB4);
510
 
                         
511
 
                        SetStyle (SecondaryTemplateColorString, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
512
 
                        SetStyle (SecondaryTemplateHighlightedColorString, 0x7F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF);
513
 
                        
514
 
                        
515
 
                        SetStyleFromWeb ("bubble.warning", "black", "#f4eeda");
516
 
                        SetStyle ("bubble.warning.text", 0, 0, 0);
517
 
                        SetStyleFromWeb ("bubble.error", "black", "#f5eae7");
518
 
                        SetStyle ("bubble.error.text", 0, 0, 0);
519
 
                        
520
 
                        //regions in ASP.NET, T4, etc.
521
 
                        SetStyle ("template", "text");
522
 
                        SetStyle ("template.tag", "constant.language");
523
 
                        SetStyle ("template.directive", "constant.language");
524
 
                        
525
 
                }
526
 
                
527
 
                protected void PopulateDefaults ()
528
 
                {
529
 
                        SetStyle ("text",                      0,    0,    0);
530
 
                        SetStyle ("text.punctuation",          0,    0,    0);
531
 
                        SetStyle ("text.link",                 0,    0,  255);
532
 
                        SetStyle ("text.preprocessor",         0,  128,    0);
533
 
                        SetStyle ("text.preprocessor.keyword", 0,  128,    0, BOLD);
534
 
                        SetStyle ("text.markup",               0, 0x8A, 0x8C);
535
 
                        SetStyle ("text.markup.tag",        0x6A, 0x5A, 0xCD);
536
 
                        
537
 
                        SetStyle ("comment",              0,   0, 255);
538
 
                        SetStyle ("comment.line",         0,   0, 255);
539
 
                        SetStyle ("comment.block",        0,   0, 255);
540
 
                        SetStyle ("comment.doc",          0,   0, 255);
541
 
                        SetStyle ("comment.tag",        128, 128, 128, ITALIC);
542
 
                        SetStyle ("comment.tag.line",   128, 128, 128, ITALIC);
543
 
                        SetStyle ("comment.tag.block" , 128, 128, 128, ITALIC);
544
 
                        SetStyle ("comment.tag.doc",    128, 128, 128, ITALIC);
545
 
                        SetStyle ("comment.keyword",      0,   0, 255, ITALIC);
546
 
                        SetStyle ("comment.keyword.todo", 0,   0, 255, BOLD);
547
 
                        
548
 
                        SetStyle ("constant",               255,   0, 255);
549
 
                        SetStyle ("constant.digit",         255,   0, 255);
550
 
                        SetStyle ("constant.language",      165,  42,  42, BOLD);
551
 
                        SetStyle ("constant.language.void", 165,  42,  42, BOLD);
552
 
                        
553
 
                        SetStyle ("string",        255, 0, 255);
554
 
                        SetStyle ("string.single", 255, 0, 255);
555
 
                        SetStyle ("string.double", 255, 0, 255);
556
 
                        SetStyle ("string.other",  255, 0, 255);
557
 
                        
558
 
                        SetStyle ("keyword.semantic.type", 0, 0x8A , 0x8C);
559
 
                        
560
 
                        SetStyle ("keyword", 0, 0, 0, BOLD);
561
 
                        SetStyle ("keyword.access",      165,  42,  42, BOLD);
562
 
                        SetStyle ("keyword.operator",    165,  42,  42, BOLD);
563
 
                        SetStyle ("keyword.operator.declaration", 165,  42,  42, BOLD);
564
 
                        SetStyle ("keyword.selection",   165,  42,  42, BOLD);
565
 
                        SetStyle ("keyword.iteration",   165,  42,  42, BOLD);
566
 
                        SetStyle ("keyword.jump",        165,  42,  42, BOLD);
567
 
                        SetStyle ("keyword.context",     165,  42,  42, BOLD);
568
 
                        SetStyle ("keyword.exceptions",  165,  42,  42, BOLD);
569
 
                        SetStyle ("keyword.modifier",    165,  42,  42, BOLD);
570
 
                        SetStyle ("keyword.type",         46, 139,  87, BOLD);
571
 
                        SetStyle ("keyword.namespace",   165,  42,  42, BOLD);
572
 
                        SetStyle ("keyword.property",    165,  42,  42, BOLD);
573
 
                        SetStyle ("keyword.declaration", 165,  42,  42, BOLD);
574
 
                        SetStyle ("keyword.parameter",   165,  42,  42, BOLD);
575
 
                        SetStyle ("keyword.misc",        165,  42,  42, BOLD);
576
 
                        
577
 
                        SetStyle ("template.directive", 0x6A, 0x5A, 0xCD, 0xF0, 0xF0, 0xD0);
578
 
                        SetStyle ("template.tag",       0x6A, 0x5A, 0xCD, 0xF0, 0xF0, 0xD0);
579
 
                        SetStyle ("template",           0x00, 0x00, 0x00, 0xF0, 0xF0, 0xD0);
580
 
                }
581
 
                
582
 
                const ChunkProperties BOLD   = ChunkProperties.Bold;
583
 
                const ChunkProperties ITALIC = ChunkProperties.Bold;
584
 
                
585
 
                void SetStyle (string name, ChunkStyle style)
586
 
                {
587
 
                        styleLookupTable[name] = style;
588
 
                }
589
 
                
590
 
                void SetStyle (string name, string referencedStyleName)
591
 
                {
592
 
                        styleLookupTable[name] = new ReferencedChunkStyle (this, referencedStyleName);
593
 
                }
594
 
                
595
 
                void SetStyle (string name, byte r, byte g, byte b)
596
 
                {
597
 
                        SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b)));
598
 
                }
599
 
                
600
 
                void SetStyleFromWeb (string name, string colorString)
601
 
                {
602
 
                        var color = new Color ();
603
 
                        if (!Gdk.Color.Parse (colorString, ref color)) 
604
 
                                throw new Exception ("Can't parse color: " + colorString);
605
 
                        SetStyle (name, new ChunkStyle (color));
606
 
                }
607
 
 
608
 
                void SetStyleFromWeb (string name, string colorString, string bgColorString)
609
 
                {
610
 
                        var color = new Color ();
611
 
                        if (!Gdk.Color.Parse (colorString, ref color)) 
612
 
                                throw new Exception ("Can't parse color: " + colorString);
613
 
                        var bgColor = new Color ();
614
 
                        if (!Gdk.Color.Parse (bgColorString, ref bgColor)) 
615
 
                                throw new Exception ("Can't parse color: " + bgColorString);
616
 
                        SetStyle (name, new ChunkStyle (color, bgColor));
617
 
                }
618
 
                
619
 
                void SetStyle (string name, byte r, byte g, byte b, byte bg_r, byte bg_g, byte bg_b)
620
 
                {
621
 
                        SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b), new Gdk.Color (bg_r, bg_g, bg_b)));
622
 
                }
623
 
                        
624
 
                void SetStyle (string name, byte r, byte g, byte b, ChunkProperties properties)
625
 
                {
626
 
                        SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b), properties));
627
 
                }
628
 
                        
629
 
/*              void SetStyle (string name, byte r, byte g, byte b, byte bg_r, byte bg_g, byte bg_b, ChunkProperties properties)
630
 
                {
631
 
                        SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b), new Gdk.Color (bg_r, bg_g, bg_b), properties));
632
 
                }*/
633
 
                
634
 
                public ChunkStyle GetDefaultChunkStyle ()
635
 
                {
636
 
                        ChunkStyle style;
637
 
                        if (!styleLookupTable.TryGetValue (DefaultString, out style)) {
638
 
                                style = new ChunkStyle (ToGdkColor (GetColorFromDefinition (DefaultString)));
639
 
                                styleLookupTable[DefaultString] = style;
640
 
                        }
641
 
                        return style;
 
41
                public string Name { get; set; }
 
42
                public string Description { get; set; }
 
43
                public string Originator { get; set; }
 
44
                public string BaseScheme { get; set; }
 
45
 
 
46
                #region Ambient Colors
 
47
                [ColorDescription("Background(Read Only)",VSSetting="color=Plain Text/Background")]
 
48
                public AmbientColor BackgroundReadOnly { get; private set; }
 
49
                
 
50
                [ColorDescription("Search result background")]
 
51
                public AmbientColor SearchResult { get; private set; }
 
52
                
 
53
                [ColorDescription("Search result background (highlighted)")]
 
54
                public AmbientColor SearchResultMain { get; private set; }
 
55
 
 
56
                [ColorDescription("Fold Square", VSSetting="color=outlining.verticalrule/Foreground")]
 
57
                public AmbientColor FoldLineColor { get; private set; }
 
58
                
 
59
                [ColorDescription("Fold Cross", VSSetting="color=outlining.square/Foreground,secondcolor=outlining.square/Background")]
 
60
                public AmbientColor FoldCross { get; private set; }
 
61
                
 
62
                [ColorDescription("Indentation Guide")] // not defined
 
63
                public AmbientColor IndentationGuide { get; private set; }
 
64
 
 
65
                [ColorDescription("Indicator Margin", VSSetting="color=Indicator Margin/Background")]
 
66
                public AmbientColor IndicatorMargin { get; private set; }
 
67
 
 
68
                [ColorDescription("Indicator Margin(Separator)", VSSetting="color=Indicator Margin/Background")]
 
69
                public AmbientColor IndicatorMarginSeparator { get; private set; }
 
70
 
 
71
                [ColorDescription("Tooltip Border")]
 
72
                public AmbientColor TooltipBorder { get; private set; }
 
73
 
 
74
                [ColorDescription("Tooltip Pager Top")]
 
75
                public AmbientColor TooltipPagerTop { get; private set; }
 
76
 
 
77
                [ColorDescription("Tooltip Pager Bottom")]
 
78
                public AmbientColor TooltipPagerBottom { get; private set; }
 
79
 
 
80
                [ColorDescription("Tooltip Pager Triangle")]
 
81
                public AmbientColor TooltipPagerTriangle { get; private set; }
 
82
                
 
83
                [ColorDescription("Tooltip Pager Text")]
 
84
                public AmbientColor TooltipPagerText { get; private set; }
 
85
 
 
86
                [ColorDescription("Bookmarks")]
 
87
                public AmbientColor Bookmarks { get; private set; }
 
88
 
 
89
                [ColorDescription("Underline(Error)", VSSetting="color=Syntax Error/Foreground")]
 
90
                public AmbientColor UnderlineError { get; private set; }
 
91
                
 
92
                [ColorDescription("Underline(Warning)", VSSetting="color=Warning/Foreground")]
 
93
                public AmbientColor UnderlineWarning { get; private set; }
 
94
 
 
95
                [ColorDescription("Underline(Suggestion)", VSSetting="color=Other Error/Foreground")]
 
96
                public AmbientColor UnderlineSuggestion { get; private set; }
 
97
 
 
98
                [ColorDescription("Underline(Hint)", VSSetting="color=Other Error/Foreground")]
 
99
                public AmbientColor UnderlineHint { get; private set; }
 
100
 
 
101
                [ColorDescription("Quick Diff(Dirty)")]
 
102
                public AmbientColor QuickDiffDirty { get; private set; }
 
103
 
 
104
                [ColorDescription("Quick Diff(Changed)")]
 
105
                public AmbientColor QuickDiffChanged { get; private set; }
 
106
 
 
107
                [ColorDescription("Brace Matching(Rectangle)", VSSetting="color=Brace Matching (Rectangle)/Background,secondcolor=Brace Matching (Rectangle)/Foreground")]
 
108
                public AmbientColor BraceMatchingRectangle { get; private set; }
 
109
                
 
110
                [ColorDescription("Usages(Rectangle)", VSSetting="color=MarkerFormatDefinition/HighlightedReference/Background,secondcolor=MarkerFormatDefinition/HighlightedReference/Background")]
 
111
                public AmbientColor UsagesRectangle { get; private set; }
 
112
 
 
113
                [ColorDescription("Breakpoint Marker")]
 
114
                public AmbientColor BreakpointMarker { get; private set; }
 
115
 
 
116
                [ColorDescription("Breakpoint Marker(Invalid)")]
 
117
                public AmbientColor InvalidBreakpointMarker { get; private set; }
 
118
 
 
119
                [ColorDescription("Breakpoint Marker(Disabled)")]
 
120
                public AmbientColor BreakpointMarkerDisabled { get; private set; }
 
121
 
 
122
                [ColorDescription("Debugger Current Line Marker")]
 
123
                public AmbientColor DebuggerCurrentLineMarker { get; private set; }
 
124
 
 
125
                [ColorDescription("Debugger Stack Line Marker")]
 
126
                public AmbientColor DebuggerStackLineMarker { get; private set; }
 
127
                
 
128
                [ColorDescription("Primary Link", VSSetting = "color=Refactoring Dependent Field/Background" )]
 
129
                public AmbientColor PrimaryTemplate { get; private set; }
 
130
                
 
131
                [ColorDescription("Primary Link(Highlighted)", VSSetting = "color=Refactoring Current Field/Background")]
 
132
                public AmbientColor PrimaryTemplateHighlighted { get; private set; }
 
133
 
 
134
                [ColorDescription("Secondary Link")] // not defined
 
135
                public AmbientColor SecondaryTemplate { get; private set; }
 
136
                
 
137
                [ColorDescription("Secondary Link(Highlighted)")] // not defined
 
138
                public AmbientColor SecondaryTemplateHighlighted { get; private set; }
 
139
 
 
140
                [ColorDescription("Current Line Marker", VSSetting = "color=CurrentLineActiveFormat/Background,secondcolor=CurrentLineActiveFormat/Foreground")]
 
141
                public AmbientColor LineMarker { get; private set; }
 
142
 
 
143
                [ColorDescription("Current Line Marker(Inactive)", VSSetting = "color=CurrentLineInactiveFormat/Background,secondcolor=CurrentLineInactiveFormat/Foreground")]
 
144
                public AmbientColor LineMarkerInactive { get; private set; }
 
145
 
 
146
                [ColorDescription("Column Ruler")] // not defined
 
147
                public AmbientColor Ruler { get; private set; }
 
148
 
 
149
                [ColorDescription("Completion Matching Substring")]
 
150
                public AmbientColor CompletionHighlight { get; private set; }
 
151
 
 
152
                [ColorDescription("Completion Border")]
 
153
                public AmbientColor CompletionBorder { get; private set; }
 
154
 
 
155
                [ColorDescription("Completion Border(Inactive)")]
 
156
                public AmbientColor CompletionInactiveBorder { get; private set; }
 
157
                
 
158
                [ColorDescription("Message Bubble Error")]
 
159
                public AmbientColor MessageBubbleError { get; private set; }
 
160
                
 
161
                [ColorDescription("Message Bubble Warning")]
 
162
                public AmbientColor MessageBubbleWarning { get; private set; }
 
163
                #endregion
 
164
 
 
165
                #region Text Colors
 
166
 
 
167
                [ColorDescription("Plain Text", VSSetting = "Plain Text")]
 
168
                public ChunkStyle PlainText { get; private set; }
 
169
 
 
170
                [ColorDescription("Selected Text", VSSetting = "Selected Text")]
 
171
                public ChunkStyle SelectedText { get; private set; }
 
172
 
 
173
                [ColorDescription("Selected Text(Inactive)", VSSetting = "Inactive Selected Text")]
 
174
                public ChunkStyle SelectedInactiveText { get; private set; }
 
175
 
 
176
                [ColorDescription("Collapsed Text", VSSetting = "Collapsible Text")]
 
177
                public ChunkStyle CollapsedText { get; private set; }
 
178
 
 
179
                [ColorDescription("Line Numbers", VSSetting = "Line Numbers")]
 
180
                public ChunkStyle LineNumbers { get; private set; }
 
181
 
 
182
                [ColorDescription("Punctuation", VSSetting = "Operator")]
 
183
                public ChunkStyle Punctuation { get; private set; }
 
184
 
 
185
                [ColorDescription("Punctuation(Brackets)", VSSetting = "Plain Text")]
 
186
                public ChunkStyle PunctuationForBrackets { get; private set; }
 
187
 
 
188
                [ColorDescription("Comment(Line)", VSSetting = "Comment")]
 
189
                public ChunkStyle CommentsSingleLine { get; private set; }
 
190
 
 
191
                [ColorDescription("Comment(Block)", VSSetting = "Comment")]
 
192
                public ChunkStyle CommentsMultiLine { get; private set; }
 
193
 
 
194
                [ColorDescription("Comment(Doc)", VSSetting = "XML Doc Comment")]
 
195
                public ChunkStyle CommentsForDocumentation { get; private set; }
 
196
                
 
197
                [ColorDescription("Comment(DocTag)", VSSetting = "XML Doc Tag")]
 
198
                public ChunkStyle CommentsForDocumentationTags { get; private set; }
 
199
                
 
200
                [ColorDescription("Comment Tag", VSSetting = "Comment")]
 
201
                public ChunkStyle CommentTags { get; private set; }
 
202
                
 
203
                [ColorDescription("Excluded Code", VSSetting = "Excluded Code")]
 
204
                public ChunkStyle ExcludedCode { get; private set; }
 
205
 
 
206
                [ColorDescription("String", VSSetting = "String")]
 
207
                public ChunkStyle String { get; private set; }
 
208
 
 
209
                [ColorDescription("String(Escape)", VSSetting = "String")]
 
210
                public ChunkStyle StringEscapeSequence { get; private set; }
 
211
 
 
212
                [ColorDescription("String(C# @ Verbatim)", VSSetting = "String(C# @ Verbatim)")]
 
213
                public ChunkStyle StringVerbatim { get; private set; }
 
214
 
 
215
                [ColorDescription("Number", VSSetting = "Number")]
 
216
                public ChunkStyle Number { get; private set; }
 
217
 
 
218
                [ColorDescription("Preprocessor", VSSetting = "Preprocessor Keyword")]
 
219
                public ChunkStyle Preprocessor { get; private set; }
 
220
 
 
221
                [ColorDescription("Xml Text", VSSetting = "XML Text")]
 
222
                public ChunkStyle XmlText { get; private set; }
 
223
 
 
224
                [ColorDescription("Xml Delimiter", VSSetting = "XML Delimiter")]
 
225
                public ChunkStyle XmlDelimiter { get; private set; }
 
226
 
 
227
                [ColorDescription("Xml Name", VSSetting ="XML Name")]
 
228
                public ChunkStyle XmlName { get; private set; }
 
229
 
 
230
                [ColorDescription("Xml Attribute", VSSetting = "XML Attribute")]
 
231
                public ChunkStyle XmlAttribute { get; private set; }
 
232
                
 
233
                [ColorDescription("Xml Attribute Quotes", VSSetting = "XML Attribute Quotes")]
 
234
                public ChunkStyle XmlAttributeQuotes { get; private set; }
 
235
                
 
236
                [ColorDescription("Xml Attribute Value", VSSetting = "XML Attribute Value")]
 
237
                public ChunkStyle XmlAttributeValue { get; private set; }
 
238
                
 
239
                [ColorDescription("Xml Comment", VSSetting = "XML Comment")]
 
240
                public ChunkStyle XmlComment { get; private set; }
 
241
 
 
242
                [ColorDescription("Xml CData Section", VSSetting = "XML CData Section")]
 
243
                public ChunkStyle XmlCDataSection { get; private set; }
 
244
 
 
245
                [ColorDescription("Tooltip Text")] // not defined in vs.net
 
246
                public ChunkStyle TooltipText { get; private set; }
 
247
 
 
248
                [ColorDescription("Completion Text")] //not defined in vs.net
 
249
                public ChunkStyle CompletionText { get; private set; }
 
250
 
 
251
                [ColorDescription("Completion Selected Text")] //not defined in vs.net
 
252
                public ChunkStyle CompletionSelectedText { get; private set; }
 
253
 
 
254
                [ColorDescription("Completion Selected Text(Inactive)")] //not defined in vs.net
 
255
                public ChunkStyle CompletionSelectedInactiveText { get; private set; }
 
256
 
 
257
                [ColorDescription("Keyword(Access)", VSSetting = "Keyword")]
 
258
                public ChunkStyle KeywordAccessors { get; private set; }
 
259
 
 
260
                [ColorDescription("Keyword(Type)", VSSetting = "Keyword")]
 
261
                public ChunkStyle KeywordTypes { get; private set; }
 
262
 
 
263
                [ColorDescription("Keyword(Operator)", VSSetting = "Keyword")]
 
264
                public ChunkStyle KeywordOperators { get; private set; }
 
265
 
 
266
                [ColorDescription("Keyword(Selection)", VSSetting = "Keyword")]
 
267
                public ChunkStyle KeywordSelection { get; private set; }
 
268
 
 
269
                [ColorDescription("Keyword(Iteration)", VSSetting = "Keyword")]
 
270
                public ChunkStyle KeywordIteration { get; private set; }
 
271
 
 
272
                [ColorDescription("Keyword(Jump)", VSSetting = "Keyword")]
 
273
                public ChunkStyle KeywordJump { get; private set; }
 
274
 
 
275
                [ColorDescription("Keyword(Context)", VSSetting = "Keyword")]
 
276
                public ChunkStyle KeywordContext { get; private set; }
 
277
 
 
278
                [ColorDescription("Keyword(Exception)", VSSetting = "Keyword")]
 
279
                public ChunkStyle KeywordException { get; private set; }
 
280
                
 
281
                [ColorDescription("Keyword(Modifiers)", VSSetting = "Keyword")]
 
282
                public ChunkStyle KeywordModifiers { get; private set; }
 
283
                
 
284
                [ColorDescription("Keyword(Constants)", VSSetting = "Keyword")]
 
285
                public ChunkStyle KeywordConstants { get; private set; }
 
286
                
 
287
                [ColorDescription("Keyword(Void)", VSSetting = "Keyword")]
 
288
                public ChunkStyle KeywordVoid { get; private set; }
 
289
                
 
290
                [ColorDescription("Keyword(Namespace)", VSSetting = "Keyword")]
 
291
                public ChunkStyle KeywordNamespace { get; private set; }
 
292
                
 
293
                [ColorDescription("Keyword(Property)", VSSetting = "Keyword")]
 
294
                public ChunkStyle KeywordProperty { get; private set; }
 
295
                
 
296
                [ColorDescription("Keyword(Declaration)", VSSetting = "Keyword")]
 
297
                public ChunkStyle KeywordDeclaration { get; private set; }
 
298
                
 
299
                [ColorDescription("Keyword(Parameter)", VSSetting = "Keyword")]
 
300
                public ChunkStyle KeywordParameter { get; private set; }
 
301
                
 
302
                [ColorDescription("Keyword(Operator Declaration)", VSSetting = "Keyword")]
 
303
                public ChunkStyle KeywordOperatorDeclaration { get; private set; }
 
304
                
 
305
                [ColorDescription("Keyword(Other)", VSSetting = "Keyword")]
 
306
                public ChunkStyle KeywordOther { get; private set; }
 
307
 
 
308
                [ColorDescription("User Types", VSSetting = "User Types")]
 
309
                public ChunkStyle UserTypes { get; private set; }
 
310
 
 
311
                [ColorDescription("User Types(Enums)", VSSetting = "User Types(Enums)")]
 
312
                public ChunkStyle UserTypesEnums { get; private set; }
 
313
                
 
314
                [ColorDescription("User Types(Interfaces)", VSSetting = "User Types(Interfaces)")]
 
315
                public ChunkStyle UserTypesInterfaces { get; private set; }
 
316
                
 
317
                [ColorDescription("User Types(Delegates)", VSSetting = "User Types(Delegates)")]
 
318
                public ChunkStyle UserTypesDelegatess { get; private set; }
 
319
                
 
320
                [ColorDescription("User Types(Value types)", VSSetting = "User Types(Value types)")]
 
321
                public ChunkStyle UserTypesValueTypes { get; private set; }
 
322
 
 
323
                [ColorDescription("User Types(Type parameters)", VSSetting = "User Types(Type parameters)")]
 
324
                public ChunkStyle UserTypesTypeParameters { get; private set; }
 
325
 
 
326
                [ColorDescription("User Field Usage", VSSetting = "Identifier")]
 
327
                public ChunkStyle UserFieldUsage { get; private set; }
 
328
                
 
329
                [ColorDescription("User Field Declaration", VSSetting = "Identifier")]
 
330
                public ChunkStyle UserFieldDeclaration { get; private set; }
 
331
                
 
332
                [ColorDescription("User Property Usage", VSSetting = "Identifier")]
 
333
                public ChunkStyle UserPropertyUsage { get; private set; }
 
334
                
 
335
                [ColorDescription("User Property Declaration", VSSetting = "Identifier")]
 
336
                public ChunkStyle UserPropertyDeclaration { get; private set; }
 
337
                
 
338
                [ColorDescription("User Event Usage", VSSetting = "Identifier")]
 
339
                public ChunkStyle UserEventUsage { get; private set; }
 
340
                
 
341
                [ColorDescription("User Event Declaration", VSSetting = "Identifier")]
 
342
                public ChunkStyle UserEventDeclaration { get; private set; }
 
343
                
 
344
                [ColorDescription("User Method Usage", VSSetting = "Identifier")]
 
345
                public ChunkStyle UserMethodUsage { get; private set; }
 
346
 
 
347
                [ColorDescription("User Method Declaration", VSSetting = "Identifier")]
 
348
                public ChunkStyle UserMethodDeclaration { get; private set; }
 
349
 
 
350
                [ColorDescription("User Parameter Usage", VSSetting = "Identifier")]
 
351
                public ChunkStyle UserParameterUsage { get; private set; }
 
352
                
 
353
                [ColorDescription("User Parameter Declaration", VSSetting = "Identifier")]
 
354
                public ChunkStyle UserParameterDeclaration { get; private set; }
 
355
 
 
356
                [ColorDescription("User Variable Usage", VSSetting = "Identifier")]
 
357
                public ChunkStyle UserVariableUsage { get; private set; }
 
358
                
 
359
                [ColorDescription("User Variable Declaration", VSSetting = "Identifier")]
 
360
                public ChunkStyle UserVariableDeclaration { get; private set; }
 
361
 
 
362
                [ColorDescription("Syntax Error", VSSetting = "Syntax Error")]
 
363
                public ChunkStyle SyntaxError { get; private set; }
 
364
 
 
365
                [ColorDescription("Breakpoint Text", VSSetting = "Breakpoint (Enabled)")]
 
366
                public ChunkStyle BreakpointText { get; private set; }
 
367
 
 
368
                [ColorDescription("Breakpoint Text(Invalid)", VSSetting = "Breakpoint (Disabled)")]
 
369
                public ChunkStyle BreakpointTextInvalid { get; private set; }
 
370
 
 
371
                [ColorDescription("Debugger Current Statement", VSSetting = "Current Statement")]
 
372
                public ChunkStyle DebuggerCurrentLine { get; private set; }
 
373
 
 
374
                [ColorDescription("Debugger Stack Line")] // not defined
 
375
                public ChunkStyle DebuggerStackLine { get; private set; }
 
376
 
 
377
 
 
378
                [ColorDescription("Diff Line(Added)")] //not defined
 
379
                public ChunkStyle DiffLineAdded { get; private set; }
 
380
 
 
381
                [ColorDescription("Diff Line(Removed)")] //not defined
 
382
                public ChunkStyle DiffLineRemoved { get; private set; }
 
383
 
 
384
                [ColorDescription("Diff Line(Changed)")] //not defined
 
385
                public ChunkStyle DiffLineChanged { get; private set; }
 
386
 
 
387
                [ColorDescription("Diff Header")] //not defined
 
388
                public ChunkStyle DiffHeader { get; private set; }
 
389
                
 
390
                [ColorDescription("Diff Header(Separator)")] //not defined
 
391
                public ChunkStyle DiffHeaderSeparator { get; private set; }
 
392
                
 
393
                [ColorDescription("Diff Header(Old)")] //not defined
 
394
                public ChunkStyle DiffHeaderOld { get; private set; }
 
395
                
 
396
                [ColorDescription("Diff Header(New)")] //not defined
 
397
                public ChunkStyle DiffHeaderNew { get; private set; }
 
398
 
 
399
                [ColorDescription("Diff Location")] //not defined
 
400
                public ChunkStyle DiffLocation { get; private set; }
 
401
 
 
402
                [ColorDescription("Html Attribute Name", VSSetting="HTML Attribute")]
 
403
                public ChunkStyle HtmlAttributeName { get; private set; }
 
404
                
 
405
                [ColorDescription("Html Attribute Value", VSSetting="HTML Attribute Value")]
 
406
                public ChunkStyle HtmlAttributeValue { get; private set; }
 
407
                
 
408
                [ColorDescription("Html Comment", VSSetting="HTML Comment")]
 
409
                public ChunkStyle HtmlComment { get; private set; }
 
410
                
 
411
                [ColorDescription("Html Element Name", VSSetting="HTML Element Name")]
 
412
                public ChunkStyle HtmlElementName { get; private set; }
 
413
                
 
414
                [ColorDescription("Html Entity", VSSetting="HTML Entity")]
 
415
                public ChunkStyle HtmlEntity { get; private set; }
 
416
                
 
417
                [ColorDescription("Html Operator", VSSetting="HTML Operator")]
 
418
                public ChunkStyle HtmlOperator { get; private set; }
 
419
                
 
420
                [ColorDescription("Html Server-Side Script", VSSetting="HTML Server-Side Script")]
 
421
                public ChunkStyle HtmlServerSideScript { get; private set; }
 
422
                
 
423
                [ColorDescription("Html Tag Delimiter", VSSetting="HTML Tag Delimiter")]
 
424
                public ChunkStyle HtmlTagDelimiter { get; private set; }
 
425
                
 
426
                [ColorDescription("Razor Code", VSSetting="Razor Code")]
 
427
                public ChunkStyle RazorCode { get; private set; }
 
428
 
 
429
 
 
430
                [ColorDescription("Css Comment", VSSetting="CSS Comment")]
 
431
                public ChunkStyle CssComment { get; private set; }
 
432
 
 
433
                [ColorDescription("Css Property Name", VSSetting="CSS Property Name")]
 
434
                public ChunkStyle CssPropertyName { get; private set; }
 
435
                
 
436
                [ColorDescription("Css Property Value", VSSetting="CSS Property Value")]
 
437
                public ChunkStyle CssPropertyValue { get; private set; }
 
438
                
 
439
                [ColorDescription("Css Selector", VSSetting="CSS Selector")]
 
440
                public ChunkStyle CssSelector { get; private set; }
 
441
                
 
442
                [ColorDescription("Css String Value", VSSetting="CSS String Value")]
 
443
                public ChunkStyle CssStringValue { get; private set; }
 
444
                
 
445
                [ColorDescription("Css Keyword", VSSetting="CSS Keyword")]
 
446
                public ChunkStyle CssKeyword { get; private set; }
 
447
 
 
448
                [ColorDescription("Script Comment", VSSetting="Script Comment")]
 
449
                public ChunkStyle ScriptComment { get; private set; }
 
450
                
 
451
                [ColorDescription("Script Identifier", VSSetting="Script Identifier")]
 
452
                public ChunkStyle ScriptIdentifier { get; private set; }
 
453
                
 
454
                [ColorDescription("Script Keyword", VSSetting="Script Keyword")]
 
455
                public ChunkStyle ScriptKeyword { get; private set; }
 
456
                
 
457
                [ColorDescription("Script Number", VSSetting="Script Number")]
 
458
                public ChunkStyle ScriptNumber { get; private set; }
 
459
                
 
460
                [ColorDescription("Script Operator", VSSetting="Script Operator")]
 
461
                public ChunkStyle ScriptOperator { get; private set; }
 
462
 
 
463
                [ColorDescription("Script String", VSSetting="Script String")]
 
464
                public ChunkStyle ScriptString { get; private set; }
 
465
 
 
466
 
 
467
                #endregion
 
468
 
 
469
                public class PropertyDecsription
 
470
                {
 
471
                        public readonly PropertyInfo Info;
 
472
                        public readonly ColorDescriptionAttribute Attribute;
 
473
 
 
474
                        public PropertyDecsription (PropertyInfo info, ColorDescriptionAttribute attribute)
 
475
                        {
 
476
                                this.Info = info;
 
477
                                this.Attribute = attribute;
 
478
                        }
 
479
                }
 
480
 
 
481
                static Dictionary<string, PropertyDecsription> textColors = new Dictionary<string, PropertyDecsription> ();
 
482
 
 
483
                public static IEnumerable<PropertyDecsription> TextColors {
 
484
                        get {
 
485
                                return textColors.Values;
 
486
                        }
 
487
                }
 
488
 
 
489
                static Dictionary<string, PropertyDecsription> ambientColors = new Dictionary<string, PropertyDecsription> ();
 
490
 
 
491
                public static IEnumerable<PropertyDecsription> AmbientColors {
 
492
                        get {
 
493
                                return ambientColors.Values;
 
494
                        }
 
495
                }
 
496
 
 
497
                static ColorScheme ()
 
498
                {
 
499
                        foreach (var property in typeof(ColorScheme).GetProperties ()) {
 
500
                                var description = property.GetCustomAttributes (false).FirstOrDefault (p => p is ColorDescriptionAttribute) as ColorDescriptionAttribute;
 
501
                                if (description == null)
 
502
                                        continue;
 
503
                                if (property.PropertyType == typeof (ChunkStyle)) {
 
504
                                        textColors.Add (description.Name, new PropertyDecsription (property, description));
 
505
                                } else {
 
506
                                        ambientColors.Add (description.Name, new PropertyDecsription (property, description));
 
507
                                }
 
508
                        }
 
509
                }
 
510
 
 
511
                public ColorScheme Clone ()
 
512
                {
 
513
                        var result = new ColorScheme () {
 
514
                                Name = this.Name,
 
515
                                BaseScheme = this.BaseScheme,
 
516
                                Originator = this.Originator,
 
517
                                Description = this.Description
 
518
                        };
 
519
                        result.CopyValues (this);
 
520
                        return result;
 
521
                }
 
522
                
 
523
                static Cairo.Color ParseColor (string value)
 
524
                {
 
525
                        return HslColor.Parse (value);
 
526
                }
 
527
 
 
528
                public static Cairo.Color ParsePaletteColor (Dictionary<string, Cairo.Color> palette, string value)
 
529
                {
 
530
                        Cairo.Color result;
 
531
                        if (palette.TryGetValue (value, out result))
 
532
                                return result;
 
533
                        return ParseColor (value);
642
534
                }
643
535
 
644
536
                public ChunkStyle GetChunkStyle (Chunk chunk)
645
537
                {
646
 
                        if (chunk == null)
647
 
                                throw new ArgumentNullException ("chunk");
648
538
                        return GetChunkStyle (chunk.Style);
649
539
                }
650
 
                
651
 
                public ChunkStyle GetChunkStyle (string name)
652
 
                {
653
 
                        if (name == null)
654
 
                                return GetDefaultChunkStyle ();
655
 
                        ChunkStyle style;
656
 
                        if (styleLookupTable.TryGetValue (name, out style))
657
 
                                return style;
658
 
                        
659
 
                        int dotIndex = name.LastIndexOf ('.');
660
 
                        string fallbackName = name;
661
 
                        while (dotIndex > 1) {
662
 
                                fallbackName = fallbackName.Substring (0, dotIndex);
663
 
                                if (styleLookupTable.TryGetValue (fallbackName, out style)) {
664
 
                                        styleLookupTable[name] = style;
665
 
                                //      Console.WriteLine ("Chunk style {0} fell back to {1}", name, fallbackName);
666
 
                                        return style;
667
 
                                }
668
 
                                dotIndex = fallbackName.LastIndexOf ('.');
669
 
                        }
670
 
                        
671
 
                //      Console.WriteLine ("Chunk style {0} fell back to default", name);
672
 
                        return GetDefaultChunkStyle ();
673
 
                }
674
 
                
675
 
                public void SetChunkStyle (string name, string weight, string foreColor, string backColor)
676
 
                {
677
 
                        var color = !string.IsNullOrEmpty (foreColor) ? this.GetColorFromString (foreColor) : new Cairo.Color (0, 0, 0);
678
 
                        var bgColor = !string.IsNullOrEmpty (backColor) ? this.GetColorFromString (backColor) : new Cairo.Color (0, 0, 0);
679
 
                        var properties = ChunkProperties.None;
680
 
                        if (weight != null) {
681
 
                                if (weight.ToUpper ().IndexOf ("BOLD") >= 0)
682
 
                                        properties |= ChunkProperties.Bold;
683
 
                                if (weight.ToUpper ().IndexOf ("ITALIC") >= 0)
684
 
                                        properties |= ChunkProperties.Italic;
685
 
                                if (weight.ToUpper ().IndexOf ("UNDERLINE") >= 0)
686
 
                                        properties |= ChunkProperties.Underline;
687
 
                        }
688
 
                        SetStyle (name, !string.IsNullOrEmpty (backColor) ? new ChunkStyle (color, bgColor, properties) : new ChunkStyle (color, properties));
689
 
                }
690
 
                
691
 
                public void SetChunkStyle (string name, ChunkStyle style)
692
 
                {
693
 
                        SetStyle (name, style);
694
 
                }
695
 
                
696
 
                static int GetNumber (string str, int offset)
697
 
                {
698
 
                        return int.Parse (str.Substring (offset, 2), NumberStyles.HexNumber);
699
 
                }
700
 
                
701
 
                public Cairo.Color GetColorFromString (string colorString)
702
 
                {
703
 
                        string refColorString;
704
 
                        if (customPalette.TryGetValue (colorString, out refColorString))
705
 
                                return this.GetColorFromString (refColorString);
706
 
                        ChunkStyle style;
707
 
                        if (styleLookupTable.TryGetValue (colorString, out style))
708
 
                                return style.CairoColor;
709
 
                        if (colorString.Length > 0 && colorString[0] == '#') {
710
 
                                if (colorString.Length == 9) {
711
 
                                        // #AARRGGBB
712
 
                                        return new Cairo.Color ( GetNumber (colorString, 3) / 255.0, GetNumber (colorString, 5) / 255.0, GetNumber (colorString, 7) / 255.0, GetNumber (colorString, 1) / 255.0);
713
 
                                }
714
 
                                if (colorString.Length == 7) {
715
 
                                        // #RRGGBB
716
 
                                        return new Cairo.Color ( GetNumber (colorString, 1) / 255.0, GetNumber (colorString, 3) / 255.0, GetNumber (colorString, 5) / 255.0);
717
 
                                }
718
 
                                throw new ArgumentException ("colorString", "colorString must either be #RRGGBB (length 7) or #AARRGGBB (length 9) your string " + colorString + " is invalid because it has a length of " + colorString.Length);
719
 
                        } 
720
 
                        var color = new Gdk.Color ();
721
 
                        if (Gdk.Color.Parse (colorString, ref color))
722
 
                                return (Cairo.Color)((HslColor)color);
723
 
                        throw new Exception ("Failed to parse color or find named color '" + colorString + "'");
724
 
                }
725
 
                
726
 
                public const string NameAttribute = "name";
727
 
                
728
 
                static void ReadStyleTree (XmlReader reader, ColorScheme result, string curName, string curWeight, string curColor, string curBgColor)
729
 
                {
730
 
                        string name    = reader.GetAttribute ("name"); 
731
 
                        string weight  = reader.GetAttribute ("weight") ?? curWeight;
732
 
                        string color   = reader.GetAttribute ("color");
733
 
                        string bgColor = reader.GetAttribute ("bgColor");
734
 
                        string fullName;
735
 
                        if (String.IsNullOrEmpty (curName)) {
736
 
                                fullName = name;
737
 
                        } else {
738
 
                                fullName = curName + "." + name;
739
 
                        }
740
 
                        if (!String.IsNullOrEmpty (color)) {
741
 
                                result.SetChunkStyle (fullName, weight, color, bgColor);
742
 
                        }
743
 
                        XmlReadHelper.ReadList (reader, "Style", delegate () {
744
 
                                switch (reader.LocalName) {
745
 
                                case "Style":
746
 
                                        ReadStyleTree (reader, result, fullName, weight, color, bgColor);
747
 
                                        return true;
748
 
                                }
749
 
                                return false;
750
 
                        });
751
 
                }
752
 
                
753
 
                public static ColorScheme LoadFrom (XmlReader reader)
 
540
        
 
541
                public ChunkStyle GetChunkStyle (string color)
 
542
                {
 
543
                        if (color == null)
 
544
                                return GetChunkStyle ("Plain Text");
 
545
                        PropertyDecsription val;
 
546
                        if (!textColors.TryGetValue (color, out val)) {
 
547
                                Console.WriteLine ("Chunk style : " + color + " is undefined.");
 
548
                                return null;
 
549
                        }
 
550
                        return val.Info.GetValue (this, null) as ChunkStyle;
 
551
                }
 
552
 
 
553
                void CopyValues (ColorScheme baseScheme)
 
554
                {
 
555
                        foreach (var color in textColors.Values)
 
556
                                color.Info.SetValue (this, color.Info.GetValue (baseScheme, null), null);
 
557
                        foreach (var color in ambientColors.Values)
 
558
                                color.Info.SetValue (this, color.Info.GetValue (baseScheme, null), null);
 
559
                }
 
560
 
 
561
                public static ColorScheme LoadFrom (Stream stream)
754
562
                {
755
563
                        var result = new ColorScheme ();
756
 
                        XmlReadHelper.ReadList (reader, "EditorStyle", delegate () {
757
 
                                switch (reader.LocalName) {
758
 
                                case "EditorStyle":
759
 
                                        result.Name = reader.GetAttribute (NameAttribute);
760
 
                                        result.Description = reader.GetAttribute ("_description");
761
 
                                        return true;
762
 
                                case "Color":
763
 
                                        result.customPalette [reader.GetAttribute ("name")] = reader.GetAttribute ("value");
764
 
                                        return true;
765
 
                                case "Style":
766
 
                                        ReadStyleTree (reader, result, null, null, null, null);
767
 
                                        return true;
768
 
                                }
769
 
                                return false;
770
 
                        });
771
 
                        result.GetChunkStyle (DefaultString).ChunkProperties |= ChunkProperties.TransparentBackground;
 
564
                        var reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader (stream, new System.Xml.XmlDictionaryReaderQuotas ());
 
565
 
 
566
                        var root = XElement.Load(reader);
 
567
                        
 
568
                        // The fields we'd like to extract
 
569
                        result.Name = root.XPathSelectElement("name").Value;
 
570
 
 
571
                        if (result.Name != "Default")
 
572
                                result.CopyValues (SyntaxModeService.DefaultColorStyle);
 
573
 
 
574
                        var version = Version.Parse (root.XPathSelectElement("version").Value);
 
575
                        if (version.Major != 1)
 
576
                                return null;
 
577
                        var el = root.XPathSelectElement ("description");
 
578
                        if (el != null)
 
579
                                result.Description = el.Value;
 
580
                        el = root.XPathSelectElement ("originator");
 
581
                        if (el != null)
 
582
                                result.Originator = el.Value;
 
583
                        el = root.XPathSelectElement ("baseScheme");
 
584
                        if (el != null)
 
585
                                result.BaseScheme = el.Value;
 
586
 
 
587
                        if (result.BaseScheme != null) {
 
588
                                var baseScheme = SyntaxModeService.GetColorStyle (result.BaseScheme);
 
589
                                if (baseScheme != null)
 
590
                                        result.CopyValues (baseScheme);
 
591
                        }
 
592
 
 
593
                        var palette = new Dictionary<string, Cairo.Color> ();
 
594
                        foreach (var color in root.XPathSelectElements("palette/*")) {
 
595
                                var name = color.XPathSelectElement ("name").Value;
 
596
                                if (palette.ContainsKey (name))
 
597
                                        throw new InvalidDataException ("Duplicate palette color definition for: " + name);
 
598
                                palette.Add (
 
599
                                        name,
 
600
                                        ParseColor (color.XPathSelectElement ("value").Value)
 
601
                                );
 
602
                        }
 
603
 
 
604
                        foreach (var colorElement in root.XPathSelectElements("//colors/*")) {
 
605
                                var color = AmbientColor.Create (colorElement, palette);
 
606
                                PropertyDecsription info;
 
607
                                if (!ambientColors.TryGetValue (color.Name, out info)) {
 
608
                                        Console.WriteLine ("Ambient color:" + color.Name + " not found.");
 
609
                                        continue;
 
610
                                }
 
611
                                info.Info.SetValue (result, color, null);
 
612
                        }
 
613
 
 
614
                        foreach (var textColorElement in root.XPathSelectElements("//text/*")) {
 
615
                                var color = ChunkStyle.Create (textColorElement, palette);
 
616
                                PropertyDecsription info;
 
617
                                if (!textColors.TryGetValue (color.Name, out info)) {
 
618
                                        Console.WriteLine ("Text color:" + color.Name + " not found.");
 
619
                                        continue;
 
620
                                }
 
621
                                info.Info.SetValue (result, color, null);
 
622
                        }
 
623
 
 
624
                        // Check scheme
 
625
                        bool valid = true;
 
626
                        foreach (var color in textColors.Values) {
 
627
                                if (color.Info.GetValue (result, null) == null) {
 
628
                                        Console.WriteLine (color.Attribute.Name + " == null");
 
629
                                        valid = false;
 
630
                                }
 
631
                        }
 
632
                        foreach (var color in ambientColors.Values) {
 
633
                                if (color.Info.GetValue (result, null) == null) {
 
634
                                        Console.WriteLine (color.Attribute.Name + " == null");
 
635
                                        valid = false;
 
636
                                }
 
637
                        }
 
638
                        if (!valid)
 
639
                                throw new InvalidDataException ("Scheme " + result.Name + " is not valid.");
772
640
                        return result;
773
641
                }
774
 
                
775
 
                static string GetColorString (double c)
776
 
                {
777
 
                        int conv = (int)(c * 255.0);
778
 
                        return string.Format ("{0:X2}", conv);
779
 
                }
780
 
                
781
 
                static string GetColorString (Cairo.Color cairoColor)
782
 
                {
783
 
                        var result = new System.Text.StringBuilder ();
784
 
                        result.Append ("#");
785
 
                        if (cairoColor.A != 1.0)
786
 
                                result.Append (GetColorString (cairoColor.A));
787
 
                        result.Append (GetColorString (cairoColor.R));
788
 
                        result.Append (GetColorString (cairoColor.G));
789
 
                        result.Append (GetColorString (cairoColor.B));
790
 
                        
791
 
                        return result.ToString ();
792
 
                }
793
 
                
 
642
 
 
643
                public static string ColorToMarkup (Cairo.Color color)
 
644
                {
 
645
                        var r = (byte)(color.R * byte.MaxValue);
 
646
                        var g = (byte)(color.G * byte.MaxValue);
 
647
                        var b = (byte)(color.B * byte.MaxValue);
 
648
                        var a = (byte)(color.A * byte.MaxValue);
 
649
 
 
650
                        if (a == 255)
 
651
                                return string.Format ("#{0:X2}{1:X2}{2:X2}", r, g, b);
 
652
                        return string.Format ("#{0:X2}{1:X2}{2:X2}{3:X2}", r, g, b, a);
 
653
                }
 
654
 
 
655
 
794
656
                public void Save (string fileName)
795
657
                {
796
 
                        var writer = new XmlTextWriter (fileName, System.Text.UTF8Encoding.UTF8);
797
 
                        writer.Formatting = Formatting.Indented;
798
 
                        
799
 
                        writer.WriteStartElement ("EditorStyle");
800
 
                        writer.WriteAttributeString (NameAttribute, Name);
801
 
                        writer.WriteAttributeString ("_description", Description);
802
 
                        
803
 
                        foreach (var style in new Dictionary<string, ChunkStyle> (this.styleLookupTable)) {
804
 
                                writer.WriteStartElement ("Style");
805
 
                                writer.WriteAttributeString ("name", style.Key);
806
 
                                writer.WriteAttributeString ("color", GetColorString (style.Value.CairoColor));
807
 
                                if (style.Value.GotBackgroundColorAssigned)
808
 
                                        writer.WriteAttributeString ("bgColor", GetColorString (style.Value.CairoBackgroundColor));
809
 
                                if ((style.Value.ChunkProperties & (ChunkProperties.Bold | ChunkProperties.Italic)) != 0)
810
 
                                        writer.WriteAttributeString ("weight", style.Value.ChunkProperties.ToString ());
811
 
                                writer.WriteEndElement ();
812
 
                        }
813
 
                        
814
 
                        writer.WriteEndElement ();
815
 
                        writer.Close ();
816
 
                }
817
 
                
818
 
                public ColorScheme Clone ()
819
 
                {
820
 
                        ColorScheme clone = (ColorScheme)MemberwiseClone ();
821
 
                        clone.styleLookupTable = new Dictionary<string, ChunkStyle> (styleLookupTable);
822
 
                        return clone;
823
 
                }
824
 
                
825
 
                public virtual void UpdateFromGtkStyle (Gtk.Style style)
826
 
                {
827
 
                }
 
658
                        using (var writer = new StreamWriter (fileName)) {
 
659
                                writer.WriteLine ("{");
 
660
                                writer.WriteLine ("\t\"name\":\"{0}\",", Name);
 
661
                                writer.WriteLine ("\t\"version\":\"1.0\",");
 
662
                                if (!string.IsNullOrEmpty (Description))
 
663
                                        writer.WriteLine ("\t\"description\":\"{0}\",", Description);
 
664
                                if (!string.IsNullOrEmpty (Originator))
 
665
                                        writer.WriteLine ("\t\"originator\":\"{0}\",", Originator);
 
666
                                if (!string.IsNullOrEmpty (BaseScheme))
 
667
                                        writer.WriteLine ("\t\"baseScheme\":\"{0}\",", BaseScheme);
 
668
 
 
669
                                var baseStyle = SyntaxModeService.GetColorStyle (BaseScheme ?? "Default");
 
670
 
 
671
                                writer.WriteLine ("\t\"colors\":[");
 
672
                                bool first = true;
 
673
                                foreach (var ambient in ambientColors) {
 
674
                                        var thisValue = ambient.Value.Info.GetValue (this, null) as AmbientColor;
 
675
                                        if (thisValue == null)
 
676
                                                continue;
 
677
                                        var baseValue = ambient.Value.Info.GetValue (baseStyle, null) as AmbientColor;
 
678
                                        if (thisValue.Equals (baseValue)) {
 
679
                                                continue;
 
680
                                        }
 
681
 
 
682
                                        var colorString = new StringBuilder ();
 
683
                                        foreach (var color in thisValue.Colors) {
 
684
                                                if (colorString.Length > 0)
 
685
                                                        colorString.Append (", ");
 
686
                                                colorString.Append (string.Format ("\"{0}\":\"{1}\"", color.Item1, ColorToMarkup (color.Item2)));
 
687
                                        }
 
688
                                        if (colorString.Length == 0) {
 
689
                                                Console.WriteLine ("Invalid ambient color :" + thisValue);
 
690
                                                continue;
 
691
                                        }
 
692
                                        if (!first) {
 
693
                                                writer.WriteLine (",");
 
694
                                        } else {
 
695
                                                first = false;
 
696
                                        }
 
697
                                        writer.Write ("\t\t{");
 
698
                                        writer.Write ("\"name\": \"{0}\", {1}", ambient.Value.Attribute.Name, colorString);
 
699
                                        writer.Write (" }");
 
700
                                }
 
701
 
 
702
                                writer.WriteLine ("\t],");
 
703
                                first = true;
 
704
                                writer.WriteLine ("\t\"text\":[");
 
705
                                foreach (var textColor in textColors) {
 
706
                                        var thisValue = textColor.Value.Info.GetValue (this, null) as ChunkStyle;
 
707
                                        if (thisValue == null)
 
708
                                                continue;
 
709
                                        var baseValue = textColor.Value.Info.GetValue (baseStyle, null) as ChunkStyle;
 
710
                                        if (thisValue.Equals (baseValue)) {
 
711
                                                continue;
 
712
                                        }
 
713
                                        var colorString = new StringBuilder ();
 
714
                                        if (!thisValue.TransparentForeground)
 
715
                                                colorString.Append (string.Format ("\"fore\":\"{0}\"", ColorToMarkup (thisValue.Foreground)));
 
716
                                        if (!thisValue.TransparentBackground) {
 
717
                                                if (colorString.Length > 0)
 
718
                                                        colorString.Append (", ");
 
719
                                                colorString.Append (string.Format ("\"back\":\"{0}\"", ColorToMarkup (thisValue.Background)));
 
720
                                        }
 
721
                                        if (thisValue.FontWeight != FontWeight.Normal) {
 
722
                                                if (colorString.Length > 0)
 
723
                                                        colorString.Append (", ");
 
724
                                                colorString.Append (string.Format ("\"weight\":\"{0}\"", thisValue.FontWeight));
 
725
                                        }
 
726
                                        if (thisValue.FontStyle != FontStyle.Normal) {
 
727
                                                if (colorString.Length > 0)
 
728
                                                        colorString.Append (", ");
 
729
                                                colorString.Append (string.Format ("\"style\":\"{0}\"", thisValue.FontStyle));
 
730
                                        }
 
731
                                        if (!first) {
 
732
                                                writer.WriteLine (",");
 
733
                                        } else {
 
734
                                                first = false;
 
735
                                        }
 
736
                                        writer.Write ("\t\t{");
 
737
                                        if (colorString.Length == 0) {
 
738
                                                writer.Write ("\"name\": \"{0}\"", textColor.Value.Attribute.Name);
 
739
                                        } else {
 
740
                                                writer.Write ("\"name\": \"{0}\", {1}", textColor.Value.Attribute.Name, colorString);
 
741
                                        }
 
742
                                        writer.Write (" }");
 
743
                                }
 
744
                                writer.WriteLine ();
 
745
                                writer.WriteLine ("\t]");
 
746
 
 
747
                                writer.WriteLine ("}");
 
748
                        }
 
749
                }
 
750
 
 
751
                internal static Cairo.Color ImportVsColor (string colorString)
 
752
                {
 
753
                        if (colorString == "0x02000000")
 
754
                                return new Cairo.Color (0, 0, 0, 0);
 
755
                        string color = "#" + colorString.Substring (8, 2) + colorString.Substring (6, 2) + colorString.Substring (4, 2);
 
756
                        return HslColor.Parse (color);
 
757
                }
 
758
 
 
759
                public class VSSettingColor
 
760
                {
 
761
                        public string Name { get; private set; }
 
762
                        public string Foreground { get; private set; }
 
763
                        public string Background { get; private set; }
 
764
                        public bool BoldFont { get; private set; }
 
765
 
 
766
                        public static VSSettingColor Create (XmlReader reader)
 
767
                        {
 
768
                                return new VSSettingColor {
 
769
                                        Name = reader.GetAttribute ("Name"),
 
770
                                        Foreground = reader.GetAttribute ("Foreground"),
 
771
                                        Background = reader.GetAttribute ("Background"),
 
772
                                        BoldFont = reader.GetAttribute ("BoldFont") == "Yes"
 
773
                                };
 
774
                        }
 
775
                }
 
776
 
 
777
                public static Cairo.Color AlphaBlend (Cairo.Color fore, Cairo.Color back, double alpha)
 
778
                {
 
779
                        return new Cairo.Color (
 
780
                                (1.0 - alpha) * back.R + alpha * fore.R,
 
781
                                (1.0 - alpha) * back.G + alpha * fore.G,
 
782
                                (1.0 - alpha) * back.B + alpha * fore.B);
 
783
                }
 
784
 
 
785
                public static ColorScheme Import (string fileName, Stream stream)
 
786
                {
 
787
                        var result = new ColorScheme ();
 
788
                        result.Name = Path.GetFileNameWithoutExtension (fileName);
 
789
                        result.Description = "Imported color scheme";
 
790
                        result.Originator = "Imported from " + fileName;
 
791
 
 
792
                        var colors = new Dictionary<string, VSSettingColor> ();
 
793
                        using (var reader = XmlReader.Create (stream)) {
 
794
                                while (reader.Read ()) {
 
795
                                        if (reader.LocalName == "Item") {
 
796
                                                var color = VSSettingColor.Create (reader);
 
797
                                                if (colors.ContainsKey (color.Name)) {
 
798
                                                        Console.WriteLine ("Warning: {0} is defined twice in vssettings.", color.Name);
 
799
                                                        continue;
 
800
                                                }
 
801
                                                colors[color.Name] = color;
 
802
                                        }
 
803
                                }
 
804
                        }
 
805
 
 
806
 
 
807
                        HashSet<string> importedAmbientColors = new HashSet<string> ();
 
808
                        // convert ambient colors
 
809
                        foreach (var ambient in ambientColors.Values) {
 
810
                                if (!string.IsNullOrEmpty (ambient.Attribute.VSSetting)) {
 
811
                                        var import = AmbientColor.Import (colors, ambient.Attribute.VSSetting);
 
812
                                        if (import != null) {
 
813
                                                importedAmbientColors.Add (import.Name);
 
814
                                                ambient.Info.SetValue (result, import, null);
 
815
                                                continue;
 
816
                                        }
 
817
                                }
 
818
                        }
 
819
 
 
820
                        // convert text colors
 
821
                        foreach (var vsc in colors.Values) {
 
822
                                bool found = false;
 
823
                                foreach (var color in textColors) {
 
824
                                        if (color.Value.Attribute.VSSetting == null)
 
825
                                                continue;
 
826
                                        var split = color.Value.Attribute.VSSetting.Split ('?');
 
827
                                        foreach (var s in split) {
 
828
                                                if (s == vsc.Name) {
 
829
                                                /*      if (vsc.Foreground == "0x02000000" && vsc.Background == "0x02000000") {
 
830
                                                                color.Value.Info.SetValue (result, result.PlainText, null);
 
831
                                                                found = true;
 
832
                                                                continue;
 
833
                                                        }*/
 
834
                                                        var textColor = ChunkStyle.Import (color.Value.Attribute.Name, vsc);
 
835
                                                        if (textColor != null) {
 
836
                                                                color.Value.Info.SetValue (result, textColor, null);
 
837
                                                                found = true;
 
838
                                                        }
 
839
                                                }
 
840
                                        }
 
841
                                }
 
842
                                if (!found && !importedAmbientColors.Contains (vsc.Name))
 
843
                                        Console.WriteLine (vsc.Name + " not imported!");
 
844
                        }
 
845
 
 
846
                        result.IndentationGuide = new AmbientColor ();
 
847
                        result.IndentationGuide.Colors.Add (Tuple.Create ("color", AlphaBlend (result.PlainText.Foreground, result.PlainText.Background, 0.3)));
 
848
 
 
849
                        result.TooltipText = result.PlainText.Clone ();
 
850
                        var h = (HslColor)result.TooltipText.Background;
 
851
                        h.L += 0.01;
 
852
                        result.TooltipText.Background = h;
 
853
 
 
854
                        result.TooltipPagerTop = new AmbientColor ();
 
855
                        result.TooltipPagerTop.Colors.Add (Tuple.Create ("color", result.TooltipText.Background));
 
856
 
 
857
                        result.TooltipPagerBottom = new AmbientColor ();
 
858
                        result.TooltipPagerBottom.Colors.Add (Tuple.Create ("color", result.TooltipText.Background));
 
859
                        
 
860
                        result.TooltipPagerTriangle = new AmbientColor ();
 
861
                        result.TooltipPagerTriangle.Colors.Add (Tuple.Create ("color", AlphaBlend (result.PlainText.Foreground, result.PlainText.Background, 0.8)));
 
862
 
 
863
                        result.TooltipBorder = new AmbientColor ();
 
864
                        result.TooltipBorder.Colors.Add (Tuple.Create ("color", AlphaBlend (result.PlainText.Foreground, result.PlainText.Background, 0.5)));
 
865
 
 
866
                        var defaultStyle = SyntaxModeService.GetColorStyle (HslColor.Brightness (result.PlainText.Background) < 0.5 ? "Monokai" : "Default");
 
867
 
 
868
                        foreach (var color in textColors.Values) {
 
869
                                if (color.Info.GetValue (result, null) == null)
 
870
                                        color.Info.SetValue (result, color.Info.GetValue (defaultStyle, null), null);
 
871
                        }
 
872
                        foreach (var color in ambientColors.Values) {
 
873
                                if (color.Info.GetValue (result, null) == null) 
 
874
                                        color.Info.SetValue (result, color.Info.GetValue (defaultStyle, null), null);
 
875
                        }
 
876
                        if (result.PlainText.TransparentForeground)
 
877
                                result.PlainText.Foreground = new Cairo.Color (0, 0, 0);
 
878
                        return result;
 
879
                }
 
880
 
 
881
                public Cairo.Color GetForeground (ChunkStyle chunkStyle)
 
882
                {
 
883
                        if (chunkStyle.TransparentForeground)
 
884
                                return PlainText.Foreground;
 
885
                        return chunkStyle.Foreground;
 
886
                }
 
887
 
828
888
        }
829
889
}