diff --git a/BizHawk.MultiClient/tools/LuaDocumentation.cs b/BizHawk.MultiClient/tools/LuaDocumentation.cs index bf05f26e56..e64ef31cf5 100644 --- a/BizHawk.MultiClient/tools/LuaDocumentation.cs +++ b/BizHawk.MultiClient/tools/LuaDocumentation.cs @@ -37,6 +37,20 @@ namespace BizHawk.MultiClient.tools return libs.ToList(); } + public List GetFunctionsByLibrary(string library) + { + List functions = new List(); + for (int i = 0; i < FunctionList.Count; i++) + { + if (FunctionList[i].library == library) + { + functions.Add(FunctionList[i].name); + } + } + + return functions; + } + public class LibraryFunction { public LibraryFunction(string method_lib, string method_name, System.Reflection.MethodInfo method) diff --git a/BizHawk.MultiClient/tools/LuaWriter.Designer.cs b/BizHawk.MultiClient/tools/LuaWriter.Designer.cs index 6e2d30c5c2..25f7f519bb 100644 --- a/BizHawk.MultiClient/tools/LuaWriter.Designer.cs +++ b/BizHawk.MultiClient/tools/LuaWriter.Designer.cs @@ -41,6 +41,8 @@ this.fontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.syntaxHighlightingToolStripMenuItem = 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.LuaText = new BizHawk.MultiClient.LuaWriterBox(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -135,6 +137,27 @@ this.MessageLabel.TabIndex = 2; this.MessageLabel.Text = " "; // + // AutoCompleteView + // + this.AutoCompleteView.FullRowSelect = true; + this.AutoCompleteView.Location = new System.Drawing.Point(695, 322); + this.AutoCompleteView.Name = "AutoCompleteView"; + this.AutoCompleteView.Size = new System.Drawing.Size(121, 97); + this.AutoCompleteView.TabIndex = 3; + this.AutoCompleteView.UseCompatibleStateImageBehavior = false; + this.AutoCompleteView.View = System.Windows.Forms.View.List; + this.AutoCompleteView.Visible = false; + this.AutoCompleteView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.AutoCompleteView_MouseDoubleClick); + // + // PositionLabel + // + this.PositionLabel.AutoSize = true; + this.PositionLabel.Location = new System.Drawing.Point(14, 30); + this.PositionLabel.Name = "PositionLabel"; + this.PositionLabel.Size = new System.Drawing.Size(46, 13); + this.PositionLabel.TabIndex = 4; + this.PositionLabel.Text = " "; + // // LuaText // this.LuaText.AcceptsTab = true; @@ -143,14 +166,15 @@ | System.Windows.Forms.AnchorStyles.Right))); this.LuaText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.LuaText.EnableAutoDragDrop = true; - this.LuaText.Location = new System.Drawing.Point(12, 29); + this.LuaText.Location = new System.Drawing.Point(15, 50); this.LuaText.Name = "LuaText"; - this.LuaText.Size = new System.Drawing.Size(819, 392); + this.LuaText.Size = new System.Drawing.Size(813, 369); this.LuaText.TabIndex = 0; this.LuaText.Text = ""; this.LuaText.WordWrap = false; this.LuaText.ZoomFactor = 2F; this.LuaText.TextChanged += new System.EventHandler(this.LuaText_TextChanged); + this.LuaText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyDown); this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp); // // LuaWriter @@ -159,6 +183,8 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(843, 441); + this.Controls.Add(this.PositionLabel); + this.Controls.Add(this.AutoCompleteView); this.Controls.Add(this.MessageLabel); this.Controls.Add(this.LuaText); this.Controls.Add(this.menuStrip1); @@ -190,5 +216,7 @@ private System.Windows.Forms.ToolStripMenuItem configToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem fontToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem syntaxHighlightingToolStripMenuItem; + private System.Windows.Forms.ListView AutoCompleteView; + private System.Windows.Forms.Label PositionLabel; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/tools/LuaWriter.cs b/BizHawk.MultiClient/tools/LuaWriter.cs index e8a7bcbfd1..1dfe4ff6f0 100644 --- a/BizHawk.MultiClient/tools/LuaWriter.cs +++ b/BizHawk.MultiClient/tools/LuaWriter.cs @@ -15,6 +15,7 @@ namespace BizHawk.MultiClient public partial class LuaWriter : Form { //TODO: + //fix tabs (tab should be 4 characters) //Line numbers //Option to toggle line numbers //Go to line number Ctrl+G @@ -409,6 +410,12 @@ namespace BizHawk.MultiClient private void LuaText_KeyUp(object sender, KeyEventArgs e) { hasChanged = true; + + int currentLineIndex = LuaText.GetLineFromCharIndex(LuaText.SelectionStart); + int lastLineIndex = LuaText.GetLineFromCharIndex(LuaText.TextLength); + int currentColumnIndex = LuaText.SelectionStart - LuaText.GetFirstCharIndexFromLine(currentLineIndex); + + PositionLabel.Text = string.Format("Line {0}/{1}, Column {2}", currentLineIndex + 1, lastLineIndex + 1, currentColumnIndex + 1); } private void Changes() @@ -443,5 +450,81 @@ namespace BizHawk.MultiClient } } + + private void LuaText_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + AutoCompleteView.Visible = false; + } + + if (e.KeyCode == Keys.OemPeriod) + { + string currentword = CurrentWord(); + if (IsLibraryWord(currentword)) + { + List libfunctions = Global.MainForm.LuaConsole1.LuaImp.docs.GetFunctionsByLibrary(currentword); + AutoCompleteView.Visible = true; + AutoCompleteView.Items.Clear(); + foreach(string function in libfunctions) + { + ListViewItem item = new ListViewItem(function); + AutoCompleteView.Items.Add(item); + } + AutoCompleteView.Location = new Point(0, 0); + + + } + } + } + + private string CurrentWord() + { + int last = LuaText.SelectionStart; + + int lastSpace = LuaText.Text.Substring(0, last).LastIndexOf(' '); + int lastLine = LuaText.Text.Substring(0, last).LastIndexOf('\n'); + int start = 0; + if (lastSpace > lastLine) + { + start = lastSpace; + } + else + { + start = lastLine; + } + + if (start == -1) + { + start = 0; + } + + int length = last - start - 1; + string word = LuaText.Text.Substring(start + 1, length); + + return word; + } + + private bool IsLibraryWord(string word) + { + List Libs = Global.MainForm.LuaConsole1.LuaImp.docs.GetLibraryList(); + if (Libs.Contains(word)) + { + return true; + } + return false; + } + + private void AutoCompleteView_MouseDoubleClick(object sender, MouseEventArgs e) + { + ListView.SelectedIndexCollection indexes = AutoCompleteView.SelectedIndices; + if (indexes.Count > 0) + { + string str = AutoCompleteView.Items[indexes[0]].Text; + int start = LuaText.SelectionStart; + LuaText.Text = LuaText.Text.Insert(start, str); + AutoCompleteView.Visible = false; + } + } } } \ No newline at end of file