row.cs
来自「Fireball.CodeEditor is an source code ed」· CS 代码 · 共 1,126 行 · 第 1/2 页
CS
1,126 行
else
ws += ' ';
i--;
if (i <= 0)
break;
}
return ws;
}
/// <summary>
/// Returns the index of this row in the owner SyntaxDocument.
/// </summary>
public int Index
{
get { return this.Document.IndexOf(this); }
}
/// <summary>
/// Returns the visible index of this row in the owner SyntaxDocument
/// </summary>
public int VisibleIndex
{
get
{
int i = this.Document.VisibleRows.IndexOf(this);
if (i == -1)
{
if (this.StartSegment != null)
{
if (this.StartSegment.StartRow != null)
{
if (this.StartSegment.StartRow != this)
return this.StartSegment.StartRow.VisibleIndex;
else
return this.Index;
}
else
return this.Index;
}
else
return this.Index;
}
else
return this.Document.VisibleRows.IndexOf(this);
}
}
/// <summary>
/// Returns the next visible row.
/// </summary>
public Row NextVisibleRow
{
get
{
int i = this.VisibleIndex;
if (i > this.Document.VisibleRows.Count)
return null;
if (i + 1 < this.Document.VisibleRows.Count)
{
return this.Document.VisibleRows[i + 1];
}
else
return null;
}
}
/// <summary>
/// Returns the next row
/// </summary>
public Row NextRow
{
get
{
int i = this.Index;
if (i + 1 <= this.Document.Lines.Length - 1)
return this.Document[i + 1];
else
return null;
}
}
/// <summary>
/// Returns the first visible row before this row.
/// </summary>
public Row PrevVisibleRow
{
get
{
int i = this.VisibleIndex;
if (i < 0)
return null;
if (i - 1 >= 0)
return this.Document.VisibleRows[i - 1];
else
return null;
}
}
/// <summary>
/// Returns true if the row is collapsed
/// </summary>
public bool IsCollapsed
{
get
{
if (this.Expansion_StartSegment != null)
if (this.Expansion_StartSegment.Expanded == false)
return true;
return false;
}
}
/// <summary>
/// Returns true if this row is the last part of a collepsed segment
/// </summary>
public bool IsCollapsedEndPart
{
get
{
if (this.Expansion_EndSegment != null)
if (this.Expansion_EndSegment.Expanded == false)
return true;
return false;
}
}
/// <summary>
/// Returns true if this row can fold
/// </summary>
public bool CanFold
{
get { return (this.Expansion_StartSegment != null && this.Expansion_StartSegment.EndRow != null && this.Document.IndexOf(this.Expansion_StartSegment.EndRow) != 0); }
}
/// <summary>
/// Gets or Sets if this row is expanded.
/// </summary>
public bool Expanded
{
get
{
if (this.CanFold)
{
return (this.Expansion_StartSegment.Expanded);
}
else
{
return false;
}
}
set
{
if (this.CanFold)
{
this.Expansion_StartSegment.Expanded = value;
}
}
}
public string ExpansionText
{
get { return this.Expansion_StartSegment.Scope.ExpansionText; }
set
{
Scope oScope = this.Expansion_StartSegment.Scope;
Scope oNewScope = new Scope();
oNewScope.CaseSensitive = oScope.CaseSensitive;
oNewScope.CauseIndent = oScope.CauseIndent;
oNewScope.DefaultExpanded = oScope.DefaultExpanded;
oNewScope.EndPatterns = oScope.EndPatterns;
oNewScope.NormalizeCase = oScope.NormalizeCase;
oNewScope.Parent = oScope.Parent;
oNewScope.SpawnBlockOnEnd = oScope.SpawnBlockOnEnd;
oNewScope.SpawnBlockOnStart = oScope.SpawnBlockOnStart;
oNewScope.Start = oScope.Start;
oNewScope.Style = oScope.Style;
oNewScope.ExpansionText = value;
this.Expansion_StartSegment.Scope = oNewScope;
this.Document.InvokeChange();
}
}
/// <summary>
/// Returns true if this row is the end part of a collapsable segment
/// </summary>
public bool CanFoldEndPart
{
get { return (this.Expansion_EndSegment != null); }
}
/// <summary>
/// For public use only
/// </summary>
public bool HasExpansionLine
{
get
{
return (this.EndSegment.Parent != null);
}
}
/// <summary>
/// Returns the last row of a collapsable segment
/// (this only applies if this row is the start row of the segment)
/// </summary>
public Row Expansion_EndRow
{
get
{
if (this.CanFold)
return this.Expansion_StartSegment.EndRow;
else
return this;
}
}
/// <summary>
/// Returns the first row of a collapsable segment
/// (this only applies if this row is the last row of the segment)
/// </summary>
public Row Expansion_StartRow
{
get
{
if (this.CanFoldEndPart)
return this.Expansion_EndSegment.StartRow;
else
return this;
}
}
/// <summary>
/// Adds a word object to this row
/// </summary>
/// <param name="word">Word object</param>
public void Add(Word word)
{
this.mWords.Add(word);
}
/// <summary>
/// For public use only
/// </summary>
public Row VirtualCollapsedRow
{
get
{
Row r = new Row();
foreach (Word w in this)
{
if (this.Expansion_StartSegment == w.Segment)
break;
r.Add(w);
}
Word wo = r.Add(this.CollapsedText);
wo.Style = new TextStyle();
wo.Style.BackColor = Color.Silver;
wo.Style.ForeColor = Color.DarkBlue;
wo.Style.Bold = true;
bool found = false;
if (this.Expansion_EndRow != null)
{
foreach (Word w in this.Expansion_EndRow)
{
if (found)
r.Add(w);
if (w == this.Expansion_EndRow.Expansion_EndSegment.EndWord)
found = true;
}
}
return r;
}
}
/// <summary>
/// Returns the text that should be displayed if the row is collapsed.
/// </summary>
public string CollapsedText
{
get
{
string str = "";
int pos = 0;
foreach (Word w in this)
{
pos += w.Text.Length;
if (w.Segment == this.Expansion_StartSegment)
{
str = this.Text.Substring(pos).Trim();
break;
}
}
if (this.Expansion_StartSegment.Scope.ExpansionText != "")
str = this.Expansion_StartSegment.Scope.ExpansionText.Replace("***", str);
return str;
}
}
/// <summary>
/// Returns the index of a specific Word object
/// </summary>
/// <param name="word">Word object to find</param>
/// <returns>index of the word in the row</returns>
public int IndexOf(Word word)
{
return mWords.IndexOf(word);
}
/// <summary>
/// For public use only
/// </summary>
/// <param name="PatternList"></param>
/// <param name="StartWord"></param>
/// <param name="IgnoreStartWord"></param>
/// <returns></returns>
public Word FindRightWordByPatternList(PatternList PatternList, Word StartWord, bool IgnoreStartWord)
{
int i = StartWord.Index;
if (IgnoreStartWord)
i++;
Word w = null;
while (i < mWords.Count)
{
w = this[i];
if (w.Pattern != null)
{
if (w.Pattern.Parent != null)
{
if (w.Pattern.Parent == PatternList && w.Type != WordType.xtSpace && w.Type != WordType.xtTab)
{
return w;
}
}
}
i++;
}
return null;
}
/// <summary>
/// For public use only
/// </summary>
/// <param name="PatternListName"></param>
/// <param name="StartWord"></param>
/// <param name="IgnoreStartWord"></param>
/// <returns></returns>
public Word FindRightWordByPatternListName(string PatternListName, Word StartWord, bool IgnoreStartWord)
{
int i = StartWord.Index;
if (IgnoreStartWord)
i++;
Word w = null;
while (i < mWords.Count)
{
w = this[i];
if (w.Pattern != null)
{
if (w.Pattern.Parent != null)
{
if (w.Pattern.Parent.Name == PatternListName && w.Type != WordType.xtSpace && w.Type != WordType.xtTab)
{
return w;
}
}
}
i++;
}
return null;
}
/// <summary>
/// For public use only
/// </summary>
/// <param name="PatternList"></param>
/// <param name="StartWord"></param>
/// <param name="IgnoreStartWord"></param>
/// <returns></returns>
public Word FindLeftWordByPatternList(PatternList PatternList, Word StartWord, bool IgnoreStartWord)
{
int i = StartWord.Index;
if (IgnoreStartWord)
i--;
Word w = null;
while (i >= 0)
{
w = this[i];
if (w.Pattern != null)
{
if (w.Pattern.Parent != null)
{
if (w.Pattern.Parent == PatternList && w.Type != WordType.xtSpace && w.Type != WordType.xtTab)
{
return w;
}
}
}
i--;
}
return null;
}
/// <summary>
/// For public use only
/// </summary>
/// <param name="PatternListName"></param>
/// <param name="StartWord"></param>
/// <param name="IgnoreStartWord"></param>
/// <returns></returns>
public Word FindLeftWordByPatternListName(string PatternListName, Word StartWord, bool IgnoreStartWord)
{
int i = StartWord.Index;
if (IgnoreStartWord)
i--;
Word w = null;
while (i >= 0)
{
w = this[i];
if (w.Pattern != null)
{
if (w.Pattern.Parent != null)
{
if (w.Pattern.Parent.Name == PatternListName && w.Type != WordType.xtSpace && w.Type != WordType.xtTab)
{
return w;
}
}
}
i--;
}
return null;
}
/// <summary>
/// For public use only
/// </summary>
/// <param name="BlockType"></param>
/// <param name="StartWord"></param>
/// <param name="IgnoreStartWord"></param>
/// <returns></returns>
public Word FindLeftWordByBlockType(BlockType BlockType, Word StartWord, bool IgnoreStartWord)
{
int i = StartWord.Index;
if (IgnoreStartWord)
i--;
Word w = null;
while (i >= 0)
{
w = this[i];
if (w.Segment.BlockType == BlockType && w.Type != WordType.xtSpace && w.Type != WordType.xtTab)
{
return w;
}
i--;
}
return null;
}
/// <summary>
/// For public use only
/// </summary>
/// <param name="BlockType"></param>
/// <param name="StartWord"></param>
/// <param name="IgnoreStartWord"></param>
/// <returns></returns>
public Word FindRightWordByBlockType(BlockType BlockType, Word StartWord, bool IgnoreStartWord)
{
int i = StartWord.Index;
if (IgnoreStartWord)
i++;
Word w = null;
while (i < mWords.Count)
{
w = this[i];
if (w.Segment.BlockType == BlockType && w.Type != WordType.xtSpace && w.Type != WordType.xtTab)
{
return w;
}
i++;
}
return null;
}
/// <summary>
/// For public use only
/// </summary>
/// <param name="BlockTypeName"></param>
/// <param name="StartWord"></param>
/// <param name="IgnoreStartWord"></param>
/// <returns></returns>
public Word FindLeftWordByBlockTypeName(string BlockTypeName, Word StartWord, bool IgnoreStartWord)
{
int i = StartWord.Index;
if (IgnoreStartWord)
i--;
Word w = null;
while (i >= 0)
{
w = this[i];
if (w.Segment.BlockType.Name == BlockTypeName && w.Type != WordType.xtSpace && w.Type != WordType.xtTab)
{
return w;
}
i--;
}
return null;
}
/// <summary>
/// For public use only
/// </summary>
/// <param name="BlockTypeName"></param>
/// <param name="StartWord"></param>
/// <param name="IgnoreStartWord"></param>
/// <returns></returns>
public Word FindRightWordByBlockTypeName(string BlockTypeName, Word StartWord, bool IgnoreStartWord)
{
int i = StartWord.Index;
if (IgnoreStartWord)
i++;
Word w = null;
while (i < mWords.Count)
{
w = this[i];
if (w.Segment.BlockType.Name == BlockTypeName && w.Type != WordType.xtSpace && w.Type != WordType.xtTab)
{
return w;
}
i++;
}
return null;
}
/// <summary>
/// Returns the row before this row.
/// </summary>
public Row PrevRow
{
get
{
int i = this.Index;
if (i - 1 >= 0)
return this.Document[i - 1];
else
return null;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?