Lua Writer - take over paint event and only paint once per ProcessText(). Still todo: better management of when and what to draw
This commit is contained in:
parent
c6cf18061f
commit
9cb825418f
|
@ -17,7 +17,7 @@ namespace BizHawk.MultiClient
|
||||||
//TODO:
|
//TODO:
|
||||||
//ability to save new script (currently causes an exception)
|
//ability to save new script (currently causes an exception)
|
||||||
//New scripts should be added to lua console automatically
|
//New scripts should be added to lua console automatically
|
||||||
//make functions is string part of string or comment since the actual way of validating it isn't correct
|
//make functions is string part of string or comment since the actual way of validating it isn't correct
|
||||||
//Save fontstyle to config
|
//Save fontstyle to config
|
||||||
//Line numbers
|
//Line numbers
|
||||||
//Option to toggle line numbers
|
//Option to toggle line numbers
|
||||||
|
@ -33,7 +33,7 @@ namespace BizHawk.MultiClient
|
||||||
public string CurrentFile = "";
|
public string CurrentFile = "";
|
||||||
|
|
||||||
bool changes = false;
|
bool changes = false;
|
||||||
bool hasChanged = false;
|
bool hasChanged = false;
|
||||||
bool ProcessingText;
|
bool ProcessingText;
|
||||||
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 = { '+', '-', '*', '/', '%', '^', '#', '=', '<', '>', '(', ')', '{', '}', '[', ']', ';', ':', ',', '.' };
|
||||||
|
@ -69,34 +69,36 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessText();
|
ProcessText();
|
||||||
|
|
||||||
hasChanged = false;
|
hasChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessText()
|
private void ProcessText()
|
||||||
{
|
{
|
||||||
ProcessingText = true;
|
LuaText.InhibitPaint = true;
|
||||||
int selPos = LuaText.SelectionStart;
|
ProcessingText = true;
|
||||||
int selChars = LuaText.SelectedText.Length;
|
int selPos = LuaText.SelectionStart;
|
||||||
|
int selChars = LuaText.SelectedText.Length;
|
||||||
|
|
||||||
LuaText.SelectAll();
|
LuaText.SelectAll();
|
||||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaDefaultTextColor);
|
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaDefaultTextColor);
|
||||||
if (Global.Config.LuaDefaultTextBold)
|
if (Global.Config.LuaDefaultTextBold)
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Bold);
|
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Bold);
|
||||||
else
|
else
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Regular);
|
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Regular);
|
||||||
|
|
||||||
AddKeyWords();
|
AddKeyWords();
|
||||||
AddLibraries();
|
AddLibraries();
|
||||||
AddSymbols();
|
AddSymbols();
|
||||||
AddComments();
|
AddComments();
|
||||||
AddStrings();
|
AddStrings();
|
||||||
AddLongStrings();
|
AddLongStrings();
|
||||||
|
|
||||||
ColorText();
|
ColorText();
|
||||||
|
|
||||||
LuaText.Select(selPos, selChars);
|
LuaText.Select(selPos, selChars);
|
||||||
ProcessingText = false;
|
ProcessingText = false;
|
||||||
|
LuaText.InhibitPaint = false;
|
||||||
|
LuaText.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddLongStrings()
|
private void AddLongStrings()
|
||||||
|
@ -130,7 +132,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
|
|
||||||
AddPosition(firstBracket, ending - firstBracket + 1, Global.Config.LuaStringColor, Global.Config.LuaStringBold);
|
AddPosition(firstBracket, ending - firstBracket + 1, Global.Config.LuaStringColor, Global.Config.LuaStringBold);
|
||||||
|
|
||||||
if (ending < temp.Length - 1)
|
if (ending < temp.Length - 1)
|
||||||
firstBracket = temp.IndexOf("[", ending + 1, temp.Length - ending - 1);
|
firstBracket = temp.IndexOf("[", ending + 1, temp.Length - ending - 1);
|
||||||
else
|
else
|
||||||
|
@ -169,11 +171,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;
|
Validated = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Validated;
|
return Validated;
|
||||||
}
|
}
|
||||||
|
@ -252,7 +254,7 @@ namespace BizHawk.MultiClient
|
||||||
if (opening != temp.Length)
|
if (opening != temp.Length)
|
||||||
{
|
{
|
||||||
AddPosition(opening, ending - opening + 1, Global.Config.LuaStringColor, Global.Config.LuaStringBold);
|
AddPosition(opening, ending - opening + 1, Global.Config.LuaStringColor, Global.Config.LuaStringBold);
|
||||||
|
|
||||||
if (ending >= temp.Length)
|
if (ending >= temp.Length)
|
||||||
ending++;
|
ending++;
|
||||||
else
|
else
|
||||||
|
@ -340,7 +342,7 @@ namespace BizHawk.MultiClient
|
||||||
if (bold)
|
if (bold)
|
||||||
IsBold = 1;
|
IsBold = 1;
|
||||||
|
|
||||||
for(int x = 0; x < pos.Count; x++)
|
for (int x = 0; x < pos.Count; x++)
|
||||||
{
|
{
|
||||||
if (start < pos[x][0])
|
if (start < pos[x][0])
|
||||||
{
|
{
|
||||||
|
@ -350,7 +352,7 @@ namespace BizHawk.MultiClient
|
||||||
if (x == pos.Count - 1)
|
if (x == pos.Count - 1)
|
||||||
IndexToAdd = x + 1;
|
IndexToAdd = x + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos.Insert(IndexToAdd, new int[] { start, lenght, color, IsBold });
|
pos.Insert(IndexToAdd, new int[] { start, lenght, color, IsBold });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,12 +360,12 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
foreach (int[] positions in pos)
|
foreach (int[] positions in pos)
|
||||||
{
|
{
|
||||||
LuaText.Select(positions[0], positions[1]);
|
LuaText.Select(positions[0], positions[1]);
|
||||||
LuaText.SelectionColor = Color.FromArgb(positions[2]);
|
LuaText.SelectionColor = Color.FromArgb(positions[2]);
|
||||||
if (positions[3] == 1)
|
if (positions[3] == 1)
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Bold);
|
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Bold);
|
||||||
else
|
else
|
||||||
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Regular);
|
LuaText.SelectionFont = new Font(LuaText.SelectionFont, FontStyle.Regular);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = new List<int[]>();
|
pos = new List<int[]>();
|
||||||
|
@ -375,13 +377,13 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
if (match.Index >= 0)
|
if (match.Index >= 0)
|
||||||
{
|
{
|
||||||
char before = ' ', after = ' ';
|
char before = ' ', after = ' ';
|
||||||
|
|
||||||
if (match.Index > 0)
|
if (match.Index > 0)
|
||||||
before = LuaText.Text[match.Index - 1];
|
before = LuaText.Text[match.Index - 1];
|
||||||
|
|
||||||
if (match.Index + match.Length != LuaText.Text.Length)
|
if (match.Index + match.Length != LuaText.Text.Length)
|
||||||
after = LuaText.Text[match.Index + match.Length];
|
after = LuaText.Text[match.Index + match.Length];
|
||||||
|
|
||||||
if (!char.IsLetterOrDigit(before))
|
if (!char.IsLetterOrDigit(before))
|
||||||
{
|
{
|
||||||
|
@ -408,7 +410,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Append("|coroutine|package|debug|file|io|math|os|package|string|table");
|
list.Append("|coroutine|package|debug|file|io|math|os|package|string|table");
|
||||||
libraryWords = new Regex(list.ToString());
|
libraryWords = new Regex(list.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,9 +460,9 @@ namespace BizHawk.MultiClient
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamReader sr = new StreamReader(file.FullName);
|
StreamReader sr = new StreamReader(file.FullName);
|
||||||
LuaText.Text = sr.ReadToEnd();
|
LuaText.Text = sr.ReadToEnd();
|
||||||
sr.Close();
|
sr.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LuaWriter_DragEnter(object sender, DragEventArgs e)
|
private void LuaWriter_DragEnter(object sender, DragEventArgs e)
|
||||||
|
@ -487,9 +489,9 @@ 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()
|
||||||
|
@ -498,7 +500,7 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
using (StreamWriter sw = new StreamWriter(CurrentFile))
|
using (StreamWriter sw = new StreamWriter(CurrentFile))
|
||||||
{
|
{
|
||||||
sw.Write(LuaText.Text);
|
sw.Write(LuaText.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
NoChanges();
|
NoChanges();
|
||||||
|
@ -550,18 +552,18 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int CountTabsAtBeginningOfLine(string line)
|
private int CountTabsAtBeginningOfLine(string line)
|
||||||
{
|
{
|
||||||
int tabs = 0;
|
int tabs = 0;
|
||||||
foreach (Char c in line)
|
foreach (Char c in line)
|
||||||
{
|
{
|
||||||
if (c == '\t')
|
if (c == '\t')
|
||||||
tabs++;
|
tabs++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return tabs;
|
return tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Changes()
|
private void Changes()
|
||||||
{
|
{
|
||||||
|
@ -571,11 +573,11 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
private void LuaText_TextChanged(object sender, EventArgs e)
|
private void LuaText_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!ProcessingText)
|
if (!ProcessingText)
|
||||||
{
|
{
|
||||||
hasChanged = true;
|
hasChanged = true;
|
||||||
Changes();
|
Changes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
@ -586,11 +588,11 @@ namespace BizHawk.MultiClient
|
||||||
private void syntaxHighlightingToolStripMenuItem_Click(object sender, EventArgs e)
|
private void syntaxHighlightingToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LuaWriterColorConfig l = new LuaWriterColorConfig();
|
LuaWriterColorConfig l = new LuaWriterColorConfig();
|
||||||
if (l.ShowDialog() == DialogResult.OK)
|
if (l.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
ProcessText(); //Update display with new settings
|
ProcessText(); //Update display with new settings
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
|
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
@ -619,7 +621,7 @@ namespace BizHawk.MultiClient
|
||||||
if (IsLibraryWord(currentword))
|
if (IsLibraryWord(currentword))
|
||||||
{
|
{
|
||||||
List<string> libfunctions = Global.MainForm.LuaConsole1.LuaImp.docs.GetFunctionsByLibrary(currentword);
|
List<string> libfunctions = Global.MainForm.LuaConsole1.LuaImp.docs.GetFunctionsByLibrary(currentword);
|
||||||
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
||||||
|
@ -629,115 +631,115 @@ namespace BizHawk.MultiClient
|
||||||
int topRow;
|
int topRow;
|
||||||
|
|
||||||
currentRow = LuaText.GetLineFromCharIndex(LuaText.SelectionStart); //Currently selected row
|
currentRow = LuaText.GetLineFromCharIndex(LuaText.SelectionStart); //Currently selected row
|
||||||
topRow = 0; //Need to figure this out, maybe LuaText.AutoScrollOffset?
|
topRow = 0; //Need to figure this out, maybe LuaText.AutoScrollOffset?
|
||||||
currentColumn = LuaText.SelectionStart - LuaText.GetFirstCharIndexFromLine(currentRow);
|
currentColumn = LuaText.SelectionStart - LuaText.GetFirstCharIndexFromLine(currentRow);
|
||||||
fontHeight = (int)LuaText.Font.GetHeight(); //Explicilty cast to int
|
fontHeight = (int)LuaText.Font.GetHeight(); //Explicilty cast to int
|
||||||
|
|
||||||
// Vertical position of auto complete box:
|
// Vertical position of auto complete box:
|
||||||
// This still needs to take into account the current scroll height of the box. Currently it only will look correct when scrolled all the way to the top.
|
// This still needs to take into account the current scroll height of the box. Currently it only will look correct when scrolled all the way to the top.
|
||||||
// ((Current row - Top row in view) + 1 to make it below the row) * (fontHeight + spaceBetweenLines)) + (Location of the top of the textbox in relation to overall control)
|
// ((Current row - Top row in view) + 1 to make it below the row) * (fontHeight + spaceBetweenLines)) + (Location of the top of the textbox in relation to overall control)
|
||||||
x = ((currentRow - topRow + 1) * (fontHeight + 1)) + LuaText.Location.Y;
|
x = ((currentRow - topRow + 1) * (fontHeight + 1)) + LuaText.Location.Y;
|
||||||
|
|
||||||
// Horizontal position of auto complete box:
|
// Horizontal position of auto complete box:
|
||||||
// (Width of each character in current font on the current line) + (Location of the left of the textbox in relation to overall control)
|
// (Width of each character in current font on the current line) + (Location of the left of the textbox in relation to overall control)
|
||||||
y = (currentColumn * (fontHeight / 2)) + LuaText.Location.X; // ¯\(°_o)/¯ Super-crude estimate for now, doesn't work great
|
y = (currentColumn * (fontHeight / 2)) + LuaText.Location.X; // ¯\(°_o)/¯ Super-crude estimate for now, doesn't work great
|
||||||
|
|
||||||
AutoCompleteView.Location = new Point(y, x);
|
AutoCompleteView.Location = new Point(y, x);
|
||||||
AutoCompleteView.Items.Clear();
|
AutoCompleteView.Items.Clear();
|
||||||
foreach(string function in libfunctions)
|
foreach (string function in libfunctions)
|
||||||
{
|
{
|
||||||
ListViewItem item = new ListViewItem(function);
|
ListViewItem item = new ListViewItem(function);
|
||||||
AutoCompleteView.Items.Add(item);
|
AutoCompleteView.Items.Add(item);
|
||||||
}
|
}
|
||||||
AutoCompleteView.Visible = true; //Show window after it has been positioned and set up
|
AutoCompleteView.Visible = true; //Show window after it has been positioned and set up
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.KeyCode == Keys.Enter)
|
if (e.KeyCode == Keys.Enter)
|
||||||
{
|
{
|
||||||
string[] Words = { "if", "for", "while", "function" };
|
string[] Words = { "if", "for", "while", "function" };
|
||||||
string tabsStr = "";
|
string tabsStr = "";
|
||||||
int linenumber = LuaText.GetLineFromCharIndex(LuaText.GetFirstCharIndexOfCurrentLine());
|
int linenumber = LuaText.GetLineFromCharIndex(LuaText.GetFirstCharIndexOfCurrentLine());
|
||||||
int tabs = CountTabsAtBeginningOfLine(LuaText.Lines[linenumber]);
|
int tabs = CountTabsAtBeginningOfLine(LuaText.Lines[linenumber]);
|
||||||
|
|
||||||
for (int a = 1; a <= tabs; a++)
|
for (int a = 1; a <= tabs; a++)
|
||||||
tabsStr += "\t";
|
tabsStr += "\t";
|
||||||
|
|
||||||
foreach (string Word in Words)
|
foreach (string Word in Words)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (LuaText.Lines[linenumber].Substring(0 + tabs, Word.Length) == Word)
|
if (LuaText.Lines[linenumber].Substring(0 + tabs, Word.Length) == Word)
|
||||||
{
|
{
|
||||||
string str = LuaText.Text.Insert(LuaText.SelectionStart, "\n" + tabsStr + "\t\n" + tabsStr + "end");
|
string str = LuaText.Text.Insert(LuaText.SelectionStart, "\n" + tabsStr + "\t\n" + tabsStr + "end");
|
||||||
LuaText.Text = str;
|
LuaText.Text = str;
|
||||||
LuaText.Select(LuaText.GetFirstCharIndexFromLine(linenumber + 1) + 1 + tabs, 0);
|
LuaText.Select(LuaText.GetFirstCharIndexFromLine(linenumber + 1) + 1 + tabs, 0);
|
||||||
e.SuppressKeyPress = true;
|
e.SuppressKeyPress = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
string tempStr = LuaText.Text.Insert(LuaText.SelectionStart, "\n" + tabsStr);
|
string tempStr = LuaText.Text.Insert(LuaText.SelectionStart, "\n" + tabsStr);
|
||||||
LuaText.Text = tempStr;
|
LuaText.Text = tempStr;
|
||||||
LuaText.Select(LuaText.GetFirstCharIndexFromLine(linenumber + 1) + tabs, 0);
|
LuaText.Select(LuaText.GetFirstCharIndexFromLine(linenumber + 1) + tabs, 0);
|
||||||
e.SuppressKeyPress = true;
|
e.SuppressKeyPress = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
|
||||||
|
{
|
||||||
|
if (AutoCompleteView.Visible)
|
||||||
|
{
|
||||||
|
e.SuppressKeyPress = true;
|
||||||
|
SelectNextItem(e.KeyCode == Keys.Down);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
|
|
||||||
{
|
|
||||||
if (AutoCompleteView.Visible)
|
|
||||||
{
|
|
||||||
e.SuppressKeyPress = true;
|
|
||||||
SelectNextItem(e.KeyCode == Keys.Down);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SelectNextItem(bool Next)
|
private void SelectNextItem(bool Next)
|
||||||
{
|
{
|
||||||
if (AutoCompleteView.SelectedItems.Count > 0)
|
if (AutoCompleteView.SelectedItems.Count > 0)
|
||||||
{
|
{
|
||||||
if (Next)
|
if (Next)
|
||||||
{
|
{
|
||||||
if (AutoCompleteView.FocusedItem == AutoCompleteView.Items[AutoCompleteView.Items.Count - 1])
|
if (AutoCompleteView.FocusedItem == AutoCompleteView.Items[AutoCompleteView.Items.Count - 1])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AutoCompleteView.FocusedItem = AutoCompleteView.Items[AutoCompleteView.Items.IndexOf(AutoCompleteView.SelectedItems[0]) + 1];
|
AutoCompleteView.FocusedItem = AutoCompleteView.Items[AutoCompleteView.Items.IndexOf(AutoCompleteView.SelectedItems[0]) + 1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (AutoCompleteView.FocusedItem == AutoCompleteView.Items[0])
|
if (AutoCompleteView.FocusedItem == AutoCompleteView.Items[0])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AutoCompleteView.FocusedItem = AutoCompleteView.Items[AutoCompleteView.Items.IndexOf(AutoCompleteView.SelectedItems[0]) - 1];
|
AutoCompleteView.FocusedItem = AutoCompleteView.Items[AutoCompleteView.Items.IndexOf(AutoCompleteView.SelectedItems[0]) - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(Next)
|
if (Next)
|
||||||
AutoCompleteView.FocusedItem = AutoCompleteView.Items[0];
|
AutoCompleteView.FocusedItem = AutoCompleteView.Items[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CurrentWord()
|
private string CurrentWord()
|
||||||
{
|
{
|
||||||
int last = LuaText.SelectionStart;
|
int last = LuaText.SelectionStart;
|
||||||
|
|
||||||
int lastSpace = LuaText.Text.Substring(0, last).LastIndexOf(' ');
|
int lastSpace = LuaText.Text.Substring(0, last).LastIndexOf(' ');
|
||||||
int lastTab = LuaText.Text.Substring(0, last).LastIndexOf('\t');
|
int lastTab = LuaText.Text.Substring(0, last).LastIndexOf('\t');
|
||||||
int lastLine = LuaText.Text.Substring(0, last).LastIndexOf('\n');
|
int lastLine = LuaText.Text.Substring(0, last).LastIndexOf('\n');
|
||||||
int start = 0;
|
int start = 0;
|
||||||
if (lastSpace > lastLine || lastTab > lastLine)
|
if (lastSpace > lastLine || lastTab > lastLine)
|
||||||
{
|
{
|
||||||
if (lastSpace > lastTab)
|
if (lastSpace > lastTab)
|
||||||
start = lastSpace;
|
start = lastSpace;
|
||||||
else
|
else
|
||||||
start = lastTab;
|
start = lastTab;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -774,7 +776,7 @@ namespace BizHawk.MultiClient
|
||||||
int start = LuaText.SelectionStart;
|
int start = LuaText.SelectionStart;
|
||||||
LuaText.Text = LuaText.Text.Insert(start, str);
|
LuaText.Text = LuaText.Text.Insert(start, str);
|
||||||
AutoCompleteView.Visible = false;
|
AutoCompleteView.Visible = false;
|
||||||
LuaText.Select(start + str.Length, 0);
|
LuaText.Select(start + str.Length, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -795,10 +797,10 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LuaText_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
private void LuaText_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -823,11 +825,11 @@ namespace BizHawk.MultiClient
|
||||||
Global.Config.LuaLibraryColor = -16711681;
|
Global.Config.LuaLibraryColor = -16711681;
|
||||||
|
|
||||||
Global.Config.LuaDefaultTextBold = false;
|
Global.Config.LuaDefaultTextBold = false;
|
||||||
Global.Config.LuaKeyWordBold = false;
|
Global.Config.LuaKeyWordBold = false;
|
||||||
Global.Config.LuaCommentBold = false;
|
Global.Config.LuaCommentBold = false;
|
||||||
Global.Config.LuaStringBold = false;
|
Global.Config.LuaStringBold = false;
|
||||||
Global.Config.LuaSymbolBold = false;
|
Global.Config.LuaSymbolBold = false;
|
||||||
Global.Config.LuaLibraryBold = false;
|
Global.Config.LuaLibraryBold = false;
|
||||||
|
|
||||||
Global.Config.LuaWriterBackColor = -1;
|
Global.Config.LuaWriterBackColor = -1;
|
||||||
LuaText.BackColor = Color.FromArgb(-1);
|
LuaText.BackColor = Color.FromArgb(-1);
|
||||||
|
@ -846,63 +848,63 @@ namespace BizHawk.MultiClient
|
||||||
ZoomLabel.Text = "Zoom: 100%";
|
ZoomLabel.Text = "Zoom: 100%";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void goToToolStripMenuItem_Click(object sender, EventArgs e)
|
private void goToToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
InputPrompt gotodialog = new InputPrompt();
|
InputPrompt gotodialog = new InputPrompt();
|
||||||
gotodialog.FormClosing += (s, a) =>
|
gotodialog.FormClosing += (s, a) =>
|
||||||
{
|
{
|
||||||
if (gotodialog.UserOK)
|
if (gotodialog.UserOK)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
if (!int.TryParse(gotodialog.UserText, out x))
|
if (!int.TryParse(gotodialog.UserText, out x))
|
||||||
{
|
{
|
||||||
a.Cancel = true;
|
a.Cancel = true;
|
||||||
MessageBox.Show("You must enter only numbers.", "Invalid text", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("You must enter only numbers.", "Invalid text", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
else if (Convert.ToInt32(gotodialog.UserText) > LuaText.Lines.Length)
|
else if (Convert.ToInt32(gotodialog.UserText) > LuaText.Lines.Length)
|
||||||
{
|
{
|
||||||
a.Cancel = true;
|
a.Cancel = true;
|
||||||
MessageBox.Show("You must enter a number between 1 and " + LuaText.Lines.Length.ToString() + '.', "Invalid Line number", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("You must enter a number between 1 and " + LuaText.Lines.Length.ToString() + '.', "Invalid Line number", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
gotodialog.Text = "Go To Line";
|
gotodialog.Text = "Go To Line";
|
||||||
gotodialog.SetMessage("Line Number (1 - " + LuaText.Lines.Length.ToString() + ')');
|
gotodialog.SetMessage("Line Number (1 - " + LuaText.Lines.Length.ToString() + ')');
|
||||||
gotodialog.ShowDialog();
|
gotodialog.ShowDialog();
|
||||||
int linepos = Convert.ToInt32(gotodialog.UserText) - 1;
|
int linepos = Convert.ToInt32(gotodialog.UserText) - 1;
|
||||||
LuaText.Select(LuaText.GetFirstCharIndexFromLine(linepos) + CountTabsAtBeginningOfLine(LuaText.Lines[linepos]), 0);
|
LuaText.Select(LuaText.GetFirstCharIndexFromLine(linepos) + CountTabsAtBeginningOfLine(LuaText.Lines[linepos]), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
|
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LuaText.SelectAll();
|
LuaText.SelectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
|
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LuaText.Cut();
|
LuaText.Cut();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
|
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LuaText.Copy();
|
LuaText.Copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
|
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LuaText.Paste();
|
LuaText.Paste();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
|
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LuaText.Undo();
|
LuaText.Undo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void redoToolStripMenuItem_Click(object sender, EventArgs e)
|
private void redoToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LuaText.Redo();
|
LuaText.Redo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startWithEmptyScriptToolStripMenuItem_Click(object sender, EventArgs e)
|
private void startWithEmptyScriptToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,15 +3,54 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace BizHawk.MultiClient
|
namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
class LuaWriterBox : RichTextBox
|
class LuaWriterBox : RichTextBox
|
||||||
{
|
{
|
||||||
|
public bool InhibitPaint = false;
|
||||||
|
|
||||||
public LuaWriterBox()
|
public LuaWriterBox()
|
||||||
{
|
{
|
||||||
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnPaintBackground(PaintEventArgs pevent)
|
||||||
|
{
|
||||||
|
base.OnPaintBackground(pevent);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnPaint(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region win32interop
|
||||||
|
|
||||||
|
protected override void WndProc(ref System.Windows.Forms.Message m)
|
||||||
|
{
|
||||||
|
base.WndProc(ref m);
|
||||||
|
if (m.Msg == 0x000F && !InhibitPaint) //WM_PAINT
|
||||||
|
{
|
||||||
|
// raise the paint event
|
||||||
|
using (Graphics graphic = base.CreateGraphics())
|
||||||
|
OnPaint(new PaintEventArgs(graphic,
|
||||||
|
base.ClientRectangle));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue