OSDN Git Service

起動時にキャレットを表示させるようにした。これにともないタイマー起動タイミングを変更した
[fooeditengine/FooEditEngine.git] / Common / WatchDogPattern.cs
1 /*\r
2  * Copyright (C) 2013 FooProject\r
3  * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by\r
4  * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\r
5 \r
6  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of \r
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\r
8 \r
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.\r
10  */\r
11 using System;\r
12 using System.Collections.Generic;\r
13 using System.Text.RegularExpressions;\r
14 \r
15 namespace FooEditEngine\r
16 {\r
17     /// <summary>\r
18     /// IMarkerPattern\83C\83\93\83^\81[\83t\83F\83C\83X\r
19     /// </summary>\r
20     public interface IMarkerPattern\r
21     {\r
22         /// <summary>\r
23         /// \83}\81[\83J\81[\82ð\95Ô\82·\r
24         /// </summary>\r
25         /// <param name="lineHeadIndex">\8ds\93ª\82Ö\82Ì\83C\83\93\83f\83b\83N\83X\82ð\95\\82·</param>\r
26         /// <param name="s">\95\8e\9a\97ñ</param>\r
27         /// <returns>Marker\97ñ\8b\93\91Ì\82ð\95Ô\82·</returns>\r
28         IEnumerable<Marker> GetMarker(int lineHeadIndex, string s);\r
29     }\r
30     /// <summary>\r
31     /// \90³\8bK\95\\8c»\82Å\83}\81[\83J\81[\82Ì\8eæ\93¾\82ð\8ds\82¤\83N\83\89\83X\r
32     /// </summary>\r
33     public sealed class RegexMarkerPattern : IMarkerPattern\r
34     {\r
35         Regex regex;\r
36         HilightType type;\r
37         Color color;\r
38         /// <summary>\r
39         /// \83R\83\93\83X\83g\83\89\83N\83^\81[\r
40         /// </summary>\r
41         /// <param name="regex">regex\83I\83u\83W\83F\83N\83g</param>\r
42         /// <param name="type">\83n\83C\83\89\83C\83g\83^\83C\83v</param>\r
43         /// <param name="color">\90F</param>\r
44         public RegexMarkerPattern(Regex regex,HilightType type,Color color)\r
45         {\r
46             this.regex = regex;\r
47             this.type = type;\r
48             this.color = color;\r
49         }\r
50 \r
51         /// <summary>\r
52         /// \83}\81[\83J\81[\82ð\95Ô\82·\r
53         /// </summary>\r
54         /// <param name="lineHeadIndex">\8ds\93ª\82Ö\82Ì\83C\83\93\83f\83b\83N\83X\82ð\95\\82·</param>\r
55         /// <param name="s">\95\8e\9a\97ñ</param>\r
56         /// <returns>Marker\97ñ\8b\93\91Ì\82ð\95Ô\82·</returns>\r
57         public IEnumerable<Marker> GetMarker(int lineHeadIndex, string s)\r
58         {\r
59             foreach (Match m in this.regex.Matches(s))\r
60             {\r
61                 yield return Marker.Create(lineHeadIndex + m.Index, m.Length, this.type,this.color);\r
62             }\r
63         }\r
64     }\r
65     /// <summary>\r
66     /// MarkerPattern\83Z\83b\83g\r
67     /// </summary>\r
68     public sealed class MarkerPatternSet\r
69     {\r
70         MarkerCollection markers;\r
71         Dictionary<int, IMarkerPattern> set = new Dictionary<int, IMarkerPattern>();\r
72 \r
73         internal MarkerPatternSet(LineToIndexTable lti,MarkerCollection markers)\r
74         {\r
75             lti.CreateingLayout += lti_CreateingLayout;\r
76             this.markers = markers;\r
77         }\r
78 \r
79         void lti_CreateingLayout(object sender, CreateLayoutEventArgs e)\r
80         {\r
81             LineToIndexTable lti = (LineToIndexTable)sender;\r
82             foreach (int id in this.set.Keys)\r
83             {\r
84                 this.markers.RemoveAll(id, e.Index, e.Length);\r
85                 this.markers.AddRange(id, this.set[id].GetMarker(e.Index,e.Content));\r
86             }\r
87         }\r
88 \r
89         internal event EventHandler Updated;\r
90 \r
91         /// <summary>\r
92         /// WatchDog\82ð\92Ç\89Á\82·\82é\r
93         /// </summary>\r
94         /// <param name="id">\83}\81[\83J\81[ID</param>\r
95         /// <param name="dog">IMarkerPattern\83C\83\93\83^\81[\83t\83F\83C\83X</param>\r
96         public void Add(int id, IMarkerPattern dog)\r
97         {\r
98             this.set.Add(id, dog);\r
99             this.Updated(this, null);\r
100         }\r
101 \r
102         /// <summary>\r
103         /// \83}\81[\83J\81[ID\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82é\82©\82Ç\82¤\82©\82ð\92²\82×\82é\r
104         /// </summary>\r
105         /// <param name="id">\83}\81[\83J\81[ID</param>\r
106         /// <returns>\8aÜ\82Ü\82ê\82Ä\82¢\82ê\82Î\90^\81B\82»\82¤\82Å\82È\82¯\82ê\82Î\8bU</returns>\r
107         public bool Contains(int id)\r
108         {\r
109             return this.set.ContainsKey(id);\r
110         }\r
111 \r
112         /// <summary>\r
113         /// WatchDog\82ð\92Ç\89Á\82·\82é\r
114         /// </summary>\r
115         /// <param name="id">\83}\81[\83J\81[ID</param>\r
116         public void Remove(int id)\r
117         {\r
118             this.markers.Clear(id);\r
119             this.set.Remove(id);\r
120             this.Updated(this, null);\r
121         }\r
122     }\r
123 }