public void MoveBlockToBottom(IItemFilterBlockViewModel targetBlockViewModel) { var currentIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModel); if (currentIndex < ItemFilterBlockViewModels.Count - 1) { var block = targetBlockViewModel.Block; Script.ItemFilterBlocks.Remove(block); Script.ItemFilterBlocks.Add(block); ItemFilterBlockViewModels.Move(currentIndex, ItemFilterBlockViewModels.Count - 1); IsDirty = true; RaisePropertyChanged("ItemFilterSectionViewModels"); } }
public void MoveBlockToTop(IItemFilterBlockViewModel targetBlockViewModel) { var currentIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModel); if (currentIndex > 0) { var block = targetBlockViewModel.Block; Script.ItemFilterBlocks.Remove(block); Script.ItemFilterBlocks.Insert(0, block); ItemFilterBlockViewModels.Move(currentIndex, 0); IsDirty = true; RaisePropertyChanged("ItemFilterSectionViewModels"); } }
public void MoveBlockDown(IItemFilterBlockViewModel targetBlockViewModel) { var currentIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModel); if (currentIndex < ItemFilterBlockViewModels.Count - 1) { var block = targetBlockViewModel.Block; var blockPos = Script.ItemFilterBlocks.IndexOf(block); Script.ItemFilterBlocks.RemoveAt(blockPos); Script.ItemFilterBlocks.Insert(blockPos + 1, block); ItemFilterBlockViewModels.Move(currentIndex, currentIndex + 1); IsDirty = true; RaisePropertyChanged("ItemFilterSectionViewModels"); } }
public void AddSection(IItemFilterBlockViewModel targetBlockViewModel) { var vm = _itemFilterBlockViewModelFactory.Create(); var newSection = new ItemFilterSection { Description = "New Section" }; vm.Initialise(newSection, this); Script.ItemFilterBlocks.Insert(Script.ItemFilterBlocks.IndexOf(targetBlockViewModel.Block), newSection); ItemFilterBlockViewModels.Insert(ItemFilterBlockViewModels.IndexOf(targetBlockViewModel), vm); IsDirty = true; SelectedBlockViewModel = vm; RaisePropertyChanged("ItemFilterSectionViewModels"); }
public void MoveBlockUp(IItemFilterBlockViewModel targetBlockViewModel) { var currentIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModel); if (currentIndex > 0) { var block = targetBlockViewModel.Block; var blockPos = Script.ItemFilterBlocks.IndexOf(block); Script.ItemFilterBlocks.RemoveAt(blockPos); Script.ItemFilterBlocks.Insert(blockPos - 1, block); ItemFilterBlockViewModels.Move(currentIndex, currentIndex - 1); IsDirty = true; RaisePropertyChanged(nameof(ItemFilterSectionViewModels)); } }
public void AddSection(IItemFilterBlockViewModel targetBlockViewModel) { var vm = _itemFilterBlockViewModelFactory.Create(); var newSection = new ItemFilterSection { Description = "New Section" }; vm.Initialise(newSection, this); Script.ItemFilterBlocks.Insert(Script.ItemFilterBlocks.IndexOf(targetBlockViewModel.Block), newSection); ItemFilterBlockViewModels.Insert(ItemFilterBlockViewModels.IndexOf(targetBlockViewModel), vm); IsDirty = true; SelectedBlockViewModel = vm; RaisePropertyChanged(nameof(ItemFilterSectionViewModels)); Messenger.Default.Send(new NotificationMessage("SectionsChanged")); }
public void PasteBlock(IItemFilterBlockViewModel targetBlockViewModel) { try { var clipboardText = _clipboardService.GetClipboardText(); if (string.IsNullOrEmpty(clipboardText)) { return; } _blockGroupHierarchyBuilder.Initialise(Script.ItemFilterBlockGroups.First()); var translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(clipboardText, Script.ThemeComponents); if (translatedBlock == null) { return; } var vm = _itemFilterBlockViewModelFactory.Create(); vm.Initialise(translatedBlock, this); if (ItemFilterBlockViewModels.Count > 0) { Script.ItemFilterBlocks.Insert(Script.ItemFilterBlocks.IndexOf(targetBlockViewModel.Block) + 1, translatedBlock); ItemFilterBlockViewModels.Insert(ItemFilterBlockViewModels.IndexOf(targetBlockViewModel) + 1, vm); } else { Script.ItemFilterBlocks.Add(translatedBlock); ItemFilterBlockViewModels.Add(vm); } SelectedBlockViewModel = vm; IsDirty = true; } catch (Exception e) { _logger.Error(e); var innerException = e.InnerException != null ? e.InnerException.Message : string.Empty; _messageBoxService.Show("Paste Error", e.Message + Environment.NewLine + innerException, MessageBoxButton.OK, MessageBoxImage.Error); } }
public void AddBlock(IItemFilterBlockViewModel targetBlockViewModel) { var vm = _itemFilterBlockViewModelFactory.Create(); var newBlock = new ItemFilterBlock(); vm.Initialise(newBlock, this); if (targetBlockViewModel != null) { Script.ItemFilterBlocks.Insert(Script.ItemFilterBlocks.IndexOf(targetBlockViewModel.Block) + 1, newBlock); ItemFilterBlockViewModels.Insert(ItemFilterBlockViewModels.IndexOf(targetBlockViewModel) + 1, vm); } else { Script.ItemFilterBlocks.Add(newBlock); ItemFilterBlockViewModels.Add(vm); } SelectedBlockViewModel = vm; vm.IsExpanded = true; IsDirty = true; }
public ItemFilterScriptViewModel(IItemFilterBlockBaseViewModelFactory itemFilterBlockBaseViewModelFactory, IItemFilterBlockTranslator blockTranslator, IAvalonDockWorkspaceViewModel avalonDockWorkspaceViewModel, IItemFilterPersistenceService persistenceService, IMessageBoxService messageBoxService, IClipboardService clipboardService, IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder) { _itemFilterBlockBaseViewModelFactory = itemFilterBlockBaseViewModelFactory; _blockTranslator = blockTranslator; _avalonDockWorkspaceViewModel = avalonDockWorkspaceViewModel; _avalonDockWorkspaceViewModel.ActiveDocumentChanged += OnActiveDocumentChanged; _persistenceService = persistenceService; _messageBoxService = messageBoxService; _clipboardService = clipboardService; _blockGroupHierarchyBuilder = blockGroupHierarchyBuilder; _itemFilterBlockViewModels = new ObservableCollection <IItemFilterBlockViewModelBase>(); _avalonDockWorkspaceViewModel.ActiveDocumentChanged += (s, e) => { RaisePropertyChanged(nameof(IsActiveDocument)); }; ToggleShowAdvancedCommand = new RelayCommand <bool>(OnToggleShowAdvancedCommand); ClearFilterCommand = new RelayCommand(OnClearFilterCommand, () => BlockFilterPredicate != null); CloseCommand = new RelayCommand(async() => await OnCloseCommand()); DeleteBlockCommand = new RelayCommand(OnDeleteBlockCommand, () => SelectedBlockViewModel != null); MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand, () => SelectedBlockViewModel != null && ItemFilterBlockViewModels.IndexOf(SelectedBlockViewModel) > 0); MoveBlockUpCommand = new RelayCommand(OnMoveBlockUpCommand, () => SelectedBlockViewModel != null && ItemFilterBlockViewModels.IndexOf(SelectedBlockViewModel) > 0); MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand, () => SelectedBlockViewModel != null && ItemFilterBlockViewModels.IndexOf(SelectedBlockViewModel) < ItemFilterBlockViewModels.Count); MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand, () => SelectedBlockViewModel != null && ItemFilterBlockViewModels.IndexOf(SelectedBlockViewModel) < ItemFilterBlockViewModels.Count); AddBlockCommand = new RelayCommand(OnAddBlockCommand); AddSectionCommand = new RelayCommand(OnAddCommentBlockCommand, () => SelectedBlockViewModel != null); DisableBlockCommand = new RelayCommand(OnDisableBlockCommand, HasSelectedEnabledBlock); EnableBlockCommand = new RelayCommand(OnEnableBlockCommand, HasSelectedDisabledBlock); CopyBlockCommand = new RelayCommand(OnCopyBlockCommand, () => SelectedBlockViewModel != null); CopyBlockStyleCommand = new RelayCommand(OnCopyBlockStyleCommand, () => SelectedBlockViewModel != null); PasteBlockCommand = new RelayCommand(OnPasteBlockCommand, () => SelectedBlockViewModel != null); PasteBlockStyleCommand = new RelayCommand(OnPasteBlockStyleCommand, () => SelectedBlockViewModel != null); ExpandAllBlocksCommand = new RelayCommand(OnExpandAllBlocksCommand); CollapseAllBlocksCommand = new RelayCommand(OnCollapseAllBlocksCommand); var icon = new BitmapImage(); icon.BeginInit(); icon.UriSource = new Uri("pack://application:,,,/Filtration;component/Resources/Icons/script_icon.png"); icon.EndInit(); IconSource = icon; }