private void data_DragEnter(object sender, DragEventArgs e)
        {
            //Get the list of files.
            bool          recycleBin = false;
            List <string> paths      = new List <string>(TaskDragDropHelper.GetFiles(e, out recycleBin));

            for (int i = 0; i < paths.Count; ++i)
            {
                //Just use the file name/directory name.
                paths[i] = Path.GetFileName(paths[i]);
            }

            //Add the recycle bin if it was dropped.
            if (recycleBin)
            {
                paths.Add(S._("Recycle Bin"));
            }

            string description = null;

            if (paths.Count == 0)
            {
                e.Effect    = DragDropEffects.None;
                description = S._("Cannot add the selected items");
            }
            else
            {
                e.Effect    = DragDropEffects.Copy;
                description = S._("Add {0}");
            }

            TaskDragDropHelper.OnDragEnter(this, e, description, paths);
        }
Beispiel #2
0
        /// <summary>
        /// Occurs when the user drags a file over the scheduler
        /// </summary>
        private void scheduler_DragEnter(object sender, DragEventArgs e)
        {
            //Get the list of files.
            bool          recycleBin = false;
            List <string> paths      = new List <string>(TaskDragDropHelper.GetFiles(e, out recycleBin));

            //We also need to determine if we are importing task lists.
            bool isTaskList = !recycleBin;

            for (int i = 0; i < paths.Count; ++i)
            {
                //Does this item exclude a task list import?
                if (isTaskList && Path.GetExtension(paths[i]) != ".ersy")
                {
                    isTaskList = false;
                }

                //Just use the file name/directory name.
                paths[i] = Path.GetFileName(paths[i]);
            }

            //Add the recycle bin if it was dropped.
            if (recycleBin)
            {
                paths.Add(S._("Recycle Bin"));
            }

            string description = null;

            if (paths.Count == 0)
            {
                e.Effect    = DragDropEffects.None;
                description = S._("Cannot erase the selected items");
            }
            else if (isTaskList)
            {
                e.Effect    = DragDropEffects.Copy;
                description = S._("Import tasks from {0}");
            }
            else
            {
                e.Effect    = DragDropEffects.Move;
                description = S._("Erase {0}");
            }

            TaskDragDropHelper.OnDragEnter(this, e, description, paths);
        }
        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();
            }
        }
Beispiel #4
0
        /// <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);
            }
        }