mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
[PowerRename]Add random string values to file names (#32836)
* Add randomizer cheat sheet texts to UI tooltip * Add randomizer icon (shuffle) + hint to main window * Add randomizer logic + helpers, regex parsing * Fix: remove unnecessary throw * Fix: remove todo comment * Fix: iffing logic * Fix: add offset to randomizer onchange * Update: guid generating to single function, handle bracket removing there * Update: toggle off enum feat when random values are selected * Update: main window UI tooltip texts to be more descriptive * Update: remove unnecessary sstream include * Fix: return empty string if chars has no value to avoid memory access violation * Add unit tests * Add PowerRename random string generating keywords * Update: generating value names to be in line with POSIX conventions * Allow to used with Enumerate at the same time * Fix spellcheck * Fix tests to take into account we no longer eat up empty expressions with randomizer --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
@@ -15,6 +15,7 @@ namespace PowerRenameUI
|
||||
Windows.Foundation.Collections.IObservableVector<PatternSnippet> SearchRegExShortcuts { get; };
|
||||
Windows.Foundation.Collections.IObservableVector<PatternSnippet> DateTimeShortcuts { get; };
|
||||
Windows.Foundation.Collections.IObservableVector<PatternSnippet> CounterShortcuts { get; };
|
||||
Windows.Foundation.Collections.IObservableVector<PatternSnippet> RandomizerShortcuts { get; };
|
||||
|
||||
String OriginalCount;
|
||||
String RenamedCount;
|
||||
|
||||
@@ -327,6 +327,8 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock x:Uid="DateTimeCheatSheet_Title" FontWeight="SemiBold" />
|
||||
<ListView
|
||||
@@ -407,6 +409,47 @@
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
<TextBlock
|
||||
x:Uid="RandomizerCheatSheet_Title"
|
||||
Grid.Row="4"
|
||||
Margin="0,10,0,0"
|
||||
FontWeight="SemiBold" />
|
||||
<ListView
|
||||
Grid.Row="5"
|
||||
Margin="-4,12,0,0"
|
||||
IsItemClickEnabled="True"
|
||||
ItemClick="DateTimeItemClick"
|
||||
ItemsSource="{x:Bind RandomizerShortcuts}"
|
||||
SelectionMode="None">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="local:PatternSnippet">
|
||||
<Grid Margin="-10,0,0,0" ColumnSpacing="8">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border
|
||||
Padding="8"
|
||||
HorizontalAlignment="Left"
|
||||
Background="{ThemeResource ButtonBackground}"
|
||||
BorderBrush="{ThemeResource ButtonBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="4">
|
||||
<TextBlock
|
||||
FontFamily="Consolas"
|
||||
Foreground="{ThemeResource ButtonForeground}"
|
||||
Text="{x:Bind Code}" />
|
||||
</Border>
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="12"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
Text="{x:Bind Description}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</Grid>
|
||||
</Flyout>
|
||||
</Button.Flyout>
|
||||
@@ -508,6 +551,12 @@
|
||||
Height="32"
|
||||
Content=""
|
||||
FontFamily="{ThemeResource SymbolThemeFontFamily}" />
|
||||
<ToggleButton
|
||||
x:Name="toggleButton_randItems"
|
||||
x:Uid="ToggleButton_RandItems"
|
||||
Height="32"
|
||||
Content=""
|
||||
FontFamily="{ThemeResource SymbolThemeFontFamily}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
@@ -203,6 +203,12 @@ namespace winrt::PowerRenameUI::implementation
|
||||
m_CounterShortcuts.Append(winrt::make<PatternSnippet>(L"${padding=8}", manager.MainResourceMap().GetValue(L"Resources/CounterCheatSheet_Padding").ValueAsString()));
|
||||
m_CounterShortcuts.Append(winrt::make<PatternSnippet>(L"${increment=3,padding=4,start=900}", manager.MainResourceMap().GetValue(L"Resources/CounterCheatSheet_Complex").ValueAsString()));
|
||||
|
||||
m_RandomizerShortcuts = winrt::single_threaded_observable_vector<PowerRenameUI::PatternSnippet>();
|
||||
m_RandomizerShortcuts.Append(winrt::make<PatternSnippet>(L"${rstringalnum=9}", manager.MainResourceMap().GetValue(L"Resources/RandomizerCheatSheet_Alnum").ValueAsString()));
|
||||
m_RandomizerShortcuts.Append(winrt::make<PatternSnippet>(L"${rstringalpha=13}", manager.MainResourceMap().GetValue(L"Resources/RandomizerCheatSheet_Alpha").ValueAsString()));
|
||||
m_RandomizerShortcuts.Append(winrt::make<PatternSnippet>(L"${rstringdigit=36}", manager.MainResourceMap().GetValue(L"Resources/RandomizerCheatSheet_Digit").ValueAsString()));
|
||||
m_RandomizerShortcuts.Append(winrt::make<PatternSnippet>(L"${ruuidv4}", manager.MainResourceMap().GetValue(L"Resources/RandomizerCheatSheet_Uuid").ValueAsString()));
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
listView_ExplorerItems().ApplyTemplate();
|
||||
@@ -283,6 +289,7 @@ namespace winrt::PowerRenameUI::implementation
|
||||
|
||||
button_rename().IsEnabled(false);
|
||||
toggleButton_enumItems().IsChecked(true);
|
||||
toggleButton_randItems().IsChecked(false);
|
||||
InitAutoComplete();
|
||||
SearchReplaceChanged();
|
||||
InvalidateItemListViewState();
|
||||
@@ -749,6 +756,15 @@ namespace winrt::PowerRenameUI::implementation
|
||||
UpdateFlag(EnumerateItems, UpdateFlagCommand::Reset);
|
||||
});
|
||||
|
||||
// CheckBox RandomizeItems
|
||||
toggleButton_randItems().Checked([&](auto const&, auto const&) {
|
||||
ValidateFlags(RandomizeItems);
|
||||
UpdateFlag(RandomizeItems, UpdateFlagCommand::Set);
|
||||
});
|
||||
toggleButton_randItems().Unchecked([&](auto const&, auto const&) {
|
||||
UpdateFlag(RandomizeItems, UpdateFlagCommand::Reset);
|
||||
});
|
||||
|
||||
// ButtonSettings
|
||||
button_settings().Click([&](auto const&, auto const&) {
|
||||
OpenSettingsApp();
|
||||
@@ -944,6 +960,10 @@ namespace winrt::PowerRenameUI::implementation
|
||||
{
|
||||
toggleButton_enumItems().IsChecked(true);
|
||||
}
|
||||
if (flags & RandomizeItems)
|
||||
{
|
||||
toggleButton_randItems().IsChecked(true);
|
||||
}
|
||||
if (flags & ExcludeFiles)
|
||||
{
|
||||
toggleButton_includeFiles().IsChecked(false);
|
||||
|
||||
@@ -85,6 +85,7 @@ namespace winrt::PowerRenameUI::implementation
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUI::PatternSnippet> SearchRegExShortcuts() { return m_searchRegExShortcuts; }
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUI::PatternSnippet> DateTimeShortcuts() { return m_dateTimeShortcuts; }
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUI::PatternSnippet> CounterShortcuts() { return m_CounterShortcuts; }
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUI::PatternSnippet> RandomizerShortcuts() { return m_RandomizerShortcuts; }
|
||||
|
||||
hstring OriginalCount();
|
||||
void OriginalCount(hstring value);
|
||||
@@ -107,6 +108,7 @@ namespace winrt::PowerRenameUI::implementation
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUI::PatternSnippet> m_searchRegExShortcuts;
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUI::PatternSnippet> m_dateTimeShortcuts;
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUI::PatternSnippet> m_CounterShortcuts;
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUI::PatternSnippet> m_RandomizerShortcuts;
|
||||
|
||||
// Used by PowerRenameManagerEvents
|
||||
HRESULT OnRename(_In_ IPowerRenameItem* renameItem);
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
<value>Replace with</value>
|
||||
</data>
|
||||
<data name="CounterCheatSheet_Title.Text" xml:space="preserve">
|
||||
<value>Replace using advanced counter syntax.</value>
|
||||
<value>Replace using advanced counter syntax</value>
|
||||
</data>
|
||||
<data name="CounterCheatSheet_Simple" xml:space="preserve">
|
||||
<value>A simple counter that you can use anywhere in a replace string.</value>
|
||||
@@ -295,10 +295,10 @@
|
||||
<value>Capitalize each word</value>
|
||||
</data>
|
||||
<data name="ToggleButton_EnumItems.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
|
||||
<value>Enumerate items</value>
|
||||
<value>Enumeration features</value>
|
||||
</data>
|
||||
<data name="ToggleButton_EnumItems.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Enumerate items</value>
|
||||
<value>Enumeration features</value>
|
||||
</data>
|
||||
<data name="SelectAllCheckBox.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Select or deselect all</value>
|
||||
@@ -363,4 +363,25 @@
|
||||
<data name="RenameParts_ExtensionOnly.Content" xml:space="preserve">
|
||||
<value>Extension only</value>
|
||||
</data>
|
||||
</root>
|
||||
<data name="RandomizerCheatSheet_Alnum" xml:space="preserve">
|
||||
<value>Random string with uppercase letters, lowercase letters and 0-9 digits, customized length.</value>
|
||||
</data>
|
||||
<data name="RandomizerCheatSheet_Alpha" xml:space="preserve">
|
||||
<value>Random string with uppercase letters and lowercase letters, customized length.</value>
|
||||
</data>
|
||||
<data name="RandomizerCheatSheet_Digit" xml:space="preserve">
|
||||
<value>Random string with 0-9 digits, customized length.</value>
|
||||
</data>
|
||||
<data name="RandomizerCheatSheet_Title.Text" xml:space="preserve">
|
||||
<value>Replace using random values</value>
|
||||
</data>
|
||||
<data name="RandomizerCheatSheet_Uuid" xml:space="preserve">
|
||||
<value>Random UUID according to v4 specification.</value>
|
||||
</data>
|
||||
<data name="ToggleButton_RandItems.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Random string features</value>
|
||||
</data>
|
||||
<data name="ToggleButton_RandItems.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
|
||||
<value>Random string features</value>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user