convert Ram Watch and Hex Editor to use EmulatorServices

This commit is contained in:
adelikat 2014-12-13 22:54:07 +00:00
parent c00b8ad78e
commit 8eda262ebe
3 changed files with 6 additions and 21 deletions
BizHawk.Client.EmuHawk/tools

View File

@ -20,9 +20,11 @@ using BizHawk.Client.EmuHawk.ToolExtensions;
namespace BizHawk.Client.EmuHawk
{
[RequiredServices(typeof(IMemoryDomains))]
public partial class HexEditor : Form, IToolForm
{
public IDictionary<Type, object> EmulatorServices { private get; set; }
private MemoryDomainList MemoryDomains { get { return (EmulatorServices[typeof(IMemoryDomains)] as IMemoryDomains).MemoryDomains; } }
private bool fontSizeSet = false;
private int fontWidth;
@ -61,8 +63,6 @@ namespace BizHawk.Client.EmuHawk
private bool _bigEndian;
private int _dataSize;
private MemoryDomainList MemoryDomains;
public HexEditor()
{
var font = new Font("Courier New", 8);
@ -135,22 +135,11 @@ namespace BizHawk.Client.EmuHawk
public void Restart()
{
MemoryDomains = null;
if (!Global.Emulator.HasMemoryDomains())
{
Close();
return;
}
if (!IsHandleCreated || IsDisposed)
{
return;
}
MemoryDomains = ((IMemoryDomains)Global.Emulator).MemoryDomains; // The cast is intentional, we want a specific cast error, not an eventual null reference error
var theDomain = _domain.Name.ToLower() == "file on disk" ? 999 : GetDomainInt(_domain.Name);
SetMemoryDomainMenu(); // Calls update routines, TODO: refactor, that is confusing!

View File

@ -1007,7 +1007,7 @@
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "RamWatch";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Ram Watch";
this.Text = " ";
this.Activated += new System.EventHandler(this.NewRamWatch_Activated);
this.Load += new System.EventHandler(this.NewRamWatch_Load);
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.NewRamWatch_DragDrop);

View File

@ -16,6 +16,7 @@ using BizHawk.Client.EmuHawk.ToolExtensions;
namespace BizHawk.Client.EmuHawk
{
[RequiredServices(typeof(IMemoryDomains))]
public partial class RamWatch : Form, IToolForm
{
private readonly Dictionary<string, int> _defaultColumnWidths = new Dictionary<string, int>
@ -30,8 +31,6 @@ namespace BizHawk.Client.EmuHawk
};
private WatchList _watches;
private IMemoryDomains _core;
private int _defaultWidth;
private int _defaultHeight;
@ -40,11 +39,10 @@ namespace BizHawk.Client.EmuHawk
private bool _paused = false;
public IDictionary<Type, object> EmulatorServices { private get; set; }
private IMemoryDomains _core { get { return (IMemoryDomains)EmulatorServices[typeof(IMemoryDomains)]; } }
public RamWatch()
{
_core = (IMemoryDomains)Global.Emulator; // Cast is intentional, better to get a cast exception than a null reference exception later
_watches = new WatchList(_core, _core.MemoryDomains.MainMemory);
InitializeComponent();
WatchListView.QueryItemText += WatchListView_QueryItemText;
WatchListView.QueryItemBkColor += WatchListView_QueryItemBkColor;
@ -203,8 +201,6 @@ namespace BizHawk.Client.EmuHawk
return;
}
_core = (IMemoryDomains)Global.Emulator; // Cast is intentional, better to get a cast exception than a null reference exception later
if (!string.IsNullOrWhiteSpace(_watches.CurrentFileName))
{
_watches.RefreshDomans(_core, _core.MemoryDomains.MainMemory);
@ -1087,7 +1083,7 @@ namespace BizHawk.Client.EmuHawk
private void NewRamWatch_Load(object sender, EventArgs e)
{
_watches = new WatchList(_core, _core.MemoryDomains.MainMemory);
LoadConfigSettings();
UpdateStatusBar();
}