On Behalf of Rolanmen - LuaWriter. Now Colors Lua Library Words.
This commit is contained in:
parent
d469a4e568
commit
817b202192
|
@ -556,7 +556,8 @@ namespace BizHawk.MultiClient
|
|||
public int LuaCommentColor = -16744448;
|
||||
public int LuaStringColor = -8355712;
|
||||
public int LuaSymbolColor = -16777216;
|
||||
public int LuaLibraryColor = 10349567;
|
||||
public int EmuluaLibraryColor = 10349567;
|
||||
public int LuaLibraryColor = -8388480;
|
||||
}
|
||||
|
||||
public class SMSControllerTemplate
|
||||
|
|
|
@ -173,6 +173,7 @@
|
|||
this.LuaText.Text = "";
|
||||
this.LuaText.WordWrap = false;
|
||||
this.LuaText.ZoomFactor = 2F;
|
||||
this.LuaText.SelectionChanged += new System.EventHandler(this.LuaText_SelectionChanged);
|
||||
this.LuaText.TextChanged += new System.EventHandler(this.LuaText_TextChanged);
|
||||
this.LuaText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyDown);
|
||||
this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp);
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace BizHawk.MultiClient
|
|||
public Regex keyWords = new Regex("and|break|do|else|if|end|false|for|function|in|local|nil|not|or|repeat|return|then|true|until|while|elseif");
|
||||
char[] Symbols = { '+', '-', '*', '/', '%', '^', '#', '=', '<', '>', '(', ')', '{', '}', '[', ']', ';', ':', ',', '.' };
|
||||
public Regex libraryWords;
|
||||
public Regex LuaLibraryWords = new Regex("coroutine|package|debug|file|io|math|os|package|string|table");
|
||||
Font LuaTextFont = new Font("Courier New", 8);
|
||||
|
||||
public LuaWriter()
|
||||
|
@ -70,13 +71,40 @@ namespace BizHawk.MultiClient
|
|||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaDefaultTextColor);
|
||||
|
||||
ColorReservedWords();
|
||||
ColorLibraries();
|
||||
ColorLuaLibraries();
|
||||
ColorComments();
|
||||
ColorStrings();
|
||||
ColorSymbols();
|
||||
ColorLibraries();
|
||||
LuaText.Select(selPos, selChars);
|
||||
}
|
||||
|
||||
private void ColorLuaLibraries()
|
||||
{
|
||||
foreach (Match libraryWordMatch in LuaLibraryWords.Matches(LuaText.Text))
|
||||
{
|
||||
if (libraryWordMatch.Index >= 0)
|
||||
{
|
||||
char before = ' ', after = ' ';
|
||||
|
||||
if (libraryWordMatch.Index > 0)
|
||||
before = LuaText.Text[libraryWordMatch.Index - 1];
|
||||
|
||||
if (libraryWordMatch.Index + libraryWordMatch.Length != LuaText.Text.Length)
|
||||
after = LuaText.Text[libraryWordMatch.Index + libraryWordMatch.Length];
|
||||
|
||||
if (!char.IsLetterOrDigit(before))
|
||||
{
|
||||
if (after == '.')
|
||||
{
|
||||
LuaText.Select(libraryWordMatch.Index, libraryWordMatch.Length);
|
||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaLibraryColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ColorSymbols()
|
||||
{
|
||||
foreach (char mark in Symbols)
|
||||
|
@ -239,39 +267,18 @@ namespace BizHawk.MultiClient
|
|||
if (libraryWordMatch.Index + libraryWordMatch.Length != LuaText.Text.Length)
|
||||
after = LuaText.Text[libraryWordMatch.Index + libraryWordMatch.Length];
|
||||
|
||||
if (!IsAlphaNumeric(before))
|
||||
if (!char.IsLetterOrDigit(before))
|
||||
{
|
||||
if (after == '.')
|
||||
{
|
||||
LuaText.Select(libraryWordMatch.Index, libraryWordMatch.Length);
|
||||
if(LuaText.SelectionColor.ToArgb() != Global.Config.LuaCommentColor && LuaText.SelectionColor.ToArgb() != Global.Config.LuaStringColor)
|
||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaLibraryColor);
|
||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.EmuluaLibraryColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsAlphaNumeric(char x)
|
||||
{
|
||||
if (x >= 'a' && x <= 'z')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (x >= 'A' && x <= 'Z')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (x >= '0' && x <= '9')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateLibraryRegex()
|
||||
{
|
||||
StringBuilder list = new StringBuilder();
|
||||
|
@ -419,13 +426,7 @@ namespace BizHawk.MultiClient
|
|||
|
||||
private void LuaText_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
hasChanged = true;
|
||||
|
||||
int currentLineIndex = LuaText.GetLineFromCharIndex(LuaText.SelectionStart);
|
||||
int lastLineIndex = LuaText.GetLineFromCharIndex(LuaText.TextLength);
|
||||
int currentColumnIndex = LuaText.SelectionStart - LuaText.GetFirstCharIndexFromLine(currentLineIndex);
|
||||
|
||||
PositionLabel.Text = string.Format("Line {0}/{1}, Column {2}", currentLineIndex + 1, lastLineIndex + 1, currentColumnIndex + 1);
|
||||
}
|
||||
|
||||
private void Changes()
|
||||
|
@ -436,6 +437,7 @@ namespace BizHawk.MultiClient
|
|||
|
||||
private void LuaText_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
hasChanged = true;
|
||||
Changes();
|
||||
}
|
||||
|
||||
|
@ -537,5 +539,17 @@ namespace BizHawk.MultiClient
|
|||
AutoCompleteView.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void LuaText_SelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!hasChanged)
|
||||
{
|
||||
int currentLineIndex = LuaText.GetLineFromCharIndex(LuaText.SelectionStart);
|
||||
int lastLineIndex = LuaText.GetLineFromCharIndex(LuaText.TextLength);
|
||||
int currentColumnIndex = LuaText.SelectionStart - LuaText.GetFirstCharIndexFromLine(currentLineIndex);
|
||||
|
||||
PositionLabel.Text = string.Format("Line {0}/{1}, Column {2}", currentLineIndex + 1, lastLineIndex + 1, currentColumnIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue