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
29
28
using System.Collections.Generic;
30
using System.Xml.Linq;
31
using System.Xml.XPath;
32
using System.Reflection;
32
using System.Globalization;
34
37
namespace Mono.TextEditor.Highlighting
36
39
public class ColorScheme
38
public static ColorScheme Empty = new ColorScheme ();
40
Dictionary<string, ChunkStyle> styleLookupTable = new Dictionary<string, ChunkStyle> ();
41
Dictionary<string, string> customPalette = new Dictionary<string, string> ();
43
public IEnumerable<string> ColorNames {
45
return styleLookupTable.Keys;
49
public Cairo.Color GetColorFromDefinition (string colorName)
51
return this.GetChunkStyle (colorName).CairoColor;
56
public const string DefaultString = "text";
57
public virtual ChunkStyle Default {
59
return GetChunkStyle (DefaultString);
63
public const string LineNumberString = "linenumber";
64
public virtual ChunkStyle LineNumber {
66
return GetChunkStyle (LineNumberString);
70
public const string LineNumberFgHighlightedString = "linenumber.highlight";
71
public virtual Cairo.Color LineNumberFgHighlighted {
73
return GetColorFromDefinition (LineNumberFgHighlightedString);
77
public const string IconBarBgString = "iconbar";
78
public virtual Cairo.Color IconBarBg {
80
return GetColorFromDefinition (IconBarBgString);
84
public const string IconBarSeperatorString = "iconbar.separator";
85
public virtual Cairo.Color IconBarSeperator {
87
return GetColorFromDefinition (IconBarSeperatorString);
91
public const string FoldLineString = "fold";
92
public virtual ChunkStyle FoldLine {
94
return GetChunkStyle (FoldLineString);
98
public const string FoldLineHighlightedString = "fold.highlight";
99
public virtual Cairo.Color FoldLineHighlighted {
101
return GetColorFromDefinition (FoldLineHighlightedString);
105
public const string LineChangedBgString = "marker.line.changed";
106
public virtual Cairo.Color LineChangedBg {
108
return GetColorFromDefinition (LineChangedBgString);
112
public const string LineDirtyBgString = "marker.line.dirty";
113
public virtual Cairo.Color LineDirtyBg {
115
return GetColorFromDefinition (LineDirtyBgString);
119
public const string SelectionString = "text.selection";
120
public virtual ChunkStyle Selection {
122
return GetChunkStyle (SelectionString);
126
public const string InactiveSelectionString = "text.selection.inactive";
127
public virtual ChunkStyle InactiveSelection {
129
return GetChunkStyle (InactiveSelectionString);
133
public const string LineMarkerString = "marker.line";
134
public virtual Cairo.Color LineMarker {
136
return GetColorFromDefinition (LineMarkerString);
140
public const string RulerString = "marker.ruler";
141
public virtual Cairo.Color Ruler {
143
return GetColorFromDefinition (RulerString);
147
public const string WhitespaceMarkerString = "marker.whitespace";
148
public virtual Cairo.Color WhitespaceMarker {
150
return GetColorFromDefinition (WhitespaceMarkerString);
154
public const string EolWhitespaceMarkerString = "marker.whitespace.eol";
155
public virtual Cairo.Color EolWhitespaceMarker {
157
return GetColorFromDefinition (EolWhitespaceMarkerString);
161
public const string InvalidLineMarkerString = "marker.invalidline";
162
public virtual Cairo.Color InvalidLineMarker {
164
return GetColorFromDefinition (InvalidLineMarkerString);
168
public const string FoldToggleMarkerString = "fold.togglemarker";
169
public virtual Cairo.Color FoldToggleMarker {
171
return GetColorFromDefinition (FoldToggleMarkerString);
175
public const string BracketHighlightRectangleString = "marker.bracket";
177
public virtual ChunkStyle BracketHighlightRectangle {
179
return GetChunkStyle (BracketHighlightRectangleString);
183
public const string UsagesHighlightRectangleString = "marker.usages";
184
public virtual ChunkStyle UsagesHighlightRectangle {
186
return GetChunkStyle (UsagesHighlightRectangleString);
190
public const string BookmarkColor2String = "marker.bookmark.color2";
191
public virtual Cairo.Color BookmarkColor2 {
193
return GetColorFromDefinition (BookmarkColor2String);
197
public const string BookmarkColor1String = "marker.bookmark.color1";
198
public virtual Cairo.Color BookmarkColor1 {
200
return GetColorFromDefinition (BookmarkColor1String);
204
public const string ReadOnlyTextBgString = "text.background.readonly";
205
public Cairo.Color ReadOnlyTextBg {
207
return GetColorFromDefinition (ReadOnlyTextBgString);
211
public const string SearchTextBgString = "text.background.searchresult";
212
public Cairo.Color SearchTextBg {
214
return GetColorFromDefinition (SearchTextBgString);
218
public const string SearchTextMainBgString = "text.background.searchresult-main";
219
public Cairo.Color SearchTextMainBg {
221
return GetColorFromDefinition (SearchTextMainBgString);
225
public const string BreakpointString = "marker.breakpoint";
226
public Cairo.Color BreakpointFg {
228
return GetChunkStyle (BreakpointString).CairoColor;
231
public Cairo.Color BreakpointBg {
233
return GetChunkStyle (BreakpointString).CairoBackgroundColor;
237
public const string BreakpointMarkerColor2String = "marker.breakpoint.color2";
238
public Cairo.Color BreakpointMarkerColor2 {
240
return GetColorFromDefinition (BreakpointMarkerColor2String);
244
public const string BreakpointMarkerColor1String = "marker.breakpoint.color1";
245
public Cairo.Color BreakpointMarkerColor1 {
247
return GetColorFromDefinition (BreakpointMarkerColor1String);
251
public const string CurrentDebugLineString = "marker.debug.currentline";
252
public Cairo.Color CurrentDebugLineFg {
254
return GetChunkStyle (CurrentDebugLineString).CairoColor;
258
public Cairo.Color CurrentDebugLineBg {
260
return GetChunkStyle (CurrentDebugLineString).CairoBackgroundColor;
264
public const string CurrentDebugLineMarkerColor2String = "marker.debug.currentline.color2";
265
public Cairo.Color CurrentDebugLineMarkerColor2 {
267
return GetColorFromDefinition (CurrentDebugLineMarkerColor2String);
271
public const string CurrentDebugLineMarkerColor1String = "marker.debug.currentline.color1";
272
public Cairo.Color CurrentDebugLineMarkerColor1 {
274
return GetColorFromDefinition (CurrentDebugLineMarkerColor1String);
278
public const string CurrentDebugLineMarkerBorderString = "marker.debug.currentline.border";
279
public Cairo.Color CurrentDebugLineMarkerBorder {
281
return GetColorFromDefinition (CurrentDebugLineMarkerBorderString);
285
public const string DebugStackLineString = "marker.debug.stackline";
286
public Cairo.Color DebugStackLineFg {
288
return GetChunkStyle (DebugStackLineString).CairoColor;
292
public Cairo.Color DebugStackLineBg {
294
return GetChunkStyle (DebugStackLineString).CairoBackgroundColor;
298
public const string DebugStackLineMarkerColor2String = "marker.debug.stackline.color2";
299
public Cairo.Color DebugStackLineMarkerColor2 {
301
return GetColorFromDefinition (DebugStackLineMarkerColor2String);
305
public const string DebugStackLineMarkerColor1String = "marker.debug.stackline.color1";
306
public Cairo.Color DebugStackLineMarkerColor1 {
308
return GetColorFromDefinition (DebugStackLineMarkerColor1String);
312
public const string DebugStackLineMarkerBorderString = "marker.debug.stackline.border";
313
public Cairo.Color DebugStackLineMarkerBorder {
315
return GetColorFromDefinition (DebugStackLineMarkerBorderString);
319
public const string InvalidBreakpointBgString = "marker.breakpoint.invalid.background";
320
public Cairo.Color InvalidBreakpointBg {
322
return GetColorFromDefinition (InvalidBreakpointBgString);
326
public const string InvalidBreakpointMarkerColor1String = "marker.breakpoint.invalid.color1";
327
public Cairo.Color InvalidBreakpointMarkerColor1 {
329
return GetColorFromDefinition (InvalidBreakpointMarkerColor1String);
333
public const string DisabledBreakpointBgString = "marker.breakpoint.disabled.background";
334
public Cairo.Color DisabledBreakpointBg {
336
return GetColorFromDefinition (DisabledBreakpointBgString);
340
public const string InvalidBreakpointMarkerBorderString = "marker.breakpoint.invalid.border";
341
public Cairo.Color InvalidBreakpointMarkerBorder {
343
return GetColorFromDefinition (InvalidBreakpointMarkerBorderString);
347
public const string ErrorUnderlineString = "marker.underline.error";
348
public Cairo.Color ErrorUnderline {
350
return GetColorFromDefinition (ErrorUnderlineString);
354
public const string WarningUnderlineString = "marker.underline.warning";
355
public Cairo.Color WarningUnderline {
357
return GetColorFromDefinition (WarningUnderlineString);
361
public const string HintUnderlineString = "marker.underline.hint";
362
public Cairo.Color HintUnderline {
364
return GetColorFromDefinition (HintUnderlineString);
368
public const string SuggestionUnderlineString = "marker.underline.suggestion";
369
public Cairo.Color SuggestionUnderline {
371
return GetColorFromDefinition (SuggestionUnderlineString);
375
public const string PrimaryTemplateColorString = "marker.template.primary_template";
376
public virtual ChunkStyle PrimaryTemplate {
378
return GetChunkStyle (PrimaryTemplateColorString);
382
public const string PrimaryTemplateHighlightedColorString = "marker.template.primary_highlighted_template";
383
public virtual ChunkStyle PrimaryTemplateHighlighted {
385
return GetChunkStyle (PrimaryTemplateHighlightedColorString);
389
public const string SecondaryTemplateColorString = "marker.template.secondary_template";
390
public virtual ChunkStyle SecondaryTemplate {
392
return GetChunkStyle (SecondaryTemplateColorString);
396
public const string SecondaryTemplateHighlightedColorString = "marker.template.secondary_highlighted_template";
397
public virtual ChunkStyle SecondaryTemplateHighlighted {
399
return GetChunkStyle (SecondaryTemplateHighlightedColorString);
409
public string Description {
414
public static Cairo.Color ToCairoColor (Gdk.Color color)
416
return new Cairo.Color ((double)color.Red / ushort.MaxValue,
417
(double)color.Green / ushort.MaxValue,
418
(double)color.Blue / ushort.MaxValue);
421
public static Gdk.Color ToGdkColor (Cairo.Color color)
423
return new Gdk.Color ((byte)(color.R * 255),
424
(byte)(color.G * 255),
425
(byte)(color.B * 255));
428
public static Cairo.Color ToCairoColor (Gdk.Color color, double alpha)
430
return new Cairo.Color ((double)color.Red / ushort.MaxValue,
431
(double)color.Green / ushort.MaxValue,
432
(double)color.Blue / ushort.MaxValue,
436
protected ColorScheme ()
438
SetStyle (DefaultString, 0, 0, 0, 255, 255, 255);
439
SetStyle (ReadOnlyTextBgString, 0xFA, 0xFA, 0xF8);
441
GetChunkStyle (DefaultString).ChunkProperties |= ChunkProperties.TransparentBackground;
443
SetStyle (LineNumberString, 172, 168, 153, 255, 255, 255);
444
SetStyle (LineNumberFgHighlightedString, 122, 118, 103);
446
SetStyle (IconBarBgString, 255, 255, 255);
447
SetStyle (IconBarSeperatorString, 172, 168, 153);
449
SetStyle (FoldLineString, LineNumberString);
450
SetStyle (FoldLineHighlightedString, IconBarSeperatorString);
451
SetStyle (FoldToggleMarkerString, DefaultString);
453
SetStyle (LineDirtyBgString, 255, 238, 98);
454
SetStyle (LineChangedBgString, 108, 226, 108);
456
SetStyle (SelectionString, 255, 255, 255, 96, 87, 210);
457
SetStyle (InactiveSelectionString, 255, 255, 255, 196, 196, 196);
459
SetStyle (LineMarkerString, 200, 255, 255);
460
SetStyle (RulerString, 187, 187, 187);
461
SetStyle (WhitespaceMarkerString, RulerString);
463
SetStyle (InvalidLineMarkerString, 210, 0, 0);
465
SetStyle (BreakpointString, 255, 255, 255, 125, 0, 0);
467
SetStyle (BreakpointMarkerColor1String, 255, 255, 255);
468
SetStyle (BreakpointMarkerColor2String, 125, 0, 0);
470
SetStyle (DisabledBreakpointBgString, 237, 220, 220);
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);
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);
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);
488
SetStyle (BracketHighlightRectangleString, 0xd3, 0xd7, 0xcf, 0xee, 0xee, 0xec);
489
SetStyle (UsagesHighlightRectangleString, 0xd3, 0xd7, 0xcf, 0xee, 0xee, 0xec);
491
SetStyle (BookmarkColor1String, 255, 255, 255);
492
SetStyle (BookmarkColor2String, 105, 156, 235);
494
SetStyle (ErrorUnderlineString, 255, 0, 0);
495
SetStyle (WarningUnderlineString, 255, 165, 0);
496
SetStyle (SuggestionUnderlineString, 143, 198, 143);
497
SetStyle (HintUnderlineString, 143, 143, 198);
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");
508
SetStyle (PrimaryTemplateColorString, 0xB4, 0xE4, 0xB4, 0xB4, 0xE4, 0xB4);
509
SetStyle (PrimaryTemplateHighlightedColorString, 0, 0, 0, 0xB4, 0xE4, 0xB4);
511
SetStyle (SecondaryTemplateColorString, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
512
SetStyle (SecondaryTemplateHighlightedColorString, 0x7F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF);
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);
520
//regions in ASP.NET, T4, etc.
521
SetStyle ("template", "text");
522
SetStyle ("template.tag", "constant.language");
523
SetStyle ("template.directive", "constant.language");
527
protected void PopulateDefaults ()
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);
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);
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);
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);
558
SetStyle ("keyword.semantic.type", 0, 0x8A , 0x8C);
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);
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);
582
const ChunkProperties BOLD = ChunkProperties.Bold;
583
const ChunkProperties ITALIC = ChunkProperties.Bold;
585
void SetStyle (string name, ChunkStyle style)
587
styleLookupTable[name] = style;
590
void SetStyle (string name, string referencedStyleName)
592
styleLookupTable[name] = new ReferencedChunkStyle (this, referencedStyleName);
595
void SetStyle (string name, byte r, byte g, byte b)
597
SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b)));
600
void SetStyleFromWeb (string name, string colorString)
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));
608
void SetStyleFromWeb (string name, string colorString, string bgColorString)
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));
619
void SetStyle (string name, byte r, byte g, byte b, byte bg_r, byte bg_g, byte bg_b)
621
SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b), new Gdk.Color (bg_r, bg_g, bg_b)));
624
void SetStyle (string name, byte r, byte g, byte b, ChunkProperties properties)
626
SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b), properties));
629
/* void SetStyle (string name, byte r, byte g, byte b, byte bg_r, byte bg_g, byte bg_b, ChunkProperties properties)
631
SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b), new Gdk.Color (bg_r, bg_g, bg_b), properties));
634
public ChunkStyle GetDefaultChunkStyle ()
637
if (!styleLookupTable.TryGetValue (DefaultString, out style)) {
638
style = new ChunkStyle (ToGdkColor (GetColorFromDefinition (DefaultString)));
639
styleLookupTable[DefaultString] = 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; }
46
#region Ambient Colors
47
[ColorDescription("Background(Read Only)",VSSetting="color=Plain Text/Background")]
48
public AmbientColor BackgroundReadOnly { get; private set; }
50
[ColorDescription("Search result background")]
51
public AmbientColor SearchResult { get; private set; }
53
[ColorDescription("Search result background (highlighted)")]
54
public AmbientColor SearchResultMain { get; private set; }
56
[ColorDescription("Fold Square", VSSetting="color=outlining.verticalrule/Foreground")]
57
public AmbientColor FoldLineColor { get; private set; }
59
[ColorDescription("Fold Cross", VSSetting="color=outlining.square/Foreground,secondcolor=outlining.square/Background")]
60
public AmbientColor FoldCross { get; private set; }
62
[ColorDescription("Indentation Guide")] // not defined
63
public AmbientColor IndentationGuide { get; private set; }
65
[ColorDescription("Indicator Margin", VSSetting="color=Indicator Margin/Background")]
66
public AmbientColor IndicatorMargin { get; private set; }
68
[ColorDescription("Indicator Margin(Separator)", VSSetting="color=Indicator Margin/Background")]
69
public AmbientColor IndicatorMarginSeparator { get; private set; }
71
[ColorDescription("Tooltip Border")]
72
public AmbientColor TooltipBorder { get; private set; }
74
[ColorDescription("Tooltip Pager Top")]
75
public AmbientColor TooltipPagerTop { get; private set; }
77
[ColorDescription("Tooltip Pager Bottom")]
78
public AmbientColor TooltipPagerBottom { get; private set; }
80
[ColorDescription("Tooltip Pager Triangle")]
81
public AmbientColor TooltipPagerTriangle { get; private set; }
83
[ColorDescription("Tooltip Pager Text")]
84
public AmbientColor TooltipPagerText { get; private set; }
86
[ColorDescription("Bookmarks")]
87
public AmbientColor Bookmarks { get; private set; }
89
[ColorDescription("Underline(Error)", VSSetting="color=Syntax Error/Foreground")]
90
public AmbientColor UnderlineError { get; private set; }
92
[ColorDescription("Underline(Warning)", VSSetting="color=Warning/Foreground")]
93
public AmbientColor UnderlineWarning { get; private set; }
95
[ColorDescription("Underline(Suggestion)", VSSetting="color=Other Error/Foreground")]
96
public AmbientColor UnderlineSuggestion { get; private set; }
98
[ColorDescription("Underline(Hint)", VSSetting="color=Other Error/Foreground")]
99
public AmbientColor UnderlineHint { get; private set; }
101
[ColorDescription("Quick Diff(Dirty)")]
102
public AmbientColor QuickDiffDirty { get; private set; }
104
[ColorDescription("Quick Diff(Changed)")]
105
public AmbientColor QuickDiffChanged { get; private set; }
107
[ColorDescription("Brace Matching(Rectangle)", VSSetting="color=Brace Matching (Rectangle)/Background,secondcolor=Brace Matching (Rectangle)/Foreground")]
108
public AmbientColor BraceMatchingRectangle { get; private set; }
110
[ColorDescription("Usages(Rectangle)", VSSetting="color=MarkerFormatDefinition/HighlightedReference/Background,secondcolor=MarkerFormatDefinition/HighlightedReference/Background")]
111
public AmbientColor UsagesRectangle { get; private set; }
113
[ColorDescription("Breakpoint Marker")]
114
public AmbientColor BreakpointMarker { get; private set; }
116
[ColorDescription("Breakpoint Marker(Invalid)")]
117
public AmbientColor InvalidBreakpointMarker { get; private set; }
119
[ColorDescription("Breakpoint Marker(Disabled)")]
120
public AmbientColor BreakpointMarkerDisabled { get; private set; }
122
[ColorDescription("Debugger Current Line Marker")]
123
public AmbientColor DebuggerCurrentLineMarker { get; private set; }
125
[ColorDescription("Debugger Stack Line Marker")]
126
public AmbientColor DebuggerStackLineMarker { get; private set; }
128
[ColorDescription("Primary Link", VSSetting = "color=Refactoring Dependent Field/Background" )]
129
public AmbientColor PrimaryTemplate { get; private set; }
131
[ColorDescription("Primary Link(Highlighted)", VSSetting = "color=Refactoring Current Field/Background")]
132
public AmbientColor PrimaryTemplateHighlighted { get; private set; }
134
[ColorDescription("Secondary Link")] // not defined
135
public AmbientColor SecondaryTemplate { get; private set; }
137
[ColorDescription("Secondary Link(Highlighted)")] // not defined
138
public AmbientColor SecondaryTemplateHighlighted { get; private set; }
140
[ColorDescription("Current Line Marker", VSSetting = "color=CurrentLineActiveFormat/Background,secondcolor=CurrentLineActiveFormat/Foreground")]
141
public AmbientColor LineMarker { get; private set; }
143
[ColorDescription("Current Line Marker(Inactive)", VSSetting = "color=CurrentLineInactiveFormat/Background,secondcolor=CurrentLineInactiveFormat/Foreground")]
144
public AmbientColor LineMarkerInactive { get; private set; }
146
[ColorDescription("Column Ruler")] // not defined
147
public AmbientColor Ruler { get; private set; }
149
[ColorDescription("Completion Matching Substring")]
150
public AmbientColor CompletionHighlight { get; private set; }
152
[ColorDescription("Completion Border")]
153
public AmbientColor CompletionBorder { get; private set; }
155
[ColorDescription("Completion Border(Inactive)")]
156
public AmbientColor CompletionInactiveBorder { get; private set; }
158
[ColorDescription("Message Bubble Error")]
159
public AmbientColor MessageBubbleError { get; private set; }
161
[ColorDescription("Message Bubble Warning")]
162
public AmbientColor MessageBubbleWarning { get; private set; }
167
[ColorDescription("Plain Text", VSSetting = "Plain Text")]
168
public ChunkStyle PlainText { get; private set; }
170
[ColorDescription("Selected Text", VSSetting = "Selected Text")]
171
public ChunkStyle SelectedText { get; private set; }
173
[ColorDescription("Selected Text(Inactive)", VSSetting = "Inactive Selected Text")]
174
public ChunkStyle SelectedInactiveText { get; private set; }
176
[ColorDescription("Collapsed Text", VSSetting = "Collapsible Text")]
177
public ChunkStyle CollapsedText { get; private set; }
179
[ColorDescription("Line Numbers", VSSetting = "Line Numbers")]
180
public ChunkStyle LineNumbers { get; private set; }
182
[ColorDescription("Punctuation", VSSetting = "Operator")]
183
public ChunkStyle Punctuation { get; private set; }
185
[ColorDescription("Punctuation(Brackets)", VSSetting = "Plain Text")]
186
public ChunkStyle PunctuationForBrackets { get; private set; }
188
[ColorDescription("Comment(Line)", VSSetting = "Comment")]
189
public ChunkStyle CommentsSingleLine { get; private set; }
191
[ColorDescription("Comment(Block)", VSSetting = "Comment")]
192
public ChunkStyle CommentsMultiLine { get; private set; }
194
[ColorDescription("Comment(Doc)", VSSetting = "XML Doc Comment")]
195
public ChunkStyle CommentsForDocumentation { get; private set; }
197
[ColorDescription("Comment(DocTag)", VSSetting = "XML Doc Tag")]
198
public ChunkStyle CommentsForDocumentationTags { get; private set; }
200
[ColorDescription("Comment Tag", VSSetting = "Comment")]
201
public ChunkStyle CommentTags { get; private set; }
203
[ColorDescription("Excluded Code", VSSetting = "Excluded Code")]
204
public ChunkStyle ExcludedCode { get; private set; }
206
[ColorDescription("String", VSSetting = "String")]
207
public ChunkStyle String { get; private set; }
209
[ColorDescription("String(Escape)", VSSetting = "String")]
210
public ChunkStyle StringEscapeSequence { get; private set; }
212
[ColorDescription("String(C# @ Verbatim)", VSSetting = "String(C# @ Verbatim)")]
213
public ChunkStyle StringVerbatim { get; private set; }
215
[ColorDescription("Number", VSSetting = "Number")]
216
public ChunkStyle Number { get; private set; }
218
[ColorDescription("Preprocessor", VSSetting = "Preprocessor Keyword")]
219
public ChunkStyle Preprocessor { get; private set; }
221
[ColorDescription("Xml Text", VSSetting = "XML Text")]
222
public ChunkStyle XmlText { get; private set; }
224
[ColorDescription("Xml Delimiter", VSSetting = "XML Delimiter")]
225
public ChunkStyle XmlDelimiter { get; private set; }
227
[ColorDescription("Xml Name", VSSetting ="XML Name")]
228
public ChunkStyle XmlName { get; private set; }
230
[ColorDescription("Xml Attribute", VSSetting = "XML Attribute")]
231
public ChunkStyle XmlAttribute { get; private set; }
233
[ColorDescription("Xml Attribute Quotes", VSSetting = "XML Attribute Quotes")]
234
public ChunkStyle XmlAttributeQuotes { get; private set; }
236
[ColorDescription("Xml Attribute Value", VSSetting = "XML Attribute Value")]
237
public ChunkStyle XmlAttributeValue { get; private set; }
239
[ColorDescription("Xml Comment", VSSetting = "XML Comment")]
240
public ChunkStyle XmlComment { get; private set; }
242
[ColorDescription("Xml CData Section", VSSetting = "XML CData Section")]
243
public ChunkStyle XmlCDataSection { get; private set; }
245
[ColorDescription("Tooltip Text")] // not defined in vs.net
246
public ChunkStyle TooltipText { get; private set; }
248
[ColorDescription("Completion Text")] //not defined in vs.net
249
public ChunkStyle CompletionText { get; private set; }
251
[ColorDescription("Completion Selected Text")] //not defined in vs.net
252
public ChunkStyle CompletionSelectedText { get; private set; }
254
[ColorDescription("Completion Selected Text(Inactive)")] //not defined in vs.net
255
public ChunkStyle CompletionSelectedInactiveText { get; private set; }
257
[ColorDescription("Keyword(Access)", VSSetting = "Keyword")]
258
public ChunkStyle KeywordAccessors { get; private set; }
260
[ColorDescription("Keyword(Type)", VSSetting = "Keyword")]
261
public ChunkStyle KeywordTypes { get; private set; }
263
[ColorDescription("Keyword(Operator)", VSSetting = "Keyword")]
264
public ChunkStyle KeywordOperators { get; private set; }
266
[ColorDescription("Keyword(Selection)", VSSetting = "Keyword")]
267
public ChunkStyle KeywordSelection { get; private set; }
269
[ColorDescription("Keyword(Iteration)", VSSetting = "Keyword")]
270
public ChunkStyle KeywordIteration { get; private set; }
272
[ColorDescription("Keyword(Jump)", VSSetting = "Keyword")]
273
public ChunkStyle KeywordJump { get; private set; }
275
[ColorDescription("Keyword(Context)", VSSetting = "Keyword")]
276
public ChunkStyle KeywordContext { get; private set; }
278
[ColorDescription("Keyword(Exception)", VSSetting = "Keyword")]
279
public ChunkStyle KeywordException { get; private set; }
281
[ColorDescription("Keyword(Modifiers)", VSSetting = "Keyword")]
282
public ChunkStyle KeywordModifiers { get; private set; }
284
[ColorDescription("Keyword(Constants)", VSSetting = "Keyword")]
285
public ChunkStyle KeywordConstants { get; private set; }
287
[ColorDescription("Keyword(Void)", VSSetting = "Keyword")]
288
public ChunkStyle KeywordVoid { get; private set; }
290
[ColorDescription("Keyword(Namespace)", VSSetting = "Keyword")]
291
public ChunkStyle KeywordNamespace { get; private set; }
293
[ColorDescription("Keyword(Property)", VSSetting = "Keyword")]
294
public ChunkStyle KeywordProperty { get; private set; }
296
[ColorDescription("Keyword(Declaration)", VSSetting = "Keyword")]
297
public ChunkStyle KeywordDeclaration { get; private set; }
299
[ColorDescription("Keyword(Parameter)", VSSetting = "Keyword")]
300
public ChunkStyle KeywordParameter { get; private set; }
302
[ColorDescription("Keyword(Operator Declaration)", VSSetting = "Keyword")]
303
public ChunkStyle KeywordOperatorDeclaration { get; private set; }
305
[ColorDescription("Keyword(Other)", VSSetting = "Keyword")]
306
public ChunkStyle KeywordOther { get; private set; }
308
[ColorDescription("User Types", VSSetting = "User Types")]
309
public ChunkStyle UserTypes { get; private set; }
311
[ColorDescription("User Types(Enums)", VSSetting = "User Types(Enums)")]
312
public ChunkStyle UserTypesEnums { get; private set; }
314
[ColorDescription("User Types(Interfaces)", VSSetting = "User Types(Interfaces)")]
315
public ChunkStyle UserTypesInterfaces { get; private set; }
317
[ColorDescription("User Types(Delegates)", VSSetting = "User Types(Delegates)")]
318
public ChunkStyle UserTypesDelegatess { get; private set; }
320
[ColorDescription("User Types(Value types)", VSSetting = "User Types(Value types)")]
321
public ChunkStyle UserTypesValueTypes { get; private set; }
323
[ColorDescription("User Types(Type parameters)", VSSetting = "User Types(Type parameters)")]
324
public ChunkStyle UserTypesTypeParameters { get; private set; }
326
[ColorDescription("User Field Usage", VSSetting = "Identifier")]
327
public ChunkStyle UserFieldUsage { get; private set; }
329
[ColorDescription("User Field Declaration", VSSetting = "Identifier")]
330
public ChunkStyle UserFieldDeclaration { get; private set; }
332
[ColorDescription("User Property Usage", VSSetting = "Identifier")]
333
public ChunkStyle UserPropertyUsage { get; private set; }
335
[ColorDescription("User Property Declaration", VSSetting = "Identifier")]
336
public ChunkStyle UserPropertyDeclaration { get; private set; }
338
[ColorDescription("User Event Usage", VSSetting = "Identifier")]
339
public ChunkStyle UserEventUsage { get; private set; }
341
[ColorDescription("User Event Declaration", VSSetting = "Identifier")]
342
public ChunkStyle UserEventDeclaration { get; private set; }
344
[ColorDescription("User Method Usage", VSSetting = "Identifier")]
345
public ChunkStyle UserMethodUsage { get; private set; }
347
[ColorDescription("User Method Declaration", VSSetting = "Identifier")]
348
public ChunkStyle UserMethodDeclaration { get; private set; }
350
[ColorDescription("User Parameter Usage", VSSetting = "Identifier")]
351
public ChunkStyle UserParameterUsage { get; private set; }
353
[ColorDescription("User Parameter Declaration", VSSetting = "Identifier")]
354
public ChunkStyle UserParameterDeclaration { get; private set; }
356
[ColorDescription("User Variable Usage", VSSetting = "Identifier")]
357
public ChunkStyle UserVariableUsage { get; private set; }
359
[ColorDescription("User Variable Declaration", VSSetting = "Identifier")]
360
public ChunkStyle UserVariableDeclaration { get; private set; }
362
[ColorDescription("Syntax Error", VSSetting = "Syntax Error")]
363
public ChunkStyle SyntaxError { get; private set; }
365
[ColorDescription("Breakpoint Text", VSSetting = "Breakpoint (Enabled)")]
366
public ChunkStyle BreakpointText { get; private set; }
368
[ColorDescription("Breakpoint Text(Invalid)", VSSetting = "Breakpoint (Disabled)")]
369
public ChunkStyle BreakpointTextInvalid { get; private set; }
371
[ColorDescription("Debugger Current Statement", VSSetting = "Current Statement")]
372
public ChunkStyle DebuggerCurrentLine { get; private set; }
374
[ColorDescription("Debugger Stack Line")] // not defined
375
public ChunkStyle DebuggerStackLine { get; private set; }
378
[ColorDescription("Diff Line(Added)")] //not defined
379
public ChunkStyle DiffLineAdded { get; private set; }
381
[ColorDescription("Diff Line(Removed)")] //not defined
382
public ChunkStyle DiffLineRemoved { get; private set; }
384
[ColorDescription("Diff Line(Changed)")] //not defined
385
public ChunkStyle DiffLineChanged { get; private set; }
387
[ColorDescription("Diff Header")] //not defined
388
public ChunkStyle DiffHeader { get; private set; }
390
[ColorDescription("Diff Header(Separator)")] //not defined
391
public ChunkStyle DiffHeaderSeparator { get; private set; }
393
[ColorDescription("Diff Header(Old)")] //not defined
394
public ChunkStyle DiffHeaderOld { get; private set; }
396
[ColorDescription("Diff Header(New)")] //not defined
397
public ChunkStyle DiffHeaderNew { get; private set; }
399
[ColorDescription("Diff Location")] //not defined
400
public ChunkStyle DiffLocation { get; private set; }
402
[ColorDescription("Html Attribute Name", VSSetting="HTML Attribute")]
403
public ChunkStyle HtmlAttributeName { get; private set; }
405
[ColorDescription("Html Attribute Value", VSSetting="HTML Attribute Value")]
406
public ChunkStyle HtmlAttributeValue { get; private set; }
408
[ColorDescription("Html Comment", VSSetting="HTML Comment")]
409
public ChunkStyle HtmlComment { get; private set; }
411
[ColorDescription("Html Element Name", VSSetting="HTML Element Name")]
412
public ChunkStyle HtmlElementName { get; private set; }
414
[ColorDescription("Html Entity", VSSetting="HTML Entity")]
415
public ChunkStyle HtmlEntity { get; private set; }
417
[ColorDescription("Html Operator", VSSetting="HTML Operator")]
418
public ChunkStyle HtmlOperator { get; private set; }
420
[ColorDescription("Html Server-Side Script", VSSetting="HTML Server-Side Script")]
421
public ChunkStyle HtmlServerSideScript { get; private set; }
423
[ColorDescription("Html Tag Delimiter", VSSetting="HTML Tag Delimiter")]
424
public ChunkStyle HtmlTagDelimiter { get; private set; }
426
[ColorDescription("Razor Code", VSSetting="Razor Code")]
427
public ChunkStyle RazorCode { get; private set; }
430
[ColorDescription("Css Comment", VSSetting="CSS Comment")]
431
public ChunkStyle CssComment { get; private set; }
433
[ColorDescription("Css Property Name", VSSetting="CSS Property Name")]
434
public ChunkStyle CssPropertyName { get; private set; }
436
[ColorDescription("Css Property Value", VSSetting="CSS Property Value")]
437
public ChunkStyle CssPropertyValue { get; private set; }
439
[ColorDescription("Css Selector", VSSetting="CSS Selector")]
440
public ChunkStyle CssSelector { get; private set; }
442
[ColorDescription("Css String Value", VSSetting="CSS String Value")]
443
public ChunkStyle CssStringValue { get; private set; }
445
[ColorDescription("Css Keyword", VSSetting="CSS Keyword")]
446
public ChunkStyle CssKeyword { get; private set; }
448
[ColorDescription("Script Comment", VSSetting="Script Comment")]
449
public ChunkStyle ScriptComment { get; private set; }
451
[ColorDescription("Script Identifier", VSSetting="Script Identifier")]
452
public ChunkStyle ScriptIdentifier { get; private set; }
454
[ColorDescription("Script Keyword", VSSetting="Script Keyword")]
455
public ChunkStyle ScriptKeyword { get; private set; }
457
[ColorDescription("Script Number", VSSetting="Script Number")]
458
public ChunkStyle ScriptNumber { get; private set; }
460
[ColorDescription("Script Operator", VSSetting="Script Operator")]
461
public ChunkStyle ScriptOperator { get; private set; }
463
[ColorDescription("Script String", VSSetting="Script String")]
464
public ChunkStyle ScriptString { get; private set; }
469
public class PropertyDecsription
471
public readonly PropertyInfo Info;
472
public readonly ColorDescriptionAttribute Attribute;
474
public PropertyDecsription (PropertyInfo info, ColorDescriptionAttribute attribute)
477
this.Attribute = attribute;
481
static Dictionary<string, PropertyDecsription> textColors = new Dictionary<string, PropertyDecsription> ();
483
public static IEnumerable<PropertyDecsription> TextColors {
485
return textColors.Values;
489
static Dictionary<string, PropertyDecsription> ambientColors = new Dictionary<string, PropertyDecsription> ();
491
public static IEnumerable<PropertyDecsription> AmbientColors {
493
return ambientColors.Values;
497
static ColorScheme ()
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)
503
if (property.PropertyType == typeof (ChunkStyle)) {
504
textColors.Add (description.Name, new PropertyDecsription (property, description));
506
ambientColors.Add (description.Name, new PropertyDecsription (property, description));
511
public ColorScheme Clone ()
513
var result = new ColorScheme () {
515
BaseScheme = this.BaseScheme,
516
Originator = this.Originator,
517
Description = this.Description
519
result.CopyValues (this);
523
static Cairo.Color ParseColor (string value)
525
return HslColor.Parse (value);
528
public static Cairo.Color ParsePaletteColor (Dictionary<string, Cairo.Color> palette, string value)
531
if (palette.TryGetValue (value, out result))
533
return ParseColor (value);
644
536
public ChunkStyle GetChunkStyle (Chunk chunk)
647
throw new ArgumentNullException ("chunk");
648
538
return GetChunkStyle (chunk.Style);
651
public ChunkStyle GetChunkStyle (string name)
654
return GetDefaultChunkStyle ();
656
if (styleLookupTable.TryGetValue (name, out style))
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);
668
dotIndex = fallbackName.LastIndexOf ('.');
671
// Console.WriteLine ("Chunk style {0} fell back to default", name);
672
return GetDefaultChunkStyle ();
675
public void SetChunkStyle (string name, string weight, string foreColor, string backColor)
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;
688
SetStyle (name, !string.IsNullOrEmpty (backColor) ? new ChunkStyle (color, bgColor, properties) : new ChunkStyle (color, properties));
691
public void SetChunkStyle (string name, ChunkStyle style)
693
SetStyle (name, style);
696
static int GetNumber (string str, int offset)
698
return int.Parse (str.Substring (offset, 2), NumberStyles.HexNumber);
701
public Cairo.Color GetColorFromString (string colorString)
703
string refColorString;
704
if (customPalette.TryGetValue (colorString, out refColorString))
705
return this.GetColorFromString (refColorString);
707
if (styleLookupTable.TryGetValue (colorString, out style))
708
return style.CairoColor;
709
if (colorString.Length > 0 && colorString[0] == '#') {
710
if (colorString.Length == 9) {
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);
714
if (colorString.Length == 7) {
716
return new Cairo.Color ( GetNumber (colorString, 1) / 255.0, GetNumber (colorString, 3) / 255.0, GetNumber (colorString, 5) / 255.0);
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);
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 + "'");
726
public const string NameAttribute = "name";
728
static void ReadStyleTree (XmlReader reader, ColorScheme result, string curName, string curWeight, string curColor, string curBgColor)
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");
735
if (String.IsNullOrEmpty (curName)) {
738
fullName = curName + "." + name;
740
if (!String.IsNullOrEmpty (color)) {
741
result.SetChunkStyle (fullName, weight, color, bgColor);
743
XmlReadHelper.ReadList (reader, "Style", delegate () {
744
switch (reader.LocalName) {
746
ReadStyleTree (reader, result, fullName, weight, color, bgColor);
753
public static ColorScheme LoadFrom (XmlReader reader)
541
public ChunkStyle GetChunkStyle (string color)
544
return GetChunkStyle ("Plain Text");
545
PropertyDecsription val;
546
if (!textColors.TryGetValue (color, out val)) {
547
Console.WriteLine ("Chunk style : " + color + " is undefined.");
550
return val.Info.GetValue (this, null) as ChunkStyle;
553
void CopyValues (ColorScheme baseScheme)
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);
561
public static ColorScheme LoadFrom (Stream stream)
755
563
var result = new ColorScheme ();
756
XmlReadHelper.ReadList (reader, "EditorStyle", delegate () {
757
switch (reader.LocalName) {
759
result.Name = reader.GetAttribute (NameAttribute);
760
result.Description = reader.GetAttribute ("_description");
763
result.customPalette [reader.GetAttribute ("name")] = reader.GetAttribute ("value");
766
ReadStyleTree (reader, result, null, null, null, null);
771
result.GetChunkStyle (DefaultString).ChunkProperties |= ChunkProperties.TransparentBackground;
564
var reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader (stream, new System.Xml.XmlDictionaryReaderQuotas ());
566
var root = XElement.Load(reader);
568
// The fields we'd like to extract
569
result.Name = root.XPathSelectElement("name").Value;
571
if (result.Name != "Default")
572
result.CopyValues (SyntaxModeService.DefaultColorStyle);
574
var version = Version.Parse (root.XPathSelectElement("version").Value);
575
if (version.Major != 1)
577
var el = root.XPathSelectElement ("description");
579
result.Description = el.Value;
580
el = root.XPathSelectElement ("originator");
582
result.Originator = el.Value;
583
el = root.XPathSelectElement ("baseScheme");
585
result.BaseScheme = el.Value;
587
if (result.BaseScheme != null) {
588
var baseScheme = SyntaxModeService.GetColorStyle (result.BaseScheme);
589
if (baseScheme != null)
590
result.CopyValues (baseScheme);
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);
600
ParseColor (color.XPathSelectElement ("value").Value)
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.");
611
info.Info.SetValue (result, color, null);
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.");
621
info.Info.SetValue (result, color, null);
626
foreach (var color in textColors.Values) {
627
if (color.Info.GetValue (result, null) == null) {
628
Console.WriteLine (color.Attribute.Name + " == null");
632
foreach (var color in ambientColors.Values) {
633
if (color.Info.GetValue (result, null) == null) {
634
Console.WriteLine (color.Attribute.Name + " == null");
639
throw new InvalidDataException ("Scheme " + result.Name + " is not valid.");
775
static string GetColorString (double c)
777
int conv = (int)(c * 255.0);
778
return string.Format ("{0:X2}", conv);
781
static string GetColorString (Cairo.Color cairoColor)
783
var result = new System.Text.StringBuilder ();
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));
791
return result.ToString ();
643
public static string ColorToMarkup (Cairo.Color color)
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);
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);
794
656
public void Save (string fileName)
796
var writer = new XmlTextWriter (fileName, System.Text.UTF8Encoding.UTF8);
797
writer.Formatting = Formatting.Indented;
799
writer.WriteStartElement ("EditorStyle");
800
writer.WriteAttributeString (NameAttribute, Name);
801
writer.WriteAttributeString ("_description", Description);
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 ();
814
writer.WriteEndElement ();
818
public ColorScheme Clone ()
820
ColorScheme clone = (ColorScheme)MemberwiseClone ();
821
clone.styleLookupTable = new Dictionary<string, ChunkStyle> (styleLookupTable);
825
public virtual void UpdateFromGtkStyle (Gtk.Style style)
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);
669
var baseStyle = SyntaxModeService.GetColorStyle (BaseScheme ?? "Default");
671
writer.WriteLine ("\t\"colors\":[");
673
foreach (var ambient in ambientColors) {
674
var thisValue = ambient.Value.Info.GetValue (this, null) as AmbientColor;
675
if (thisValue == null)
677
var baseValue = ambient.Value.Info.GetValue (baseStyle, null) as AmbientColor;
678
if (thisValue.Equals (baseValue)) {
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)));
688
if (colorString.Length == 0) {
689
Console.WriteLine ("Invalid ambient color :" + thisValue);
693
writer.WriteLine (",");
697
writer.Write ("\t\t{");
698
writer.Write ("\"name\": \"{0}\", {1}", ambient.Value.Attribute.Name, colorString);
702
writer.WriteLine ("\t],");
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)
709
var baseValue = textColor.Value.Info.GetValue (baseStyle, null) as ChunkStyle;
710
if (thisValue.Equals (baseValue)) {
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)));
721
if (thisValue.FontWeight != FontWeight.Normal) {
722
if (colorString.Length > 0)
723
colorString.Append (", ");
724
colorString.Append (string.Format ("\"weight\":\"{0}\"", thisValue.FontWeight));
726
if (thisValue.FontStyle != FontStyle.Normal) {
727
if (colorString.Length > 0)
728
colorString.Append (", ");
729
colorString.Append (string.Format ("\"style\":\"{0}\"", thisValue.FontStyle));
732
writer.WriteLine (",");
736
writer.Write ("\t\t{");
737
if (colorString.Length == 0) {
738
writer.Write ("\"name\": \"{0}\"", textColor.Value.Attribute.Name);
740
writer.Write ("\"name\": \"{0}\", {1}", textColor.Value.Attribute.Name, colorString);
745
writer.WriteLine ("\t]");
747
writer.WriteLine ("}");
751
internal static Cairo.Color ImportVsColor (string colorString)
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);
759
public class VSSettingColor
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; }
766
public static VSSettingColor Create (XmlReader reader)
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"
777
public static Cairo.Color AlphaBlend (Cairo.Color fore, Cairo.Color back, double alpha)
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);
785
public static ColorScheme Import (string fileName, Stream stream)
787
var result = new ColorScheme ();
788
result.Name = Path.GetFileNameWithoutExtension (fileName);
789
result.Description = "Imported color scheme";
790
result.Originator = "Imported from " + fileName;
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);
801
colors[color.Name] = color;
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);
820
// convert text colors
821
foreach (var vsc in colors.Values) {
823
foreach (var color in textColors) {
824
if (color.Value.Attribute.VSSetting == null)
826
var split = color.Value.Attribute.VSSetting.Split ('?');
827
foreach (var s in split) {
829
/* if (vsc.Foreground == "0x02000000" && vsc.Background == "0x02000000") {
830
color.Value.Info.SetValue (result, result.PlainText, null);
834
var textColor = ChunkStyle.Import (color.Value.Attribute.Name, vsc);
835
if (textColor != null) {
836
color.Value.Info.SetValue (result, textColor, null);
842
if (!found && !importedAmbientColors.Contains (vsc.Name))
843
Console.WriteLine (vsc.Name + " not imported!");
846
result.IndentationGuide = new AmbientColor ();
847
result.IndentationGuide.Colors.Add (Tuple.Create ("color", AlphaBlend (result.PlainText.Foreground, result.PlainText.Background, 0.3)));
849
result.TooltipText = result.PlainText.Clone ();
850
var h = (HslColor)result.TooltipText.Background;
852
result.TooltipText.Background = h;
854
result.TooltipPagerTop = new AmbientColor ();
855
result.TooltipPagerTop.Colors.Add (Tuple.Create ("color", result.TooltipText.Background));
857
result.TooltipPagerBottom = new AmbientColor ();
858
result.TooltipPagerBottom.Colors.Add (Tuple.Create ("color", result.TooltipText.Background));
860
result.TooltipPagerTriangle = new AmbientColor ();
861
result.TooltipPagerTriangle.Colors.Add (Tuple.Create ("color", AlphaBlend (result.PlainText.Foreground, result.PlainText.Background, 0.8)));
863
result.TooltipBorder = new AmbientColor ();
864
result.TooltipBorder.Colors.Add (Tuple.Create ("color", AlphaBlend (result.PlainText.Foreground, result.PlainText.Background, 0.5)));
866
var defaultStyle = SyntaxModeService.GetColorStyle (HslColor.Brightness (result.PlainText.Background) < 0.5 ? "Monokai" : "Default");
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);
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);
876
if (result.PlainText.TransparentForeground)
877
result.PlainText.Foreground = new Cairo.Color (0, 0, 0);
881
public Cairo.Color GetForeground (ChunkStyle chunkStyle)
883
if (chunkStyle.TransparentForeground)
884
return PlainText.Foreground;
885
return chunkStyle.Foreground;