using QVCopier.Models; using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using QVCopier.Utility; namespace QVCopier { public partial class QvcMainForm : Form { private readonly List _logs = new(); private readonly List _items = new(); public QvcMainForm() { InitializeComponent(); } private void QvcMainForm_Load(object sender, EventArgs e) { MainListView.Items.Clear(); LogListView.Items.Clear(); InitLogger(); } private void QvcMainForm_Shown(object sender, EventArgs e) { } private void DestFolderTextBox_DragEnter(object sender, DragEventArgs e) { string[] data; e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) && (data = (string[])e.Data.GetData(DataFormats.FileDrop)).Length == 1 && Directory.Exists(data[0]) ? DragDropEffects.Link : DragDropEffects.None; } private void DestFolderTextBox_DragDrop(object sender, DragEventArgs e) { DestFolderTextBox.Text = ((string[])e.Data.GetData(DataFormats.FileDrop))[0]; } private void ChooseDestButton_Click(object sender, EventArgs e) { var cm = new ContextMenuStrip(); var msgItem = cm.Items.Add("Looking up..."); msgItem.Enabled = false; cm.Items.Add("-").Enabled = false; Task.Run(() => { var paths = ExplorerAccessor.GetOpenedWindowPath(); if (paths.Length == 0) { cm.Invoke(new Action(() => msgItem.Text = "No explorer window found")); } else { cm.Invoke(new Action(() => msgItem.Text = $"{paths.Length} found")); foreach (var path in paths) { cm.Invoke(new Action(() => { var item = new ToolStripMenuItem(path); item.Click += delegate { DestFolderTextBox.Text = path; }; cm.Items.Add(item); })); } } }); cm.Show(ChooseDestButton, new Point(0, ChooseDestButton.Height)); } } }