mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
[New+]Support for variables in template filenames (#37074)
* Add variable support - initial version without UI * Add variable in template filename support in New+ * Fix XAML style * Addressed code review feedback
This commit is contained in:
committed by
GitHub
parent
1d358af600
commit
1f81d14000
@@ -18,6 +18,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
HideFileExtension = new BoolProperty(true);
|
||||
HideStartingDigits = new BoolProperty(true);
|
||||
TemplateLocation = new StringProperty(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "PowerToys", "NewPlus", "Templates"));
|
||||
ReplaceVariables = new BoolProperty(false);
|
||||
}
|
||||
|
||||
[JsonPropertyName("HideFileExtension")]
|
||||
@@ -29,6 +30,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
[JsonPropertyName("TemplateLocation")]
|
||||
public StringProperty TemplateLocation { get; set; }
|
||||
|
||||
[JsonPropertyName("ReplaceVariables")]
|
||||
public BoolProperty ReplaceVariables { get; set; }
|
||||
|
||||
public override string ToString() => JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<Page
|
||||
<Page
|
||||
x:Class="Microsoft.PowerToys.Settings.UI.Views.NewPlusPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Microsoft.PowerToys.Settings.UI.ViewModels"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||
@@ -84,6 +85,116 @@
|
||||
</tkcontrols:SettingsCard.Description>
|
||||
</tkcontrols:SettingsCard>
|
||||
</controls:SettingsGroup>
|
||||
|
||||
<controls:SettingsGroup x:Uid="NewPlus_behavior" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
|
||||
<tkcontrols:SettingsCard x:Uid="NewPlus_Behaviour_Replace_Variables_Toggle" IsEnabled="{x:Bind ViewModel.IsReplaceVariablesSettingsCardEnabled, Mode=OneWay}">
|
||||
<StackPanel Orientation="Horizontal" Spacing="4">
|
||||
<ToggleSwitch x:Uid="ReplaceVariablesToggle" IsOn="{x:Bind ViewModel.ReplaceVariables, Mode=TwoWay}" />
|
||||
<Button
|
||||
x:Uid="FileCreationButton"
|
||||
Width="28"
|
||||
Height="40"
|
||||
Margin="0,0,-4,0"
|
||||
Padding="0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
Content=""
|
||||
FontFamily="{ThemeResource SymbolThemeFontFamily}">
|
||||
<Button.Flyout>
|
||||
<Flyout x:Name="VariableExamplesFlyout" ShouldConstrainToRootBounds="False">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="62" />
|
||||
<ColumnDefinition Width="300" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Text="$YYYY" />
|
||||
<TextBlock
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,0,5"
|
||||
TextWrapping="Wrap"><Run x:Uid="NewPlus_Year_YYYY_Variable_Description" /></TextBlock>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Text="$MM" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,0,5"
|
||||
TextWrapping="Wrap"><Run x:Uid="NewPlus_Month_MM_Variable_Description" /></TextBlock>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
Text="$DD" />
|
||||
<TextBlock
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,0,5"
|
||||
TextWrapping="Wrap"><Run x:Uid="NewPlus_Day_DD_Variable_Description" /></TextBlock>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="3"
|
||||
Grid.Column="0"
|
||||
Text="$hh" />
|
||||
<TextBlock
|
||||
Grid.Row="3"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,0,5"
|
||||
TextWrapping="Wrap"><Run x:Uid="NewPlus_Hour_hh_Variable_Description" /></TextBlock>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="4"
|
||||
Grid.Column="0"
|
||||
Text="$mm" />
|
||||
<TextBlock
|
||||
Grid.Row="4"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,0,5"
|
||||
TextWrapping="Wrap"><Run x:Uid="NewPlus_Minute_mm_Variable_Description" /></TextBlock>
|
||||
|
||||
<TextBlock
|
||||
Grid.Row="5"
|
||||
Grid.Column="0"
|
||||
Text="$ss" />
|
||||
<TextBlock
|
||||
Grid.Row="5"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,0,0"
|
||||
TextWrapping="Wrap"><Run x:Uid="NewPlus_Second_ss_Variable_Description" /></TextBlock>
|
||||
</Grid>
|
||||
</Flyout>
|
||||
</Button.Flyout>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<tkcontrols:SettingsCard.Description>
|
||||
<StackPanel>
|
||||
<HyperlinkButton x:Uid="NewPlus_Behaviour_Replace_Variables_Learn_More" NavigateUri="https://aka.ms/PowerToysOverview_NewPlus" />
|
||||
</StackPanel>
|
||||
</tkcontrols:SettingsCard.Description>
|
||||
</tkcontrols:SettingsCard>
|
||||
<InfoBar
|
||||
x:Uid="GPO_SettingIsManaged"
|
||||
IsClosable="False"
|
||||
IsOpen="{x:Bind ViewModel.IsReplaceVariablesSettingGPOConfigured, Mode=OneWay}"
|
||||
IsTabStop="{x:Bind ViewModel.IsReplaceVariablesSettingGPOConfigured, Mode=OneWay}"
|
||||
Severity="Informational" />
|
||||
</controls:SettingsGroup>
|
||||
</StackPanel>
|
||||
</controls:SettingsPageControl.ModuleContent>
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
// 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.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
|
||||
@@ -4445,6 +4445,46 @@ Activate by holding the key for the character you want to add an accent to, then
|
||||
<value>This option is useful when using digits, spaces and dots at the beginning of filenames to control the display order of templates</value>
|
||||
<comment>Template filename starting digits settings toggle</comment>
|
||||
</data>
|
||||
<data name="NewPlus_behavior.Header" xml:space="preserve">
|
||||
<value>Behavior</value>
|
||||
<comment>New+ behavior related settings label</comment>
|
||||
</data>
|
||||
<data name="NewPlus_Behaviour_Replace_Variables_Toggle.Header" xml:space="preserve">
|
||||
<value>Replace variables in template filename</value>
|
||||
<comment>New+ replace variables in template filename behavior toggle</comment>
|
||||
</data>
|
||||
<data name="NewPlus_Behaviour_Replace_Variables_Learn_More.Content" xml:space="preserve">
|
||||
<value>Learn more about supported variables and see examples</value>
|
||||
<comment>New+ help link to learn more about supported variables and see examples</comment>
|
||||
</data>
|
||||
<data name="NewPlus_Behaviour_Replace_Variables_Info_Card_Title.Text" xml:space="preserve">
|
||||
<value>Commonly used variables</value>
|
||||
<comment>New+ commonly used variables header in the flyout info card</comment>
|
||||
</data>
|
||||
<data name="NewPlus_Year_YYYY_Variable_Description.Text" xml:space="preserve">
|
||||
<value>Year, represented by a full four or five digits, depending on the calendar used.</value>
|
||||
<comment>New+ description of the year $YYYY variable - casing of $YYYY is important</comment>
|
||||
</data>
|
||||
<data name="NewPlus_Month_MM_Variable_Description.Text" xml:space="preserve">
|
||||
<value>Month, as digits with leading zeros for single-digit months.</value>
|
||||
<comment>New+ description of the month $MM variable - casing of $MM is important</comment>
|
||||
</data>
|
||||
<data name="NewPlus_Day_DD_Variable_Description.Text" xml:space="preserve">
|
||||
<value>Day of the month, as digits with leading zeros for single-digit days.</value>
|
||||
<comment>New+ description of the day $DD variable - casing of $DD is important</comment>
|
||||
</data>
|
||||
<data name="NewPlus_Hour_hh_Variable_Description.Text" xml:space="preserve">
|
||||
<value>Hours, with leading zeros for single-digit hours.</value>
|
||||
<comment>New+ description of the hour $hh variable - casing of $hh is important</comment>
|
||||
</data>
|
||||
<data name="NewPlus_Minute_mm_Variable_Description.Text" xml:space="preserve">
|
||||
<value>Minutes, with leading zeros for single-digit minutes.</value>
|
||||
<comment>New+ description of the minute $mm variable - casing of $mm is important</comment>
|
||||
</data>
|
||||
<data name="NewPlus_Second_ss_Variable_Description.Text" xml:space="preserve">
|
||||
<value>Seconds, with leading zeros for single-digit seconds.</value>
|
||||
<comment>New+ description of the second $ss variable - casing of $ss is important</comment>
|
||||
</data>
|
||||
<data name="NewPlus.SecondaryLinksHeader" xml:space="preserve">
|
||||
<value>Attribution</value>
|
||||
<comment>giving credit</comment>
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using global::PowerToys.GPOWrapper;
|
||||
@@ -18,8 +17,6 @@ using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
using Microsoft.PowerToys.Settings.UI.SerializationContext;
|
||||
using Windows.ApplicationModel.VoiceCommands;
|
||||
using Windows.System;
|
||||
|
||||
using static Microsoft.PowerToys.Settings.UI.Helpers.ShellGetFolder;
|
||||
|
||||
@@ -50,6 +47,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
_hideFileExtension = Settings.Properties.HideFileExtension.Value;
|
||||
_hideStartingDigits = Settings.Properties.HideStartingDigits.Value;
|
||||
_templateLocation = Settings.Properties.TemplateLocation.Value;
|
||||
_replaceVariables = Settings.Properties.ReplaceVariables.Value;
|
||||
InitializeEnabledValue();
|
||||
InitializeGpoValues();
|
||||
|
||||
@@ -77,6 +75,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
// Policy for hide file extension setting
|
||||
_hideFileExtensionGpoRuleConfiguration = GPOWrapper.GetConfiguredNewPlusHideTemplateFilenameExtensionValue();
|
||||
_hideFileExtensionIsGPOConfigured = _hideFileExtensionGpoRuleConfiguration == GpoRuleConfigured.Disabled || _hideFileExtensionGpoRuleConfiguration == GpoRuleConfigured.Enabled;
|
||||
|
||||
// Same for Replace Variables
|
||||
_replaceVariablesIsGPOConfigured = GPOWrapper.GetConfiguredNewPlusReplaceVariablesValue() == GpoRuleConfigured.Enabled
|
||||
|| GPOWrapper.GetConfiguredNewPlusReplaceVariablesValue() == GpoRuleConfigured.Disabled;
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
@@ -92,6 +94,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
OnPropertyChanged(nameof(IsHideFileExtSettingsCardEnabled));
|
||||
OnPropertyChanged(nameof(IsHideFileExtSettingGPOConfigured));
|
||||
OnPropertyChanged(nameof(IsReplaceVariablesSettingGPOConfigured));
|
||||
OnPropertyChanged(nameof(IsReplaceVariablesSettingsCardEnabled));
|
||||
|
||||
OutGoingGeneralSettings outgoingMessage = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
SendConfigMSG(outgoingMessage.ToString());
|
||||
@@ -156,6 +160,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
public bool IsHideFileExtSettingGPOConfigured => _isNewPlusEnabled && _hideFileExtensionIsGPOConfigured;
|
||||
|
||||
public bool IsReplaceVariablesSettingsCardEnabled => _isNewPlusEnabled && !_replaceVariablesIsGPOConfigured;
|
||||
|
||||
public bool IsReplaceVariablesSettingGPOConfigured => _isNewPlusEnabled && _replaceVariablesIsGPOConfigured;
|
||||
|
||||
public bool HideStartingDigits
|
||||
{
|
||||
get => _hideStartingDigits;
|
||||
@@ -172,6 +180,32 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool ReplaceVariables
|
||||
{
|
||||
get
|
||||
{
|
||||
// Check to see if setting has been enabled or disabled via GPO, and if so, use that value
|
||||
if (IsReplaceVariablesSettingGPOConfigured)
|
||||
{
|
||||
return GPOWrapper.GetConfiguredNewPlusReplaceVariablesValue() == GpoRuleConfigured.Enabled;
|
||||
}
|
||||
|
||||
return _replaceVariables;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_replaceVariables != value)
|
||||
{
|
||||
_replaceVariables = value;
|
||||
Settings.Properties.ReplaceVariables.Value = value;
|
||||
OnPropertyChanged(nameof(ReplaceVariables));
|
||||
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEnabledGpoConfigured
|
||||
{
|
||||
get => _enabledStateIsGPOConfigured;
|
||||
@@ -236,11 +270,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
private string _templateLocation;
|
||||
private bool _hideFileExtension;
|
||||
private bool _hideStartingDigits;
|
||||
private bool _replaceVariables;
|
||||
|
||||
private GpoRuleConfigured _enabledGpoRuleConfiguration;
|
||||
private bool _enabledStateIsGPOConfigured;
|
||||
private GpoRuleConfigured _hideFileExtensionGpoRuleConfiguration;
|
||||
private bool _hideFileExtensionIsGPOConfigured;
|
||||
private bool _replaceVariablesIsGPOConfigured;
|
||||
|
||||
public void RefreshEnabledState()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user