From d81224de7a45e80bea388d2c56129dd15b26a1ab Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 2 Dec 2015 18:51:33 -0800 Subject: [PATCH] Support drag and drop onto the settings widget will still add to queue. --- MatterControlApplication.cs | 63 ++++++++++++++++++++++++++++++++++- Queue/QueueDataWidget.cs | 65 ++++++++++++++++++++----------------- 2 files changed, 97 insertions(+), 31 deletions(-) diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 1a59d73f3..c9ab91e57 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -350,7 +350,68 @@ namespace MatterHackers.MatterControl showWindow = true; } - public enum ReportSeverity2 { Warning, Error } + bool dropWasOnChild = true; + public override void OnDragEnter(FileDropEventArgs fileDropEventArgs) + { + base.OnDragEnter(fileDropEventArgs); + + if (!fileDropEventArgs.AcceptDrop) + { + // no child has accepted the drop + foreach (string file in fileDropEventArgs.DroppedFiles) + { + string extension = Path.GetExtension(file).ToUpper(); + if ((extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension)) + || extension == ".GCODE" + || extension == ".ZIP") + { + fileDropEventArgs.AcceptDrop = true; + } + } + dropWasOnChild = false; + } + else + { + dropWasOnChild = true; + } + } + + public override void OnDragOver(FileDropEventArgs fileDropEventArgs) + { + base.OnDragOver(fileDropEventArgs); + + if (!fileDropEventArgs.AcceptDrop) + { + // no child has accepted the drop + foreach (string file in fileDropEventArgs.DroppedFiles) + { + string extension = Path.GetExtension(file).ToUpper(); + if ((extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension)) + || extension == ".GCODE" + || extension == ".ZIP") + { + fileDropEventArgs.AcceptDrop = true; + } + } + dropWasOnChild = false; + } + else + { + dropWasOnChild = true; + } + } + + public override void OnDragDrop(FileDropEventArgs fileDropEventArgs) + { + base.OnDragDrop(fileDropEventArgs); + + if (!dropWasOnChild) + { + QueueDataWidget.DoAddFiles(fileDropEventArgs.DroppedFiles); + } + } + + public enum ReportSeverity2 { Warning, Error } public void ReportException(Exception e, string key = "", string value = "", ReportSeverity2 warningLevel = ReportSeverity2.Warning) { diff --git a/Queue/QueueDataWidget.cs b/Queue/QueueDataWidget.cs index 926246b32..4e9bc3c6a 100644 --- a/Queue/QueueDataWidget.cs +++ b/Queue/QueueDataWidget.cs @@ -350,40 +350,45 @@ namespace MatterHackers.MatterControl.PrintQueue } public override void OnDragDrop(FileDropEventArgs fileDropEventArgs) - { - int preAddCount = QueueData.Instance.Count; + { + DoAddFiles(fileDropEventArgs.DroppedFiles); - foreach (string droppedFileName in fileDropEventArgs.DroppedFiles) - { - string extension = Path.GetExtension(droppedFileName).ToUpper(); - if ((extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension)) - || extension == ".GCODE") - { - QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(droppedFileName), Path.GetFullPath(droppedFileName)))); - } - else if (extension == ".ZIP") - { - ProjectFileHandler project = new ProjectFileHandler(null); - List partFiles = project.ImportFromProjectArchive(droppedFileName); - if (partFiles != null) - { - foreach (PrintItem part in partFiles) - { - QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(part.Name, part.FileLocation))); - } - } - } - } + base.OnDragDrop(fileDropEventArgs); + } - if (QueueData.Instance.Count != preAddCount) - { - QueueData.Instance.SelectedIndex = QueueData.Instance.Count - 1; - } + public static void DoAddFiles(List files) + { + int preAddCount = QueueData.Instance.Count; - base.OnDragDrop(fileDropEventArgs); - } + foreach (string fileToAdd in files) + { + string extension = Path.GetExtension(fileToAdd).ToUpper(); + if ((extension != "" && MeshFileIo.ValidFileExtensions().Contains(extension)) + || extension == ".GCODE") + { + QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(fileToAdd), Path.GetFullPath(fileToAdd)))); + } + else if (extension == ".ZIP") + { + ProjectFileHandler project = new ProjectFileHandler(null); + List partFiles = project.ImportFromProjectArchive(fileToAdd); + if (partFiles != null) + { + foreach (PrintItem part in partFiles) + { + QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(part.Name, part.FileLocation))); + } + } + } + } - public override void OnDragEnter(FileDropEventArgs fileDropEventArgs) + if (QueueData.Instance.Count != preAddCount) + { + QueueData.Instance.SelectedIndex = QueueData.Instance.Count - 1; + } + } + + public override void OnDragEnter(FileDropEventArgs fileDropEventArgs) { foreach (string file in fileDropEventArgs.DroppedFiles) {