~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/FontsAndColorsItems.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
using ICSharpCode.AvalonEdit.AddIn;
 
7
 
 
8
namespace ICSharpCode.PackageManagement.EnvDTE
 
9
{
 
10
        public class FontsAndColorsItems
 
11
        {
 
12
                static readonly string PlainTextItem = "Plain Text";
 
13
                
 
14
                ICustomizedHighlightingRules highlightingRules;
 
15
                List<CustomizedHighlightingColor> colors;
 
16
                
 
17
                public FontsAndColorsItems()
 
18
                        : this(new CustomizedHighlightingRules())
 
19
                {
 
20
                }
 
21
                
 
22
                public FontsAndColorsItems(ICustomizedHighlightingRules highlightingRules)
 
23
                {
 
24
                        this.highlightingRules = highlightingRules;
 
25
                }
 
26
                
 
27
                public ColorableItems Item(string name)
 
28
                {
 
29
                        if (IsPlainText(name)) {
 
30
                                return CreatePlainTextColorableItems();
 
31
                        }
 
32
                        return null;
 
33
                }
 
34
                
 
35
                bool IsPlainText(string name)
 
36
                {
 
37
                        return String.Equals(name, PlainTextItem, StringComparison.InvariantCultureIgnoreCase);
 
38
                }
 
39
                
 
40
                ColorableItems CreatePlainTextColorableItems()
 
41
                {
 
42
                        CustomizedHighlightingColor color = FindPlainTextHighlightingColor();
 
43
                        if (color == null) {
 
44
                                color = AddPlainTextHighlightingColorToCustomColors();
 
45
                        }
 
46
                        return new ColorableItems(PlainTextItem, color, this);
 
47
                }
 
48
                
 
49
                CustomizedHighlightingColor FindPlainTextHighlightingColor()
 
50
                {
 
51
                        return Colors.Find(c => c.Name == CustomizableHighlightingColorizer.DefaultTextAndBackground);
 
52
                }
 
53
                
 
54
                CustomizedHighlightingColor AddPlainTextHighlightingColorToCustomColors()
 
55
                {
 
56
                        var color = new CustomizedHighlightingColor() {
 
57
                                Name = CustomizableHighlightingColorizer.DefaultTextAndBackground
 
58
                        };
 
59
                        Colors.Add(color);
 
60
                        return color;
 
61
                }
 
62
                
 
63
                List<CustomizedHighlightingColor> Colors {
 
64
                        get {
 
65
                                if (colors == null) {
 
66
                                        colors = highlightingRules.LoadColors();
 
67
                                }
 
68
                                return colors;
 
69
                        }
 
70
                }
 
71
                
 
72
                internal void Save()
 
73
                {
 
74
                        highlightingRules.SaveColors(Colors);
 
75
                }
 
76
        }
 
77
}