//public static char[] Parse(string text,string separators) //{ // //string Result=""; // System.Text.StringBuilder Result=new System.Text.StringBuilder (); // text= " " + text +" "; // char c; // for(int i = 0; i <text.Length;i++) // { // c = text[i]; // if (separators.IndexOf (c)>=0 ) // Result.Append (' '); // else // Result.Append ('.'); // } // return Result.ToString().ToCharArray (); //} public static void AddPatternString(string text, Row row, Pattern pattern, TextStyle style, Segment segment, bool hasError) { Word x = row.Add(text); x.Style = style; x.Pattern = pattern; x.HasError = hasError; x.Segment = segment; }
public bool RowContainsFormats(Row row) { foreach (FormatRange frang in this) { if (frang.Bounds.FirstRow <= row.Index && frang.Bounds.LastRow >= row.Index) return true; } return false; }
private void ParseText(Row Row, Segment CurrentSegment, string Text) { int CurrentPosition = 0; bool HasComplex = true; while (true) { ScanResult_Word Word = GetNextWord(Text, CurrentSegment, CurrentPosition, ref HasComplex); if (!Word.HasContent) { ParseTools.AddString(Text.Substring(CurrentPosition), Row, CurrentSegment.BlockType.Style, CurrentSegment); break; } else { ParseTools.AddString(Text.Substring(CurrentPosition, Word.Position - CurrentPosition), Row, CurrentSegment.BlockType.Style, CurrentSegment); ParseTools.AddPatternString(Word.Token, Row, Word.Pattern, Word.ParentList.Style, CurrentSegment, false); CurrentPosition = Word.Position + Word.Token.Length; } } }
/// <summary> /// Forces a row to be parsed /// </summary> /// <param name="r">Row to parse</param> /// <param name="ParseKeywords">true if keywords and operators should be parsed</param> public void ParseRow(Row r, bool ParseKeywords) { int index = this.IndexOf(r); if (index >= 0) { if (index > 0) if (this[index - 1].InQueue) ParseRow(this[index - 1]); Parser.ParseLine(index, false); if (ParseKeywords) Parser.ParseLine(index, true); } int i = this.ParseQueue.IndexOf(r); if (i >= 0) this.ParseQueue.RemoveAt(i); r.InQueue = false; }
private int ParseRows(Row r) { return ParseRows(r, false); }
/// <summary> /// Add a new row with the specified text to the bottom of the document /// </summary> /// <param name="Text">Text to add</param> /// <param name="StoreUndo">true if and undo action should be added to the undo stack</param> /// <returns>The row that was added</returns> public Row Add(string Text, bool StoreUndo) { Row xtl = new Row(); mDocument.Add(xtl); xtl.Document = this; xtl.Text = Text; return xtl; }
public virtual void InvokeBookmarkRemoved(Row r) { OnBookmarkRemoved(r); }
protected internal void OnApplyFormatRanges(Row row) { if (this.FormatRanges == null) return; if (!this.FormatRanges.RowContainsFormats(row) || row.RowState != RowState.AllParsed) { row.FormattedWords = row.mWords; } else { row.FormattedWords = new WordCollection(); int i = 0; int l = 0; int x = 0; int ri = row.Index; foreach (char c in row.Text) { Word w = row[i]; FormatRange fr = FormatRanges.MergeFormats(x, ri); Word wn = new Word(); wn.Text = c.ToString(); if (fr == null) { wn.Style = w.Style; } else { wn.Style = new TextStyle(); if (w.Style == null) w.Style = new TextStyle(); wn.Style.BackColor = (fr.BackColor == Color.Empty) ? w.Style.BackColor : fr.BackColor; wn.Style.ForeColor = (fr.ForeColor == Color.Empty) ? w.Style.ForeColor : fr.ForeColor; wn.InfoTip = fr.InfoTip; /*wn.Style.Bold = false; wn.Style.Italic = true; wn.Style.Underline = false;*/ if (fr.WaveColor != Color.Empty) { wn.HasError = true; wn.ErrorColor = fr.WaveColor; } } wn.Type = w.Type; wn.Segment = w.Segment; row.FormattedWords.Add(wn); l++; if (l == row[i].Text.Length) { i++; l = 0; } x++; } } }
public virtual void InvokeBreakPointRemoved(Row r) { OnBreakPointRemoved(r); }
/// <summary> /// Returns the index of a given row /// </summary> /// <param name="xtr">row to find</param> /// <returns>Index of the given row</returns> public int IndexOf(Row xtr) { return mDocument.IndexOf(xtr); }
public unsafe static void AddString(string text,Row row,TextStyle style,Segment segment) { if (text == "") return; string[] spl = WordSplitter.Split(text); string w = null; for (int i = 0; i < spl.Length; i++) { w = spl[i]; Word word = row.Add(w); word.Style = style; word.Segment = segment; if (w == " ") { word.Type = WordType.xtSpace; } else if (w == "\t") { word.Type = WordType.xtTab; } } /*if (Text=="") return; System.Text.StringBuilder CurrentWord=new System.Text.StringBuilder(); char[] Buff=Text.ToCharArray(); fixed (char* c = &Buff[0]) { for (int i=0;i<Text.Length;i++) { if (c[i]==' ' || c[i]=='\t') { if (CurrentWord.Length != 0) { Word word = Row.Add (CurrentWord.ToString ()); word.Style =Style; word.Segment =Segment; CurrentWord =new System.Text.StringBuilder(); } Word ws=Row.Add (c[i].ToString ()); if (c[i]==' ') ws.Type= WordType.xtSpace; else ws.Type= WordType.xtTab; ws.Style = Style ; ws.Segment = Segment; } else CurrentWord.Append (c[i].ToString ()); } if (CurrentWord.Length != 0) { Word word=Row.Add (CurrentWord.ToString ()); word.Style =Style; word.Segment =Segment; } }*/ }
private void RenderCollapsed(Row r,Row TrueRow,int i,string ImagePath,string guid) { Out("<div style=\"display:none;\" id=\"closed" + guid+"_"+i.ToString () + "\">"); string img= "plus.gif"; try { if (TrueRow.Expansion_StartSegment.Parent.Parent == null) img = "PlusNoLines.gif"; } catch { } Out ("<img src=\"" + ImagePath + img +"\" align=top onclick=\"open" + guid+"_"+i.ToString () +".style.display='block'; closed" + guid+"_"+i.ToString () +".style.display='none'; \">"); foreach (Word w in r) { write (w.Text,w.Style); } Out("</div>"); }
private Size MeasureRow(Row xtr, int Count, int OffsetX) { int width = 0; int taborig = -Control.View.FirstVisibleColumn * Control.View.CharWidth + Control.View.TextMargin; int xpos = Control.View.TextMargin - Control.View.ClientAreaStart; if (xtr.InQueue) { SetStringFont(false, false, false); int Padd = Math.Max(Count - xtr.Text.Length, 0); string PaddStr = new String(' ', Padd); string TotStr = xtr.Text + PaddStr; width = GFX.StringBuffer.MeasureTabbedString(TotStr.Substring(0, Count), Control.PixelTabSize).Width; } else { int CharNo = 0; int TotWidth = 0; int CharPos = 0; foreach (Word w in xtr.FormattedWords) { if (w.Type == WordType.xtWord && w.Style != null) SetStringFont(w.Style.Bold, w.Style.Italic, w.Style.Underline); else SetStringFont(false, false, false); if (w.Text.Length + CharNo >= Count || w == xtr.FormattedWords[xtr.FormattedWords.Count - 1]) { CharPos = Count - CharNo; int MaxChars = Math.Min(CharPos, w.Text.Length); TotWidth += GFX.StringBuffer.DrawTabbedString(w.Text.Substring(0, MaxChars), xpos + TotWidth, 0, taborig, Control.PixelTabSize) .Width; width = TotWidth; break; } else { TotWidth += GFX.StringBuffer.DrawTabbedString(w.Text, xpos + TotWidth, 0, taborig, Control.PixelTabSize).Width; CharNo += w.Text.Length; } } SetStringFont(false, false, false); int Padd = Math.Max(Count - xtr.Text.Length, 0); string PaddStr = new String(' ', Padd); width += GFX.StringBuffer.DrawTabbedString(PaddStr, xpos + TotWidth, 0, taborig, Control.PixelTabSize).Width; } return new Size(width, 0); // return GFX.BackBuffer.MeasureTabbedString (xtr.Text.Substring (0,Count),Control.PixelTabSize); }
/// <summary> /// Implementation of the IPainter MeasureRow method. /// </summary> /// <param name="xtr">Row to measure</param> /// <param name="Count">Last char index</param> /// <returns>The size of the row in pixels</returns> public Size MeasureRow(Row xtr, int Count) { return MeasureRow(xtr, Count, 0); }
/// <summary> /// Expand a given row /// </summary> /// <param name="r">Row to expand</param> private void ExpandRow(Row r) { //add rows to visible list... Row start = r.Expansion_StartRow; Row end = r.Expansion_EndRow; int count = end.Index - start.Index - 1; int startIndex = start.Index + 1; int visIndex = start.VisibleIndex + 1; int i = 0; while (i <= count) { Row tmpRow = this[startIndex + i]; this.VisibleRows.Insert(visIndex, tmpRow); if (tmpRow.Expansion_StartSegment != null) if (tmpRow.Expansion_StartSegment.Expanded == false) { tmpRow = tmpRow.Expansion_StartSegment.EndRow; i = tmpRow.Index - startIndex; } visIndex++; i++; } //ResetVisibleRows (); }
private void OnRowParsed(Row r) { if (RowParsed != null) RowParsed(this, new RowEventArgs(r)); this.OnApplyFormatRanges(r); }
public virtual void InvokeBreakPointAdded(Row r) { OnBreakPointAdded(r); }
// private void OnRowAdded(Row r) // { // if (RowAdded != null) // RowAdded(this,new RowEventArgs(r)); // } private void OnRowDeleted(Row r) { if (RowDeleted != null) RowDeleted(this, new RowEventArgs(r)); }
/// <summary> /// /// </summary> /// <param name="row"></param> public RowEventArgs(Row row) { this.Row = row; }
protected virtual void OnBreakPointRemoved(Row r) { if (BreakPointRemoved != null) BreakPointRemoved(this, new RowEventArgs(r)); }
public virtual void InvokeBookmarkAdded(Row r) { OnBookmarkAdded(r); }
/// <summary> /// Call this method to make the document raise the RowParsed event /// </summary> /// <param name="row"></param> public void InvokeRowParsed(Row row) { this.OnRowParsed(row); }
/// <summary> /// Call this method to ensure that a specific row is fully parsed /// </summary> /// <param name="Row"></param> public void EnsureParsed(Row Row) { this.ParseAll(); Parser.ParseLine(Row.Index, true); }
protected virtual void OnBookmarkRemoved(Row r) { if (BookmarkRemoved != null) BookmarkRemoved(this, new RowEventArgs(r)); }
/// <summary> /// Insert a text at the specified row index /// </summary> /// <param name="Text">Text to insert</param> /// <param name="index">Row index where the text should be inserted</param> /// <param name="StoreUndo">true if and undo action should be added to the undo stack</param> /// <returns>The row that was inserted</returns> public Row Insert(string Text, int index, bool StoreUndo) { Row xtl = new Row(); xtl.Document = this; mDocument.Insert(index, xtl); xtl.Text = Text; if (StoreUndo) { UndoBlock undo = new UndoBlock(); undo.Text = Text; undo.Position.Y = this.IndexOf(xtl); AddToUndoList(undo); } //this.ResetVisibleRows (); return xtl; }
/// <summary> /// Toggle expansion of a given row /// </summary> /// <param name="r"></param> public void ToggleRow(Row r) { if (!mFolding) return; if (r.Expansion_EndRow == null || r.Expansion_StartRow == null) return; // if (r.IsCollapsed) // { // r.Expansion_StartSegment.Expanded = true; // ExpandRow(r); // } // else // { // r.Expansion_StartSegment.Expanded = false; // CollapseRow(r); // } if (r.CanFold) r.Expanded = !r.Expanded; ResetVisibleRows(); OnChange(); }
private int ParseRows(Row r, bool Keywords) { int rowLimit = 1000; if (!Keywords) { int index = this.IndexOf(r); int count = 0; while (r.InQueue && count < rowLimit) { if (index >= 0) { if (index > 0) if (this[index - 1].InQueue) ParseRow(this[index - 1]); Parser.ParseLine(index, false); } int i = this.ParseQueue.IndexOf(r); if (i >= 0) this.ParseQueue.RemoveAt(i); r.InQueue = false; index++; count++; r = this[index]; if (r == null) break; } return count; } else { int index = this.IndexOf(r); if (index == -1 || r.InKeywordQueue == false) { this.KeywordQueue.Remove(r); return 0; } int count = 0; while (r.InKeywordQueue && count < rowLimit) { if (index >= 0) { if (index > 0) if (this[index - 1].InQueue) ParseRow(this[index - 1]); Parser.ParseLine(index, true); } index++; count++; r = this[index]; if (r == null) break; } return count; } }
/// <summary> /// Collapse a given row /// </summary> /// <param name="r">Row to collapse</param> private void CollapseRow(Row r) { //remove rows from visible list Row start = r.Expansion_StartRow; Row end = r.Expansion_EndRow; int count = end.VisibleIndex - start.VisibleIndex - 1; int startIndex = start.VisibleIndex + 1; for (int i = 0; i <= count; i++) { this.VisibleRows.RemoveAt(startIndex); } }
/// <summary> /// Forces a row to be parsed /// </summary> /// <param name="r">Row to parse</param> public void ParseRow(Row r) { ParseRow(r, false); }
private ScanResult_Segment GetNextChildSegment(Row Row, Segment CurrentSegment, int StartPos) { //this row has no text , just bail out... if (StartPos >= Row.Text.Length) return new ScanResult_Segment(); ScanResult_Segment Result = new ScanResult_Segment(); Result.HasContent = false; //make sure we have no content in this object Result.IsEndSegment = false; //nope , were looking for start blocks here BlockType ChildBlock; //foreach (BlockType ChildBlock in CurrentSegment.BlockType.ChildBlocks) BlockTypeCollection blocks = CurrentSegment.BlockType.ChildBlocks; for (int i = 0; i < blocks.Count; i++) { ChildBlock = blocks[i]; //scan each scope in each childblock //foreach (Scope Scope in ChildBlock.ScopePatterns) Scope Scope; ScopeCollection scopeColl = ChildBlock.ScopePatterns; for (int j = 0; j < scopeColl.Count; j++) { Scope = scopeColl[j]; PatternScanResult psr = Scope.Start.IndexIn(Row.Text, StartPos, Scope.CaseSensitive, Separators); int CurrentPosition = psr.Index; if ((!Result.HasContent || CurrentPosition < Result.Position) && psr.Token != "") { //we found a better match //store this new match Result.Pattern = Scope.Start; Result.Position = CurrentPosition; Result.Token = psr.Token; Result.HasContent = true; Result.BlockType = ChildBlock; Result.Scope = Scope; if (Scope.NormalizeCase) if (!Scope.Start.IsComplex) Result.Token = Scope.Start.StringPattern; } } } //no result , new ScanResult_Segment(); if (!Result.HasContent) return new ScanResult_Segment(); return Result; }