public bool Generate(Document doc, LineToIndexTable lti, bool force = true) { if (this.Hilighter == null) { return(false); } long nowTick = DateTime.Now.Ticks; bool sync = force || !this._IsSync; if (sync || Math.Abs(nowTick - this.lastUpdateTicks) >= AllowCallTicks) { for (int i = 0; i < lti.Count; i++) { this.HilightLine(lti, i); } this.Hilighter.Reset(); lti.ClearLayoutCache(); this.lastUpdateTicks = nowTick; this._IsSync = true; return(true); } return(false); }
internal void ReplaceRegexAll(LineToIndexTable layoutlines, Regex regex, string pattern, bool groupReplace) { for (int i = 0; i < layoutlines.Count; i++) { int lineHeadIndex = layoutlines.GetIndexFromLineNumber(i), lineLength = layoutlines.GetLengthFromLineNumber(i); int left = lineHeadIndex, right = lineHeadIndex; string output; output = regex.Replace(layoutlines[i], (m) => { if (groupReplace) { return(m.Result(pattern)); } else { return(pattern); } }); using (this.rwlock.WriterLock()) { //空行は削除する必要はない if (lineHeadIndex < this.buf.Count) { this.buf.RemoveRange(lineHeadIndex, lineLength); } this.buf.InsertRange(lineHeadIndex, output); } this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, lineHeadIndex, lineLength, output.Length, i)); } }
/// <summary> /// コンストラクター /// </summary> /// <param name="doc">ドキュメントオブジェクト</param> /// <remarks>docが複製されますが、プロパティは引き継がれません</remarks> public Document(Document doc) { if (doc == null) { this.buffer = new StringBuffer(); } else { this.buffer = new StringBuffer(doc.buffer); } this.buffer.Update = new DocumentUpdateEventHandler(buffer_Update); this.Update += new DocumentUpdateEventHandler((s, e) => { }); this.ChangeFireUpdateEvent += new EventHandler((s, e) => { }); this.StatusUpdate += new EventHandler((s, e) => { }); this.Markers = new MarkerCollection(); this.UndoManager = new UndoManager(); this._LayoutLines = new LineToIndexTable(this); this._LayoutLines.Clear(); this.MarkerPatternSet = new MarkerPatternSet(this._LayoutLines, this.Markers); this.MarkerPatternSet.Updated += WacthDogPattern_Updated; this.Selections = new SelectCollection(); this.CaretPostion = new TextPoint(); this.HideLineMarker = true; this.SelectGrippers = new GripperRectangle(new Gripper(), new Gripper()); this.SelectionChanged += new EventHandler((s, e) => { }); this.CaretChanged += (s, e) => { }; this.AutoIndentHook += (s, e) => { }; this.LineBreakChanged += (s, e) => { }; this.Dirty = false; }
public FastReplaceAllCommand(StringBuffer buffer, LineToIndexTable layoutlines, string targetPattern, string replacePattern, bool ci) { this.buffer = buffer; this.replacePattern = replacePattern; this.targetPattern = targetPattern; this.caseInsensitve = ci; this.layoutLines = layoutlines; }
public ReplaceAllCommand(StringBuffer buffer, LineToIndexTable layoutlines, Regex regex, string replacePattern, bool groupReplace) { this.buffer = buffer; this.regex = regex; this.replacePattern = replacePattern; this.groupReplace = groupReplace; this.layoutLines = layoutlines; }
public void Clear(LineToIndexTable lti) { for (int i = 0; i < lti.Count; i++) { lti.GetRaw(i).Syntax = null; } lti.ClearLayoutCache(); this._IsSync = false; }
public int Move(TextUnit unit, int count) { if (count == 0) { return(0); } Controller ctrl = textbox.Controller; LineToIndexTable layoutLine = textbox.LayoutLineCollection; int moved = this.MoveEndpointByUnit(TextPatternRangeEndpoint.Start, unit, count); this.ExpandToEnclosingUnit(unit); return(moved); }
public double[] GetBoundingRectangles() #endif { LineToIndexTable layoutLineCollection = this.textbox.LayoutLineCollection; TextPoint topLeft = layoutLineCollection.GetTextPointFromIndex(this.start); TextPoint bottomRight = this.textbox.LayoutLineCollection.GetTextPointFromIndex(IsNewLine(this.end) ? this.end - 1 : this.end); #if METRO || WINDOWS_UWP float dpi; Util.GetDpi(out dpi, out dpi); double scale = dpi / 96; Point topLeftPos = this.textbox.GetPostionFromTextPoint(topLeft); Point bottomRightPos = this.textbox.GetPostionFromTextPoint(bottomRight); topLeftPos = Util.GetPointInWindow(topLeftPos.Scale(scale), textbox); bottomRightPos = Util.GetPointInWindow(bottomRightPos.Scale(scale), textbox); #endif #if WPF Point topLeftPos = this.textbox.GetPostionFromTextPoint(topLeft); Point bottomRightPos = this.textbox.GetPostionFromTextPoint(bottomRight); topLeftPos = this.textbox.PointToScreen(topLeftPos); bottomRightPos = this.textbox.PointToScreen(bottomRightPos); #endif double width = bottomRightPos.X - topLeftPos.X; if (width == 0) { width = 1; } Rectangle rect = new Rectangle(topLeftPos.X, topLeftPos.Y, width, bottomRightPos.Y - topLeftPos.Y + layoutLineCollection.GetLineHeight(bottomRight)); #if METRO || WINDOWS_UWP rectangles = new double[4] { rect.X, rect.Y, rect.Width, rect.Height }; #endif #if WPF return(new double[4] { rect.X, rect.Y, rect.Width, rect.Height }); #endif }
public bool Generate(Document doc, LineToIndexTable lti, bool force = true) { if (doc.Length == 0) { return(false); } long nowTick = DateTime.Now.Ticks; bool sync = force || !this._IsSync; if (sync && Math.Abs(nowTick - this.lastUpdateTicks) >= AllowCallTicks) { this.GenerateFolding(doc, lti, 0, doc.Length - 1); this.lastUpdateTicks = nowTick; this._IsSync = true; return(true); } return(false); }
void GenerateFolding(Document doc, LineToIndexTable lti, int start, int end) { if (start > end) { throw new ArgumentException("start <= endである必要があります"); } if (this.FoldingStrategy != null) { //再生成するとすべて展開状態になってしまうので、閉じてるやつだけを保存しておく FoldingItem[] closed_items = this.FoldingCollection.Where((e) => { return(!e.Expand); }).ToArray(); this.FoldingCollection.Clear(); var items = this.FoldingStrategy.AnalyzeDocument(doc, start, end) .Select((item) => item); this.FoldingCollection.AddRange(items); this.FoldingCollection.ApplyExpandStatus(closed_items); } }
private void HilightLine(LineToIndexTable lti, int row) { //シンタックスハイライトを行う List <SyntaxInfo> syntax = new List <SyntaxInfo>(); string str = lti[row]; int level = this.Hilighter.DoHilight(str, str.Length, (s) => { if (s.type == TokenType.None || s.type == TokenType.Control) { return; } if (str[s.index + s.length - 1] == Document.NewLine) { s.length--; } syntax.Add(new SyntaxInfo(s.index, s.length, s.type)); }); LineToIndexTableData lineData = lti.GetRaw(row); lineData.Syntax = syntax.ToArray(); }
internal void ReplaceAll(LineToIndexTable layoutlines, string target, string pattern, bool ci = false) { TextSearch ts = new TextSearch(target, ci); char[] pattern_chars = pattern.ToCharArray(); for (int i = 0; i < layoutlines.Count; i++) { int lineHeadIndex = layoutlines.GetIndexFromLineNumber(i), lineLength = layoutlines.GetLengthFromLineNumber(i); int left = lineHeadIndex, right = lineHeadIndex; int newLineLength = lineLength; while ((right = ts.IndexOf(this.buf, left, lineHeadIndex + newLineLength)) != -1) { using (this.rwlock.WriterLock()) { this.buf.RemoveRange(right, target.Length); this.buf.InsertRange(right, pattern_chars); } left = right + pattern.Length; newLineLength += pattern.Length - target.Length; } this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, lineHeadIndex, lineLength, newLineLength, i)); } }
public void DrawOneLine(Document doc, LineToIndexTable lti, int row, double x, double y) { throw new NotImplementedException(); }
internal bool IsFirstLine(LineToIndexTable layoutLines, int row) { int firstRow = layoutLines.GetLineNumberFromIndex(this.Start); return(row == firstRow); }
public int MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, int count) { if (count == 0) { return(0); } int moved = 0; TextPoint caret = TextPoint.Null, newCaret = TextPoint.Null; Controller ctrl = textbox.Controller; LineToIndexTable layoutLine = textbox.LayoutLineCollection; if (endpoint == TextPatternRangeEndpoint.Start) { caret = layoutLine.GetTextPointFromIndex(this.start); } else if (endpoint == TextPatternRangeEndpoint.End) { caret = layoutLine.GetTextPointFromIndex(this.end); } switch (unit) { case TextUnit.Character: newCaret = ctrl.GetNextCaret(caret, count, MoveFlow.Character, out moved); break; case TextUnit.Format: case TextUnit.Word: newCaret = ctrl.GetNextCaret(caret, count, MoveFlow.Word, out moved); break; case TextUnit.Line: newCaret = ctrl.GetNextCaret(caret, count, MoveFlow.Line, out moved); break; case TextUnit.Paragraph: newCaret = ctrl.GetNextCaret(caret, count, MoveFlow.Paragraph, out moved); break; case TextUnit.Page: case TextUnit.Document: this.start = 0; this.end = this.textbox.Document.Length - 1; moved = 1; break; } if (endpoint == TextPatternRangeEndpoint.Start) { this.start = layoutLine.GetIndexFromTextPoint(newCaret); if (this.start > this.end) { this.end = this.start; } } else if (endpoint == TextPatternRangeEndpoint.End) { this.end = layoutLine.GetIndexFromTextPoint(newCaret); if (this.end < this.start) { this.start = this.end; } } return(moved); }
internal MarkerPatternSet(LineToIndexTable lti, MarkerCollection markers) { this.markers = markers; }
public List <LineToIndexTableData> BreakLine(Document doc, LineToIndexTable layoutLineCollection, int startIndex, int endIndex, double wrapwidth) { throw new NotImplementedException(); }
public void DrawOneLine(Document doc, LineToIndexTable lti, int row, double x, double y, PreDrawOneLineHandler PreDrawOneLine) { int lineLength = lti.GetLengthFromLineNumber(row); if (lineLength == 0 || this.render == null || this.render.IsDisposed) { return; } MyTextLayout layout = (MyTextLayout)lti.GetLayout(row); if (PreDrawOneLine != null) { PreDrawOneLine(layout, lti, row, x, y); } if (layout.Markers != null) { foreach (Marker sel in layout.Markers) { if (sel.length == 0 || sel.start == -1) { continue; } Color4 color = new Color4() { Alpha = sel.color.A, Red = sel.color.R, Blue = sel.color.B, Green = sel.color.G }; if (sel.hilight == HilightType.Url) { color = this.Url; } this.DrawMarkerEffect(layout, sel.hilight, sel.start, sel.length, x, y, sel.isBoldLine, color); } } if (layout.Selects != null) { foreach (Selection sel in layout.Selects) { if (sel.length == 0 || sel.start == -1) { continue; } this.DrawMarkerEffect(layout, HilightType.Select, sel.start, sel.length, x, y, false); } } if (this.ShowFullSpace || this.ShowHalfSpace || this.ShowTab) { string str = lti[row]; D2D.GeometryRealization geo = null; for (int i = 0; i < lineLength; i++) { Point pos = new Point(0, 0); if (this.ShowTab && str[i] == '\t') { pos = layout.GetPostionFromIndex(i); geo = this._factory.CreateSymbol(ShowSymbol.Tab, this.format); } else if (this.ShowFullSpace && str[i] == ' ') { pos = layout.GetPostionFromIndex(i); geo = this._factory.CreateSymbol(ShowSymbol.FullSpace, this.format); } else if (this.ShowHalfSpace && str[i] == ' ') { pos = layout.GetPostionFromIndex(i); geo = this._factory.CreateSymbol(ShowSymbol.HalfSpace, this.format); } if (geo != null) { var old_trans = this.render.Transform; this.render.Transform = SharpDX.Matrix3x2.Translation(new Vector2((float)(pos.X + x), (float)(pos.Y + y))); this.render.DrawGeometryRealization(geo, this._factory.GetSolidColorBrush(this.ControlChar)); this.render.Transform = old_trans; geo = null; } } } layout.Draw(this.render, (float)x, (float)y, this._factory.GetSolidColorBrush(this.Foreground)); }
public void Clear(LineToIndexTable lti) { this.FoldingCollection.Clear(); this._IsSync = false; }