mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Plugin settings - Only enable install/uninstall prereqs when applicable
Sidebar - Added missing context menu on profiles
This commit is contained in:
parent
45e810c3ac
commit
3625d1ad11
@ -49,7 +49,7 @@
|
|||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<controls:SplitButton Content="Settings" Command="{CompiledBinding OpenSettings}">
|
<controls:SplitButton Content="Settings" Command="{CompiledBinding OpenSettings}">
|
||||||
<controls:SplitButton.Flyout>
|
<controls:SplitButton.Flyout>
|
||||||
<MenuFlyout Placement="Bottom" IsOpen="{CompiledBinding IsSettingsPopupOpen, Mode=OneWayToSource}">
|
<MenuFlyout Placement="Bottom" Opening="FlyoutBase_OnOpening">
|
||||||
<MenuItem Header="Open plugin directory" Command="{CompiledBinding OpenPluginDirectory}">
|
<MenuItem Header="Open plugin directory" Command="{CompiledBinding OpenPluginDirectory}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<avalonia:MaterialIcon Kind="FolderOpen" />
|
<avalonia:MaterialIcon Kind="FolderOpen" />
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
@ -27,4 +28,9 @@ public partial class PluginView : ReactiveUserControl<PluginViewModel>
|
|||||||
{
|
{
|
||||||
Dispatcher.UIThread.Post(() => ViewModel?.UpdateEnabled(!ViewModel.Plugin.IsEnabled));
|
Dispatcher.UIThread.Post(() => ViewModel?.UpdateEnabled(!ViewModel.Plugin.IsEnabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FlyoutBase_OnOpening(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ViewModel?.CheckPrerequisites();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -28,14 +28,13 @@ public class PluginViewModel : ActivatableViewModelBase
|
|||||||
private bool _canInstallPrerequisites;
|
private bool _canInstallPrerequisites;
|
||||||
private bool _canRemovePrerequisites;
|
private bool _canRemovePrerequisites;
|
||||||
private bool _enabling;
|
private bool _enabling;
|
||||||
private bool _isSettingsPopupOpen;
|
|
||||||
private Plugin _plugin;
|
private Plugin _plugin;
|
||||||
private Window? _window;
|
private Window? _window;
|
||||||
|
|
||||||
public PluginViewModel(Plugin plugin,
|
public PluginViewModel(Plugin plugin,
|
||||||
ReactiveCommand<Unit, Unit>? reload,
|
ReactiveCommand<Unit, Unit>? reload,
|
||||||
ICoreService coreService,
|
ICoreService coreService,
|
||||||
IWindowService windowService,
|
IWindowService windowService,
|
||||||
INotificationService notificationService,
|
INotificationService notificationService,
|
||||||
IPluginManagementService pluginManagementService)
|
IPluginManagementService pluginManagementService)
|
||||||
{
|
{
|
||||||
@ -105,16 +104,6 @@ public class PluginViewModel : ActivatableViewModelBase
|
|||||||
public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name;
|
public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name;
|
||||||
public bool IsEnabled => Plugin.IsEnabled;
|
public bool IsEnabled => Plugin.IsEnabled;
|
||||||
|
|
||||||
public bool IsSettingsPopupOpen
|
|
||||||
{
|
|
||||||
get => _isSettingsPopupOpen;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (!RaiseAndSetIfChanged(ref _isSettingsPopupOpen, value)) return;
|
|
||||||
CheckPrerequisites();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CanInstallPrerequisites
|
public bool CanInstallPrerequisites
|
||||||
{
|
{
|
||||||
get => _canInstallPrerequisites;
|
get => _canInstallPrerequisites;
|
||||||
@ -166,7 +155,7 @@ public class PluginViewModel : ActivatableViewModelBase
|
|||||||
_windowService.ShowExceptionDialog("Welp, we couldn't open the device's plugin folder for you", e);
|
_windowService.ShowExceptionDialog("Welp, we couldn't open the device's plugin folder for you", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ExecuteInstallPrerequisites()
|
private async Task ExecuteInstallPrerequisites()
|
||||||
{
|
{
|
||||||
List<IPrerequisitesSubject> subjects = new() {Plugin.Info};
|
List<IPrerequisitesSubject> subjects = new() {Plugin.Info};
|
||||||
@ -309,12 +298,17 @@ public class PluginViewModel : ActivatableViewModelBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void CheckPrerequisites()
|
public void CheckPrerequisites()
|
||||||
{
|
{
|
||||||
CanInstallPrerequisites = Plugin.Info.PlatformPrerequisites.Any() ||
|
CanInstallPrerequisites = false;
|
||||||
Plugin.Features.Where(f => f.AlwaysEnabled).Any(f => f.PlatformPrerequisites.Any());
|
CanRemovePrerequisites = false;
|
||||||
CanRemovePrerequisites = Plugin.Info.PlatformPrerequisites.Any(p => p.UninstallActions.Any()) ||
|
|
||||||
Plugin.Features.Where(f => f.AlwaysEnabled).Any(f => f.PlatformPrerequisites.Any(p => p.UninstallActions.Any()));
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
|
CanInstallPrerequisites = !Plugin.Info.ArePrerequisitesMet() || Plugin.Features.Where(f => f.AlwaysEnabled).Any(f => !f.ArePrerequisitesMet());
|
||||||
|
CanRemovePrerequisites = Plugin.Info.PlatformPrerequisites.Any(p => p.IsMet() && p.UninstallActions.Any()) ||
|
||||||
|
Plugin.Features.Where(f => f.AlwaysEnabled).Any(f => f.PlatformPrerequisites.Any(p => p.IsMet() && p.UninstallActions.Any()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPluginToggled(object? sender, EventArgs e)
|
private void OnPluginToggled(object? sender, EventArgs e)
|
||||||
|
|||||||
@ -101,7 +101,7 @@
|
|||||||
</TreeView.Styles>
|
</TreeView.Styles>
|
||||||
<TreeView.ItemTemplate>
|
<TreeView.ItemTemplate>
|
||||||
<TreeDataTemplate ItemsSource="{Binding Children}">
|
<TreeDataTemplate ItemsSource="{Binding Children}">
|
||||||
<ContentControl Content="{Binding}" x:DataType="profileTree:TreeItemViewModel">
|
<ContentControl Content="{Binding}" x:DataType="profileTree:TreeItemViewModel" Background="Transparent">
|
||||||
<ContentControl.ContextFlyout>
|
<ContentControl.ContextFlyout>
|
||||||
<MenuFlyout IsOpen="{CompiledBinding IsFlyoutOpen, Mode=OneWayToSource}">
|
<MenuFlyout IsOpen="{CompiledBinding IsFlyoutOpen, Mode=OneWayToSource}">
|
||||||
<MenuItem Header="Add new folder" Command="{CompiledBinding AddFolder}">
|
<MenuItem Header="Add new folder" Command="{CompiledBinding AddFolder}">
|
||||||
|
|||||||
@ -171,15 +171,6 @@
|
|||||||
MinHeight="10"
|
MinHeight="10"
|
||||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||||
ScrollViewer.VerticalScrollBarVisibility="Disabled">
|
ScrollViewer.VerticalScrollBarVisibility="Disabled">
|
||||||
<ListBox.ContextMenu>
|
|
||||||
<ContextMenu>
|
|
||||||
<MenuItem Header="Paste">
|
|
||||||
<MenuItem.Icon>
|
|
||||||
<avalonia:MaterialIcon Kind="ContentPaste" />
|
|
||||||
</MenuItem.Icon>
|
|
||||||
</MenuItem>
|
|
||||||
</ContextMenu>
|
|
||||||
</ListBox.ContextMenu>
|
|
||||||
</ListBox>
|
</ListBox>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@ -8,65 +8,56 @@
|
|||||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Artemis.UI.Screens.Sidebar.SidebarProfileConfigurationView"
|
x:Class="Artemis.UI.Screens.Sidebar.SidebarProfileConfigurationView"
|
||||||
x:DataType="sidebar:SidebarProfileConfigurationViewModel">
|
x:DataType="sidebar:SidebarProfileConfigurationViewModel"
|
||||||
|
Background="Transparent">
|
||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
<converters:ValuesAdditionConverter x:Key="ValuesAddition" />
|
<converters:ValuesAdditionConverter x:Key="ValuesAddition" />
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
<UserControl.ContextMenu>
|
<UserControl.ContextFlyout>
|
||||||
<ContextMenu>
|
<MenuFlyout>
|
||||||
<MenuItem Header="View properties">
|
<MenuItem Header="View properties" Command="{CompiledBinding EditProfile}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<avalonia:MaterialIcon Kind="Cog" />
|
<avalonia:MaterialIcon Kind="Cog" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="Suspend">
|
<MenuItem Header="Suspend" Command="{CompiledBinding ToggleSuspended}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<avalonia:MaterialIcon Kind="Pause" />
|
<avalonia:MaterialIcon Kind="Check" IsVisible="{CompiledBinding IsSuspended}" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="Suspend all">
|
<MenuItem Header="Suspend all">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<avalonia:MaterialIcon Kind="Pause" />
|
<avalonia:MaterialIcon Kind="Pause" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
<MenuItem Header="Above" CommandParameter="suspend" />
|
<MenuItem Header="Above" Command="{CompiledBinding SuspendAll}" CommandParameter="above" />
|
||||||
<MenuItem Header="Below" CommandParameter="suspend" />
|
<MenuItem Header="Below" Command="{CompiledBinding SuspendAll}" CommandParameter="below" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="Resume all">
|
<MenuItem Header="Resume all">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<avalonia:MaterialIcon Kind="Play" />
|
<avalonia:MaterialIcon Kind="Play" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
<MenuItem Header="Above" CommandParameter="resume" />
|
<MenuItem Header="Above" Command="{CompiledBinding ResumeAll}" CommandParameter="above" />
|
||||||
<MenuItem Header="Below" CommandParameter="resume" />
|
<MenuItem Header="Below" Command="{CompiledBinding ResumeAll}" CommandParameter="below" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<Separator />
|
<MenuItem Header="-" />
|
||||||
<MenuItem Header="Export">
|
<MenuItem Header="Export" Command="{CompiledBinding ExportProfile}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<avalonia:MaterialIcon Kind="Export" />
|
<avalonia:MaterialIcon Kind="Export" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="Duplicate">
|
<MenuItem Header="Duplicate" Command="{CompiledBinding DuplicateProfile}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<avalonia:MaterialIcon Kind="ContentDuplicate" />
|
<avalonia:MaterialIcon Kind="ContentDuplicate" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="Copy">
|
<MenuItem Header="-" />
|
||||||
<MenuItem.Icon>
|
<MenuItem Header="Delete" Command="{CompiledBinding DeleteProfile}">
|
||||||
<avalonia:MaterialIcon Kind="ContentCopy" />
|
|
||||||
</MenuItem.Icon>
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="Paste">
|
|
||||||
<MenuItem.Icon>
|
|
||||||
<avalonia:MaterialIcon Kind="ContentPaste" />
|
|
||||||
</MenuItem.Icon>
|
|
||||||
</MenuItem>
|
|
||||||
<Separator />
|
|
||||||
<MenuItem Header="Delete">
|
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<avalonia:MaterialIcon Kind="Trash" />
|
<avalonia:MaterialIcon Kind="Trash" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</ContextMenu>
|
</MenuFlyout>
|
||||||
</UserControl.ContextMenu>
|
</UserControl.ContextFlyout>
|
||||||
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
|
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
|
||||||
<shared:ProfileConfigurationIcon Grid.Column="0"
|
<shared:ProfileConfigurationIcon Grid.Column="0"
|
||||||
x:Name="ProfileIcon"
|
x:Name="ProfileIcon"
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
using System.Reactive;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reactive;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -6,6 +9,8 @@ using Artemis.Core;
|
|||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.Shared;
|
using Artemis.UI.Shared;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
|
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Sidebar
|
namespace Artemis.UI.Screens.Sidebar
|
||||||
@ -14,30 +19,43 @@ namespace Artemis.UI.Screens.Sidebar
|
|||||||
{
|
{
|
||||||
private readonly SidebarViewModel _sidebarViewModel;
|
private readonly SidebarViewModel _sidebarViewModel;
|
||||||
private readonly IProfileService _profileService;
|
private readonly IProfileService _profileService;
|
||||||
|
private readonly IProfileEditorService _profileEditorService;
|
||||||
private readonly IWindowService _windowService;
|
private readonly IWindowService _windowService;
|
||||||
private ObservableAsPropertyHelper<bool>? _isSuspended;
|
private ObservableAsPropertyHelper<bool>? _isSuspended;
|
||||||
public ProfileConfiguration ProfileConfiguration { get; }
|
public ProfileConfiguration ProfileConfiguration { get; }
|
||||||
|
|
||||||
public SidebarProfileConfigurationViewModel(SidebarViewModel sidebarViewModel, ProfileConfiguration profileConfiguration, IProfileService profileService, IWindowService windowService)
|
public SidebarProfileConfigurationViewModel(SidebarViewModel sidebarViewModel,
|
||||||
|
ProfileConfiguration profileConfiguration,
|
||||||
|
IProfileService profileService,
|
||||||
|
IProfileEditorService profileEditorService,
|
||||||
|
IWindowService windowService)
|
||||||
{
|
{
|
||||||
_sidebarViewModel = sidebarViewModel;
|
_sidebarViewModel = sidebarViewModel;
|
||||||
_profileService = profileService;
|
_profileService = profileService;
|
||||||
|
_profileEditorService = profileEditorService;
|
||||||
_windowService = windowService;
|
_windowService = windowService;
|
||||||
|
|
||||||
ProfileConfiguration = profileConfiguration;
|
ProfileConfiguration = profileConfiguration;
|
||||||
EditProfile = ReactiveCommand.CreateFromTask(ExecuteEditProfile);
|
EditProfile = ReactiveCommand.CreateFromTask(ExecuteEditProfile);
|
||||||
ToggleSuspended = ReactiveCommand.Create(ExecuteToggleSuspended);
|
ToggleSuspended = ReactiveCommand.Create(ExecuteToggleSuspended);
|
||||||
|
ResumeAll = ReactiveCommand.Create<string>(ExecuteResumeAll);
|
||||||
|
SuspendAll = ReactiveCommand.Create<string>(ExecuteSuspendAll);
|
||||||
|
DeleteProfile = ReactiveCommand.CreateFromTask(ExecuteDeleteProfile);
|
||||||
|
ExportProfile = ReactiveCommand.CreateFromTask(ExecuteExportProfile);
|
||||||
|
DuplicateProfile = ReactiveCommand.Create(ExecuteDuplicateProfile);
|
||||||
|
|
||||||
this.WhenActivated(d =>
|
this.WhenActivated(d => { _isSuspended = ProfileConfiguration.WhenAnyValue(c => c.IsSuspended).ToProperty(this, vm => vm.IsSuspended).DisposeWith(d); });
|
||||||
{
|
|
||||||
_isSuspended = ProfileConfiguration.WhenAnyValue(c => c.IsSuspended).ToProperty(this, vm => vm.IsSuspended).DisposeWith(d);
|
|
||||||
});
|
|
||||||
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
|
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> EditProfile { get; }
|
public ReactiveCommand<Unit, Unit> EditProfile { get; }
|
||||||
public ReactiveCommand<Unit,Unit> ToggleSuspended { get; }
|
public ReactiveCommand<Unit, Unit> ToggleSuspended { get; }
|
||||||
|
public ReactiveCommand<string, Unit> ResumeAll { get; }
|
||||||
|
public ReactiveCommand<string, Unit> SuspendAll { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> DeleteProfile { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> ExportProfile { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> DuplicateProfile { get; }
|
||||||
|
|
||||||
public bool IsSuspended => _isSuspended?.Value ?? false;
|
public bool IsSuspended => _isSuspended?.Value ?? false;
|
||||||
|
|
||||||
@ -51,11 +69,85 @@ namespace Artemis.UI.Screens.Sidebar
|
|||||||
if (edited != null)
|
if (edited != null)
|
||||||
_sidebarViewModel.UpdateProfileCategories();
|
_sidebarViewModel.UpdateProfileCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteToggleSuspended()
|
private void ExecuteToggleSuspended()
|
||||||
{
|
{
|
||||||
ProfileConfiguration.IsSuspended = !ProfileConfiguration.IsSuspended;
|
ProfileConfiguration.IsSuspended = !ProfileConfiguration.IsSuspended;
|
||||||
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ExecuteResumeAll(string direction)
|
||||||
|
{
|
||||||
|
int index = ProfileConfiguration.Category.ProfileConfigurations.IndexOf(ProfileConfiguration);
|
||||||
|
if (direction == "above")
|
||||||
|
{
|
||||||
|
for (int i = 0; i < index; i++)
|
||||||
|
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = index + 1; i < ProfileConfiguration.Category.ProfileConfigurations.Count; i++)
|
||||||
|
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExecuteSuspendAll(string direction)
|
||||||
|
{
|
||||||
|
int index = ProfileConfiguration.Category.ProfileConfigurations.IndexOf(ProfileConfiguration);
|
||||||
|
if (direction == "above")
|
||||||
|
{
|
||||||
|
for (int i = 0; i < index; i++)
|
||||||
|
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = index + 1; i < ProfileConfiguration.Category.ProfileConfigurations.Count; i++)
|
||||||
|
ProfileConfiguration.Category.ProfileConfigurations[i].IsSuspended = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_profileService.SaveProfileCategory(ProfileConfiguration.Category);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExecuteDeleteProfile()
|
||||||
|
{
|
||||||
|
if (!await _windowService.ShowConfirmContentDialog("Delete profile", "Are you sure you want to permanently delete this profile?"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ProfileConfiguration.IsBeingEdited)
|
||||||
|
_profileEditorService.ChangeCurrentProfileConfiguration(null);
|
||||||
|
_profileService.RemoveProfileConfiguration(ProfileConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExecuteExportProfile()
|
||||||
|
{
|
||||||
|
// Might not cover everything but then the dialog will complain and that's good enough
|
||||||
|
string fileName = Path.GetInvalidFileNameChars().Aggregate(ProfileConfiguration.Name, (current, c) => current.Replace(c, '-'));
|
||||||
|
string? result = await _windowService.CreateSaveFileDialog()
|
||||||
|
.HavingFilter(f => f.WithExtension("json").WithName("Artemis profile"))
|
||||||
|
.WithInitialFileName(fileName)
|
||||||
|
.ShowAsync();
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ProfileConfigurationExportModel export = _profileService.ExportProfile(ProfileConfiguration);
|
||||||
|
string json = JsonConvert.SerializeObject(export, IProfileService.ExportSettings);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await File.WriteAllTextAsync(result, json);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_windowService.ShowExceptionDialog("Failed to export profile", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExecuteDuplicateProfile()
|
||||||
|
{
|
||||||
|
ProfileConfigurationExportModel export = _profileService.ExportProfile(ProfileConfiguration);
|
||||||
|
_profileService.ImportProfile(ProfileConfiguration.Category, export, true, false, "copy");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user