Add section features

This commit is contained in:
azakhi 2018-08-10 16:02:12 +03:00
parent 2c4096ff2c
commit bd730dd518
11 changed files with 616 additions and 18 deletions

View File

@ -0,0 +1,49 @@
using System.Collections.Generic;
namespace Filtration.ObjectModel.Commands.ItemFilterScript
{
public class MoveSectionToIndexCommand : IUndoableCommand
{
private readonly IItemFilterScript _itemFilterScript;
private int _sectionStart;
private int _sectionSize;
private int _index;
public MoveSectionToIndexCommand(IItemFilterScript itemFilterScript, int sectionStart, int sectionSize, int index)
{
_itemFilterScript = itemFilterScript;
_sectionStart = sectionStart;
_sectionSize = sectionSize;
_index = index;
}
public void Execute()
{
List<IItemFilterBlockBase> blocksToMove = new List<IItemFilterBlockBase>();
for(var i = 0; i < _sectionSize; i++)
{
blocksToMove.Add(_itemFilterScript.ItemFilterBlocks[_sectionStart]);
_itemFilterScript.ItemFilterBlocks.RemoveAt(_sectionStart);
}
for (var i = 0; i < _sectionSize; i++)
{
_itemFilterScript.ItemFilterBlocks.Insert(_index + i, blocksToMove[i]);
}
}
public void Undo()
{
List<IItemFilterBlockBase> blocksToMove = new List<IItemFilterBlockBase>();
for (var i = 0; i < _sectionSize; i++)
{
blocksToMove.Add(_itemFilterScript.ItemFilterBlocks[_index]);
_itemFilterScript.ItemFilterBlocks.RemoveAt(_index);
}
for (var i = 0; i < _sectionSize; i++)
{
_itemFilterScript.ItemFilterBlocks.Insert(_sectionStart + i, blocksToMove[i]);
}
}
public void Redo() => Execute();
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
namespace Filtration.ObjectModel.Commands.ItemFilterScript
{
public class PasteSectionCommand : IUndoableCommand
{
private readonly IItemFilterScript _itemFilterScript;
private readonly List<IItemFilterBlockBase> _pastedItemFilterBlocks;
private readonly IItemFilterBlockBase _addAfterItemFilterBlock;
public PasteSectionCommand(IItemFilterScript itemFilterScript, List<IItemFilterBlockBase> pastedItemFilterBlocks, IItemFilterBlockBase addAfterItemFilterBlock)
{
_itemFilterScript = itemFilterScript;
_pastedItemFilterBlocks = pastedItemFilterBlocks;
_addAfterItemFilterBlock = addAfterItemFilterBlock;
}
public void Execute()
{
if (_addAfterItemFilterBlock != null)
{
var lastAddedBlock = _addAfterItemFilterBlock;
foreach(var block in _pastedItemFilterBlocks)
{
_itemFilterScript.ItemFilterBlocks.Insert(_itemFilterScript.ItemFilterBlocks.IndexOf(lastAddedBlock) + 1, block);
lastAddedBlock = block;
}
}
else
{
foreach (var block in _pastedItemFilterBlocks)
{
_itemFilterScript.ItemFilterBlocks.Add(block);
}
}
}
public void Undo()
{
foreach (var block in _pastedItemFilterBlocks)
{
_itemFilterScript.ItemFilterBlocks.Remove(block);
}
}
public void Redo() => Execute();
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
namespace Filtration.ObjectModel.Commands.ItemFilterScript
{
public class RemoveSectionCommand : IUndoableCommand
{
private readonly IItemFilterScript _itemFilterScript;
private List<IItemFilterBlockBase> _removedItemFilterBlocks;
private int _sectionStart;
private int _sectionSize;
public RemoveSectionCommand(IItemFilterScript itemFilterScript, int sectionStart, int sectionSize)
{
_itemFilterScript = itemFilterScript;
_sectionStart = sectionStart;
_sectionSize = sectionSize;
_removedItemFilterBlocks = new List<IItemFilterBlockBase>();
for(var i = 0; i < _sectionSize; i++)
{
_removedItemFilterBlocks.Add(_itemFilterScript.ItemFilterBlocks[_sectionStart + i]);
}
}
public void Execute()
{
for (var i = 0; i < _sectionSize; i++)
{
_itemFilterScript.ItemFilterBlocks.RemoveAt(_sectionStart);
}
}
public void Undo()
{
for (var i = 0; i < _sectionSize; i++)
{
_itemFilterScript.ItemFilterBlocks.Insert(_sectionStart + i, _removedItemFilterBlocks[i]);
}
}
public void Redo() => Execute();
}
}

View File

@ -86,12 +86,15 @@
<Compile Include="BlockItemTypes\WidthBlockItem.cs" /> <Compile Include="BlockItemTypes\WidthBlockItem.cs" />
<Compile Include="Commands\CommandManager.cs" /> <Compile Include="Commands\CommandManager.cs" />
<Compile Include="Commands\ICommand.cs" /> <Compile Include="Commands\ICommand.cs" />
<Compile Include="Commands\ItemFilterScript\MoveSectionToIndexCommand.cs" />
<Compile Include="Commands\ItemFilterScript\PasteBlockCommand.cs" /> <Compile Include="Commands\ItemFilterScript\PasteBlockCommand.cs" />
<Compile Include="Commands\ItemFilterScript\MoveBlockToBottomCommand.cs" /> <Compile Include="Commands\ItemFilterScript\MoveBlockToBottomCommand.cs" />
<Compile Include="Commands\ItemFilterScript\AddCommentBlockCommand.cs" /> <Compile Include="Commands\ItemFilterScript\AddCommentBlockCommand.cs" />
<Compile Include="Commands\ItemFilterScript\MoveBlockDownCommand.cs" /> <Compile Include="Commands\ItemFilterScript\MoveBlockDownCommand.cs" />
<Compile Include="Commands\ItemFilterScript\MoveBlockUpCommand.cs" /> <Compile Include="Commands\ItemFilterScript\MoveBlockUpCommand.cs" />
<Compile Include="Commands\ItemFilterScript\MoveBlockToTopCommand.cs" /> <Compile Include="Commands\ItemFilterScript\MoveBlockToTopCommand.cs" />
<Compile Include="Commands\ItemFilterScript\PasteSectionCommand.cs" />
<Compile Include="Commands\ItemFilterScript\RemoveSectionCommand.cs" />
<Compile Include="Commands\ItemFilterScript\SetScriptDescriptionCommand.cs" /> <Compile Include="Commands\ItemFilterScript\SetScriptDescriptionCommand.cs" />
<Compile Include="Commands\ItemFilterScript\RemoveBlockCommand.cs" /> <Compile Include="Commands\ItemFilterScript\RemoveBlockCommand.cs" />
<Compile Include="Commands\ItemFilterScript\AddBlockCommand.cs" /> <Compile Include="Commands\ItemFilterScript\AddBlockCommand.cs" />

View File

@ -10,12 +10,14 @@ namespace Filtration.ViewModels
void Initialise(IItemFilterBlockBase itemfilterBlock, IItemFilterScriptViewModel itemFilterScriptViewModel); void Initialise(IItemFilterBlockBase itemfilterBlock, IItemFilterScriptViewModel itemFilterScriptViewModel);
IItemFilterBlockBase BaseBlock { get; } IItemFilterBlockBase BaseBlock { get; }
bool IsDirty { get; set; } bool IsDirty { get; set; }
bool IsVisible { get; set; }
event EventHandler BlockBecameDirty; event EventHandler BlockBecameDirty;
} }
internal abstract class ItemFilterBlockViewModelBase : ViewModelBase, IItemFilterBlockViewModelBase internal abstract class ItemFilterBlockViewModelBase : ViewModelBase, IItemFilterBlockViewModelBase
{ {
private bool _isDirty; private bool _isDirty;
private bool _isVisible;
public ItemFilterBlockViewModelBase() public ItemFilterBlockViewModelBase()
{ {
@ -28,6 +30,8 @@ namespace Filtration.ViewModels
MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand); MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand);
MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand); MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand);
MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand); MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand);
_isVisible = true;
} }
@ -66,6 +70,16 @@ namespace Filtration.ViewModels
} }
} }
public bool IsVisible
{
get => _isVisible;
set
{
_isVisible = value;
RaisePropertyChanged();
}
}
private void OnCopyBlockCommand() private void OnCopyBlockCommand()
{ {
_parentScriptViewModel.CopyBlock(this); _parentScriptViewModel.CopyBlock(this);

View File

@ -1,4 +1,5 @@
using Filtration.ObjectModel; using Filtration.ObjectModel;
using GalaSoft.MvvmLight.CommandWpf;
namespace Filtration.ViewModels namespace Filtration.ViewModels
{ {
@ -6,10 +7,20 @@ namespace Filtration.ViewModels
{ {
IItemFilterCommentBlock ItemFilterCommentBlock { get; } IItemFilterCommentBlock ItemFilterCommentBlock { get; }
string Comment { get; } string Comment { get; }
bool IsExpanded { get; set; }
} }
internal class ItemFilterCommentBlockViewModel : ItemFilterBlockViewModelBase, IItemFilterCommentBlockViewModel internal class ItemFilterCommentBlockViewModel : ItemFilterBlockViewModelBase, IItemFilterCommentBlockViewModel
{ {
private bool _isExpanded;
public ItemFilterCommentBlockViewModel()
{
_isExpanded = true;
ToggleSectionCommand = new RelayCommand(OnToggleSectionCommand);
}
public override void Initialise(IItemFilterBlockBase itemfilterBlock, IItemFilterScriptViewModel itemFilterScriptViewModel) public override void Initialise(IItemFilterBlockBase itemfilterBlock, IItemFilterScriptViewModel itemFilterScriptViewModel)
{ {
_parentScriptViewModel = itemFilterScriptViewModel; _parentScriptViewModel = itemFilterScriptViewModel;
@ -19,6 +30,8 @@ namespace Filtration.ViewModels
base.Initialise(itemfilterBlock, itemFilterScriptViewModel); base.Initialise(itemfilterBlock, itemFilterScriptViewModel);
} }
public RelayCommand ToggleSectionCommand { get; }
public IItemFilterCommentBlock ItemFilterCommentBlock { get; private set; } public IItemFilterCommentBlock ItemFilterCommentBlock { get; private set; }
public string Comment public string Comment
@ -37,5 +50,21 @@ namespace Filtration.ViewModels
} }
} }
} }
public bool IsExpanded
{
get => _isExpanded;
set
{
_isExpanded = value;
RaisePropertyChanged();
}
}
private void OnToggleSectionCommand()
{
_parentScriptViewModel.ToggleSection(this);
}
} }
} }

View File

@ -44,11 +44,16 @@ namespace Filtration.ViewModels
void SetDirtyFlag(); void SetDirtyFlag();
bool HasSelectedEnabledBlock(); bool HasSelectedEnabledBlock();
bool HasSelectedDisabledBlock(); bool HasSelectedDisabledBlock();
bool HasSelectedCommentBlock();
RelayCommand AddBlockCommand { get; } RelayCommand AddBlockCommand { get; }
RelayCommand AddSectionCommand { get; } RelayCommand AddSectionCommand { get; }
RelayCommand DisableBlockCommand { get; } RelayCommand DisableBlockCommand { get; }
RelayCommand EnableBlockCommand { get; } RelayCommand EnableBlockCommand { get; }
RelayCommand DisableSectionCommand { get; }
RelayCommand EnableSectionCommand { get; }
RelayCommand ExpandSectionCommand { get; }
RelayCommand CollapseSectionCommand { get; }
RelayCommand DeleteBlockCommand { get; } RelayCommand DeleteBlockCommand { get; }
RelayCommand MoveBlockUpCommand { get; } RelayCommand MoveBlockUpCommand { get; }
RelayCommand MoveBlockDownCommand { get; } RelayCommand MoveBlockDownCommand { get; }
@ -74,6 +79,7 @@ namespace Filtration.ViewModels
void MoveBlockUp(IItemFilterBlockViewModelBase targetBlockViewModelBase); void MoveBlockUp(IItemFilterBlockViewModelBase targetBlockViewModelBase);
void MoveBlockDown(IItemFilterBlockViewModelBase targetBlockViewModelBase); void MoveBlockDown(IItemFilterBlockViewModelBase targetBlockViewModelBase);
void MoveBlockToBottom(IItemFilterBlockViewModelBase targetBlockViewModelBase); void MoveBlockToBottom(IItemFilterBlockViewModelBase targetBlockViewModelBase);
void ToggleSection(IItemFilterCommentBlockViewModel targetCommentBlockViewModelBase);
} }
internal class ItemFilterScriptViewModel : PaneViewModel, IItemFilterScriptViewModel internal class ItemFilterScriptViewModel : PaneViewModel, IItemFilterScriptViewModel
@ -131,6 +137,10 @@ namespace Filtration.ViewModels
AddSectionCommand = new RelayCommand(OnAddCommentBlockCommand, () => SelectedBlockViewModel != null); AddSectionCommand = new RelayCommand(OnAddCommentBlockCommand, () => SelectedBlockViewModel != null);
DisableBlockCommand = new RelayCommand(OnDisableBlockCommand, HasSelectedEnabledBlock); DisableBlockCommand = new RelayCommand(OnDisableBlockCommand, HasSelectedEnabledBlock);
EnableBlockCommand = new RelayCommand(OnEnableBlockCommand, HasSelectedDisabledBlock); EnableBlockCommand = new RelayCommand(OnEnableBlockCommand, HasSelectedDisabledBlock);
DisableSectionCommand = new RelayCommand(OnDisableSectionCommand, HasSelectedCommentBlock);
EnableSectionCommand = new RelayCommand(OnEnableSectionCommand, HasSelectedCommentBlock);
ExpandSectionCommand = new RelayCommand(OnExpandSectionCommand, HasSelectedCommentBlock);
CollapseSectionCommand = new RelayCommand(OnCollapseSectionCommand, HasSelectedCommentBlock);
CopyBlockCommand = new RelayCommand(OnCopyBlockCommand, () => SelectedBlockViewModel != null); CopyBlockCommand = new RelayCommand(OnCopyBlockCommand, () => SelectedBlockViewModel != null);
CopyBlockStyleCommand = new RelayCommand(OnCopyBlockStyleCommand, () => SelectedBlockViewModel != null); CopyBlockStyleCommand = new RelayCommand(OnCopyBlockStyleCommand, () => SelectedBlockViewModel != null);
PasteBlockCommand = new RelayCommand(OnPasteBlockCommand, () => SelectedBlockViewModel != null); PasteBlockCommand = new RelayCommand(OnPasteBlockCommand, () => SelectedBlockViewModel != null);
@ -245,6 +255,10 @@ namespace Filtration.ViewModels
public RelayCommand AddSectionCommand { get; } public RelayCommand AddSectionCommand { get; }
public RelayCommand EnableBlockCommand { get; } public RelayCommand EnableBlockCommand { get; }
public RelayCommand DisableBlockCommand { get; } public RelayCommand DisableBlockCommand { get; }
public RelayCommand DisableSectionCommand { get; }
public RelayCommand EnableSectionCommand { get; }
public RelayCommand ExpandSectionCommand { get; }
public RelayCommand CollapseSectionCommand { get; }
public RelayCommand CopyBlockCommand { get; } public RelayCommand CopyBlockCommand { get; }
public RelayCommand CopyBlockStyleCommand { get; } public RelayCommand CopyBlockStyleCommand { get; }
public RelayCommand PasteBlockCommand { get; } public RelayCommand PasteBlockCommand { get; }
@ -359,6 +373,13 @@ namespace Filtration.ViewModels
return SelectedBlockViewModel != null; return SelectedBlockViewModel != null;
} }
public bool HasSelectedCommentBlock()
{
var selectedBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
return selectedBlockViewModel != null;
}
public IItemFilterBlockViewModelBase SelectedBlockViewModel public IItemFilterBlockViewModelBase SelectedBlockViewModel
{ {
get => _selectedBlockViewModel; get => _selectedBlockViewModel;
@ -633,9 +654,17 @@ namespace Filtration.ViewModels
} }
private void OnCopyBlockCommand() private void OnCopyBlockCommand()
{
var commentBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if (commentBlockViewModel == null || commentBlockViewModel.IsExpanded)
{ {
CopyBlock(SelectedBlockViewModel); CopyBlock(SelectedBlockViewModel);
} }
else
{
CopySection(commentBlockViewModel);
}
}
public void CopyBlock(IItemFilterBlockViewModelBase targetBlockViewModel) public void CopyBlock(IItemFilterBlockViewModelBase targetBlockViewModel)
{ {
@ -649,6 +678,26 @@ namespace Filtration.ViewModels
} }
} }
public void CopySection(IItemFilterCommentBlockViewModel targetCommentBlockViewModel)
{
var sectionStart = ItemFilterBlockViewModels.IndexOf(targetCommentBlockViewModel) + 1;
var copyText = _blockTranslator.TranslateItemFilterBlockBaseToString(targetCommentBlockViewModel.BaseBlock);
while (sectionStart < ItemFilterBlockViewModels.Count && ItemFilterBlockViewModels[sectionStart] as IItemFilterCommentBlockViewModel == null)
{
copyText += Environment.NewLine + "##CopySection##" + Environment.NewLine + _blockTranslator.TranslateItemFilterBlockBaseToString(ItemFilterBlockViewModels[sectionStart].BaseBlock);
sectionStart++;
}
try
{
_clipboardService.SetClipboardText(copyText);
}
catch
{
_messageBoxService.Show("Clipboard Error", "Failed to access the clipboard, copy command not completed.", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void OnCopyBlockStyleCommand() private void OnCopyBlockStyleCommand()
{ {
var selectedBlockViewModel = SelectedBlockViewModel as IItemFilterBlockViewModel; var selectedBlockViewModel = SelectedBlockViewModel as IItemFilterBlockViewModel;
@ -714,10 +763,77 @@ namespace Filtration.ViewModels
var clipboardText = _clipboardService.GetClipboardText(); var clipboardText = _clipboardService.GetClipboardText();
if (string.IsNullOrEmpty(clipboardText)) return; if (string.IsNullOrEmpty(clipboardText)) return;
var translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(clipboardText, Script, true); // TODO: Doesn't handle pasting comment blocks? string[] blockTexts = clipboardText.Split(new string[] { Environment.NewLine + "##CopySection##" + Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
if (translatedBlock == null) return;
_scriptCommandManager.ExecuteCommand(new PasteBlockCommand(Script, translatedBlock, targetBlockViewModelBase.BaseBlock)); var previousBlock = targetBlockViewModelBase.BaseBlock;
var pastedSection = false;
List<IItemFilterBlockBase> blocksToPaste = new List<IItemFilterBlockBase>();
List<bool> isBlockDisabled = new List<bool>();
foreach (var curBlock in blockTexts)
{
IItemFilterBlockBase translatedBlock;
var pastedDisabledBlock = false;
if (!curBlock.StartsWith(@"#Disabled Block Start") && curBlock.StartsWith(@"#"))
{
translatedBlock = _blockTranslator.TranslateStringToItemFilterCommentBlock(curBlock, Script);
pastedSection = true;
}
else if (curBlock.StartsWith(@"#Disabled Block Start"))
{
pastedDisabledBlock = true;
string[] textLines = curBlock.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
if (textLines.Length < 3)
continue;
string cleanBlock = textLines[1].Substring(1);
for(int i = 2; i < (textLines.Length - 1); i++)
{
cleanBlock += Environment.NewLine + textLines[i].Substring(1);
}
translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(cleanBlock, Script, true);
}
else
{
translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(curBlock, Script, true);
}
if (translatedBlock == null) continue;
blocksToPaste.Add(translatedBlock);
isBlockDisabled.Add(pastedDisabledBlock);
}
if(pastedSection)
{
var blockIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase) + 1;
_scriptCommandManager.ExecuteCommand(new PasteSectionCommand(Script, blocksToPaste, targetBlockViewModelBase.BaseBlock));
SelectedBlockViewModel = ItemFilterBlockViewModels[blockIndex];
foreach (var isDisabled in isBlockDisabled)
{
var block = ItemFilterBlockViewModels[blockIndex++] as IItemFilterBlockViewModel;
if(block != null)
{
block.BlockEnabled = !isDisabled;
}
}
OnCollapseSectionCommand();
}
else
{
var blockIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase) + 1;
for (var i = 0; i < blocksToPaste.Count; i++)
{
_scriptCommandManager.ExecuteCommand(new PasteBlockCommand(Script, blocksToPaste[i], previousBlock));
previousBlock = blocksToPaste[i];
var block = ItemFilterBlockViewModels[blockIndex + i] as IItemFilterBlockViewModel;
if (block != null)
{
block.BlockEnabled = !isBlockDisabled[i];
}
}
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -729,34 +845,153 @@ namespace Filtration.ViewModels
} }
private void OnMoveBlockToTopCommand() private void OnMoveBlockToTopCommand()
{
var commentBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if (commentBlockViewModel == null || commentBlockViewModel.IsExpanded)
{ {
MoveBlockToTop(SelectedBlockViewModel); MoveBlockToTop(SelectedBlockViewModel);
} }
else
{
MoveSectionToTop(commentBlockViewModel);
}
}
private void OnMoveBlockUpCommand() private void OnMoveBlockUpCommand()
{
var commentBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if(commentBlockViewModel == null || commentBlockViewModel.IsExpanded)
{ {
MoveBlockUp(SelectedBlockViewModel); MoveBlockUp(SelectedBlockViewModel);
} }
else
{
MoveSectionUp(commentBlockViewModel);
}
}
public void MoveBlockUp(IItemFilterBlockViewModelBase targetBlockViewModelBase) public void MoveBlockUp(IItemFilterBlockViewModelBase targetBlockViewModelBase)
{
var blockIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase);
if (ItemFilterBlockViewModels[blockIndex - 1].IsVisible)
{ {
_scriptCommandManager.ExecuteCommand(new MoveBlockUpCommand(Script, targetBlockViewModelBase?.BaseBlock)); _scriptCommandManager.ExecuteCommand(new MoveBlockUpCommand(Script, targetBlockViewModelBase?.BaseBlock));
} }
else
{
var aboveSectionStart = blockIndex - 1;
while(ItemFilterBlockViewModels[aboveSectionStart] as IItemFilterCommentBlockViewModel == null)
{
aboveSectionStart--;
}
_scriptCommandManager.ExecuteCommand(new MoveSectionToIndexCommand(Script, blockIndex, 1, aboveSectionStart));
}
}
public void MoveSectionUp(IItemFilterCommentBlockViewModel targetCommentBlockViewModel)
{
var sectionStart = ItemFilterBlockViewModels.IndexOf(targetCommentBlockViewModel);
var sectionEnd = sectionStart + 1;
while(sectionEnd < ItemFilterBlockViewModels.Count && ItemFilterBlockViewModels[sectionEnd] as IItemFilterCommentBlockViewModel == null)
{
sectionEnd++;
}
var newLocation = sectionStart - 1;
if (ItemFilterBlockViewModels[newLocation].IsVisible)
{
_scriptCommandManager.ExecuteCommand(new MoveSectionToIndexCommand(Script, sectionStart, sectionEnd - sectionStart, newLocation));
}
else
{
while (ItemFilterBlockViewModels[newLocation] as IItemFilterCommentBlockViewModel == null)
{
newLocation--;
}
_scriptCommandManager.ExecuteCommand(new MoveSectionToIndexCommand(Script, sectionStart, sectionEnd - sectionStart, newLocation));
}
ToggleSection(ItemFilterBlockViewModels[newLocation] as IItemFilterCommentBlockViewModel);
SelectedBlockViewModel = ItemFilterBlockViewModels[newLocation];
}
private void OnMoveBlockDownCommand() private void OnMoveBlockDownCommand()
{
var commentBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if (commentBlockViewModel == null || commentBlockViewModel.IsExpanded)
{ {
MoveBlockDown(SelectedBlockViewModel); MoveBlockDown(SelectedBlockViewModel);
} }
else
{
MoveSectionDown(commentBlockViewModel);
}
}
public void MoveBlockDown(IItemFilterBlockViewModelBase targetBlockViewModelBase) public void MoveBlockDown(IItemFilterBlockViewModelBase targetBlockViewModelBase)
{
var blockIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase);
var beloveBlockAsComment = ItemFilterBlockViewModels[blockIndex + 1] as IItemFilterCommentBlockViewModel;
if (beloveBlockAsComment == null || beloveBlockAsComment.IsExpanded)
{ {
_scriptCommandManager.ExecuteCommand(new MoveBlockDownCommand(Script, targetBlockViewModelBase?.BaseBlock)); _scriptCommandManager.ExecuteCommand(new MoveBlockDownCommand(Script, targetBlockViewModelBase?.BaseBlock));
} }
else
{
var beloveSectionEnd = blockIndex + 2;
while (beloveSectionEnd < ItemFilterBlockViewModels.Count && ItemFilterBlockViewModels[beloveSectionEnd] as IItemFilterCommentBlockViewModel == null)
{
beloveSectionEnd++;
}
_scriptCommandManager.ExecuteCommand(new MoveSectionToIndexCommand(Script, blockIndex, 1, beloveSectionEnd - 1));
}
}
public void MoveSectionDown(IItemFilterCommentBlockViewModel targetCommentBlockViewModel)
{
var sectionStart = ItemFilterBlockViewModels.IndexOf(targetCommentBlockViewModel);
var sectionEnd = sectionStart + 1;
while (sectionEnd < ItemFilterBlockViewModels.Count && ItemFilterBlockViewModels[sectionEnd] as IItemFilterCommentBlockViewModel == null)
{
sectionEnd++;
}
if (sectionEnd >= ItemFilterBlockViewModels.Count)
return;
var sectionSize = sectionEnd - sectionStart;
var newLocation = sectionStart + 1;
var beloveBlockAsComment = ItemFilterBlockViewModels[sectionEnd] as IItemFilterCommentBlockViewModel;
if (beloveBlockAsComment == null || beloveBlockAsComment.IsExpanded)
{
_scriptCommandManager.ExecuteCommand(new MoveSectionToIndexCommand(Script, sectionStart, sectionSize, newLocation));
}
else
{
while ((newLocation + sectionSize) < ItemFilterBlockViewModels.Count && ItemFilterBlockViewModels[newLocation + sectionSize] as IItemFilterCommentBlockViewModel == null)
{
newLocation++;
}
_scriptCommandManager.ExecuteCommand(new MoveSectionToIndexCommand(Script, sectionStart, sectionEnd - sectionStart, newLocation));
}
ToggleSection(ItemFilterBlockViewModels[newLocation] as IItemFilterCommentBlockViewModel);
SelectedBlockViewModel = ItemFilterBlockViewModels[newLocation];
}
private void OnMoveBlockToBottomCommand() private void OnMoveBlockToBottomCommand()
{
var commentBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if (commentBlockViewModel == null || commentBlockViewModel.IsExpanded)
{ {
MoveBlockToBottom(SelectedBlockViewModel); MoveBlockToBottom(SelectedBlockViewModel);
} }
else
{
MoveSectionToBottom(commentBlockViewModel);
}
}
private void OnAddBlockCommand() private void OnAddBlockCommand()
{ {
@ -775,20 +1010,67 @@ namespace Filtration.ViewModels
} }
public void DeleteBlock(IItemFilterBlockViewModelBase targetBlockViewModelBase) public void DeleteBlock(IItemFilterBlockViewModelBase targetBlockViewModelBase)
{
var commentBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if (commentBlockViewModel == null || commentBlockViewModel.IsExpanded)
{ {
_scriptCommandManager.ExecuteCommand(new RemoveBlockCommand(Script, targetBlockViewModelBase.BaseBlock)); _scriptCommandManager.ExecuteCommand(new RemoveBlockCommand(Script, targetBlockViewModelBase.BaseBlock));
} }
else
{
var sectionStart = ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase);
var sectionEnd = sectionStart + 1;
while (sectionEnd < ItemFilterBlockViewModels.Count && ItemFilterBlockViewModels[sectionEnd] as IItemFilterCommentBlockViewModel == null)
{
sectionEnd++;
}
_scriptCommandManager.ExecuteCommand(new RemoveSectionCommand(Script, sectionStart, sectionEnd - sectionStart));
}
}
public void MoveBlockToBottom(IItemFilterBlockViewModelBase targetBlockViewModelBase) public void MoveBlockToBottom(IItemFilterBlockViewModelBase targetBlockViewModelBase)
{ {
_scriptCommandManager.ExecuteCommand(new MoveBlockToBottomCommand(Script, targetBlockViewModelBase.BaseBlock)); _scriptCommandManager.ExecuteCommand(new MoveBlockToBottomCommand(Script, targetBlockViewModelBase.BaseBlock));
} }
public void MoveSectionToBottom(IItemFilterCommentBlockViewModel targetCommentBlockViewModel)
{
var sectionStart = ItemFilterBlockViewModels.IndexOf(targetCommentBlockViewModel);
var sectionEnd = sectionStart + 1;
while (sectionEnd < ItemFilterBlockViewModels.Count && ItemFilterBlockViewModels[sectionEnd] as IItemFilterCommentBlockViewModel == null)
{
sectionEnd++;
}
var newLocation = ItemFilterBlockViewModels.Count - (sectionEnd - sectionStart);
_scriptCommandManager.ExecuteCommand(new MoveSectionToIndexCommand(Script, sectionStart, sectionEnd - sectionStart, newLocation));
ToggleSection(ItemFilterBlockViewModels[newLocation] as IItemFilterCommentBlockViewModel);
SelectedBlockViewModel = ItemFilterBlockViewModels[newLocation];
}
public void MoveBlockToTop(IItemFilterBlockViewModelBase targetBlockViewModelBase) public void MoveBlockToTop(IItemFilterBlockViewModelBase targetBlockViewModelBase)
{ {
_scriptCommandManager.ExecuteCommand(new MoveBlockToTopCommand(Script, targetBlockViewModelBase.BaseBlock)); _scriptCommandManager.ExecuteCommand(new MoveBlockToTopCommand(Script, targetBlockViewModelBase.BaseBlock));
} }
public void MoveSectionToTop(IItemFilterCommentBlockViewModel targetCommentBlockViewModel)
{
var sectionStart = ItemFilterBlockViewModels.IndexOf(targetCommentBlockViewModel);
var sectionEnd = sectionStart + 1;
while (sectionEnd < ItemFilterBlockViewModels.Count && ItemFilterBlockViewModels[sectionEnd] as IItemFilterCommentBlockViewModel == null)
{
sectionEnd++;
}
var newLocation = 0;
_scriptCommandManager.ExecuteCommand(new MoveSectionToIndexCommand(Script, sectionStart, sectionEnd - sectionStart, newLocation));
ToggleSection(ItemFilterBlockViewModels[newLocation] as IItemFilterCommentBlockViewModel);
SelectedBlockViewModel = ItemFilterBlockViewModels[newLocation];
}
private void OnBlockBecameDirty(object sender, EventArgs e) private void OnBlockBecameDirty(object sender, EventArgs e)
{ {
SetDirtyFlag(); SetDirtyFlag();
@ -837,5 +1119,78 @@ namespace Filtration.ViewModels
selectedBlockViewModel.BlockEnabled = true; selectedBlockViewModel.BlockEnabled = true;
} }
} }
private void OnDisableSectionCommand()
{
var selectedBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if (selectedBlockViewModel != null)
{
var sectionIndex = ItemFilterBlockViewModels.IndexOf(selectedBlockViewModel);
for (int i = sectionIndex + 1; i < ItemFilterBlockViewModels.Count; i++)
{
var block = ItemFilterBlockViewModels[i] as IItemFilterBlockViewModel;
if (block != null)
{
block.BlockEnabled = false;
}
else
break;
}
}
}
private void OnEnableSectionCommand()
{
var selectedBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if (selectedBlockViewModel != null)
{
var sectionIndex = ItemFilterBlockViewModels.IndexOf(selectedBlockViewModel);
for (int i = sectionIndex + 1; i < ItemFilterBlockViewModels.Count; i++)
{
var block = ItemFilterBlockViewModels[i] as IItemFilterBlockViewModel;
if (block != null)
{
block.BlockEnabled = true;
}
else
break;
}
}
}
private void OnExpandSectionCommand()
{
var selectedBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if (selectedBlockViewModel != null && !selectedBlockViewModel.IsExpanded)
{
ToggleSection(selectedBlockViewModel);
}
}
private void OnCollapseSectionCommand()
{
var selectedBlockViewModel = SelectedBlockViewModel as IItemFilterCommentBlockViewModel;
if (selectedBlockViewModel != null && selectedBlockViewModel.IsExpanded)
{
ToggleSection(selectedBlockViewModel);
}
}
public void ToggleSection(IItemFilterCommentBlockViewModel targetCommentBlockViewModelBase)
{
var newState = !targetCommentBlockViewModelBase.IsExpanded;
targetCommentBlockViewModelBase.IsExpanded = newState;
var sectionIndex = ItemFilterBlockViewModels.IndexOf(targetCommentBlockViewModelBase);
for (int i = sectionIndex + 1; i < ItemFilterBlockViewModels.Count; i++)
{
var block = ItemFilterBlockViewModels[i] as IItemFilterBlockViewModel;
if (block != null)
{
block.IsVisible = newState;
}
else
break;
}
}
} }
} }

View File

@ -100,6 +100,10 @@ namespace Filtration.ViewModels
DeleteBlockCommand = new RelayCommand(OnDeleteBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock); DeleteBlockCommand = new RelayCommand(OnDeleteBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
DisableBlockCommand = new RelayCommand(OnDisableBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedEnabledBlock); DisableBlockCommand = new RelayCommand(OnDisableBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedEnabledBlock);
EnableBlockCommand = new RelayCommand(OnEnableBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedDisabledBlock); EnableBlockCommand = new RelayCommand(OnEnableBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedDisabledBlock);
DisableSectionCommand = new RelayCommand(OnDisableSectionCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedCommentBlock);
EnableSectionCommand = new RelayCommand(OnEnableSectionCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedCommentBlock);
ExpandSectionCommand = new RelayCommand(OnExpandSectionCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedCommentBlock);
CollapseSectionCommand = new RelayCommand(OnCollapseSectionCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedCommentBlock);
OpenAboutWindowCommand = new RelayCommand(OnOpenAboutWindowCommand); OpenAboutWindowCommand = new RelayCommand(OnOpenAboutWindowCommand);
ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand, () => ActiveDocumentIsScript); ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand, () => ActiveDocumentIsScript);
@ -213,6 +217,10 @@ namespace Filtration.ViewModels
public RelayCommand DeleteBlockCommand { get; } public RelayCommand DeleteBlockCommand { get; }
public RelayCommand DisableBlockCommand { get; } public RelayCommand DisableBlockCommand { get; }
public RelayCommand EnableBlockCommand { get; } public RelayCommand EnableBlockCommand { get; }
public RelayCommand DisableSectionCommand { get; }
public RelayCommand EnableSectionCommand { get; }
public RelayCommand ExpandSectionCommand { get; }
public RelayCommand CollapseSectionCommand { get; }
public RelayCommand MoveBlockUpCommand { get; } public RelayCommand MoveBlockUpCommand { get; }
public RelayCommand MoveBlockDownCommand { get; } public RelayCommand MoveBlockDownCommand { get; }
@ -260,6 +268,9 @@ namespace Filtration.ViewModels
public bool ActiveScriptHasSelectedDisabledBlock => AvalonDockWorkspaceViewModel.ActiveScriptViewModel.HasSelectedDisabledBlock(); public bool ActiveScriptHasSelectedDisabledBlock => AvalonDockWorkspaceViewModel.ActiveScriptViewModel.HasSelectedDisabledBlock();
public bool ActiveScriptHasSelectedCommentBlock => AvalonDockWorkspaceViewModel.ActiveScriptViewModel.HasSelectedCommentBlock();
public bool ActiveThemeIsEditable => AvalonDockWorkspaceViewModel.ActiveThemeViewModel.IsMasterTheme; public bool ActiveThemeIsEditable => AvalonDockWorkspaceViewModel.ActiveThemeViewModel.IsMasterTheme;
private bool ActiveDocumentIsEditable() private bool ActiveDocumentIsEditable()
@ -595,6 +606,26 @@ namespace Filtration.ViewModels
_avalonDockWorkspaceViewModel.ActiveScriptViewModel.EnableBlockCommand.Execute(null); _avalonDockWorkspaceViewModel.ActiveScriptViewModel.EnableBlockCommand.Execute(null);
} }
private void OnDisableSectionCommand()
{
_avalonDockWorkspaceViewModel.ActiveScriptViewModel.DisableSectionCommand.Execute(null);
}
private void OnEnableSectionCommand()
{
_avalonDockWorkspaceViewModel.ActiveScriptViewModel.EnableSectionCommand.Execute(null);
}
private void OnExpandSectionCommand()
{
_avalonDockWorkspaceViewModel.ActiveScriptViewModel.ExpandSectionCommand.Execute(null);
}
private void OnCollapseSectionCommand()
{
_avalonDockWorkspaceViewModel.ActiveScriptViewModel.CollapseSectionCommand.Execute(null);
}
private void OnExpandAllBlocksCommand() private void OnExpandAllBlocksCommand()
{ {
_avalonDockWorkspaceViewModel.ActiveScriptViewModel.ExpandAllBlocksCommand.Execute(null); _avalonDockWorkspaceViewModel.ActiveScriptViewModel.ExpandAllBlocksCommand.Execute(null);

View File

@ -11,7 +11,7 @@
xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
mc:Ignorable="d" mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=viewModels:ItemFilterBlockViewModel}" d:DataContext="{d:DesignInstance Type=viewModels:ItemFilterBlockViewModel}"
d:DesignHeight="200" d:DesignWidth="800"> d:DesignHeight="200" d:DesignWidth="800" Visibility="{Binding IsVisible, Converter={StaticResource BooleanVisibilityConverter}}">
<UserControl.Resources> <UserControl.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>

View File

@ -77,6 +77,28 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBox Grid.Column ="0" Text="{Binding Comment, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" VerticalAlignment="Center" TextWrapping="Wrap" MinWidth="150"/> <TextBox Grid.Column ="0" Text="{Binding Comment, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" VerticalAlignment="Center" TextWrapping="Wrap" MinWidth="150"/>
<Button Grid.Column="1" Command="{Binding ToggleSectionCommand}"
Width="25"
Height="25"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="0,0,3,0"
Background="Transparent"
BorderBrush="Transparent"
ToolTip="Expand Section" Visibility="{Binding IsExpanded, Converter={StaticResource InverseBooleanVisibilityConverter}}">
<Image Source="/Filtration;component/Resources/Icons/expand_icon.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Button>
<Button Grid.Column="1" Command="{Binding ToggleSectionCommand}"
Width="25"
Height="25"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="0,0,3,0"
Background="Transparent"
BorderBrush="Transparent"
ToolTip="Collapse Section" Visibility="{Binding IsExpanded, Converter={StaticResource BooleanVisibilityConverter}}">
<Image Source="/Filtration;component/Resources/Icons/collapse_icon.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Button>
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>

View File

@ -101,6 +101,10 @@
<fluent:Button Header="Move To Bottom" Command="{Binding MoveBlockToBottomCommand}" SizeDefinition="Middle" Icon="{StaticResource MoveToBottomIcon}" /> <fluent:Button Header="Move To Bottom" Command="{Binding MoveBlockToBottomCommand}" SizeDefinition="Middle" Icon="{StaticResource MoveToBottomIcon}" />
<fluent:Button Header="Enable Block" Command="{Binding EnableBlockCommand}" SizeDefinition="Middle" Icon="{StaticResource StandbyEnabledIcon}" /> <fluent:Button Header="Enable Block" Command="{Binding EnableBlockCommand}" SizeDefinition="Middle" Icon="{StaticResource StandbyEnabledIcon}" />
<fluent:Button Header="Disable Block" Command="{Binding DisableBlockCommand}" SizeDefinition="Middle" Icon="{StaticResource StandbyDisabledIcon}" /> <fluent:Button Header="Disable Block" Command="{Binding DisableBlockCommand}" SizeDefinition="Middle" Icon="{StaticResource StandbyDisabledIcon}" />
<fluent:Button Header="Enable Section" Command="{Binding EnableSectionCommand}" SizeDefinition="Middle" Icon="{StaticResource StandbyEnabledIcon}" />
<fluent:Button Header="Disable Section" Command="{Binding DisableSectionCommand}" SizeDefinition="Middle" Icon="{StaticResource StandbyDisabledIcon}" />
<fluent:Button Header="Expand Section" Command="{Binding ExpandSectionCommand}" SizeDefinition="Middle" Icon="{StaticResource StandbyEnabledIcon}" />
<fluent:Button Header="Collapse Section" Command="{Binding CollapseSectionCommand}" SizeDefinition="Middle" Icon="{StaticResource StandbyDisabledIcon}" />
</fluent:RibbonGroupBox> </fluent:RibbonGroupBox>
<fluent:RibbonGroupBox Header="Expand / Collapse"> <fluent:RibbonGroupBox Header="Expand / Collapse">
<fluent:Button Header="Expand All" Command="{Binding ExpandAllBlocksCommand}" SizeDefinition="Middle" Icon="{StaticResource ExpandIcon}" /> <fluent:Button Header="Expand All" Command="{Binding ExpandAllBlocksCommand}" SizeDefinition="Middle" Icon="{StaticResource ExpandIcon}" />