Keyframes - Copy/paste WIP

Timeline - Improved sizing, avoid unnecessary scrolling
Timeline - Fix selection rectangle appearing on mousedown
This commit is contained in:
Robert committed 2020-12-02 19:11:39 +01:00
1 parent 7c955d1134
commit f110383ed4
18 files changed
+381 -122

No files matched your search

@@ -32,7 +32,8 @@
HorizontalContentAlignment="Stretch"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropHandler="{Binding}">
dd:DragDrop.DropHandler="{Binding}"
ContextMenuOpening="{s:Action ContextMenuOpening}">
<TreeView.InputBindings>
<KeyBinding Key="F2" Command="{s:Action RenameElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
<KeyBinding Key="Delete" Command="{s:Action DeleteElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
@@ -40,6 +41,47 @@
<KeyBinding Key="C" Modifiers="Control" Command="{s:Action CopyElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
<KeyBinding Key="V" Modifiers="Control" Command="{s:Action PasteElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
</TreeView.InputBindings>
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Header="Add new folder" Command="{s:Action AddFolder}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="CreateNewFolder" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Add new layer" Command="{s:Action AddLayer}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="LayersPlus" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Duplicate" Command="{s:Action DuplicateElement}" InputGestureText="Ctrl+D" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentDuplicate" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Copy" Command="{s:Action CopyElement}" InputGestureText="Ctrl+C" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentCopy" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Paste" Command="{s:Action PasteElement}" InputGestureText="Ctrl+V">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentPaste" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Rename" Command="{s:Action RenameElement}" InputGestureText="F2" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="RenameBox" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Delete" Command="{s:Action DeleteElement}" InputGestureText="Del" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="TrashCan" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</TreeView.ContextMenu>
<b:Interaction.Behaviors>
<behaviors:TreeViewSelectionBehavior ExpandSelected="True" SelectedItem="{Binding SelectedTreeItem}" />
</b:Interaction.Behaviors>
@@ -2,6 +2,7 @@
using System.Linq;
using System.Windows;
using Artemis.Core;
using Artemis.Storage.Entities.Profile;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem;
using Artemis.UI.Shared;
@@ -41,17 +42,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
}
}
// ReSharper disable once UnusedMember.Global - Called from view
public void AddFolder()
{
ActiveItem?.AddFolder();
}
// ReSharper disable once UnusedMember.Global - Called from view
public void AddLayer()
{
ActiveItem?.AddLayer();
}
public bool CanPasteElement => _profileEditorService.GetCanPaste();
protected override void OnInitialActivate()
{
@@ -79,10 +70,12 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
_updatingTree = false;
}
#region IDropTarget
private static DragDropType GetDragDropType(IDropInfo dropInfo)
{
TreeItemViewModel source = (TreeItemViewModel) dropInfo.Data;
TreeItemViewModel target = (TreeItemViewModel) dropInfo.TargetItem;
TreeItemViewModel source = (TreeItemViewModel)dropInfo.Data;
TreeItemViewModel target = (TreeItemViewModel)dropInfo.TargetItem;
if (source == target)
return DragDropType.None;
@@ -128,14 +121,14 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
public void Drop(IDropInfo dropInfo)
{
TreeItemViewModel source = (TreeItemViewModel) dropInfo.Data;
TreeItemViewModel target = (TreeItemViewModel) dropInfo.TargetItem;
TreeItemViewModel source = (TreeItemViewModel)dropInfo.Data;
TreeItemViewModel target = (TreeItemViewModel)dropInfo.TargetItem;
DragDropType dragDropType = GetDragDropType(dropInfo);
switch (dragDropType)
{
case DragDropType.Add:
((TreeItemViewModel) source.Parent).RemoveExistingElement(source);
((TreeItemViewModel)source.Parent).RemoveExistingElement(source);
target.AddExistingElement(source);
break;
case DragDropType.InsertBefore:
@@ -151,6 +144,34 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
Subscribe();
}
#endregion
#region Context menu
public void AddFolder()
{
ActiveItem?.AddFolder();
}
public void AddLayer()
{
ActiveItem?.AddLayer();
}
public void PasteElement()
{
Folder rootFolder = _profileEditorService.SelectedProfile?.GetRootFolder();
if (rootFolder != null)
_profileEditorService.PasteProfileElement(rootFolder, rootFolder.Children.Count);
}
public void ContextMenuOpening(object sender, EventArgs e)
{
NotifyOfPropertyChange(nameof(CanPasteElement));
}
#endregion
#region Event handlers
private void Subscribe()
@@ -10,7 +10,7 @@
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type treeItem1:FolderViewModel}}">
<!-- Capture clicks on full tree view item -->
<StackPanel Margin="-10" Background="Transparent">
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
<StackPanel.ContextMenu>
<ContextMenu>
<MenuItem Header="Add new folder" Command="{s:Action AddFolder}">
@@ -10,7 +10,7 @@
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type treeItem1:LayerViewModel}}">
<!-- Capture clicks on full tree view item -->
<StackPanel Margin="-10" Background="Transparent">
<StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
<StackPanel.ContextMenu>
<ContextMenu>
<MenuItem Header="Duplicate" Command="{s:Action DuplicateElement}" InputGestureText="Ctrl+D">
@@ -48,6 +48,8 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
set => SetAndNotify(ref _profileElement, value);
}
public bool CanPasteElement => _profileEditorService.GetCanPaste();
public abstract bool SupportsChildren { get; }
public List<TreeItemViewModel> GetAllChildren()
@@ -254,6 +256,11 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
_profileEditorService.UpdateSelectedProfile();
}
public void ContextMenuOpening(object sender, EventArgs e)
{
NotifyOfPropertyChange(nameof(CanPasteElement));
}
private void Subscribe()
{
ProfileElement.ChildAdded += ProfileElementOnChildAdded;