mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Profiles - Reworked profile system
Sidebar - Redesigned sidebar with customizable categories Profiles - Added the ability to configure custom profile icons Profiles - Added the ability to activate multiple profiles for modules at once Profiles - Added the ability to create profiles for no modules Profiles - Added the ability to suspend a profile or an entire category Profiles - Added profile activation conditions Profiles - Added file-based importing/exporting Profile editor - Condensed UI, removed tabs Profile editor - Disable condition operators until a left-side is picked
This commit is contained in:
1 parent
4152c290d2
commit
ceeaa4bf6d
164 files changed
+5019
-4220
No files matched your search
@@ -0,0 +1,127 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
|
||||
<Style x:Key="SidebarListBoxItem" TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource MaterialDesignToolToggleListBoxItem}">
|
||||
<Setter Property="Padding" Value="8" />
|
||||
<Setter Property="Margin" Value="6 1" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ListBoxItem}">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Margin="{TemplateBinding Margin}"
|
||||
ClipToBounds="{TemplateBinding ClipToBounds}"
|
||||
Cursor="Hand">
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="CommonStates">
|
||||
<VisualStateGroup.Transitions>
|
||||
<VisualTransition GeneratedDuration="0:0:0.3" To="Normal">
|
||||
<VisualTransition.GeneratedEasingFunction>
|
||||
<CircleEase EasingMode="EaseOut" />
|
||||
</VisualTransition.GeneratedEasingFunction>
|
||||
</VisualTransition>
|
||||
</VisualStateGroup.Transitions>
|
||||
<VisualState Name="Normal" />
|
||||
<VisualState Name="MouseOver">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="Opacity"
|
||||
To="0.03" Duration="0" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="Disabled" />
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup Name="SelectionStates">
|
||||
<VisualStateGroup.Transitions>
|
||||
<VisualTransition From="*" To="Selected">
|
||||
<Storyboard>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBackgroundBorder">
|
||||
<EasingDoubleKeyFrame KeyTime="0" Value="1" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualTransition>
|
||||
<VisualTransition From="*" To="SelectedUnfocused">
|
||||
<Storyboard>
|
||||
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBackgroundBorder">
|
||||
<EasingDoubleKeyFrame KeyTime="0" Value="1" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualTransition>
|
||||
<VisualTransition From="Selected" To="Unselected">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="SelectedBackgroundBorder"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0" Duration="0" />
|
||||
</Storyboard>
|
||||
</VisualTransition>
|
||||
</VisualStateGroup.Transitions>
|
||||
<VisualState Name="Selected">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="SelectedBackgroundBorder"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="1" Duration="0" />
|
||||
<DoubleAnimation Storyboard.TargetName="SelectedBorder"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="1" Duration="0" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState Name="Unselected" />
|
||||
<VisualState Name="SelectedUnfocused">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="SelectedBackgroundBorder"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="1" Duration="0" />
|
||||
<DoubleAnimation Storyboard.TargetName="SelectedBorder"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="1" Duration="0" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid>
|
||||
<Grid.OpacityMask>
|
||||
<VisualBrush>
|
||||
<VisualBrush.Visual>
|
||||
<Border Background="Black"
|
||||
CornerRadius="4"
|
||||
Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
|
||||
Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}" />
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</Grid.OpacityMask>
|
||||
<Border x:Name="MouseOverBorder"
|
||||
Opacity="0"
|
||||
Background="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}" />
|
||||
<Border x:Name="SelectedBackgroundBorder"
|
||||
Opacity="0"
|
||||
Background="{DynamicResource MaterialDesignDivider}" />
|
||||
<materialDesign:Ripple x:Name="Ripple" Feedback="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"
|
||||
Opacity=".82"
|
||||
Focusable="False"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Padding="{TemplateBinding Padding}" />
|
||||
<Border x:Name="SelectedBorder"
|
||||
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}, Path=SelectionMode, Converter={StaticResource EqualityToVisibilityConverter}, ConverterParameter={x:Static SelectionMode.Extended}, Mode=OneWay}"
|
||||
Opacity="0"
|
||||
BorderThickness="0"
|
||||
BorderBrush="{DynamicResource MaterialDesignDivider}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="Ripple" Property="Opacity" Value=".92" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Opacity" Value=".56" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit.ModuleActivationRequirementView"
|
||||
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.Sidebar.Dialogs.ProfileEdit"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:ModuleActivationRequirementViewModel}">
|
||||
<Border BorderThickness="0 1 0 0" BorderBrush="{DynamicResource MaterialDesignDivider}" Padding="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0">
|
||||
<TextBlock Style="{StaticResource MaterialDesignTextBlock}"
|
||||
Text="{Binding RequirementName}" />
|
||||
<TextBlock Style="{StaticResource MaterialDesignTextBlock}"
|
||||
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
|
||||
TextWrapping="Wrap"
|
||||
Text="{Binding RequirementDescription}" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
|
||||
<ToggleButton Style="{StaticResource MaterialDesignActionToggleButton}"
|
||||
Focusable="False"
|
||||
IsHitTestVisible="False"
|
||||
IsChecked="{Binding RequirementMet}">
|
||||
<ToggleButton.Content>
|
||||
<Border Background="#E74C4C" Width="32" Height="32">
|
||||
<materialDesign:PackIcon Kind="Close" VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Border>
|
||||
</ToggleButton.Content>
|
||||
<materialDesign:ToggleButtonAssist.OnContent>
|
||||
<materialDesign:PackIcon Kind="Check" />
|
||||
</materialDesign:ToggleButtonAssist.OnContent>
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
</UserControl>
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Timers;
|
||||
using Artemis.Core.Modules;
|
||||
using Humanizer;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
{
|
||||
public sealed class ModuleActivationRequirementViewModel : Screen, IDisposable
|
||||
{
|
||||
private readonly IModuleActivationRequirement _activationRequirement;
|
||||
private readonly Timer _updateTimer;
|
||||
private string _requirementDescription;
|
||||
private bool _requirementMet;
|
||||
|
||||
public ModuleActivationRequirementViewModel(IModuleActivationRequirement activationRequirement)
|
||||
{
|
||||
_activationRequirement = activationRequirement;
|
||||
_updateTimer = new Timer(500);
|
||||
|
||||
RequirementName = activationRequirement.GetType().Name.Humanize();
|
||||
RequirementDescription = activationRequirement.GetUserFriendlyDescription();
|
||||
|
||||
_updateTimer.Elapsed += UpdateTimerOnElapsed;
|
||||
}
|
||||
|
||||
public string RequirementName { get; }
|
||||
|
||||
public string RequirementDescription
|
||||
{
|
||||
get => _requirementDescription;
|
||||
set => SetAndNotify(ref _requirementDescription, value);
|
||||
}
|
||||
|
||||
public bool RequirementMet
|
||||
{
|
||||
get => _requirementMet;
|
||||
set => SetAndNotify(ref _requirementMet, value);
|
||||
}
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
Update();
|
||||
_updateTimer.Start();
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
protected override void OnDeactivate()
|
||||
{
|
||||
_updateTimer.Stop();
|
||||
base.OnDeactivate();
|
||||
}
|
||||
|
||||
private void UpdateTimerOnElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
Update();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
RequirementDescription = _activationRequirement.GetUserFriendlyDescription();
|
||||
RequirementMet = _activationRequirement.Evaluate();
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_updateTimer?.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit.ModuleActivationRequirementsView"
|
||||
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.Sidebar.Dialogs.ProfileEdit"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:ModuleActivationRequirementsViewModel}">
|
||||
<StackPanel>
|
||||
<TextBlock TextWrapping="Wrap" Style="{StaticResource MaterialDesignTextBlock}">
|
||||
This module has built-in activation requirements and your profile won't activate until
|
||||
<Run Text="{Binding ActivationType}" FontWeight="Medium" Foreground="{StaticResource SecondaryHueMidBrush}" />. <LineBreak />
|
||||
These requirements allow the module creator to decide when the data is available to your profile you cannot override them.
|
||||
</TextBlock>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding Items}" Margin="0 10 0 0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
using System.Linq;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
{
|
||||
public class ModuleActivationRequirementsViewModel : Conductor<ModuleActivationRequirementViewModel>.Collection.AllActive
|
||||
{
|
||||
private readonly ISidebarVmFactory _sidebarVmFactory;
|
||||
private Module _module;
|
||||
private string _activationType;
|
||||
|
||||
public ModuleActivationRequirementsViewModel(ISidebarVmFactory sidebarVmFactory)
|
||||
{
|
||||
_sidebarVmFactory = sidebarVmFactory;
|
||||
}
|
||||
|
||||
public Module Module
|
||||
{
|
||||
get => _module;
|
||||
set => SetAndNotify(ref _module, value);
|
||||
}
|
||||
|
||||
public string ActivationType
|
||||
{
|
||||
get => _activationType;
|
||||
set => SetAndNotify(ref _activationType, value);
|
||||
}
|
||||
|
||||
public void SetModule(Module module)
|
||||
{
|
||||
Module = module;
|
||||
ActivationType = Module != null && Module.ActivationRequirementMode == ActivationRequirementType.All
|
||||
? "all requirements are met"
|
||||
: "any requirement is met";
|
||||
|
||||
Items.Clear();
|
||||
if (Module != null)
|
||||
Items.AddRange(Module.ActivationRequirements.Select(_sidebarVmFactory.ModuleActivationRequirementViewModel));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit.ProfileEditView"
|
||||
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:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:dialogs="clr-namespace:Artemis.UI.Screens.Sidebar.Dialogs"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:profileEdit="clr-namespace:Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit"
|
||||
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="280"
|
||||
d:DataContext="{d:DesignInstance {x:Type profileEdit:ProfileEditViewModel}}"
|
||||
Width="800">
|
||||
<UserControl.Resources>
|
||||
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||
<shared:StreamToBitmapImageConverter x:Key="StreamToBitmapImageConverter"/>
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
<shared:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
|
||||
</UserControl.Resources>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Style="{StaticResource MaterialDesignHeadline6TextBlock}"
|
||||
Margin="0 0 0 10"
|
||||
Visibility="{Binding IsNew, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
|
||||
Add a new profile
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Style="{StaticResource MaterialDesignHeadline6TextBlock}"
|
||||
Margin="0 0 0 10"
|
||||
Visibility="{Binding IsNew, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
|
||||
<Run Text="{Binding ProfileConfiguration.Name}" /> | Properties
|
||||
</TextBlock>
|
||||
|
||||
<StackPanel Grid.Row="1" Grid.Column="0">
|
||||
<StackPanel>
|
||||
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}" Margin="0 0 0 14">
|
||||
General
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
<TextBox materialDesign:HintAssist.Hint="Profile name"
|
||||
Margin="0 4 0 8"
|
||||
Style="{StaticResource MaterialDesignFilledTextBox}"
|
||||
Text="{Binding ProfileName, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
<ComboBox materialDesign:HintAssist.Hint="Module"
|
||||
materialDesign:TextFieldAssist.HasClearButton="True"
|
||||
materialDesign:HintAssist.HelperText="Optional and binds the profile to the selected module, making module data available."
|
||||
Margin="0 0 0 32"
|
||||
Style="{StaticResource MaterialDesignFilledComboBox}"
|
||||
SelectedItem="{Binding SelectedModule}">
|
||||
<ComboBox.ItemsSource>
|
||||
<CompositeCollection>
|
||||
<ComboBoxItem IsEnabled="False"
|
||||
Visibility="{Binding HasUsableModules, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
|
||||
No usable modules found
|
||||
</ComboBoxItem>
|
||||
<CollectionContainer Collection="{Binding Data.Modules, Source={StaticResource DataContextProxy}}" />
|
||||
</CompositeCollection>
|
||||
</ComboBox.ItemsSource>
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type profileEdit:ProfileModuleViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<shared:ArtemisIcon Icon="{Binding Icon}" Width="16" Height="16" Margin="0 0 5 0" />
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<ComboBox materialDesign:HintAssist.Hint="Icon type"
|
||||
Margin="0 0 0 8"
|
||||
Style="{StaticResource MaterialDesignFilledComboBox}"
|
||||
SelectedValue="{Binding SelectedIconType}"
|
||||
ItemsSource="{Binding IconTypes}"
|
||||
SelectedValuePath="Value"
|
||||
DisplayMemberPath="Description" />
|
||||
|
||||
<ContentControl VerticalAlignment="Center">
|
||||
<ContentControl.Style>
|
||||
<Style TargetType="ContentControl">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding SelectedIconType}" Value="{x:Static core:ProfileConfigurationIconType.MaterialIcon}">
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<materialDesign:PackIcon Grid.Column="0"
|
||||
Kind="{Binding DataContext.SelectedIcon.Icon, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=OneWay}"
|
||||
Width="45"
|
||||
Height="45"
|
||||
Margin="0 0 10 0"
|
||||
VerticalAlignment="Center" />
|
||||
|
||||
<ComboBox Grid.Column="1"
|
||||
materialDesign:HintAssist.Hint="Profile icon"
|
||||
Style="{StaticResource MaterialDesignFilledComboBox}"
|
||||
SelectedItem="{Binding DataContext.SelectedIcon, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
||||
IsEnabled="{Binding DataContext.Initializing, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}"
|
||||
ItemsSource="{Binding DataContext.Icons, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
||||
TextSearch.TextPath="IconName">
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type profileEdit:ProfileIconViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="{Binding Icon}" Width="16" Margin="0 0 5 0" />
|
||||
<TextBlock Text="{Binding IconName}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding SelectedIconType}" Value="{x:Static core:ProfileConfigurationIconType.BitmapImage}">
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Grid.Column="0"
|
||||
Source="{Binding DataContext.SelectedImage, Converter={StaticResource StreamToBitmapImageConverter}, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"
|
||||
Margin="0 0 10 0"
|
||||
Width="45"
|
||||
Height="45"
|
||||
VerticalAlignment="Center" />
|
||||
<Button Grid.Column="1"
|
||||
Command="{s:Action SelectBitmapFile}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
ToolTip="Select an image">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="Paperclip" Margin="0 0 10 0" />
|
||||
<TextBlock>BROWSE IMAGE</TextBlock>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding SelectedIconType}" Value="{x:Static core:ProfileConfigurationIconType.SvgImage}">
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<svgc:SvgViewbox Grid.Column="0"
|
||||
StreamSource="{Binding DataContext.SelectedImage, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
||||
Margin="0 0 10 0"
|
||||
Width="45"
|
||||
Height="45"
|
||||
VerticalAlignment="Center" />
|
||||
<Button Grid.Column="1"
|
||||
Command="{s:Action SelectSvgFile}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
ToolTip="Select an image">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="Paperclip" Margin="0 0 10 0" />
|
||||
<TextBlock>BROWSE IMAGE</TextBlock>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ContentControl.Style>
|
||||
</ContentControl>
|
||||
</StackPanel>
|
||||
|
||||
<Border Grid.Row="1" Grid.Column="1" BorderThickness="1" BorderBrush="{StaticResource MaterialDesignDivider}" Width="1" Margin="10 0" />
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0">
|
||||
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}">
|
||||
Keybinds
|
||||
</TextBlock>
|
||||
<TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}">You may set up keybinds to activate/deactivate the profile</TextBlock>
|
||||
|
||||
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Top" Margin="16">
|
||||
<materialDesign:PackIcon Kind="Crane" Width="100" Height="100" HorizontalAlignment="Center" />
|
||||
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="0 20">
|
||||
Keybinds are not yet implemented
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Margin="0 16" BorderThickness="1" Height="1" BorderBrush="{StaticResource MaterialDesignDivider}" />
|
||||
|
||||
<Grid Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0">
|
||||
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}">
|
||||
Activation conditions
|
||||
</TextBlock>
|
||||
<TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}">If you only want this profile to be active under certain conditions, configure those conditions below</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<materialDesign:Card Grid.Row="1" Background="{DynamicResource MaterialDesignToolBarBackground}" Padding="10">
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Auto"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
MinHeight="150"
|
||||
MaxHeight="300"
|
||||
Margin="0 5">
|
||||
<ContentControl s:View.Model="{Binding ActivationConditionViewModel}" />
|
||||
</ScrollViewer>
|
||||
</materialDesign:Card>
|
||||
|
||||
<Grid Grid.Row="2" Margin="0 10" Visibility="{Binding SelectedModule, Converter={StaticResource NullToVisibilityConverter}, Mode=OneWay}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border Grid.Column="0" BorderThickness="1" Height="1" BorderBrush="{StaticResource MaterialDesignDivider}" />
|
||||
<TextBlock Grid.Column="1" Margin="16 0" Style="{StaticResource MaterialDesignBody2TextBlock}">AND</TextBlock>
|
||||
<Border Grid.Column="2" BorderThickness="1" Height="1" BorderBrush="{StaticResource MaterialDesignDivider}" />
|
||||
</Grid>
|
||||
|
||||
<materialDesign:Card Grid.Row="3"
|
||||
Background="{DynamicResource MaterialDesignToolBarBackground}"
|
||||
Padding="10"
|
||||
Visibility="{Binding SelectedModule, Converter={StaticResource NullToVisibilityConverter}, Mode=OneWay}">
|
||||
<ContentControl s:View.Model="{Binding ModuleActivationRequirementsViewModel}" />
|
||||
</materialDesign:Card>
|
||||
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" Margin="0 16 0 0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Grid.Column="0"
|
||||
HorizontalAlignment="Left"
|
||||
Style="{StaticResource MaterialDesignFlatAccentButton}"
|
||||
Command="{s:Action Delete}"
|
||||
Visibility="{Binding IsNew, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
|
||||
DELETE
|
||||
</Button>
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Command="{s:Action Cancel}">
|
||||
CANCEL
|
||||
</Button>
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" Command="{s:Action Accept}">
|
||||
ACCEPT
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,214 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.ProfileEditor.Conditions;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using FluentValidation;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Ookii.Dialogs.Wpf;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
{
|
||||
public class ProfileEditViewModel : DialogViewModelBase
|
||||
{
|
||||
private readonly DataModelConditionGroup _dataModelConditionGroup;
|
||||
private readonly List<Module> _modules;
|
||||
private readonly IProfileService _profileService;
|
||||
private bool _changedImage;
|
||||
private bool _initializing;
|
||||
private string _profileName;
|
||||
private ProfileIconViewModel _selectedIcon;
|
||||
private ProfileConfigurationIconType _selectedIconType;
|
||||
private Stream _selectedImage;
|
||||
private ProfileModuleViewModel _selectedModule;
|
||||
|
||||
public ProfileEditViewModel(ProfileConfiguration profileConfiguration, bool isNew,
|
||||
IProfileService profileService,
|
||||
IPluginManagementService pluginManagementService,
|
||||
ISidebarVmFactory sidebarVmFactory,
|
||||
IDataModelConditionsVmFactory dataModelConditionsVmFactory,
|
||||
IModelValidator<ProfileEditViewModel> validator) : base(validator)
|
||||
{
|
||||
ProfileConfiguration = profileConfiguration;
|
||||
IsNew = isNew;
|
||||
|
||||
_profileService = profileService;
|
||||
_dataModelConditionGroup = ProfileConfiguration.ActivationCondition ?? new DataModelConditionGroup(null);
|
||||
_modules = ProfileConfiguration.Module != null ? new List<Module> {ProfileConfiguration.Module} : new List<Module>();
|
||||
|
||||
IconTypes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(ProfileConfigurationIconType)));
|
||||
Icons = new BindableCollection<ProfileIconViewModel>();
|
||||
Modules = new BindableCollection<ProfileModuleViewModel>(
|
||||
pluginManagementService.GetFeaturesOfType<Module>().Where(m => !m.IsAlwaysAvailable).Select(m => new ProfileModuleViewModel(m))
|
||||
);
|
||||
Initializing = true;
|
||||
ActivationConditionViewModel = dataModelConditionsVmFactory.DataModelConditionGroupViewModel(_dataModelConditionGroup, ConditionGroupType.General, _modules);
|
||||
ActivationConditionViewModel.ConductWith(this);
|
||||
ActivationConditionViewModel.IsRootGroup = true;
|
||||
ModuleActivationRequirementsViewModel = new ModuleActivationRequirementsViewModel(sidebarVmFactory);
|
||||
ModuleActivationRequirementsViewModel.ConductWith(this);
|
||||
ModuleActivationRequirementsViewModel.SetModule(ProfileConfiguration.Module);
|
||||
|
||||
_profileName = ProfileConfiguration.Name;
|
||||
_selectedModule = Modules.FirstOrDefault(m => m.Module == ProfileConfiguration.Module);
|
||||
_selectedIconType = ProfileConfiguration.Icon.IconType;
|
||||
_selectedImage = ProfileConfiguration.Icon.FileIcon;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
Icons.AddRange(Enum.GetValues<PackIconKind>()
|
||||
.GroupBy(i => i).Select(g => g.First()).Select(i => new ProfileIconViewModel(i))
|
||||
.OrderBy(i => i.IconName)
|
||||
.ToList());
|
||||
if (IsNew)
|
||||
SelectedIcon = Icons[new Random().Next(0, Icons.Count - 1)];
|
||||
else
|
||||
SelectedIcon = Icons.FirstOrDefault(i => i.Icon.ToString() == ProfileConfiguration.Icon.MaterialIcon);
|
||||
Initializing = false;
|
||||
});
|
||||
}
|
||||
|
||||
public ProfileConfiguration ProfileConfiguration { get; }
|
||||
public bool IsNew { get; }
|
||||
public BindableCollection<ValueDescription> IconTypes { get; }
|
||||
public BindableCollection<ProfileIconViewModel> Icons { get; }
|
||||
public BindableCollection<ProfileModuleViewModel> Modules { get; }
|
||||
public bool HasUsableModules => Modules.Any();
|
||||
|
||||
public bool Initializing
|
||||
{
|
||||
get => _initializing;
|
||||
set => SetAndNotify(ref _initializing, value);
|
||||
}
|
||||
|
||||
public string ProfileName
|
||||
{
|
||||
get => _profileName;
|
||||
set => SetAndNotify(ref _profileName, value);
|
||||
}
|
||||
|
||||
public ProfileConfigurationIconType SelectedIconType
|
||||
{
|
||||
get => _selectedIconType;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _selectedIconType, value)) return;
|
||||
SelectedImage = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Stream SelectedImage
|
||||
{
|
||||
get => _selectedImage;
|
||||
set => SetAndNotify(ref _selectedImage, value);
|
||||
}
|
||||
|
||||
public ProfileIconViewModel SelectedIcon
|
||||
{
|
||||
get => _selectedIcon;
|
||||
set => SetAndNotify(ref _selectedIcon, value);
|
||||
}
|
||||
|
||||
public ProfileModuleViewModel SelectedModule
|
||||
{
|
||||
get => _selectedModule;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _selectedModule, value)) return;
|
||||
_modules.Clear();
|
||||
if (value != null)
|
||||
_modules.Add(value.Module);
|
||||
|
||||
ActivationConditionViewModel.UpdateModules();
|
||||
ModuleActivationRequirementsViewModel.SetModule(value?.Module);
|
||||
}
|
||||
}
|
||||
|
||||
public DataModelConditionGroupViewModel ActivationConditionViewModel { get; }
|
||||
public ModuleActivationRequirementsViewModel ModuleActivationRequirementsViewModel { get; }
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Session.Close(nameof(Delete));
|
||||
}
|
||||
|
||||
public async Task Accept()
|
||||
{
|
||||
await ValidateAsync();
|
||||
|
||||
if (HasErrors)
|
||||
return;
|
||||
|
||||
ProfileConfiguration.Name = ProfileName;
|
||||
ProfileConfiguration.Icon.IconType = SelectedIconType;
|
||||
ProfileConfiguration.Icon.MaterialIcon = SelectedIcon?.Icon.ToString();
|
||||
ProfileConfiguration.Icon.FileIcon = SelectedImage;
|
||||
|
||||
ProfileConfiguration.Module = SelectedModule?.Module;
|
||||
|
||||
if (_dataModelConditionGroup.Children.Any())
|
||||
ProfileConfiguration.ActivationCondition = _dataModelConditionGroup;
|
||||
|
||||
if (_changedImage)
|
||||
{
|
||||
ProfileConfiguration.Icon.FileIcon = SelectedImage;
|
||||
_profileService.SaveProfileConfigurationIcon(ProfileConfiguration);
|
||||
}
|
||||
|
||||
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||
|
||||
Session.Close(nameof(Accept));
|
||||
}
|
||||
|
||||
public void SelectBitmapFile()
|
||||
{
|
||||
VistaOpenFileDialog dialog = new()
|
||||
{
|
||||
Filter = "All Graphics Types|*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff|BMP |*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff",
|
||||
Title = "Select profile icon"
|
||||
};
|
||||
bool? result = dialog.ShowDialog();
|
||||
if (result != true)
|
||||
return;
|
||||
|
||||
_changedImage = true;
|
||||
|
||||
// TODO: Scale down to 100x100-ish
|
||||
SelectedImage = File.OpenRead(dialog.FileName);
|
||||
}
|
||||
|
||||
public void SelectSvgFile()
|
||||
{
|
||||
VistaOpenFileDialog dialog = new()
|
||||
{
|
||||
Filter = "Scalable Vector Graphics|*.svg",
|
||||
Title = "Select profile icon"
|
||||
};
|
||||
bool? result = dialog.ShowDialog();
|
||||
if (result != true)
|
||||
return;
|
||||
|
||||
_changedImage = true;
|
||||
SelectedImage = File.OpenRead(dialog.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
public class ProfileEditViewModelValidator : AbstractValidator<ProfileEditViewModel>
|
||||
{
|
||||
public ProfileEditViewModelValidator()
|
||||
{
|
||||
RuleFor(m => m.ProfileName).NotEmpty().WithMessage("Profile name may not be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using MaterialDesignThemes.Wpf;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
{
|
||||
public class ProfileIconViewModel
|
||||
{
|
||||
public ProfileIconViewModel(PackIconKind icon)
|
||||
{
|
||||
Icon = icon;
|
||||
IconName = icon.ToString();
|
||||
}
|
||||
|
||||
public PackIconKind Icon { get; }
|
||||
public string IconName { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Artemis.Core.Modules;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
{
|
||||
public class ProfileModuleViewModel : PropertyChangedBase
|
||||
{
|
||||
public ProfileModuleViewModel(Module module)
|
||||
{
|
||||
Module = module;
|
||||
Icon = module.DisplayIcon;
|
||||
Name = module.DisplayName;
|
||||
Description = module.Info.Description;
|
||||
}
|
||||
|
||||
public string Icon { get; }
|
||||
public string Name { get; }
|
||||
public string Description { get; }
|
||||
|
||||
public Module Module { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Sidebar.Dialogs.SidebarCategoryCreateView"
|
||||
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="280"
|
||||
Width="300">
|
||||
<StackPanel Margin="16">
|
||||
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}">
|
||||
Add a new category
|
||||
</TextBlock>
|
||||
|
||||
<TextBox materialDesign:HintAssist.Hint="Category name"
|
||||
Margin="0 16 0 8"
|
||||
Style="{StaticResource MaterialDesignFilledTextBox}"
|
||||
Text="{Binding CategoryName, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 8 0 0">
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Command="{s:Action Cancel}">
|
||||
CANCEL
|
||||
</Button>
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Command="{s:Action Accept}">
|
||||
ACCEPT
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Artemis.UI.Screens.ProfileEditor.Dialogs;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using FluentValidation;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs
|
||||
{
|
||||
public class SidebarCategoryCreateViewModel : DialogViewModelBase
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private string _categoryName;
|
||||
|
||||
public SidebarCategoryCreateViewModel(IProfileService profileService, IModelValidator<SidebarCategoryCreateViewModel> validator) : base(validator)
|
||||
{
|
||||
_profileService = profileService;
|
||||
}
|
||||
|
||||
public string CategoryName
|
||||
{
|
||||
get => _categoryName;
|
||||
set => SetAndNotify(ref _categoryName, value);
|
||||
}
|
||||
|
||||
public async Task Accept()
|
||||
{
|
||||
await ValidateAsync();
|
||||
|
||||
if (HasErrors)
|
||||
return;
|
||||
|
||||
Session.Close(_profileService.CreateProfileCategory(CategoryName));
|
||||
}
|
||||
}
|
||||
|
||||
public class SidebarCategoryCreateViewModelValidator : AbstractValidator<SidebarCategoryCreateViewModel>
|
||||
{
|
||||
private readonly IProfileCategoryRepository _profileCategoryRepository;
|
||||
|
||||
public SidebarCategoryCreateViewModelValidator(IProfileCategoryRepository profileCategoryRepository)
|
||||
{
|
||||
_profileCategoryRepository = profileCategoryRepository;
|
||||
|
||||
RuleFor(m => m.CategoryName)
|
||||
.NotEmpty().WithMessage("Category name may not be empty")
|
||||
.Must(BeUniqueCategory).WithMessage("Category name already taken");
|
||||
}
|
||||
|
||||
private bool BeUniqueCategory(SidebarCategoryCreateViewModel viewModel, string categoryName)
|
||||
{
|
||||
return _profileCategoryRepository.IsUnique(categoryName, null) == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Sidebar.Dialogs.SidebarCategoryUpdateView"
|
||||
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.Sidebar.Dialogs"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="280"
|
||||
Width="300">
|
||||
<StackPanel Margin="16" >
|
||||
<TextBlock Style="{StaticResource MaterialDesignHeadline6TextBlock}">
|
||||
Update category
|
||||
</TextBlock>
|
||||
|
||||
<TextBox materialDesign:HintAssist.Hint="Category name"
|
||||
Margin="0 16 0 8"
|
||||
Style="{StaticResource MaterialDesignFilledTextBox}"
|
||||
Text="{Binding CategoryName, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
<Grid Margin="0 8 0 0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Grid.Column="0"
|
||||
HorizontalAlignment="Left"
|
||||
Style="{StaticResource MaterialDesignFlatAccentButton}"
|
||||
Command="{s:Action Delete}">
|
||||
DELETE
|
||||
</Button>
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Command="{s:Action Cancel}">
|
||||
CANCEL
|
||||
</Button>
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Command="{s:Action Accept}">
|
||||
ACCEPT
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using FluentValidation;
|
||||
using Stylet;
|
||||
using WinRT.Interop;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs
|
||||
{
|
||||
public class SidebarCategoryUpdateViewModel : DialogViewModelBase
|
||||
{
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IProfileService _profileService;
|
||||
private string _categoryName;
|
||||
|
||||
public SidebarCategoryUpdateViewModel(ProfileCategory profileCategory, IProfileService profileService, IDialogService dialogService,
|
||||
IModelValidator<SidebarCategoryUpdateViewModel> validator) : base(validator)
|
||||
{
|
||||
_categoryName = profileCategory.Name;
|
||||
_profileService = profileService;
|
||||
_dialogService = dialogService;
|
||||
|
||||
ProfileCategory = profileCategory;
|
||||
}
|
||||
|
||||
public ProfileCategory ProfileCategory { get; }
|
||||
|
||||
public string CategoryName
|
||||
{
|
||||
get => _categoryName;
|
||||
set => SetAndNotify(ref _categoryName, value);
|
||||
}
|
||||
|
||||
public async Task Accept()
|
||||
{
|
||||
await ValidateAsync();
|
||||
|
||||
if (HasErrors)
|
||||
return;
|
||||
|
||||
ProfileCategory.Name = CategoryName;
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
|
||||
Session.Close(nameof(Accept));
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Session.Close(nameof(Delete));
|
||||
}
|
||||
}
|
||||
|
||||
public class SidebarCategoryUpdateViewModelValidator : AbstractValidator<SidebarCategoryUpdateViewModel>
|
||||
{
|
||||
private readonly IProfileCategoryRepository _profileCategoryRepository;
|
||||
|
||||
public SidebarCategoryUpdateViewModelValidator(IProfileCategoryRepository profileCategoryRepository)
|
||||
{
|
||||
_profileCategoryRepository = profileCategoryRepository;
|
||||
|
||||
RuleFor(m => m.CategoryName)
|
||||
.NotEmpty().WithMessage("Category name may not be empty")
|
||||
.Must(BeUniqueCategory).WithMessage("Category name already taken");
|
||||
}
|
||||
|
||||
private bool BeUniqueCategory(SidebarCategoryUpdateViewModel viewModel, string categoryName)
|
||||
{
|
||||
return _profileCategoryRepository.IsUnique(categoryName, viewModel.ProfileCategory.EntityId) == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<UserControl
|
||||
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.Sidebar"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:dd="urn:gong-wpf-dragdrop"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:behaviors="clr-namespace:Artemis.UI.Behaviors"
|
||||
x:Class="Artemis.UI.Screens.Sidebar.SidebarCategoryView"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type local:SidebarCategoryViewModel}}">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="ArtemisSidebar.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid Margin="0 8 0 0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="0" Background="Transparent">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ToggleButton Grid.Column="0"
|
||||
x:Name="Expander"
|
||||
Foreground="{DynamicResource MaterialDesignBody}"
|
||||
Style="{StaticResource MaterialDesignExpandCollapseToggleStyle}"
|
||||
IsChecked="{Binding ShowItems}"
|
||||
ClickMode="Press"
|
||||
Margin="5 0" />
|
||||
<TextBlock Grid.Column="1"
|
||||
Padding="0 5"
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding ProfileCategory.Name}"
|
||||
MouseLeftButtonUp="{s:Action OnMouseLeftButtonUp}">
|
||||
<TextBlock.Style>
|
||||
<Style>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsSuspended}" Value="True">
|
||||
<DataTrigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.33" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.EnterActions>
|
||||
<DataTrigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.ExitActions>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
|
||||
<Border Grid.Column="1" BorderThickness="1" BorderBrush="{DynamicResource MaterialDesignBody}" Height="1" Opacity="0">
|
||||
<Border.Style>
|
||||
<Style>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsSuspended}" Value="True">
|
||||
<DataTrigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.75" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.EnterActions>
|
||||
<DataTrigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.ExitActions>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
|
||||
<Button Grid.Column="2"
|
||||
ToolTip="Edit category"
|
||||
Width="26"
|
||||
Height="26"
|
||||
Command="{s:Action UpdateCategory}"
|
||||
HorizontalAlignment="Right">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignIconForegroundButton}">
|
||||
<Setter Property="Visibility" Value="Hidden" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type Grid}, Mode=FindAncestor}}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
<materialDesign:PackIcon Kind="Cog" Width="16" Height="16" />
|
||||
</Button>
|
||||
<ToggleButton Grid.Column="3" ToolTip="Suspend profile" Width="18" Height="18" Margin="2 0 0 0" IsChecked="{Binding IsSuspended}">
|
||||
<ToggleButton.Style>
|
||||
<Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignFlatToggleButton}">
|
||||
<Setter Property="Visibility" Value="Hidden" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type Grid}, Mode=FindAncestor}}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ToggleButton.Style>
|
||||
<materialDesign:PackIcon Kind="Pause" Height="14" Width="14" />
|
||||
</ToggleButton>
|
||||
|
||||
|
||||
<materialDesign:PopupBox Grid.Column="4"
|
||||
PlacementMode="BottomAndAlignCentres"
|
||||
ToolTip="Add profile"
|
||||
Margin="0 0 10 0">
|
||||
<materialDesign:PopupBox.Style>
|
||||
<Style TargetType="{x:Type materialDesign:PopupBox}">
|
||||
<Setter Property="Visibility" Value="Hidden" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type Grid}, Mode=FindAncestor}}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</materialDesign:PopupBox.Style>
|
||||
<materialDesign:PopupBox.ToggleContent>
|
||||
<materialDesign:PackIcon Kind="Plus" Width="20" Height="20" Foreground="{DynamicResource MaterialDesignBody}" />
|
||||
</materialDesign:PopupBox.ToggleContent>
|
||||
<StackPanel>
|
||||
<Button Command="{s:Action AddProfile}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="Plus" VerticalAlignment="Center" Margin="0 0 5 0" />
|
||||
<TextBlock VerticalAlignment="Center"> Add new profile</TextBlock>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Command="{s:Action ImportProfile}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="Import" VerticalAlignment="Center" Margin="0 0 5 0" />
|
||||
<TextBlock VerticalAlignment="Center">Import existing profile</TextBlock>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</materialDesign:PopupBox>
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="1">
|
||||
<Border.Resources>
|
||||
<DataTemplate x:Key="ProfileDragTemplate" DataType="{x:Type local:SidebarProfileConfigurationViewModel}">
|
||||
<Border Background="{DynamicResource MaterialDesignDivider}" Padding="10" CornerRadius="4">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<shared:ProfileConfigurationIcon ConfigurationIcon="{Binding ProfileConfiguration.Icon}"
|
||||
Width="20"
|
||||
Height="20"
|
||||
Margin="0 0 10 0"
|
||||
Foreground="{DynamicResource MaterialDesignBody}" />
|
||||
<TextBlock Text="{Binding ProfileConfiguration.Name}" VerticalAlignment="Center" Foreground="{DynamicResource MaterialDesignBody}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</Border.Resources>
|
||||
<ListBox ItemsSource="{Binding Items}"
|
||||
SelectedItem="{Binding SelectedProfileConfiguration}"
|
||||
MinHeight="10"
|
||||
PreviewMouseRightButtonDown="UIElement_OnPreviewMouseRightButtonDown"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled"
|
||||
dd:DragDrop.IsDragSource="True"
|
||||
dd:DragDrop.IsDropTarget="True"
|
||||
dd:DragDrop.DropHandler="{Binding}"
|
||||
dd:DragDrop.DragAdornerTemplate="{StaticResource ProfileDragTemplate}">
|
||||
<ListBox.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Paste" Command="{s:Action Paste}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentPaste" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</ListBox.ContextMenu>
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource SidebarListBoxItem}" />
|
||||
</ListBox.ItemContainerStyle>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SidebarCategoryView.xaml
|
||||
/// </summary>
|
||||
public partial class SidebarCategoryView : UserControl
|
||||
{
|
||||
public SidebarCategoryView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void UIElement_OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
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.Extensions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Sidebar.Dialogs;
|
||||
using Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using GongSolutions.Wpf.DragDrop;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using MaterialDesignThemes.Wpf.Transitions;
|
||||
using Newtonsoft.Json;
|
||||
using Ookii.Dialogs.Wpf;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarCategoryViewModel : Conductor<SidebarProfileConfigurationViewModel>.Collection.AllActive, IDropTarget
|
||||
{
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly ISidebarVmFactory _vmFactory;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IProfileService _profileService;
|
||||
private SidebarProfileConfigurationViewModel _selectedProfileConfiguration;
|
||||
private bool _showItems;
|
||||
private readonly DefaultDropHandler _defaultDropHandler;
|
||||
private bool _addingProfile;
|
||||
|
||||
public SidebarCategoryViewModel(ProfileCategory profileCategory,
|
||||
IProfileService profileService,
|
||||
IDialogService dialogService,
|
||||
ISidebarVmFactory vmFactory,
|
||||
IEventAggregator eventAggregator)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_dialogService = dialogService;
|
||||
_vmFactory = vmFactory;
|
||||
_eventAggregator = eventAggregator;
|
||||
_showItems = !profileCategory.IsCollapsed;
|
||||
_defaultDropHandler = new DefaultDropHandler();
|
||||
|
||||
ProfileCategory = profileCategory;
|
||||
}
|
||||
|
||||
public ProfileCategory ProfileCategory { get; }
|
||||
|
||||
public bool ShowItems
|
||||
{
|
||||
get => _showItems;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _showItems, value)) return;
|
||||
|
||||
if (value)
|
||||
CreateProfileViewModels();
|
||||
else
|
||||
Items.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSuspended
|
||||
{
|
||||
get => ProfileCategory.IsSuspended;
|
||||
set
|
||||
{
|
||||
ProfileCategory.IsSuspended = value;
|
||||
NotifyOfPropertyChange(nameof(IsSuspended));
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
}
|
||||
}
|
||||
|
||||
public SidebarProfileConfigurationViewModel SelectedProfileConfiguration
|
||||
{
|
||||
get => _selectedProfileConfiguration;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _selectedProfileConfiguration, value)) return;
|
||||
if (value == null) return;
|
||||
try
|
||||
{
|
||||
((SidebarViewModel) Parent).SelectProfileConfiguration(value.ProfileConfiguration);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_dialogService.ShowExceptionDialog("Failed select profile", e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateCategory()
|
||||
{
|
||||
object result = await _dialogService.ShowDialog<SidebarCategoryUpdateViewModel>(new Dictionary<string, object> {{"profileCategory", ProfileCategory}});
|
||||
if (result is nameof(SidebarCategoryUpdateViewModel.Delete))
|
||||
await DeleteCategory();
|
||||
}
|
||||
|
||||
public async Task DeleteCategory()
|
||||
{
|
||||
bool confirmed = await _dialogService.ShowConfirmDialog(
|
||||
"Delete category",
|
||||
"Are you sure you want to delete this category?\r\nAll profiles will be deleted too."
|
||||
);
|
||||
if (!confirmed)
|
||||
return;
|
||||
|
||||
// Close the editor first by heading to Home if any of the profiles are being edited
|
||||
if (ProfileCategory.ProfileConfigurations.Any(p => p.IsBeingEdited))
|
||||
_eventAggregator.Publish(new RequestSelectSidebarItemEvent("Home"));
|
||||
|
||||
_profileService.DeleteProfileCategory(ProfileCategory);
|
||||
((SidebarViewModel) Parent).RemoveProfileCategoryViewModel(this);
|
||||
}
|
||||
|
||||
public void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
ShowItems = !ShowItems;
|
||||
}
|
||||
|
||||
public async Task AddProfile()
|
||||
{
|
||||
try
|
||||
{
|
||||
_addingProfile = true;
|
||||
ProfileConfiguration profileConfiguration = _profileService.CreateProfileConfiguration(ProfileCategory, "New profile", Enum.GetValues<PackIconKind>().First().ToString());
|
||||
object result = await _dialogService.ShowDialog<ProfileEditViewModel>(new Dictionary<string, object>
|
||||
{
|
||||
{"profileConfiguration", profileConfiguration},
|
||||
{"isNew", true}
|
||||
});
|
||||
if (result is nameof(ProfileEditViewModel.Accept))
|
||||
{
|
||||
if (!ShowItems)
|
||||
ShowItems = true;
|
||||
else
|
||||
CreateProfileViewModels();
|
||||
}
|
||||
else
|
||||
_profileService.RemoveProfileConfiguration(profileConfiguration);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_addingProfile = false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ImportProfile()
|
||||
{
|
||||
VistaOpenFileDialog dialog = new()
|
||||
{
|
||||
Filter = "Artemis Profile|*.json",
|
||||
Title = "Export Artemis profile"
|
||||
};
|
||||
bool? result = dialog.ShowDialog();
|
||||
if (result != true)
|
||||
return;
|
||||
|
||||
string json = await File.ReadAllTextAsync(dialog.FileName);
|
||||
try
|
||||
{
|
||||
ProfileConfigurationExportModel profileConfigurationExportModel = JsonConvert.DeserializeObject<ProfileConfigurationExportModel>(json, IProfileService.ExportSettings);
|
||||
if (profileConfigurationExportModel == null)
|
||||
{
|
||||
await _dialogService.ShowConfirmDialog("Import profile", "Failed to import this profile, make sure it is a valid Artemis profile.", "Confirm", null);
|
||||
return;
|
||||
}
|
||||
|
||||
_profileService.ImportProfile(ProfileCategory, profileConfigurationExportModel);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _dialogService.ShowConfirmDialog("Import profile", $"Failed to import this profile, make sure it is a valid Artemis profile.\r\n{e.Message}", "Confirm", null);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateProfileViewModels()
|
||||
{
|
||||
Items.Clear();
|
||||
foreach (ProfileConfiguration profileConfiguration in ProfileCategory.ProfileConfigurations.OrderBy(p => p.Order))
|
||||
Items.Add(_vmFactory.SidebarProfileConfigurationViewModel(profileConfiguration));
|
||||
|
||||
SelectedProfileConfiguration = Items.FirstOrDefault(i => i.ProfileConfiguration.IsBeingEdited);
|
||||
}
|
||||
|
||||
private void ProfileCategoryOnProfileConfigurationRemoved(object sender, ProfileConfigurationEventArgs e)
|
||||
{
|
||||
if (!_addingProfile && ShowItems)
|
||||
{
|
||||
Items.Remove(Items.FirstOrDefault(i => i.ProfileConfiguration == e.ProfileConfiguration));
|
||||
((BindableCollection<SidebarProfileConfigurationViewModel>) Items).Sort(p => p.ProfileConfiguration.Order);
|
||||
}
|
||||
|
||||
SelectedProfileConfiguration = Items.FirstOrDefault(i => i.ProfileConfiguration.IsBeingEdited);
|
||||
}
|
||||
|
||||
private void ProfileCategoryOnProfileConfigurationAdded(object sender, ProfileConfigurationEventArgs e)
|
||||
{
|
||||
if (!_addingProfile && ShowItems)
|
||||
{
|
||||
Items.Add(_vmFactory.SidebarProfileConfigurationViewModel(e.ProfileConfiguration));
|
||||
((BindableCollection<SidebarProfileConfigurationViewModel>) Items).Sort(p => p.ProfileConfiguration.Order);
|
||||
}
|
||||
|
||||
SelectedProfileConfiguration = Items.FirstOrDefault(i => i.ProfileConfiguration.IsBeingEdited);
|
||||
}
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
#region Overrides of AllActive
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnActivate()
|
||||
{
|
||||
CreateProfileViewModels();
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
ProfileCategory.ProfileConfigurationAdded += ProfileCategoryOnProfileConfigurationAdded;
|
||||
ProfileCategory.ProfileConfigurationRemoved += ProfileCategoryOnProfileConfigurationRemoved;
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnClose()
|
||||
{
|
||||
ProfileCategory.ProfileConfigurationAdded -= ProfileCategoryOnProfileConfigurationAdded;
|
||||
ProfileCategory.ProfileConfigurationRemoved -= ProfileCategoryOnProfileConfigurationRemoved;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IDropTarget
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DragOver(IDropInfo dropInfo)
|
||||
{
|
||||
_defaultDropHandler.DragOver(dropInfo);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Drop(IDropInfo dropInfo)
|
||||
{
|
||||
if (dropInfo.Data is not SidebarProfileConfigurationViewModel sourceItem)
|
||||
return;
|
||||
if (dropInfo.Data == dropInfo.TargetItem)
|
||||
return;
|
||||
|
||||
SidebarCategoryViewModel sourceCategory = (SidebarCategoryViewModel) sourceItem.Parent;
|
||||
SidebarCategoryViewModel targetCategory = (SidebarCategoryViewModel) ((FrameworkElement) dropInfo.VisualTarget).DataContext;
|
||||
|
||||
int targetIndex = 0;
|
||||
if (dropInfo.TargetItem is SidebarProfileConfigurationViewModel targetItem)
|
||||
{
|
||||
if (dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.BeforeTargetItem))
|
||||
targetIndex = targetCategory.Items.IndexOf(targetItem);
|
||||
else
|
||||
targetIndex = targetCategory.Items.IndexOf(targetItem) + 1;
|
||||
}
|
||||
|
||||
targetCategory.ProfileCategory.AddProfileConfiguration(sourceItem.ProfileConfiguration, targetIndex);
|
||||
|
||||
if (sourceCategory != targetCategory)
|
||||
_profileService.SaveProfileCategory(sourceCategory.ProfileCategory);
|
||||
_profileService.SaveProfileCategory(targetCategory.ProfileCategory);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Sidebar.SidebarProfileConfigurationView"
|
||||
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.Sidebar"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:SidebarProfileConfigurationViewModel}"
|
||||
Background="Transparent"
|
||||
Margin="-8"
|
||||
Padding="8">
|
||||
<!-- Above is a dumb hack to get the context menu to cover the entire item -->
|
||||
<UserControl.Resources>
|
||||
<shared:StreamToBitmapImageConverter x:Key="StreamToBitmapImageConverter" />
|
||||
</UserControl.Resources>
|
||||
<UserControl.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="View properties" Command="{s:Action ViewProperties}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Cog" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Suspend" IsCheckable="True" IsChecked="{Binding IsSuspended}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Pause" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Suspend all">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Pause" />
|
||||
</MenuItem.Icon>
|
||||
<MenuItem Header="Above" Command="{s:Action SuspendAbove}" CommandParameter="suspend" />
|
||||
<MenuItem Header="Below" Command="{s:Action SuspendBelow}" CommandParameter="suspend" />
|
||||
</MenuItem>
|
||||
<MenuItem Header="Resume all">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Play" />
|
||||
</MenuItem.Icon>
|
||||
<MenuItem Header="Above" Command="{s:Action SuspendAbove}" CommandParameter="resume" />
|
||||
<MenuItem Header="Below" Command="{s:Action SuspendBelow}" CommandParameter="resume" />
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Export" Command="{s:Action Export}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Export" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Duplicate" Command="{s:Action Duplicate}" >
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentDuplicate" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Copy" Command="{s:Action Copy}" >
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentCopy" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Paste" Command="{s:Action Paste}" >
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="ContentPaste" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Delete" Command="{s:Action Delete}" InputGestureText="Del">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="TrashCan" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</UserControl.ContextMenu>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<shared:ProfileConfigurationIcon Grid.Column="0" VerticalAlignment="Center" ConfigurationIcon="{Binding ProfileConfiguration.Icon}" Width="20" Height="20">
|
||||
<shared:ProfileConfigurationIcon.Style>
|
||||
<Style>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsProfileActive}" Value="False">
|
||||
<DataTrigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.33" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.EnterActions>
|
||||
<DataTrigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.ExitActions>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</shared:ProfileConfigurationIcon.Style>
|
||||
</shared:ProfileConfigurationIcon>
|
||||
|
||||
<TextBlock Grid.Column="1" FontSize="12" Margin="10 0 0 0" VerticalAlignment="Center" Text="{Binding ProfileConfiguration.Name}">
|
||||
<TextBlock.Style>
|
||||
<Style>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsProfileActive}" Value="False">
|
||||
<DataTrigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.33" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.EnterActions>
|
||||
<DataTrigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.ExitActions>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
|
||||
<Border Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="1" BorderBrush="{DynamicResource MaterialDesignBody}" Height="1" Opacity="0">
|
||||
<Border.Style>
|
||||
<Style>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsSuspended}" Value="True">
|
||||
<DataTrigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.75" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.EnterActions>
|
||||
<DataTrigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.ExitActions>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
|
||||
<Button Grid.Column="2" ToolTip="View properties" Width="20" Height="20" Command="{s:Action ViewProperties}" HorizontalAlignment="Right">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignIconForegroundButton}">
|
||||
<Setter Property="Visibility" Value="Hidden" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
<materialDesign:PackIcon Kind="Cog" Width="16" Height="16" />
|
||||
</Button>
|
||||
<ToggleButton Grid.Column="3" ToolTip="Suspend profile" Width="18" Height="18" Margin="2 0 0 0" IsChecked="{Binding IsSuspended}">
|
||||
<ToggleButton.Style>
|
||||
<Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignFlatToggleButton}">
|
||||
<Setter Property="Visibility" Value="Hidden" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ToggleButton.Style>
|
||||
<materialDesign:PackIcon Kind="Pause" Height="14" Width="14" />
|
||||
</ToggleButton>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,165 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Newtonsoft.Json;
|
||||
using Ookii.Dialogs.Wpf;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarProfileConfigurationViewModel : Screen
|
||||
{
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IProfileService _profileService;
|
||||
|
||||
public SidebarProfileConfigurationViewModel(ProfileConfiguration profileConfiguration,
|
||||
IProfileService profileService,
|
||||
IDialogService dialogService,
|
||||
IEventAggregator eventAggregator)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_dialogService = dialogService;
|
||||
_eventAggregator = eventAggregator;
|
||||
ProfileConfiguration = profileConfiguration;
|
||||
}
|
||||
|
||||
public ProfileConfiguration ProfileConfiguration { get; }
|
||||
|
||||
public bool IsProfileActive => ProfileConfiguration.Profile != null;
|
||||
|
||||
public bool IsSuspended
|
||||
{
|
||||
get => ProfileConfiguration.IsSuspended;
|
||||
set
|
||||
{
|
||||
ProfileConfiguration.IsSuspended = value;
|
||||
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ViewProperties()
|
||||
{
|
||||
object result = await _dialogService.ShowDialog<ProfileEditViewModel>(new Dictionary<string, object>
|
||||
{
|
||||
{"profileConfiguration", ProfileConfiguration},
|
||||
{"isNew", false}
|
||||
});
|
||||
|
||||
if (result is nameof(ProfileEditViewModel.Delete))
|
||||
await Delete();
|
||||
}
|
||||
|
||||
public void SuspendAbove(string action)
|
||||
{
|
||||
foreach (ProfileConfiguration profileConfiguration in ProfileConfiguration.Category.ProfileConfigurations.OrderBy(p => p.Order).TakeWhile(c => c != ProfileConfiguration))
|
||||
{
|
||||
if (profileConfiguration != ProfileConfiguration)
|
||||
profileConfiguration.IsSuspended = action == "suspend";
|
||||
}
|
||||
}
|
||||
|
||||
public void SuspendBelow(string action)
|
||||
{
|
||||
foreach (ProfileConfiguration profileConfiguration in ProfileConfiguration.Category.ProfileConfigurations.OrderBy(p => p.Order).SkipWhile(c => c != ProfileConfiguration))
|
||||
{
|
||||
if (profileConfiguration != ProfileConfiguration)
|
||||
profileConfiguration.IsSuspended = action == "suspend";
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Export()
|
||||
{
|
||||
string filename = new string(ProfileConfiguration.Name.Select(ch => Path.GetInvalidFileNameChars().Contains(ch) ? '_' : ch).ToArray()) + ".json";
|
||||
VistaSaveFileDialog dialog = new()
|
||||
{
|
||||
Filter = "Artemis Profile|*.json",
|
||||
Title = "Export Artemis profile",
|
||||
FileName = filename
|
||||
};
|
||||
bool? result = dialog.ShowDialog();
|
||||
if (result != true)
|
||||
return;
|
||||
|
||||
ProfileConfigurationExportModel profileConfigurationExportModel = _profileService.ExportProfile(ProfileConfiguration);
|
||||
string json = JsonConvert.SerializeObject(profileConfigurationExportModel, IProfileService.ExportSettings);
|
||||
|
||||
if (!dialog.FileName.EndsWith(".json"))
|
||||
dialog.FileName += ".json";
|
||||
await File.WriteAllTextAsync(dialog.FileName, json);
|
||||
}
|
||||
|
||||
public void Duplicate()
|
||||
{
|
||||
ProfileConfigurationExportModel export = _profileService.ExportProfile(ProfileConfiguration);
|
||||
_profileService.ImportProfile(ProfileConfiguration.Category, export, true, false, "copy");
|
||||
}
|
||||
|
||||
public void Copy()
|
||||
{
|
||||
JsonClipboard.SetObject(_profileService.ExportProfile(ProfileConfiguration));
|
||||
}
|
||||
|
||||
public void Paste()
|
||||
{
|
||||
ProfileConfigurationExportModel profileConfiguration = JsonClipboard.GetData<ProfileConfigurationExportModel>();
|
||||
if (profileConfiguration == null)
|
||||
return;
|
||||
|
||||
_profileService.ImportProfile(ProfileConfiguration.Category, profileConfiguration, true, false, "copy");
|
||||
}
|
||||
|
||||
public async Task Delete()
|
||||
{
|
||||
if (await _dialogService.ShowConfirmDialog("Delete profile", "Are you sure you want to delete this profile?\r\nThis cannot be undone."))
|
||||
{
|
||||
// Close the editor first by heading to Home if the profile is being edited
|
||||
if (ProfileConfiguration.IsBeingEdited)
|
||||
_eventAggregator.Publish(new RequestSelectSidebarItemEvent("Home"));
|
||||
|
||||
_profileService.RemoveProfileConfiguration(ProfileConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnActivate()
|
||||
{
|
||||
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
|
||||
ProfileConfiguration.PropertyChanged += ProfileConfigurationOnPropertyChanged;
|
||||
NotifyOfPropertyChange(nameof(IsProfileActive));
|
||||
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnDeactivate()
|
||||
{
|
||||
ProfileConfiguration.PropertyChanged -= ProfileConfigurationOnPropertyChanged;
|
||||
base.OnDeactivate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void ProfileConfigurationOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(ProfileConfiguration.Profile))
|
||||
NotifyOfPropertyChange(nameof(IsProfileActive));
|
||||
if (e.PropertyName == nameof(ProfileConfiguration.IsSuspended))
|
||||
NotifyOfPropertyChange(nameof(IsSuspended));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Sidebar.SidebarScreenView"
|
||||
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.Sidebar"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:SidebarScreenViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<materialDesign:PackIcon Kind="{Binding Icon}" Width="16" Height="16" />
|
||||
<TextBlock FontSize="12" Margin="10 0" VerticalAlignment="Center" Text="{Binding DisplayName}" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,31 @@
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Ninject;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarScreenViewModel<T> : SidebarScreenViewModel where T : Screen
|
||||
{
|
||||
public SidebarScreenViewModel(PackIconKind icon, string displayName) : base(icon, displayName)
|
||||
{
|
||||
}
|
||||
|
||||
public override Screen CreateInstance(IKernel kernel)
|
||||
{
|
||||
return kernel.Get<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SidebarScreenViewModel
|
||||
{
|
||||
protected SidebarScreenViewModel(PackIconKind icon, string displayName)
|
||||
{
|
||||
Icon = icon;
|
||||
DisplayName = displayName;
|
||||
}
|
||||
|
||||
public abstract Screen CreateInstance(IKernel kernel);
|
||||
public PackIconKind Icon { get; }
|
||||
public string DisplayName { get; }
|
||||
}
|
||||
}
|
||||
@@ -4,56 +4,163 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:sidebar="clr-namespace:Artemis.UI.Screens.Sidebar"
|
||||
xmlns:controls="clr-namespace:MaterialDesignExtensions.Controls;assembly=MaterialDesignExtensions"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:dd="urn:gong-wpf-dragdrop"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance sidebar:SidebarViewModel}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="ArtemisSidebar.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<materialDesign:DialogHost IsTabStop="False" Focusable="False" Identifier="SidebarDialog" DialogTheme="Inherit" DialogMargin="14">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="60" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Image Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Source="/Resources/Images/Sidebar/sidebar-header.png"
|
||||
Stretch="UniformToFill"
|
||||
VerticalAlignment="Top" Height="120" />
|
||||
<Grid Grid.Row="0" ClipToBounds="True">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<ToggleButton Grid.Row="0"
|
||||
Style="{StaticResource MaterialDesignSwitchLightToggleButton}"
|
||||
ToolTip="Pin sidebar"
|
||||
HorizontalAlignment="Right"
|
||||
IsChecked="{Binding PinSidebar.Value, Delay=300}"
|
||||
Margin="10 0">
|
||||
<materialDesign:PackIcon Kind="Pin" RenderTransformOrigin=".5,.5">
|
||||
<materialDesign:PackIcon.RenderTransform>
|
||||
<RotateTransform Angle="45" />
|
||||
</materialDesign:PackIcon.RenderTransform>
|
||||
</materialDesign:PackIcon>
|
||||
<materialDesign:ToggleButtonAssist.OnContent>
|
||||
<materialDesign:PackIcon Kind="Pin" />
|
||||
</materialDesign:ToggleButtonAssist.OnContent>
|
||||
</ToggleButton>
|
||||
<shared:DeviceVisualizer Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Device="{Binding HeaderDevice}"
|
||||
ShowColors="True"
|
||||
RenderTransformOrigin="0.5 0.5"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
RenderOptions.BitmapScalingMode="HighQuality">
|
||||
<shared:DeviceVisualizer.RenderTransform>
|
||||
<TransformGroup>
|
||||
<RotateTransform Angle="20" />
|
||||
<ScaleTransform ScaleX="2" ScaleY="2" />
|
||||
</TransformGroup>
|
||||
</shared:DeviceVisualizer.RenderTransform>
|
||||
</shared:DeviceVisualizer>
|
||||
<Rectangle Grid.Column="0" Grid.ColumnSpan="2" Height="60" VerticalAlignment="Bottom">
|
||||
<Rectangle.Fill>
|
||||
<LinearGradientBrush StartPoint="0,1" EndPoint="0,0">
|
||||
<GradientStop Color="{Binding Path=Color, Source={StaticResource MaterialDesignToolBarBackground}}" Offset="0" /> <!-- TODO: Get the color from MaterialDesign -->
|
||||
<GradientStop Color="#00000000" Offset="1" />
|
||||
</LinearGradientBrush>
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
<Image Grid.Column="0" Source="{svgc:SvgImage Source=/Resources/Images/Logo/bow.svg}" Height="35" Width="35" Margin="10" />
|
||||
<TextBlock Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
|
||||
Foreground="{DynamicResource MaterialDesignDarkForeground}">
|
||||
Artemis 2
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
|
||||
<TextBlock Grid.Row="1"
|
||||
Style="{StaticResource MaterialDesignHeadline6TextBlock}"
|
||||
Foreground="{StaticResource PrimaryHueDarkForegroundBrush}"
|
||||
Margin="15"
|
||||
materialDesign:ShadowAssist.ShadowDepth="Depth1"
|
||||
Text="{Binding ActiveModules}"
|
||||
VerticalAlignment="Bottom" />
|
||||
<!-- Built-in screens -->
|
||||
<ListBox Grid.Row="1"
|
||||
Margin="0 2"
|
||||
ItemContainerStyle="{StaticResource SidebarListBoxItem}"
|
||||
ItemsSource="{Binding SidebarScreens}"
|
||||
SelectedItem="{Binding SelectedSidebarScreen}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Separator Grid.Row="2" Margin="8" />
|
||||
|
||||
<controls:SideNavigation Grid.Row="3"
|
||||
Items="{Binding SidebarItems}"
|
||||
SelectedItem="{Binding SelectedItem}"
|
||||
WillSelectNavigationItemCommand="{s:Action SelectItem}"
|
||||
materialDesign:RippleAssist.Feedback="{StaticResource SecondaryHueMidBrush}"
|
||||
Margin="0 5 0 0" />
|
||||
</Grid>
|
||||
<!-- Categories -->
|
||||
<ScrollViewer Grid.Row="3" VerticalScrollBarVisibility="Auto">
|
||||
<ScrollViewer.Resources>
|
||||
<Style TargetType="ScrollBar" BasedOn="{StaticResource MaterialDesignScrollBarMinimal}" />
|
||||
</ScrollViewer.Resources>
|
||||
<StackPanel>
|
||||
<StackPanel.Resources>
|
||||
<DataTemplate x:Key="CategoryDragTemplate" DataType="{x:Type sidebar:SidebarCategoryViewModel}">
|
||||
<DataTemplate.Resources>
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</DataTemplate.Resources>
|
||||
<Border Background="{DynamicResource MaterialDesignTextFieldBoxHoverBackground}"
|
||||
Padding="10"
|
||||
CornerRadius="4"
|
||||
Visibility="{Binding Path=ProfileCategory, FallbackValue=null, Converter={StaticResource NullToVisibilityConverter}}">
|
||||
<TextBlock Text="{Binding ProfileCategory.Name,TargetNullValue='Oops, I am missing'}" VerticalAlignment="Center" Foreground="{DynamicResource MaterialDesignBody}" />
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</StackPanel.Resources>
|
||||
<ItemsControl ItemsSource="{Binding Items}"
|
||||
dd:DragDrop.IsDragSource="True"
|
||||
dd:DragDrop.IsDropTarget="True"
|
||||
dd:DragDrop.DragAdornerTemplate="{StaticResource CategoryDragTemplate}"
|
||||
dd:DragDrop.DropHandler="{Binding}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Content="ADD NEW CATEGORY" Margin="10 10 10 0" Command="{s:Action AddCategory}" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- Bottom buttons -->
|
||||
<Separator Grid.Row="4" Margin="8" />
|
||||
<StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Center" Margin="5 0 5 5">
|
||||
<Button Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip="View website"
|
||||
Command="{s:Action OpenUrl}"
|
||||
CommandParameter="https://artemis-rgb.com">
|
||||
<materialDesign:PackIcon Kind="Web" Width="20" Height="20" />
|
||||
</Button>
|
||||
<Button Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip="View GitHub repository"
|
||||
Command="{s:Action OpenUrl}"
|
||||
CommandParameter="https://github.com/Artemis-RGB/Artemis">
|
||||
<materialDesign:PackIcon Kind="Github" Width="20" Height="20" />
|
||||
</Button>
|
||||
<Button Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip="View Wiki"
|
||||
Command="{s:Action OpenUrl}"
|
||||
CommandParameter="https://wiki.artemis-rgb.com">
|
||||
<materialDesign:PackIcon Kind="BookOpenOutline" Width="20" Height="20" />
|
||||
</Button>
|
||||
<Button Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip="Join our Discord"
|
||||
Command="{s:Action OpenUrl}"
|
||||
CommandParameter="https://discord.gg/S3MVaC9">
|
||||
<materialDesign:PackIcon Kind="Discord" Width="20" Height="20" />
|
||||
</Button>
|
||||
<Button Style="{StaticResource MaterialDesignIconForegroundButton}"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip="View donation options"
|
||||
Command="{s:Action OpenUrl}"
|
||||
CommandParameter="https://wiki.artemis-rgb.com/en/donating">
|
||||
<materialDesign:PackIcon Kind="Gift" Width="20" Height="20" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</materialDesign:DialogHost>
|
||||
</UserControl>
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SidebarView.xaml
|
||||
/// </summary>
|
||||
public partial class SidebarView : UserControl
|
||||
{
|
||||
public SidebarView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,285 +1,214 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Home;
|
||||
using Artemis.UI.Screens.Modules;
|
||||
using Artemis.UI.Screens.News;
|
||||
using Artemis.UI.Screens.ProfileEditor;
|
||||
using Artemis.UI.Screens.Settings;
|
||||
using Artemis.UI.Screens.Sidebar.Dialogs;
|
||||
using Artemis.UI.Screens.SurfaceEditor;
|
||||
using Artemis.UI.Screens.Workshop;
|
||||
using Artemis.UI.Shared;
|
||||
using MaterialDesignExtensions.Controls;
|
||||
using MaterialDesignExtensions.Model;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using GongSolutions.Wpf.DragDrop;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Ninject;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public sealed class SidebarViewModel : Screen, IHandle<RequestSelectSidebarItemEvent>, IDisposable
|
||||
public sealed class SidebarViewModel : Conductor<SidebarCategoryViewModel>.Collection.AllActive, IHandle<RequestSelectSidebarItemEvent>, IDropTarget
|
||||
{
|
||||
private readonly Timer _activeModulesUpdateTimer;
|
||||
private readonly IKernel _kernel;
|
||||
private readonly IModuleVmFactory _moduleVmFactory;
|
||||
private readonly IPluginManagementService _pluginManagementService;
|
||||
private readonly IModuleService _moduleService;
|
||||
private string _activeModules;
|
||||
private bool _isSidebarOpen;
|
||||
private IScreen _selectedItem;
|
||||
private BindableCollection<INavigationItem> _sidebarItems;
|
||||
private Dictionary<INavigationItem, Module> _sidebarModules;
|
||||
private readonly ISidebarVmFactory _sidebarVmFactory;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IDialogService _dialogService;
|
||||
private SidebarScreenViewModel _selectedSidebarScreen;
|
||||
private ArtemisDevice _headerDevice;
|
||||
private Screen _selectedScreen;
|
||||
private readonly SidebarScreenViewModel<ProfileEditorViewModel> _profileEditor;
|
||||
private readonly DefaultDropHandler _defaultDropHandler;
|
||||
|
||||
public SidebarViewModel(IKernel kernel, ISettingsService settingsService, IEventAggregator eventAggregator, IModuleVmFactory moduleVmFactory, IPluginManagementService pluginManagementService, IModuleService moduleService)
|
||||
public SidebarViewModel(IKernel kernel,
|
||||
IEventAggregator eventAggregator,
|
||||
ISidebarVmFactory sidebarVmFactory,
|
||||
IRgbService rgbService,
|
||||
IProfileService profileService,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDialogService dialogService)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_moduleVmFactory = moduleVmFactory;
|
||||
_pluginManagementService = pluginManagementService;
|
||||
_moduleService = moduleService;
|
||||
_sidebarVmFactory = sidebarVmFactory;
|
||||
_rgbService = rgbService;
|
||||
_profileService = profileService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_dialogService = dialogService;
|
||||
_profileEditor = new SidebarScreenViewModel<ProfileEditorViewModel>(PackIconKind.Wrench, "Profile Editor");
|
||||
_defaultDropHandler = new DefaultDropHandler();
|
||||
|
||||
SidebarModules = new Dictionary<INavigationItem, Module>();
|
||||
SidebarItems = new BindableCollection<INavigationItem>();
|
||||
PinSidebar = settingsService.GetSetting("UI.PinSidebar", false);
|
||||
PinSidebar.AutoSave = true;
|
||||
|
||||
_activeModulesUpdateTimer = new Timer(1000);
|
||||
eventAggregator.Subscribe(this);
|
||||
|
||||
SidebarScreens = new BindableCollection<SidebarScreenViewModel>
|
||||
{
|
||||
new SidebarScreenViewModel<HomeViewModel>(PackIconKind.Home, "Home"),
|
||||
new SidebarScreenViewModel<WorkshopViewModel>(PackIconKind.TestTube, "Workshop"),
|
||||
new SidebarScreenViewModel<SurfaceEditorViewModel>(PackIconKind.Devices, "Surface Editor"),
|
||||
new SidebarScreenViewModel<SettingsViewModel>(PackIconKind.Cog, "Settings")
|
||||
};
|
||||
SelectedSidebarScreen = SidebarScreens.First();
|
||||
UpdateProfileCategories();
|
||||
UpdateHeaderDevice();
|
||||
}
|
||||
|
||||
public PluginSetting<bool> PinSidebar { get; }
|
||||
|
||||
public BindableCollection<INavigationItem> SidebarItems
|
||||
private void UpdateHeaderDevice()
|
||||
{
|
||||
get => _sidebarItems;
|
||||
set => SetAndNotify(ref _sidebarItems, value);
|
||||
HeaderDevice = _rgbService.Devices.FirstOrDefault(d => d.DeviceType == RGBDeviceType.Keyboard && d.Layout.IsValid);
|
||||
}
|
||||
|
||||
public Dictionary<INavigationItem, Module> SidebarModules
|
||||
public ArtemisDevice HeaderDevice
|
||||
{
|
||||
get => _sidebarModules;
|
||||
set => SetAndNotify(ref _sidebarModules, value);
|
||||
get => _headerDevice;
|
||||
set => SetAndNotify(ref _headerDevice, value);
|
||||
}
|
||||
|
||||
public string ActiveModules
|
||||
public BindableCollection<SidebarScreenViewModel> SidebarScreens { get; }
|
||||
|
||||
public Screen SelectedScreen
|
||||
{
|
||||
get => _activeModules;
|
||||
set => SetAndNotify(ref _activeModules, value);
|
||||
get => _selectedScreen;
|
||||
private set => SetAndNotify(ref _selectedScreen, value);
|
||||
}
|
||||
|
||||
public IScreen SelectedItem
|
||||
public SidebarScreenViewModel SelectedSidebarScreen
|
||||
{
|
||||
get => _selectedItem;
|
||||
set => SetAndNotify(ref _selectedItem, value);
|
||||
}
|
||||
|
||||
public bool IsSidebarOpen
|
||||
{
|
||||
get => _isSidebarOpen;
|
||||
get => _selectedSidebarScreen;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _isSidebarOpen, value);
|
||||
if (value)
|
||||
ActiveModulesUpdateTimerOnElapsed(this, EventArgs.Empty);
|
||||
if (SetAndNotify(ref _selectedSidebarScreen, value))
|
||||
ActivateScreenViewModel(_selectedSidebarScreen);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetupSidebar()
|
||||
private void ActivateScreenViewModel(SidebarScreenViewModel screenViewModel)
|
||||
{
|
||||
UpdateSidebarItems();
|
||||
|
||||
// Set the sidebar as open if it's pinned
|
||||
if (PinSidebar.Value)
|
||||
IsSidebarOpen = true;
|
||||
|
||||
// Select the top item, which will be one of the defaults
|
||||
Task.Run(() => SelectSidebarItem(SidebarItems[0]));
|
||||
SelectedScreen = screenViewModel.CreateInstance(_kernel);
|
||||
OnSelectedScreenChanged();
|
||||
if (screenViewModel != _profileEditor)
|
||||
SelectProfileConfiguration(null);
|
||||
}
|
||||
|
||||
private void UpdateSidebarItems()
|
||||
private void UpdateProfileCategories()
|
||||
{
|
||||
SidebarItems.Clear();
|
||||
SidebarModules.Clear();
|
||||
|
||||
// Add all default sidebar items
|
||||
SidebarItems.Add(new FirstLevelNavigationItem { Icon = PackIconKind.Home, Label = "Home" });
|
||||
SidebarItems.Add(new FirstLevelNavigationItem { Icon = PackIconKind.Newspaper, Label = "News" });
|
||||
SidebarItems.Add(new FirstLevelNavigationItem { Icon = PackIconKind.TestTube, Label = "Workshop" });
|
||||
SidebarItems.Add(new FirstLevelNavigationItem { Icon = PackIconKind.Edit, Label = "Surface Editor" });
|
||||
SidebarItems.Add(new FirstLevelNavigationItem { Icon = PackIconKind.Settings, Label = "Settings" });
|
||||
|
||||
// Add all activated modules
|
||||
SidebarItems.Add(new DividerNavigationItem());
|
||||
List<Module> modules = _pluginManagementService.GetFeaturesOfType<Module>().ToList();
|
||||
|
||||
foreach (IGrouping<ModulePriorityCategory, Module> category in modules.OrderByDescending(m => m.PriorityCategory).GroupBy(m => m.PriorityCategory))
|
||||
{
|
||||
SidebarItems.Add(new SubheaderNavigationItem { Subheader = category.Key.ToString() });
|
||||
foreach(Module module in category.OrderBy(m => m.Priority))
|
||||
{
|
||||
AddModule(module);
|
||||
}
|
||||
}
|
||||
foreach (ProfileCategory profileCategory in _profileService.ProfileCategories.OrderBy(p => p.Order))
|
||||
AddProfileCategoryViewModel(profileCategory);
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global - Called by view
|
||||
public void SelectItem(WillSelectNavigationItemEventArgs args)
|
||||
public async Task AddCategory()
|
||||
{
|
||||
if (args.NavigationItemToSelect == null)
|
||||
{
|
||||
SelectedItem = null;
|
||||
return;
|
||||
}
|
||||
object result = await _dialogService.ShowDialog<SidebarCategoryCreateViewModel>();
|
||||
if (result is ProfileCategory profileCategory)
|
||||
AddProfileCategoryViewModel(profileCategory);
|
||||
|
||||
SelectSidebarItem(args.NavigationItemToSelect);
|
||||
((BindableCollection<SidebarCategoryViewModel>) Items).Sort(p => p.ProfileCategory.Order);
|
||||
}
|
||||
|
||||
public void AddModule(Module module)
|
||||
public void OpenUrl(string url)
|
||||
{
|
||||
// Ensure the module is not already in the list
|
||||
if (SidebarModules.Any(io => io.Value == module))
|
||||
return;
|
||||
|
||||
FirstLevelNavigationItem sidebarItem = new()
|
||||
{
|
||||
Icon = PluginUtilities.GetPluginIcon(module.Plugin, module.DisplayIcon),
|
||||
Label = module.DisplayName
|
||||
};
|
||||
SidebarItems.Add(sidebarItem);
|
||||
SidebarModules.Add(sidebarItem, module);
|
||||
}
|
||||
|
||||
public void RemoveModule(Module module)
|
||||
{
|
||||
// If not in the list there's nothing to do
|
||||
if (SidebarModules.All(io => io.Value != module))
|
||||
return;
|
||||
|
||||
KeyValuePair<INavigationItem, Module> existing = SidebarModules.First(io => io.Value == module);
|
||||
SidebarItems.Remove(existing.Key);
|
||||
SidebarModules.Remove(existing.Key);
|
||||
}
|
||||
|
||||
private void ActiveModulesUpdateTimerOnElapsed(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsSidebarOpen)
|
||||
return;
|
||||
|
||||
int activeModules = SidebarModules.Count(m => m.Value.IsActivated);
|
||||
ActiveModules = activeModules == 1 ? "1 active module" : $"{activeModules} active modules";
|
||||
}
|
||||
|
||||
private void SelectSidebarItem(INavigationItem sidebarItem)
|
||||
{
|
||||
// A module was selected if the dictionary contains the selected item
|
||||
if (SidebarModules.ContainsKey(sidebarItem))
|
||||
ActivateModule(sidebarItem);
|
||||
else if (sidebarItem is FirstLevelNavigationItem navigationItem)
|
||||
ActivateViewModel(navigationItem.Label);
|
||||
else
|
||||
SelectedItem = null;
|
||||
}
|
||||
|
||||
private void ActivateViewModel(string label)
|
||||
{
|
||||
if (label == "Home")
|
||||
ActivateViewModel<HomeViewModel>();
|
||||
else if (label == "News")
|
||||
ActivateViewModel<NewsViewModel>();
|
||||
else if (label == "Workshop")
|
||||
ActivateViewModel<WorkshopViewModel>();
|
||||
else if (label == "Surface Editor")
|
||||
ActivateViewModel<SurfaceEditorViewModel>();
|
||||
else if (label == "Settings")
|
||||
ActivateViewModel<SettingsViewModel>();
|
||||
}
|
||||
|
||||
private void ActivateViewModel<T>()
|
||||
{
|
||||
if (SelectedItem != null && SelectedItem.GetType() == typeof(T))
|
||||
return;
|
||||
SelectedItem = (IScreen) _kernel.Get<T>();
|
||||
}
|
||||
|
||||
private void ActivateModule(INavigationItem sidebarItem)
|
||||
{
|
||||
if (!SidebarModules.ContainsKey(sidebarItem))
|
||||
return;
|
||||
if (SelectedItem is ModuleRootViewModel moduleRootViewModel && moduleRootViewModel.Module == SidebarModules[sidebarItem])
|
||||
return;
|
||||
|
||||
SelectedItem = _moduleVmFactory.CreateModuleRootViewModel(SidebarModules[sidebarItem]);
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_activeModulesUpdateTimer?.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void OnFeatureEnabled(object sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
if (e.PluginFeature is Module)
|
||||
UpdateSidebarItems();
|
||||
}
|
||||
|
||||
private void OnFeatureDisabled(object sender, PluginFeatureEventArgs e)
|
||||
{
|
||||
if (e.PluginFeature is Module)
|
||||
UpdateSidebarItems();
|
||||
}
|
||||
|
||||
private void OnModulePriorityUpdated(object sender, EventArgs e)
|
||||
{
|
||||
UpdateSidebarItems();
|
||||
Core.Utilities.OpenUrl(url);
|
||||
}
|
||||
|
||||
public void Handle(RequestSelectSidebarItemEvent message)
|
||||
{
|
||||
ActivateViewModel(message.Label);
|
||||
SidebarScreenViewModel requested = SidebarScreens.FirstOrDefault(s => s.DisplayName == message.DisplayName);
|
||||
if (requested != null)
|
||||
SelectedSidebarScreen = requested;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public SidebarCategoryViewModel AddProfileCategoryViewModel(ProfileCategory profileCategory)
|
||||
{
|
||||
SidebarCategoryViewModel viewModel = _sidebarVmFactory.SidebarCategoryViewModel(profileCategory);
|
||||
Items.Add(viewModel);
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public void RemoveProfileCategoryViewModel(SidebarCategoryViewModel viewModel)
|
||||
{
|
||||
Items.Remove(viewModel);
|
||||
}
|
||||
|
||||
public void SelectProfileConfiguration(ProfileConfiguration profileConfiguration)
|
||||
{
|
||||
foreach (SidebarCategoryViewModel sidebarCategoryViewModel in Items)
|
||||
sidebarCategoryViewModel.SelectedProfileConfiguration = sidebarCategoryViewModel.Items.FirstOrDefault(i => i.ProfileConfiguration == profileConfiguration);
|
||||
|
||||
_profileEditorService.ChangeSelectedProfileConfiguration(profileConfiguration);
|
||||
if (profileConfiguration != null)
|
||||
{
|
||||
// Little workaround to clear the selected item in the menu, ugly but oh well
|
||||
if (_selectedSidebarScreen != _profileEditor)
|
||||
{
|
||||
_selectedSidebarScreen = null;
|
||||
NotifyOfPropertyChange(nameof(SelectedSidebarScreen));
|
||||
}
|
||||
|
||||
SelectedSidebarScreen = _profileEditor;
|
||||
}
|
||||
}
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
_activeModulesUpdateTimer.Start();
|
||||
_activeModulesUpdateTimer.Elapsed += ActiveModulesUpdateTimerOnElapsed;
|
||||
|
||||
_pluginManagementService.PluginFeatureEnabled += OnFeatureEnabled;
|
||||
_pluginManagementService.PluginFeatureDisabled += OnFeatureDisabled;
|
||||
_moduleService.ModulePriorityUpdated += OnModulePriorityUpdated;
|
||||
|
||||
SetupSidebar();
|
||||
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnClose()
|
||||
{
|
||||
_activeModulesUpdateTimer.Stop();
|
||||
_activeModulesUpdateTimer.Elapsed -= ActiveModulesUpdateTimerOnElapsed;
|
||||
|
||||
_pluginManagementService.PluginFeatureEnabled -= OnFeatureEnabled;
|
||||
_pluginManagementService.PluginFeatureDisabled -= OnFeatureDisabled;
|
||||
_moduleService.ModulePriorityUpdated -= OnModulePriorityUpdated;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler SelectedScreenChanged;
|
||||
|
||||
private void OnSelectedScreenChanged()
|
||||
{
|
||||
SelectedScreenChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IDropTarget
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DragOver(IDropInfo dropInfo)
|
||||
{
|
||||
_defaultDropHandler.DragOver(dropInfo);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Drop(IDropInfo dropInfo)
|
||||
{
|
||||
_defaultDropHandler.Drop(dropInfo);
|
||||
for (int index = 0; index < Items.Count; index++)
|
||||
Items[index].ProfileCategory.Order = index;
|
||||
|
||||
// Bit dumb but gets the job done
|
||||
foreach (SidebarCategoryViewModel viewModel in Items)
|
||||
_profileService.SaveProfileCategory(viewModel.ProfileCategory);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user