diff --git a/src/Artemis.Core/Models/Profile/ProfileElement.cs b/src/Artemis.Core/Models/Profile/ProfileElement.cs index e30b5d355..60ecda321 100644 --- a/src/Artemis.Core/Models/Profile/ProfileElement.cs +++ b/src/Artemis.Core/Models/Profile/ProfileElement.cs @@ -203,6 +203,14 @@ namespace Artemis.Core if (Disposed) throw new ObjectDisposedException(GetType().Name); + ProfileElement? current = this; + while (current != null) + { + if (ReferenceEquals(child, this)) + throw new ArtemisCoreException("Cannot make an element a child of itself"); + current = current.Parent; + } + lock (ChildrenList) { if (ChildrenList.Contains(child)) diff --git a/src/Avalonia/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs b/src/Avalonia/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs index 366a3e90f..0657f256c 100644 --- a/src/Avalonia/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs +++ b/src/Avalonia/Artemis.UI/Screens/Sidebar/Dialogs/ProfileConfigurationEditViewModel.cs @@ -8,6 +8,7 @@ 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; @@ -17,10 +18,11 @@ using ReactiveUI; namespace Artemis.UI.Screens.Sidebar { - public class ProfileConfigurationEditViewModel : DialogViewModelBase + public class ProfileConfigurationEditViewModel : DialogViewModelBase { private readonly ProfileCategory _profileCategory; private readonly IProfileService _profileService; + private readonly IProfileEditorService _profileEditorService; private readonly IWindowService _windowService; private Hotkey? _disableHotkey; private Hotkey? _enableHotkey; @@ -35,12 +37,18 @@ namespace Artemis.UI.Screens.Sidebar private ProfileModuleViewModel? _selectedModule; private SvgImage? _selectedSvgSource; - public ProfileConfigurationEditViewModel(ProfileCategory profileCategory, ProfileConfiguration? profileConfiguration, IWindowService windowService, - IProfileService profileService, IPluginManagementService pluginManagementService) + 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().First().ToString()); _profileName = _profileConfiguration.Name; _iconType = _profileConfiguration.Icon.IconType; @@ -133,7 +141,7 @@ namespace Artemis.UI.Screens.Sidebar // Import the new profile configuration _profileService.ImportProfile(_profileCategory, profileConfigurationExportModel); - Close(true); + Close(_profileConfiguration); } public async Task Delete() @@ -145,6 +153,8 @@ namespace Artemis.UI.Screens.Sidebar try { + if (_profileConfiguration.IsBeingEdited) + _profileEditorService.ChangeCurrentProfileConfiguration(null); _profileService.RemoveProfileConfiguration(_profileConfiguration); } catch (Exception e) @@ -152,8 +162,8 @@ namespace Artemis.UI.Screens.Sidebar Console.WriteLine(e); throw; } - - Close(true); + + Close(_profileConfiguration); } public async Task Confirm() @@ -168,14 +178,14 @@ namespace Artemis.UI.Screens.Sidebar _profileService.SaveProfileConfigurationIcon(ProfileConfiguration); _profileService.SaveProfileCategory(_profileCategory); - Close(true); + Close(ProfileConfiguration); } public void Cancel() { if (IsNew) _profileService.RemoveProfileConfiguration(_profileConfiguration); - Close(false); + Close(null); } #region Icon diff --git a/src/Avalonia/Artemis.UI/Screens/Sidebar/SidebarCategoryView.axaml b/src/Avalonia/Artemis.UI/Screens/Sidebar/SidebarCategoryView.axaml index ec6820379..2d75e58eb 100644 --- a/src/Avalonia/Artemis.UI/Screens/Sidebar/SidebarCategoryView.axaml +++ b/src/Avalonia/Artemis.UI/Screens/Sidebar/SidebarCategoryView.axaml @@ -8,7 +8,6 @@ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Artemis.UI.Screens.Sidebar.SidebarCategoryView"> - @@ -99,20 +98,7 @@ - - - - - - - - - - - (("profileCategory", ProfileCategory), ("profileConfiguration", null)); - if (result) - _sidebarViewModel.UpdateProfileCategories(); + ProfileConfiguration? result = await _windowService.ShowDialogAsync( + ("profileCategory", ProfileCategory), + ("profileConfiguration", null) + ); + if (result != null) + { + SidebarProfileConfigurationViewModel viewModel = _vmFactory.SidebarProfileConfigurationViewModel(_sidebarViewModel, result); + ProfileConfigurations.Add(viewModel); + SelectedProfileConfiguration = viewModel; + } } private void CreateProfileViewModels() diff --git a/src/Avalonia/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.axaml b/src/Avalonia/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.axaml index 42c77832e..a803394db 100644 --- a/src/Avalonia/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.axaml +++ b/src/Avalonia/Artemis.UI/Screens/Sidebar/SidebarProfileConfigurationView.axaml @@ -102,7 +102,7 @@ -