Skip to content

Commit

Permalink
auto switch page on file drag
Browse files Browse the repository at this point in the history
  • Loading branch information
siblount committed Jan 13, 2024
1 parent f49485d commit 1bc7311
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 50 deletions.
3 changes: 3 additions & 0 deletions src/DAZ_Installer.Windows/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/DAZ_Installer.Windows/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,20 @@ private void libraryLbl_Click(object sender, EventArgs e)
}

private void pictureBox1_Click(object sender, EventArgs e) => new AboutForm().ShowDialog();

private void MainForm_DragDrop(object sender, DragEventArgs e)
{

}

private void MainForm_DragEnter(object sender, DragEventArgs e)
{
e.Effect = Program.DropEffect;
// Get the page we are currently in... If we are not on the home page, then switch to it.
if (visiblePage != homePage1)
{
SwitchPage(homePage1);
}
}
}
}
6 changes: 3 additions & 3 deletions src/DAZ_Installer.Windows/Pages/Home.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 56 additions & 47 deletions src/DAZ_Installer.Windows/Pages/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ public Home()
InitializeComponent();
HomePage = this;
titleLbl.Text = Program.AppName;

RegisterGlobalEvents(this);
}

private void RegisterGlobalEvents(Control parent)
{
foreach (Control control in parent.Controls)
{
control.AllowDrop = true;
control.DragDrop += Home_DragDrop;
control.DragEnter += Home_DragEnter;
RegisterGlobalEvents(control);
}
}

private void dropBtn_Click(object sender, EventArgs e) => HandleOpenDialogue();
Expand Down Expand Up @@ -51,55 +64,10 @@ internal void button1_Click(object sender, EventArgs e)
clearListBtn_Click(null, null);
}

private void dropBtn_DragEnter(object sender, DragEventArgs e)
{
dropBtn.Text = "Drop here!";
e.Effect = Program.DropEffect;
}
private void dropBtn_DragEnter(object sender, DragEventArgs e) => dropBtn.Text = "Drop here!";

private void dropBtn_DragLeave(object sender, EventArgs e) => dropBtn.Text = "Click here to select file(s) or drag them here.";

private void dropBtn_DragDrop(object sender, DragEventArgs e)
{
if (e.Data is null) return;
var tmp = (string[])e.Data.GetData(DataFormats.FileDrop, false);
Queue<string> invalidFiles = new();
listView1.BeginUpdate();
// Check for string if it's valid.
foreach (var path in tmp)
{
var fileInfo = new FileInfo(path);
var ext = fileInfo.Extension;
ext = ext.IndexOf('.') != -1 ? ext.Substring(1) : ext;
if (fileInfo.Exists && DPFile.ValidImportExtension(ext))
{
// Add to list.
listView1.Items.Add(path);
}
else
{
ArchiveFormat type = DPArchive.DetermineArchiveFormatPrecise(path); // TODO: I'm pretty sure this can be removed.
if (type == ArchiveFormat.SevenZ && ext.EndsWith("001"))
listView1.Items.Add(path);
else invalidFiles.Enqueue(path);
}
}
listView1.EndUpdate();
if (invalidFiles.Count > 0)
{
var builder = new StringBuilder(50);
while (invalidFiles.Count != 0)
builder.AppendLine(" \u2022 " + invalidFiles.Dequeue());
MessageBox.Show("Files that cannot be processed where removed from the list." +
"\nRemoved files:\n" + builder.ToString(), "Invalid files removed", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
if (listView1.Items.Count != 0)
dropBtn.Visible = dropBtn.Enabled = false;

dropBtn.Text = "Click here to select file(s) or drag them here.";
}

private void removeToolStripMenuItem_Click(object sender, EventArgs e)
{
for (var i = listView1.SelectedItems.Count - 1; i >= 0; i--)
Expand Down Expand Up @@ -148,6 +116,47 @@ private void homeListContextMenuStrip_Opening(object sender, CancelEventArgs e)

private void addMoreItemsToolStripMenuItem_Click(object sender, EventArgs e) => HandleOpenDialogue();

private void listView1_DragEnter(object sender, DragEventArgs e) => e.Effect = Program.DropEffect;
private void Home_DragEnter(object sender, DragEventArgs e) => e.Effect = Program.DropEffect;

private void Home_DragDrop(object sender, DragEventArgs e)
{
if (e.Data is null) return;
var tmp = (string[])e.Data.GetData(DataFormats.FileDrop, false);
Queue<string> invalidFiles = new();
listView1.BeginUpdate();
// Check for string if it's valid.
foreach (var path in tmp)
{
var fileInfo = new FileInfo(path);
var ext = fileInfo.Extension;
ext = ext.IndexOf('.') != -1 ? ext.Substring(1) : ext;
if (fileInfo.Exists && DPFile.ValidImportExtension(ext))
{
// Add to list.
listView1.Items.Add(path);
}
else
{
ArchiveFormat type = DPArchive.DetermineArchiveFormatPrecise(path); // TODO: I'm pretty sure this can be removed.
if (type == ArchiveFormat.SevenZ && ext.EndsWith("001"))
listView1.Items.Add(path);
else invalidFiles.Enqueue(path);
}
}
listView1.EndUpdate();
if (invalidFiles.Count > 0)
{
var builder = new StringBuilder(50);
while (invalidFiles.Count != 0)
builder.AppendLine(" \u2022 " + invalidFiles.Dequeue());
MessageBox.Show("Files that cannot be processed where removed from the list." +
"\nRemoved files:\n" + builder.ToString(), "Invalid files removed", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
if (listView1.Items.Count != 0)
dropBtn.Visible = dropBtn.Enabled = false;

dropBtn.Text = "Click here to select file(s) or drag them here.";
}
}
}

0 comments on commit 1bc7311

Please sign in to comment.