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

@@ -160,7 +160,9 @@
VerticalScrollBarVisibility="Hidden"
ScrollChanged="TimelineScrollChanged">
<Border BorderThickness="0,0,1,0" BorderBrush="{DynamicResource MaterialDesignDivider}">
<ContentControl s:View.Model="{Binding TreeViewModel}" />
<ContentControl s:View.Model="{Binding TreeViewModel}"
shared:SizeObserver.Observe="True"
shared:SizeObserver.ObservedHeight="{Binding TreeViewModelHeight, Mode=OneWayToSource}"/>
</Border>
</ScrollViewer>
<materialDesign:TransitionerSlide>
@@ -35,6 +35,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
private int _rightSideIndex;
private RenderProfileElement _selectedProfileElement;
private DateTime _lastEffectsViewModelToggle;
private double _treeViewModelHeight;
public LayerPropertiesViewModel(IProfileEditorService profileEditorService,
ICoreService coreService,
@@ -157,6 +158,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public Layer SelectedLayer => SelectedProfileElement as Layer;
public Folder SelectedFolder => SelectedProfileElement as Folder;
public double TreeViewModelHeight
{
get => _treeViewModelHeight;
set => SetAndNotify(ref _treeViewModelHeight, value);
}
#region Segments
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using Artemis.Core;
using Artemis.Storage.Entities.Profile;
using Artemis.UI.Exceptions;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Models
{
public class KeyframeClipboardModel
{
public Dictionary<string, KeyframeEntity> KeyframeEntities { get; set; }
public KeyframeClipboardModel(List<ILayerPropertyKeyframe> keyframes)
{
KeyframeEntities = new Dictionary<string, KeyframeEntity>();
foreach (ILayerPropertyKeyframe keyframe in keyframes)
{
KeyframeEntities.Add(keyframe.UntypedLayerProperty.Path, );
}
}
public void Paste(RenderProfileElement target, TimeSpan pastePosition)
{
if (target == null) throw new ArgumentNullException(nameof(target));
if (HasBeenPasted)
throw new ArtemisUIException("Clipboard model can only be pasted once");
HasBeenPasted = true;
}
public bool HasBeenPasted { get; set; }
}
}
@@ -48,6 +48,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
}
public TimeSpan Position => LayerPropertyKeyframe.Position;
public ILayerPropertyKeyframe Keyframe => LayerPropertyKeyframe;
public void Dispose()
{
@@ -158,35 +159,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
#endregion
#region Context menu actions
public void Copy()
{
LayerPropertyKeyframe<T> newKeyframe = new LayerPropertyKeyframe<T>(
LayerPropertyKeyframe.Value,
LayerPropertyKeyframe.Position,
LayerPropertyKeyframe.EasingFunction,
LayerPropertyKeyframe.LayerProperty
);
// If possible, shift the keyframe to the right by 11 pixels
TimeSpan desiredPosition = newKeyframe.Position + TimeSpan.FromMilliseconds(1000f / _profileEditorService.PixelsPerSecond * 11);
if (desiredPosition <= newKeyframe.LayerProperty.ProfileElement.Timeline.Length)
newKeyframe.Position = desiredPosition;
// Otherwise if possible shift it to the left by 11 pixels
else
{
desiredPosition = newKeyframe.Position - TimeSpan.FromMilliseconds(1000f / _profileEditorService.PixelsPerSecond * 11);
if (desiredPosition > TimeSpan.Zero)
newKeyframe.Position = desiredPosition;
}
LayerPropertyKeyframe.LayerProperty.AddKeyframe(newKeyframe);
_profileEditorService.UpdateSelectedProfileElement();
}
public void Delete()
public void Delete(bool save = true)
{
LayerPropertyKeyframe.LayerProperty.RemoveKeyframe(LayerPropertyKeyframe);
_profileEditorService.UpdateSelectedProfileElement();
if (save)
_profileEditorService.UpdateSelectedProfileElement();
}
#endregion
@@ -196,6 +174,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
{
bool IsSelected { get; set; }
TimeSpan Position { get; }
ILayerPropertyKeyframe Keyframe { get; }
#region Movement
@@ -210,8 +189,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
void PopulateEasingViewModels();
void ClearEasingViewModels();
void Copy();
void Delete();
void Delete(bool save = true);
#endregion
}
@@ -36,8 +36,8 @@
MouseDown="{s:Action KeyframeMouseDown}"
MouseUp="{s:Action KeyframeMouseUp}"
MouseMove="{s:Action KeyframeMouseMove}"
ContextMenuOpening="{s:Action ContextMenuOpening}"
ContextMenuClosing="{s:Action ContextMenuClosing}">
ContextMenuOpening="{s:Action KeyframeContextMenuOpening}"
ContextMenuClosing="{s:Action KeyframeContextMenuClosing}">
<Ellipse.Style>
<Style TargetType="{x:Type Ellipse}">
<Style.Triggers>
@@ -62,17 +62,6 @@
</Ellipse.Style>
<Ellipse.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy" Command="{s:Action Copy}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentCopy" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Delete" Command="{s:Action Delete}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Delete" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Easing" ItemsSource="{Binding EasingViewModels}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Creation" />
@@ -98,6 +87,28 @@
</DataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>
<Separator />
<MenuItem Header="Duplicate" Command="{s:Action DuplicateKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+D">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentDuplicate" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Copy" Command="{s:Action CopyKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+C">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentCopy" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Paste" Command="{s:Action PasteKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+V">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentPaste" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Delete" Command="{s:Action DeleteKeyframes}" InputGestureText="Del">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Delete" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Ellipse.ContextMenu>
</Ellipse>
@@ -5,33 +5,67 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="25"
d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:TimelineViewModel}">
<Grid x:Name="TimelineContainerGrid"
Background="{DynamicResource MaterialDesignToolBarBackground}"
<Grid Background="{DynamicResource MaterialDesignToolBarBackground}"
MouseDown="{s:Action TimelineCanvasMouseDown}"
MouseUp="{s:Action TimelineCanvasMouseUp}"
MouseMove="{s:Action TimelineCanvasMouseMove}"
Margin="0 0 -1 0">
ContextMenuOpening="{s:Action ContextMenuOpening}"
ContextMenuClosing="{s:Action ContextMenuClosing}"
Height="{Binding LayerPropertiesViewModel.TreeViewModelHeight}"
VerticalAlignment="Top"
Focusable="True">
<Grid.InputBindings>
<KeyBinding Key="Delete" Command="{s:Action DeleteKeyframes}" />
<KeyBinding Key="D" Modifiers="Control" Command="{s:Action DuplicateKeyframes}" />
<KeyBinding Key="C" Modifiers="Control" Command="{s:Action CopyKeyframes}" />
<KeyBinding Key="V" Modifiers="Control" Command="{s:Action PasteKeyframes}" />
</Grid.InputBindings>
<Grid.Triggers>
<EventTrigger RoutedEvent="UIElement.MouseLeftButtonDown">
<BeginStoryboard>
<Storyboard Storyboard.TargetName="MultiSelectionPath" Storyboard.TargetProperty="Opacity">
<DoubleAnimation From="0" To="1" Duration="0:0:0.1" />
<DoubleAnimation To="1" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="UIElement.MouseLeftButtonUp">
<BeginStoryboard>
<Storyboard Storyboard.TargetName="MultiSelectionPath" Storyboard.TargetProperty="Opacity">
<DoubleAnimation From="1" To="0" Duration="0:0:0.2" />
<DoubleAnimation To="0" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Duplicate" Command="{s:Action DuplicateKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+D" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentDuplicate" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Copy" Command="{s:Action CopyKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+C" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentCopy" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Paste" Command="{s:Action PasteKeyframes}" CommandParameter="{Binding}" InputGestureText="Ctrl+V" >
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentPaste" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Delete" Command="{s:Action DeleteKeyframes}" InputGestureText="Del" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Delete" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Grid.ContextMenu>
<ItemsControl ItemsSource="{Binding LayerPropertyGroups}"
MinWidth="{Binding TotalTimelineWidth}"
HorizontalAlignment="Left">
@@ -48,7 +82,7 @@
X1="{Binding StartSegmentEndPosition}"
X2="{Binding StartSegmentEndPosition}"
Y1="0"
Y2="{Binding ActualHeight, ElementName=TimelineContainerGrid}"
Y2="{Binding LayerPropertiesViewModel.TreeViewModelHeight}"
HorizontalAlignment="Left"
Visibility="{Binding LayerPropertiesViewModel.StartTimelineSegmentViewModel.SegmentEnabled, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
<Line Stroke="{StaticResource PrimaryHueDarkBrush}"
@@ -57,14 +91,14 @@
X1="{Binding MainSegmentEndPosition}"
X2="{Binding MainSegmentEndPosition}"
Y1="0"
Y2="{Binding ActualHeight, ElementName=TimelineContainerGrid}" />
Y2="{Binding LayerPropertiesViewModel.TreeViewModelHeight}" />
<Line Stroke="{StaticResource PrimaryHueDarkBrush}"
Opacity="0.5"
StrokeDashArray="4 2"
X1="{Binding EndSegmentEndPosition}"
X2="{Binding EndSegmentEndPosition}"
Y1="0"
Y2="{Binding ActualHeight, ElementName=TimelineContainerGrid}"
Y2="{Binding LayerPropertiesViewModel.TreeViewModelHeight}"
Visibility="{Binding LayerPropertiesViewModel.EndTimelineSegmentViewModel.SegmentEnabled, Converter={x:Static s:BoolToVisibilityConverter.Instance}}" />
<!-- Multi-selection rectangle -->
@@ -3,11 +3,15 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using Artemis.Core;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline.Models;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.Models;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
@@ -151,31 +155,108 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
#region Context menu actions
public void ContextMenuOpening(object sender, EventArgs e)
public bool CanDuplicateKeyframes => GetAllKeyframeViewModels().Any(k => k.IsSelected);
public bool CanCopyKeyframes => GetAllKeyframeViewModels().Any(k => k.IsSelected);
public bool CanDeleteKeyframes => GetAllKeyframeViewModels().Any(k => k.IsSelected);
public bool CanPasteKeyframes => JsonClipboard.GetData() is KeyframeClipboardModel;
private TimeSpan? _contextMenuOpenPosition;
public void ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
if (sender is Ellipse ellipse && ellipse.DataContext is ITimelineKeyframeViewModel viewModel)
_contextMenuOpenPosition = GetCursorTime(new Point(e.CursorLeft, e.CursorTop));
}
public void ContextMenuClosing(object sender, ContextMenuEventArgs e)
{
_contextMenuOpenPosition = null;
}
public void KeyframeContextMenuOpening(object sender, ContextMenuEventArgs e)
{
if (sender is FrameworkElement fe && fe.DataContext is ITimelineKeyframeViewModel viewModel)
viewModel.PopulateEasingViewModels();
}
public void ContextMenuClosing(object sender, EventArgs e)
public void KeyframeContextMenuClosing(object sender, ContextMenuEventArgs e)
{
if (sender is Ellipse ellipse && ellipse.DataContext is ITimelineKeyframeViewModel viewModel)
viewModel.ClearEasingViewModels();
}
public void Copy(ITimelineKeyframeViewModel viewModel)
public void DeleteKeyframes()
{
// viewModel.Copy();
List<ITimelineKeyframeViewModel> keyframeViewModels = GetAllKeyframeViewModels();
foreach (ITimelineKeyframeViewModel keyframeViewModel in keyframeViewModels.Where(k => k.IsSelected))
keyframeViewModel.Copy();
List<ITimelineKeyframeViewModel> keyframeViewModels = GetAllKeyframeViewModels().Where(k => k.IsSelected).ToList();
foreach (ITimelineKeyframeViewModel keyframeViewModel in keyframeViewModels)
keyframeViewModel.Delete(false);
_profileEditorService.UpdateSelectedProfileElement();
}
public void Delete(ITimelineKeyframeViewModel viewModel)
public void DuplicateKeyframes(ITimelineKeyframeViewModel viewModel = null)
{
List<ITimelineKeyframeViewModel> keyframeViewModels = GetAllKeyframeViewModels();
foreach (ITimelineKeyframeViewModel keyframeViewModel in keyframeViewModels.Where(k => k.IsSelected))
keyframeViewModel.Delete();
TimeSpan pastePosition = GetPastePosition(viewModel);
List<ILayerPropertyKeyframe> keyframes = GetAllKeyframeViewModels().Where(k => k.IsSelected).Select(k => k.Keyframe).ToList();
DuplicateKeyframes(keyframes, pastePosition);
}
public void CopyKeyframes()
{
List<ILayerPropertyKeyframe> keyframes = GetAllKeyframeViewModels().Where(k => k.IsSelected).Select(k => k.Keyframe).ToList();
CopyKeyframes(keyframes);
}
public void PasteKeyframes(ITimelineKeyframeViewModel viewModel = null)
{
TimeSpan pastePosition = GetPastePosition(viewModel);
PasteKeyframes(pastePosition);
}
private TimeSpan GetPastePosition(ITimelineKeyframeViewModel viewModel)
{
TimeSpan pastePosition = _profileEditorService.CurrentTime;
// If a keyframe VM is provided, paste onto there
if (viewModel != null)
pastePosition = viewModel.Position;
// Paste at the position the context menu was opened
else if (_contextMenuOpenPosition != null)
pastePosition = _contextMenuOpenPosition.Value;
return pastePosition;
}
public List<ILayerPropertyKeyframe> DuplicateKeyframes(List<ILayerPropertyKeyframe> keyframes, TimeSpan pastePosition)
{
KeyframeClipboardModel clipboardModel = CoreJson.DeserializeObject<KeyframeClipboardModel>(CoreJson.SerializeObject(new KeyframeClipboardModel(keyframes), true), true);
return PasteClipboardData(clipboardModel, pastePosition);
}
public void CopyKeyframes(List<ILayerPropertyKeyframe> keyframes)
{
KeyframeClipboardModel clipboardModel = new KeyframeClipboardModel(keyframes);
JsonClipboard.SetObject(clipboardModel);
}
public List<ILayerPropertyKeyframe> PasteKeyframes(TimeSpan pastePosition)
{
KeyframeClipboardModel clipboardObject = JsonClipboard.GetData<KeyframeClipboardModel>();
return PasteClipboardData(clipboardObject, pastePosition);
}
private List<ILayerPropertyKeyframe> PasteClipboardData(KeyframeClipboardModel clipboardModel, TimeSpan pastePosition)
{
List<ILayerPropertyKeyframe> pasted = new List<ILayerPropertyKeyframe>();
if (clipboardModel == null)
return pasted;
RenderProfileElement target = _profileEditorService.SelectedProfileElement;
if (target == null)
return pasted;
clipboardModel.Paste(target, pastePosition);
return pasted;
}
#endregion
@@ -254,6 +335,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
// ReSharper disable once UnusedMember.Global - Called from view
public void TimelineCanvasMouseDown(object sender, MouseButtonEventArgs e)
{
// Workaround for focus not being applied to the grid causing keybinds not to function
((IInputElement) sender).Focus();
if (e.LeftButton == MouseButtonState.Released)
return;
@@ -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;