LuaWriter. Fixed small bug when editting a script from Lua Console, also from the Save and SaveAs options. Created a bool value that tells when the Text is being processed or not, since coloring triggers the TextChanged Event it will ProcessText multiple innecessary times.

This commit is contained in:
rolanmen1 2012-08-03 22:08:28 +00:00
parent b14154b30c
commit 886ef5940a
2 changed files with 356 additions and 356 deletions

View File

@ -53,14 +53,14 @@
this.configToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.configToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.fontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.fontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.syntaxHighlightingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.syntaxHighlightingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
this.startWithEmptyScriptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.restoreSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.restoreSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.MessageLabel = new System.Windows.Forms.Label(); this.MessageLabel = new System.Windows.Forms.Label();
this.AutoCompleteView = new System.Windows.Forms.ListView(); this.AutoCompleteView = new System.Windows.Forms.ListView();
this.PositionLabel = new System.Windows.Forms.Label(); this.PositionLabel = new System.Windows.Forms.Label();
this.ZoomLabel = new System.Windows.Forms.Label(); this.ZoomLabel = new System.Windows.Forms.Label();
this.startWithEmptyScriptToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LuaText = new BizHawk.MultiClient.LuaWriterBox(); this.LuaText = new BizHawk.MultiClient.LuaWriterBox();
this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -260,6 +260,18 @@
this.syntaxHighlightingToolStripMenuItem.Text = "&Syntax Highlighting"; this.syntaxHighlightingToolStripMenuItem.Text = "&Syntax Highlighting";
this.syntaxHighlightingToolStripMenuItem.Click += new System.EventHandler(this.syntaxHighlightingToolStripMenuItem_Click); this.syntaxHighlightingToolStripMenuItem.Click += new System.EventHandler(this.syntaxHighlightingToolStripMenuItem_Click);
// //
// toolStripSeparator5
//
this.toolStripSeparator5.Name = "toolStripSeparator5";
this.toolStripSeparator5.Size = new System.Drawing.Size(193, 6);
//
// startWithEmptyScriptToolStripMenuItem
//
this.startWithEmptyScriptToolStripMenuItem.Name = "startWithEmptyScriptToolStripMenuItem";
this.startWithEmptyScriptToolStripMenuItem.Size = new System.Drawing.Size(196, 22);
this.startWithEmptyScriptToolStripMenuItem.Text = "Start With Empty Script";
this.startWithEmptyScriptToolStripMenuItem.Click += new System.EventHandler(this.startWithEmptyScriptToolStripMenuItem_Click);
//
// restoreSettingsToolStripMenuItem // restoreSettingsToolStripMenuItem
// //
this.restoreSettingsToolStripMenuItem.Name = "restoreSettingsToolStripMenuItem"; this.restoreSettingsToolStripMenuItem.Name = "restoreSettingsToolStripMenuItem";
@ -308,13 +320,6 @@
this.ZoomLabel.TabIndex = 5; this.ZoomLabel.TabIndex = 5;
this.ZoomLabel.Text = "Zoom: 100%"; this.ZoomLabel.Text = "Zoom: 100%";
// //
// startWithEmptyScriptToolStripMenuItem
//
this.startWithEmptyScriptToolStripMenuItem.Name = "startWithEmptyScriptToolStripMenuItem";
this.startWithEmptyScriptToolStripMenuItem.Size = new System.Drawing.Size(196, 22);
this.startWithEmptyScriptToolStripMenuItem.Text = "Start With Empty Script";
this.startWithEmptyScriptToolStripMenuItem.Click += new System.EventHandler(this.startWithEmptyScriptToolStripMenuItem_Click);
//
// LuaText // LuaText
// //
this.LuaText.AcceptsTab = true; this.LuaText.AcceptsTab = true;
@ -335,11 +340,6 @@
this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp); this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp);
this.LuaText.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.LuaText_PreviewKeyDown); this.LuaText.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.LuaText_PreviewKeyDown);
// //
// toolStripSeparator5
//
this.toolStripSeparator5.Name = "toolStripSeparator5";
this.toolStripSeparator5.Size = new System.Drawing.Size(193, 6);
//
// LuaWriter // LuaWriter
// //
this.AllowDrop = true; this.AllowDrop = true;

View File

@ -33,7 +33,8 @@ namespace BizHawk.MultiClient
public string CurrentFile = ""; public string CurrentFile = "";
bool changes = false; bool changes = false;
bool hasChanged; bool hasChanged = false;
bool ProcessingText = false;
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"); 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 = { '+', '-', '*', '/', '%', '^', '#', '=', '<', '>', '(', ')', '{', '}', '[', ']', ';', ':', ',', '.' }; char[] Symbols = { '+', '-', '*', '/', '%', '^', '#', '=', '<', '>', '(', ')', '{', '}', '[', ']', ';', ':', ',', '.' };
public Regex libraryWords; public Regex libraryWords;
@ -72,6 +73,7 @@ namespace BizHawk.MultiClient
private void ProcessText() private void ProcessText()
{ {
ProcessingText = true;
int selPos = LuaText.SelectionStart; int selPos = LuaText.SelectionStart;
int selChars = LuaText.SelectedText.Length; int selChars = LuaText.SelectedText.Length;
@ -86,6 +88,7 @@ namespace BizHawk.MultiClient
ColorStrings(); ColorStrings();
ColorLongStrings(); ColorLongStrings();
LuaText.Select(selPos, selChars); LuaText.Select(selPos, selChars);
ProcessingText = false;
} }
private void ColorLongStrings() private void ColorLongStrings()
@ -103,7 +106,7 @@ namespace BizHawk.MultiClient
else if (firstBracket != LuaText.Text.Length - 1) else if (firstBracket != LuaText.Text.Length - 1)
{ {
secondBracket = LuaText.Find("[", firstBracket + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase); secondBracket = LuaText.Find("[", firstBracket + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
if (secondBracket >= 0 && IsLongString(LuaText.Text.Substring(firstBracket, secondBracket - firstBracket))) if (secondBracket >= 0 && IsLongString(LuaText.Text.Substring(firstBracket, secondBracket - firstBracket + 1)))
{ {
if (secondBracket + 1 == LuaText.Text.Length) if (secondBracket + 1 == LuaText.Text.Length)
ending = LuaText.Text.Length - 1; ending = LuaText.Text.Length - 1;
@ -111,21 +114,27 @@ namespace BizHawk.MultiClient
{ {
string temp = GetLongStringClosingBracket(LuaText.Text.Substring(firstBracket, secondBracket - firstBracket + 1)); string temp = GetLongStringClosingBracket(LuaText.Text.Substring(firstBracket, secondBracket - firstBracket + 1));
ending = LuaText.Find(temp, secondBracket + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase); ending = LuaText.Find(temp, secondBracket + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
if (ending < 0)
ending = LuaText.Text.Length;
else
ending += temp.Length - 1; ending += temp.Length - 1;
} }
if (ending < 0)
ending = LuaText.Text.Length - 1;
LuaText.Select(firstBracket, ending - firstBracket + 1); LuaText.Select(firstBracket, ending - firstBracket + 1);
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaStringColor); LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaStringColor);
if(ending < LuaText.Text.Length - 1) if (ending < LuaText.Text.Length - 1)
firstBracket = LuaText.Find("[", ending + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase); firstBracket = LuaText.Find("[", ending + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
else else
break; break;
} }
else
{
if(secondBracket >= 0 && secondBracket != LuaText.Text.Length - 1)
firstBracket = LuaText.Find("[", secondBracket, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
else else
break; break;
}
} }
else else
break; break;
@ -152,8 +161,11 @@ namespace BizHawk.MultiClient
bool Validated = true; bool Validated = true;
foreach (char c in longstring) foreach (char c in longstring)
if (c != ']' && c != '=') if (c != '[' && c != '=')
{
Validated = false;
break; break;
}
return Validated; return Validated;
} }
@ -404,21 +416,9 @@ namespace BizHawk.MultiClient
return; return;
} }
using (StreamReader sr = file.OpenText()) StreamReader sr = new StreamReader(file.FullName);
{ LuaText.Text = sr.ReadToEnd();
StringBuilder luaText = new StringBuilder(); sr.Close();
string s = "";
while ((s = sr.ReadLine()) != null)
{
luaText.Append(s);
luaText.Append('\n');
}
if (luaText.Length > 0)
{
LuaText.Text = luaText.ToString();
}
}
MessageLabel.Text = CurrentFile; MessageLabel.Text = CurrentFile;
} }
@ -448,8 +448,8 @@ namespace BizHawk.MultiClient
else if (changes) else if (changes)
{ {
SaveScriptAs(); SaveScriptAs();
MessageLabel.Text = Path.GetFileName(CurrentFile) + " saved.";
} }
MessageLabel.Text = Path.GetFileName(CurrentFile) + " saved.";
} }
private void SaveScript() private void SaveScript()
@ -458,10 +458,7 @@ namespace BizHawk.MultiClient
using (StreamWriter sw = new StreamWriter(CurrentFile)) using (StreamWriter sw = new StreamWriter(CurrentFile))
{ {
foreach (string s in LuaText.Lines) sw.Write(LuaText.Text);
{
sw.WriteLine(s + '\n');
}
} }
NoChanges(); NoChanges();
@ -533,9 +530,12 @@ namespace BizHawk.MultiClient
} }
private void LuaText_TextChanged(object sender, EventArgs e) private void LuaText_TextChanged(object sender, EventArgs e)
{
if (!ProcessingText)
{ {
hasChanged = true; hasChanged = true;
Changes(); Changes();
}
} }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)