BizHawk/BizHawk.Client.EmuHawk/tools/ToolBox.cs

118 lines
2.7 KiB
C#
Raw Normal View History

2011-04-07 00:46:10 +00:00
using System;
using System.Collections.Generic;
2011-04-07 00:46:10 +00:00
using System.Drawing;
using System.Linq;
2016-12-06 16:40:09 +00:00
using System.Reflection;
2011-04-07 00:46:10 +00:00
using System.Windows.Forms;
2016-12-06 16:40:09 +00:00
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
2011-04-07 00:46:10 +00:00
{
public partial class ToolBox : Form, IToolForm
{
[RequiredService]
private IEmulator Emulator { get; set; }
public ToolBox()
{
InitializeComponent();
}
private void ToolBox_Load(object sender, EventArgs e)
{
2013-12-21 21:37:00 +00:00
Location = new Point(
Owner.Location.X + Owner.Size.Width,
Owner.Location.Y
2013-12-21 21:37:00 +00:00
);
}
public void NewUpdate(ToolFormUpdateType type) { }
public bool AskSaveChanges() { return true; }
public bool UpdateBefore { get { return false; } }
public void UpdateValues() { }
2013-12-21 21:37:00 +00:00
public void FastUpdate()
{
// Do nothing
}
public void Restart()
{
SetTools();
SetSize();
ToolBoxStrip.Select();
ToolBoxItems.First().Select();
}
private void SetTools()
{
ToolBoxStrip.Items.Clear();
2015-12-10 12:08:00 +00:00
foreach (var t in Assembly.GetAssembly(GetType()).GetTypes())
{
2015-12-10 12:08:00 +00:00
if (!typeof(IToolForm).IsAssignableFrom(t))
continue;
if (!typeof(Form).IsAssignableFrom(t))
continue;
if (typeof(ToolBox).IsAssignableFrom(t)) //yo dawg i head you like toolboxes
continue;
2017-07-12 19:44:14 +00:00
if (VersionInfo.DeveloperBuild && t.GetCustomAttributes(false).OfType<ToolAttribute>().Any(a => !a.Released))
2015-12-10 12:08:00 +00:00
continue;
if (t == typeof(GBGameGenie)) // Hack, this tool is specific to a system id and a sub-system (gb and gg) we have no reasonable way to declare a dependency like that
continue;
if (!ServiceInjector.IsAvailable(Emulator.ServiceProvider, t))
2015-12-10 12:08:00 +00:00
continue;
var instance = Activator.CreateInstance(t);
var tsb = new ToolStripButton
{
2015-12-10 12:08:00 +00:00
Image = (instance as Form).Icon.ToBitmap(),
Text = (instance as Form).Text,
DisplayStyle = (instance as Form).ShowIcon ? ToolStripItemDisplayStyle.Image : ToolStripItemDisplayStyle.Text
};
2015-12-10 12:08:00 +00:00
tsb.Click += (o, e) =>
{
2015-12-10 12:08:00 +00:00
GlobalWin.Tools.Load(t);
Close();
};
2015-12-10 12:08:00 +00:00
ToolBoxStrip.Items.Add(tsb);
}
}
private void SetSize()
{
2014-01-08 03:53:53 +00:00
var rows = (int)Math.Ceiling(ToolBoxItems.Count() / 4.0);
Height = 30 + (rows * 30);
}
2014-01-08 03:53:53 +00:00
// Provide LINQ capabilities to an outdated form collection
private IEnumerable<ToolStripItem> ToolBoxItems
{
get
{
return ToolBoxStrip.Items.Cast<ToolStripItem>();
}
}
2013-12-22 03:41:10 +00:00
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
2013-12-22 03:41:10 +00:00
if (keyData == Keys.Escape)
{
Close();
return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
}
}
2011-04-07 00:46:10 +00:00
}