~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingColor.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 System.Collections.ObjectModel;
 
7
using System.Linq;
 
8
using System.Windows.Media;
 
9
 
 
10
using ICSharpCode.Core;
 
11
 
 
12
namespace ICSharpCode.AvalonEdit.AddIn
 
13
{
 
14
        /// <summary>
 
15
        /// Holds a customized highlighting color.
 
16
        /// </summary>
 
17
        public class CustomizedHighlightingColor
 
18
        {
 
19
                /// <summary>
 
20
                /// The language to which this customization applies. null==all languages.
 
21
                /// </summary>
 
22
                public string Language;
 
23
                
 
24
                /// <summary>
 
25
                /// The name of the highlighting color being modified.
 
26
                /// </summary>
 
27
                public string Name;
 
28
                
 
29
                public bool Bold, Italic;
 
30
                public Color? Foreground, Background;
 
31
                
 
32
                public static List<CustomizedHighlightingColor> LoadColors()
 
33
                {
 
34
                        var list = PropertyService.Get("CustomizedHighlightingRules", new List<CustomizedHighlightingColor>());
 
35
                        // Always make a copy of the list so that the original list cannot be modified without using SaveColors().
 
36
                        return new List<CustomizedHighlightingColor>(list);
 
37
                }
 
38
                
 
39
                /// <summary>
 
40
                /// Saves the set of colors.
 
41
                /// </summary>
 
42
                public static void SaveColors(IEnumerable<CustomizedHighlightingColor> colors)
 
43
                {
 
44
                        lock (staticLockObj) {
 
45
                                activeColors = null;
 
46
                                PropertyService.Set("CustomizedHighlightingRules", colors.ToList());
 
47
                        }
 
48
                        EventHandler e = ActiveColorsChanged;
 
49
                        if (e != null)
 
50
                                e(null, EventArgs.Empty);
 
51
                }
 
52
                
 
53
                static ReadOnlyCollection<CustomizedHighlightingColor> activeColors;
 
54
                static readonly object staticLockObj = new object();
 
55
                
 
56
                public static ReadOnlyCollection<CustomizedHighlightingColor> ActiveColors {
 
57
                        get {
 
58
                                lock (staticLockObj) {
 
59
                                        if (activeColors == null)
 
60
                                                activeColors = LoadColors().AsReadOnly();
 
61
                                        return activeColors;
 
62
                                }
 
63
                        }
 
64
                }
 
65
                
 
66
                /// <summary>
 
67
                /// Occurs when the set of customized highlighting colors was changed.
 
68
                /// </summary>
 
69
                public static EventHandler ActiveColorsChanged;
 
70
        }
 
71
}