User and system variables

This commit is contained in:
Stefan Markovic
2023-09-05 12:12:45 +02:00
parent b725ded223
commit 30c716159a
12 changed files with 177 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

View File

@@ -50,6 +50,9 @@
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="WinUIEx" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" />
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="CommunityToolkit.Labs.WinUI.SettingsControls" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

View File

@@ -4,12 +4,115 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:EnvironmentVariables.EnvironmentVariablesXAML.Views"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
xmlns:local="using:EnvironmentVariables.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:EnvironmentVariables.Models"
xmlns:ui="using:CommunityToolkit.WinUI.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<Grid>
<TextBlock>AAAAAAAAA</TextBlock>
<i:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="Loaded">
<ic:InvokeCommandAction Command="{x:Bind ViewModel.LoadEnvironmentVariablesCommand}" />
</ic:EventTriggerBehavior>
</i:Interaction.Behaviors>
<Grid Margin="16">
<Grid.RowDefinitions>
<!-- Button -->
<RowDefinition />
<!-- Profiles -->
<RowDefinition />
<!-- Default sets -->
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<!-- Left side -->
<ColumnDefinition />
<!-- Applied values -->
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button
x:Uid="NewProfileBtn"
Grid.Row="0"
Grid.Column="0" />
<TextBlock Grid.Row="1" Grid.Column="0">Placeholder for profiles</TextBlock>
<Grid Grid.Row="2" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock x:Uid="DefaultVariablesLbl" />
<StackPanel Grid.Row="1" Orientation="Vertical">
<labs:SettingsExpander>
<labs:SettingsExpander.Header>
<!-- TODO(stefan): How to use HeaderIcon here instead of this stack panel???? -->
<StackPanel Orientation="Horizontal" Spacing="8">
<Image
Width="16"
Height="16"
Source="{x:Bind ViewModel.UserDefaultSet.IconPath}" />
<TextBlock Text="{x:Bind ViewModel.UserDefaultSet.Name}" />
</StackPanel>
</labs:SettingsExpander.Header>
<labs:SettingsExpander.Items>
<ListView
x:Name="UserDefaultSetVariablesList"
x:Uid="UserDefaultSetVariablesList"
ItemsSource="{x:Bind ViewModel.UserDefaultSet.Variables, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:Variable">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="50" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1"><Run Text="{x:Bind Name}" /></TextBlock>
<TextBlock Grid.Column="2"><Run Text="{x:Bind Values}" /></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</labs:SettingsExpander.Items>
</labs:SettingsExpander>
<labs:SettingsExpander>
<labs:SettingsExpander.Header>
<!-- TODO(stefan): How to use HeaderIcon here instead of this stack panel???? -->
<StackPanel Orientation="Horizontal" Spacing="8">
<Image
Width="16"
Height="16"
Source="{x:Bind ViewModel.SystemDefaultSet.IconPath}" />
<TextBlock Text="{x:Bind ViewModel.SystemDefaultSet.Name}" />
</StackPanel>
</labs:SettingsExpander.Header>
<labs:SettingsExpander.Items>
<ListView
x:Name="SystemDefaultSetVariablesList"
x:Uid="SystemDefaultSetVariablesList"
ItemsSource="{x:Bind ViewModel.SystemDefaultSet.Variables, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:Variable">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="50" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1"><Run Text="{x:Bind Name}" /></TextBlock>
<TextBlock Grid.Column="2"><Run Text="{x:Bind Values}" /></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</labs:SettingsExpander.Items>
</labs:SettingsExpander>
</StackPanel>
</Grid>
</Grid>
</Page>

View File

@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using EnvironmentVariables.ViewModels;
using Microsoft.UI.Xaml.Controls;
namespace EnvironmentVariables.Views
@@ -11,9 +12,13 @@ namespace EnvironmentVariables.Views
/// </summary>
public sealed partial class MainPage : Page
{
public MainViewModel ViewModel { get; private set; }
public MainPage()
{
this.InitializeComponent();
ViewModel = App.GetService<MainViewModel>();
DataContext = ViewModel;
}
}
}

View File

@@ -3,14 +3,13 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
namespace EnvironmentVariables.Models
{
public class DefaultVariablesSet : VariablesSet
{
public DefaultVariablesSet(Guid id, string name, List<Variable> variables)
: base(id, name, VariablesSetType.Default, variables)
public DefaultVariablesSet(Guid id, string name, VariablesSetType type)
: base(id, name, type)
{
}
}

View File

@@ -3,14 +3,13 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
namespace EnvironmentVariables.Models
{
public class ProfileVariablesSet : VariablesSet
{
public ProfileVariablesSet(Guid id, string name, List<Variable> variables)
: base(id, name, VariablesSetType.UserProfile, variables)
public ProfileVariablesSet(Guid id, string name)
: base(id, name, VariablesSetType.Profile)
{
}
}

View File

@@ -9,20 +9,37 @@ namespace EnvironmentVariables.Models
{
public class VariablesSet
{
public static readonly Guid UserGuid = new Guid("92F7AA9A-AE31-49CD-83C8-80A71E432AA5");
public static readonly Guid SystemGuid = new Guid("F679C74D-DB00-4795-92E1-B1F6A4833279");
private static readonly string UserIconPath = "/Assets/EnvironmentVariables/UserIcon.png";
private static readonly string SystemIconPath = "/Assets/EnvironmentVariables/SystemIcon.png";
private static readonly string ProfileIconPath = "/Assets/EnvironmentVariables/ProfileIcon.png";
public Guid Id { get; }
public string Name { get; }
public VariablesSetType Type { get; }
public string IconPath { get; }
public List<Variable> Variables { get; }
public VariablesSet(Guid id, string name, VariablesSetType type, List<Variable> variables)
public VariablesSet(Guid id, string name, VariablesSetType type)
{
Id = id;
Name = name;
Type = type;
Variables = variables;
Variables = new List<Variable>();
IconPath = Type switch
{
VariablesSetType.User => UserIconPath,
VariablesSetType.System => SystemIconPath,
VariablesSetType.Profile => ProfileIconPath,
_ => throw new NotImplementedException(),
};
}
}
}

View File

@@ -6,7 +6,8 @@ namespace EnvironmentVariables.Models
{
public enum VariablesSetType
{
Default = 0,
UserProfile,
User = 0,
System,
Profile,
}
}

View File

@@ -120,6 +120,18 @@
<data name="DefaultSetsLabel.Text" xml:space="preserve">
<value>Default variables</value>
</data>
<data name="DefaultVariablesLbl.Text" xml:space="preserve">
<value>Default variables</value>
</data>
<data name="NewProfileBtn.Content" xml:space="preserve">
<value>New</value>
</data>
<data name="System" xml:space="preserve">
<value>System</value>
</data>
<data name="User" xml:space="preserve">
<value>User</value>
</data>
<data name="WindowTitle" xml:space="preserve">
<value>Environment Variables</value>
</data>

View File

@@ -2,9 +2,33 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.Input;
using EnvironmentVariables.Helpers;
using EnvironmentVariables.Models;
namespace EnvironmentVariables.ViewModels
{
public class MainViewModel
public partial class MainViewModel
{
public VariablesSet UserDefaultSet { get; private set; } = new DefaultVariablesSet(VariablesSet.UserGuid, ResourceLoaderInstance.ResourceLoader.GetString("User"), VariablesSetType.User);
public VariablesSet SystemDefaultSet { get; private set; } = new DefaultVariablesSet(VariablesSet.SystemGuid, ResourceLoaderInstance.ResourceLoader.GetString("System"), VariablesSetType.System);
public MainViewModel()
{
}
[RelayCommand]
public void LoadEnvironmentVariables()
{
UserDefaultSet.Variables.Add(new Variable("user1", "value1"));
UserDefaultSet.Variables.Add(new Variable("user2", "value2"));
SystemDefaultSet.Variables.Add(new Variable("system1", "svalue1"));
SystemDefaultSet.Variables.Add(new Variable("system2", "svalue2"));
}
}
}