1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Editor - Added message when profile failed to load

Editor - Implemented creating elements inside folders
This commit is contained in:
Robert 2022-01-06 23:11:55 +01:00
parent aa8667544f
commit 68cd8287a6
7 changed files with 114 additions and 29 deletions

View File

@ -6,31 +6,34 @@
x:Class="Artemis.UI.Shared.Services.ExceptionDialogView" x:Class="Artemis.UI.Shared.Services.ExceptionDialogView"
Title="{Binding Title}" Title="{Binding Title}"
ExtendClientAreaToDecorationsHint="True" ExtendClientAreaToDecorationsHint="True"
Width="800" Width="800"
Height="800" Height="800"
WindowStartupLocation="CenterOwner"> WindowStartupLocation="CenterOwner">
<Grid> <Grid>
<TextBlock Margin="10" IsHitTestVisible="False" Text="{Binding Title}" /> <Grid.RowDefinitions>
<Grid Margin="0 32 0 0" ColumnDefinitions="*,Auto" RowDefinitions="*,Auto"> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Margin="10" Grid.Row="1" IsHitTestVisible="False" Text="{Binding Title}" />
<Border Classes="card" Grid.Row="0" Grid.ColumnSpan="2" Margin="10"> <StackPanel Grid.Row="2" Margin="20">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="0 5"> <TextBlock Classes="h3">Awww :(</TextBlock>
<Grid RowDefinitions="Auto,Auto,*"> <TextBlock>
<TextBlock Grid.Row="0" Classes="h3">Awww :(</TextBlock> It looks like Artemis ran into an unhandled exception. If this keeps happening feel free to hit us up on Discord.
<TextBlock Grid.Row="1"> </TextBlock>
It looks like Artemis ran into an unhandled exception. If this keeps happening feel free to hit us up on Discord. </StackPanel>
</TextBlock>
<TextBox Grid.Row="2" Text="{Binding Exception, Mode=OneTime}" <Grid Grid.Row="3" ColumnDefinitions="*,Auto" RowDefinitions="*,Auto">
Margin="0 10" <ScrollViewer Grid.Row="0" Grid.ColumnSpan="2" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="20 0">
AcceptsReturn="True" <TextBox Text="{Binding Exception, Mode=OneTime}"
IsReadOnly="True" AcceptsReturn="True"
FontFamily="Consolas" IsReadOnly="True"
FontSize="12" FontFamily="Consolas"
BorderThickness="0" /> FontSize="12"
</Grid> BorderThickness="0" />
</ScrollViewer> </ScrollViewer>
</Border>
<TextBlock Grid.Row="1" Grid.Column="0" TextWrapping="Wrap" Margin="15" VerticalAlignment="Center"> <TextBlock Grid.Row="1" Grid.Column="0" TextWrapping="Wrap" Margin="15" VerticalAlignment="Center">
When reporting errors please don't take a screenshot of the error, instead copy the text, thanks! When reporting errors please don't take a screenshot of the error, instead copy the text, thanks!

View File

@ -31,7 +31,7 @@ namespace Artemis.UI.Shared.Services
_notificationService.CreateNotification() _notificationService.CreateNotification()
.WithMessage("Copied stack trace to clipboard.") .WithMessage("Copied stack trace to clipboard.")
.WithSeverity(NotificationSeverity.Success) .WithSeverity(NotificationSeverity.Success)
.WithHorizontalPosition(HorizontalAlignment.Center) .WithHorizontalPosition(HorizontalAlignment.Left)
.Show(); .Show();
} }
} }

View File

@ -1,13 +1,17 @@
using Artemis.Core.Ninject; using System;
using System.Reactive;
using Artemis.Core.Ninject;
using Artemis.Core; using Artemis.Core;
using Artemis.UI.Exceptions; using Artemis.UI.Exceptions;
using Artemis.UI.Ninject; using Artemis.UI.Ninject;
using Artemis.UI.Screens.Root; using Artemis.UI.Screens.Root;
using Artemis.UI.Shared.Ninject; using Artemis.UI.Shared.Ninject;
using Artemis.UI.Shared.Services.Interfaces;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Ninject; using Ninject;
using ReactiveUI;
using Splat.Ninject; using Splat.Ninject;
namespace Artemis.UI namespace Artemis.UI
@ -23,7 +27,7 @@ namespace Artemis.UI
throw new ArtemisUIException("UI already bootstrapped"); throw new ArtemisUIException("UI already bootstrapped");
Utilities.PrepareFirstLaunch(); Utilities.PrepareFirstLaunch();
_application = application; _application = application;
_kernel = new StandardKernel(); _kernel = new StandardKernel();
_kernel.Settings.InjectNonPublic = true; _kernel.Settings.InjectNonPublic = true;
@ -42,7 +46,7 @@ namespace Artemis.UI
if (_application == null || _kernel == null) if (_application == null || _kernel == null)
throw new ArtemisUIException("UI not yet bootstrapped"); throw new ArtemisUIException("UI not yet bootstrapped");
if (_application.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) if (_application.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
return; return;
// Don't shut down when the last window closes, we might still be active in the tray // Don't shut down when the last window closes, we might still be active in the tray
desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown; desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
@ -50,6 +54,13 @@ namespace Artemis.UI
RootViewModel rootViewModel = _kernel.Get<RootViewModel>(); RootViewModel rootViewModel = _kernel.Get<RootViewModel>();
// Apply the root view model to the data context of the application so that tray icon commands work // Apply the root view model to the data context of the application so that tray icon commands work
_application.DataContext = rootViewModel; _application.DataContext = rootViewModel;
RxApp.DefaultExceptionHandler = Observer.Create<Exception>(DisplayUnhandledException);
}
private static void DisplayUnhandledException(Exception exception)
{
_kernel?.Get<IWindowService>().ShowExceptionDialog("Exception", exception);
} }
} }
} }

View File

@ -21,7 +21,49 @@
</TreeView.KeyBindings> </TreeView.KeyBindings>
<TreeView.ItemTemplate> <TreeView.ItemTemplate>
<TreeDataTemplate ItemsSource="{Binding Children}"> <TreeDataTemplate ItemsSource="{Binding Children}">
<ContentControl Content="{Binding}" /> <ContentControl Content="{Binding}">
<ContentControl.ContextFlyout>
<MenuFlyout>
<MenuItem Header="Add new folder" Command="{Binding AddFolder}">
<MenuItem.Icon>
<avalonia:MaterialIcon Kind="CreateNewFolder" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Add new layer" Command="{Binding AddLayer}">
<MenuItem.Icon>
<avalonia:MaterialIcon Kind="LayersPlus" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Duplicate" Command="{Binding DuplicateElement}" InputGesture="Ctrl+D" IsEnabled="False">
<MenuItem.Icon>
<avalonia:MaterialIcon Kind="ContentDuplicate" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Copy" Command="{Binding CopyElement}" InputGesture="Ctrl+C" IsEnabled="False">
<MenuItem.Icon>
<avalonia:MaterialIcon Kind="ContentCopy" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Paste" Command="{Binding PasteElement}" InputGesture="Ctrl+V">
<MenuItem.Icon>
<avalonia:MaterialIcon Kind="ContentPaste" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Rename" Command="{Binding RenameElement}" InputGesture="F2" IsEnabled="False">
<MenuItem.Icon>
<avalonia:MaterialIcon Kind="RenameBox" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Delete" Command="{Binding DeleteElement}" InputGesture="Delete" IsEnabled="False">
<MenuItem.Icon>
<avalonia:MaterialIcon Kind="TrashCan" />
</MenuItem.Icon>
</MenuItem>
</MenuFlyout>
</ContentControl.ContextFlyout>
</ContentControl>
</TreeDataTemplate> </TreeDataTemplate>
</TreeView.ItemTemplate> </TreeView.ItemTemplate>
</TreeView> </TreeView>

View File

@ -22,12 +22,18 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
{ {
profileEditorService.ProfileConfiguration.WhereNotNull().Subscribe(configuration => profileEditorService.ProfileConfiguration.WhereNotNull().Subscribe(configuration =>
{ {
ProfileElement = configuration.Profile!.GetRootFolder(); if (configuration.Profile == null)
{
windowService.ShowConfirmContentDialog("Failed to load profile", "It appears that this profile is corrupt and cannot be loaded. Please check your logs.", "Confirm", null);
return;
}
ProfileElement = configuration.Profile.GetRootFolder();
SubscribeToProfileElement(d); SubscribeToProfileElement(d);
CreateTreeItems(); CreateTreeItems();
}).DisposeWith(d); }).DisposeWith(d);
profileEditorService.ProfileElement.WhereNotNull().Subscribe(SelectCurrentProfileElement).DisposeWith(d); profileEditorService.ProfileElement.Subscribe(SelectCurrentProfileElement).DisposeWith(d);
}); });
this.WhenAnyValue(vm => vm.SelectedChild).Subscribe(model => this.WhenAnyValue(vm => vm.SelectedChild).Subscribe(model =>
@ -43,7 +49,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
set => this.RaiseAndSetIfChanged(ref _selectedChild, value); set => this.RaiseAndSetIfChanged(ref _selectedChild, value);
} }
private void SelectCurrentProfileElement(RenderProfileElement element) private void SelectCurrentProfileElement(RenderProfileElement? element)
{ {
if (SelectedChild?.ProfileElement == element) if (SelectedChild?.ProfileElement == element)
return; return;

View File

@ -20,13 +20,16 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
{ {
private readonly IProfileEditorVmFactory _profileEditorVmFactory; private readonly IProfileEditorVmFactory _profileEditorVmFactory;
private readonly IWindowService _windowService; private readonly IWindowService _windowService;
private readonly IProfileEditorService _profileEditorService;
private bool _isExpanded; private bool _isExpanded;
private ProfileElement? _profileElement; private ProfileElement? _profileElement;
private RenderProfileElement? _currentProfileElement;
protected TreeItemViewModel(TreeItemViewModel? parent, ProfileElement? profileElement, IWindowService windowService, IProfileEditorService profileEditorService, protected TreeItemViewModel(TreeItemViewModel? parent, ProfileElement? profileElement, IWindowService windowService, IProfileEditorService profileEditorService,
IProfileEditorVmFactory profileEditorVmFactory) IProfileEditorVmFactory profileEditorVmFactory)
{ {
_windowService = windowService; _windowService = windowService;
_profileEditorService = profileEditorService;
_profileEditorVmFactory = profileEditorVmFactory; _profileEditorVmFactory = profileEditorVmFactory;
Parent = parent; Parent = parent;
@ -50,6 +53,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
this.WhenActivated(d => this.WhenActivated(d =>
{ {
_profileEditorService.ProfileElement.Subscribe(element => _currentProfileElement = element).DisposeWith(d);
SubscribeToProfileElement(d); SubscribeToProfileElement(d);
CreateTreeItems(); CreateTreeItems();
}); });
@ -105,6 +109,10 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
List<TreeItemViewModel> toRemove = Children.Where(t => t.ProfileElement == profileElement).ToList(); List<TreeItemViewModel> toRemove = Children.Where(t => t.ProfileElement == profileElement).ToList();
foreach (TreeItemViewModel treeItemViewModel in toRemove) foreach (TreeItemViewModel treeItemViewModel in toRemove)
Children.Remove(treeItemViewModel); Children.Remove(treeItemViewModel);
// Deselect the current profile element if removed
if (_currentProfileElement == profileElement)
_profileEditorService.ChangeCurrentProfileElement(null);
} }
protected void AddTreeItemIfMissing(ProfileElement profileElement) protected void AddTreeItemIfMissing(ProfileElement profileElement)
@ -116,6 +124,10 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
Children.Insert(folder.Parent.Children.IndexOf(folder), _profileEditorVmFactory.FolderTreeItemViewModel(this, folder)); Children.Insert(folder.Parent.Children.IndexOf(folder), _profileEditorVmFactory.FolderTreeItemViewModel(this, folder));
else if (profileElement is Layer layer) else if (profileElement is Layer layer)
Children.Insert(layer.Parent.Children.IndexOf(layer), _profileEditorVmFactory.LayerTreeItemViewModel(this, layer)); Children.Insert(layer.Parent.Children.IndexOf(layer), _profileEditorVmFactory.LayerTreeItemViewModel(this, layer));
// Select the newly added element
if (profileElement is RenderProfileElement renderProfileElement)
_profileEditorService.ChangeCurrentProfileElement(renderProfileElement);
} }
protected void CreateTreeItems() protected void CreateTreeItems()
@ -127,10 +139,12 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
return; return;
foreach (ProfileElement profileElement in ProfileElement.Children) foreach (ProfileElement profileElement in ProfileElement.Children)
{
if (profileElement is Folder folder) if (profileElement is Folder folder)
Children.Add(_profileEditorVmFactory.FolderTreeItemViewModel(this, folder)); Children.Add(_profileEditorVmFactory.FolderTreeItemViewModel(this, folder));
else if (profileElement is Layer layer) else if (profileElement is Layer layer)
Children.Add(_profileEditorVmFactory.LayerTreeItemViewModel(this, layer)); Children.Add(_profileEditorVmFactory.LayerTreeItemViewModel(this, layer));
}
} }
} }
} }

View File

@ -143,7 +143,16 @@ namespace Artemis.UI.Screens.Sidebar
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?")) if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
return; return;
_profileService.RemoveProfileConfiguration(_profileConfiguration); try
{
_profileService.RemoveProfileConfiguration(_profileConfiguration);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
Close(true); Close(true);
} }