Exemplo n.º 1
0
        public TestDroppableViewModel()
        {
            IProfile exProfile = new FileSystemInfoExProfile(null, null);

            DropHelper = new LambdaShellDropHelper <IEntryModel>(
                new LambdaValueConverter <IEntryViewModel, IEntryModel>(
                    (evm) => evm.EntryModel,
                    (em) => EntryViewModel.FromEntryModel(em)),

                new LambdaValueConverter <IEnumerable <IEntryModel>, IDataObject>(
                    (ems) => exProfile.DragDrop.GetDataObject(ems),
                    (da) => exProfile.DragDrop.GetEntryModels(da)),

                (ems, eff) =>
            {
                return(QueryDropEffects.CreateNew(DragDropEffectsEx.Copy));
            },
                (ems, da, eff) =>
            {
                if (ems.Count() > 1)
                {
                    Label = ems.Count() + " items.";
                }
                else
                {
                    Label = ems.First().FullPath;
                }
                return(DragDropEffectsEx.Copy);
            })
            {
                DisplayName = "TestLabel"
            };
        }
Exemplo n.º 2
0
        public NumberNodeViewModel(object parentNode, NumberModel model)
            : base(model)
        {
            _parentNode = parentNode;
            Items       = new ObservableCollection <NumberNodeViewModel>();

            var converter = new LambdaValueConverter <IDraggable, NumberModel>(
                d => (d is NumberViewModel) ? (d as NumberViewModel).Model : null,
                nm => new NumberNodeViewModel(this, nm));

            DragHelper = new LambdaDragHelper <NumberModel>(converter,
                                                            () => GetAllSubItems(true).Select(nvm => nvm.Model).ToList(),
                                                            nms => DragDropEffectsEx.Move,
                                                            (nms, eff) =>
            {
                if (parentNode is NumberNodeViewModel)
                {
                    (parentNode as NumberNodeViewModel).Items.Remove(this);
                }
                else if (parentNode is NumberTreeViewModel)
                {
                    (parentNode as NumberTreeViewModel).Items.Remove(this);
                }

                //foreach (var nm in nms)
                //    Items.Remove(new NumberNodeViewModel(this, nm));
            }
                                                            );
            DropHelper = new LambdaDropHelper <NumberModel>(converter,
                                                            (nms, eff) =>
            {
                foreach (var nm in nms)
                {
                    if (Items.Any(ivm => ivm.Model.Equals(nm)))
                    {
                        return(QueryDropEffects.None);
                    }
                }
                return(QueryDropEffects.CreateNew(DragDropEffectsEx.Move));
            },
                                                            (nms, eff) =>
            {
                foreach (var nm in nms)
                {
                    Items.Add(new NumberNodeViewModel(this, nm));
                }
                return(DragDropEffectsEx.Move);
            })
            {
                DisplayName = "Node " + model.Value.ToString()
            };
        }
Exemplo n.º 3
0
        public NumberListViewModel(string displayName)
        {
            Items = new ObservableCollection <NumberViewModel>();

            //Convert from IDraggable (implemented by ViewModel)
            //to Model (value transferred from dragsource to drop target).
            var converter = new LambdaValueConverter <IDraggable, NumberModel>(
                d => (d is NumberViewModel) ? (d as NumberViewModel).Model : null,
                nm => new NumberViewModel(nm));

            DragHelper = new LambdaDragHelper <NumberModel>(converter,
                                                                                           //GetModels()
                                                            () => Items.Where(nvm => nvm.IsSelected).Select(nvm => nvm.Model).ToList(),
                                                            nms => DragDropEffectsEx.Move, //OnQueryDrag(models)
                                                            (nms, eff) =>
            {
                //OnDropCompleted(models, dropEffect)
                foreach (var nm in nms)
                {
                    Items.Remove(new NumberViewModel(nm));
                }
            }
                                                            );
            DropHelper = new LambdaDropHelper <NumberModel>(converter,
                                                            (nms, eff) =>
            {
                //OnQueryDrop(models, possibleEffects)
                foreach (var nm in nms)
                {
                    if (Items.Any(ivm => ivm.Model.Equals(nm)))
                    {
                        return(QueryDropEffects.None);
                    }
                }
                return(QueryDropEffects.CreateNew(DragDropEffectsEx.Move));
            },
                                                            (nms, eff) =>
            {
                //OnDrop(models, possibleEffects)
                foreach (var nm in nms)
                {
                    Items.Add(new NumberViewModel(nm));
                }
                return(DragDropEffectsEx.Move);
            })
            {
                DisplayName = displayName
            };
        }
Exemplo n.º 4
0
 public QueryDropEffects QueryDrop(IEnumerable <IDraggable> draggables, DragDropEffectsEx allowedEffects)
 {
     if (draggables.Count() == 0)
     {
         return(QueryDropEffects.None);
     }
     foreach (var dm in draggables.Cast <DragDropItemViewModel>())
     {
         if (dm.Value == this.Value)
         {
             return(QueryDropEffects.None);
         }
     }
     return(QueryDropEffects.CreateNew(DragDropEffectsEx.Move | DragDropEffectsEx.Copy, DragDropEffectsEx.Move));
 }
        public QueryDropEffects QueryDrop(IEnumerable <IEntryModel> entries, IEntryModel destDir, DragDropEffectsEx allowedEffects)
        {
            if (entries.Any(e => e.Equals(destDir) || e.Parent.Equals(destDir)))
            {
                return(QueryDropEffects.None);
            }

            if (destDir.IsDirectory)
            {
                return(QueryDropEffects.CreateNew(DragDropEffectsEx.Copy | DragDropEffectsEx.Move, DragDropEffectsEx.Copy));
            }
            else
            {
                return(QueryDropEffects.None);
            }
        }
Exemplo n.º 6
0
        public NumberTreeViewModel(string displayName)
        {
            Items = new ObservableCollection <NumberNodeViewModel>();


            var converter = new LambdaValueConverter <IDraggable, NumberModel>(
                d => (d is NumberViewModel) ? (d as NumberViewModel).Model : null,
                nm => new NumberNodeViewModel(this, nm));

            DragHelper = new LambdaDragHelper <NumberModel>(converter,
                                                            () => Items.Where(nvm => nvm.IsSelected).Select(nvm => nvm.Model).ToList(),
                                                            nms => DragDropEffectsEx.Move,
                                                            (nms, eff) =>
            {
                foreach (var nm in nms)
                {
                    Items.Remove(new NumberNodeViewModel(this, nm));
                }
            }
                                                            );
            DropHelper = new LambdaDropHelper <NumberModel>(converter,
                                                            (nms, eff) =>
            {
                foreach (var nm in nms)
                {
                    if (Items.Any(ivm => ivm.Model.Equals(nm)))
                    {
                        return(QueryDropEffects.None);
                    }
                }
                return(QueryDropEffects.CreateNew(DragDropEffectsEx.Move));
            },
                                                            (nms, eff) =>
            {
                foreach (var nm in nms)
                {
                    Items.Add(new NumberNodeViewModel(this, nm));
                }
                return(DragDropEffectsEx.Move);
            })
            {
                DisplayName = displayName
            };
        }
Exemplo n.º 7
0
        public FileListViewModel(string label)
        {
            Items = new ObservableCollection <FileViewModel>();

            #region Initialize DynamicCommandDictionary

            Commands = new DynamicRelayCommandDictionary()
            {
                ParameterDicConverter = ParameterDicConverters.FromParameterDic(
                    new ParameterDic()
                {
                    { "FileListVM", this }
                })
            };

            Commands.UnselectAll = _unselectCommand;

            #endregion

            #region Initialize DragHelper and DropHelper

            DragHelper = new LambdaShellDragHelper <FileModel>(
                _fileModelConverter,                                                                  //Convert IDraggable (FileViewModel) to M (FileModel), ConvertBack is used.
                _dataObjectConverter,                                                                 //Convert IEnumerable<M> (IEnumerable<FileModel>) to IDataObject, Convert is used.
                () => Items.Where(fvm => fvm.IsSelected).Select(fvm => fvm.Model),
                (fmList) => DragDropEffectsEx.Link | DragDropEffectsEx.Copy | DragDropEffectsEx.Move, //QueryDrag
                (fmList, da, effect) =>                                                               //OnDragCompleted
            {
                if (effect == DragDropEffectsEx.Move)
                {
                    foreach (var f in fmList)
                    {
                        var foundItem = Items.FirstOrDefault(fvm => fvm.Model.Equals(f));
                        if (foundItem != null)
                        {
                            Items.Remove(foundItem);
                        }
                    }
                }
            });

            DropHelper = new LambdaShellDropHelper <FileModel>(
                _fileModelConverter,  //Convert IDraggable (FileViewModel) to M (FileModel), Convert is used.
                _dataObjectConverter, //Convert IEnumerable<M> (IEnumerable<FileModel>) to IDataObject, ConvertBack is used.
                (fms, eff) =>         //QueryDrop(IEnumerable<FileModel>, DragDropEffectsEx) : QueryDropEffects
            {
                IEnumerable <FileModel> itemsModel = Items.Select(fvm => fvm.Model);
                if (fms.Any(f => itemsModel.Contains(f)))
                {
                    return(QueryDropEffects.None);
                }
                return(QueryDropEffects.CreateNew(eff & (DragDropEffectsEx.Link | DragDropEffectsEx.Move), eff & DragDropEffectsEx.Move));
            },
                (fms, da, eff) => //Drop(IEnumerable<FileModel>, IDataObject, DragDropEffectsEx) : DragDropEffectsEx
            {
                foreach (var existingFvm in Items)
                {
                    existingFvm.IsSelected = false;
                }
                foreach (var fm in fms)
                {
                    Items.Add(new FileViewModel(fm));
                }
                if (eff.HasFlag(DragDropEffectsEx.Move))
                {
                    return(DragDropEffectsEx.Move);
                }
                if (eff.HasFlag(DragDropEffectsEx.Copy))
                {
                    return(DragDropEffectsEx.Copy);
                }
                return(DragDropEffectsEx.Link);
            })
            {
                DisplayName = label
            };

            #endregion
        }