Support drag and drop onto the settings widget will still add to queue.

This commit is contained in:
Lars Brubaker 2015-12-02 18:51:33 -08:00
parent b7a0dff005
commit d81224de7a
2 changed files with 97 additions and 31 deletions

View file

@ -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)
{

View file

@ -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<PrintItem> 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<string> 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<PrintItem> 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)
{