LuaWriter. Added coloring symbols, it won't color if the symbol is part of a comment or a string. Also made (") and (') to not color when it's part of a comment.
Config.cs. Added SymbolColor, wich by default is black.
This commit is contained in:
parent
f951b5e932
commit
0eba6e53e4
|
@ -551,9 +551,11 @@ namespace BizHawk.MultiClient
|
||||||
public bool GifAnimatorReversable;
|
public bool GifAnimatorReversable;
|
||||||
|
|
||||||
//LuaWriter Settings
|
//LuaWriter Settings
|
||||||
|
public int LuaDefaultTextColor = -16777216;
|
||||||
public int LuaKeyWordColor = -16776961;
|
public int LuaKeyWordColor = -16776961;
|
||||||
public int LuaCommentColor = -16744448;
|
public int LuaCommentColor = -16744448;
|
||||||
public int LuaStringColor = -8355712;
|
public int LuaStringColor = -8355712;
|
||||||
|
public int LuaSymbolsColor = -16777216;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SMSControllerTemplate
|
public class SMSControllerTemplate
|
||||||
|
|
|
@ -14,7 +14,10 @@ namespace BizHawk.MultiClient
|
||||||
public partial class LuaWriter : Form
|
public partial class LuaWriter : Form
|
||||||
{
|
{
|
||||||
public string CurrentFile = "";
|
public string CurrentFile = "";
|
||||||
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");
|
|
||||||
|
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 LuaWriter()
|
public LuaWriter()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -26,7 +29,7 @@ namespace BizHawk.MultiClient
|
||||||
int selChars = LuaText.SelectedText.Length;
|
int selChars = LuaText.SelectedText.Length;
|
||||||
|
|
||||||
LuaText.SelectAll();
|
LuaText.SelectAll();
|
||||||
LuaText.SelectionColor = Color.Black;
|
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaDefaultTextColor);
|
||||||
|
|
||||||
ColorReservedWords();
|
ColorReservedWords();
|
||||||
|
|
||||||
|
@ -34,9 +37,28 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
ColorStrings();
|
ColorStrings();
|
||||||
|
|
||||||
|
ColorSymbols();
|
||||||
|
|
||||||
LuaText.Select(selPos, selChars);
|
LuaText.Select(selPos, selChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ColorSymbols()
|
||||||
|
{
|
||||||
|
foreach (char mark in Symbols)
|
||||||
|
{
|
||||||
|
int currPos = 0;
|
||||||
|
while (LuaText.Find(mark.ToString(), currPos, RichTextBoxFinds.None) >= 0)
|
||||||
|
{
|
||||||
|
if (LuaText.SelectionColor.ToArgb() != Global.Config.LuaCommentColor && LuaText.SelectionColor.ToArgb() != Global.Config.LuaStringColor)
|
||||||
|
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaSymbolsColor);
|
||||||
|
currPos = LuaText.SelectionStart + 1;
|
||||||
|
|
||||||
|
if (currPos == LuaText.Text.Length)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ColorStrings()
|
private void ColorStrings()
|
||||||
{
|
{
|
||||||
int firstMark, opening, ending, endLine;
|
int firstMark, opening, ending, endLine;
|
||||||
|
@ -45,56 +67,61 @@ namespace BizHawk.MultiClient
|
||||||
foreach (char mark in chars)
|
foreach (char mark in chars)
|
||||||
{
|
{
|
||||||
firstMark = LuaText.Find(mark.ToString());
|
firstMark = LuaText.Find(mark.ToString());
|
||||||
while (firstMark > 0)
|
while (firstMark >= 0)
|
||||||
{
|
{
|
||||||
opening = firstMark;
|
if (LuaText.SelectionColor.ToArgb() != Global.Config.LuaCommentColor)
|
||||||
if (LuaText.GetLineFromCharIndex(opening) + 1 == LuaText.Lines.Count())
|
{
|
||||||
endLine = LuaText.Text.Length - 1;
|
opening = firstMark;
|
||||||
else
|
if (LuaText.GetLineFromCharIndex(opening) + 1 == LuaText.Lines.Count())
|
||||||
endLine = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(opening) + 1) - 1;
|
endLine = LuaText.Text.Length - 1;
|
||||||
|
else
|
||||||
|
endLine = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(opening) + 1) - 1;
|
||||||
|
|
||||||
ending = 0;
|
ending = 0;
|
||||||
|
|
||||||
if (opening != LuaText.Text.Length - 1)
|
if (opening != LuaText.Text.Length - 1)
|
||||||
{
|
{
|
||||||
if (opening + 1 != endLine)
|
if (opening + 1 != endLine)
|
||||||
{
|
{
|
||||||
ending = LuaText.Find(mark.ToString(), opening + 1, endLine, RichTextBoxFinds.MatchCase);
|
ending = LuaText.Find(mark.ToString(), opening + 1, endLine, RichTextBoxFinds.MatchCase);
|
||||||
if (ending > 0)
|
if (ending > 0)
|
||||||
{
|
{
|
||||||
while (ending > 0)
|
while (ending > 0)
|
||||||
{
|
{
|
||||||
if (!IsThisPartOfTheString(LuaText.Text.Substring(opening, ending - opening + 1)))
|
if (!IsThisPartOfTheString(LuaText.Text.Substring(opening, ending - opening + 1)))
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
ending++;
|
ending++;
|
||||||
|
|
||||||
ending = LuaText.Find(mark.ToString(), ending, endLine, RichTextBoxFinds.MatchCase);
|
ending = LuaText.Find(mark.ToString(), ending, endLine, RichTextBoxFinds.MatchCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ending = endLine;
|
ending = endLine;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ending = endLine;
|
ending = endLine;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ending = endLine;
|
ending = endLine;
|
||||||
|
|
||||||
if (opening != LuaText.Text.Length)
|
if (opening != LuaText.Text.Length)
|
||||||
{
|
{
|
||||||
LuaText.Select(opening, ending - opening + 1);
|
LuaText.Select(opening, ending - opening + 1);
|
||||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaStringColor);
|
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaStringColor);
|
||||||
if (ending >= LuaText.Text.Length)
|
if (ending >= LuaText.Text.Length)
|
||||||
ending++;
|
ending++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
firstMark = LuaText.Find(mark.ToString(), ending + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
firstMark = LuaText.Find(mark.ToString(), ending + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
firstMark = LuaText.Find(mark.ToString(), firstMark + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +191,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LuaWriter_Load(object sender, EventArgs e)
|
private void LuaWriter_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrWhiteSpace(CurrentFile))
|
if (!String.IsNullOrWhiteSpace(CurrentFile))
|
||||||
{
|
{
|
||||||
LoadCurrentFile();
|
LoadCurrentFile();
|
||||||
|
|
Loading…
Reference in New Issue