mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Code style - Use file scoped namespaces
Code style - Ran code cleanup
This commit is contained in:
1 parent
e68e16df4d
commit
f6090dc296
691 files changed
+37301
-38119
No files matched your search
@@ -1,13 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Screens.ProfileEditor.ProfileTree;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Generators;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.VisualTree;
|
||||
using Avalonia.Xaml.Interactions.DragAndDrop;
|
||||
|
||||
@@ -15,6 +9,30 @@ namespace Artemis.UI.Screens.Sidebar.Behaviors;
|
||||
|
||||
public class SidebarCategoryViewDropHandler : DropHandlerBase
|
||||
{
|
||||
public override bool Validate(object? sender, DragEventArgs e, object? sourceContext, object? targetContext, object? state)
|
||||
{
|
||||
if (sender is ItemsControl itemsControl)
|
||||
foreach (ItemContainerInfo? item in itemsControl.ItemContainerGenerator.Containers)
|
||||
SetDraggingPseudoClasses(item.ContainerControl, false, false);
|
||||
|
||||
if (e.Source is IControl && sender is ListBox listBox)
|
||||
return Validate(listBox, e, sourceContext, targetContext, false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Execute(object? sender, DragEventArgs e, object? sourceContext, object? targetContext, object? state)
|
||||
{
|
||||
if (sender is ItemsControl itemsControl)
|
||||
foreach (ItemContainerInfo? item in itemsControl.ItemContainerGenerator.Containers)
|
||||
SetDraggingPseudoClasses(item.ContainerControl, false, false);
|
||||
|
||||
if (e.Source is IControl && sender is ListBox listBox)
|
||||
return Validate(listBox, e, sourceContext, targetContext, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool Validate(ListBox listBox, DragEventArgs e, object? sourceContext, object? targetContext, bool bExecute)
|
||||
{
|
||||
if (sourceContext is not SidebarProfileConfigurationViewModel sourceItem || targetContext is not SidebarCategoryViewModel vm ||
|
||||
@@ -33,7 +51,7 @@ public class SidebarCategoryViewDropHandler : DropHandlerBase
|
||||
if (targetVisual != null)
|
||||
{
|
||||
Point positionInTarget = e.GetPosition(targetVisual);
|
||||
if (positionInTarget.Y > (targetVisual.Bounds.Height / 2))
|
||||
if (positionInTarget.Y > targetVisual.Bounds.Height / 2)
|
||||
before = false;
|
||||
}
|
||||
}
|
||||
@@ -63,38 +81,6 @@ public class SidebarCategoryViewDropHandler : DropHandlerBase
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Validate(object? sender, DragEventArgs e, object? sourceContext, object? targetContext, object? state)
|
||||
{
|
||||
if (sender is ItemsControl itemsControl)
|
||||
{
|
||||
foreach (ItemContainerInfo? item in itemsControl.ItemContainerGenerator.Containers)
|
||||
SetDraggingPseudoClasses(item.ContainerControl, false, false);
|
||||
}
|
||||
|
||||
if (e.Source is IControl && sender is ListBox listBox)
|
||||
{
|
||||
return Validate(listBox, e, sourceContext, targetContext, false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Execute(object? sender, DragEventArgs e, object? sourceContext, object? targetContext, object? state)
|
||||
{
|
||||
if (sender is ItemsControl itemsControl)
|
||||
{
|
||||
foreach (ItemContainerInfo? item in itemsControl.ItemContainerGenerator.Containers)
|
||||
SetDraggingPseudoClasses(item.ContainerControl, false, false);
|
||||
}
|
||||
|
||||
if (e.Source is IControl && sender is ListBox listBox)
|
||||
{
|
||||
return Validate(listBox, e, sourceContext, targetContext, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SetDraggingPseudoClasses(IControl control, bool dragging, bool before)
|
||||
{
|
||||
if (!dragging)
|
||||
|
||||
@@ -3,19 +3,18 @@ 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());
|
||||
}
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
public class SidebarCategoryEditView : ReactiveUserControl<SidebarCategoryEditViewModel>
|
||||
{
|
||||
public SidebarCategoryEditView()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.WhenActivated(_ => this.ClearAllDataValidationErrors());
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -6,55 +6,56 @@ using FluentAvalonia.UI.Controls;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Validation.Extensions;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
public class SidebarCategoryEditViewModel : ContentDialogViewModelBase
|
||||
{
|
||||
public class SidebarCategoryEditViewModel : ContentDialogViewModelBase
|
||||
private readonly ProfileCategory? _category;
|
||||
private readonly IProfileService _profileService;
|
||||
private string? _categoryName;
|
||||
|
||||
public SidebarCategoryEditViewModel(IProfileService profileService, ProfileCategory? category)
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly ProfileCategory? _category;
|
||||
private string? _categoryName;
|
||||
_profileService = profileService;
|
||||
_category = category;
|
||||
|
||||
public SidebarCategoryEditViewModel(IProfileService profileService, ProfileCategory? 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 => RaiseAndSetIfChanged(ref _categoryName, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Confirm { get; }
|
||||
|
||||
private void ExecuteConfirm()
|
||||
{
|
||||
if (_category != null)
|
||||
{
|
||||
_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");
|
||||
_category.Name = CategoryName!;
|
||||
_profileService.SaveProfileCategory(_category);
|
||||
}
|
||||
else
|
||||
{
|
||||
_profileService.CreateProfileCategory(CategoryName!);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Delete { get; set; }
|
||||
ContentDialog?.Hide(ContentDialogResult.Primary);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
private void ExecuteDelete()
|
||||
{
|
||||
if (_category != null)
|
||||
_profileService.DeleteProfileCategory(_category);
|
||||
}
|
||||
}
|
||||
@@ -6,23 +6,22 @@ using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public partial class ProfileConfigurationEditView : ReactiveCoreWindow<ProfileConfigurationEditViewModel>
|
||||
{
|
||||
public ProfileConfigurationEditView()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.WhenActivated(d => ViewModel.WhenAnyValue(vm => vm.SelectedBitmapSource).Subscribe(_ => this.Get<Border>("FillPreview").InvalidateVisual()).DisposeWith(d));
|
||||
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
public class ProfileConfigurationEditView : ReactiveCoreWindow<ProfileConfigurationEditViewModel>
|
||||
{
|
||||
public ProfileConfigurationEditView()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.WhenActivated(d => ViewModel.WhenAnyValue(vm => vm.SelectedBitmapSource).Subscribe(_ => this.Get<Border>("FillPreview").InvalidateVisual()).DisposeWith(d));
|
||||
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -19,287 +19,284 @@ using Material.Icons;
|
||||
using Newtonsoft.Json;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConfiguration?>
|
||||
{
|
||||
public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConfiguration?>
|
||||
private readonly ObservableAsPropertyHelper<ModuleActivationRequirementsViewModel?> _moduleActivationRequirementsViewModel;
|
||||
private readonly ProfileCategory _profileCategory;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IProfileService _profileService;
|
||||
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;
|
||||
|
||||
public ProfileConfigurationEditViewModel(
|
||||
ProfileCategory profileCategory,
|
||||
ProfileConfiguration? profileConfiguration,
|
||||
IWindowService windowService,
|
||||
IProfileService profileService,
|
||||
IProfileEditorService profileEditorService,
|
||||
IPluginManagementService pluginManagementService,
|
||||
INodeVmFactory nodeVmFactory)
|
||||
{
|
||||
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 readonly ObservableAsPropertyHelper<ModuleActivationRequirementsViewModel?> _moduleActivationRequirementsViewModel;
|
||||
_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};
|
||||
|
||||
public ProfileConfigurationEditViewModel(
|
||||
ProfileCategory profileCategory,
|
||||
ProfileConfiguration? profileConfiguration,
|
||||
IWindowService windowService,
|
||||
IProfileService profileService,
|
||||
IProfileEditorService profileEditorService,
|
||||
IPluginManagementService pluginManagementService,
|
||||
INodeVmFactory nodeVmFactory)
|
||||
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))
|
||||
);
|
||||
Modules.Insert(0, null);
|
||||
_selectedModule = Modules.FirstOrDefault(m => m?.Module == _profileConfiguration.Module);
|
||||
|
||||
VisualEditorViewModel = nodeVmFactory.NodeScriptViewModel(_profileConfiguration.ActivationCondition, true);
|
||||
|
||||
BrowseBitmapFile = ReactiveCommand.CreateFromTask(ExecuteBrowseBitmapFile);
|
||||
OpenConditionEditor = ReactiveCommand.CreateFromTask(ExecuteOpenConditionEditor);
|
||||
Confirm = ReactiveCommand.CreateFromTask(ExecuteConfirm);
|
||||
Import = ReactiveCommand.CreateFromTask(ExecuteImport);
|
||||
Delete = ReactiveCommand.CreateFromTask(ExecuteDelete);
|
||||
Cancel = ReactiveCommand.Create(ExecuteCancel);
|
||||
|
||||
_moduleActivationRequirementsViewModel = this.WhenAnyValue(vm => vm.SelectedModule)
|
||||
.Select(m => m != null ? new ModuleActivationRequirementsViewModel(m.Module) : null)
|
||||
.ToProperty(this, vm => vm.ModuleActivationRequirementsViewModel);
|
||||
|
||||
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 NodeScriptViewModel VisualEditorViewModel { get; }
|
||||
public ModuleActivationRequirementsViewModel? ModuleActivationRequirementsViewModel => _moduleActivationRequirementsViewModel.Value;
|
||||
|
||||
public ReactiveCommand<Unit, Unit> OpenConditionEditor { get; }
|
||||
public ReactiveCommand<Unit, Unit> BrowseBitmapFile { get; }
|
||||
public ReactiveCommand<Unit, Unit> Confirm { get; }
|
||||
public ReactiveCommand<Unit, Unit> Import { get; }
|
||||
public ReactiveCommand<Unit, Unit> Delete { get; }
|
||||
public ReactiveCommand<Unit, Unit> Cancel { get; }
|
||||
|
||||
private async Task ExecuteImport()
|
||||
{
|
||||
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
|
||||
{
|
||||
_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))
|
||||
);
|
||||
Modules.Insert(0, null);
|
||||
_selectedModule = Modules.FirstOrDefault(m => m?.Module == _profileConfiguration.Module);
|
||||
|
||||
VisualEditorViewModel = nodeVmFactory.NodeScriptViewModel(_profileConfiguration.ActivationCondition, true);
|
||||
|
||||
BrowseBitmapFile = ReactiveCommand.CreateFromTask(ExecuteBrowseBitmapFile);
|
||||
OpenConditionEditor = ReactiveCommand.CreateFromTask(ExecuteOpenConditionEditor);
|
||||
Confirm = ReactiveCommand.CreateFromTask(ExecuteConfirm);
|
||||
Import = ReactiveCommand.CreateFromTask(ExecuteImport);
|
||||
Delete = ReactiveCommand.CreateFromTask(ExecuteDelete);
|
||||
Cancel = ReactiveCommand.Create(ExecuteCancel);
|
||||
|
||||
_moduleActivationRequirementsViewModel = this.WhenAnyValue(vm => vm.SelectedModule)
|
||||
.Select(m => m != null ? new ModuleActivationRequirementsViewModel(m.Module) : null)
|
||||
.ToProperty(this, vm => vm.ModuleActivationRequirementsViewModel);
|
||||
|
||||
Dispatcher.UIThread.Post(LoadIcon, DispatcherPriority.Background);
|
||||
profileConfigurationExportModel = JsonConvert.DeserializeObject<ProfileConfigurationExportModel>(json, IProfileService.ExportSettings);
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
_windowService.ShowExceptionDialog("Import profile failed", e);
|
||||
}
|
||||
|
||||
public bool IsNew { get; }
|
||||
|
||||
public ProfileConfiguration ProfileConfiguration
|
||||
if (profileConfigurationExportModel == null)
|
||||
{
|
||||
get => _profileConfiguration;
|
||||
set => RaiseAndSetIfChanged(ref _profileConfiguration, value);
|
||||
await _windowService.ShowConfirmContentDialog("Import profile", "Failed to import this profile, make sure it is a valid Artemis profile.", "Confirm", null);
|
||||
return;
|
||||
}
|
||||
|
||||
public string ProfileName
|
||||
try
|
||||
{
|
||||
get => _profileName;
|
||||
set => RaiseAndSetIfChanged(ref _profileName, value);
|
||||
ProfileConfiguration profileConfiguration = _profileService.ImportProfile(_profileCategory, profileConfigurationExportModel);
|
||||
|
||||
// Remove the temporary profile configuration
|
||||
_profileService.RemoveProfileConfiguration(_profileConfiguration);
|
||||
|
||||
Close(profileConfiguration);
|
||||
}
|
||||
|
||||
public ProfileConfigurationHotkeyMode HotkeyMode
|
||||
catch (Exception e)
|
||||
{
|
||||
get => _hotkeyMode;
|
||||
set => RaiseAndSetIfChanged(ref _hotkeyMode, value);
|
||||
_windowService.ShowExceptionDialog("Import profile failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Hotkey? EnableHotkey
|
||||
{
|
||||
get => _enableHotkey;
|
||||
set => RaiseAndSetIfChanged(ref _enableHotkey, value);
|
||||
}
|
||||
private async Task ExecuteDelete()
|
||||
{
|
||||
if (IsNew)
|
||||
return;
|
||||
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
|
||||
return;
|
||||
|
||||
public Hotkey? DisableHotkey
|
||||
{
|
||||
get => _disableHotkey;
|
||||
set => RaiseAndSetIfChanged(ref _disableHotkey, value);
|
||||
}
|
||||
if (_profileConfiguration.IsBeingEdited)
|
||||
_profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||
_profileService.RemoveProfileConfiguration(_profileConfiguration);
|
||||
Close(_profileConfiguration);
|
||||
}
|
||||
|
||||
public ObservableCollection<ProfileModuleViewModel?> Modules { get; }
|
||||
private async Task ExecuteConfirm()
|
||||
{
|
||||
ProfileConfiguration.Name = ProfileName;
|
||||
ProfileConfiguration.Module = SelectedModule?.Module;
|
||||
ProfileConfiguration.HotkeyMode = HotkeyMode;
|
||||
ProfileConfiguration.EnableHotkey = EnableHotkey;
|
||||
ProfileConfiguration.DisableHotkey = DisableHotkey;
|
||||
|
||||
public ProfileModuleViewModel? SelectedModule
|
||||
{
|
||||
get => _selectedModule;
|
||||
set => RaiseAndSetIfChanged(ref _selectedModule, value);
|
||||
}
|
||||
await SaveIcon();
|
||||
|
||||
public NodeScriptViewModel VisualEditorViewModel { get; }
|
||||
public ModuleActivationRequirementsViewModel? ModuleActivationRequirementsViewModel => _moduleActivationRequirementsViewModel.Value;
|
||||
_profileService.SaveProfileConfigurationIcon(ProfileConfiguration);
|
||||
_profileService.SaveProfileCategory(_profileCategory);
|
||||
Close(ProfileConfiguration);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> OpenConditionEditor { get; }
|
||||
public ReactiveCommand<Unit, Unit> BrowseBitmapFile { get; }
|
||||
public ReactiveCommand<Unit, Unit> Confirm { get; }
|
||||
public ReactiveCommand<Unit, Unit> Import { get; }
|
||||
public ReactiveCommand<Unit, Unit> Delete { get; }
|
||||
public ReactiveCommand<Unit, Unit> Cancel { get; }
|
||||
private void ExecuteCancel()
|
||||
{
|
||||
if (IsNew)
|
||||
_profileService.RemoveProfileConfiguration(_profileConfiguration);
|
||||
Close(null);
|
||||
}
|
||||
|
||||
private async Task ExecuteImport()
|
||||
{
|
||||
if (!IsNew)
|
||||
return;
|
||||
#region Icon
|
||||
|
||||
string[]? result = await _windowService.CreateOpenFileDialog()
|
||||
.HavingFilter(f => f.WithExtension("json").WithName("Artemis profile"))
|
||||
.ShowAsync();
|
||||
public ProfileConfigurationIconType IconType
|
||||
{
|
||||
get => _iconType;
|
||||
set => RaiseAndSetIfChanged(ref _iconType, value);
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
return;
|
||||
public ObservableCollection<ProfileIconViewModel>? MaterialIcons
|
||||
{
|
||||
get => _materialIcons;
|
||||
set => RaiseAndSetIfChanged(ref _materialIcons, value);
|
||||
}
|
||||
|
||||
string json = await File.ReadAllTextAsync(result[0]);
|
||||
ProfileConfigurationExportModel? profileConfigurationExportModel = null;
|
||||
public ProfileIconViewModel? SelectedMaterialIcon
|
||||
{
|
||||
get => _selectedMaterialIcon;
|
||||
set => RaiseAndSetIfChanged(ref _selectedMaterialIcon, value);
|
||||
}
|
||||
|
||||
public Bitmap? SelectedBitmapSource
|
||||
{
|
||||
get => _selectedBitmapSource;
|
||||
set => RaiseAndSetIfChanged(ref _selectedBitmapSource, value);
|
||||
}
|
||||
|
||||
private void LoadIcon()
|
||||
{
|
||||
// Preselect the icon based on streams if needed
|
||||
if (_profileConfiguration.Icon.IconType == ProfileConfigurationIconType.BitmapImage)
|
||||
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;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProfileConfiguration profileConfiguration = _profileService.ImportProfile(_profileCategory, profileConfigurationExportModel);
|
||||
|
||||
// Remove the temporary profile configuration
|
||||
_profileService.RemoveProfileConfiguration(_profileConfiguration);
|
||||
|
||||
Close(profileConfiguration);
|
||||
SelectedBitmapSource = new Bitmap(_profileConfiguration.Icon.GetIconStream());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_windowService.ShowExceptionDialog("Import profile failed", e);
|
||||
_windowService.ShowConfirmContentDialog("Failed to load profile icon", e.Message, "Meh", null);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ExecuteDelete()
|
||||
{
|
||||
if (IsNew)
|
||||
return;
|
||||
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
|
||||
return;
|
||||
// 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));
|
||||
|
||||
if (_profileConfiguration.IsBeingEdited)
|
||||
_profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||
_profileService.RemoveProfileConfiguration(_profileConfiguration);
|
||||
Close(_profileConfiguration);
|
||||
}
|
||||
|
||||
private async Task ExecuteConfirm()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
private void ExecuteCancel()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
private void LoadIcon()
|
||||
{
|
||||
// Preselect the icon based on streams if needed
|
||||
if (_profileConfiguration.Icon.IconType == ProfileConfigurationIconType.BitmapImage)
|
||||
{
|
||||
try
|
||||
{
|
||||
SelectedBitmapSource = new Bitmap(_profileConfiguration.Icon.GetIconStream());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_windowService.ShowConfirmContentDialog("Failed to load profile icon", e.Message, "Meh", null);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ExecuteBrowseBitmapFile()
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
private async Task ExecuteOpenConditionEditor()
|
||||
{
|
||||
await _windowService.ShowDialogAsync<NodeScriptWindowViewModel, bool>(("nodeScript", ProfileConfiguration.ActivationCondition));
|
||||
}
|
||||
|
||||
#endregion
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ExecuteBrowseBitmapFile()
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
private async Task ExecuteOpenConditionEditor()
|
||||
{
|
||||
await _windowService.ShowDialogAsync<NodeScriptWindowViewModel, bool>(("nodeScript", ProfileConfiguration.ActivationCondition));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
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();
|
||||
}
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
public MaterialIconKind Icon { get; }
|
||||
public class ProfileIconViewModel : ViewModelBase
|
||||
{
|
||||
public ProfileIconViewModel(MaterialIconKind icon)
|
||||
{
|
||||
Icon = icon;
|
||||
DisplayName = icon.ToString();
|
||||
}
|
||||
|
||||
public MaterialIconKind Icon { get; }
|
||||
}
|
||||
@@ -2,22 +2,21 @@
|
||||
using Artemis.UI.Shared;
|
||||
using Material.Icons;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
public class ProfileModuleViewModel : ViewModelBase
|
||||
{
|
||||
public class ProfileModuleViewModel : ViewModelBase
|
||||
public ProfileModuleViewModel(Module module)
|
||||
{
|
||||
public ProfileModuleViewModel(Module module)
|
||||
{
|
||||
Module = module;
|
||||
Name = module.Info.Name;
|
||||
Icon = module.Info.ResolvedIcon ?? MaterialIconKind.QuestionMark.ToString();
|
||||
Description = module.Info.Description;
|
||||
}
|
||||
|
||||
public string Icon { get; }
|
||||
public string Name { get; }
|
||||
public string? Description { get; }
|
||||
|
||||
public Module Module { get; }
|
||||
Module = module;
|
||||
Name = module.Info.Name;
|
||||
Icon = module.Info.ResolvedIcon ?? MaterialIconKind.QuestionMark.ToString();
|
||||
Description = module.Info.Description;
|
||||
}
|
||||
|
||||
public string Icon { get; }
|
||||
public string Name { get; }
|
||||
public string? Description { get; }
|
||||
|
||||
public Module Module { get; }
|
||||
}
|
||||
@@ -12,128 +12,126 @@ using Avalonia.Media.Imaging;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Avalonia.VisualTree;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
public class SidebarCategoryView : ReactiveUserControl<SidebarCategoryViewModel>
|
||||
{
|
||||
public class SidebarCategoryView : ReactiveUserControl<SidebarCategoryViewModel>
|
||||
private static Image? _dragAdorner;
|
||||
private Point _dragStartPosition;
|
||||
private Point _elementDragOffset;
|
||||
private ListBox _listBox;
|
||||
|
||||
public SidebarCategoryView()
|
||||
{
|
||||
private static Image? _dragAdorner;
|
||||
private Point _dragStartPosition;
|
||||
private Point _elementDragOffset;
|
||||
private ListBox _listBox;
|
||||
InitializeComponent();
|
||||
_listBox = this.Get<ListBox>("SidebarListBox");
|
||||
|
||||
public SidebarCategoryView()
|
||||
{
|
||||
InitializeComponent();
|
||||
_listBox = this.Get<ListBox>("SidebarListBox");
|
||||
|
||||
AddHandler(DragDrop.DragEnterEvent, HandleDragEnterEvent, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
|
||||
AddHandler(DragDrop.DragOverEvent, HandleDragOver, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
|
||||
AddHandler(PointerEnterEvent, HandlePointerEnter, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void InputElement_OnPointerReleased(object? sender, PointerReleasedEventArgs e)
|
||||
{
|
||||
if (e.InitialPressMouseButton == MouseButton.Left)
|
||||
ViewModel?.ToggleCollapsed.Execute().Subscribe();
|
||||
}
|
||||
|
||||
#region Dragging
|
||||
|
||||
private void HandlePointerEnter(object? sender, PointerEventArgs e)
|
||||
{
|
||||
DisposeDragAdorner();
|
||||
}
|
||||
|
||||
private void HandleDragEnterEvent(object? sender, DragEventArgs e)
|
||||
{
|
||||
CreateDragAdorner(e);
|
||||
}
|
||||
|
||||
private void CreateDragAdorner(DragEventArgs e)
|
||||
{
|
||||
if (_dragAdorner != null)
|
||||
return;
|
||||
|
||||
if (e.Source is not Control c)
|
||||
return;
|
||||
|
||||
// Get the list box item that raised the event
|
||||
ListBoxItem? container = c.FindLogicalAncestorOfType<ListBoxItem>();
|
||||
if (container == null)
|
||||
return;
|
||||
|
||||
// Take a snapshot of said tree view item and add it as an adorner
|
||||
ITransform? originalTransform = container.RenderTransform;
|
||||
try
|
||||
{
|
||||
_dragStartPosition = e.GetPosition(this.FindAncestorOfType<Window>());
|
||||
_elementDragOffset = e.GetPosition(container);
|
||||
|
||||
RenderTargetBitmap renderTarget = new(new PixelSize((int) container.Bounds.Width, (int) container.Bounds.Height));
|
||||
container.RenderTransform = new TranslateTransform(container.Bounds.X * -1, container.Bounds.Y * -1);
|
||||
renderTarget.Render(container);
|
||||
_dragAdorner = new Image
|
||||
{
|
||||
Source = renderTarget,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
Stretch = Stretch.None,
|
||||
IsHitTestVisible = false
|
||||
};
|
||||
AdornerLayer.GetAdornerLayer(this)!.Children.Add(_dragAdorner);
|
||||
}
|
||||
finally
|
||||
{
|
||||
container.RenderTransform = originalTransform;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleDragOver(object? sender, DragEventArgs e)
|
||||
{
|
||||
UpdateDragAdorner(e.GetPosition(this.FindAncestorOfType<Window>()));
|
||||
}
|
||||
|
||||
private void HandleLeaveEvent(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// If there is currently an adorner, dispose of it
|
||||
DisposeDragAdorner();
|
||||
}
|
||||
|
||||
private void HandleDrop(object? sender, DragEventArgs e)
|
||||
{
|
||||
// If there is currently an adorner, dispose of it
|
||||
DisposeDragAdorner();
|
||||
}
|
||||
|
||||
private void DisposeDragAdorner()
|
||||
{
|
||||
if (_dragAdorner == null)
|
||||
return;
|
||||
|
||||
AdornerLayer.GetAdornerLayer(this)!.Children.Remove(_dragAdorner);
|
||||
(_dragAdorner.Source as RenderTargetBitmap)?.Dispose();
|
||||
_dragAdorner = null;
|
||||
|
||||
}
|
||||
|
||||
private void UpdateDragAdorner(Point position)
|
||||
{
|
||||
if (_dragAdorner == null)
|
||||
return;
|
||||
|
||||
_dragAdorner.RenderTransform = new TranslateTransform(_dragStartPosition.X - _elementDragOffset.X, position.Y - _elementDragOffset.Y);
|
||||
}
|
||||
|
||||
private void InputElement_OnPointerMoved(object? sender, PointerEventArgs e)
|
||||
{
|
||||
DisposeDragAdorner();
|
||||
}
|
||||
|
||||
#endregion
|
||||
AddHandler(DragDrop.DragEnterEvent, HandleDragEnterEvent, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
|
||||
AddHandler(DragDrop.DragOverEvent, HandleDragOver, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
|
||||
AddHandler(PointerEnterEvent, HandlePointerEnter, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void InputElement_OnPointerReleased(object? sender, PointerReleasedEventArgs e)
|
||||
{
|
||||
if (e.InitialPressMouseButton == MouseButton.Left)
|
||||
ViewModel?.ToggleCollapsed.Execute().Subscribe();
|
||||
}
|
||||
|
||||
#region Dragging
|
||||
|
||||
private void HandlePointerEnter(object? sender, PointerEventArgs e)
|
||||
{
|
||||
DisposeDragAdorner();
|
||||
}
|
||||
|
||||
private void HandleDragEnterEvent(object? sender, DragEventArgs e)
|
||||
{
|
||||
CreateDragAdorner(e);
|
||||
}
|
||||
|
||||
private void CreateDragAdorner(DragEventArgs e)
|
||||
{
|
||||
if (_dragAdorner != null)
|
||||
return;
|
||||
|
||||
if (e.Source is not Control c)
|
||||
return;
|
||||
|
||||
// Get the list box item that raised the event
|
||||
ListBoxItem? container = c.FindLogicalAncestorOfType<ListBoxItem>();
|
||||
if (container == null)
|
||||
return;
|
||||
|
||||
// Take a snapshot of said tree view item and add it as an adorner
|
||||
ITransform? originalTransform = container.RenderTransform;
|
||||
try
|
||||
{
|
||||
_dragStartPosition = e.GetPosition(this.FindAncestorOfType<Window>());
|
||||
_elementDragOffset = e.GetPosition(container);
|
||||
|
||||
RenderTargetBitmap renderTarget = new(new PixelSize((int) container.Bounds.Width, (int) container.Bounds.Height));
|
||||
container.RenderTransform = new TranslateTransform(container.Bounds.X * -1, container.Bounds.Y * -1);
|
||||
renderTarget.Render(container);
|
||||
_dragAdorner = new Image
|
||||
{
|
||||
Source = renderTarget,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
Stretch = Stretch.None,
|
||||
IsHitTestVisible = false
|
||||
};
|
||||
AdornerLayer.GetAdornerLayer(this)!.Children.Add(_dragAdorner);
|
||||
}
|
||||
finally
|
||||
{
|
||||
container.RenderTransform = originalTransform;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleDragOver(object? sender, DragEventArgs e)
|
||||
{
|
||||
UpdateDragAdorner(e.GetPosition(this.FindAncestorOfType<Window>()));
|
||||
}
|
||||
|
||||
private void HandleLeaveEvent(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// If there is currently an adorner, dispose of it
|
||||
DisposeDragAdorner();
|
||||
}
|
||||
|
||||
private void HandleDrop(object? sender, DragEventArgs e)
|
||||
{
|
||||
// If there is currently an adorner, dispose of it
|
||||
DisposeDragAdorner();
|
||||
}
|
||||
|
||||
private void DisposeDragAdorner()
|
||||
{
|
||||
if (_dragAdorner == null)
|
||||
return;
|
||||
|
||||
AdornerLayer.GetAdornerLayer(this)!.Children.Remove(_dragAdorner);
|
||||
(_dragAdorner.Source as RenderTargetBitmap)?.Dispose();
|
||||
_dragAdorner = null;
|
||||
}
|
||||
|
||||
private void UpdateDragAdorner(Point position)
|
||||
{
|
||||
if (_dragAdorner == null)
|
||||
return;
|
||||
|
||||
_dragAdorner.RenderTransform = new TranslateTransform(_dragStartPosition.X - _elementDragOffset.X, position.Y - _elementDragOffset.Y);
|
||||
}
|
||||
|
||||
private void InputElement_OnPointerMoved(object? sender, PointerEventArgs e)
|
||||
{
|
||||
DisposeDragAdorner();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -7,7 +7,6 @@ using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Shared;
|
||||
@@ -18,170 +17,169 @@ using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
public class SidebarCategoryViewModel : ActivatableViewModelBase
|
||||
{
|
||||
public class SidebarCategoryViewModel : ActivatableViewModelBase
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly SidebarViewModel _sidebarViewModel;
|
||||
private readonly ISidebarVmFactory _vmFactory;
|
||||
private readonly IWindowService _windowService;
|
||||
private ObservableAsPropertyHelper<bool>? _isCollapsed;
|
||||
private ObservableAsPropertyHelper<bool>? _isSuspended;
|
||||
private SidebarProfileConfigurationViewModel? _selectedProfileConfiguration;
|
||||
|
||||
public SidebarCategoryViewModel(SidebarViewModel sidebarViewModel, ProfileCategory profileCategory, IProfileService profileService, IWindowService windowService,
|
||||
IProfileEditorService profileEditorService, ISidebarVmFactory vmFactory)
|
||||
{
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly SidebarViewModel _sidebarViewModel;
|
||||
private readonly ISidebarVmFactory _vmFactory;
|
||||
private readonly IWindowService _windowService;
|
||||
private SidebarProfileConfigurationViewModel? _selectedProfileConfiguration;
|
||||
private ObservableAsPropertyHelper<bool>? _isCollapsed;
|
||||
private ObservableAsPropertyHelper<bool>? _isSuspended;
|
||||
_sidebarViewModel = sidebarViewModel;
|
||||
_profileService = profileService;
|
||||
_windowService = windowService;
|
||||
_vmFactory = vmFactory;
|
||||
|
||||
public SidebarCategoryViewModel(SidebarViewModel sidebarViewModel, ProfileCategory profileCategory, IProfileService profileService, IWindowService windowService,
|
||||
IProfileEditorService profileEditorService, ISidebarVmFactory vmFactory)
|
||||
ProfileCategory = profileCategory;
|
||||
SourceList<ProfileConfiguration> profileConfigurations = new();
|
||||
|
||||
// Only show items when not collapsed
|
||||
IObservable<Func<ProfileConfiguration, bool>> profileConfigurationsFilter = this.WhenAnyValue(vm => vm.IsCollapsed).Select(b => new Func<object, bool>(_ => !b));
|
||||
profileConfigurations.Connect()
|
||||
.Filter(profileConfigurationsFilter)
|
||||
.Sort(SortExpressionComparer<ProfileConfiguration>.Ascending(c => c.Order))
|
||||
.Transform(c => _vmFactory.SidebarProfileConfigurationViewModel(_sidebarViewModel, c))
|
||||
.Bind(out ReadOnlyObservableCollection<SidebarProfileConfigurationViewModel> profileConfigurationViewModels)
|
||||
.Subscribe();
|
||||
ProfileConfigurations = profileConfigurationViewModels;
|
||||
|
||||
ToggleCollapsed = ReactiveCommand.Create(ExecuteToggleCollapsed);
|
||||
ToggleSuspended = ReactiveCommand.Create(ExecuteToggleSuspended);
|
||||
AddProfile = ReactiveCommand.CreateFromTask(ExecuteAddProfile);
|
||||
EditCategory = ReactiveCommand.CreateFromTask(ExecuteEditCategory);
|
||||
MoveUp = ReactiveCommand.Create(ExecuteMoveUp);
|
||||
MoveDown = ReactiveCommand.Create(ExecuteMoveDown);
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_sidebarViewModel = sidebarViewModel;
|
||||
_profileService = profileService;
|
||||
_windowService = windowService;
|
||||
_vmFactory = vmFactory;
|
||||
// Update the list of profiles whenever the category fires events
|
||||
Observable.FromEventPattern<ProfileConfigurationEventArgs>(x => profileCategory.ProfileConfigurationAdded += x, x => profileCategory.ProfileConfigurationAdded -= x)
|
||||
.Subscribe(e => profileConfigurations.Add(e.EventArgs.ProfileConfiguration))
|
||||
.DisposeWith(d);
|
||||
Observable.FromEventPattern<ProfileConfigurationEventArgs>(x => profileCategory.ProfileConfigurationRemoved += x, x => profileCategory.ProfileConfigurationRemoved -= x)
|
||||
.Subscribe(e => profileConfigurations.Remove(e.EventArgs.ProfileConfiguration))
|
||||
.DisposeWith(d);
|
||||
|
||||
ProfileCategory = profileCategory;
|
||||
SourceList<ProfileConfiguration> profileConfigurations = new();
|
||||
profileEditorService.ProfileConfiguration.Subscribe(p => SelectedProfileConfiguration = ProfileConfigurations.FirstOrDefault(c => ReferenceEquals(c.ProfileConfiguration, p)))
|
||||
.DisposeWith(d);
|
||||
|
||||
// Only show items when not collapsed
|
||||
IObservable<Func<ProfileConfiguration, bool>> profileConfigurationsFilter = this.WhenAnyValue(vm => vm.IsCollapsed).Select(b => new Func<object, bool>(_ => !b));
|
||||
profileConfigurations.Connect()
|
||||
.Filter(profileConfigurationsFilter)
|
||||
.Sort(SortExpressionComparer<ProfileConfiguration>.Ascending(c => c.Order))
|
||||
.Transform(c => _vmFactory.SidebarProfileConfigurationViewModel(_sidebarViewModel, c))
|
||||
.Bind(out ReadOnlyObservableCollection<SidebarProfileConfigurationViewModel> profileConfigurationViewModels)
|
||||
.Subscribe();
|
||||
ProfileConfigurations = profileConfigurationViewModels;
|
||||
_isCollapsed = ProfileCategory.WhenAnyValue(vm => vm.IsCollapsed).ToProperty(this, vm => vm.IsCollapsed).DisposeWith(d);
|
||||
_isSuspended = ProfileCategory.WhenAnyValue(vm => vm.IsSuspended).ToProperty(this, vm => vm.IsSuspended).DisposeWith(d);
|
||||
|
||||
ToggleCollapsed = ReactiveCommand.Create(ExecuteToggleCollapsed);
|
||||
ToggleSuspended = ReactiveCommand.Create(ExecuteToggleSuspended);
|
||||
AddProfile = ReactiveCommand.CreateFromTask(ExecuteAddProfile);
|
||||
EditCategory = ReactiveCommand.CreateFromTask(ExecuteEditCategory);
|
||||
MoveUp = ReactiveCommand.Create(ExecuteMoveUp);
|
||||
MoveDown = ReactiveCommand.Create(ExecuteMoveDown);
|
||||
// Change the current profile configuration when a new one is selected
|
||||
this.WhenAnyValue(vm => vm.SelectedProfileConfiguration).WhereNotNull().Subscribe(s => profileEditorService.ChangeCurrentProfileConfiguration(s.ProfileConfiguration));
|
||||
});
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
// Update the list of profiles whenever the category fires events
|
||||
Observable.FromEventPattern<ProfileConfigurationEventArgs>(x => profileCategory.ProfileConfigurationAdded += x, x => profileCategory.ProfileConfigurationAdded -= x)
|
||||
.Subscribe(e => profileConfigurations.Add(e.EventArgs.ProfileConfiguration))
|
||||
.DisposeWith(d);
|
||||
Observable.FromEventPattern<ProfileConfigurationEventArgs>(x => profileCategory.ProfileConfigurationRemoved += x, x => profileCategory.ProfileConfigurationRemoved -= x)
|
||||
.Subscribe(e => profileConfigurations.Remove(e.EventArgs.ProfileConfiguration))
|
||||
.DisposeWith(d);
|
||||
|
||||
profileEditorService.ProfileConfiguration.Subscribe(p => SelectedProfileConfiguration = ProfileConfigurations.FirstOrDefault(c => ReferenceEquals(c.ProfileConfiguration, p)))
|
||||
.DisposeWith(d);
|
||||
|
||||
_isCollapsed = ProfileCategory.WhenAnyValue(vm => vm.IsCollapsed).ToProperty(this, vm => vm.IsCollapsed).DisposeWith(d);
|
||||
_isSuspended = ProfileCategory.WhenAnyValue(vm => vm.IsSuspended).ToProperty(this, vm => vm.IsSuspended).DisposeWith(d);
|
||||
|
||||
// Change the current profile configuration when a new one is selected
|
||||
this.WhenAnyValue(vm => vm.SelectedProfileConfiguration).WhereNotNull().Subscribe(s => profileEditorService.ChangeCurrentProfileConfiguration(s.ProfileConfiguration));
|
||||
});
|
||||
|
||||
profileConfigurations.Edit(updater =>
|
||||
{
|
||||
foreach (ProfileConfiguration profileConfiguration in profileCategory.ProfileConfigurations)
|
||||
updater.Add(profileConfiguration);
|
||||
});
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> ToggleCollapsed { get; }
|
||||
public ReactiveCommand<Unit, Unit> ToggleSuspended { get; }
|
||||
public ReactiveCommand<Unit, Unit> AddProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> EditCategory { get; }
|
||||
public ReactiveCommand<Unit, Unit> MoveUp { get; }
|
||||
public ReactiveCommand<Unit, Unit> MoveDown { get; }
|
||||
|
||||
public ProfileCategory ProfileCategory { get; }
|
||||
public ReadOnlyObservableCollection<SidebarProfileConfigurationViewModel> ProfileConfigurations { get; }
|
||||
|
||||
public bool IsCollapsed => _isCollapsed?.Value ?? false;
|
||||
public bool IsSuspended => _isSuspended?.Value ?? false;
|
||||
|
||||
public SidebarProfileConfigurationViewModel? SelectedProfileConfiguration
|
||||
profileConfigurations.Edit(updater =>
|
||||
{
|
||||
get => _selectedProfileConfiguration;
|
||||
set => RaiseAndSetIfChanged(ref _selectedProfileConfiguration, value);
|
||||
}
|
||||
foreach (ProfileConfiguration profileConfiguration in profileCategory.ProfileConfigurations)
|
||||
updater.Add(profileConfiguration);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task ExecuteEditCategory()
|
||||
public ReactiveCommand<Unit, Unit> ToggleCollapsed { get; }
|
||||
public ReactiveCommand<Unit, Unit> ToggleSuspended { get; }
|
||||
public ReactiveCommand<Unit, Unit> AddProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> EditCategory { get; }
|
||||
public ReactiveCommand<Unit, Unit> MoveUp { get; }
|
||||
public ReactiveCommand<Unit, Unit> MoveDown { get; }
|
||||
|
||||
public ProfileCategory ProfileCategory { get; }
|
||||
public ReadOnlyObservableCollection<SidebarProfileConfigurationViewModel> ProfileConfigurations { get; }
|
||||
|
||||
public bool IsCollapsed => _isCollapsed?.Value ?? false;
|
||||
public bool IsSuspended => _isSuspended?.Value ?? false;
|
||||
|
||||
public SidebarProfileConfigurationViewModel? SelectedProfileConfiguration
|
||||
{
|
||||
get => _selectedProfileConfiguration;
|
||||
set => RaiseAndSetIfChanged(ref _selectedProfileConfiguration, value);
|
||||
}
|
||||
|
||||
public void AddProfileConfiguration(ProfileConfiguration profileConfiguration, int? index)
|
||||
{
|
||||
ProfileCategory oldCategory = profileConfiguration.Category;
|
||||
ProfileCategory.AddProfileConfiguration(profileConfiguration, index);
|
||||
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
// If the profile moved to a new category, also save the old category
|
||||
if (oldCategory != ProfileCategory)
|
||||
_profileService.SaveProfileCategory(oldCategory);
|
||||
}
|
||||
|
||||
private async Task ExecuteEditCategory()
|
||||
{
|
||||
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();
|
||||
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
|
||||
private async Task ExecuteAddProfile()
|
||||
{
|
||||
ProfileConfiguration? result = await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, ProfileConfiguration?>(
|
||||
("profileCategory", ProfileCategory),
|
||||
("profileConfiguration", null)
|
||||
);
|
||||
if (result != null)
|
||||
{
|
||||
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();
|
||||
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
|
||||
private async Task ExecuteAddProfile()
|
||||
{
|
||||
ProfileConfiguration? result = await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, ProfileConfiguration?>(
|
||||
("profileCategory", ProfileCategory),
|
||||
("profileConfiguration", null)
|
||||
);
|
||||
if (result != null)
|
||||
{
|
||||
SidebarProfileConfigurationViewModel viewModel = _vmFactory.SidebarProfileConfigurationViewModel(_sidebarViewModel, result);
|
||||
SelectedProfileConfiguration = viewModel;
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteToggleCollapsed()
|
||||
{
|
||||
ProfileCategory.IsCollapsed = !ProfileCategory.IsCollapsed;
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
}
|
||||
|
||||
private void ExecuteToggleSuspended()
|
||||
{
|
||||
ProfileCategory.IsSuspended = !ProfileCategory.IsSuspended;
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
}
|
||||
|
||||
private void ExecuteMoveUp()
|
||||
{
|
||||
List<ProfileCategory> categories = _profileService.ProfileCategories.OrderBy(p => p.Order).ToList();
|
||||
int index = categories.IndexOf(ProfileCategory);
|
||||
if (index <= 0)
|
||||
return;
|
||||
|
||||
categories[index - 1].Order++;
|
||||
ProfileCategory.Order--;
|
||||
_profileService.SaveProfileCategory(categories[index - 1]);
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
|
||||
private void ExecuteMoveDown()
|
||||
{
|
||||
List<ProfileCategory> categories = _profileService.ProfileCategories.OrderBy(p => p.Order).ToList();
|
||||
int index = categories.IndexOf(ProfileCategory);
|
||||
if (index >= categories.Count - 1)
|
||||
return;
|
||||
|
||||
categories[index + 1].Order--;
|
||||
ProfileCategory.Order++;
|
||||
_profileService.SaveProfileCategory(categories[index + 1]);
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
|
||||
public void AddProfileConfiguration(ProfileConfiguration profileConfiguration, int? index)
|
||||
{
|
||||
ProfileCategory oldCategory = profileConfiguration.Category;
|
||||
ProfileCategory.AddProfileConfiguration(profileConfiguration, index);
|
||||
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
// If the profile moved to a new category, also save the old category
|
||||
if (oldCategory != ProfileCategory)
|
||||
_profileService.SaveProfileCategory(oldCategory);
|
||||
SidebarProfileConfigurationViewModel viewModel = _vmFactory.SidebarProfileConfigurationViewModel(_sidebarViewModel, result);
|
||||
SelectedProfileConfiguration = viewModel;
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteToggleCollapsed()
|
||||
{
|
||||
ProfileCategory.IsCollapsed = !ProfileCategory.IsCollapsed;
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
}
|
||||
|
||||
private void ExecuteToggleSuspended()
|
||||
{
|
||||
ProfileCategory.IsSuspended = !ProfileCategory.IsSuspended;
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
}
|
||||
|
||||
private void ExecuteMoveUp()
|
||||
{
|
||||
List<ProfileCategory> categories = _profileService.ProfileCategories.OrderBy(p => p.Order).ToList();
|
||||
int index = categories.IndexOf(ProfileCategory);
|
||||
if (index <= 0)
|
||||
return;
|
||||
|
||||
categories[index - 1].Order++;
|
||||
ProfileCategory.Order--;
|
||||
_profileService.SaveProfileCategory(categories[index - 1]);
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
|
||||
private void ExecuteMoveDown()
|
||||
{
|
||||
List<ProfileCategory> categories = _profileService.ProfileCategories.OrderBy(p => p.Order).ToList();
|
||||
int index = categories.IndexOf(ProfileCategory);
|
||||
if (index >= categories.Count - 1)
|
||||
return;
|
||||
|
||||
categories[index + 1].Order--;
|
||||
ProfileCategory.Order++;
|
||||
_profileService.SaveProfileCategory(categories[index + 1]);
|
||||
_profileService.SaveProfileCategory(ProfileCategory);
|
||||
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,8 @@
|
||||
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:sidebar="clr-namespace:Artemis.UI.Screens.Sidebar"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.UI.Screens.Sidebar.SidebarProfileConfigurationView"
|
||||
x:DataType="sidebar:SidebarProfileConfigurationViewModel"
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarProfileConfigurationView : ReactiveUserControl<SidebarProfileConfigurationViewModel>
|
||||
{
|
||||
public SidebarProfileConfigurationView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
public class SidebarProfileConfigurationView : ReactiveUserControl<SidebarProfileConfigurationViewModel>
|
||||
{
|
||||
public SidebarProfileConfigurationView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -13,143 +13,134 @@ using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Newtonsoft.Json;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
public class SidebarProfileConfigurationViewModel : ActivatableViewModelBase
|
||||
{
|
||||
public class SidebarProfileConfigurationViewModel : ActivatableViewModelBase
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly SidebarViewModel _sidebarViewModel;
|
||||
private readonly IWindowService _windowService;
|
||||
private ObservableAsPropertyHelper<bool>? _isDisabled;
|
||||
|
||||
public SidebarProfileConfigurationViewModel(SidebarViewModel sidebarViewModel,
|
||||
ProfileConfiguration profileConfiguration,
|
||||
IProfileService profileService,
|
||||
IProfileEditorService profileEditorService,
|
||||
IWindowService windowService)
|
||||
{
|
||||
private readonly SidebarViewModel _sidebarViewModel;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IWindowService _windowService;
|
||||
private ObservableAsPropertyHelper<bool>? _isDisabled;
|
||||
_sidebarViewModel = sidebarViewModel;
|
||||
_profileService = profileService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_windowService = windowService;
|
||||
|
||||
public SidebarProfileConfigurationViewModel(SidebarViewModel sidebarViewModel,
|
||||
ProfileConfiguration profileConfiguration,
|
||||
IProfileService profileService,
|
||||
IProfileEditorService profileEditorService,
|
||||
IWindowService windowService)
|
||||
ProfileConfiguration = profileConfiguration;
|
||||
EditProfile = ReactiveCommand.CreateFromTask(ExecuteEditProfile);
|
||||
ToggleSuspended = ReactiveCommand.Create(ExecuteToggleSuspended);
|
||||
ResumeAll = ReactiveCommand.Create<string>(ExecuteResumeAll);
|
||||
SuspendAll = ReactiveCommand.Create<string>(ExecuteSuspendAll);
|
||||
DeleteProfile = ReactiveCommand.CreateFromTask(ExecuteDeleteProfile);
|
||||
ExportProfile = ReactiveCommand.CreateFromTask(ExecuteExportProfile);
|
||||
DuplicateProfile = ReactiveCommand.Create(ExecuteDuplicateProfile);
|
||||
|
||||
this.WhenActivated(d => _isDisabled = ProfileConfiguration.WhenAnyValue(c => c.Profile)
|
||||
.Select(p => p == null)
|
||||
.ToProperty(this, vm => vm.IsDisabled)
|
||||
.DisposeWith(d));
|
||||
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
|
||||
}
|
||||
|
||||
public ProfileConfiguration ProfileConfiguration { get; }
|
||||
public ReactiveCommand<Unit, Unit> EditProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> ToggleSuspended { get; }
|
||||
public ReactiveCommand<string, Unit> ResumeAll { get; }
|
||||
public ReactiveCommand<string, Unit> SuspendAll { get; }
|
||||
public ReactiveCommand<Unit, Unit> DeleteProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> ExportProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> DuplicateProfile { get; }
|
||||
|
||||
public bool IsDisabled => _isDisabled?.Value ?? false;
|
||||
|
||||
private async Task ExecuteEditProfile()
|
||||
{
|
||||
ProfileConfiguration? edited = await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, ProfileConfiguration?>(
|
||||
("profileCategory", ProfileConfiguration.Category),
|
||||
("profileConfiguration", ProfileConfiguration)
|
||||
);
|
||||
|
||||
if (edited != null)
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
|
||||
private void ExecuteToggleSuspended()
|
||||
{
|
||||
ProfileConfiguration.IsSuspended = !ProfileConfiguration.IsSuspended;
|
||||
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||
}
|
||||
|
||||
private void ExecuteResumeAll(string direction)
|
||||
{
|
||||
int index = ProfileConfiguration.Category.ProfileConfigurations.IndexOf(ProfileConfiguration);
|
||||
if (direction == "above")
|
||||
for (int i = 0; i < index; i++)
|
||||
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = false;
|
||||
else
|
||||
for (int i = index + 1; i < ProfileConfiguration.Category.ProfileConfigurations.Count; i++)
|
||||
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = false;
|
||||
|
||||
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||
}
|
||||
|
||||
private void ExecuteSuspendAll(string direction)
|
||||
{
|
||||
int index = ProfileConfiguration.Category.ProfileConfigurations.IndexOf(ProfileConfiguration);
|
||||
if (direction == "above")
|
||||
for (int i = 0; i < index; i++)
|
||||
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = true;
|
||||
else
|
||||
for (int i = index + 1; i < ProfileConfiguration.Category.ProfileConfigurations.Count; i++)
|
||||
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = true;
|
||||
|
||||
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||
}
|
||||
|
||||
private async Task ExecuteDeleteProfile()
|
||||
{
|
||||
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
|
||||
return;
|
||||
|
||||
if (ProfileConfiguration.IsBeingEdited)
|
||||
_profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||
_profileService.RemoveProfileConfiguration(ProfileConfiguration);
|
||||
}
|
||||
|
||||
private async Task ExecuteExportProfile()
|
||||
{
|
||||
// Might not cover everything but then the dialog will complain and that's good enough
|
||||
string fileName = Path.GetInvalidFileNameChars().Aggregate(ProfileConfiguration.Name, (current, c) => current.Replace(c, '-'));
|
||||
string? result = await _windowService.CreateSaveFileDialog()
|
||||
.HavingFilter(f => f.WithExtension("json").WithName("Artemis profile"))
|
||||
.WithInitialFileName(fileName)
|
||||
.ShowAsync();
|
||||
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
ProfileConfigurationExportModel export = _profileService.ExportProfile(ProfileConfiguration);
|
||||
string json = JsonConvert.SerializeObject(export, IProfileService.ExportSettings);
|
||||
try
|
||||
{
|
||||
_sidebarViewModel = sidebarViewModel;
|
||||
_profileService = profileService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_windowService = windowService;
|
||||
|
||||
ProfileConfiguration = profileConfiguration;
|
||||
EditProfile = ReactiveCommand.CreateFromTask(ExecuteEditProfile);
|
||||
ToggleSuspended = ReactiveCommand.Create(ExecuteToggleSuspended);
|
||||
ResumeAll = ReactiveCommand.Create<string>(ExecuteResumeAll);
|
||||
SuspendAll = ReactiveCommand.Create<string>(ExecuteSuspendAll);
|
||||
DeleteProfile = ReactiveCommand.CreateFromTask(ExecuteDeleteProfile);
|
||||
ExportProfile = ReactiveCommand.CreateFromTask(ExecuteExportProfile);
|
||||
DuplicateProfile = ReactiveCommand.Create(ExecuteDuplicateProfile);
|
||||
|
||||
this.WhenActivated(d => _isDisabled = ProfileConfiguration.WhenAnyValue(c => c.Profile)
|
||||
.Select(p => p == null)
|
||||
.ToProperty(this, vm => vm.IsDisabled)
|
||||
.DisposeWith(d));
|
||||
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
|
||||
await File.WriteAllTextAsync(result, json);
|
||||
}
|
||||
|
||||
public ProfileConfiguration ProfileConfiguration { get; }
|
||||
public ReactiveCommand<Unit, Unit> EditProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> ToggleSuspended { get; }
|
||||
public ReactiveCommand<string, Unit> ResumeAll { get; }
|
||||
public ReactiveCommand<string, Unit> SuspendAll { get; }
|
||||
public ReactiveCommand<Unit, Unit> DeleteProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> ExportProfile { get; }
|
||||
public ReactiveCommand<Unit, Unit> DuplicateProfile { get; }
|
||||
|
||||
public bool IsDisabled => _isDisabled?.Value ?? false;
|
||||
|
||||
private async Task ExecuteEditProfile()
|
||||
catch (Exception e)
|
||||
{
|
||||
ProfileConfiguration? edited = await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, ProfileConfiguration?>(
|
||||
("profileCategory", ProfileConfiguration.Category),
|
||||
("profileConfiguration", ProfileConfiguration)
|
||||
);
|
||||
|
||||
if (edited != null)
|
||||
_sidebarViewModel.UpdateProfileCategories();
|
||||
}
|
||||
|
||||
private void ExecuteToggleSuspended()
|
||||
{
|
||||
ProfileConfiguration.IsSuspended = !ProfileConfiguration.IsSuspended;
|
||||
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||
}
|
||||
|
||||
private void ExecuteResumeAll(string direction)
|
||||
{
|
||||
int index = ProfileConfiguration.Category.ProfileConfigurations.IndexOf(ProfileConfiguration);
|
||||
if (direction == "above")
|
||||
{
|
||||
for (int i = 0; i < index; i++)
|
||||
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = index + 1; i < ProfileConfiguration.Category.ProfileConfigurations.Count; i++)
|
||||
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = false;
|
||||
}
|
||||
|
||||
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||
}
|
||||
|
||||
private void ExecuteSuspendAll(string direction)
|
||||
{
|
||||
int index = ProfileConfiguration.Category.ProfileConfigurations.IndexOf(ProfileConfiguration);
|
||||
if (direction == "above")
|
||||
{
|
||||
for (int i = 0; i < index; i++)
|
||||
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = index + 1; i < ProfileConfiguration.Category.ProfileConfigurations.Count; i++)
|
||||
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = true;
|
||||
}
|
||||
|
||||
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||
}
|
||||
|
||||
private async Task ExecuteDeleteProfile()
|
||||
{
|
||||
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
|
||||
return;
|
||||
|
||||
if (ProfileConfiguration.IsBeingEdited)
|
||||
_profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||
_profileService.RemoveProfileConfiguration(ProfileConfiguration);
|
||||
}
|
||||
|
||||
private async Task ExecuteExportProfile()
|
||||
{
|
||||
// Might not cover everything but then the dialog will complain and that's good enough
|
||||
string fileName = Path.GetInvalidFileNameChars().Aggregate(ProfileConfiguration.Name, (current, c) => current.Replace(c, '-'));
|
||||
string? result = await _windowService.CreateSaveFileDialog()
|
||||
.HavingFilter(f => f.WithExtension("json").WithName("Artemis profile"))
|
||||
.WithInitialFileName(fileName)
|
||||
.ShowAsync();
|
||||
|
||||
if (result == null)
|
||||
return;
|
||||
|
||||
ProfileConfigurationExportModel export = _profileService.ExportProfile(ProfileConfiguration);
|
||||
string json = JsonConvert.SerializeObject(export, IProfileService.ExportSettings);
|
||||
try
|
||||
{
|
||||
await File.WriteAllTextAsync(result, json);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_windowService.ShowExceptionDialog("Failed to export profile", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteDuplicateProfile()
|
||||
{
|
||||
ProfileConfigurationExportModel export = _profileService.ExportProfile(ProfileConfiguration);
|
||||
_profileService.ImportProfile(ProfileConfiguration.Category, export, true, false, "copy");
|
||||
_windowService.ShowExceptionDialog("Failed to export profile", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteDuplicateProfile()
|
||||
{
|
||||
ProfileConfigurationExportModel export = _profileService.ExportProfile(ProfileConfiguration);
|
||||
_profileService.ImportProfile(ProfileConfiguration.Category, export, true, false, "copy");
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public partial class SidebarScreenView : UserControl
|
||||
{
|
||||
public SidebarScreenView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
public class SidebarScreenView : UserControl
|
||||
{
|
||||
public SidebarScreenView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -5,33 +5,32 @@ using Ninject;
|
||||
using Ninject.Parameters;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
public class SidebarScreenViewModel<T> : SidebarScreenViewModel where T : MainScreenViewModel
|
||||
{
|
||||
public class SidebarScreenViewModel<T> : SidebarScreenViewModel where T : MainScreenViewModel
|
||||
public SidebarScreenViewModel(MaterialIconKind icon, string displayName) : base(icon, displayName)
|
||||
{
|
||||
public SidebarScreenViewModel(MaterialIconKind icon, string displayName) : base(icon, displayName)
|
||||
{
|
||||
}
|
||||
|
||||
public override Type ScreenType => typeof(T);
|
||||
|
||||
public override MainScreenViewModel CreateInstance(IKernel kernel, IScreen screen)
|
||||
{
|
||||
return kernel.Get<T>(new ConstructorArgument("hostScreen", screen));
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SidebarScreenViewModel : ViewModelBase
|
||||
public override Type ScreenType => typeof(T);
|
||||
|
||||
public override MainScreenViewModel CreateInstance(IKernel kernel, IScreen screen)
|
||||
{
|
||||
protected SidebarScreenViewModel(MaterialIconKind icon, string displayName)
|
||||
{
|
||||
Icon = icon;
|
||||
DisplayName = displayName;
|
||||
}
|
||||
|
||||
public MaterialIconKind Icon { get; }
|
||||
|
||||
public abstract Type ScreenType { get; }
|
||||
public abstract MainScreenViewModel CreateInstance(IKernel kernel, IScreen screen);
|
||||
return kernel.Get<T>(new ConstructorArgument("hostScreen", screen));
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SidebarScreenViewModel : ViewModelBase
|
||||
{
|
||||
protected SidebarScreenViewModel(MaterialIconKind icon, string displayName)
|
||||
{
|
||||
Icon = icon;
|
||||
DisplayName = displayName;
|
||||
}
|
||||
|
||||
public MaterialIconKind Icon { get; }
|
||||
|
||||
public abstract Type ScreenType { get; }
|
||||
public abstract MainScreenViewModel CreateInstance(IKernel kernel, IScreen screen);
|
||||
}
|
||||
@@ -1,18 +1,17 @@
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
{
|
||||
public class SidebarView : ReactiveUserControl<SidebarViewModel>
|
||||
{
|
||||
public SidebarView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
public class SidebarView : ReactiveUserControl<SidebarViewModel>
|
||||
{
|
||||
public SidebarView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -20,118 +20,117 @@ using Ninject;
|
||||
using ReactiveUI;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.UI.Screens.Sidebar
|
||||
namespace Artemis.UI.Screens.Sidebar;
|
||||
|
||||
public class SidebarViewModel : ActivatableViewModelBase
|
||||
{
|
||||
public class SidebarViewModel : ActivatableViewModelBase
|
||||
private readonly IScreen _hostScreen;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly ISidebarVmFactory _sidebarVmFactory;
|
||||
private readonly IWindowService _windowService;
|
||||
private ArtemisDevice? _headerDevice;
|
||||
|
||||
private SidebarScreenViewModel? _selectedSidebarScreen;
|
||||
|
||||
|
||||
public SidebarViewModel(IScreen hostScreen, IKernel kernel, IProfileService profileService, IRgbService rgbService, IWindowService windowService,
|
||||
IProfileEditorService profileEditorService, ISidebarVmFactory sidebarVmFactory, IProfileEditorVmFactory profileEditorVmFactory)
|
||||
{
|
||||
private readonly IScreen _hostScreen;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly ISidebarVmFactory _sidebarVmFactory;
|
||||
private readonly IWindowService _windowService;
|
||||
private ArtemisDevice? _headerDevice;
|
||||
_hostScreen = hostScreen;
|
||||
_profileService = profileService;
|
||||
_rgbService = rgbService;
|
||||
_windowService = windowService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_sidebarVmFactory = sidebarVmFactory;
|
||||
|
||||
private SidebarScreenViewModel? _selectedSidebarScreen;
|
||||
|
||||
|
||||
public SidebarViewModel(IScreen hostScreen, IKernel kernel, IProfileService profileService, IRgbService rgbService, IWindowService windowService,
|
||||
IProfileEditorService profileEditorService, ISidebarVmFactory sidebarVmFactory, IProfileEditorVmFactory profileEditorVmFactory)
|
||||
SidebarScreens = new ObservableCollection<SidebarScreenViewModel>
|
||||
{
|
||||
_hostScreen = hostScreen;
|
||||
_profileService = profileService;
|
||||
_rgbService = rgbService;
|
||||
_windowService = windowService;
|
||||
_profileEditorService = profileEditorService;
|
||||
_sidebarVmFactory = sidebarVmFactory;
|
||||
new SidebarScreenViewModel<HomeViewModel>(MaterialIconKind.Home, "Home"),
|
||||
#if DEBUG
|
||||
new SidebarScreenViewModel<WorkshopViewModel>(MaterialIconKind.TestTube, "Workshop"),
|
||||
#endif
|
||||
new SidebarScreenViewModel<SurfaceEditorViewModel>(MaterialIconKind.Devices, "Surface Editor"),
|
||||
new SidebarScreenViewModel<SettingsViewModel>(MaterialIconKind.Cog, "Settings")
|
||||
};
|
||||
|
||||
SidebarScreens = new ObservableCollection<SidebarScreenViewModel>
|
||||
{
|
||||
new SidebarScreenViewModel<HomeViewModel>(MaterialIconKind.Home, "Home"),
|
||||
#if DEBUG
|
||||
new SidebarScreenViewModel<WorkshopViewModel>(MaterialIconKind.TestTube, "Workshop"),
|
||||
#endif
|
||||
new SidebarScreenViewModel<SurfaceEditorViewModel>(MaterialIconKind.Devices, "Surface Editor"),
|
||||
new SidebarScreenViewModel<SettingsViewModel>(MaterialIconKind.Cog, "Settings")
|
||||
};
|
||||
|
||||
UpdateProfileCategories();
|
||||
UpdateHeaderDevice();
|
||||
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);
|
||||
|
||||
SelectedSidebarScreen = SidebarScreens.First();
|
||||
});
|
||||
}
|
||||
|
||||
public ObservableCollection<SidebarScreenViewModel> SidebarScreens { get; }
|
||||
public ObservableCollection<SidebarCategoryViewModel> SidebarCategories { get; } = new();
|
||||
|
||||
public ArtemisDevice? HeaderDevice
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
get => _headerDevice;
|
||||
set => RaiseAndSetIfChanged(ref _headerDevice, value);
|
||||
}
|
||||
this.WhenAnyObservable(vm => vm._hostScreen.Router.CurrentViewModel)
|
||||
.WhereNotNull()
|
||||
.Subscribe(c => SelectedSidebarScreen = SidebarScreens.FirstOrDefault(s => s.ScreenType == c.GetType()))
|
||||
.DisposeWith(disposables);
|
||||
|
||||
public SidebarScreenViewModel? SelectedSidebarScreen
|
||||
{
|
||||
get => _selectedSidebarScreen;
|
||||
set => RaiseAndSetIfChanged(ref _selectedSidebarScreen, value);
|
||||
}
|
||||
this.WhenAnyValue(vm => vm.SelectedSidebarScreen)
|
||||
.WhereNotNull()
|
||||
.Subscribe(s =>
|
||||
{
|
||||
_hostScreen.Router.Navigate.Execute(s.CreateInstance(kernel, _hostScreen));
|
||||
profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||
});
|
||||
|
||||
public SidebarCategoryViewModel AddProfileCategoryViewModel(ProfileCategory profileCategory)
|
||||
{
|
||||
SidebarCategoryViewModel viewModel = _sidebarVmFactory.SidebarCategoryViewModel(this, profileCategory);
|
||||
SidebarCategories.Add(viewModel);
|
||||
return viewModel;
|
||||
}
|
||||
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 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();
|
||||
SelectedSidebarScreen = SidebarScreens.First();
|
||||
});
|
||||
}
|
||||
|
||||
UpdateProfileCategories();
|
||||
}
|
||||
public ObservableCollection<SidebarScreenViewModel> SidebarScreens { get; }
|
||||
public ObservableCollection<SidebarCategoryViewModel> SidebarCategories { get; } = new();
|
||||
|
||||
public void UpdateProfileCategories()
|
||||
{
|
||||
SidebarCategories.Clear();
|
||||
foreach (ProfileCategory profileCategory in _profileService.ProfileCategories.OrderBy(p => p.Order))
|
||||
AddProfileCategoryViewModel(profileCategory);
|
||||
}
|
||||
public ArtemisDevice? HeaderDevice
|
||||
{
|
||||
get => _headerDevice;
|
||||
set => RaiseAndSetIfChanged(ref _headerDevice, value);
|
||||
}
|
||||
|
||||
private void UpdateHeaderDevice()
|
||||
{
|
||||
HeaderDevice = _rgbService.Devices.FirstOrDefault(d => d.DeviceType == RGBDeviceType.Keyboard && d.Layout is {IsValid: true});
|
||||
}
|
||||
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});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user