1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

Sidebar - Open newly created profiles in the editor

Sidebar - Close the editor when deleting the current profile
Sidebar - Removed test drag/drop that was breaking the settings/suspend button
This commit is contained in:
Robert 2022-03-09 19:06:39 +01:00
parent 376a9142d3
commit 5e4fd1de8b
7 changed files with 54 additions and 33 deletions

View File

@ -203,6 +203,14 @@ namespace Artemis.Core
if (Disposed) if (Disposed)
throw new ObjectDisposedException(GetType().Name); 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) lock (ChildrenList)
{ {
if (ChildrenList.Contains(child)) if (ChildrenList.Contains(child))

View File

@ -8,6 +8,7 @@ using Artemis.Core.Modules;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.UI.Shared; using Artemis.UI.Shared;
using Artemis.UI.Shared.Services.Interfaces; using Artemis.UI.Shared.Services.Interfaces;
using Artemis.UI.Shared.Services.ProfileEditor;
using Avalonia.Media.Imaging; using Avalonia.Media.Imaging;
using Avalonia.Svg.Skia; using Avalonia.Svg.Skia;
using Avalonia.Threading; using Avalonia.Threading;
@ -17,10 +18,11 @@ using ReactiveUI;
namespace Artemis.UI.Screens.Sidebar namespace Artemis.UI.Screens.Sidebar
{ {
public class ProfileConfigurationEditViewModel : DialogViewModelBase<bool> public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConfiguration?>
{ {
private readonly ProfileCategory _profileCategory; private readonly ProfileCategory _profileCategory;
private readonly IProfileService _profileService; private readonly IProfileService _profileService;
private readonly IProfileEditorService _profileEditorService;
private readonly IWindowService _windowService; private readonly IWindowService _windowService;
private Hotkey? _disableHotkey; private Hotkey? _disableHotkey;
private Hotkey? _enableHotkey; private Hotkey? _enableHotkey;
@ -35,12 +37,18 @@ namespace Artemis.UI.Screens.Sidebar
private ProfileModuleViewModel? _selectedModule; private ProfileModuleViewModel? _selectedModule;
private SvgImage? _selectedSvgSource; private SvgImage? _selectedSvgSource;
public ProfileConfigurationEditViewModel(ProfileCategory profileCategory, ProfileConfiguration? profileConfiguration, IWindowService windowService, public ProfileConfigurationEditViewModel(
IProfileService profileService, IPluginManagementService pluginManagementService) ProfileCategory profileCategory,
ProfileConfiguration? profileConfiguration,
IWindowService windowService,
IProfileService profileService,
IProfileEditorService profileEditorService,
IPluginManagementService pluginManagementService)
{ {
_profileCategory = profileCategory; _profileCategory = profileCategory;
_windowService = windowService; _windowService = windowService;
_profileService = profileService; _profileService = profileService;
_profileEditorService = profileEditorService;
_profileConfiguration = profileConfiguration ?? profileService.CreateProfileConfiguration(profileCategory, "New profile", Enum.GetValues<MaterialIconKind>().First().ToString()); _profileConfiguration = profileConfiguration ?? profileService.CreateProfileConfiguration(profileCategory, "New profile", Enum.GetValues<MaterialIconKind>().First().ToString());
_profileName = _profileConfiguration.Name; _profileName = _profileConfiguration.Name;
_iconType = _profileConfiguration.Icon.IconType; _iconType = _profileConfiguration.Icon.IconType;
@ -133,7 +141,7 @@ namespace Artemis.UI.Screens.Sidebar
// Import the new profile configuration // Import the new profile configuration
_profileService.ImportProfile(_profileCategory, profileConfigurationExportModel); _profileService.ImportProfile(_profileCategory, profileConfigurationExportModel);
Close(true); Close(_profileConfiguration);
} }
public async Task Delete() public async Task Delete()
@ -145,6 +153,8 @@ namespace Artemis.UI.Screens.Sidebar
try try
{ {
if (_profileConfiguration.IsBeingEdited)
_profileEditorService.ChangeCurrentProfileConfiguration(null);
_profileService.RemoveProfileConfiguration(_profileConfiguration); _profileService.RemoveProfileConfiguration(_profileConfiguration);
} }
catch (Exception e) catch (Exception e)
@ -153,7 +163,7 @@ namespace Artemis.UI.Screens.Sidebar
throw; throw;
} }
Close(true); Close(_profileConfiguration);
} }
public async Task Confirm() public async Task Confirm()
@ -168,14 +178,14 @@ namespace Artemis.UI.Screens.Sidebar
_profileService.SaveProfileConfigurationIcon(ProfileConfiguration); _profileService.SaveProfileConfigurationIcon(ProfileConfiguration);
_profileService.SaveProfileCategory(_profileCategory); _profileService.SaveProfileCategory(_profileCategory);
Close(true); Close(ProfileConfiguration);
} }
public void Cancel() public void Cancel()
{ {
if (IsNew) if (IsNew)
_profileService.RemoveProfileConfiguration(_profileConfiguration); _profileService.RemoveProfileConfiguration(_profileConfiguration);
Close(false); Close(null);
} }
#region Icon #region Icon

View File

@ -8,7 +8,6 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Sidebar.SidebarCategoryView"> x:Class="Artemis.UI.Screens.Sidebar.SidebarCategoryView">
<UserControl.Styles> <UserControl.Styles>
<StyleInclude Source="avares://Avalonia.Xaml.Interactions/Draggable/Styles.axaml" />
<Style Selector=":is(Button).category-button"> <Style Selector=":is(Button).category-button">
<Setter Property="IsVisible" Value="False" /> <Setter Property="IsVisible" Value="False" />
</Style> </Style>
@ -99,20 +98,7 @@
</Grid> </Grid>
<Border Grid.Row="1"> <Border Grid.Row="1">
<Border.Resources> <ListBox Classes="sidebar-listbox"
<DataTemplate x:Key="ProfileDragTemplate" DataType="{x:Type local:SidebarProfileConfigurationViewModel}">
<Border Background="{DynamicResource MaterialDesignDivider}" Padding="10" CornerRadius="4">
<StackPanel Orientation="Horizontal">
<controls:ProfileConfigurationIcon ConfigurationIcon="{Binding ProfileConfiguration.Icon}"
Width="20"
Height="20"
Margin="0 0 10 0" />
<TextBlock Text="{Binding ProfileConfiguration.Name}" VerticalAlignment="Center" />
</StackPanel>
</Border>
</DataTemplate>
</Border.Resources>
<ListBox Classes="sidebar-listbox draggable"
Items="{Binding ProfileConfigurations}" Items="{Binding ProfileConfigurations}"
SelectedItem="{Binding SelectedProfileConfiguration}" SelectedItem="{Binding SelectedProfileConfiguration}"
MinHeight="10" MinHeight="10"

View File

@ -99,9 +99,16 @@ namespace Artemis.UI.Screens.Sidebar
public async Task AddProfile() public async Task AddProfile()
{ {
bool result = await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, bool>(("profileCategory", ProfileCategory), ("profileConfiguration", null)); ProfileConfiguration? result = await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, ProfileConfiguration?>(
if (result) ("profileCategory", ProfileCategory),
_sidebarViewModel.UpdateProfileCategories(); ("profileConfiguration", null)
);
if (result != null)
{
SidebarProfileConfigurationViewModel viewModel = _vmFactory.SidebarProfileConfigurationViewModel(_sidebarViewModel, result);
ProfileConfigurations.Add(viewModel);
SelectedProfileConfiguration = viewModel;
}
} }
private void CreateProfileViewModels() private void CreateProfileViewModels()

View File

@ -102,7 +102,7 @@
</Border> </Border>
<Button Command="{Binding EditProfile}" <Button Command="{CompiledBinding EditProfile}"
Classes="icon-button icon-button-small" Classes="icon-button icon-button-small"
Grid.Column="2" Grid.Column="2"
ToolTip.Tip="View properties" ToolTip.Tip="View properties"

View File

@ -1,4 +1,5 @@
using System.Reactive.Disposables; using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.Core; using Artemis.Core;
@ -24,6 +25,7 @@ namespace Artemis.UI.Screens.Sidebar
_windowService = windowService; _windowService = windowService;
ProfileConfiguration = profileConfiguration; ProfileConfiguration = profileConfiguration;
EditProfile = ReactiveCommand.CreateFromTask(ExecuteEditProfile);
this.WhenActivated(d => this.WhenActivated(d =>
{ {
@ -34,6 +36,8 @@ namespace Artemis.UI.Screens.Sidebar
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration); _profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
} }
public ReactiveCommand<Unit, Unit> EditProfile { get; }
public bool IsProfileActive => ProfileConfiguration.Profile != null; public bool IsProfileActive => ProfileConfiguration.Profile != null;
public bool IsSuspended public bool IsSuspended
@ -46,9 +50,14 @@ namespace Artemis.UI.Screens.Sidebar
} }
} }
public async Task EditProfile() public async Task ExecuteEditProfile()
{ {
if (await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, bool>(("profileCategory", ProfileConfiguration.Category), ("profileConfiguration", ProfileConfiguration))) ProfileConfiguration? deleted = await _windowService.ShowDialogAsync<ProfileConfigurationEditViewModel, ProfileConfiguration?>(
("profileCategory", ProfileConfiguration.Category),
("profileConfiguration", ProfileConfiguration)
);
if (deleted != null)
_sidebarViewModel.UpdateProfileCategories(); _sidebarViewModel.UpdateProfileCategories();
} }
} }

View File

@ -73,10 +73,11 @@ namespace Artemis.UI.Screens.Sidebar
}); });
this.WhenAnyObservable(vm => vm._profileEditorService.ProfileConfiguration) this.WhenAnyObservable(vm => vm._profileEditorService.ProfileConfiguration)
.WhereNotNull() .Subscribe(profile =>
.Subscribe(_ =>
{ {
if (_hostScreen.Router.GetCurrentViewModel() is not ProfileEditorViewModel) 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)); _hostScreen.Router.Navigate.Execute(profileEditorVmFactory.ProfileEditorViewModel(_hostScreen));
}) })
.DisposeWith(disposables); .DisposeWith(disposables);