Convert a copy/pasted method in a bunch of tool dialogs to an extension method

This commit is contained in:
adelikat 2014-07-28 02:31:51 +00:00
parent 726122e579
commit 5d4ff76ed6
6 changed files with 38 additions and 43 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
@ -52,6 +53,11 @@ namespace BizHawk.Client.EmuHawk.WinFormExtensions
}
}
}
public static Point ChildPointToScreen(this Control control, Control child)
{
return control.PointToScreen(new Point(child.Location.X, child.Location.Y));
}
}
public static class FormExtensions

View File

@ -679,12 +679,6 @@ namespace BizHawk.Client.EmuHawk
_domainMenuItems.Add(rom_item);
}
private Point GetPromptPoint()
{
return PointToScreen(
new Point(MemoryViewerBox.Location.X + 30, MemoryViewerBox.Location.Y + 30));
}
private void ClearNibbles()
{
for (var i = 0; i < 8; i++)
@ -1483,7 +1477,11 @@ namespace BizHawk.Client.EmuHawk
private void GoToAddressMenuItem_Click(object sender, EventArgs e)
{
var inputPrompt = new InputPrompt { Text = "Go to Address", StartLocation = GetPromptPoint() };
var inputPrompt = new InputPrompt
{
Text = "Go to Address",
StartLocation = this.ChildPointToScreen(MemoryViewerBox)
};
inputPrompt.SetMessage("Enter a hexadecimal value");
var result = inputPrompt.ShowHawkDialog();

View File

@ -558,12 +558,6 @@ namespace BizHawk.Client.EmuHawk
return true;
}
private Point GetPromptPoint()
{
return PointToScreen(
new Point(LuaListView.Location.X + 30, LuaListView.Location.Y + 30));
}
private static void UpdateRegisteredFunctionsDialog()
{
foreach (var form in Application.OpenForms.OfType<LuaRegisteredFunctionsList>())
@ -880,8 +874,10 @@ namespace BizHawk.Client.EmuHawk
if (!alreadyOpen)
{
var form = new LuaRegisteredFunctionsList { StartLocation = GetPromptPoint() };
form.Show();
new LuaRegisteredFunctionsList
{
StartLocation = this.ChildPointToScreen(LuaListView)
}.Show();
}
}
}

View File

@ -152,13 +152,6 @@ namespace BizHawk.Client.EmuHawk
TraceView.ItemCount = _instructions.Count;
}
private Point GetPromptPoint()
{
return PointToScreen(
new Point(TraceView.Location.X + 30, TraceView.Location.Y + 30)
);
}
private void SetTracerBoxTitle()
{
if (Global.CoreComm.Tracer.Enabled)
@ -292,11 +285,15 @@ namespace BizHawk.Client.EmuHawk
private void MaxLinesMenuItem_Click(object sender, EventArgs e)
{
var prompt = new InputPrompt();
var prompt = new InputPrompt
{
StartLocation = this.ChildPointToScreen(TraceView),
TextInputType = InputPrompt.InputType.Unsigned
};
prompt.SetMessage("Max lines to display in the window");
prompt.SetInitialValue(Global.Config.TraceLoggerMaxLines.ToString());
prompt.TextInputType = InputPrompt.InputType.Unsigned;
prompt.StartLocation = GetPromptPoint();
var result = prompt.ShowHawkDialog();
if (result == DialogResult.OK)
{

View File

@ -868,20 +868,18 @@ namespace BizHawk.Client.EmuHawk
}
}
private Point GetPromptPoint()
{
return PointToScreen(new Point(WatchListView.Location.X, WatchListView.Location.Y));
}
private void PokeAddress()
{
if (SelectedIndices.Any())
{
var poke = new RamPoke();
var watches = SelectedIndices.Select(t => _searches[t]).ToList();
poke.SetWatch(watches);
poke.InitialLocation = GetPromptPoint();
var poke = new RamPoke
{
InitialLocation = this.ChildPointToScreen(WatchListView)
};
poke.SetWatch(SelectedIndices.Select(t => _searches[t]).ToList());
poke.ShowHawkDialog();
UpdateValues();
}
}
@ -933,7 +931,12 @@ namespace BizHawk.Client.EmuHawk
private void GoToSpecifiedAddress()
{
WatchListView.SelectedIndices.Clear();
var prompt = new InputPrompt { Text = "Go to Address", StartLocation = GetPromptPoint() };
var prompt = new InputPrompt
{
Text = "Go to Address",
StartLocation = this.ChildPointToScreen(WatchListView)
};
prompt.SetMessage("Enter a hexadecimal value");
var result = prompt.ShowHawkDialog();

View File

@ -335,7 +335,7 @@ namespace BizHawk.Client.EmuHawk
{
var we = new WatchEditor
{
InitialLocation = GetPromptPoint(),
InitialLocation = this.ChildPointToScreen(WatchListView)
};
we.SetWatch(_watches.Domain, SelectedWatches, duplicate ? WatchEditor.Mode.Duplicate : WatchEditor.Mode.Edit);
@ -396,11 +396,6 @@ namespace BizHawk.Client.EmuHawk
return width;
}
private Point GetPromptPoint()
{
return PointToScreen(new Point(WatchListView.Location.X, WatchListView.Location.Y));
}
private void LoadColumnInfo()
{
WatchListView.Columns.Clear();
@ -723,7 +718,7 @@ namespace BizHawk.Client.EmuHawk
{
var we = new WatchEditor
{
InitialLocation = GetPromptPoint()
InitialLocation = this.ChildPointToScreen(WatchListView)
};
we.SetWatch(_watches.Domain);
we.ShowHawkDialog();
@ -769,7 +764,7 @@ namespace BizHawk.Client.EmuHawk
{
var poke = new RamPoke
{
InitialLocation = GetPromptPoint()
InitialLocation = this.ChildPointToScreen(WatchListView)
};
poke.SetWatch(SelectedWatches);