Browse Source

Add Env var settings

pull/55/head
Ionite 1 year ago
parent
commit
7c4d55ab8d
No known key found for this signature in database
  1. 3
      StabilityMatrix.Avalonia/App.axaml.cs
  2. 8
      StabilityMatrix.Avalonia/DesignData/DesignData.cs
  3. 27
      StabilityMatrix.Avalonia/ViewModels/Dialogs/EnvVarsViewModel.cs
  4. 29
      StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs
  5. 70
      StabilityMatrix.Avalonia/Views/Dialogs/EnvVarsDialog.axaml
  6. 17
      StabilityMatrix.Avalonia/Views/Dialogs/EnvVarsDialog.axaml.cs
  7. 6
      StabilityMatrix.Avalonia/Views/Dialogs/LaunchOptionsDialog.axaml
  8. 51
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml
  9. 13
      StabilityMatrix.Core/Models/EnvVarKeyPair.cs

3
StabilityMatrix.Avalonia/App.axaml.cs

@ -232,6 +232,7 @@ public sealed class App : Application
services.AddTransient<SelectDataDirectoryViewModel>();
services.AddTransient<LaunchOptionsViewModel>();
services.AddTransient<ExceptionViewModel>();
services.AddTransient<EnvVarsViewModel>();
services.AddSingleton<FirstLaunchSetupViewModel>();
services.AddSingleton<UpdateViewModel>();
@ -258,6 +259,7 @@ public sealed class App : Application
.Register(provider.GetRequiredService<CheckpointFile>)
.Register(provider.GetRequiredService<RefreshBadgeViewModel>)
.Register(provider.GetRequiredService<ExceptionViewModel>)
.Register(provider.GetRequiredService<EnvVarsViewModel>)
.Register(provider.GetRequiredService<ProgressManagerViewModel>)
.Register(provider.GetRequiredService<FirstLaunchSetupViewModel>));
}
@ -277,6 +279,7 @@ public sealed class App : Application
services.AddTransient<LaunchOptionsDialog>();
services.AddTransient<UpdateDialog>();
services.AddTransient<ExceptionDialog>();
services.AddTransient<EnvVarsDialog>();
// Controls
services.AddTransient<RefreshBadge>();

8
StabilityMatrix.Avalonia/DesignData/DesignData.cs

@ -298,6 +298,14 @@ public static class DesignData
}
});
public static EnvVarsViewModel EnvVarsViewModel => DialogFactory.Get<EnvVarsViewModel>(viewModel =>
{
viewModel.EnvVars = new List<EnvVarKeyPair>
{
new("UWU", "TRUE"),
};
});
public static RefreshBadgeViewModel RefreshBadgeViewModel => new()
{
State = ProgressState.Success

27
StabilityMatrix.Avalonia/ViewModels/Dialogs/EnvVarsViewModel.cs

@ -0,0 +1,27 @@
using System.Collections.Generic;
using Avalonia.Collections;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Models;
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
[View(typeof(EnvVarsViewModel))]
public partial class EnvVarsViewModel : ContentDialogViewModelBase
{
[ObservableProperty]
private string title = "Environment Variables";
[ObservableProperty, NotifyPropertyChangedFor(nameof(EnvVarsView))]
private IList<EnvVarKeyPair> envVars = new List<EnvVarKeyPair>();
public DataGridCollectionView EnvVarsView => new(EnvVars);
// Add new environment variable
[RelayCommand]
private void AddEnvVar()
{
EnvVars.Add(new EnvVarKeyPair());
}
}

29
StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs

@ -17,7 +17,9 @@ using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Helpers;
using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Dialogs;
using StabilityMatrix.Avalonia.Views;
using StabilityMatrix.Avalonia.Views.Dialogs;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Helper;
@ -39,6 +41,7 @@ public partial class SettingsViewModel : PageViewModelBase
private readonly ISettingsManager settingsManager;
private readonly IPrerequisiteHelper prerequisiteHelper;
private readonly IPyRunner pyRunner;
private readonly ServiceManager<ViewModelBase> dialogFactory;
public SharedState SharedState { get; }
public override string Title => "Settings";
@ -77,12 +80,14 @@ public partial class SettingsViewModel : PageViewModelBase
ISettingsManager settingsManager,
IPrerequisiteHelper prerequisiteHelper,
IPyRunner pyRunner,
ServiceManager<ViewModelBase> dialogFactory,
SharedState sharedState)
{
this.notificationService = notificationService;
this.settingsManager = settingsManager;
this.prerequisiteHelper = prerequisiteHelper;
this.pyRunner = pyRunner;
this.dialogFactory = dialogFactory;
SharedState = sharedState;
SelectedTheme = settingsManager.Settings.Theme ?? AvailableThemes[1];
@ -111,6 +116,26 @@ public partial class SettingsViewModel : PageViewModelBase
settingsManager.Transaction(s => s.RemoveFolderLinksOnShutdown = value);
}
#region Package Environment
[RelayCommand]
private async Task OpenEnvVarsDialog()
{
var viewModel = dialogFactory.Get<EnvVarsViewModel>();
var dialog = new BetterContentDialog
{
Content = new EnvVarsDialog
{
DataContext = viewModel
},
PrimaryButtonText = "Save",
IsPrimaryButtonEnabled = true,
CloseButtonText = "Cancel",
};
await dialog.ShowAsync();
}
[RelayCommand]
private async Task CheckPythonVersion()
{
@ -143,6 +168,10 @@ public partial class SettingsViewModel : PageViewModelBase
await dialog.ShowAsync();
}
#endregion
#region System
/// <summary>

70
StabilityMatrix.Avalonia/Views/Dialogs/EnvVarsDialog.axaml

@ -0,0 +1,70 @@
<controls:UserControlBase xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData"
xmlns:controls="clr-namespace:StabilityMatrix.Avalonia.Controls"
xmlns:models="clr-namespace:StabilityMatrix.Core.Models;assembly=StabilityMatrix.Core"
xmlns:dialogs="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Dialogs"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
d:DataContext="{x:Static mocks:DesignData.EnvVarsViewModel}"
x:DataType="dialogs:EnvVarsViewModel"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="StabilityMatrix.Avalonia.Views.Dialogs.EnvVarsDialog">
<controls:UserControlBase.Resources>
<Style Selector="DataGridCell /template/ Border#CellBorder">
<Setter Property="Background" Value="Aqua"/>
</Style>
</controls:UserControlBase.Resources>
<Grid RowDefinitions="Auto,Auto,*" MinHeight="300" Margin="8">
<StackPanel
HorizontalAlignment="Stretch"
Spacing="4"
Margin="0,0,0,0"
Orientation="Vertical">
<!-- Title -->
<TextBlock
FontSize="24"
FontWeight="Bold"
Margin="16,16,16,0"
Text="{Binding Title}"
TextWrapping="Wrap" />
</StackPanel>
<Panel Grid.Row="1">
<ui:CommandBar >
<ui:CommandBar.PrimaryCommands>
<ui:CommandBarButton IconSource="Add" Label="Save" Command="{Binding AddEnvVarCommand}"/>
<ui:CommandBarButton IconSource="Remove" Label="Undo" />
<ui:CommandBarSeparator />
<ui:CommandBarButton IconSource="Copy" Label="Bold" />
</ui:CommandBar.PrimaryCommands>
</ui:CommandBar>
</Panel>
<!-- Option Cards -->
<controls:Card Grid.Row="2"
Background="Transparent"
VerticalAlignment="Stretch"
VerticalContentAlignment="Stretch">
<DataGrid
MinHeight="200"
ItemsSource="{Binding EnvVarsView}" >
<DataGrid.Columns>
<DataGridTextColumn x:DataType="models:EnvVarKeyPair"
Width="5*"
Header="Name"
Binding="{Binding Key}" />
<DataGridTextColumn x:DataType="models:EnvVarKeyPair"
Width="5*"
Header="Value"
Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
</controls:Card>
</Grid>
</controls:UserControlBase>

17
StabilityMatrix.Avalonia/Views/Dialogs/EnvVarsDialog.axaml.cs

@ -0,0 +1,17 @@
using Avalonia.Markup.Xaml;
using StabilityMatrix.Avalonia.Controls;
namespace StabilityMatrix.Avalonia.Views.Dialogs;
public partial class EnvVarsDialog : UserControlBase
{
public EnvVarsDialog()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}

6
StabilityMatrix.Avalonia/Views/Dialogs/LaunchOptionsDialog.axaml

@ -46,7 +46,7 @@
IsVisible="{Binding IsSearchBoxEnabled}"
x:Name="SearchBox">
<TextBox.InnerRightContent>
<ui:SymbolIcon Symbol="Find" />
<ui:SymbolIcon Symbol="Find" Margin="0,0,8,0" />
</TextBox.InnerRightContent>
</TextBox>
</StackPanel>
@ -60,7 +60,7 @@
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
<StackPanel Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
@ -68,7 +68,7 @@
<controls:LaunchOptionCardTemplateSelector>
<!-- Int type card (textboxes) -->
<DataTemplate x:DataType="models:LaunchOptionCard" x:Key="{x:Static models:LaunchOptionType.Int}">
<controls:Card Margin="0,8">
<controls:Card>
<StackPanel
HorizontalAlignment="Stretch"
Margin="8,0,8,0"

51
StabilityMatrix.Avalonia/Views/SettingsPage.axaml

@ -59,30 +59,41 @@
</ui:SettingsExpander>
</Grid>
<!-- Python Options -->
<!-- Environment Options -->
<Grid RowDefinitions="auto,*">
<TextBlock
FontWeight="Medium"
Text="Python Environment"
Text="Package Environment"
Margin="0,16,0,0" />
<ui:SettingsExpander
Grid.Row="1"
Header="Embedded Python Environment"
Margin="8">
<ui:SettingsExpander.IconSource>
<controls:FASymbolIconSource Symbol="fa-brands fa-python"/>
</ui:SettingsExpander.IconSource>
<ui:SettingsExpander.Footer>
<StackPanel Orientation="Horizontal" Spacing="16">
<controls:ProgressRing
IsEnabled="{Binding CheckPythonVersionCommand.IsRunning}"
IsVisible="{Binding CheckPythonVersionCommand.IsRunning}"
IsIndeterminate="True"
BorderThickness="3"/>
<Button Content="Check Version" Command="{Binding CheckPythonVersionCommand}"/>
</StackPanel>
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
<StackPanel Grid.Row="1" Margin="0,8" Spacing="4">
<ui:SettingsExpander
Header="Environment Variables"
IconSource="OtherUser"
Margin="8,0">
<ui:SettingsExpander.Footer>
<Button Content="Edit" Command="{Binding OpenEnvVarsDialogCommand}"/>
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
<ui:SettingsExpander
Header="Embedded Python"
Margin="8,0">
<ui:SettingsExpander.IconSource>
<controls:FASymbolIconSource Symbol="fa-brands fa-python"/>
</ui:SettingsExpander.IconSource>
<ui:SettingsExpander.Footer>
<StackPanel Orientation="Horizontal" Spacing="16">
<controls:ProgressRing
IsEnabled="{Binding CheckPythonVersionCommand.IsRunning}"
IsVisible="{Binding CheckPythonVersionCommand.IsRunning}"
IsIndeterminate="True"
BorderThickness="3"/>
<Button Content="Check Version" Command="{Binding CheckPythonVersionCommand}"/>
</StackPanel>
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
</StackPanel>
</Grid>
<!-- System Options -->

13
StabilityMatrix.Core/Models/EnvVarKeyPair.cs

@ -0,0 +1,13 @@
namespace StabilityMatrix.Core.Models;
public class EnvVarKeyPair
{
public string Key { get; set; }
public string Value { get; set; }
public EnvVarKeyPair(string key = "", string value = "")
{
Key = key;
Value = value;
}
}
Loading…
Cancel
Save