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:
parent
b14154b30c
commit
886ef5940a
|
@ -53,14 +53,14 @@
|
|||
this.configToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.fontToolStripMenuItem = 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.MessageLabel = new System.Windows.Forms.Label();
|
||||
this.AutoCompleteView = new System.Windows.Forms.ListView();
|
||||
this.PositionLabel = 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.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
|
@ -260,6 +260,18 @@
|
|||
this.syntaxHighlightingToolStripMenuItem.Text = "&Syntax Highlighting";
|
||||
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
|
||||
//
|
||||
this.restoreSettingsToolStripMenuItem.Name = "restoreSettingsToolStripMenuItem";
|
||||
|
@ -308,13 +320,6 @@
|
|||
this.ZoomLabel.TabIndex = 5;
|
||||
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
|
||||
//
|
||||
this.LuaText.AcceptsTab = true;
|
||||
|
@ -335,11 +340,6 @@
|
|||
this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp);
|
||||
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
|
||||
//
|
||||
this.AllowDrop = true;
|
||||
|
|
|
@ -33,7 +33,8 @@ namespace BizHawk.MultiClient
|
|||
public string CurrentFile = "";
|
||||
|
||||
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");
|
||||
char[] Symbols = { '+', '-', '*', '/', '%', '^', '#', '=', '<', '>', '(', ')', '{', '}', '[', ']', ';', ':', ',', '.' };
|
||||
public Regex libraryWords;
|
||||
|
@ -72,6 +73,7 @@ namespace BizHawk.MultiClient
|
|||
|
||||
private void ProcessText()
|
||||
{
|
||||
ProcessingText = true;
|
||||
int selPos = LuaText.SelectionStart;
|
||||
int selChars = LuaText.SelectedText.Length;
|
||||
|
||||
|
@ -86,6 +88,7 @@ namespace BizHawk.MultiClient
|
|||
ColorStrings();
|
||||
ColorLongStrings();
|
||||
LuaText.Select(selPos, selChars);
|
||||
ProcessingText = false;
|
||||
}
|
||||
|
||||
private void ColorLongStrings()
|
||||
|
@ -103,7 +106,7 @@ namespace BizHawk.MultiClient
|
|||
else if (firstBracket != LuaText.Text.Length - 1)
|
||||
{
|
||||
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)
|
||||
ending = LuaText.Text.Length - 1;
|
||||
|
@ -111,10 +114,11 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
string temp = GetLongStringClosingBracket(LuaText.Text.Substring(firstBracket, secondBracket - firstBracket + 1));
|
||||
ending = LuaText.Find(temp, secondBracket + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
||||
if (ending < 0)
|
||||
ending = LuaText.Text.Length;
|
||||
else
|
||||
ending += temp.Length - 1;
|
||||
}
|
||||
if (ending < 0)
|
||||
ending = LuaText.Text.Length - 1;
|
||||
|
||||
LuaText.Select(firstBracket, ending - firstBracket + 1);
|
||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaStringColor);
|
||||
|
@ -124,8 +128,13 @@ namespace BizHawk.MultiClient
|
|||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(secondBracket >= 0 && secondBracket != LuaText.Text.Length - 1)
|
||||
firstBracket = LuaText.Find("[", secondBracket, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
@ -152,8 +161,11 @@ namespace BizHawk.MultiClient
|
|||
bool Validated = true;
|
||||
|
||||
foreach (char c in longstring)
|
||||
if (c != ']' && c != '=')
|
||||
if (c != '[' && c != '=')
|
||||
{
|
||||
Validated = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return Validated;
|
||||
}
|
||||
|
@ -404,21 +416,9 @@ namespace BizHawk.MultiClient
|
|||
return;
|
||||
}
|
||||
|
||||
using (StreamReader sr = file.OpenText())
|
||||
{
|
||||
StringBuilder luaText = new StringBuilder();
|
||||
string s = "";
|
||||
while ((s = sr.ReadLine()) != null)
|
||||
{
|
||||
luaText.Append(s);
|
||||
luaText.Append('\n');
|
||||
}
|
||||
|
||||
if (luaText.Length > 0)
|
||||
{
|
||||
LuaText.Text = luaText.ToString();
|
||||
}
|
||||
}
|
||||
StreamReader sr = new StreamReader(file.FullName);
|
||||
LuaText.Text = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
|
||||
MessageLabel.Text = CurrentFile;
|
||||
}
|
||||
|
@ -448,8 +448,8 @@ namespace BizHawk.MultiClient
|
|||
else if (changes)
|
||||
{
|
||||
SaveScriptAs();
|
||||
MessageLabel.Text = Path.GetFileName(CurrentFile) + " saved.";
|
||||
}
|
||||
MessageLabel.Text = Path.GetFileName(CurrentFile) + " saved.";
|
||||
}
|
||||
|
||||
private void SaveScript()
|
||||
|
@ -458,10 +458,7 @@ namespace BizHawk.MultiClient
|
|||
|
||||
using (StreamWriter sw = new StreamWriter(CurrentFile))
|
||||
{
|
||||
foreach (string s in LuaText.Lines)
|
||||
{
|
||||
sw.WriteLine(s + '\n');
|
||||
}
|
||||
sw.Write(LuaText.Text);
|
||||
}
|
||||
|
||||
NoChanges();
|
||||
|
@ -533,9 +530,12 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
|
||||
private void LuaText_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!ProcessingText)
|
||||
{
|
||||
hasChanged = true;
|
||||
Changes();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
Loading…
Reference in New Issue