示例#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
                 });
             }
         }
     }
 }
示例#2
0
        //public IEnumerable<IDraggable> QueryDropDraggables(IDataObject da)
        //{
        //    if (da.GetDataPresent(Format_DragDropItem))
        //    {
        //        var data = da.GetData(Format_DragDropItem) as int[];
        //        for (int i = 0; i < data.Length; i++)
        //            yield return new DragDropItemViewModel(data[i], IsChildDroppable, IsChildDroppable);
        //    }
        //}

        public DragDropEffectsEx Drop(IEnumerable <IDraggable> draggable, DragDropEffectsEx allowedEffects)
        {
            if (allowedEffects.HasFlag(DragDropEffectsEx.Move) ||
                allowedEffects.HasFlag(DragDropEffectsEx.Copy))
            {
                var draggableViewModels = draggable.Cast <DragDropItemViewModel>();
                if (draggableViewModels.Any())
                {
                    int idx = 0;
                    foreach (var d in draggableViewModels)
                    {
                        Items.Insert(idx++, d);
                    }
                }
                return(DragDropEffectsEx.Move);
            }
            else
            {
                return(DragDropEffectsEx.None);
            }
        }
        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);
        }