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:
rolanmen1 2012-07-22 22:16:44 +00:00
parent f951b5e932
commit 0eba6e53e4
2 changed files with 77 additions and 48 deletions

View File

@ -551,9 +551,11 @@ namespace BizHawk.MultiClient
public bool GifAnimatorReversable;
//LuaWriter Settings
public int LuaDefaultTextColor = -16777216;
public int LuaKeyWordColor = -16776961;
public int LuaCommentColor = -16744448;
public int LuaStringColor = -8355712;
public int LuaSymbolsColor = -16777216;
}
public class SMSControllerTemplate

View File

@ -14,7 +14,10 @@ namespace BizHawk.MultiClient
public partial class LuaWriter : Form
{
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()
{
InitializeComponent();
@ -26,7 +29,7 @@ namespace BizHawk.MultiClient
int selChars = LuaText.SelectedText.Length;
LuaText.SelectAll();
LuaText.SelectionColor = Color.Black;
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaDefaultTextColor);
ColorReservedWords();
@ -34,9 +37,28 @@ namespace BizHawk.MultiClient
ColorStrings();
ColorSymbols();
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()
{
int firstMark, opening, ending, endLine;
@ -45,7 +67,9 @@ namespace BizHawk.MultiClient
foreach (char mark in chars)
{
firstMark = LuaText.Find(mark.ToString());
while (firstMark > 0)
while (firstMark >= 0)
{
if (LuaText.SelectionColor.ToArgb() != Global.Config.LuaCommentColor)
{
opening = firstMark;
if (LuaText.GetLineFromCharIndex(opening) + 1 == LuaText.Lines.Count())
@ -94,6 +118,9 @@ namespace BizHawk.MultiClient
}
else
break;
}
else
firstMark = LuaText.Find(mark.ToString(), firstMark + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
}
}
}