From cb600e5bf71f07b4d41729b524ae86bd2ded970b Mon Sep 17 00:00:00 2001 From: mvl1986 Date: Mon, 20 Jan 2014 16:33:45 +0000 Subject: [PATCH] Updated the AutoCompleteView, now shows possible libraries, possible methods within libraries, replaces halftyped words and adjusts to what you typed. Also made it a bit easier to use --- .../tools/Lua/LuaWriter.Designer.cs | 15 +- BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs | 149 +++++++++++++++--- 2 files changed, 143 insertions(+), 21 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.Designer.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.Designer.cs index 77499470dc..e4fe3282db 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.Designer.cs @@ -62,6 +62,7 @@ this.PositionLabel = new System.Windows.Forms.Label(); this.ZoomLabel = new System.Windows.Forms.Label(); this.LuaText = new BizHawk.Client.EmuHawk.LuaWriterBox(); + this.Suggestion = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -302,17 +303,24 @@ // // AutoCompleteView // + this.AutoCompleteView.Activation = System.Windows.Forms.ItemActivation.OneClick; + this.AutoCompleteView.AllowColumnReorder = true; this.AutoCompleteView.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.AutoCompleteView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.Suggestion}); this.AutoCompleteView.FullRowSelect = true; + this.AutoCompleteView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; this.AutoCompleteView.HideSelection = false; + this.AutoCompleteView.HoverSelection = true; this.AutoCompleteView.Location = new System.Drawing.Point(324, 322); this.AutoCompleteView.MultiSelect = false; 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.View = System.Windows.Forms.View.Details; this.AutoCompleteView.Visible = false; + this.AutoCompleteView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.AutoComplete_KeyDown); this.AutoCompleteView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.AutoCompleteView_MouseDoubleClick); // // PositionLabel @@ -353,6 +361,10 @@ this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp); this.LuaText.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.LuaText_PreviewKeyDown); // + // Suggestion + // + this.Suggestion.Width = 114; + // // LuaWriter // this.AllowDrop = true; @@ -415,5 +427,6 @@ private System.Windows.Forms.ToolStripMenuItem startWithEmptyScriptToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator5; private System.Windows.Forms.ToolStripMenuItem backgroundColorToolStripMenuItem; + private System.Windows.Forms.ColumnHeader Suggestion; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs index e033bedf3b..fbe713e22d 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaWriter.cs @@ -44,8 +44,8 @@ namespace BizHawk.Client.EmuHawk public LuaWriter() { InitializeComponent(); - LuaText.MouseWheel += LuaText_MouseWheel; - } + LuaText.MouseWheel += LuaText_MouseWheel; + } void LuaText_MouseWheel(object sender, MouseEventArgs e) { @@ -589,7 +589,7 @@ namespace BizHawk.Client.EmuHawk private void LuaText_KeyUp(object sender, KeyEventArgs e) { - + } private int CountTabsAtBeginningOfLine(string line) @@ -632,7 +632,6 @@ namespace BizHawk.Client.EmuHawk { ProcessText(); //Update display with new settings } - } private void fontToolStripMenuItem_Click(object sender, EventArgs e) @@ -648,14 +647,44 @@ namespace BizHawk.Client.EmuHawk } } + private void AutoComplete_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Back) + { + AutoCompleteView.Visible = false; + } + + else if (e.KeyCode == Keys.Enter) + { + AutoCompleteViewEnterSelection(); + } + + else if (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) + { + AutoCompleteView.Visible = false; + e.SuppressKeyPress = true; + int start = LuaText.SelectionStart; + String letter = e.KeyCode.ToString(); + if (!e.Shift) + { + letter = letter.ToLower(); + } + LuaText.Text = LuaText.Text.Insert(start, letter); + LuaText.Select(start + 1, 0); + + } + } + private void LuaText_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { AutoCompleteView.Visible = false; + e.SuppressKeyPress = true; + return; } - if (e.KeyCode == Keys.OemPeriod) + else if (e.KeyCode == Keys.OemPeriod) { string currentword = CurrentWord(); if (IsLibraryWord(currentword)) @@ -666,7 +695,7 @@ namespace BizHawk.Client.EmuHawk int x = LuaText.GetPositionFromCharIndex(LuaText.SelectionStart).X + LuaText.Location.X + 5; int y = LuaText.GetPositionFromCharIndex(LuaText.SelectionStart).Y + LuaText.Location.Y + (int)LuaText.Font.GetHeight() + 5; // One row down AutoCompleteView.Location = new Point(x, y); - + // Populate list with available options AutoCompleteView.Items.Clear(); foreach (string function in libfunctions) @@ -674,14 +703,18 @@ namespace BizHawk.Client.EmuHawk ListViewItem item = new ListViewItem(function); AutoCompleteView.Items.Add(item); } - // Show window after it has been positioned and set up - AutoCompleteView.Visible = true; + + AutoCompleteView.Visible = true; } } - if (e.KeyCode == Keys.Enter) + else if (e.KeyCode == Keys.Enter) { + if (AutoCompleteView.Visible == true) + { + AutoCompleteView.Visible = false; + } string[] Words = { "if", "for", "while", "function" }; string tabsStr = ""; int linenumber = LuaText.GetLineFromCharIndex(LuaText.GetFirstCharIndexOfCurrentLine()); @@ -712,21 +745,77 @@ namespace BizHawk.Client.EmuHawk e.SuppressKeyPress = true; } - if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) - { - if (AutoCompleteView.Visible) - { - e.SuppressKeyPress = true; - SelectNextItem(e.KeyCode == Keys.Down); - } - } + else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) + { + if (AutoCompleteView.Visible) + { + e.SuppressKeyPress = true; + AutoCompleteView.FocusedItem = AutoCompleteView.Items[0]; + AutoCompleteView.FocusedItem.Selected = true; + AutoCompleteView.Focus(); + + } + } + else if (e.KeyCode == Keys.D9 && e.Shift) + { + if (AutoCompleteView.Visible == true) + { + AutoCompleteView.Visible = false; + } + } + + else if (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) + { + String currentWord = CurrentWord(); + currentWord += e.KeyCode; + currentWord = currentWord.ToLower(); + List libList = GlobalWin.Tools.LuaConsole.LuaImp.Docs.GetLibraryList(); + + int x = LuaText.GetPositionFromCharIndex(LuaText.SelectionStart).X + LuaText.Location.X + 5; + int y = LuaText.GetPositionFromCharIndex(LuaText.SelectionStart).Y + LuaText.Location.Y + (int)LuaText.Font.GetHeight() + 5; // One row down + AutoCompleteView.Location = new Point(x, y); + AutoCompleteView.Items.Clear(); + + if (!currentWord.Contains('.')) + { + foreach (string library in libList) + { + if (library.StartsWith(currentWord)) + { + ListViewItem item = new ListViewItem(library); + AutoCompleteView.Items.Add(item); + } + } + AutoCompleteView.Visible = true; + } + else + { + String [] words = currentWord.Split('.'); + String fileName = words[0]; + if (IsLibraryWord(fileName)) + { + List libfunctions = GlobalWin.Tools.LuaConsole.LuaImp.Docs.GetFunctionsByLibrary(fileName); + foreach (String libfunction in libfunctions) + { + if (libfunction.StartsWith(words[1])) + { + ListViewItem item = new ListViewItem(libfunction); + AutoCompleteView.Items.Add(item); + } + } + AutoCompleteView.Visible = true; + } + } + } } +/* private void SelectNextItem(bool Next) { + if (AutoCompleteView.SelectedItems.Count > 0) { if (Next) @@ -748,9 +837,10 @@ namespace BizHawk.Client.EmuHawk { if (Next) AutoCompleteView.FocusedItem = AutoCompleteView.Items[0]; + } } - +*/ private string CurrentWord() { int last = LuaText.SelectionStart; @@ -794,11 +884,30 @@ namespace BizHawk.Client.EmuHawk private void AutoCompleteView_MouseDoubleClick(object sender, MouseEventArgs e) { + AutoCompleteViewEnterSelection(); + } + + private void AutoCompleteViewEnterSelection () + { ListView.SelectedIndexCollection indexes = AutoCompleteView.SelectedIndices; if (indexes.Count > 0) { - string str = AutoCompleteView.Items[indexes[0]].Text; - int start = LuaText.SelectionStart; + + string str = AutoCompleteView.Items[indexes[0]].Text; + int start = LuaText.SelectionStart; + + String wordToReplace = CurrentWord(); + if (!wordToReplace.Contains('.')) + { + start -= wordToReplace.Length; + } + else + { + String[] words = wordToReplace.Split('.'); + wordToReplace = words[words.Length - 1]; + start -= wordToReplace.Length; + } + LuaText.Text = LuaText.Text.Remove(start, wordToReplace.Length); LuaText.Text = LuaText.Text.Insert(start, str); AutoCompleteView.Visible = false; LuaText.Select(start + str.Length, 0);