-
Notifications
You must be signed in to change notification settings - Fork 18
/
ScintillaEx.cs
75 lines (58 loc) · 1.93 KB
/
ScintillaEx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using ScintillaNET;
using System;
using System.Collections.Generic;
namespace ScintillaNET_Kitchen
{
public class ScintillaEx : Scintilla
{
#region Constructors & Private Fields
public ScintillaEx()
{
this.TextChanged += (object sender, EventArgs e) => this.UpdateLineMargin();
this.UpdateLineMargin();
}
private Dictionary<int, string> keywords = new Dictionary<int, string>();
private bool showLineMargin = true;
private int maxLineNumberCharLength;
#endregion
#region Properties
public bool ShowLineMargin
{
get { return this.showLineMargin; }
set
{
this.showLineMargin = value;
this.UpdateLineMargin();
}
}
#endregion
#region Public Methods
public new void SetKeywords(int sid, string keywords)
{
this.keywords[sid] = keywords;
base.SetKeywords(sid, String.IsNullOrEmpty(keywords) ? " " : keywords);
}
public string GetKeywords(int sid)
{
return this.keywords.ContainsKey(sid) ? this.keywords[sid] : "";
}
#endregion
#region Utility Methods
protected virtual void UpdateLineMargin()
{
var lineMarginChars = this.ShowLineMargin ? this.Lines.Count.ToString().Length : 0;
if (lineMarginChars != this.maxLineNumberCharLength)
{
this.DoUpdateLineMargin(lineMarginChars);
}
}
protected virtual void DoUpdateLineMargin(int lineMarginChars)
{
const int padding = 2;
this.Margins[0].Width = !this.ShowLineMargin ? 0
: this.TextWidth(Style.LineNumber, new string('9', lineMarginChars + 1)) + padding;
this.maxLineNumberCharLength = lineMarginChars;
}
#endregion
}
}