mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Meta - Replace WPF projects with Avalonia projects
This commit is contained in:
1 parent
fcf0376a9a
commit
d7f3ee1190
1110 files changed
+10872
-52240
No files matched your search
@@ -1,127 +0,0 @@
|
||||
<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>
|
||||
@@ -0,0 +1,13 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Sidebar.SidebarCategoryEditView">
|
||||
<StackPanel>
|
||||
<StackPanel.KeyBindings>
|
||||
<KeyBinding Gesture="Enter" Command="{Binding Confirm}" />
|
||||
</StackPanel.KeyBindings>
|
||||
<TextBox Text="{Binding CategoryName}" Watermark="Category name"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,21 @@
|
||||
using Artemis.UI.Shared.Extensions;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarCategoryEditView : ReactiveUserControl<SidebarCategoryEditViewModel>
|
||||
{
|
||||
public SidebarCategoryEditView()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.WhenActivated(_ => this.ClearAllDataValidationErrors());
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Reactive;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Validation.Extensions;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarCategoryEditViewModel : ContentDialogViewModelBase
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly ProfileCategory? _category;
|
||||
private string? _categoryName;
|
||||
|
||||
public SidebarCategoryEditViewModel(IProfileService profileService, ProfileCategory? category)
|
||||
{
|
||||
_profileService = profileService;
|
||||
_category = category;
|
||||
|
||||
if (_category != null)
|
||||
_categoryName = _category.Name;
|
||||
|
||||
Confirm = ReactiveCommand.Create(ExecuteConfirm, ValidationContext.Valid);
|
||||
Delete = ReactiveCommand.Create(ExecuteDelete);
|
||||
|
||||
this.ValidationRule(vm => vm.CategoryName, categoryName => !string.IsNullOrWhiteSpace(categoryName), "You must specify a valid name");
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Delete { get; set; }
|
||||
|
||||
public string? CategoryName
|
||||
{
|
||||
get => _categoryName;
|
||||
set => this.RaiseAndSetIfChanged(ref _categoryName, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Confirm { get; }
|
||||
|
||||
private void ExecuteConfirm()
|
||||
{
|
||||
if (_category != null)
|
||||
{
|
||||
_category.Name = CategoryName!;
|
||||
_profileService.SaveProfileCategory(_category);
|
||||
}
|
||||
else
|
||||
_profileService.CreateProfileCategory(CategoryName!);
|
||||
|
||||
ContentDialog?.Hide(ContentDialogResult.Primary);
|
||||
}
|
||||
|
||||
private void ExecuteDelete()
|
||||
{
|
||||
if (_category != null)
|
||||
_profileService.DeleteProfileCategory(_category);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<controls1:CoreWindow xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
xmlns:svg="clr-namespace:Avalonia.Svg.Skia;assembly=Avalonia.Svg.Skia"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Sidebar"
|
||||
xmlns:controls1="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="850"
|
||||
x:Class="Artemis.UI.Screens.Sidebar.ProfileConfigurationEditView"
|
||||
Title="{Binding DisplayName}"
|
||||
Icon="/Assets/Images/Logo/application.ico"
|
||||
Width="800"
|
||||
MinWidth="420"
|
||||
Height="850">
|
||||
<Window.Resources>
|
||||
<converters:EnumToBooleanConverter x:Key="EnumBoolConverter" />
|
||||
</Window.Resources>
|
||||
<Grid Margin="16" RowDefinitions="*,Auto">
|
||||
<ScrollViewer>
|
||||
<StackPanel>
|
||||
<StackPanel.Styles>
|
||||
<Style Selector="TextBlock.label">
|
||||
<Setter Property="Margin" Value="0 10 0 5" />
|
||||
</Style>
|
||||
<Style Selector="TextBlock.section-header">
|
||||
<Setter Property="Margin" Value="0 0 5 0" />
|
||||
</Style>
|
||||
<Style Selector="TextBlock.section-subtitle">
|
||||
<Setter Property="VerticalAlignment" Value="Bottom" />
|
||||
<Setter Property="Margin" Value="0 0 0 1" />
|
||||
<Setter Property="TextWrapping" Value="Wrap" />
|
||||
</Style>
|
||||
</StackPanel.Styles>
|
||||
|
||||
<Grid>
|
||||
<TextBlock Classes="h4" IsVisible="{Binding IsNew}">Add a new profile</TextBlock>
|
||||
<TextBlock Classes="h4" IsVisible="{Binding !IsNew}" Text="{Binding ProfileConfiguration.Name}" />
|
||||
</Grid>
|
||||
|
||||
<Border Classes="card" Margin="0 0 0 15">
|
||||
<StackPanel>
|
||||
<TextBlock Classes="label">Profile name</TextBlock>
|
||||
<TextBox Watermark="Name" Text="{Binding ProfileName}" />
|
||||
<TextBlock Classes="label">Module</TextBlock>
|
||||
<ComboBox SelectedItem="{Binding SelectedModule}" IsEnabled="{Binding Modules.Count}" Items="{Binding Modules}" HorizontalAlignment="Stretch">
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type local:ProfileModuleViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<controls:ArtemisIcon Icon="{Binding Icon}" Width="16" Height="16" Margin="0 0 5 0" />
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<Grid>
|
||||
<TextBlock Classes="subtitle" IsVisible="{Binding Modules.Count}">Optional and binds the profile to the selected module, making module data available</TextBlock>
|
||||
<TextBlock Classes="subtitle" IsVisible="{Binding !Modules.Count}">No available modules were found</TextBlock>
|
||||
</Grid>
|
||||
|
||||
<TextBlock Classes="label">Icon type</TextBlock>
|
||||
<WrapPanel Orientation="Horizontal">
|
||||
<RadioButton Content="Material Icon"
|
||||
IsChecked="{Binding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.MaterialIcon}}" />
|
||||
<RadioButton Content="Bitmap image"
|
||||
IsChecked="{Binding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.BitmapImage}}" />
|
||||
<RadioButton Content="SVG image"
|
||||
IsChecked="{Binding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.SvgImage}}" />
|
||||
</WrapPanel>
|
||||
|
||||
<TextBlock Classes="label">Icon</TextBlock>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
IsVisible="{Binding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.BitmapImage}}">
|
||||
<Border Background="{DynamicResource CheckerboardBrush}" CornerRadius="{DynamicResource CardCornerRadius}" Width="78" Height="78">
|
||||
<Image Source="{Binding SelectedBitmapSource}" Margin="10" />
|
||||
</Border>
|
||||
<Button Command="{Binding BrowseBitmapFile}"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="10 0"
|
||||
IsVisible="{Binding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.BitmapImage}}">
|
||||
Browse bitmap file
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
IsVisible="{Binding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.SvgImage}}">
|
||||
<Border Background="{DynamicResource CheckerboardBrush}" CornerRadius="{DynamicResource CardCornerRadius}" Width="78" Height="78">
|
||||
<Image Margin="10" Source="{Binding SelectedSvgSource}" />
|
||||
</Border>
|
||||
<Button Command="{Binding BrowseSvgFile}"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="10 0"
|
||||
IsVisible="{Binding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.SvgImage}}">
|
||||
Browse SVG file
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
IsVisible="{Binding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.MaterialIcon}}">
|
||||
<Border Background="{DynamicResource CheckerboardBrush}" CornerRadius="{DynamicResource CardCornerRadius}" Width="78" Height="78">
|
||||
<avalonia:MaterialIcon Kind="{Binding SelectedMaterialIcon.Icon}" Width="45" Height="45" />
|
||||
</Border>
|
||||
<ComboBox Items="{Binding MaterialIcons}"
|
||||
SelectedItem="{Binding SelectedMaterialIcon}"
|
||||
VirtualizationMode="Simple"
|
||||
VerticalAlignment="Bottom"
|
||||
IsTextSearchEnabled="True"
|
||||
Margin="10 0"
|
||||
Width="250"
|
||||
IsVisible="{Binding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.MaterialIcon}}">
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="local:ProfileIconViewModel">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<avalonia:MaterialIcon Kind="{Binding Icon}" Margin="0 0 5 0" />
|
||||
<TextBlock Text="{Binding DisplayName}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Classes="h5 section-header">Keybindings</TextBlock>
|
||||
<TextBlock Classes="subtitle section-subtitle">You may set up hotkeys to activate/deactivate the profile</TextBlock>
|
||||
</StackPanel>
|
||||
<Border Classes="card" Margin="0 5 0 15">
|
||||
<StackPanel>
|
||||
<TextBlock>Hotkey mode</TextBlock>
|
||||
<WrapPanel Orientation="Horizontal">
|
||||
<RadioButton Content="None"
|
||||
IsChecked="{Binding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.None}}" />
|
||||
<RadioButton Content="Toggle"
|
||||
IsChecked="{Binding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.Toggle}}" />
|
||||
<RadioButton Content="Separate enable/disable"
|
||||
IsChecked="{Binding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.EnableDisable}}" />
|
||||
</WrapPanel>
|
||||
|
||||
<controls:HotkeyBox Watermark="Toggle hotkey"
|
||||
Hotkey="{Binding EnableHotkey}"
|
||||
IsVisible="{Binding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.Toggle}}"
|
||||
HorizontalAlignment="Left"
|
||||
Width="200"
|
||||
Margin="0 5 0 0"/>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
IsVisible="{Binding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.EnableDisable}}"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0 5 0 0">
|
||||
<controls:HotkeyBox Watermark="Enable hotkey" Hotkey="{Binding EnableHotkey}" Margin="0 0 4 0" Width="200"/>
|
||||
<controls:HotkeyBox Watermark="Disable hotkey" Hotkey="{Binding DisableHotkey}" Margin="4 0 0 0" Width="200"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Classes="h5 section-header">Activation conditions</TextBlock>
|
||||
<TextBlock Classes="subtitle section-subtitle">Set up certain conditions under which the profile should be active</TextBlock>
|
||||
</StackPanel>
|
||||
<Border Classes="card" Margin="0 5 0 15">
|
||||
<TextBlock TextWrapping="Wrap">Here you'll find the node editor layer at some point, use your imagination for now.</TextBlock>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<Grid Grid.Row="1" ColumnDefinitions="Auto,Auto,Auto" HorizontalAlignment="Right">
|
||||
<Button Grid.Column="0" Classes="accent" Command="{Binding Confirm}">Confirm</Button>
|
||||
<Button Grid.Column="1" Margin="5" Command="{Binding Import}" IsVisible="{Binding IsNew}">Import</Button>
|
||||
<Button Grid.Column="1" Margin="5" Command="{Binding Delete}" IsVisible="{Binding !IsNew}">Delete</Button>
|
||||
<Button Grid.Column="2" Command="{Binding Cancel}">Cancel</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
</controls1:CoreWindow>
|
||||
@@ -0,0 +1,22 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public partial class ProfileConfigurationEditView : ReactiveCoreWindow<ProfileConfigurationEditViewModel>
|
||||
{
|
||||
public ProfileConfigurationEditView()
|
||||
{
|
||||
InitializeComponent();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Svg.Skia;
|
||||
using Avalonia.Threading;
|
||||
using Material.Icons;
|
||||
using Newtonsoft.Json;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConfiguration?>
|
||||
{
|
||||
private readonly ProfileCategory _profileCategory;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IWindowService _windowService;
|
||||
private Hotkey? _disableHotkey;
|
||||
private Hotkey? _enableHotkey;
|
||||
private ProfileConfigurationHotkeyMode _hotkeyMode;
|
||||
private ProfileConfigurationIconType _iconType;
|
||||
private ObservableCollection<ProfileIconViewModel>? _materialIcons;
|
||||
private ProfileConfiguration _profileConfiguration;
|
||||
private string _profileName;
|
||||
private Bitmap? _selectedBitmapSource;
|
||||
private string? _selectedIconPath;
|
||||
private ProfileIconViewModel? _selectedMaterialIcon;
|
||||
private ProfileModuleViewModel? _selectedModule;
|
||||
private SvgImage? _selectedSvgSource;
|
||||
|
||||
public ProfileConfigurationEditViewModel(
|
||||
ProfileCategory profileCategory,
|
||||
ProfileConfiguration? profileConfiguration,
|
||||
IWindowService windowService,
|
||||
IProfileService profileService,
|
||||
IProfileEditorService profileEditorService,
|
||||
IPluginManagementService pluginManagementService)
|
||||
{
|
||||
_profileCategory = profileCategory;
|
||||
_windowService = windowService;
|
||||
_profileService = profileService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_profileConfiguration = profileConfiguration ?? profileService.CreateProfileConfiguration(profileCategory, "New profile", Enum.GetValues<MaterialIconKind>().First().ToString());
|
||||
_profileName = _profileConfiguration.Name;
|
||||
_iconType = _profileConfiguration.Icon.IconType;
|
||||
_hotkeyMode = _profileConfiguration.HotkeyMode;
|
||||
if (_profileConfiguration.EnableHotkey != null)
|
||||
_enableHotkey = new Hotkey {Key = _profileConfiguration.EnableHotkey.Key, Modifiers = _profileConfiguration.EnableHotkey.Modifiers};
|
||||
if (_profileConfiguration.DisableHotkey != null)
|
||||
_disableHotkey = new Hotkey {Key = _profileConfiguration.DisableHotkey.Key, Modifiers = _profileConfiguration.DisableHotkey.Modifiers};
|
||||
|
||||
IsNew = profileConfiguration == null;
|
||||
DisplayName = IsNew ? "Artemis | Add profile" : "Artemis | Edit profile";
|
||||
Modules = new ObservableCollection<ProfileModuleViewModel>(
|
||||
pluginManagementService.GetFeaturesOfType<Module>().Where(m => !m.IsAlwaysAvailable).Select(m => new ProfileModuleViewModel(m))
|
||||
);
|
||||
|
||||
Dispatcher.UIThread.Post(LoadIcon, DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
public bool IsNew { get; }
|
||||
|
||||
public ProfileConfiguration ProfileConfiguration
|
||||
{
|
||||
get => _profileConfiguration;
|
||||
set => RaiseAndSetIfChanged(ref _profileConfiguration, value);
|
||||
}
|
||||
|
||||
public string ProfileName
|
||||
{
|
||||
get => _profileName;
|
||||
set => RaiseAndSetIfChanged(ref _profileName, value);
|
||||
}
|
||||
|
||||
public ProfileConfigurationHotkeyMode HotkeyMode
|
||||
{
|
||||
get => _hotkeyMode;
|
||||
set => RaiseAndSetIfChanged(ref _hotkeyMode, value);
|
||||
}
|
||||
|
||||
public Hotkey? EnableHotkey
|
||||
{
|
||||
get => _enableHotkey;
|
||||
set => RaiseAndSetIfChanged(ref _enableHotkey, value);
|
||||
}
|
||||
|
||||
public Hotkey? DisableHotkey
|
||||
{
|
||||
get => _disableHotkey;
|
||||
set => RaiseAndSetIfChanged(ref _disableHotkey, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<ProfileModuleViewModel> Modules { get; }
|
||||
|
||||
public ProfileModuleViewModel? SelectedModule
|
||||
{
|
||||
get => _selectedModule;
|
||||
set => RaiseAndSetIfChanged(ref _selectedModule, value);
|
||||
}
|
||||
|
||||
public async Task Import()
|
||||
{
|
||||
if (!IsNew)
|
||||
return;
|
||||
|
||||
string[]? result = await _windowService.CreateOpenFileDialog()
|
||||
.HavingFilter(f => f.WithExtension("json").WithName("Artemis profile"))
|
||||
.ShowAsync();
|
||||
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
string json = await File.ReadAllTextAsync(result[0]);
|
||||
ProfileConfigurationExportModel? profileConfigurationExportModel = null;
|
||||
try
|
||||
{
|
||||
profileConfigurationExportModel = JsonConvert.DeserializeObject<ProfileConfigurationExportModel>(json, IProfileService.ExportSettings);
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
_windowService.ShowExceptionDialog("Import profile failed", e);
|
||||
}
|
||||
|
||||
if (profileConfigurationExportModel == null)
|
||||
{
|
||||
await _windowService.ShowConfirmContentDialog("Import profile", "Failed to import this profile, make sure it is a valid Artemis profile.", "Confirm", null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the temporary profile configuration
|
||||
_profileService.RemoveProfileConfiguration(_profileConfiguration);
|
||||
// Import the new profile configuration
|
||||
_profileService.ImportProfile(_profileCategory, profileConfigurationExportModel);
|
||||
|
||||
Close(_profileConfiguration);
|
||||
}
|
||||
|
||||
public async Task Delete()
|
||||
{
|
||||
if (IsNew)
|
||||
return;
|
||||
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (_profileConfiguration.IsBeingEdited)
|
||||
_profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||
_profileService.RemoveProfileConfiguration(_profileConfiguration);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
Close(_profileConfiguration);
|
||||
}
|
||||
|
||||
public async Task Confirm()
|
||||
{
|
||||
ProfileConfiguration.Name = ProfileName;
|
||||
ProfileConfiguration.Module = SelectedModule?.Module;
|
||||
ProfileConfiguration.HotkeyMode = HotkeyMode;
|
||||
ProfileConfiguration.EnableHotkey = EnableHotkey;
|
||||
ProfileConfiguration.DisableHotkey = DisableHotkey;
|
||||
|
||||
await SaveIcon();
|
||||
|
||||
_profileService.SaveProfileConfigurationIcon(ProfileConfiguration);
|
||||
_profileService.SaveProfileCategory(_profileCategory);
|
||||
Close(ProfileConfiguration);
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
if (IsNew)
|
||||
_profileService.RemoveProfileConfiguration(_profileConfiguration);
|
||||
Close(null);
|
||||
}
|
||||
|
||||
#region Icon
|
||||
|
||||
public ProfileConfigurationIconType IconType
|
||||
{
|
||||
get => _iconType;
|
||||
set => RaiseAndSetIfChanged(ref _iconType, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<ProfileIconViewModel>? MaterialIcons
|
||||
{
|
||||
get => _materialIcons;
|
||||
set => RaiseAndSetIfChanged(ref _materialIcons, value);
|
||||
}
|
||||
|
||||
public ProfileIconViewModel? SelectedMaterialIcon
|
||||
{
|
||||
get => _selectedMaterialIcon;
|
||||
set => RaiseAndSetIfChanged(ref _selectedMaterialIcon, value);
|
||||
}
|
||||
|
||||
public Bitmap? SelectedBitmapSource
|
||||
{
|
||||
get => _selectedBitmapSource;
|
||||
set => RaiseAndSetIfChanged(ref _selectedBitmapSource, value);
|
||||
}
|
||||
|
||||
public SvgImage? SelectedSvgSource
|
||||
{
|
||||
get => _selectedSvgSource;
|
||||
set => RaiseAndSetIfChanged(ref _selectedSvgSource, value);
|
||||
}
|
||||
|
||||
private void LoadIcon()
|
||||
{
|
||||
// Preselect the icon based on streams if needed
|
||||
if (_profileConfiguration.Icon.IconType == ProfileConfigurationIconType.BitmapImage)
|
||||
{
|
||||
SelectedBitmapSource = new Bitmap(_profileConfiguration.Icon.GetIconStream());
|
||||
}
|
||||
else if (_profileConfiguration.Icon.IconType == ProfileConfigurationIconType.SvgImage)
|
||||
{
|
||||
Stream? iconStream = _profileConfiguration.Icon.GetIconStream();
|
||||
if (iconStream != null)
|
||||
{
|
||||
SvgSource newSource = new();
|
||||
newSource.Load(iconStream);
|
||||
SelectedSvgSource = new SvgImage {Source = newSource};
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare the contents of the dropdown box, it should be virtualized so no need to wait with this
|
||||
ObservableCollection<ProfileIconViewModel> icons = new(Enum.GetValues<MaterialIconKind>()
|
||||
.Select(kind => new ProfileIconViewModel(kind))
|
||||
.DistinctBy(vm => vm.DisplayName)
|
||||
.OrderBy(vm => vm.DisplayName));
|
||||
|
||||
// Preselect the icon or fall back to a random one
|
||||
SelectedMaterialIcon = !IsNew && Enum.TryParse(_profileConfiguration.Icon.IconName, out MaterialIconKind enumValue)
|
||||
? icons.FirstOrDefault(m => m.Icon == enumValue)
|
||||
: icons.ElementAt(new Random().Next(0, icons.Count - 1));
|
||||
MaterialIcons = icons;
|
||||
}
|
||||
|
||||
private async Task SaveIcon()
|
||||
{
|
||||
if (IconType == ProfileConfigurationIconType.MaterialIcon && SelectedMaterialIcon != null)
|
||||
{
|
||||
ProfileConfiguration.Icon.SetIconByName(SelectedMaterialIcon.Icon.ToString());
|
||||
}
|
||||
else if (_selectedIconPath != null)
|
||||
{
|
||||
await using FileStream fileStream = File.OpenRead(_selectedIconPath);
|
||||
ProfileConfiguration.Icon.SetIconByStream(Path.GetFileName(_selectedIconPath), fileStream);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task BrowseBitmapFile()
|
||||
{
|
||||
string[]? result = await _windowService.CreateOpenFileDialog()
|
||||
.HavingFilter(f => f.WithExtension("png").WithExtension("jpg").WithExtension("bmp").WithName("Bitmap image"))
|
||||
.ShowAsync();
|
||||
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
SelectedBitmapSource = new Bitmap(result[0]);
|
||||
_selectedIconPath = result[0];
|
||||
}
|
||||
|
||||
public async Task BrowseSvgFile()
|
||||
{
|
||||
string[]? result = await _windowService.CreateOpenFileDialog()
|
||||
.HavingFilter(f => f.WithExtension("svg").WithName("SVG image"))
|
||||
.ShowAsync();
|
||||
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
SvgSource newSource = new();
|
||||
newSource.Load(result[0]);
|
||||
|
||||
SelectedSvgSource = new SvgImage {Source = newSource};
|
||||
_selectedIconPath = result[0];
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
<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
@@ -1,75 +0,0 @@
|
||||
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
@@ -1,27 +0,0 @@
|
||||
<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
@@ -1,43 +0,0 @@
|
||||
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?.ActivationRequirements != null)
|
||||
Items.AddRange(Module.ActivationRequirements.Select(_sidebarVmFactory.ModuleActivationRequirementViewModel));
|
||||
}
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit.ProfileConfigurationHotkeyView"
|
||||
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:ProfileConfigurationHotkeyViewModel}">
|
||||
<TextBox Style="{StaticResource MaterialDesignFilledTextBox}"
|
||||
IsReadOnly="True"
|
||||
IsReadOnlyCaretVisible="True"
|
||||
Text="{Binding HotkeyDisplay, UpdateSourceTrigger=PropertyChanged}"
|
||||
VerticalAlignment="Center"
|
||||
materialDesign:TextFieldAssist.HasClearButton="True"
|
||||
materialDesign:HintAssist.Hint="{Binding Hint}"
|
||||
KeyDown="{s:Action TextBoxKeyDown}"/>
|
||||
</UserControl>
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
{
|
||||
public class ProfileConfigurationHotkeyViewModel : Screen
|
||||
{
|
||||
private readonly bool _isDisableHotkey;
|
||||
private readonly ProfileConfiguration _profileConfiguration;
|
||||
private string _hint;
|
||||
private string _hotkeyDisplay;
|
||||
|
||||
public ProfileConfigurationHotkeyViewModel(ProfileConfiguration profileConfiguration, bool isDisableHotkey)
|
||||
{
|
||||
_profileConfiguration = profileConfiguration;
|
||||
_isDisableHotkey = isDisableHotkey;
|
||||
|
||||
UpdateHotkeyDisplay();
|
||||
}
|
||||
|
||||
public Hotkey Hotkey => _isDisableHotkey ? _profileConfiguration.DisableHotkey : _profileConfiguration.EnableHotkey;
|
||||
|
||||
public string Hint
|
||||
{
|
||||
get => _hint;
|
||||
set => SetAndNotify(ref _hint, value);
|
||||
}
|
||||
|
||||
public string HotkeyDisplay
|
||||
{
|
||||
get => _hotkeyDisplay;
|
||||
set
|
||||
{
|
||||
if (!SetAndNotify(ref _hotkeyDisplay, value)) return;
|
||||
if (value == null && Hotkey != null)
|
||||
{
|
||||
Hotkey.Key = null;
|
||||
Hotkey.Modifiers = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateHotkeyDisplay()
|
||||
{
|
||||
string display = null;
|
||||
if (Hotkey?.Modifiers != null)
|
||||
display = string.Join("+", Enum.GetValues<KeyboardModifierKey>().Skip(1).Where(m => Hotkey.Modifiers.Value.HasFlag(m)));
|
||||
if (Hotkey?.Key != null)
|
||||
display = string.IsNullOrEmpty(display) ? Hotkey.Key.ToString() : $"{display}+{Hotkey.Key}";
|
||||
|
||||
HotkeyDisplay = display;
|
||||
if (_profileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.EnableDisable)
|
||||
Hint = _isDisableHotkey ? "Disable hotkey" : "Enable hotkey";
|
||||
else
|
||||
Hint = "Toggle hotkey";
|
||||
}
|
||||
|
||||
public void TextBoxKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key >= Key.LeftShift && e.Key <= Key.RightAlt)
|
||||
return;
|
||||
|
||||
if (_isDisableHotkey)
|
||||
{
|
||||
_profileConfiguration.DisableHotkey ??= new Hotkey();
|
||||
_profileConfiguration.DisableHotkey.Key = (KeyboardKey?) e.Key;
|
||||
_profileConfiguration.DisableHotkey.Modifiers = (KeyboardModifierKey?) Keyboard.Modifiers;
|
||||
}
|
||||
else
|
||||
{
|
||||
_profileConfiguration.EnableHotkey ??= new Hotkey();
|
||||
_profileConfiguration.EnableHotkey.Key = (KeyboardKey?) e.Key;
|
||||
_profileConfiguration.EnableHotkey.Modifiers = (KeyboardModifierKey?) Keyboard.Modifiers;
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
UpdateHotkeyDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,318 +0,0 @@
|
||||
<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:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:profileEdit="clr-namespace:Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit"
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="600"
|
||||
d:DataContext="{d:DesignInstance {x:Type profileEdit:ProfileEditViewModel}}"
|
||||
Width="800">
|
||||
<UserControl.Resources>
|
||||
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
|
||||
<shared:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
<shared:StreamToBitmapImageConverter x:Key="StreamToBitmapImageConverter" />
|
||||
<shared:StreamToSvgImageConverter x:Key="StreamToSvgImageConverter" />
|
||||
</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"
|
||||
IsEditable="True"
|
||||
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}}}"
|
||||
Margin="0 0 10 0"
|
||||
Width="45"
|
||||
Height="45"
|
||||
VerticalAlignment="Center"
|
||||
RenderOptions.BitmapScalingMode="HighQuality" />
|
||||
<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>
|
||||
|
||||
<Image Grid.Column="0"
|
||||
Source="{Binding DataContext.SelectedImage, Converter={StaticResource StreamToSvgImageConverter}, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
||||
Margin="0 0 10 0"
|
||||
Width="45"
|
||||
Height="45"
|
||||
VerticalAlignment="Center"
|
||||
RenderOptions.BitmapScalingMode="HighQuality" />
|
||||
<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}">
|
||||
Hotkeys
|
||||
</TextBlock>
|
||||
<TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}">You may set up hotkeys to activate/deactivate the profile</TextBlock>
|
||||
|
||||
<ComboBox materialDesign:HintAssist.Hint="Hotkey mode"
|
||||
Margin="0 6 0 8"
|
||||
Style="{StaticResource MaterialDesignFilledComboBox}"
|
||||
SelectedValue="{Binding SelectedHotkeyMode}"
|
||||
ItemsSource="{Binding HotkeyModes}"
|
||||
SelectedValuePath="Value"
|
||||
DisplayMemberPath="Description" />
|
||||
|
||||
<ContentControl s:View.Model="{Binding EnableHotkeyViewModel}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsTabStop="False"
|
||||
Visibility="{Binding ShowEnableHotkey, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
|
||||
Margin="0 0 0 8"/>
|
||||
<ContentControl s:View.Model="{Binding DisableHotkeyViewModel}"
|
||||
VerticalContentAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
IsTabStop="False"
|
||||
Visibility="{Binding ShowDisableHotkey, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"/>
|
||||
</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" Margin="0 0 0 4">
|
||||
<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>
|
||||
@@ -1,246 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using FluentValidation;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Ookii.Dialogs.Wpf;
|
||||
using Stylet;
|
||||
using EnumUtilities = Artemis.UI.Shared.EnumUtilities;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
{
|
||||
public class ProfileEditViewModel : DialogViewModelBase
|
||||
{
|
||||
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;
|
||||
private string _selectedIconPath;
|
||||
|
||||
public ProfileEditViewModel(ProfileConfiguration profileConfiguration, bool isNew,
|
||||
IProfileService profileService,
|
||||
IPluginManagementService pluginManagementService,
|
||||
ISidebarVmFactory sidebarVmFactory,
|
||||
IModelValidator<ProfileEditViewModel> validator) : base(validator)
|
||||
{
|
||||
ProfileConfiguration = profileConfiguration;
|
||||
IsNew = isNew;
|
||||
|
||||
_profileService = profileService;
|
||||
_modules = ProfileConfiguration.Module != null ? new List<Module> {ProfileConfiguration.Module} : new List<Module>();
|
||||
|
||||
IconTypes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(ProfileConfigurationIconType)));
|
||||
HotkeyModes = new BindableCollection<ValueDescription>(EnumUtilities.GetAllValuesAndDescriptions(typeof(ProfileConfigurationHotkeyMode)));
|
||||
Icons = new BindableCollection<ProfileIconViewModel>();
|
||||
Modules = new BindableCollection<ProfileModuleViewModel>(
|
||||
pluginManagementService.GetFeaturesOfType<Module>().Where(m => !m.IsAlwaysAvailable).Select(m => new ProfileModuleViewModel(m))
|
||||
);
|
||||
Initializing = true;
|
||||
|
||||
ModuleActivationRequirementsViewModel = new ModuleActivationRequirementsViewModel(sidebarVmFactory);
|
||||
ModuleActivationRequirementsViewModel.ConductWith(this);
|
||||
ModuleActivationRequirementsViewModel.SetModule(ProfileConfiguration.Module);
|
||||
EnableHotkeyViewModel = sidebarVmFactory.ProfileConfigurationHotkeyViewModel(ProfileConfiguration, false);
|
||||
EnableHotkeyViewModel.ConductWith(this);
|
||||
DisableHotkeyViewModel = sidebarVmFactory.ProfileConfigurationHotkeyViewModel(ProfileConfiguration, true);
|
||||
DisableHotkeyViewModel.ConductWith(this);
|
||||
|
||||
_profileName = ProfileConfiguration.Name;
|
||||
_selectedModule = Modules.FirstOrDefault(m => m.Module == ProfileConfiguration.Module);
|
||||
_selectedIconType = ProfileConfiguration.Icon.IconType;
|
||||
_selectedImage = ProfileConfiguration.Icon.GetIconStream();
|
||||
|
||||
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.IconName);
|
||||
Initializing = false;
|
||||
});
|
||||
}
|
||||
|
||||
public ModuleActivationRequirementsViewModel ModuleActivationRequirementsViewModel { get; }
|
||||
public ProfileConfigurationHotkeyViewModel EnableHotkeyViewModel { get; }
|
||||
public ProfileConfigurationHotkeyViewModel DisableHotkeyViewModel { get; }
|
||||
|
||||
public bool IsNew { get; }
|
||||
public ProfileConfiguration ProfileConfiguration { get; }
|
||||
public BindableCollection<ValueDescription> IconTypes { get; }
|
||||
public BindableCollection<ValueDescription> HotkeyModes { 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 ProfileConfigurationHotkeyMode SelectedHotkeyMode
|
||||
{
|
||||
get => ProfileConfiguration.HotkeyMode;
|
||||
set
|
||||
{
|
||||
ProfileConfiguration.HotkeyMode = value;
|
||||
NotifyOfPropertyChange(nameof(SelectedHotkeyMode));
|
||||
NotifyOfPropertyChange(nameof(ShowEnableHotkey));
|
||||
NotifyOfPropertyChange(nameof(ShowDisableHotkey));
|
||||
|
||||
EnableHotkeyViewModel.UpdateHotkeyDisplay();
|
||||
DisableHotkeyViewModel.UpdateHotkeyDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowEnableHotkey => ProfileConfiguration.HotkeyMode != ProfileConfigurationHotkeyMode.None;
|
||||
public bool ShowDisableHotkey => ProfileConfiguration.HotkeyMode == ProfileConfigurationHotkeyMode.EnableDisable;
|
||||
|
||||
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);
|
||||
|
||||
ModuleActivationRequirementsViewModel.SetModule(value?.Module);
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Session.Close(nameof(Delete));
|
||||
}
|
||||
|
||||
public async Task Accept()
|
||||
{
|
||||
await ValidateAsync();
|
||||
|
||||
if (HasErrors)
|
||||
return;
|
||||
|
||||
ProfileConfiguration.Name = ProfileName;
|
||||
if (SelectedIconType == ProfileConfigurationIconType.MaterialIcon)
|
||||
ProfileConfiguration.Icon.SetIconByName(SelectedIcon?.Icon.ToString());
|
||||
else if (_selectedIconPath != null)
|
||||
{
|
||||
await using FileStream fileStream = File.OpenRead(_selectedIconPath);
|
||||
ProfileConfiguration.Icon.SetIconByStream(Path.GetFileName(_selectedIconPath), fileStream);
|
||||
}
|
||||
|
||||
ProfileConfiguration.Module = SelectedModule?.Module;
|
||||
|
||||
if (_changedImage)
|
||||
_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);
|
||||
_selectedIconPath = 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);
|
||||
_selectedIconPath = dialog.FileName;
|
||||
}
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
_profileService.HotkeysEnabled = false;
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
_profileService.HotkeysEnabled = true;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class ProfileEditViewModelValidator : AbstractValidator<ProfileEditViewModel>
|
||||
{
|
||||
public ProfileEditViewModelValidator()
|
||||
{
|
||||
RuleFor(m => m.ProfileName).NotEmpty().WithMessage("Profile name may not be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
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,16 @@
|
||||
using Artemis.UI.Shared;
|
||||
using Material.Icons;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class ProfileIconViewModel : ViewModelBase
|
||||
{
|
||||
public ProfileIconViewModel(MaterialIconKind icon)
|
||||
{
|
||||
Icon = icon;
|
||||
DisplayName = icon.ToString();
|
||||
}
|
||||
|
||||
public MaterialIconKind Icon { get; }
|
||||
}
|
||||
}
|
||||
+6
-7
@@ -1,23 +1,22 @@
|
||||
using Artemis.Core.Modules;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Stylet;
|
||||
using Artemis.UI.Shared;
|
||||
using Material.Icons;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar.Dialogs.ProfileEdit
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class ProfileModuleViewModel : PropertyChangedBase
|
||||
public class ProfileModuleViewModel : ViewModelBase
|
||||
{
|
||||
public ProfileModuleViewModel(Module module)
|
||||
{
|
||||
Module = module;
|
||||
Name = module.Info.Name;
|
||||
Icon = module.Info.ResolvedIcon ?? PackIconKind.QuestionMark.ToString();
|
||||
|
||||
Icon = module.Info.ResolvedIcon ?? MaterialIconKind.QuestionMark.ToString();
|
||||
Description = module.Info.Description;
|
||||
}
|
||||
|
||||
public string Icon { get; }
|
||||
public string Name { get; }
|
||||
public string Description { get; }
|
||||
public string? Description { get; }
|
||||
|
||||
public Module Module { get; }
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<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>
|
||||
@@ -1,56 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<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>
|
||||
@@ -1,73 +0,0 @@
|
||||
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,119 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Sidebar"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Sidebar.SidebarCategoryView">
|
||||
<UserControl.Styles>
|
||||
<Style Selector=":is(Button).category-button">
|
||||
<Setter Property="IsVisible" Value="False" />
|
||||
</Style>
|
||||
<Style Selector="Grid#ContainerGrid:pointerover :is(Button).category-button">
|
||||
<Setter Property="IsVisible" Value="True" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="avalonia|MaterialIcon.chevron-collapsed">
|
||||
<Setter Property="RenderTransform" Value="rotate(180deg)" />
|
||||
</Style>
|
||||
<Style Selector="TextBlock.fadable.suspended">
|
||||
<Setter Property="Opacity" Value="0.33" />
|
||||
</Style>
|
||||
<Style Selector="Border.fadable">
|
||||
<Setter Property="Opacity" Value="0" />
|
||||
</Style>
|
||||
<Style Selector="Border.fadable.suspended">
|
||||
<Setter Property="Opacity" Value="1" />
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
<Grid x:Name="ContainerGrid" Margin="0 8 0 0" RowDefinitions="Auto,*">
|
||||
<Grid Grid.Row="0" Background="Transparent" ColumnDefinitions="Auto,Auto,*,Auto,Auto,Auto">
|
||||
|
||||
<avalonia:MaterialIcon Classes.chevron-collapsed="{Binding ShowItems}"
|
||||
Kind="ChevronUp"
|
||||
Grid.Column="0"
|
||||
Margin="5 0"
|
||||
PointerPressed="Title_OnPointerPressed"
|
||||
Background="Transparent">
|
||||
<avalonia:MaterialIcon.Transitions>
|
||||
<Transitions>
|
||||
<TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.2" />
|
||||
</Transitions>
|
||||
</avalonia:MaterialIcon.Transitions>
|
||||
</avalonia:MaterialIcon>
|
||||
|
||||
<TextBlock Classes="fadable"
|
||||
Classes.suspended="{Binding IsSuspended}"
|
||||
Grid.Column="1"
|
||||
Padding="0 5"
|
||||
FontWeight="SemiBold"
|
||||
FontSize="13"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding ProfileCategory.Name, FallbackValue='Profile name'}"
|
||||
PointerPressed="Title_OnPointerPressed"
|
||||
Background="Transparent">
|
||||
<TextBlock.Transitions>
|
||||
<Transitions>
|
||||
<DoubleTransition Property="Opacity" Duration="0:0:0.2" />
|
||||
</Transitions>
|
||||
</TextBlock.Transitions>
|
||||
</TextBlock>
|
||||
|
||||
<Border Classes="fadable"
|
||||
Classes.suspended="{Binding IsSuspended}"
|
||||
Grid.Column="1"
|
||||
BorderBrush="White"
|
||||
BorderThickness="0.5"
|
||||
Height="1">
|
||||
<Border.Transitions>
|
||||
<Transitions>
|
||||
<DoubleTransition Property="Opacity" Duration="0:0:0.2" />
|
||||
</Transitions>
|
||||
</Border.Transitions>
|
||||
</Border>
|
||||
|
||||
<Button Classes="category-button icon-button icon-button-small"
|
||||
Grid.Column="2"
|
||||
ToolTip.Tip="Edit category"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{Binding EditCategory}">
|
||||
<avalonia:MaterialIcon Kind="Cog" />
|
||||
</Button>
|
||||
<ToggleButton Classes="category-button icon-button icon-button-small"
|
||||
Grid.Column="3"
|
||||
ToolTip.Tip="Suspend category"
|
||||
Margin="5 0"
|
||||
IsChecked="{Binding IsSuspended}">
|
||||
<avalonia:MaterialIcon Kind="Pause" />
|
||||
</ToggleButton>
|
||||
<Button Classes="category-button icon-button icon-button-small"
|
||||
Grid.Column="4"
|
||||
ToolTip.Tip="Add profile"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{Binding AddProfile}">
|
||||
<avalonia:MaterialIcon Kind="Plus" />
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="1">
|
||||
<ListBox Classes="sidebar-listbox"
|
||||
Items="{Binding ProfileConfigurations}"
|
||||
SelectedItem="{Binding SelectedProfileConfiguration}"
|
||||
MinHeight="10"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled">
|
||||
<ListBox.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Paste">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="ContentPaste" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</ListBox.ContextMenu>
|
||||
</ListBox>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,25 @@
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarCategoryView : ReactiveUserControl<SidebarCategoryViewModel>
|
||||
{
|
||||
public SidebarCategoryView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void Title_OnPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (ViewModel != null)
|
||||
ViewModel.ShowItems = !ViewModel.ShowItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
<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>
|
||||
@@ -1,21 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
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;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services.Builders;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarCategoryViewModel : Conductor<SidebarProfileConfigurationViewModel>.Collection.AllActive, IDropTarget
|
||||
public class SidebarCategoryViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly ISidebarVmFactory _vmFactory;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IProfileService _profileService;
|
||||
private SidebarProfileConfigurationViewModel _selectedProfileConfiguration;
|
||||
private readonly DefaultDropHandler _defaultDropHandler;
|
||||
private bool _addingProfile;
|
||||
private readonly SidebarViewModel _sidebarViewModel;
|
||||
private readonly ISidebarVmFactory _vmFactory;
|
||||
private readonly IWindowService _windowService;
|
||||
private SidebarProfileConfigurationViewModel? _selectedProfileConfiguration;
|
||||
|
||||
public SidebarCategoryViewModel(ProfileCategory profileCategory,
|
||||
IProfileService profileService,
|
||||
IDialogService dialogService,
|
||||
ISidebarVmFactory vmFactory,
|
||||
IEventAggregator eventAggregator)
|
||||
public SidebarCategoryViewModel(SidebarViewModel sidebarViewModel, ProfileCategory profileCategory, IProfileService profileService, IWindowService windowService,
|
||||
IProfileEditorService profileEditorService, ISidebarVmFactory vmFactory)
|
||||
{
|
||||
_sidebarViewModel = sidebarViewModel;
|
||||
_profileService = profileService;
|
||||
_dialogService = dialogService;
|
||||
_windowService = windowService;
|
||||
_vmFactory = vmFactory;
|
||||
_eventAggregator = eventAggregator;
|
||||
_defaultDropHandler = new DefaultDropHandler();
|
||||
|
||||
ProfileCategory = profileCategory;
|
||||
|
||||
if (ShowItems)
|
||||
CreateProfileViewModels();
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
profileEditorService.ProfileConfiguration
|
||||
.Subscribe(p => SelectedProfileConfiguration = ProfileConfigurations.FirstOrDefault(c => ReferenceEquals(c.ProfileConfiguration, p)))
|
||||
.DisposeWith(disposables);
|
||||
this.WhenAnyValue(vm => vm.SelectedProfileConfiguration)
|
||||
.WhereNotNull()
|
||||
.Subscribe(s => profileEditorService.ChangeCurrentProfileConfiguration(s.ProfileConfiguration));
|
||||
});
|
||||
}
|
||||
|
||||
public ProfileCategory ProfileCategory { get; }
|
||||
|
||||
public ObservableCollection<SidebarProfileConfigurationViewModel> ProfileConfigurations { get; } = new();
|
||||
|
||||
public SidebarProfileConfigurationViewModel? SelectedProfileConfiguration
|
||||
{
|
||||
get => _selectedProfileConfiguration;
|
||||
set => RaiseAndSetIfChanged(ref _selectedProfileConfiguration, value);
|
||||
}
|
||||
|
||||
public bool ShowItems
|
||||
{
|
||||
get => !ProfileCategory.IsCollapsed;
|
||||
@@ -56,10 +63,12 @@ namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
ProfileCategory.IsCollapsed = !value;
|
||||
if (ProfileCategory.IsCollapsed)
|
||||
Items.Clear();
|
||||
ProfileConfigurations.Clear();
|
||||
else
|
||||
CreateProfileViewModels();
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
|
||||
this.RaisePropertyChanged(nameof(ShowItems));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,216 +78,46 @@ namespace Artemis.UI.Screens.Sidebar
|
||||
set
|
||||
{
|
||||
ProfileCategory.IsSuspended = value;
|
||||
NotifyOfPropertyChange(nameof(IsSuspended));
|
||||
this.RaisePropertyChanged(nameof(IsSuspended));
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
}
|
||||
}
|
||||
|
||||
public SidebarProfileConfigurationViewModel SelectedProfileConfiguration
|
||||
public async Task EditCategory()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
await _windowService.CreateContentDialog()
|
||||
.WithTitle("Edit category")
|
||||
.WithViewModel(out SidebarCategoryEditViewModel vm, ("category", ProfileCategory))
|
||||
.HavingPrimaryButton(b => b.WithText("Confirm").WithCommand(vm.Confirm))
|
||||
.HavingSecondaryButton(b => b.WithText("Delete").WithCommand(vm.Delete))
|
||||
.WithCloseButtonText("Cancel")
|
||||
.WithDefaultButton(ContentDialogButton.Primary)
|
||||
.ShowAsync();
|
||||
|
||||
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;
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
|
||||
public async Task AddProfile()
|
||||
{
|
||||
try
|
||||
ProfileConfiguration? result = await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, ProfileConfiguration?>(
|
||||
("profileCategory", ProfileCategory),
|
||||
("profileConfiguration", null)
|
||||
);
|
||||
if (result != null)
|
||||
{
|
||||
_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 = "Import 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);
|
||||
SidebarProfileConfigurationViewModel viewModel = _vmFactory.SidebarProfileConfigurationViewModel(_sidebarViewModel, result);
|
||||
ProfileConfigurations.Insert(0, viewModel);
|
||||
SelectedProfileConfiguration = viewModel;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateProfileViewModels()
|
||||
{
|
||||
Items.Clear();
|
||||
ProfileConfigurations.Clear();
|
||||
foreach (ProfileConfiguration profileConfiguration in ProfileCategory.ProfileConfigurations.OrderBy(p => p.Order))
|
||||
Items.Add(_vmFactory.SidebarProfileConfigurationViewModel(profileConfiguration));
|
||||
ProfileConfigurations.Add(_vmFactory.SidebarProfileConfigurationViewModel(_sidebarViewModel, profileConfiguration));
|
||||
|
||||
SelectedProfileConfiguration = Items.FirstOrDefault(i => i.ProfileConfiguration.IsBeingEdited);
|
||||
SelectedProfileConfiguration = ProfileConfigurations.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)
|
||||
{
|
||||
Execute.PostToUIThread(() =>
|
||||
{
|
||||
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()
|
||||
{
|
||||
if (ShowItems)
|
||||
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,120 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
xmlns:sidebar="clr-namespace:Artemis.UI.Screens.Sidebar"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Sidebar.SidebarProfileConfigurationView"
|
||||
x:DataType="sidebar:SidebarProfileConfigurationViewModel">
|
||||
<UserControl.Resources>
|
||||
<converters:ValuesAdditionConverter x:Key="ValuesAddition" />
|
||||
</UserControl.Resources>
|
||||
<UserControl.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="View properties">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="Cog" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Suspend">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="Pause" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Suspend all">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="Pause" />
|
||||
</MenuItem.Icon>
|
||||
<MenuItem Header="Above" CommandParameter="suspend" />
|
||||
<MenuItem Header="Below" CommandParameter="suspend" />
|
||||
</MenuItem>
|
||||
<MenuItem Header="Resume all">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="Play" />
|
||||
</MenuItem.Icon>
|
||||
<MenuItem Header="Above" CommandParameter="resume" />
|
||||
<MenuItem Header="Below" CommandParameter="resume" />
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Export">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="Export" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Duplicate">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="ContentDuplicate" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Copy">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="ContentCopy" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Paste">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="ContentPaste" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Delete">
|
||||
<MenuItem.Icon>
|
||||
<avalonia:MaterialIcon Kind="Trash" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</UserControl.ContextMenu>
|
||||
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
|
||||
<controls:ProfileConfigurationIcon Grid.Column="0"
|
||||
x:Name="ProfileIcon"
|
||||
VerticalAlignment="Center"
|
||||
ConfigurationIcon="{CompiledBinding ProfileConfiguration.Icon}"
|
||||
Width="20"
|
||||
Height="20" />
|
||||
|
||||
<TextBlock Grid.Column="1"
|
||||
x:Name="ProfileName"
|
||||
FontSize="12"
|
||||
Margin="10 0 0 0"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left"
|
||||
Text="{CompiledBinding ProfileConfiguration.Name}"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
|
||||
<Border Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{DynamicResource MaterialDesignBody}"
|
||||
Height="1"
|
||||
Opacity="0"
|
||||
HorizontalAlignment="Left">
|
||||
<!-- Ensure the line covers the profile and the text but not the full two columns -->
|
||||
<Border.Width>
|
||||
<MultiBinding Converter="{StaticResource ValuesAddition}">
|
||||
<Binding Path="ActualWidth" ElementName="ProfileIcon" />
|
||||
<Binding Path="Width" ElementName="ProfileName" />
|
||||
<Binding Path="Margin.Left" ElementName="ProfileName" />
|
||||
</MultiBinding>
|
||||
</Border.Width>
|
||||
|
||||
</Border>
|
||||
|
||||
<Button Command="{CompiledBinding EditProfile}"
|
||||
Classes="icon-button icon-button-small"
|
||||
Grid.Column="2"
|
||||
ToolTip.Tip="View properties"
|
||||
HorizontalAlignment="Right">
|
||||
<avalonia:MaterialIcon Kind="Cog" />
|
||||
</Button>
|
||||
<ToggleButton Classes="icon-button icon-button-small"
|
||||
Grid.Column="3"
|
||||
ToolTip.Tip="Suspend profile"
|
||||
Margin="2 0 0 0"
|
||||
IsChecked="{CompiledBinding IsSuspended}">
|
||||
<avalonia:MaterialIcon Kind="Pause" />
|
||||
</ToggleButton>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,19 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarProfileConfigurationView : ReactiveUserControl<SidebarProfileConfigurationViewModel>
|
||||
{
|
||||
public SidebarProfileConfigurationView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
<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>
|
||||
<converters:ValuesAdditionConverter x:Key="ValuesAddition" />
|
||||
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</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="Trash" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</UserControl.ContextMenu>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<shared:ProfileConfigurationIcon Grid.Column="0"
|
||||
x:Name="ProfileIcon"
|
||||
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"
|
||||
x:Name="ProfileName"
|
||||
FontSize="12"
|
||||
Margin="10 0 0 0"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left"
|
||||
Text="{Binding ProfileConfiguration.Name}"
|
||||
TextTrimming="CharacterEllipsis">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsProfileActive}" Value="False">
|
||||
<DataTrigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.33" />
|
||||
</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"
|
||||
HorizontalAlignment="Left">
|
||||
<!-- Ensure the line covers the profile and the text but not the full two columns -->
|
||||
<Border.Width>
|
||||
<MultiBinding Converter="{StaticResource ValuesAddition}">
|
||||
<Binding Path="ActualWidth" ElementName="ProfileIcon" />
|
||||
<Binding Path="ActualWidth" ElementName="ProfileName" />
|
||||
<Binding Path="Margin.Left" ElementName="ProfileName" />
|
||||
</MultiBinding>
|
||||
</Border.Width>
|
||||
<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"
|
||||
Visibility="{Binding ProfileConfiguration.BrokenState, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignIconForegroundButton}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<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}"
|
||||
Visibility="{Binding ProfileConfiguration.BrokenState, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
|
||||
<ToggleButton.Style>
|
||||
<Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignFlatToggleButton}">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<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>
|
||||
|
||||
<materialDesign:PackIcon Grid.Column="3"
|
||||
Margin="-2"
|
||||
Kind="AlertCircle"
|
||||
Height="22"
|
||||
Width="22"
|
||||
Foreground="#E74C4C"
|
||||
ToolTip="{Binding ProfileConfiguration.BrokenState}"
|
||||
Visibility="{Binding ProfileConfiguration.BrokenState, Converter={StaticResource NullToVisibilityConverter}}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,44 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.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;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarProfileConfigurationViewModel : Screen
|
||||
public class SidebarProfileConfigurationViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly SidebarViewModel _sidebarViewModel;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IWindowService _windowService;
|
||||
private ObservableAsPropertyHelper<bool>? _isSuspended;
|
||||
public ProfileConfiguration ProfileConfiguration { get; }
|
||||
|
||||
public SidebarProfileConfigurationViewModel(ProfileConfiguration profileConfiguration,
|
||||
IProfileService profileService,
|
||||
IDialogService dialogService,
|
||||
IEventAggregator eventAggregator)
|
||||
public SidebarProfileConfigurationViewModel(SidebarViewModel sidebarViewModel, ProfileConfiguration profileConfiguration, IProfileService profileService, IWindowService windowService)
|
||||
{
|
||||
_sidebarViewModel = sidebarViewModel;
|
||||
_profileService = profileService;
|
||||
_dialogService = dialogService;
|
||||
_eventAggregator = eventAggregator;
|
||||
_windowService = windowService;
|
||||
|
||||
ProfileConfiguration = profileConfiguration;
|
||||
EditProfile = ReactiveCommand.CreateFromTask(ExecuteEditProfile);
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_isSuspended = ProfileConfiguration.WhenAnyValue(c => c.IsSuspended)
|
||||
.ToProperty(this, vm => vm.IsSuspended)
|
||||
.DisposeWith(d);
|
||||
});
|
||||
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
|
||||
}
|
||||
|
||||
public ProfileConfiguration ProfileConfiguration { get; }
|
||||
public ReactiveCommand<Unit, Unit> EditProfile { get; }
|
||||
|
||||
public bool IsProfileActive => ProfileConfiguration.Profile != null;
|
||||
|
||||
public bool IsSuspended
|
||||
{
|
||||
get => ProfileConfiguration.IsSuspended;
|
||||
get => _isSuspended?.Value ?? false;
|
||||
set
|
||||
{
|
||||
ProfileConfiguration.IsSuspended = value;
|
||||
@@ -46,119 +50,15 @@ namespace Artemis.UI.Screens.Sidebar
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ViewProperties()
|
||||
public async Task ExecuteEditProfile()
|
||||
{
|
||||
object result = await _dialogService.ShowDialog<ProfileEditViewModel>(new Dictionary<string, object>
|
||||
{
|
||||
{"profileConfiguration", ProfileConfiguration},
|
||||
{"isNew", false}
|
||||
});
|
||||
ProfileConfiguration? edited = await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, ProfileConfiguration?>(
|
||||
("profileCategory", ProfileConfiguration.Category),
|
||||
("profileConfiguration", ProfileConfiguration)
|
||||
);
|
||||
|
||||
if (result is nameof(ProfileEditViewModel.Delete))
|
||||
await Delete();
|
||||
if (edited != null)
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
string path = Path.ChangeExtension(dialog.FileName, ".json");
|
||||
await File.WriteAllTextAsync(path, 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,12 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Sidebar.SidebarScreenView">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<avalonia:MaterialIcon Kind="{Binding Icon}" Width="16" Height="16" />
|
||||
<TextBlock FontSize="12" Margin="10 0" VerticalAlignment="Center" Text="{Binding DisplayName}" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,18 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public partial class SidebarScreenView : UserControl
|
||||
{
|
||||
public SidebarScreenView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<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>
|
||||
@@ -1,31 +1,37 @@
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using System;
|
||||
using Artemis.UI.Shared;
|
||||
using Material.Icons;
|
||||
using Ninject;
|
||||
using Ninject.Parameters;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarScreenViewModel<T> : SidebarScreenViewModel where T : MainScreenViewModel
|
||||
{
|
||||
public SidebarScreenViewModel(PackIconKind icon, string displayName) : base(icon, displayName)
|
||||
public SidebarScreenViewModel(MaterialIconKind icon, string displayName) : base(icon, displayName)
|
||||
{
|
||||
}
|
||||
|
||||
public override MainScreenViewModel CreateInstance(IKernel kernel)
|
||||
public override Type ScreenType => typeof(T);
|
||||
|
||||
public override MainScreenViewModel CreateInstance(IKernel kernel, IScreen screen)
|
||||
{
|
||||
return kernel.Get<T>();
|
||||
return kernel.Get<T>(new ConstructorArgument("hostScreen", screen));
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SidebarScreenViewModel
|
||||
public abstract class SidebarScreenViewModel : ViewModelBase
|
||||
{
|
||||
protected SidebarScreenViewModel(PackIconKind icon, string displayName)
|
||||
protected SidebarScreenViewModel(MaterialIconKind icon, string displayName)
|
||||
{
|
||||
Icon = icon;
|
||||
DisplayName = displayName;
|
||||
}
|
||||
|
||||
public PackIconKind Icon { get; }
|
||||
public string DisplayName { get; }
|
||||
public MaterialIconKind Icon { get; }
|
||||
|
||||
public abstract MainScreenViewModel CreateInstance(IKernel kernel);
|
||||
public abstract Type ScreenType { get; }
|
||||
public abstract MainScreenViewModel CreateInstance(IKernel kernel, IScreen screen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:svg="clr-namespace:Avalonia.Svg.Skia;assembly=Avalonia.Svg.Skia"
|
||||
mc:Ignorable="d" d:DesignWidth="240" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Sidebar.SidebarView">
|
||||
<Grid RowDefinitions="60,Auto,Auto,*,Auto,Auto">
|
||||
<Grid Grid.Row="0" IsHitTestVisible="False" ColumnDefinitions="Auto,*">
|
||||
<Image Grid.Column="0">
|
||||
<Image.Source>
|
||||
<svg:SvgImage Source="/Assets/Images/Logo/bow.svg" />
|
||||
</Image.Source>
|
||||
</Image>
|
||||
<TextBlock Grid.Column="1"
|
||||
FontSize="24"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource MaterialDesignDarkForeground}">
|
||||
Artemis 2
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
|
||||
<!-- Built-in screens -->
|
||||
<ListBox Classes="sidebar-listbox"
|
||||
Grid.Row="1"
|
||||
Margin="10 2"
|
||||
Items="{Binding SidebarScreens}"
|
||||
SelectedItem="{Binding SelectedSidebarScreen}" />
|
||||
<Separator Grid.Row="2" Margin="8" Height="1" Background="#FF6c6c6c" />
|
||||
|
||||
<!-- Categories -->
|
||||
<ScrollViewer Grid.Row="3" VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel>
|
||||
<ItemsControl Margin="10 2" Items="{Binding SidebarCategories}" />
|
||||
<Button Content="Add new category"
|
||||
Margin="10"
|
||||
HorizontalAlignment="Stretch"
|
||||
Command="{Binding AddCategory}" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- Bottom buttons -->
|
||||
<Separator Grid.Row="4" Margin="8" />
|
||||
<WrapPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5 0 5 5">
|
||||
<controls:HyperlinkButton Classes="icon-button"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip.Tip="View website"
|
||||
NavigateUri="https://artemis-rgb.com">
|
||||
<avalonia:MaterialIcon Kind="Web" Width="20" Height="20" />
|
||||
</controls:HyperlinkButton>
|
||||
<controls:HyperlinkButton Classes="icon-button"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip.Tip="View GitHub repository"
|
||||
NavigateUri="https://github.com/Artemis-RGB/Artemis">
|
||||
<avalonia:MaterialIcon Kind="Github" Width="20" Height="20" />
|
||||
</controls:HyperlinkButton>
|
||||
<controls:HyperlinkButton Classes="icon-button"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip.Tip="View Wiki"
|
||||
NavigateUri="https://wiki.artemis-rgb.com">
|
||||
<avalonia:MaterialIcon Kind="BookOpenOutline" Width="20" Height="20" />
|
||||
</controls:HyperlinkButton>
|
||||
<controls:HyperlinkButton Classes="icon-button"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip.Tip="Join our Discord"
|
||||
NavigateUri="https://discord.gg/S3MVaC9">
|
||||
<avalonia:MaterialIcon Kind="Discord" Width="20" Height="20" />
|
||||
</controls:HyperlinkButton>
|
||||
<controls:HyperlinkButton Classes="icon-button"
|
||||
Width="44"
|
||||
Height="44"
|
||||
ToolTip.Tip="View donation options"
|
||||
NavigateUri="https://wiki.artemis-rgb.com/en/donating">
|
||||
<avalonia:MaterialIcon Kind="Gift" Width="20" Height="20" />
|
||||
</controls:HyperlinkButton>
|
||||
</WrapPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,18 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarView : ReactiveUserControl<SidebarViewModel>
|
||||
{
|
||||
public SidebarView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Sidebar.SidebarView"
|
||||
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:sidebar="clr-namespace:Artemis.UI.Screens.Sidebar"
|
||||
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}">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="ArtemisSidebar.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
|
||||
</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>
|
||||
|
||||
<Grid Grid.Row="0" ClipToBounds="True">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<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>
|
||||
|
||||
<!-- Built-in screens -->
|
||||
<ListBox Grid.Row="1"
|
||||
Margin="0 2"
|
||||
ItemContainerStyle="{StaticResource SidebarListBoxItem}"
|
||||
ItemsSource="{Binding SidebarScreens}"
|
||||
SelectedItem="{Binding SelectedSidebarScreen}"
|
||||
IsEnabled="{Binding ActivatingProfile, Converter={StaticResource InverseBooleanConverter}}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Separator Grid.Row="2" Margin="8" />
|
||||
|
||||
<!-- 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}">
|
||||
<Border Background="{DynamicResource MaterialDesignTextFieldBoxHoverBackground}"
|
||||
Padding="10"
|
||||
CornerRadius="4">
|
||||
<TextBlock Text="{Binding ProfileCategory.Name}" 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"
|
||||
IsEnabled="{Binding DataContext.ActivatingProfile, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource InverseBooleanConverter}}" />
|
||||
</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" />
|
||||
<WrapPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Left" 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>
|
||||
</WrapPanel>
|
||||
</Grid>
|
||||
</materialDesign:DialogHost>
|
||||
</UserControl>
|
||||
@@ -1,250 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
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.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.Services;
|
||||
using GongSolutions.Wpf.DragDrop;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services.Builders;
|
||||
using Artemis.UI.Shared.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Material.Icons;
|
||||
using Ninject;
|
||||
using ReactiveUI;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public sealed class SidebarViewModel : Conductor<SidebarCategoryViewModel>.Collection.AllActive, IHandle<RequestSelectSidebarItemEvent>, IDropTarget
|
||||
public class SidebarViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly IKernel _kernel;
|
||||
private readonly ISidebarVmFactory _sidebarVmFactory;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IScreen _hostScreen;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IDialogService _dialogService;
|
||||
private ArtemisDevice _headerDevice;
|
||||
private SidebarScreenViewModel _selectedSidebarScreen;
|
||||
private MainScreenViewModel _selectedScreen;
|
||||
private readonly SidebarScreenViewModel<ProfileEditorViewModel> _profileEditor;
|
||||
private readonly DefaultDropHandler _defaultDropHandler;
|
||||
private bool _activatingProfile;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly ISidebarVmFactory _sidebarVmFactory;
|
||||
private readonly IWindowService _windowService;
|
||||
private ArtemisDevice? _headerDevice;
|
||||
|
||||
public SidebarViewModel(IKernel kernel,
|
||||
IEventAggregator eventAggregator,
|
||||
ISidebarVmFactory sidebarVmFactory,
|
||||
IRgbService rgbService,
|
||||
IProfileService profileService,
|
||||
IProfileEditorService profileEditorService,
|
||||
IDialogService dialogService)
|
||||
private SidebarScreenViewModel? _selectedSidebarScreen;
|
||||
|
||||
|
||||
public SidebarViewModel(IScreen hostScreen, IKernel kernel, IProfileService profileService, IRgbService rgbService, IWindowService windowService,
|
||||
IProfileEditorService profileEditorService, ISidebarVmFactory sidebarVmFactory, IProfileEditorVmFactory profileEditorVmFactory)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_sidebarVmFactory = sidebarVmFactory;
|
||||
_rgbService = rgbService;
|
||||
_hostScreen = hostScreen;
|
||||
_profileService = profileService;
|
||||
_rgbService = rgbService;
|
||||
_windowService = windowService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_dialogService = dialogService;
|
||||
_profileEditor = new SidebarScreenViewModel<ProfileEditorViewModel>(PackIconKind.Wrench, "Profile Editor");
|
||||
_defaultDropHandler = new DefaultDropHandler();
|
||||
_sidebarVmFactory = sidebarVmFactory;
|
||||
|
||||
eventAggregator.Subscribe(this);
|
||||
|
||||
SidebarScreens = new BindableCollection<SidebarScreenViewModel>
|
||||
SidebarScreens = new ObservableCollection<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")
|
||||
new SidebarScreenViewModel<HomeViewModel>(MaterialIconKind.Home, "Home"),
|
||||
new SidebarScreenViewModel<WorkshopViewModel>(MaterialIconKind.TestTube, "Workshop"),
|
||||
new SidebarScreenViewModel<SurfaceEditorViewModel>(MaterialIconKind.Devices, "Surface Editor"),
|
||||
new SidebarScreenViewModel<SettingsViewModel>(MaterialIconKind.Cog, "Settings")
|
||||
};
|
||||
SelectedSidebarScreen = SidebarScreens.First();
|
||||
_selectedSidebarScreen = SidebarScreens.First();
|
||||
|
||||
UpdateProfileCategories();
|
||||
UpdateHeaderDevice();
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
this.WhenAnyObservable(vm => vm._hostScreen.Router.CurrentViewModel)
|
||||
.WhereNotNull()
|
||||
.Subscribe(c => SelectedSidebarScreen = SidebarScreens.FirstOrDefault(s => s.ScreenType == c.GetType()))
|
||||
.DisposeWith(disposables);
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedSidebarScreen)
|
||||
.WhereNotNull()
|
||||
.Subscribe(s =>
|
||||
{
|
||||
_hostScreen.Router.Navigate.Execute(s.CreateInstance(kernel, _hostScreen));
|
||||
profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||
});
|
||||
|
||||
this.WhenAnyObservable(vm => vm._profileEditorService.ProfileConfiguration)
|
||||
.Subscribe(profile =>
|
||||
{
|
||||
if (profile == null && _hostScreen.Router.GetCurrentViewModel() is ProfileEditorViewModel)
|
||||
SelectedSidebarScreen = SidebarScreens.FirstOrDefault();
|
||||
else if (profile != null && _hostScreen.Router.GetCurrentViewModel() is not ProfileEditorViewModel)
|
||||
_hostScreen.Router.Navigate.Execute(profileEditorVmFactory.ProfileEditorViewModel(_hostScreen));
|
||||
})
|
||||
.DisposeWith(disposables);
|
||||
});
|
||||
}
|
||||
|
||||
public ObservableCollection<SidebarScreenViewModel> SidebarScreens { get; }
|
||||
public ObservableCollection<SidebarCategoryViewModel> SidebarCategories { get; } = new();
|
||||
|
||||
public ArtemisDevice? HeaderDevice
|
||||
{
|
||||
get => _headerDevice;
|
||||
set => RaiseAndSetIfChanged(ref _headerDevice, value);
|
||||
}
|
||||
|
||||
public SidebarScreenViewModel? SelectedSidebarScreen
|
||||
{
|
||||
get => _selectedSidebarScreen;
|
||||
set => RaiseAndSetIfChanged(ref _selectedSidebarScreen, value);
|
||||
}
|
||||
|
||||
public SidebarCategoryViewModel AddProfileCategoryViewModel(ProfileCategory profileCategory)
|
||||
{
|
||||
SidebarCategoryViewModel viewModel = _sidebarVmFactory.SidebarCategoryViewModel(this, profileCategory);
|
||||
SidebarCategories.Add(viewModel);
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public async Task AddCategory()
|
||||
{
|
||||
await _windowService.CreateContentDialog()
|
||||
.WithTitle("Add new category")
|
||||
.WithViewModel(out SidebarCategoryEditViewModel vm, ("category", null))
|
||||
.HavingPrimaryButton(b => b.WithText("Confirm").WithCommand(vm.Confirm))
|
||||
.WithCloseButtonText("Cancel")
|
||||
.WithDefaultButton(ContentDialogButton.Primary)
|
||||
.ShowAsync();
|
||||
|
||||
UpdateProfileCategories();
|
||||
}
|
||||
|
||||
public void UpdateProfileCategories()
|
||||
{
|
||||
SidebarCategories.Clear();
|
||||
foreach (ProfileCategory profileCategory in _profileService.ProfileCategories.OrderBy(p => p.Order))
|
||||
AddProfileCategoryViewModel(profileCategory);
|
||||
}
|
||||
|
||||
private void UpdateHeaderDevice()
|
||||
{
|
||||
HeaderDevice = _rgbService.Devices.FirstOrDefault(d => d.DeviceType == RGBDeviceType.Keyboard && d.Layout is {IsValid: true});
|
||||
}
|
||||
|
||||
public ArtemisDevice HeaderDevice
|
||||
{
|
||||
get => _headerDevice;
|
||||
set => SetAndNotify(ref _headerDevice, value);
|
||||
}
|
||||
|
||||
public BindableCollection<SidebarScreenViewModel> SidebarScreens { get; }
|
||||
|
||||
public MainScreenViewModel SelectedScreen
|
||||
{
|
||||
get => _selectedScreen;
|
||||
private set => SetAndNotify(ref _selectedScreen, value);
|
||||
}
|
||||
|
||||
public SidebarScreenViewModel SelectedSidebarScreen
|
||||
{
|
||||
get => _selectedSidebarScreen;
|
||||
set
|
||||
{
|
||||
if (SetAndNotify(ref _selectedSidebarScreen, value))
|
||||
ActivateScreenViewModel(_selectedSidebarScreen);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ActivatingProfile
|
||||
{
|
||||
get => _activatingProfile;
|
||||
set => SetAndNotify(ref _activatingProfile, value);
|
||||
}
|
||||
|
||||
private void ActivateScreenViewModel(SidebarScreenViewModel screenViewModel)
|
||||
{
|
||||
SelectedScreen = screenViewModel.CreateInstance(_kernel);
|
||||
OnSelectedScreenChanged();
|
||||
if (screenViewModel != _profileEditor)
|
||||
SelectProfileConfiguration(null);
|
||||
}
|
||||
|
||||
private void UpdateProfileCategories()
|
||||
{
|
||||
foreach (ProfileCategory profileCategory in _profileService.ProfileCategories.OrderBy(p => p.Order))
|
||||
AddProfileCategoryViewModel(profileCategory);
|
||||
}
|
||||
|
||||
public async Task AddCategory()
|
||||
{
|
||||
object result = await _dialogService.ShowDialog<SidebarCategoryCreateViewModel>();
|
||||
if (result is ProfileCategory profileCategory)
|
||||
AddProfileCategoryViewModel(profileCategory);
|
||||
|
||||
((BindableCollection<SidebarCategoryViewModel>) Items).Sort(p => p.ProfileCategory.Order);
|
||||
}
|
||||
|
||||
public void OpenUrl(string url)
|
||||
{
|
||||
Core.Utilities.OpenUrl(url);
|
||||
}
|
||||
|
||||
public void Handle(RequestSelectSidebarItemEvent message)
|
||||
{
|
||||
SidebarScreenViewModel requested = null;
|
||||
if (message.DisplayName != null)
|
||||
requested = SidebarScreens.FirstOrDefault(s => s.DisplayName == message.DisplayName);
|
||||
else
|
||||
requested = message.ViewModel;
|
||||
|
||||
if (requested != null)
|
||||
SelectedSidebarScreen = requested;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (profileConfiguration?.BrokenStateException != null)
|
||||
{
|
||||
_dialogService.ShowExceptionDialog("The profile failed to load", profileConfiguration.BrokenStateException);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (SidebarCategoryViewModel sidebarCategoryViewModel in Items)
|
||||
sidebarCategoryViewModel.SelectedProfileConfiguration = sidebarCategoryViewModel.Items.FirstOrDefault(i => i.ProfileConfiguration == profileConfiguration);
|
||||
|
||||
if (_profileEditorService.SuspendEditing)
|
||||
_profileEditorService.SuspendEditing = false;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
ActivatingProfile = true;
|
||||
_profileEditorService.ChangeSelectedProfileConfiguration(profileConfiguration);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ActivatingProfile = false;
|
||||
}
|
||||
|
||||
if (profileConfiguration == null)
|
||||
return;
|
||||
|
||||
Execute.PostToUIThread(() =>
|
||||
{
|
||||
// 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()
|
||||
{
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnClose()
|
||||
{
|
||||
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