Profiles - Save folder open/closed state

Profiles editor - Save last selected element and reselect it
Profile editor - Save pan/zoom position
Profile editor - Added option to resume normal playback on focus loss
This commit is contained in:
Robert committed 2021-07-01 21:12:09 +02:00
1 parent ab754942d5
commit 8728599dcc
24 files changed
+415 -191

No files matched your search

@@ -559,6 +559,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
private void CoreServiceOnFrameRendering(object sender, FrameRenderingEventArgs e)
{
if (!ProfileEditorService.Playing)
{
Pause();
return;
}
Execute.PostToUIThread(() =>
{
TimeSpan newTime = ProfileEditorService.CurrentTime.Add(TimeSpan.FromSeconds(e.DeltaTime));
@@ -110,6 +110,24 @@
IsEnabled="{Binding HasSelectedElement}"
Command="{s:Action OpenLayerPropertyScripts}"/>
</MenuItem>
<MenuItem Header="_Options">
<MenuItem Header="Focus Selected Layer"
ToolTip="If enabled, displays only the layer you currently have selected"
IsCheckable="True"
IsChecked="{Binding FocusSelectedLayer.Value}"
IsEnabled="False"/>
<MenuItem Header="Display Data Model Values"
IsCheckable="True"
IsChecked="{Binding ShowDataModelValues.Value}"/>
<MenuItem Header="Run Profile on Focus Loss"
ToolTip="If enabled, regular profile playback is resumed on focus loss"
IsCheckable="True"
IsChecked="{Binding StopOnFocusLoss.Value}"/>
<MenuItem Header="Apply All Data Bindings During Edit"
ToolTip="If enabled, updates all data bindings instead of only the one you are editing"
IsCheckable="True"
IsChecked="{Binding AlwaysApplyDataBindings.Value}"/>
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="Artemis Wiki"
Icon="{materialDesign:PackIcon Kind=BookEdit}"
@@ -1,24 +1,28 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Events;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.DisplayConditions;
using Artemis.UI.Screens.ProfileEditor.LayerProperties;
using Artemis.UI.Screens.ProfileEditor.ProfileTree;
using Artemis.UI.Screens.ProfileEditor.Visualization;
using Artemis.UI.Screens.Sidebar;
using Artemis.UI.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using MaterialDesignThemes.Wpf;
using Stylet;
using ProfileConfigurationEventArgs = Artemis.UI.Shared.ProfileConfigurationEventArgs;
namespace Artemis.UI.Screens.ProfileEditor
{
public class ProfileEditorViewModel : MainScreenViewModel
public class ProfileEditorViewModel : MainScreenViewModel, IHandle<MainWindowFocusChangedEvent>
{
private readonly IDebugService _debugService;
private readonly IMessageService _messageService;
@@ -28,15 +32,12 @@ namespace Artemis.UI.Screens.ProfileEditor
private readonly ISettingsService _settingsService;
private readonly ISidebarVmFactory _sidebarVmFactory;
private readonly IWindowManager _windowManager;
private PluginSetting<GridLength> _bottomPanelsHeight;
private PluginSetting<GridLength> _dataModelConditionsHeight;
private readonly IEventAggregator _eventAggregator;
private DisplayConditionsViewModel _displayConditionsViewModel;
private PluginSetting<GridLength> _elementPropertiesWidth;
private LayerPropertiesViewModel _layerPropertiesViewModel;
private ProfileTreeViewModel _profileTreeViewModel;
private ProfileViewModel _profileViewModel;
private PluginSetting<GridLength> _sidePanelsWidth;
public ProfileEditorViewModel(ProfileViewModel profileViewModel,
ProfileTreeViewModel profileTreeViewModel,
DisplayConditionsViewModel dataModelConditionsViewModel,
@@ -48,6 +49,7 @@ namespace Artemis.UI.Screens.ProfileEditor
IMessageService messageService,
IDebugService debugService,
IWindowManager windowManager,
IEventAggregator eventAggregator,
IScriptVmFactory scriptVmFactory,
ISidebarVmFactory sidebarVmFactory)
{
@@ -57,9 +59,10 @@ namespace Artemis.UI.Screens.ProfileEditor
_messageService = messageService;
_debugService = debugService;
_windowManager = windowManager;
_eventAggregator = eventAggregator;
_scriptVmFactory = scriptVmFactory;
_sidebarVmFactory = sidebarVmFactory;
DisplayName = "Profile Editor";
DialogService = dialogService;
@@ -102,29 +105,14 @@ namespace Artemis.UI.Screens.ProfileEditor
set => SetAndNotify(ref _profileViewModel, value);
}
public PluginSetting<GridLength> SidePanelsWidth
{
get => _sidePanelsWidth;
set => SetAndNotify(ref _sidePanelsWidth, value);
}
public PluginSetting<GridLength> DataModelConditionsHeight
{
get => _dataModelConditionsHeight;
set => SetAndNotify(ref _dataModelConditionsHeight, value);
}
public PluginSetting<GridLength> BottomPanelsHeight
{
get => _bottomPanelsHeight;
set => SetAndNotify(ref _bottomPanelsHeight, value);
}
public PluginSetting<GridLength> ElementPropertiesWidth
{
get => _elementPropertiesWidth;
set => SetAndNotify(ref _elementPropertiesWidth, value);
}
public PluginSetting<GridLength> SidePanelsWidth => _settingsService.GetSetting("ProfileEditor.SidePanelsWidth", new GridLength(385));
public PluginSetting<GridLength> DataModelConditionsHeight => _settingsService.GetSetting("ProfileEditor.DataModelConditionsHeight", new GridLength(345));
public PluginSetting<GridLength> BottomPanelsHeight => _settingsService.GetSetting("ProfileEditor.BottomPanelsHeight", new GridLength(265));
public PluginSetting<GridLength> ElementPropertiesWidth => _settingsService.GetSetting("ProfileEditor.ElementPropertiesWidth", new GridLength(545));
public PluginSetting<bool> StopOnFocusLoss => _settingsService.GetSetting("ProfileEditor.StopOnFocusLoss", true);
public PluginSetting<bool> ShowDataModelValues => _settingsService.GetSetting("ProfileEditor.ShowDataModelValues", false);
public PluginSetting<bool> FocusSelectedLayer => _settingsService.GetSetting("ProfileEditor.FocusSelectedLayer", true);
public PluginSetting<bool> AlwaysApplyDataBindings => _settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", true);
public void Undo()
{
@@ -180,25 +168,39 @@ namespace Artemis.UI.Screens.ProfileEditor
_messageService.ShowMessage("Redid profile update", "UNDO", Undo);
}
#region Overrides of Screen
protected override void OnInitialActivate()
{
StopOnFocusLoss.AutoSave = true;
ShowDataModelValues.AutoSave = true;
FocusSelectedLayer.AutoSave = true;
AlwaysApplyDataBindings.AutoSave = true;
_profileEditorService.SelectedProfileChanged += ProfileEditorServiceOnSelectedProfileChanged;
_profileEditorService.SelectedProfileElementChanged += ProfileEditorServiceOnSelectedProfileElementChanged;
LoadWorkspaceSettings();
_eventAggregator.Subscribe(this);
base.OnInitialActivate();
}
protected override void OnClose()
{
StopOnFocusLoss.AutoSave = false;
ShowDataModelValues.AutoSave = false;
FocusSelectedLayer.AutoSave = false;
AlwaysApplyDataBindings.AutoSave = false;
_profileEditorService.SelectedProfileChanged -= ProfileEditorServiceOnSelectedProfileChanged;
_profileEditorService.SelectedProfileElementChanged -= ProfileEditorServiceOnSelectedProfileElementChanged;
_eventAggregator.Unsubscribe(this);
SaveWorkspaceSettings();
_profileEditorService.ChangeSelectedProfileConfiguration(null);
base.OnClose();
}
#endregion
private void ProfileEditorServiceOnSelectedProfileChanged(object sender, ProfileConfigurationEventArgs e)
{
NotifyOfPropertyChange(nameof(ProfileConfiguration));
@@ -208,15 +210,7 @@ namespace Artemis.UI.Screens.ProfileEditor
{
NotifyOfPropertyChange(nameof(HasSelectedElement));
}
private void LoadWorkspaceSettings()
{
SidePanelsWidth = _settingsService.GetSetting("ProfileEditor.SidePanelsWidth", new GridLength(385));
DataModelConditionsHeight = _settingsService.GetSetting("ProfileEditor.DataModelConditionsHeight", new GridLength(345));
BottomPanelsHeight = _settingsService.GetSetting("ProfileEditor.BottomPanelsHeight", new GridLength(265));
ElementPropertiesWidth = _settingsService.GetSetting("ProfileEditor.ElementPropertiesWidth", new GridLength(545));
}
private void SaveWorkspaceSettings()
{
SidePanelsWidth.Save();
@@ -234,7 +228,7 @@ namespace Artemis.UI.Screens.ProfileEditor
{
await _sidebarVmFactory.SidebarProfileConfigurationViewModel(_profileEditorService.SelectedProfileConfiguration).ViewProperties();
}
public async Task AdaptProfile()
{
if (_profileEditorService.SelectedProfileConfiguration?.Profile == null)
@@ -322,5 +316,19 @@ namespace Artemis.UI.Screens.ProfileEditor
}
#endregion
#region Implementation of IHandle<in MainWindowFocusChangedEvent>
/// <inheritdoc />
public void Handle(MainWindowFocusChangedEvent message)
{
if (!StopOnFocusLoss.Value)
return;
_profileEditorService.SuspendEditing = !message.IsFocused;
ProfileViewModel.SuspendedEditing = !message.IsFocused;
}
#endregion
}
}
@@ -97,6 +97,11 @@
<b:Interaction.Behaviors>
<behaviors:TreeViewSelectionBehavior SelectedItem="{Binding SelectedTreeItem}" />
</b:Interaction.Behaviors>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource MaterialDesignTreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay, FallbackValue=False}"/>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type treeItem:FolderViewModel}" ItemsSource="{Binding Items}">
<ContentControl s:View.Model="{Binding}" />
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Artemis.Core;
@@ -24,8 +25,6 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
{
_profileEditorService = profileEditorService;
_profileTreeVmFactory = profileTreeVmFactory;
CreateRootFolderViewModel();
}
public TreeItemViewModel SelectedTreeItem
@@ -33,7 +32,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
get => _selectedTreeItem;
set
{
if (!_updatingTree && SetAndNotify(ref _selectedTreeItem, value) && !_draggingTreeView)
if (!_updatingTree && SetAndNotify(ref _selectedTreeItem, value) && !_draggingTreeView)
ApplySelectedTreeItem();
}
}
@@ -54,6 +53,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
protected override void OnInitialActivate()
{
Subscribe();
CreateRootFolderViewModel();
base.OnInitialActivate();
}
@@ -83,6 +83,13 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
ActiveItem = _profileTreeVmFactory.FolderViewModel(folder);
_updatingTree = false;
Execute.PostToUIThread(async () =>
{
await Task.Delay(1500);
SelectedTreeItem = ActiveItem.GetAllChildren().FirstOrDefault(c => c.ProfileElement == _profileEditorService.SelectedProfileElement);
});
}
#region IDropTarget
@@ -1,4 +1,5 @@
using Artemis.Core;
using System.ComponentModel;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Shared.Services;
@@ -19,5 +20,35 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
}
public override bool SupportsChildren => true;
public override bool IsExpanded
{
get => ((Folder) ProfileElement).IsExpanded;
set => ((Folder) ProfileElement).IsExpanded = value;
}
private void ProfileElementOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Folder.IsExpanded))
NotifyOfPropertyChange(nameof(IsExpanded));
}
#region Overrides of Screen
/// <inheritdoc />
protected override void OnInitialActivate()
{
ProfileElement.PropertyChanged += ProfileElementOnPropertyChanged;
base.OnInitialActivate();
}
/// <inheritdoc />
protected override void OnClose()
{
ProfileElement.PropertyChanged -= ProfileElementOnPropertyChanged;
base.OnClose();
}
#endregion
}
}
@@ -33,5 +33,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
public Layer Layer => ProfileElement as Layer;
public bool ShowIcons => Layer?.LayerBrush != null;
public override bool SupportsChildren => false;
public override bool IsExpanded { get; set; }
}
}
@@ -52,6 +52,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem
public bool CanPasteElement => _profileEditorService.GetCanPasteProfileElement();
public abstract bool SupportsChildren { get; }
public abstract bool IsExpanded { get; set; }
public List<TreeItemViewModel> GetAllChildren()
{
@@ -0,0 +1,23 @@
<UserControl x:Class="Artemis.UI.Screens.ProfileEditor.SuspendedProfileEditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.ProfileEditor"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Top" Margin="16">
<materialDesign:PackIcon Kind="PauseCircle" Width="250" Height="250" HorizontalAlignment="Center" />
<TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="0 25">
Profile editing has been paused
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" TextWrapping="Wrap" HorizontalAlignment="Center">
Artemis has resumed regular profile playback. As soon as you focus this window, the editor will open to continue editing
'<Run Text="{Binding PreviousSelectedProfileConfiguration.Name}" />'.
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" HorizontalAlignment="Center">
You can disable this behaviour in the editor's option menu.
</TextBlock>
</StackPanel>
</UserControl>
@@ -0,0 +1,53 @@
using Artemis.Core;
using Artemis.UI.Events;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.UI.Screens.ProfileEditor
{
public class SuspendedProfileEditorViewModel : MainScreenViewModel, IHandle<MainWindowFocusChangedEvent>
{
private readonly IEventAggregator _eventAggregator;
private readonly IProfileEditorService _profileEditorService;
private ProfileConfiguration _previousSelectedProfileConfiguration;
public SuspendedProfileEditorViewModel(IEventAggregator eventAggregator, IProfileEditorService profileEditorService)
{
_eventAggregator = eventAggregator;
_profileEditorService = profileEditorService;
}
public ProfileConfiguration PreviousSelectedProfileConfiguration
{
get => _previousSelectedProfileConfiguration;
set => SetAndNotify(ref _previousSelectedProfileConfiguration, value);
}
public void Handle(MainWindowFocusChangedEvent message)
{
if (!message.IsFocused)
return;
RootViewModel rootViewModel = (RootViewModel) Parent;
if (PreviousSelectedProfileConfiguration != null)
rootViewModel.SidebarViewModel.SelectProfileConfiguration(PreviousSelectedProfileConfiguration);
}
#region Overrides of Screen
protected override void OnInitialActivate()
{
PreviousSelectedProfileConfiguration = _profileEditorService.PreviousSelectedProfileConfiguration;
_eventAggregator.Subscribe(this);
base.OnInitialActivate();
}
protected override void OnClose()
{
_eventAggregator.Unsubscribe(this);
base.OnClose();
}
#endregion
}
}
@@ -101,6 +101,7 @@
</Grid>
<Grid Name="EditorDisplayGrid"
Visibility="{Binding SuspendedEditing, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}"
shared:SizeObserver.Observe="True"
shared:SizeObserver.ObservedHeight="{Binding PanZoomViewModel.CanvasHeight}"
shared:SizeObserver.ObservedWidth="{Binding PanZoomViewModel.CanvasWidth}">
@@ -129,25 +130,7 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<StackPanel ZIndex="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10" Cursor="Arrow">
<materialDesign:Card Padding="8">
<StackPanel Orientation="Horizontal">
<CheckBox Style="{StaticResource MaterialDesignCheckBox}"
IsChecked="{Binding FocusSelectedLayer.Value}"
ToolTip="If selected, dims all LEDs that are not part of the selected layer">
Focus selected layer
</CheckBox>
<CheckBox Style="{StaticResource MaterialDesignCheckBox}"
Margin="10 0 0 0"
IsChecked="{Binding AlwaysApplyDataBindings.Value}"
ToolTip="If selected, updates all data bindings instead of only the one you are editing">
Apply all data bindings in editor
</CheckBox>
</StackPanel>
</materialDesign:Card>
</StackPanel>
<StackPanel Orientation="Vertical" VerticalAlignment="Bottom" HorizontalAlignment="Right"
Margin="10" ZIndex="1">
<Slider Orientation="Vertical"
@@ -26,16 +26,15 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
private int _activeToolIndex;
private VisualizationToolViewModel _activeToolViewModel;
private PluginSetting<bool> _alwaysApplyDataBindings;
private bool _canApplyToLayer;
private bool _canSelectEditTool;
private BindableCollection<ArtemisDevice> _devices;
private BindableCollection<ArtemisLed> _highlightedLeds;
private PluginSetting<bool> _focusSelectedLayer;
private DateTime _lastUpdate;
private PanZoomViewModel _panZoomViewModel;
private Layer _previousSelectedLayer;
private int _previousTool;
private bool _suspendedEditing;
public ProfileViewModel(IProfileEditorService profileEditorService,
IRgbService rgbService,
@@ -78,19 +77,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
get => _highlightedLeds;
set => SetAndNotify(ref _highlightedLeds, value);
}
public PluginSetting<bool> AlwaysApplyDataBindings
{
get => _alwaysApplyDataBindings;
set => SetAndNotify(ref _alwaysApplyDataBindings, value);
}
public PluginSetting<bool> FocusSelectedLayer
{
get => _focusSelectedLayer;
set => SetAndNotify(ref _focusSelectedLayer, value);
}
public VisualizationToolViewModel ActiveToolViewModel
{
get => _activeToolViewModel;
@@ -132,9 +119,21 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
set => SetAndNotify(ref _canApplyToLayer, value);
}
public bool SuspendedEditing
{
get => _suspendedEditing;
set => SetAndNotify(ref _suspendedEditing, value);
}
protected override void OnInitialActivate()
{
PanZoomViewModel = new PanZoomViewModel {LimitToZero = false};
PanZoomViewModel = new PanZoomViewModel
{
LimitToZero = false,
PanX = _settingsService.GetSetting("ProfileEditor.PanX", 0d).Value,
PanY = _settingsService.GetSetting("ProfileEditor.PanY", 0d).Value,
Zoom = _settingsService.GetSetting("ProfileEditor.Zoom", 0d).Value
};
Devices = new BindableCollection<ArtemisDevice>();
HighlightedLeds = new BindableCollection<ArtemisLed>();
@@ -143,14 +142,10 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
ActivateToolByIndex(0);
ApplyActiveProfile();
AlwaysApplyDataBindings = _settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", true);
FocusSelectedLayer = _settingsService.GetSetting("ProfileEditor.FocusSelectedLayer", true);
_lastUpdate = DateTime.Now;
_coreService.FrameRendered += OnFrameRendered;
FocusSelectedLayer.SettingChanged += HighlightSelectedLayerOnSettingChanged;
_rgbService.DeviceAdded += RgbServiceOnDevicesModified;
_rgbService.DeviceRemoved += RgbServiceOnDevicesModified;
_profileEditorService.SelectedProfileChanged += OnSelectedProfileChanged;
@@ -163,7 +158,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
protected override void OnClose()
{
_coreService.FrameRendered -= OnFrameRendered;
FocusSelectedLayer.SettingChanged -= HighlightSelectedLayerOnSettingChanged;
_rgbService.DeviceAdded -= RgbServiceOnDevicesModified;
_rgbService.DeviceRemoved -= RgbServiceOnDevicesModified;
_profileEditorService.SelectedProfileChanged -= OnSelectedProfileChanged;
@@ -172,9 +166,13 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
if (_previousSelectedLayer != null)
_previousSelectedLayer.LayerBrushUpdated -= SelectedLayerOnLayerBrushUpdated;
AlwaysApplyDataBindings.Save();
FocusSelectedLayer.Save();
_settingsService.GetSetting("ProfileEditor.PanX", 0d).Value = PanZoomViewModel.PanX;
_settingsService.GetSetting("ProfileEditor.PanX", 0d).Save();
_settingsService.GetSetting("ProfileEditor.PanY", 0d).Value = PanZoomViewModel.PanY;
_settingsService.GetSetting("ProfileEditor.PanY", 0d).Save();
_settingsService.GetSetting("ProfileEditor.Zoom", 0d).Value = PanZoomViewModel.Zoom;
_settingsService.GetSetting("ProfileEditor.Zoom", 0d).Save();
base.OnClose();
}
@@ -210,7 +208,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
private void UpdateLedsDimStatus()
{
HighlightedLeds.Clear();
if (FocusSelectedLayer.Value && _profileEditorService.SelectedProfileElement is Layer layer)
if (_profileEditorService.SelectedProfileElement is Layer layer)
HighlightedLeds.AddRange(layer.Leds);
}
@@ -308,7 +306,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
TimeSpan delta = DateTime.Now - _lastUpdate;
_lastUpdate = DateTime.Now;
if (!AlwaysApplyDataBindings.Value || _profileEditorService.SelectedProfile == null)
if (!_settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", true).Value || _profileEditorService.SelectedProfile == null)
return;
foreach (IDataBindingRegistration dataBindingRegistration in _profileEditorService.SelectedProfile.GetAllFolders()