mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-29 00:24:42 +01:00
Edit profile
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
xmlns:views="using:EnvironmentVariables.Views"
|
||||
xmlns:winuiex="using:WinUIEx"
|
||||
x:Uid="Window"
|
||||
MinWidth="700"
|
||||
MinHeight="480"
|
||||
mc:Ignorable="d">
|
||||
<Window.SystemBackdrop>
|
||||
<MicaBackdrop />
|
||||
|
||||
@@ -140,13 +140,23 @@
|
||||
<DataTemplate x:DataType="models:ProfileVariablesSet">
|
||||
<controls:SettingsExpander
|
||||
Margin="0,0,0,4"
|
||||
Header="{x:Bind Name}"
|
||||
Header="{x:Bind Name, Mode=TwoWay}"
|
||||
HeaderIcon="{ui:FontIcon Glyph=}"
|
||||
ItemTemplate="{StaticResource VariableTemplate}"
|
||||
ItemsSource="{x:Bind Variables, Mode=OneWay}">
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind Mode=TwoWay, Path=IsEnabled}" />
|
||||
<Button
|
||||
x:Name="EditProfileBtn"
|
||||
x:Uid="EditProfileBtn"
|
||||
Width="40"
|
||||
Height="36"
|
||||
Click="EditProfileBtn_Click"
|
||||
CommandParameter="{x:Bind (models:ProfileVariablesSet)}"
|
||||
Content=""
|
||||
FontFamily="{ThemeResource SymbolThemeFontFamily}"
|
||||
Style="{StaticResource SubtleButtonStyle}" />
|
||||
<Button
|
||||
x:Name="RemoveProfileBtn"
|
||||
x:Uid="RemoveProfileBtn"
|
||||
@@ -198,7 +208,7 @@
|
||||
Visibility="{x:Bind ViewModel.IsElevated, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
|
||||
<!-- TO DO: Glyph not showing, known WinUI issue - need to follow up with team -->
|
||||
<InfoBadge IconSource="{ui:FontIconSource Glyph=}" Style="{StaticResource AttentionIconInfoBadgeStyle}" />
|
||||
<TextBlock x:Uid="EditSystemDefaultSetInfoBar" />
|
||||
<TextBlock x:Uid="EditSystemDefaultSetInfoBar" />
|
||||
</StackPanel>
|
||||
</controls:SettingsExpander.Description>
|
||||
</controls:SettingsExpander>
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace EnvironmentVariables.Views
|
||||
|
||||
public ICommand AddProfileCommand => new RelayCommand(AddProfile);
|
||||
|
||||
public ICommand UpdateProfileCommand => new RelayCommand(UpdateProfile);
|
||||
|
||||
public ICommand AddVariableCommand => new RelayCommand(AddVariable);
|
||||
|
||||
public MainPage()
|
||||
@@ -86,6 +88,12 @@ namespace EnvironmentVariables.Views
|
||||
ViewModel.AddProfile(profile);
|
||||
}
|
||||
|
||||
private void UpdateProfile()
|
||||
{
|
||||
var updatedProfile = AddProfileDialog.DataContext as ProfileVariablesSet;
|
||||
ViewModel.UpdateProfile(updatedProfile);
|
||||
}
|
||||
|
||||
private async void RemoveProfileBtn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||
{
|
||||
var button = sender as Button;
|
||||
@@ -192,5 +200,24 @@ namespace EnvironmentVariables.Views
|
||||
ConfirmAddVariableBtn.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async void EditProfileBtn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||
{
|
||||
SwitchViewsSegmentedView.SelectedIndex = 0;
|
||||
|
||||
var button = sender as Button;
|
||||
var profile = button.CommandParameter as ProfileVariablesSet;
|
||||
|
||||
if (profile != null)
|
||||
{
|
||||
var resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
||||
AddProfileDialog.Title = resourceLoader.GetString("AddNewProfileDialog_Title");
|
||||
AddProfileDialog.PrimaryButtonText = resourceLoader.GetString("SaveBtn");
|
||||
AddProfileDialog.SecondaryButtonText = resourceLoader.GetString("CancelBtn");
|
||||
AddProfileDialog.PrimaryButtonCommand = UpdateProfileCommand;
|
||||
AddProfileDialog.DataContext = profile.Clone();
|
||||
await AddProfileDialog.ShowAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using EnvironmentVariables.Helpers;
|
||||
using EnvironmentVariables.ViewModels;
|
||||
using ManagedCommon;
|
||||
|
||||
namespace EnvironmentVariables.Models
|
||||
@@ -118,5 +118,14 @@ namespace EnvironmentVariables.Models
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ProfileVariablesSet Clone()
|
||||
{
|
||||
var clone = new ProfileVariablesSet(this.Id, this.Name);
|
||||
clone.Variables = new ObservableCollection<Variable>(this.Variables);
|
||||
clone.IsEnabled = this.IsEnabled;
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,4 +233,7 @@
|
||||
<data name="Delete_Variable_Description" xml:space="preserve">
|
||||
<value>Are you sure you want to delete this variable?</value>
|
||||
</data>
|
||||
<data name="EditProfileDialog_Title" xml:space="preserve">
|
||||
<value>Edit profile</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -169,6 +169,14 @@ namespace EnvironmentVariables.ViewModels
|
||||
_ = Task.Run(SaveAsync);
|
||||
}
|
||||
|
||||
internal void UpdateProfile(ProfileVariablesSet updatedProfile)
|
||||
{
|
||||
var existingProfile = Profiles.Where(x => x.Id == updatedProfile.Id).FirstOrDefault();
|
||||
existingProfile.Name = updatedProfile.Name;
|
||||
existingProfile.IsEnabled = updatedProfile.IsEnabled;
|
||||
existingProfile.Variables = updatedProfile.Variables;
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user