private void data_DragDrop(object sender, DragEventArgs e) { TaskDragDropHelper.OnDrop(e); if (e.Effect == DragDropEffects.None) { return; } //Add the targets foreach (IErasureTarget target in TaskDragDropHelper.GetTargets(e)) { task.Targets.Add(target); ++data.VirtualListSize; errorProvider.Clear(); } }
/// <summary> /// Occurs when the user drops a file into the scheduler. /// </summary> private void scheduler_DragDrop(object sender, DragEventArgs e) { TaskDragDropHelper.OnDrop(e); if (e.Effect == DragDropEffects.None) { return; } //Determine our action. bool recycleBin = false; List <string> paths = new List <string>(TaskDragDropHelper.GetFiles(e, out recycleBin)); bool isTaskList = !recycleBin; foreach (string path in paths) { //Does this item exclude a task list import? if (isTaskList && Path.GetExtension(path) != ".ersy") { isTaskList = false; break; } } if (isTaskList) { foreach (string file in paths) { using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { try { Program.eraserClient.Tasks.LoadFromStream(stream); } catch (InvalidDataException ex) { MessageBox.Show(S._("Could not import task list from {0}. The " + "error returned was: {1}", file, ex.Message), S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, Localisation.IsRightToLeft(this) ? MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0); } } } } else { //Create a task with the default settings Task task = new Task(); foreach (IErasureTarget target in TaskDragDropHelper.GetTargets(e)) { task.Targets.Add(target); } //If the task has no targets, we should not go on. if (task.Targets.Count == 0) { return; } //Schedule the task dialog to be shown (to get to the event loop so that //ComCtl32.dll v6 is used.) BeginInvoke((Action <Task>)scheduler_DragDropConfirm, task); } }