public void ReOrderActionGroups(int sourceIndex, int targetIndex)
        {
            CharacterActionGroupViewModel sourceViewModel = this.CharacterActionGroups[sourceIndex];

            this.CharacterActionGroups.RemoveAt(sourceIndex);
            this.EditedCharacter.RemoveActionGroupAt(sourceIndex);
            this.CharacterActionGroups.Insert(targetIndex, sourceViewModel);
            this.EditedCharacter.InsertActionGroup(targetIndex, sourceViewModel.ActionGroup);

            this.EventAggregator.Publish(new CrowdCollectionModifiedEvent(), action => System.Windows.Application.Current.Dispatcher.Invoke(action));
        }
        private void GroupBox_PreviewDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(OPTION_DRAG_KEY))
            {
                expanderExpandedForDrop = false;
                GroupBox groupBox = (GroupBox)sender;
                Tuple <CharacterActionGroupViewModel, int, CharacterAction> dragDropDataTuple = e.Data.GetData(OPTION_DRAG_KEY) as Tuple <CharacterActionGroupViewModel, int, CharacterAction>;
                if (dragDropDataTuple != null)
                {
                    CharacterActionGroupViewModel sourceViewModel = dragDropDataTuple.Item1;
                    int             sourceIndex = dragDropDataTuple.Item2;
                    CharacterAction option      = dragDropDataTuple.Item3;
                    if (this.viewModel.ActionGroup.Type == CharacterActionType.Mixed && sourceViewModel.ActionGroup.Type != CharacterActionType.Mixed) // do a copy paste
                    {
                        sourceIndex = -1;
                    }
                    int targetIndex = 0;

                    ListBoxItem listBoxItem;
                    FindDropTarget(groupBox, out listBoxItem, e);
                    if (listBoxItem != null)
                    {
                        CharacterAction target = listBoxItem.DataContext as CharacterAction;
                        if (dragDropDataTuple != null && target != null)
                        {
                            targetIndex = optionListBox.Items.IndexOf(target);
                        }
                    }
                    else
                    {
                        targetIndex = optionListBox.Items != null ? optionListBox.Items.Count : 0; // append to last of current option group
                        if (sourceIndex >= 0 && this.viewModel == sourceViewModel)                 // an item will be removed from the current option group, so reduce target index by 1
                        {
                            targetIndex -= 1;
                        }
                    }
                    if (sourceViewModel != null && sourceIndex >= 0)
                    {
                        sourceViewModel.RemoveAction(sourceIndex);
                    }
                    this.viewModel.InsertAction(option, targetIndex);
                    this.viewModel.SaveActionGroup();
                }
            }
        }
Esempio n. 3
0
 private void ListView_PreviewDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(OPTION_GROUP_DRAG_KEY))
     {
         string       draggingOPtionGroupName = e.Data.GetData(OPTION_GROUP_DRAG_KEY) as string;
         ListViewItem listViewItem;
         FindDropTarget(sender as ListView, out listViewItem, e);
         if (listViewItem != null)
         {
             CharacterActionGroupViewModel targetViewModel = listViewItem.DataContext as CharacterActionGroupViewModel;
             if (targetViewModel.ActionGroup.Name != draggingOPtionGroupName)
             {
                 var sourceViewModel = this.viewModel.CharacterActionGroups.FirstOrDefault(vm => vm.ActionGroup.Name == draggingOPtionGroupName);
                 int sourceIndex     = this.viewModel.CharacterActionGroups.IndexOf(sourceViewModel);
                 int targetIndex     = this.viewModel.CharacterActionGroups.IndexOf(targetViewModel);
                 this.viewModel.ReOrderActionGroups(sourceIndex, targetIndex);
             }
         }
     }
 }
 private void grpBoxOptionGroup_PreviewDragOver(object sender, DragEventArgs e)
 {
     if (!e.Data.GetDataPresent(OPTION_DRAG_KEY) || sender == e.Source)
     {
         e.Effects = DragDropEffects.None;
     }
     else
     {
         Tuple <CharacterActionGroupViewModel, int, CharacterAction> dragDropDataTuple = e.Data.GetData(OPTION_DRAG_KEY) as Tuple <CharacterActionGroupViewModel, int, CharacterAction>;
         CharacterActionGroupViewModel sourceViewModel = dragDropDataTuple.Item1;
         if (sourceViewModel != this.viewModel && this.viewModel.ActionGroup.Type != CharacterActionType.Mixed)
         {
             e.Effects = DragDropEffects.None;
         }
     }
     if (e.Effects != DragDropEffects.None && !this.ExpanderOptionGroup.IsExpanded)
     {
         this.ExpanderOptionGroup.IsExpanded = expanderExpandedForDrop = true;
     }
     e.Handled = true;
 }
 private void CharacterActionGroupView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     this.viewModel = this.DataContext as CharacterActionGroupViewModel;
     this.viewModel.EditModeEnter += viewModel_EditModeEnter;
     this.viewModel.EditModeLeave += viewModel_EditModeLeave;
 }