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

@ -10,27 +10,30 @@
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>
<TextBlock Grid.Row="1">
It looks like Artemis ran into an unhandled exception. If this keeps happening feel free to hit us up on Discord. It looks like Artemis ran into an unhandled exception. If this keeps happening feel free to hit us up on Discord.
</TextBlock> </TextBlock>
</StackPanel>
<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">
<TextBox Text="{Binding Exception, Mode=OneTime}"
AcceptsReturn="True" AcceptsReturn="True"
IsReadOnly="True" IsReadOnly="True"
FontFamily="Consolas" FontFamily="Consolas"
FontSize="12" FontSize="12"
BorderThickness="0" /> BorderThickness="0" />
</Grid>
</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
@ -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;
try
{
_profileService.RemoveProfileConfiguration(_profileConfiguration); _profileService.RemoveProfileConfiguration(_profileConfiguration);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
Close(true); Close(true);
} }