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

This commit is contained in:
mvl1986 2014-01-20 16:33:45 +00:00
parent 4ab3789672
commit cb600e5bf7
2 changed files with 143 additions and 21 deletions

View File

@ -62,6 +62,7 @@
this.PositionLabel = new System.Windows.Forms.Label(); this.PositionLabel = new System.Windows.Forms.Label();
this.ZoomLabel = new System.Windows.Forms.Label(); this.ZoomLabel = new System.Windows.Forms.Label();
this.LuaText = new BizHawk.Client.EmuHawk.LuaWriterBox(); this.LuaText = new BizHawk.Client.EmuHawk.LuaWriterBox();
this.Suggestion = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -302,17 +303,24 @@
// //
// AutoCompleteView // 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.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.FullRowSelect = true;
this.AutoCompleteView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.AutoCompleteView.HideSelection = false; this.AutoCompleteView.HideSelection = false;
this.AutoCompleteView.HoverSelection = true;
this.AutoCompleteView.Location = new System.Drawing.Point(324, 322); this.AutoCompleteView.Location = new System.Drawing.Point(324, 322);
this.AutoCompleteView.MultiSelect = false; this.AutoCompleteView.MultiSelect = false;
this.AutoCompleteView.Name = "AutoCompleteView"; this.AutoCompleteView.Name = "AutoCompleteView";
this.AutoCompleteView.Size = new System.Drawing.Size(121, 97); this.AutoCompleteView.Size = new System.Drawing.Size(121, 97);
this.AutoCompleteView.TabIndex = 3; this.AutoCompleteView.TabIndex = 3;
this.AutoCompleteView.UseCompatibleStateImageBehavior = false; 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.Visible = false;
this.AutoCompleteView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.AutoComplete_KeyDown);
this.AutoCompleteView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.AutoCompleteView_MouseDoubleClick); this.AutoCompleteView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.AutoCompleteView_MouseDoubleClick);
// //
// PositionLabel // PositionLabel
@ -353,6 +361,10 @@
this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp); this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp);
this.LuaText.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.LuaText_PreviewKeyDown); this.LuaText.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.LuaText_PreviewKeyDown);
// //
// Suggestion
//
this.Suggestion.Width = 114;
//
// LuaWriter // LuaWriter
// //
this.AllowDrop = true; this.AllowDrop = true;
@ -415,5 +427,6 @@
private System.Windows.Forms.ToolStripMenuItem startWithEmptyScriptToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem startWithEmptyScriptToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator5; private System.Windows.Forms.ToolStripSeparator toolStripSeparator5;
private System.Windows.Forms.ToolStripMenuItem backgroundColorToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem backgroundColorToolStripMenuItem;
private System.Windows.Forms.ColumnHeader Suggestion;
} }
} }

View File

@ -44,8 +44,8 @@ namespace BizHawk.Client.EmuHawk
public LuaWriter() public LuaWriter()
{ {
InitializeComponent(); InitializeComponent();
LuaText.MouseWheel += LuaText_MouseWheel; LuaText.MouseWheel += LuaText_MouseWheel;
} }
void LuaText_MouseWheel(object sender, MouseEventArgs e) void LuaText_MouseWheel(object sender, MouseEventArgs e)
{ {
@ -589,7 +589,7 @@ namespace BizHawk.Client.EmuHawk
private void LuaText_KeyUp(object sender, KeyEventArgs e) private void LuaText_KeyUp(object sender, KeyEventArgs e)
{ {
} }
private int CountTabsAtBeginningOfLine(string line) private int CountTabsAtBeginningOfLine(string line)
@ -632,7 +632,6 @@ namespace BizHawk.Client.EmuHawk
{ {
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)
@ -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) private void LuaText_KeyDown(object sender, KeyEventArgs e)
{ {
if (e.KeyCode == Keys.Escape) if (e.KeyCode == Keys.Escape)
{ {
AutoCompleteView.Visible = false; AutoCompleteView.Visible = false;
e.SuppressKeyPress = true;
return;
} }
if (e.KeyCode == Keys.OemPeriod) else if (e.KeyCode == Keys.OemPeriod)
{ {
string currentword = CurrentWord(); string currentword = CurrentWord();
if (IsLibraryWord(currentword)) if (IsLibraryWord(currentword))
@ -666,7 +695,7 @@ namespace BizHawk.Client.EmuHawk
int x = LuaText.GetPositionFromCharIndex(LuaText.SelectionStart).X + LuaText.Location.X + 5; 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 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.Location = new Point(x, y);
// Populate list with available options // Populate list with available options
AutoCompleteView.Items.Clear(); AutoCompleteView.Items.Clear();
foreach (string function in libfunctions) foreach (string function in libfunctions)
@ -674,14 +703,18 @@ namespace BizHawk.Client.EmuHawk
ListViewItem item = new ListViewItem(function); ListViewItem item = new ListViewItem(function);
AutoCompleteView.Items.Add(item); AutoCompleteView.Items.Add(item);
} }
// Show window after it has been positioned and set up // 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[] Words = { "if", "for", "while", "function" };
string tabsStr = ""; string tabsStr = "";
int linenumber = LuaText.GetLineFromCharIndex(LuaText.GetFirstCharIndexOfCurrentLine()); int linenumber = LuaText.GetLineFromCharIndex(LuaText.GetFirstCharIndexOfCurrentLine());
@ -712,21 +745,77 @@ namespace BizHawk.Client.EmuHawk
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
} }
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
{ {
if (AutoCompleteView.Visible) if (AutoCompleteView.Visible)
{ {
e.SuppressKeyPress = true; e.SuppressKeyPress = true;
SelectNextItem(e.KeyCode == Keys.Down); 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<string> 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<string> 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) private void SelectNextItem(bool Next)
{ {
if (AutoCompleteView.SelectedItems.Count > 0) if (AutoCompleteView.SelectedItems.Count > 0)
{ {
if (Next) if (Next)
@ -748,9 +837,10 @@ namespace BizHawk.Client.EmuHawk
{ {
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;
@ -794,11 +884,30 @@ namespace BizHawk.Client.EmuHawk
private void AutoCompleteView_MouseDoubleClick(object sender, MouseEventArgs e) private void AutoCompleteView_MouseDoubleClick(object sender, MouseEventArgs e)
{ {
AutoCompleteViewEnterSelection();
}
private void AutoCompleteViewEnterSelection ()
{
ListView.SelectedIndexCollection indexes = AutoCompleteView.SelectedIndices; ListView.SelectedIndexCollection indexes = AutoCompleteView.SelectedIndices;
if (indexes.Count > 0) 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); 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);