Implement DragDrop for MultiDiskBundler

- closes #3950
This commit is contained in:
Morilli 2024-06-21 20:13:32 +02:00
parent 542e043261
commit aeb80e5810
2 changed files with 46 additions and 14 deletions

View File

@ -111,7 +111,8 @@
// //
// FileSelectorPanel // FileSelectorPanel
// //
this.FileSelectorPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.FileSelectorPanel.AllowDrop = true;
this.FileSelectorPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.FileSelectorPanel.AutoScroll = true; this.FileSelectorPanel.AutoScroll = true;
@ -120,6 +121,8 @@
this.FileSelectorPanel.Name = "FileSelectorPanel"; this.FileSelectorPanel.Name = "FileSelectorPanel";
this.FileSelectorPanel.Size = new System.Drawing.Size(486, 214); this.FileSelectorPanel.Size = new System.Drawing.Size(486, 214);
this.FileSelectorPanel.TabIndex = 12; this.FileSelectorPanel.TabIndex = 12;
this.FileSelectorPanel.DragDrop += new System.Windows.Forms.DragEventHandler(this.OnDragDrop);
this.FileSelectorPanel.DragEnter += new System.Windows.Forms.DragEventHandler(this.OnDragEnter);
// //
// AddButton // AddButton
// //

View File

@ -33,8 +33,7 @@ namespace BizHawk.Client.EmuHawk
{ {
InitializeComponent(); InitializeComponent();
Icon = ToolIcon; Icon = ToolIcon;
SystemDropDown.Items.AddRange(new[] SystemDropDown.Items.AddRange([
{
VSystemID.Raw.Amiga, VSystemID.Raw.Amiga,
VSystemID.Raw.AmstradCPC, VSystemID.Raw.AmstradCPC,
VSystemID.Raw.AppleII, VSystemID.Raw.AppleII,
@ -51,7 +50,7 @@ namespace BizHawk.Client.EmuHawk
VSystemID.Raw.SAT, VSystemID.Raw.SAT,
VSystemID.Raw.TI83, VSystemID.Raw.TI83,
VSystemID.Raw.ZXSpectrum, VSystemID.Raw.ZXSpectrum,
}); ]);
} }
public override void Restart() public override void Restart()
@ -101,16 +100,7 @@ namespace BizHawk.Client.EmuHawk
try try
{ {
var xmlGame = XmlGame.Create(new HawkFile(xmlPath)); var xmlGame = XmlGame.Create(new HawkFile(xmlPath));
for (int i = FileSelectorPanel.Controls.Count; i < xmlGame.AssetFullPaths.Count; i++) AddFiles(xmlGame.AssetFullPaths);
{
AddButton_Click(null, null);
}
var fileSelectors = FileSelectors.ToArray();
for (int i = 0; i < xmlGame.AssetFullPaths.Count; i++)
{
fileSelectors[i].Path = xmlGame.AssetFullPaths[i];
}
} }
catch catch
{ {
@ -118,6 +108,24 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private void AddFiles(IList<string> filePaths)
{
var existingEmptyControls = FileSelectors.Count(fileSelector => string.IsNullOrEmpty(fileSelector.Path));
for (int i = existingEmptyControls; i < filePaths.Count; i++)
{
AddButton_Click(null, null);
}
var fileSelectors = FileSelectors.ToArray();
int currentFileSelector = 0;
foreach (string filePath in filePaths)
{
while (currentFileSelector < fileSelectors.Length && !string.IsNullOrEmpty(fileSelectors[currentFileSelector].Path))
currentFileSelector++;
fileSelectors[currentFileSelector].Path = filePath;
}
}
private void CancelBtn_Click(object sender, EventArgs e) private void CancelBtn_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
@ -311,5 +319,26 @@ namespace BizHawk.Client.EmuHawk
{ {
Recalculate(); Recalculate();
} }
private void OnDragDrop(object sender, DragEventArgs e)
{
string[] droppedFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
if (droppedFiles is null) return;
string xmlPath = droppedFiles.FirstOrDefault(path => path.EndsWith(".xml", StringComparison.OrdinalIgnoreCase));
if (xmlPath is not null)
{
PopulateFromXmlFile(xmlPath);
}
else
{
AddFiles(droppedFiles);
}
}
private void OnDragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
}
} }
} }