4 namespace FooEditEngine
6 class FoldingGenerator : ILineInfoGenerator
8 public FoldingCollection FoldingCollection = new FoldingCollection();
9 const long AllowCallTicks = 1000 * 10000; //see.DateTime.Ticks プロパティ
10 long lastUpdateTicks = DateTime.Now.Ticks;
11 IFoldingStrategy _folding;
14 public IFoldingStrategy FoldingStrategy
22 this._folding = value;
24 this.FoldingCollection.Clear();
28 public void Clear(LineToIndexTable lti)
30 this.FoldingCollection.Clear();
34 public bool Generate(Document doc,LineToIndexTable lti, bool force = true)
38 long nowTick = DateTime.Now.Ticks;
39 bool sync = force || !this._IsSync;
40 if (sync && Math.Abs(nowTick - this.lastUpdateTicks) >= AllowCallTicks)
42 this.GenerateFolding(doc, lti, 0, doc.Length - 1);
43 this.lastUpdateTicks = nowTick;
50 void GenerateFolding(Document doc, LineToIndexTable lti,int start, int end)
53 throw new ArgumentException("start <= endである必要があります");
54 if (this.FoldingStrategy != null)
56 //再生成するとすべて展開状態になってしまうので、閉じてるやつだけを保存しておく
57 FoldingItem[] closed_items = this.FoldingCollection.Where((e) => { return !e.Expand; }).ToArray();
59 this.FoldingCollection.Clear();
61 var items = this.FoldingStrategy.AnalyzeDocument(doc, start, end)
64 int startRow = lti.GetLineNumberFromIndex(item.Start);
65 int endRow = lti.GetLineNumberFromIndex(item.End);
66 return startRow != endRow;
68 .Select((item) => item);
69 this.FoldingCollection.AddRange(items);
71 this.FoldingCollection.ApplyExpandStatus(closed_items);
75 public void Update(Document doc, int startIndex, int insertLength, int removeLength)
77 this.FoldingCollection.UpdateData(doc, startIndex, insertLength, removeLength);
79 this.lastUpdateTicks = DateTime.Now.Ticks;