Exemplo n.º 1
0
        private static void OnPreviewDragOver(object sender, DragEventArgs e)
        {
            var dropInfo    = new DropInfo(sender, e, _dragInfo, Format.Name);
            var dropHandler = GetDropHandler((UIElement)sender);

            if (dropHandler != null)
            {
                dropHandler.DragOver(dropInfo);
            }
            else
            {
                DefaultDropHandler.DragOver(dropInfo);
            }

            UpdateDragAdorner(dropInfo, e);

            var target = sender as ItemsControl;

            if (target != null)
            {
                UpdateTargetDropAdorner(target, dropInfo);
            }

            e.Effects = dropInfo.Effects;
            e.Handled = true;

            Scroll((DependencyObject)sender, e);
        }
Exemplo n.º 2
0
 void IDropTarget.DragOver(IDropInfo dropInfo)
 {
     if (DefaultDropHandler.CanAcceptData(dropInfo))
     {
         var isTreeViewItem          = dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter) && dropInfo.VisualTargetItem is TreeViewItem;
         RemoteTreeViewItem srcItem  = dropInfo.Data as RemoteTreeViewItem;
         RemoteTreeViewItem destItem = dropInfo.TargetItem as RemoteTreeViewItem;
         if (destItem != null)
         {
             if (destItem.RemoteType != RemoteType.dir && destItem.Parent == srcItem.Parent)
             {
                 return;
             }
             if (destItem == srcItem.Parent)
             {
                 return;
             }
         }
         else
         {
             if (srcItem.Parent is RemoteTreeViewItem == false)
             {
                 return;
             }
         }
         dropInfo.Effects = DefaultDropHandler.ShouldCopyData(dropInfo) ? DragDropEffects.Copy : DragDropEffects.Move;
         if (isTreeViewItem)
         {
             dropInfo.DropTargetAdorner = typeof(RemooeTreeHighlightAdorner);
         }
     }
 }
        private async void HandleDropActionAsync(IDropInfo dropInfo, IList fileOrDirDropList)
        {
            if (this.FileSearchWorker.CanStartSearch())
            {
                var files = await this.FileSearchWorker.StartSearchAsync(fileOrDirDropList);

                var currentFilesCollView = this.FirstSimplePlaylistFiles as ICollectionView;

                if (currentFilesCollView == null)
                {
                    var filesColl     = new PlayListObservableCollection(files);
                    var filesCollView = CollectionViewSource.GetDefaultView(filesColl);
                    this.FirstSimplePlaylistFiles = filesCollView;
                    ((ICollectionView)this.FirstSimplePlaylistFiles).MoveCurrentTo(null);
                }
                else
                {
                    var insertIndex     = dropInfo.InsertIndex;
                    var destinationList = DefaultDropHandler.GetList(dropInfo.TargetCollection);
                    foreach (var o in files)
                    {
                        destinationList.Insert(insertIndex++, o);
                    }

                    var mediaFiles = destinationList.OfType <IMediaFile>();//.ToList();
                    this.ResetPlayListIndices(mediaFiles);
                }
            }
        }
        protected override bool CanHandleData(object data)
        {
            var items = DefaultDropHandler.ExtractData(data)?.OfType <GiftItemModel>();

            return(items?.Any() == true && this.recipient.Gifts == null);
            //return base.CanHandle(dropInfo);
        }
 public override void Drop(IDropInfo dropInfo)
 {
     if (this.CanHandleData(dropInfo.Data))
     {
         this.recipient.Gifts = DefaultDropHandler.ExtractData(dropInfo.Data)?
                                .OfType <GiftItemModel>()
                                .ToList();
     }
 }
Exemplo n.º 6
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            if (!(dropInfo.VisualTarget is DataGrid))
            {
                return;
            }

            if (dropInfo.TargetGroup == null)
            {
                HandleEx(dropInfo);
                return;
            }

            int    target_posse_id;
            string target_group_name = dropInfo.TargetGroup.Name.ToString();

            if (Int32.TryParse(target_group_name, out target_posse_id))
            {
                var shooters           = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <Shooter>().ToList();
                var match_participants = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <MatchParticipation>().ToList();

                if ((shooters != null) && (shooters.Count > 0))
                {
                    foreach (Shooter s in shooters)
                    {
                        MatchParticipation mp = new MatchParticipation()
                        {
                            ShooterID = s.ShooterID,
                            MatchID   = _m.MatchID,
                            Posse     = (int)target_posse_id,
                            Category  = s.Category
                        };

                        _ctx.MatchParticipations.Attach(mp);

                        if (!_ctx.MatchParticipations.Any(x => x.Match.MatchID.Equals(_m.MatchID) && x.Shooter.ShooterID.Equals(s.ShooterID)))
                        {
                            _ctx.MatchParticipations.Add(mp);
                        }

                        _ctx.SaveChanges();
                    }
                }
                else if ((match_participants != null) && (match_participants.Count > 0))
                {
                    foreach (MatchParticipation mp in match_participants)
                    {
                        _ctx.MatchParticipations.Where(x => x.MatchParticipationId.Equals(mp.MatchParticipationId)).First().Posse = (int)target_posse_id;
                    }

                    _ctx.SaveChanges();
                }

                Refresh();
            }
        }
Exemplo n.º 7
0
        public ModuleOrderTabViewModel(IPluginManagementService pluginManagementService, IModuleService moduleService)
        {
            DisplayName = "MODULE PRIORITY";

            _pluginManagementService = pluginManagementService;
            _moduleService           = moduleService;
            _defaultDropHandler      = new DefaultDropHandler();

            NormalModules      = new BindableCollection <ModuleOrderModuleViewModel>();
            ApplicationModules = new BindableCollection <ModuleOrderModuleViewModel>();
            OverlayModules     = new BindableCollection <ModuleOrderModuleViewModel>();
        }
Exemplo n.º 8
0
 public void DragOver(IDropInfo dropInfo)
 {
     if (DefaultDropHandler.CanAcceptData(dropInfo))
     {
         // default should always the move action/effect
         var copyData = (dropInfo.DragInfo.DragDropCopyKeyState != default(DragDropKeyStates)) && dropInfo.KeyStates.HasFlag(dropInfo.DragInfo.DragDropCopyKeyState)
                        //&& (dropInfo.DragInfo.VisualSource != dropInfo.VisualTarget)
                        && !(dropInfo.DragInfo.SourceItem is HeaderedContentControl) &&
                        !(dropInfo.DragInfo.SourceItem is HeaderedItemsControl) &&
                        !(dropInfo.DragInfo.SourceItem is ListBoxItem);
         dropInfo.Effects = copyData ? DragDropEffects.Copy : DragDropEffects.Move;
         var isTreeViewItem = dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter) && dropInfo.VisualTargetItem is TreeViewItem;
         dropInfo.DropTargetAdorner = isTreeViewItem ? DropTargetAdorners.Highlight : DropTargetAdorners.Insert;
     }
 }
Exemplo n.º 9
0
        public ModuleOrderTabViewModel(IPluginService pluginService, IModuleService moduleService)
        {
            DisplayName = "MODULE PRIORITY";

            _pluginService      = pluginService;
            _moduleService      = moduleService;
            _modules            = new List <ModuleOrderModuleViewModel>(pluginService.GetPluginsOfType <Module>().Select(m => new ModuleOrderModuleViewModel(m)));
            _defaultDropHandler = new DefaultDropHandler();

            NormalModules      = new BindableCollection <ModuleOrderModuleViewModel>();
            ApplicationModules = new BindableCollection <ModuleOrderModuleViewModel>();
            OverlayModules     = new BindableCollection <ModuleOrderModuleViewModel>();

            Update();
        }
Exemplo n.º 10
0
        public void Drop(IDropInfo dropInfo)
        {
            // The default drop handler don't know how to set an item's group. You need to explicitly set the group on the dropped item like this.
            GongSolutions.Wpf.DragDrop.DragDrop.DefaultDropHandler.Drop(dropInfo);

            // Now extract the dragged group items and set the new group (target)
            System.Collections.Generic.List <PlusPropertyDescriptor> data = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <PlusPropertyDescriptor>().ToList();
            foreach (PlusPropertyDescriptor groupedItem in data)
            {
                // groupedItem.GroupName = dropInfo.TargetGroup.Name.ToString();
            }

            // Changing group data at runtime isn't handled well: force a refresh on the collection view.
            if (dropInfo.TargetCollection is ICollectionView)
            {
                ((ICollectionView)dropInfo.TargetCollection).Refresh();
            }
        }
Exemplo n.º 11
0
        public void Drop(IDropInfo dropInfo)
        {
            DragDrop.DefaultDropHandler.Drop(dropInfo);

            // Now extract the dragged group items and set the new group (target)
            var data = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <Card>().ToList();

            foreach (var groupedItem in data)
            {
                groupedItem.View.Content = dropInfo.Data;
            }

            // Changing group data at runtime isn't handled well: force a refresh on the collection view.
            if (dropInfo.TargetCollection is ICollectionView view)
            {
                view.Refresh();
            }
        }
Exemplo n.º 12
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            // I know this example is called DefaultsExample, but the default handlers don't know how
            // to set an item's group. You need to explicitly set the group on the dropped item like this.
            DragDrop.DefaultDropHandler.Drop(dropInfo);
            var data = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <GroupedItem>().ToList();

            foreach (var groupedItem in data)
            {
                groupedItem.Group = dropInfo.TargetGroup.Name.ToString();
            }

            // Changing group data at runtime isn't handled well: force a refresh on the collection view.
            if (dropInfo.TargetCollection is ICollectionView)
            {
                ((ICollectionView)dropInfo.TargetCollection).Refresh();
            }
        }
Exemplo n.º 13
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            if (!(DataContext is LibraryVM libraryVM))
            {
                Log.Error("DataContext of SongsGrid is not LibraryVM in Songs_OnDrop, but is {type}", DataContext?.GetType());
                return;
            }

            if (!(Songs.ItemsSource is ListCollectionView view))
            {
                Log.Error("ItemSource of the SongsGrid is not a ListCollectionView, but is a {itemsSource}", Songs.ItemsSource?.GetType());
                return;
            }

            DefaultDropHandler handler = new DefaultDropHandler();

            handler.Drop(dropInfo);
            libraryVM.ResetSongsInCurrentPlaylist(view.SourceCollection.Cast <SongItem>().Select(x => x.Id));
        }
Exemplo n.º 14
0
        private static void OnPreviewDrop(object sender, DragEventArgs e)
        {
            var dropInfo    = new DropInfo(sender, e, _dragInfo, Format.Name);
            var dropHandler = GetDropHandler((UIElement)sender);

            DragAdorner       = null;
            DropTargetAdorner = null;

            if (dropHandler != null)
            {
                dropHandler.Drop(dropInfo);
            }
            else
            {
                DefaultDropHandler.Drop(dropInfo);
            }

            e.Handled = true;
        }
Exemplo n.º 15
0
        public static void DragOver(IDropInfo dropInfo)
        {
            if (dropInfo.DragInfo == null)
            {
                if (dropInfo.Data is DataObject data && data.ContainsFileDropList())
                {
                    dropInfo.Effects = DragDropEffects.Copy;
                }
            }
            else if (DefaultDropHandler.CanAcceptData(dropInfo))
            {
                dropInfo.Effects = DragDropEffects.Move;
            }

            if (dropInfo.Effects != DragDropEffects.None)
            {
                dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
            }
        }
Exemplo n.º 16
0
        public void Drop(IDropInfo dropInfo)
        {
            bool stringFlag = false;

            if (dropInfo.DragInfo == null && dropInfo.Data is IToolboxItem item && dropInfo.IsSameDragDropContextAsSource)
            {
                if (item.DataSource.Data.Format != DataFormats.Text)
                {
                    return;
                }
                stringFlag = true;
            }
            if (dropInfo.IsSameDragDropContextAsSource && !stringFlag)
            {
                //Restore original data
                dropInfo.Data = dropInfo.DragInfo.SourceItem;
            }
            if (stringFlag)
            {
                var destinationList = dropInfo.TargetCollection.TryGetList();
                if (destinationList != null)
                {
                    destinationList.Insert(dropInfo.InsertIndex, dropInfo.Data);

                    var selectDroppedItems = DragDrop.DragDrop.GetSelectDroppedItems(dropInfo.VisualTarget);
                    if (selectDroppedItems)
                    {
                        DefaultDropHandler.SelectDroppedItems(dropInfo, new List <object> {
                            dropInfo.Data
                        });
                    }
                }
            }
            else
            {
                DragDrop.DragDrop.DefaultDropHandler.Drop(dropInfo);
            }
        }
        /// <inheritdoc />
        public void Drop(IDropInfo dropInfo)
        {
            var textBox = (TextBox)dropInfo.VisualTarget;

            if (dropInfo.Data is IDataObject dataObject)
            {
                if (dataObject.GetDataPresent(DataFormats.Text))
                {
                    textBox.Text = dataObject.GetData(DataFormats.Text) as string ?? string.Empty;
                }
                else if (dataObject.GetDataPresent(DataFormats.FileDrop))
                {
                    // Note that you can have more than one file.
                    string[] files = (string[])dataObject.GetData(DataFormats.FileDrop);
                    textBox.Text = string.Join(Environment.NewLine, files);
                }
            }
            else
            {
                var realData = DefaultDropHandler.ExtractData(dropInfo.Data);
                textBox.Text = string.Join(", ", realData.OfType <object>().ToArray());
            }
        }
Exemplo n.º 18
0
        void HandleEx(IDropInfo di)
        {
            DataGrid t = di.VisualTarget as DataGrid;

            var shooters = DefaultDropHandler.ExtractData(di.Data).OfType <Shooter>().ToList();

            if ((shooters != null) && (shooters.Count > 0))
            {
                foreach (Shooter s in shooters)
                {
                    MatchParticipation mp = new MatchParticipation()
                    {
                        ShooterID = s.ShooterID,
                        MatchID   = _m.MatchID,
                        Posse     = 0,
                        Category  = s.Category
                    };

                    if (t.Name.Equals("SpeedTicketGrid"))
                    {
                        mp.IsSpeedTicket = true;
                    }

                    _ctx.MatchParticipations.Attach(mp);

                    if (!_ctx.MatchParticipations.Any(x => x.Match.MatchID.Equals(_m.MatchID) && x.Shooter.ShooterID.Equals(s.ShooterID)))
                    {
                        _ctx.MatchParticipations.Add(mp);
                    }

                    _ctx.SaveChanges();
                }
                Refresh();
                return;
            }
        }
Exemplo n.º 19
0
        public static async Task Drop(IDropInfo dropInfo)
        {
            var invalid = new List <string>();

            var insertIndex     = dropInfo.UnfilteredInsertIndex;
            var destinationList = dropInfo.TargetCollection.TryGetList();

            if (dropInfo.DragInfo == null)
            {
                if (!(dropInfo.Data is DataObject data) || !data.ContainsFileDropList())
                {
                    return;
                }

                foreach (var o in data.GetFileDropList())
                {
                    try
                    {
                        var toInsert = await MainWindow.CreateGdItemAsync(o);

                        destinationList.Insert(insertIndex++, toInsert);
                    }
                    catch
                    {
                        invalid.Add(o);
                    }
                }
            }
            else
            {
                var data = DefaultDropHandler.ExtractData(dropInfo.Data).OfType <object>().ToList();

                var sourceList = dropInfo.DragInfo.SourceCollection.TryGetList();
                if (sourceList != null)
                {
                    foreach (var o in data)
                    {
                        var index = sourceList.IndexOf(o);
                        if (index != -1)
                        {
                            sourceList.RemoveAt(index);
                            if (destinationList != null && Equals(sourceList, destinationList) && index < insertIndex)
                            {
                                --insertIndex;
                            }
                        }
                    }
                }

                if (destinationList != null)
                {
                    foreach (var o in data)
                    {
                        destinationList.Insert(insertIndex++, o);
                    }
                }
            }

            if (invalid.Any())
            {
                throw new InvalidDropException(string.Join(Environment.NewLine, invalid));
            }
        }
Exemplo n.º 20
0
        public void Drop(IDropInfo dropInfo)
        {
            if (dropInfo == null || dropInfo.DragInfo == null)
            {
                return;
            }
            var insertIndex = dropInfo.InsertIndex != dropInfo.UnfilteredInsertIndex ? dropInfo.UnfilteredInsertIndex : dropInfo.InsertIndex;

            var itemsControl = dropInfo.VisualTarget as ItemsControl;

            if (itemsControl != null)
            {
                var editableItems = itemsControl.Items as IEditableCollectionView;
                if (editableItems != null)
                {
                    var newItemPlaceholderPosition = editableItems.NewItemPlaceholderPosition;
                    if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtBeginning && insertIndex == 0)
                    {
                        ++insertIndex;
                    }
                    else if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtEnd && insertIndex == itemsControl.Items.Count)
                    {
                        --insertIndex;
                    }
                }
            }

            var destinationList = dropInfo.TargetCollection.TryGetList();
            var data            = DefaultDropHandler.ExtractData(dropInfo.Data);

            // default should always the move action/effect
            var copyData = (dropInfo.DragInfo.DragDropCopyKeyState != default(DragDropKeyStates)) && dropInfo.KeyStates.HasFlag(dropInfo.DragInfo.DragDropCopyKeyState)
                           //&& (dropInfo.DragInfo.VisualSource != dropInfo.VisualTarget)
                           && !(dropInfo.DragInfo.SourceItem is HeaderedContentControl) &&
                           !(dropInfo.DragInfo.SourceItem is HeaderedItemsControl) &&
                           !(dropInfo.DragInfo.SourceItem is ListBoxItem);
            var selected = false;

            if (!copyData)
            {
                var sourceList = dropInfo.DragInfo.SourceCollection.TryGetList();

                foreach (var o in data)
                {
                    var index = sourceList.IndexOf(o);

                    var vm = (PlayListEntryViewModel)o;
                    selected = vm.IsSelected;

                    if (index != -1)
                    {
                        sourceList.RemoveAt(index);
                        // so, is the source list the destination list too ?
                        if (Equals(sourceList, destinationList) && index < insertIndex)
                        {
                            --insertIndex;
                        }
                    }
                }
            }
            foreach (var o in data)
            {
                var obj2Insert = (PlayListEntryViewModel)o;

                destinationList.Insert(insertIndex++, obj2Insert);

                if (selected)
                {
                    itemsControl.SetSelectedItem(obj2Insert);
                }
            }
        }
Exemplo n.º 21
0
        void IDropTarget.DragOver(IDropInfo dropInfo)
        {
            DefaultDropHandler handler = new DefaultDropHandler();

            handler.DragOver(dropInfo);
        }
        public void Drop(IDropInfo dropInfo)
        {
            var dataAsList = DefaultDropHandler.ExtractData(dropInfo.Data);

            ((TextBox)dropInfo.VisualTarget).Text = string.Join(", ", dataAsList.OfType <object>().ToArray());
        }
Exemplo n.º 23
0
        private async Task HandleDropActionAsync(IDropInfo dropInfo, IList fileOrDirDropList)
        {
            if (!this.FileSearchWorker.IsWorking)
            {
                var files = await this.FileSearchWorker.StartSearchAsync(fileOrDirDropList);

                var currentFilesCollView = this.FirstSimplePlaylistFiles as ICollectionView;

                if (currentFilesCollView == null)
                {
                    var filesColl     = new PlayListCollection(files);
                    var filesCollView = CollectionViewSource.GetDefaultView(filesColl);
                    this.FirstSimplePlaylistFiles = filesCollView;
                    ((ICollectionView)this.FirstSimplePlaylistFiles).MoveCurrentTo(null);
                }
                else
                {
                    var insertIndex     = dropInfo.InsertIndex;
                    var destinationList = (QuickFillObservableCollection <IMediaFile>)DefaultDropHandler.GetList(dropInfo.TargetCollection);
                    destinationList.AddItems(files, insertIndex);
                }
            }
        }
        /// <inheritdoc />
        public void Drop(IDropInfo dropInfo)
        {
            var wrapper = GetSerializableWrapper(dropInfo);

            if (wrapper == null || dropInfo.TargetCollection == null)
            {
                return;
            }

            // at this point the drag info can be null, cause the other app doesn't know it

            var  insertIndex      = dropInfo.UnfilteredInsertIndex;
            var  destinationList  = dropInfo.TargetCollection.TryGetList();
            var  data             = wrapper.Items.ToList();
            bool isSameCollection = false;

            var copyData = ShouldCopyData(dropInfo, wrapper.DragDropCopyKeyState);

            if (!copyData)
            {
                var sourceList = dropInfo.DragInfo?.SourceCollection?.TryGetList();
                if (sourceList != null)
                {
                    isSameCollection = sourceList.IsSameObservableCollection(destinationList);
                    if (!isSameCollection)
                    {
                        foreach (var o in data)
                        {
                            var index = sourceList.IndexOf(o);
                            if (index != -1)
                            {
                                sourceList.RemoveAt(index);

                                // so, is the source list the destination list too ?
                                if (destinationList != null && Equals(sourceList, destinationList) && index < insertIndex)
                                {
                                    --insertIndex;
                                }
                            }
                        }
                    }
                }
            }

            if (destinationList != null)
            {
                var objects2Insert = new List <object>();

                // check for cloning
                var cloneData = dropInfo.Effects.HasFlag(DragDropEffects.Copy) || dropInfo.Effects.HasFlag(DragDropEffects.Link);

                foreach (var o in data)
                {
                    var obj2Insert = o;
                    if (cloneData)
                    {
                        if (o is ICloneable cloneable)
                        {
                            obj2Insert = cloneable.Clone();
                        }
                    }

                    objects2Insert.Add(obj2Insert);

                    if (!cloneData && isSameCollection)
                    {
                        var index = destinationList.IndexOf(o);
                        if (index != -1)
                        {
                            if (insertIndex > index)
                            {
                                insertIndex--;
                            }

                            Move(destinationList, index, insertIndex++);
                        }
                    }
                    else
                    {
                        destinationList.Insert(insertIndex++, obj2Insert);
                    }
                }

                DefaultDropHandler.SelectDroppedItems(dropInfo, objects2Insert);
            }
        }