This commit is contained in:
Stefan Markovic
2021-11-08 14:54:47 +01:00
parent 06882b4fbd
commit 3a1108e944
8 changed files with 68 additions and 133 deletions

View File

@@ -64,7 +64,7 @@ AppWindow::AppWindow(HINSTANCE hInstance, std::vector<std::wstring> files) noexc
CComPtr<IShellItemArray> shellItemArray;
// To test PowerRenameUIHost uncomment this line and update the path to
// your local (absolute or relative) path which you want to see in PowerRename
//files.push_back(L"<path>");
files.push_back(L"C:\\Users\\stefa\\Projects\\Xaml-Controls-Gallery");
if (!files.empty())
{
@@ -246,11 +246,6 @@ void AppWindow::PopulateExplorerItems()
m_prManager->GetVisibleItemCount(&count);
Logger::debug(L"Number of visible items: {}", count);
UINT currDepth = 0;
std::stack<UINT> parents{};
UINT prevId = 0;
parents.push(0);
for (UINT i = 0; i < count; ++i)
{
CComPtr<IPowerRenameItem> renameItem;
@@ -274,23 +269,8 @@ void AppWindow::PopulateExplorerItems()
bool isSubFolderContent = false;
winrt::check_hresult(renameItem->GetIsFolder(&isFolder));
if (depth > currDepth)
{
parents.push(prevId);
currDepth = depth;
}
else
{
while (currDepth > depth)
{
parents.pop();
currDepth--;
}
currDepth = depth;
}
m_mainUserControl.AddExplorerItem(
id, originalName, newName == nullptr ? hstring{} : hstring{ newName }, isFolder ? 0 : 1, parents.top(), selected);
prevId = id;
id, originalName, newName == nullptr ? hstring{} : hstring{ newName }, isFolder ? 0 : 1, depth, selected);
}
}
}

View File

@@ -4,8 +4,8 @@
namespace winrt::PowerRenameUILib::implementation
{
ExplorerItem::ExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, bool checked) :
m_id{ id }, m_idStr{ std::to_wstring(id) }, m_original{ original }, m_renamed{ renamed }, m_type{ type }, m_checked{ checked }
ExplorerItem::ExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, uint32_t depth, bool checked) :
m_id{ id }, m_idStr{ std::to_wstring(id) }, m_original{ original }, m_renamed{ renamed }, m_type{ type }, m_depth{ depth }, m_checked{ checked }
{
if (m_type == static_cast<UINT>(ExplorerItemType::Folder))
{
@@ -51,6 +51,10 @@ namespace winrt::PowerRenameUILib::implementation
}
}
uint32_t ExplorerItem::Depth() {
return m_depth;
}
int32_t ExplorerItem::Type()
{
return m_type;

View File

@@ -13,13 +13,14 @@ namespace winrt::PowerRenameUILib::implementation
ExplorerItem() = delete;
ExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, bool checked);
ExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, uint32_t depth, bool checked);
int32_t Id();
hstring IdStr();
hstring Original();
void Original(hstring const& value);
hstring Renamed();
void Renamed(hstring const& value);
uint32_t Depth();
int32_t Type();
void Type(int32_t value);
bool Checked();
@@ -34,6 +35,7 @@ namespace winrt::PowerRenameUILib::implementation
hstring m_idStr;
winrt::hstring m_original;
winrt::hstring m_renamed;
uint32_t m_depth;
winrt::Windows::Foundation::Collections::IObservableVector<PowerRenameUILib::ExplorerItem> m_children;
int32_t m_type;
bool m_checked;

View File

@@ -2,11 +2,12 @@ namespace PowerRenameUILib
{
runtimeclass ExplorerItem : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
ExplorerItem(Int32 id, String original, String renamed, Int32 type, Boolean checked);
ExplorerItem(Int32 id, String original, String renamed, Int32 type, UInt32 depth, Boolean checked);
Int32 Id { get; };
String IdStr { get; };
String Original;
String Renamed;
UInt32 Depth { get; };
Int32 Type;
Boolean Checked;
Windows.Foundation.Collections.IObservableVector<ExplorerItem> Children;

View File

@@ -163,18 +163,10 @@ namespace winrt::PowerRenameUILib::implementation
return m_uiUpdatesItem;
}
void MainWindow::AddExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, int32_t parentId, bool checked)
void MainWindow::AddExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, uint32_t depth, bool checked)
{
auto newItem = winrt::make<PowerRenameUILib::implementation::ExplorerItem>(id, original, renamed, type, checked);
if (parentId == 0)
{
m_explorerItems.Append(newItem);
}
else
{
auto parent = FindById(parentId);
parent.Children().Append(newItem);
}
auto newItem = winrt::make<PowerRenameUILib::implementation::ExplorerItem>(id, original, renamed, type, depth, checked);
m_explorerItems.Append(newItem);
}
void MainWindow::UpdateExplorerItem(int32_t id, hstring const& newName)
@@ -208,42 +200,15 @@ namespace winrt::PowerRenameUILib::implementation
PowerRenameUILib::ExplorerItem MainWindow::FindById(int32_t id)
{
auto fakeRoot = winrt::make<PowerRenameUILib::implementation::ExplorerItem>(0, L"Fake", L"", 0, false);
fakeRoot.Children(m_explorerItems);
return FindById(fakeRoot, id);
auto it = std::find_if(m_explorerItems.begin(), m_explorerItems.end(), [id](const auto& item) { return item.Id() == id; });
return it != m_explorerItems.end() ? *it : NULL;
}
PowerRenameUILib::ExplorerItem MainWindow::FindById(PowerRenameUILib::ExplorerItem& root, int32_t id)
void MainWindow::ToggleAll(bool checked)
{
if (root.Id() == id)
return root;
if (root.Type() == static_cast<UINT>(ExplorerItem::ExplorerItemType::Folder))
for (auto item : m_explorerItems)
{
for (auto c : root.Children())
{
auto result = FindById(c, id);
if (result != NULL)
return result;
}
}
return NULL;
}
void MainWindow::ToggleAll(PowerRenameUILib::ExplorerItem node, bool checked)
{
if (node == NULL)
return;
node.Checked(checked);
if (node.Type() == static_cast<UINT>(ExplorerItem::ExplorerItemType::Folder))
{
for (auto c : node.Children())
{
ToggleAll(c, checked);
}
item.Checked(checked);
}
}
@@ -263,9 +228,7 @@ namespace winrt::PowerRenameUILib::implementation
{
if (checkBox_selectAll().IsChecked().GetBoolean() != m_allSelected)
{
auto fakeRoot = winrt::make<PowerRenameUILib::implementation::ExplorerItem>(0, L"Fake", L"", 0, false);
fakeRoot.Children(m_explorerItems);
ToggleAll(fakeRoot, checkBox_selectAll().IsChecked().GetBoolean());
ToggleAll(checkBox_selectAll().IsChecked().GetBoolean());
m_uiUpdatesItem.ToggleAll();
m_allSelected = !m_allSelected;
}

View File

@@ -47,7 +47,7 @@ namespace winrt::PowerRenameUILib::implementation
PowerRenameUILib::UIUpdates UIUpdatesItem();
void AddExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, int32_t parentId, bool checked);
void AddExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, uint32_t depth, bool checked);
void UpdateExplorerItem(int32_t id, hstring const& newName);
void UpdateRenamedExplorerItem(int32_t id, hstring const& newOriginalName);
void AppendSearchMRU(hstring const& value);
@@ -62,8 +62,7 @@ namespace winrt::PowerRenameUILib::implementation
bool m_allSelected;
PowerRenameUILib::UIUpdates m_uiUpdatesItem;
PowerRenameUILib::ExplorerItem FindById(int32_t id);
PowerRenameUILib::ExplorerItem FindById(PowerRenameUILib::ExplorerItem& root, int32_t id);
void ToggleAll(PowerRenameUILib::ExplorerItem node, bool checked);
void ToggleAll(bool checked);
winrt::Windows::Foundation::Collections::IObservableVector<hstring> m_searchMRU;
winrt::Windows::Foundation::Collections::IObservableVector<hstring> m_replaceMRU;

View File

@@ -50,7 +50,7 @@ namespace PowerRenameUILib
Windows.UI.Xaml.Controls.Primitives.ToggleButton ToggleButtonTitleCase { get; };
Windows.UI.Xaml.Controls.Primitives.ToggleButton ToggleButtonCapitalize { get; };
void AddExplorerItem(Int32 id, String original, String renamed, Int32 type, Int32 parentId, Boolean checked);
void AddExplorerItem(Int32 id, String original, String renamed, Int32 type, UInt32 depth, Boolean checked);
void UpdateExplorerItem(Int32 id, String newName);
void UpdateRenamedExplorerItem(Int32 id, String newOriginalName);
void AppendSearchMRU(String value);

View File

@@ -3,53 +3,41 @@
<UserControl.Resources>
<local:ExplorerItemTemplateSelector x:Key="ExplorerItemTemplateSelector" FolderTemplate="{StaticResource FolderTemplate}" FileTemplate="{StaticResource FileTemplate}" />
<local:ExplorerItemTemplateSelector x:Key="RenamedExplorerItemTemplateSelector" FolderTemplate="{StaticResource RenamedFolderTemplate}" FileTemplate="{StaticResource RenamedFileTemplate}" />
<!--<local:ExplorerItemTemplateSelector x:Key="RenamedExplorerItemTemplateSelector" FolderTemplate="{StaticResource RenamedFolderTemplate}" FileTemplate="{StaticResource RenamedFileTemplate}" />-->
<DataTemplate x:Key="FileTemplate" x:DataType="local:ExplorerItem">
<Grid Height="24" Margin="0,4,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="36" />
<ColumnDefinition Width="36" />
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<CheckBox TabIndex="0" Grid.Column="0" XYFocusKeyboardNavigation="Enabled" Checked="Checked_ids" IsTabStop="True" Unchecked="Checked_ids" Content="" Name="{x:Bind IdStr}" AutomationProperties.Name="{x:Bind Original}" AutomationProperties.HelpText="{x:Bind Renamed}" IsChecked="{x:Bind Checked, Mode=TwoWay}" />
<Image Width="16" Source="ms-appx:///Assets/file.png" HorizontalAlignment="Left" Grid.Column="1" />
<TextBlock Text="{x:Bind Original, Mode=OneWay}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" VerticalAlignment="Center" FontSize="12" Grid.Column="2" />
<StackPanel Orientation="Horizontal" Grid.Column="0">
<CheckBox TabIndex="0" XYFocusKeyboardNavigation="Enabled" Checked="Checked_ids" IsTabStop="True" Unchecked="Checked_ids" Content="" Name="{x:Bind IdStr}" AutomationProperties.Name="{x:Bind Original}" AutomationProperties.HelpText="{x:Bind Renamed}" IsChecked="{x:Bind Checked, Mode=TwoWay}" />
<Image Width="16" Source="ms-appx:///Assets/file.png" HorizontalAlignment="Left" />
<TextBlock Text="{x:Bind Original, Mode=OneWay}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" VerticalAlignment="Center" FontSize="12" />
</StackPanel>
<TextBlock Text="{x:Bind Renamed, Mode=OneWay}" Grid.Column="1" FontWeight="Bold" VerticalAlignment="Center" FontSize="14" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="FolderTemplate" x:DataType="local:ExplorerItem">
<Grid Margin="0,4,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="36" />
<ColumnDefinition Width="36" />
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="24" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<CheckBox TabIndex="0" IsTabStop="True" XYFocusKeyboardNavigation="Enabled" Grid.Row="0" Grid.Column="0" Checked="Checked_ids" Unchecked="Checked_ids" Content="" Name="{x:Bind IdStr}" AutomationProperties.Name="{x:Bind Original}" AutomationProperties.HelpText="{x:Bind Renamed}" IsChecked="{x:Bind Checked, Mode=TwoWay}" />
<Image Width="16" Source="ms-appx:///Assets/folder.png" HorizontalAlignment="Left" Grid.Column="1" />
<TextBlock Text="{x:Bind Original, Mode=OneWay}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" VerticalAlignment="Center" FontSize="12" Grid.Column="2" />
<ListView Grid.ColumnSpan="3" IsTabStop="false" XYFocusKeyboardNavigation="Enabled" SelectionMode="None" IsItemClickEnabled="False" ItemsSource="{x:Bind Children}" Grid.Row="1" ItemTemplateSelector="{StaticResource ExplorerItemTemplateSelector}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsTabStop" Value="False" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
<StackPanel Orientation="Horizontal" Grid.Column="0">
<CheckBox TabIndex="0" IsTabStop="True" XYFocusKeyboardNavigation="Enabled" Grid.Row="0" Grid.Column="0" Checked="Checked_ids" Unchecked="Checked_ids" Content="" Name="{x:Bind IdStr}" AutomationProperties.Name="{x:Bind Original}" AutomationProperties.HelpText="{x:Bind Renamed}" IsChecked="{x:Bind Checked, Mode=TwoWay}" />
<Image Width="16" Source="ms-appx:///Assets/folder.png" HorizontalAlignment="Left" Grid.Column="1" />
<TextBlock Text="{x:Bind Original, Mode=OneWay}" Foreground="{ThemeResource TextFillColorSecondaryBrush}" VerticalAlignment="Center" FontSize="12" Grid.Column="2" />
</StackPanel>
<TextBlock Text="{x:Bind Renamed, Mode=OneWay}" Grid.Column="1" FontWeight="Bold" VerticalAlignment="Center" FontSize="14" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="RenamedFileTemplate" x:DataType="local:ExplorerItem">
<!--<DataTemplate x:Key="RenamedFileTemplate" x:DataType="local:ExplorerItem">
<Grid Height="24" Margin="0,4,0,0">
<TextBlock Text="{x:Bind Renamed, Mode=OneWay}" FontWeight="SemiBold" VerticalAlignment="Center" FontSize="14" />
</Grid>
@@ -69,7 +57,7 @@
</ListView.ItemContainerStyle>
</ListView>
</Grid>
</DataTemplate>
</DataTemplate>-->
</UserControl.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="20">
@@ -112,34 +100,32 @@
</Button>
<Rectangle Height="1" Grid.ColumnSpan="5" Fill="{ThemeResource CardStrokeColorDefaultBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />
<ScrollViewer Grid.ColumnSpan="6" HorizontalScrollMode="Enabled" Grid.Row="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="286" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ListView IsTabStop="false" SelectionMode="None" XYFocusKeyboardNavigation="Enabled" IsItemClickEnabled="False" ItemsSource="{x:Bind ExplorerItems, Mode=OneWay}" Margin="4,0,0,0" ItemTemplateSelector="{StaticResource ExplorerItemTemplateSelector}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsTabStop" Value="False" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
<!--<controls:ItemsRepeater ItemsSource="{x:Bind ExplorerItems, Mode=OneWay}"
Margin="16,0,0,0"
ItemTemplate="{StaticResource ExplorerItemTemplateSelector}" />-->
<ListView Grid.Column="1" IsTabStop="false" SelectionMode="None" IsItemClickEnabled="False" ItemsSource="{x:Bind ExplorerItems, Mode=OneWay}" ItemTemplateSelector="{StaticResource RenamedExplorerItemTemplateSelector}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsTabStop" Value="False" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
<!--<controls:ItemsRepeater ItemsSource="{x:Bind ExplorerItems, Mode=OneWay}"
Grid.Column="1"
ItemTemplate="{StaticResource RenamedExplorerItemTemplateSelector}" />-->
</Grid>
</ScrollViewer>
<Grid Grid.ColumnSpan="6" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="286" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ListView IsTabStop="false" SelectionMode="None" XYFocusKeyboardNavigation="Enabled" IsItemClickEnabled="False" ItemsSource="{x:Bind ExplorerItems, Mode=OneWay}" Margin="4,0,0,0" ItemTemplateSelector="{StaticResource ExplorerItemTemplateSelector}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsTabStop" Value="False" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
<!--<controls:ItemsRepeater ItemsSource="{x:Bind ExplorerItems, Mode=OneWay}"
Margin="16,0,0,0"
ItemTemplate="{StaticResource ExplorerItemTemplateSelector}" />-->
<!--<ListView Grid.Column="1" IsTabStop="false" SelectionMode="None" IsItemClickEnabled="False" ItemsSource="{x:Bind ExplorerItems, Mode=OneWay}" ItemTemplateSelector="{StaticResource RenamedExplorerItemTemplateSelector}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsTabStop" Value="False" />
</Style>
</ListView.ItemContainerStyle>
</ListView>-->
<!--<controls:ItemsRepeater ItemsSource="{x:Bind ExplorerItems, Mode=OneWay}"
Grid.Column="1"
ItemTemplate="{StaticResource RenamedExplorerItemTemplateSelector}" />-->
</Grid>
</Grid>
<Grid Grid.Column="0" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}">