BizHawk/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskFileSelector.cs

110 lines
2.4 KiB
C#
Raw Normal View History

2015-04-19 22:34:08 +00:00
using System;
using System.Windows.Forms;
using BizHawk.Client.Common;
2015-04-23 01:41:56 +00:00
using BizHawk.Client.EmuHawk.WinFormExtensions;
2015-04-19 22:34:08 +00:00
namespace BizHawk.Client.EmuHawk
{
public partial class MultiDiskFileSelector : UserControl
{
public string GetName()
{
2015-04-23 01:41:56 +00:00
return PathBox.Text;
2015-04-19 22:34:08 +00:00
}
public void SetName(string val)
{
2015-04-23 01:41:56 +00:00
PathBox.Text = val;
2015-04-19 22:34:08 +00:00
}
public event EventHandler NameChanged;
private void HandleLabelTextChanged(object sender, EventArgs e)
{
this.OnNameChanged(EventArgs.Empty);
}
public MultiDiskFileSelector()
{
InitializeComponent();
2015-04-23 01:41:56 +00:00
PathBox.TextChanged += this.HandleLabelTextChanged;
2015-04-19 22:34:08 +00:00
}
protected virtual void OnNameChanged(EventArgs e)
{
EventHandler handler = this.NameChanged;
if (handler != null)
{
handler(this, e);
}
}
private void PathBox_DragEnter(object sender, DragEventArgs e)
2015-04-19 22:34:08 +00:00
{
if (e.Data.GetDataPresent(DataFormats.FileDrop) &&
((string[])e.Data.GetData(DataFormats.FileDrop)).Length == 1)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void PathBox_DragDrop(object sender, DragEventArgs e)
2015-04-19 22:34:08 +00:00
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
var ff = (string[])e.Data.GetData(DataFormats.FileDrop);
if (ff.Length == 1)
{
2015-04-23 01:41:56 +00:00
PathBox.Text = ff[0];
2015-04-19 22:34:08 +00:00
}
2015-04-23 01:41:56 +00:00
}
2015-04-19 22:34:08 +00:00
}
private void BrowseButton_Click(object sender, EventArgs e)
2015-04-19 22:34:08 +00:00
{
using (var ofd = new OpenFileDialog
{
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["Global_NULL", "ROM"].Path, "Global_NULL"),
Filter = MainForm.RomFilter,
RestoreDirectory = true
})
{
2015-04-23 01:41:56 +00:00
var result = ofd.ShowHawkDialog();
2015-04-19 22:34:08 +00:00
if (result == DialogResult.OK)
{
2015-04-23 01:41:56 +00:00
PathBox.Text = ofd.FileName;
2015-04-19 22:34:08 +00:00
}
}
}
private void UseCurrentRomButton_Click(object sender, EventArgs e)
{
2015-04-23 01:41:56 +00:00
PathBox.Text = GlobalWin.MainForm.CurrentlyOpenRom;
2015-04-19 22:34:08 +00:00
}
private void DualGBFileSelector_Load(object sender, EventArgs e)
{
UpdateValues();
}
public void NewUpdate(ToolFormUpdateType type) { }
2015-04-19 22:34:08 +00:00
public void UpdateValues()
{
UseCurrentRomButton.Enabled =
!string.IsNullOrEmpty(GlobalWin.MainForm.CurrentlyOpenRom)
&& !GlobalWin.MainForm.CurrentlyOpenRom.Contains(".xml"); // Can't already be an xml
2015-04-19 22:34:08 +00:00
}
2015-04-23 01:41:56 +00:00
private void PathBox_TextChanged(object sender, EventArgs e)
{
OnNameChanged(e);
}
2015-04-19 22:34:08 +00:00
}
}