From 06c0417f96412d25d7e22b37a0b07c446cc34876 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 25 Jan 2014 20:27:51 +0000 Subject: [PATCH] some Lua documentation related cleanup and support column sorting on Description in Lua Functions list --- .../lua/EmuLuaLibrary.Bit.cs | 1 - BizHawk.Client.Common/lua/LuaDocumentation.cs | 57 +++++++++++----- .../tools/Lua/LuaFunctionsForm.Designer.cs | 3 +- .../tools/Lua/LuaFunctionsForm.cs | 65 ++++++++++--------- BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs | 4 +- 5 files changed, 77 insertions(+), 53 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs index 698ce2c53e..7b56b5750f 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs @@ -161,6 +161,5 @@ namespace BizHawk.Client.Common (value & 0x000000FF00000000UL) >> 8 | (value & 0x0000FF0000000000UL) >> 24 | (value & 0x00FF000000000000UL) >> 40 | (value & 0xFF00000000000000UL) >> 56; } - } } diff --git a/BizHawk.Client.Common/lua/LuaDocumentation.cs b/BizHawk.Client.Common/lua/LuaDocumentation.cs index 60340f0ba8..dc0443c19d 100644 --- a/BizHawk.Client.Common/lua/LuaDocumentation.cs +++ b/BizHawk.Client.Common/lua/LuaDocumentation.cs @@ -1,23 +1,29 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; namespace BizHawk.Client.Common { public interface ILuaDocumentation { - void Add(string method_lib, string method_name, System.Reflection.MethodInfo method, string description); + void Add(string methodLib, string methodName, MethodInfo method, string description); } public class LuaDocumentation : ILuaDocumentation { - public List FunctionList = new List(); + public List FunctionList { get; set; } - public void Add(string method_lib, string method_name, System.Reflection.MethodInfo method, string description) + public LuaDocumentation() + { + FunctionList = new List(); + } + + public void Add(string methodLib, string methodName, MethodInfo method, string description) { FunctionList.Add( - new LibraryFunction(method_lib, method_name, method, description) + new LibraryFunction(methodLib, methodName, method, description) ); } @@ -36,32 +42,36 @@ namespace BizHawk.Client.Common return FunctionList.Select(x => x.Library); } - public List GetFunctionsByLibrary(string library) + public IEnumerable GetFunctionsByLibrary(string library) { - return (from t in FunctionList where t.Library == library select t.Name).ToList(); + return FunctionList + .Where(func => func.Library == library) + .Select(func => func.Name); } public class LibraryFunction { - public LibraryFunction(string method_lib, string method_name, System.Reflection.MethodInfo method, string description) + public LibraryFunction(string methodLib, string methodName, MethodInfo method, string description) { - Library = method_lib; - Name = method_name; + Library = methodLib; + Name = methodName; var info = method.GetParameters(); + + Parameters = new List(); foreach (var p in info) { Parameters.Add(p.ToString()); } - return_type = method.ReturnType.ToString(); + this._returnType = method.ReturnType.ToString(); Description = description; } - - public string Library = String.Empty; - public string Name = String.Empty; - public List Parameters = new List(); - public string return_type = String.Empty; + + public string Library { get; set; } + public string Name { get; set; } + public List Parameters { get; set; } + private readonly string _returnType = String.Empty; public string Description { get; set; } @@ -71,9 +81,15 @@ namespace BizHawk.Client.Common { var list = new StringBuilder(); list.Append('('); - for (int i = 0; i < Parameters.Count; i++) + for (var i = 0; i < Parameters.Count; i++) { - var param = Parameters[i].Replace("System", "").Replace("Object", "").Replace(" ", "").Replace(".", "").Replace("LuaInterface", ""); + var param = Parameters[i] + .Replace("System", String.Empty) + .Replace("Object", String.Empty) + .Replace(" ", String.Empty) + .Replace(".", String.Empty) + .Replace("LuaInterface", String.Empty); + list.Append(param); if (i < Parameters.Count - 1) { @@ -82,6 +98,7 @@ namespace BizHawk.Client.Common } list.Append(')'); + return list.ToString(); } } @@ -90,7 +107,11 @@ namespace BizHawk.Client.Common { get { - return return_type.Replace("System.", "").Replace("LuaInterface.", "").ToLower().Trim(); + return _returnType + .Replace("System.", String.Empty) + .Replace("LuaInterface.", String.Empty) + .ToLower() + .Trim(); } } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.Designer.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.Designer.cs index fcd995a027..4463162796 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.Designer.cs @@ -48,7 +48,7 @@ this.OK.TabIndex = 0; this.OK.Text = "&Ok"; this.OK.UseVisualStyleBackColor = true; - this.OK.Click += new System.EventHandler(this.OK_Click); + this.OK.Click += new System.EventHandler(this.Ok_Click); // // FunctionView // @@ -70,7 +70,6 @@ this.FunctionView.UseCompatibleStateImageBehavior = false; this.FunctionView.View = System.Windows.Forms.View.Details; this.FunctionView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.FunctionView_ColumnClick); - this.FunctionView.SelectedIndexChanged += new System.EventHandler(this.FunctionView_SelectedIndexChanged); this.FunctionView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FunctionView_KeyDown); // // LibraryReturn diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs index 8e20b368f7..f81f2e4305 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaFunctionsForm.cs @@ -1,9 +1,7 @@ using System; using System.Linq; -using System.Windows.Forms; using System.Text; - -using BizHawk.Client.Common; +using System.Windows.Forms; namespace BizHawk.Client.EmuHawk { @@ -24,13 +22,13 @@ namespace BizHawk.Client.EmuHawk private void PopulateListView() { FunctionView.Items.Clear(); - foreach (var l in GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList) + foreach (var libraryFunction in GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList) { - ListViewItem item = new ListViewItem {Text = l.ReturnType}; - item.SubItems.Add(l.Library + "."); - item.SubItems.Add(l.Name); - item.SubItems.Add(l.ParameterList); - item.SubItems.Add(l.Description); + var item = new ListViewItem { Text = libraryFunction.ReturnType }; + item.SubItems.Add(libraryFunction.Library + "."); + item.SubItems.Add(libraryFunction.Name); + item.SubItems.Add(libraryFunction.ParameterList); + item.SubItems.Add(libraryFunction.Description); FunctionView.Items.Add(item); } } @@ -42,42 +40,49 @@ namespace BizHawk.Client.EmuHawk { switch (column) { - case 0: //Return + case 0: // Return GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderByDescending(x => x.ReturnType).ToList(); break; - case 1: //Library + case 1: // Library GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderByDescending(x => x.Library).ToList(); break; - case 2: //Name + case 2: // Name GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderByDescending(x => x.Name).ToList(); break; - case 3: //Parameters + case 3: // Parameters GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderByDescending(x => x.ParameterList).ToList(); break; + case 4: // Description + GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderByDescending(x => x.Description).ToList(); + break; } } else { switch (column) { - case 0: //Return + case 0: // Return GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderBy(x => x.ReturnType).ToList(); break; - case 1: //Library + case 1: // Library GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderBy(x => x.Library).ToList(); break; - case 2: //Name + case 2: // Name GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderBy(x => x.Name).ToList(); break; - case 3: //Parameters + case 3: // Parameters GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderBy(x => x.ParameterList).ToList(); break; + case 4: // Description + GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList.OrderBy(x => x.Description).ToList(); + break; } } + PopulateListView(); } - private void OK_Click(object sender, EventArgs e) + private void Ok_Click(object sender, EventArgs e) { Close(); } @@ -94,13 +99,18 @@ namespace BizHawk.Client.EmuHawk public int Column { - get { return _column; } + get + { + return _column; + } + set { if (_column == value) { _desc ^= true; } + _column = value; } } @@ -111,30 +121,25 @@ namespace BizHawk.Client.EmuHawk } } - private void FunctionView_SelectedIndexChanged(object sender, EventArgs e) - { - - } - private void FunctionView_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) //Copy + if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) // Copy { - ListView.SelectedIndexCollection indexes = FunctionView.SelectedIndices; + var indexes = FunctionView.SelectedIndices; if (indexes.Count > 0) { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); foreach (int index in indexes) { - var library_function = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList[index]; - sb.Append(library_function.Library).Append('.').Append(library_function.Name).Append("()\n"); + var libraryFunction = GlobalWin.Tools.LuaConsole.LuaImp.Docs.FunctionList[index]; + sb.Append(libraryFunction.Library).Append('.').Append(libraryFunction.Name).Append("()\n"); } if (sb.Length > 0) { - Clipboard.SetDataObject((sb.ToString())); + Clipboard.SetDataObject(sb.ToString()); } } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs index 704744d06e..606f6a1b34 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs @@ -729,7 +729,7 @@ namespace BizHawk.Client.EmuHawk string currentword = CurrentWord(); if (IsLibraryWord(currentword)) { - List libfunctions = GlobalWin.Tools.LuaConsole.LuaImp.Docs.GetFunctionsByLibrary(currentword); + List libfunctions = GlobalWin.Tools.LuaConsole.LuaImp.Docs.GetFunctionsByLibrary(currentword).ToList(); // Position autocomplete box near the cursor's current position int x = LuaText.GetPositionFromCharIndex(LuaText.SelectionStart).X + LuaText.Location.X + 5; @@ -845,7 +845,7 @@ namespace BizHawk.Client.EmuHawk String fileName = words[0]; if (IsLibraryWord(fileName)) { - List libfunctions = GlobalWin.Tools.LuaConsole.LuaImp.Docs.GetFunctionsByLibrary(fileName); + List libfunctions = GlobalWin.Tools.LuaConsole.LuaImp.Docs.GetFunctionsByLibrary(fileName).ToList(); foreach (String libfunction in libfunctions) { if (libfunction.StartsWith(words[1]))