QvcMainForm.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using QVCopier.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. using QVCopier.Utility;
  10. namespace QVCopier
  11. {
  12. public partial class QvcMainForm : Form
  13. {
  14. private readonly List<LogEntry> _logs = new();
  15. private readonly List<WorkItem> _items = new();
  16. public QvcMainForm()
  17. {
  18. InitializeComponent();
  19. }
  20. private void QvcMainForm_Load(object sender, EventArgs e)
  21. {
  22. MainListView.Items.Clear();
  23. LogListView.Items.Clear();
  24. InitLogger();
  25. }
  26. private void QvcMainForm_Shown(object sender, EventArgs e)
  27. {
  28. }
  29. private void DestFolderTextBox_DragEnter(object sender, DragEventArgs e)
  30. {
  31. string[] data;
  32. e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop)
  33. && (data = (string[])e.Data.GetData(DataFormats.FileDrop)).Length == 1
  34. && Directory.Exists(data[0])
  35. ? DragDropEffects.Link
  36. : DragDropEffects.None;
  37. }
  38. private void DestFolderTextBox_DragDrop(object sender, DragEventArgs e)
  39. {
  40. DestFolderTextBox.Text = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
  41. }
  42. private void ChooseDestButton_Click(object sender, EventArgs e)
  43. {
  44. var cm = new ContextMenuStrip();
  45. var msgItem = cm.Items.Add("Looking up...");
  46. msgItem.Enabled = false;
  47. cm.Items.Add("-").Enabled = false;
  48. Task.Run(() =>
  49. {
  50. var paths = ExplorerAccessor.GetOpenedWindowPath();
  51. if (paths.Length == 0)
  52. {
  53. cm.Invoke(new Action(() => msgItem.Text = "No explorer window found"));
  54. }
  55. else
  56. {
  57. cm.Invoke(new Action(() => msgItem.Text = $"{paths.Length} found"));
  58. foreach (var path in paths)
  59. {
  60. cm.Invoke(new Action(() =>
  61. {
  62. var item = new ToolStripMenuItem(path);
  63. item.Click += delegate { DestFolderTextBox.Text = path; };
  64. cm.Items.Add(item);
  65. }));
  66. }
  67. }
  68. });
  69. cm.Show(ChooseDestButton, new Point(0, ChooseDestButton.Height));
  70. }
  71. }
  72. }