1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +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)
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))

View File

@ -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<bool>
public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConfiguration?>
{
private readonly ProfileCategory _profileCategory;
private readonly IProfileService _profileService;
private readonly IProfileEditorService _profileEditorService;
private readonly IWindowService _windowService;
private Hotkey? _disableHotkey;
private Hotkey? _enableHotkey;
@ -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<MaterialIconKind>().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

View File

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

View File

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

View File

@ -102,7 +102,7 @@
</Border>
<Button Command="{Binding EditProfile}"
<Button Command="{CompiledBinding EditProfile}"
Classes="icon-button icon-button-small"
Grid.Column="2"
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.Threading.Tasks;
using Artemis.Core;
@ -24,6 +25,7 @@ namespace Artemis.UI.Screens.Sidebar
_windowService = windowService;
ProfileConfiguration = profileConfiguration;
EditProfile = ReactiveCommand.CreateFromTask(ExecuteEditProfile);
this.WhenActivated(d =>
{
@ -34,6 +36,8 @@ namespace Artemis.UI.Screens.Sidebar
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
}
public ReactiveCommand<Unit, Unit> EditProfile { get; }
public bool IsProfileActive => ProfileConfiguration.Profile != null;
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();
}
}

View File

@ -73,10 +73,11 @@ namespace Artemis.UI.Screens.Sidebar
});
this.WhenAnyObservable(vm => vm._profileEditorService.ProfileConfiguration)
.WhereNotNull()
.Subscribe(_ =>
.Subscribe(profile =>
{
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));
})
.DisposeWith(disposables);