Lua Registered Functions dialog - open up in a reasonable location, support multiple selection on Call and Remove buttons. Support hotkeys - Space or Enter = Call, Delete = remove

This commit is contained in:
adelikat 2013-11-10 23:16:18 +00:00
parent 9feb4d0871
commit b52ec7e647
3 changed files with 44 additions and 9 deletions

View File

@ -1248,6 +1248,12 @@ namespace BizHawk.Client.EmuHawk
NewScript(); NewScript();
} }
private Point GetPromptPoint()
{
Point p = new Point(LuaListView.Location.X + 30, LuaListView.Location.Y + 30);
return PointToScreen(p);
}
private void showRegisteredFunctionsToolStripMenuItem_Click(object sender, EventArgs e) private void showRegisteredFunctionsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (LuaImp.RegisteredFunctions.Any()) if (LuaImp.RegisteredFunctions.Any())
@ -1264,7 +1270,9 @@ namespace BizHawk.Client.EmuHawk
if (!alreadyOpen) if (!alreadyOpen)
{ {
new LuaRegisteredFunctionsList().Show(); var form = new LuaRegisteredFunctionsList();
form.StartLocation = GetPromptPoint();
form.Show();
} }
} }
} }

View File

@ -63,6 +63,7 @@
this.FunctionView.View = System.Windows.Forms.View.Details; this.FunctionView.View = System.Windows.Forms.View.Details;
this.FunctionView.SelectedIndexChanged += new System.EventHandler(this.FunctionView_SelectedIndexChanged); this.FunctionView.SelectedIndexChanged += new System.EventHandler(this.FunctionView_SelectedIndexChanged);
this.FunctionView.DoubleClick += new System.EventHandler(this.FunctionView_DoubleClick); this.FunctionView.DoubleClick += new System.EventHandler(this.FunctionView_DoubleClick);
this.FunctionView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FunctionView_KeyDown);
// //
// FunctionsEvent // FunctionsEvent
// //
@ -150,7 +151,6 @@
// //
// LuaRegisteredFunctionsList // LuaRegisteredFunctionsList
// //
this.AcceptButton = this.OK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.OK; this.CancelButton = this.OK;

View File

@ -13,6 +13,7 @@ namespace BizHawk.Client.EmuHawk
{ {
public partial class LuaRegisteredFunctionsList : Form public partial class LuaRegisteredFunctionsList : Form
{ {
public Point StartLocation = new Point(0, 0);
public LuaRegisteredFunctionsList() public LuaRegisteredFunctionsList()
{ {
InitializeComponent(); InitializeComponent();
@ -20,6 +21,10 @@ namespace BizHawk.Client.EmuHawk
private void LuaRegisteredFunctionsList_Load(object sender, EventArgs e) private void LuaRegisteredFunctionsList_Load(object sender, EventArgs e)
{ {
if (StartLocation.X > 0 && StartLocation.Y > 0)
{
Location = StartLocation;
}
PopulateListView(); PopulateListView();
} }
@ -56,20 +61,26 @@ namespace BizHawk.Client.EmuHawk
private void CallFunction() private void CallFunction()
{ {
ListView.SelectedIndexCollection indexes = FunctionView.SelectedIndices; ListView.SelectedIndexCollection indices = FunctionView.SelectedIndices;
if (indexes.Count > 0) if (indices.Count > 0)
{ {
GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions[indexes[0]].Call(); foreach (int index in indices)
{
GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions[index].Call();
}
} }
} }
private void RemoveFunctionButton() private void RemoveFunctionButton()
{ {
ListView.SelectedIndexCollection indexes = FunctionView.SelectedIndices; ListView.SelectedIndexCollection indices = FunctionView.SelectedIndices;
if (indexes.Count > 0) if (indices.Count > 0)
{ {
NamedLuaFunction nlf = GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions[indexes[0]]; foreach (int index in indices)
GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.RemoveFunction(nlf); {
NamedLuaFunction nlf = GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions[index];
GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.RemoveFunction(nlf);
}
PopulateListView(); PopulateListView();
} }
} }
@ -97,5 +108,21 @@ namespace BizHawk.Client.EmuHawk
RemoveButton.Enabled = indexes.Count > 0; RemoveButton.Enabled = indexes.Count > 0;
RemoveAllBtn.Enabled = GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.Any(); RemoveAllBtn.Enabled = GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.Any();
} }
private void FunctionView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete && !e.Control && !e.Alt && !e.Shift) //Delete
{
RemoveFunctionButton();
}
else if (e.KeyCode == Keys.Space && !e.Control && !e.Alt && !e.Shift) //Space
{
CallFunction();
}
else if (e.KeyCode == Keys.Enter && !e.Control && !e.Alt && !e.Shift) //Enter
{
CallFunction();
}
}
} }
} }