Implement element selection event within profile editor VMs

This commit is contained in:
Robert committed 2019-11-27 20:56:07 +01:00
1 parent 0b56fd9088
commit bf729b64fd
13 files changed
+120 -22

No files matched your search

@@ -1,4 +1,5 @@
using Stylet;
using Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.ProfileElement;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor
{
@@ -13,5 +14,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
public virtual void ActiveProfileUpdated()
{
}
public virtual void ProfileElementSelected(ProfileElementViewModel profileElement)
{
}
}
}
@@ -20,7 +20,6 @@
</ResourceDictionary>
</UserControl.Resources>
<!-- Blue -->
<Grid Margin="16">
<Grid.ColumnDefinitions>
<!-- Left side -->
@@ -31,7 +30,7 @@
<ColumnDefinition Width="{Binding SidePanelsWidth.Value, Mode=TwoWay}" MinWidth="100" />
</Grid.ColumnDefinitions>
<!-- Left side (orange) -->
<!-- Left side -->
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<!-- Introduction -->
@@ -60,7 +59,7 @@
<!-- Bottom panels resize -->
<GridSplitter Grid.Row="2" Grid.Column="0" Height="5" HorizontalAlignment="Stretch" Cursor="SizeNS" Margin="0 5" />
<!-- Bottom panels (green) -->
<!-- Bottom panels -->
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<!-- Layer elements -->
@@ -89,7 +88,7 @@
<!-- Side panels resize -->
<GridSplitter Grid.Row="0" Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Cursor="SizeWE" Margin="5 35 5 0" />
<!-- Side panels (orange) -->
<!-- Side panels -->
<Grid Grid.Row="0" Grid.Column="2">
<Grid.RowDefinitions>
<!-- Profile selection -->
@@ -13,6 +13,7 @@ using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions;
using Artemis.UI.Screens.Module.ProfileEditor.ElementProperties;
using Artemis.UI.Screens.Module.ProfileEditor.LayerElements;
using Artemis.UI.Screens.Module.ProfileEditor.ProfileElements;
using Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.ProfileElement;
using Artemis.UI.Screens.Module.ProfileEditor.Visualization;
using Artemis.UI.Services.Interfaces;
using Stylet;
@@ -195,12 +196,18 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
Module.ChangeActiveProfile(activeProfile);
}
public void OnProfileUpdated()
public void OnProfileUpdated(ProfileEditorPanelViewModel source = null)
{
_profileService.UpdateProfile(SelectedProfile, true);
foreach (var panelViewModel in Items)
foreach (var panelViewModel in Items.Where(p => p != source))
panelViewModel.ActiveProfileUpdated();
}
public void OnProfileElementSelected(ProfileElementViewModel profileElement, ProfileEditorPanelViewModel source = null)
{
foreach (var panelViewModel in Items.Where(p => p != source))
panelViewModel.ProfileElementSelected(profileElement);
}
}
}
@@ -10,6 +10,8 @@
xmlns:dd="urn:gong-wpf-dragdrop"
xmlns:profileElements="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.ProfileElements"
xmlns:profileElement="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.ProfileElements.ProfileElement"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type profileElements:ProfileElementsViewModel}}">
@@ -32,6 +34,9 @@
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropHandler="{Binding}">
<i:Interaction.Behaviors>
<utilities:BindableSelectedItemBehavior SelectedItem="{Binding SelectedProfileElement, Mode=TwoWay}" />
</i:Interaction.Behaviors>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type profileElement:FolderViewModel}" ItemsSource="{Binding Children}">
<ContentControl s:View.Model="{Binding}" />
@@ -8,6 +8,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
{
public class ProfileElementsViewModel : ProfileEditorPanelViewModel, IDropTarget
{
private ProfileElementViewModel _selectedProfileElement;
public ProfileElementsViewModel()
{
CreateRootFolderViewModel();
@@ -15,6 +17,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
public FolderViewModel RootFolder { get; set; }
public ProfileElementViewModel SelectedProfileElement
{
get => _selectedProfileElement;
set
{
_selectedProfileElement = value;
ProfileEditorViewModel.OnProfileElementSelected(_selectedProfileElement, this);
}
}
public void DragOver(IDropInfo dropInfo)
{
var dragDropType = GetDragDropType(dropInfo);
@@ -53,7 +65,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
break;
}
ProfileEditorViewModel.OnProfileUpdated();
ProfileEditorViewModel.OnProfileUpdated(this);
}
// ReSharper disable once UnusedMember.Global - Called from view
@@ -74,6 +86,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.ProfileElements
base.ActiveProfileChanged();
}
public override void ProfileElementSelected(ProfileElementViewModel profileElement)
{
// Don't set it using the setter or that will trigger the event again
_selectedProfileElement = profileElement;
NotifyOfPropertyChange(() => SelectedProfileElement);
base.ProfileElementSelected(profileElement);
}
private void CreateRootFolderViewModel()
{
if (!(ProfileEditorViewModel?.SelectedProfile?.Children?.FirstOrDefault() is Folder folder))
@@ -6,7 +6,7 @@
xmlns:s="https://github.com/canton7/Stylet"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:profileEditor="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.Visualization"
xmlns:observers="clr-namespace:Artemis.UI.Observers"
xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type profileEditor:ProfileViewModel}}">
@@ -44,9 +44,9 @@
MouseDown="{s:Action EditorGridMouseClick}"
MouseMove="{s:Action EditorGridMouseMove}"
Cursor="{Binding Cursor}"
observers:SizeObserver.Observe="True"
observers:SizeObserver.ObservedWidth="{Binding PanZoomViewModel.CanvasWidth, Mode=OneWayToSource}"
observers:SizeObserver.ObservedHeight="{Binding PanZoomViewModel.CanvasHeight, Mode=OneWayToSource}">
utilities:SizeObserver.Observe="True"
utilities:SizeObserver.ObservedWidth="{Binding PanZoomViewModel.CanvasWidth, Mode=OneWayToSource}"
utilities:SizeObserver.ObservedHeight="{Binding PanZoomViewModel.CanvasHeight, Mode=OneWayToSource}">
<Grid.Background>
<VisualBrush TileMode="Tile" Stretch="Uniform" Viewport="{Binding PanZoomViewModel.BackgroundViewport}" ViewportUnits="Absolute">
@@ -6,6 +6,7 @@ using System.Windows.Input;
using System.Windows.Media;
using Artemis.Core.Events;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services;
using Artemis.Core.Services.Storage.Interfaces;
using Artemis.UI.Extensions;
@@ -20,10 +21,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
{
public class ProfileViewModel : ProfileEditorPanelViewModel
{
private readonly ISettingsService _settingsService;
private readonly TimerUpdateTrigger _updateTrigger;
public ProfileViewModel(ISurfaceService surfaceService, ISettingsService settingsService)
{
_settingsService = settingsService;
Devices = new ObservableCollection<ProfileDeviceViewModel>();
Execute.PostToUIThread(() =>
{
@@ -48,6 +51,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
public ObservableCollection<ProfileDeviceViewModel> Devices { get; set; }
public RectangleGeometry SelectionRectangle { get; set; }
public PanZoomViewModel PanZoomViewModel { get; set; }
public PluginSetting<bool> HighlightSelectedLayer { get; set; }
public PluginSetting<bool> PauseRenderingOnFocusLoss { get; set; }
public Cursor Cursor { get; set; }
private void OnActiveSurfaceConfigurationChanged(object sender, SurfaceConfigurationEventArgs e)
@@ -106,12 +112,18 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
protected override void OnActivate()
{
HighlightSelectedLayer = _settingsService.GetSetting("ProfileEditor.HighlightSelectedLayer", true);
PauseRenderingOnFocusLoss = _settingsService.GetSetting("ProfileEditor.PauseRenderingOnFocusLoss", true);
_updateTrigger.Start();
base.OnActivate();
}
protected override void OnDeactivate()
{
HighlightSelectedLayer.Save();
PauseRenderingOnFocusLoss.Save();
_updateTrigger.Stop();
base.OnDeactivate();
}
@@ -172,7 +184,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
profileLedViewModel.SelectionStatus = SelectionStatus.None;
}
}
_mouseDragStatus = MouseDragStatus.None;
}
@@ -180,7 +192,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
{
if (IsPanKeyDown())
return;
var selectedRect = new Rect(_mouseDragStartPoint, position);
SelectionRectangle.Rect = selectedRect;