示例#1
0
 public void SetSupportedDragDropEffects(DragDropEffectsEx effects, DragDropEffectsEx defaultEffect = DragDropEffectsEx.Copy)
 {
     ContextMenu.Items.Clear();
     foreach (var e in Enum.GetValues(typeof(DragDropEffectsEx)))
     {
         DragDropEffectsEx curEffect = (DragDropEffectsEx)e;
         if (curEffect != DragDropEffectsEx.None && effects.HasFlag(curEffect))
         {
             var header = new TextBlock()
             {
                 Text = curEffect.ToString()
             };
             if (curEffect.Equals(defaultEffect))
             {
                 header.FontWeight = FontWeights.Bold;
                 ContextMenu.Items.Insert(0, new MenuItem()
                 {
                     Tag = e, Header = header
                 });
             }
             else
             {
                 ContextMenu.Items.Add(new MenuItem()
                 {
                     Tag = e, Header = header
                 });
             }
         }
     }
 }
        public DragDropEffectsEx OnDropCompleted(IEnumerable <IEntryModel> entries, IDataObject da, IEntryModel destDir, DragDropEffectsEx allowedEffects)
        {
            string fileName = PathEx.GetFileName(destDir.FullPath);

            if (fileName == null)
            {
                fileName = destDir.FullPath;
            }

            if (entries.Count() == 0)
            {
                return(DragDropEffectsEx.None);
            }
            if (entries.Any(e => e.Equals(destDir) || e.Parent.Equals(destDir)))
            {
                return(DragDropEffectsEx.None);
            }



            //if (MessageBox.Show(
            //    String.Format("[OnDropCompleted] ({2}) {0} entries to {1}",
            //    entries.Count(), fileName, allowedEffects), "FileBasedDragDropHandler.OnDropCompleted", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                DragDropEffectsEx effect = allowedEffects.HasFlag(DragDropEffectsEx.Copy) ? DragDropEffectsEx.Copy :
                                           allowedEffects.HasFlag(DragDropEffectsEx.Move) ? DragDropEffectsEx.Move : DragDropEffectsEx.None;

                if (effect == DragDropEffectsEx.None)
                {
                    return(DragDropEffectsEx.None);
                }

                ScriptRunner.RunScriptAsync(
                    WPFScriptCommands.ShowProgress(effect.ToString(),
                                                   IOScriptCommands.DiskTransfer(entries.ToArray(), destDir, effect == DragDropEffectsEx.Move, true), true));
                return(effect);
            };
            return(DragDropEffectsEx.None);
        }