コード例 #1
0
        public void SwapBlocks(int sourceIndex, int destinationIndex)
        {
            Block block = blocks[sourceIndex];

            blocks.RemoveAt(sourceIndex);
            blocks.Insert(destinationIndex, block);

            // Context for moved block, source, source + 1, and destination + 1 blocks possibly changed so update viewmodels
            BlockViewModel movedBlockViewModel = blockViewModelFactory.CreateBlockViewModel(block, blocks);

            blockViewModels.RemoveAt(sourceIndex);
            blockViewModels.Insert(destinationIndex, movedBlockViewModel);

            BlockViewModel newBlockAtSource = blockViewModelFactory.CreateBlockViewModel(blocks[sourceIndex], blocks);

            blockViewModels[sourceIndex] = newBlockAtSource;

            if (sourceIndex + 1 < blocks.Count)
            {
                BlockViewModel afterSource = blockViewModelFactory.CreateBlockViewModel(blocks[sourceIndex + 1], blocks);
                blockViewModels[sourceIndex + 1] = afterSource;
            }

            if (destinationIndex + 1 < blocks.Count)
            {
                BlockViewModel afterDestination = blockViewModelFactory.CreateBlockViewModel(blocks[destinationIndex + 1], blocks);
                blockViewModels[destinationIndex + 1] = afterDestination;
            }

            programRepository.Update(blocks);
            BlocksChanged?.Invoke(this, EventArgs.Empty);
        }
コード例 #2
0
        void AddBlock(Block block)
        {
            blocks.Add(block);
            blockViewModels.Add(blockViewModelFactory.CreateBlockViewModel(block, blocks));

            programRepository.Update(blocks);
            BlocksChanged?.Invoke(this, EventArgs.Empty);
        }
コード例 #3
0
        void ReplaceBlock(Block oldBlock, Block newBlock)
        {
            int index = blocks.FindIndex(block => block == oldBlock);

            if (index >= 0)
            {
                blocks[index]          = newBlock;
                blockViewModels[index] = blockViewModelFactory.CreateBlockViewModel(newBlock, blocks);

                programRepository.Update(blocks);
                BlocksChanged?.Invoke(this, EventArgs.Empty);
            }
        }
コード例 #4
0
        void RemoveBlock(Block block)
        {
            int index = blocks.FindIndex(b => b == block);

            if (index >= 0)
            {
                blocks.RemoveAt(index);
                blockViewModels.RemoveAt(index);

                // Create new view model to set new context blocks
                if (index < blocks.Count)
                {
                    BlockViewModel newBlockViewModel = blockViewModelFactory.CreateBlockViewModel(blocks[index], blocks);
                    blockViewModels[index] = newBlockViewModel;
                }

                programRepository.Update(blocks);
                BlocksChanged?.Invoke(this, EventArgs.Empty);
            }
        }