diff --git a/src/modules/powerrename/PowerRenameUIHost/PowerRenameUIHost.cpp b/src/modules/powerrename/PowerRenameUIHost/PowerRenameUIHost.cpp index 9f1b94317e..f47cad7555 100644 --- a/src/modules/powerrename/PowerRenameUIHost/PowerRenameUIHost.cpp +++ b/src/modules/powerrename/PowerRenameUIHost/PowerRenameUIHost.cpp @@ -134,6 +134,7 @@ bool AppWindow::OnCreate(HWND, LPCREATESTRUCT) noexcept try { PopulateExplorerItems(); + UpdateCounts(); SetHandlers(); ReadSettings(); } @@ -246,11 +247,6 @@ void AppWindow::PopulateExplorerItems() m_prManager->GetVisibleItemCount(&count); Logger::debug(L"Number of visible items: {}", count); - UINT currDepth = 0; - std::stack parents{}; - UINT prevId = 0; - parents.push(0); - for (UINT i = 0; i < count; ++i) { CComPtr renameItem; @@ -274,23 +270,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); } } } @@ -638,6 +619,7 @@ void AppWindow::SwitchView() m_prManager->SwitchFilter(0); PopulateExplorerItems(); + UpdateCounts(); } void AppWindow::Rename(bool closeWindow) @@ -851,11 +833,12 @@ void AppWindow::UpdateCounts() m_selectedCount = selectedCount; m_renamingCount = renamingCount; - // Update counts UI elements if/when added - // Update Rename button state m_mainUserControl.UIUpdatesItem().ButtonRenameEnabled(renamingCount > 0); } + + m_mainUserControl.UIUpdatesItem().OriginalCount(std::to_wstring(m_mainUserControl.ExplorerItems().Size())); + m_mainUserControl.UIUpdatesItem().RenamedCount(std::to_wstring(m_renamingCount)); } HRESULT AppWindow::OnItemAdded(_In_ IPowerRenameItem* renameItem) @@ -878,7 +861,6 @@ HRESULT AppWindow::OnUpdate(_In_ IPowerRenameItem* renameItem) } } - UpdateCounts(); return S_OK; } @@ -935,6 +917,7 @@ HRESULT AppWindow::OnRegExCompleted(_In_ DWORD threadId) } } + UpdateCounts(); return S_OK; } diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp index 8897dc9039..2e6b1d7e29 100644 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp @@ -2,15 +2,17 @@ #include "ExplorerItem.h" #include "ExplorerItem.g.cpp" +namespace { + const wchar_t fileImagePath[] = L"ms-appx:///Assets/file.png"; + const wchar_t folderImagePath[] = L"ms-appx:///Assets/folder.png"; +} + 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(ExplorerItemType::Folder)) - { - m_children = winrt::single_threaded_observable_vector(); - } + m_imagePath = (m_type == static_cast(ExplorerItemType::Folder)) ? folderImagePath : fileImagePath; } int32_t ExplorerItem::Id() @@ -51,6 +53,15 @@ namespace winrt::PowerRenameUILib::implementation } } + double ExplorerItem::Indentation() { + return static_cast(m_depth) * 12; + } + + hstring ExplorerItem::ImagePath() + { + return m_imagePath; + } + int32_t ExplorerItem::Type() { return m_type; @@ -79,20 +90,6 @@ namespace winrt::PowerRenameUILib::implementation } } - winrt::Windows::Foundation::Collections::IObservableVector ExplorerItem::Children() - { - return m_children; - } - - void ExplorerItem::Children(Windows::Foundation::Collections::IObservableVector const& value) - { - if (m_children != value) - { - m_children = value; - m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Children" }); - } - } - winrt::event_token ExplorerItem::PropertyChanged(winrt::Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler) { return m_propertyChanged.add(handler); diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h index f1d97d80ed..b16f0c6427 100644 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h @@ -11,15 +11,17 @@ namespace winrt::PowerRenameUILib::implementation File = 1 }; - ExplorerItem() = delete; + ExplorerItem() = default; - 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); + double Indentation(); + hstring ImagePath(); int32_t Type(); void Type(int32_t value); bool Checked(); @@ -34,6 +36,8 @@ namespace winrt::PowerRenameUILib::implementation hstring m_idStr; winrt::hstring m_original; winrt::hstring m_renamed; + uint32_t m_depth; + hstring m_imagePath; winrt::Windows::Foundation::Collections::IObservableVector m_children; int32_t m_type; bool m_checked; diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl index c628b2af6c..c83dbf7add 100644 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl @@ -2,13 +2,15 @@ namespace PowerRenameUILib { runtimeclass ExplorerItem : Windows.UI.Xaml.Data.INotifyPropertyChanged { - ExplorerItem(Int32 id, String original, String renamed, Int32 type, Boolean checked); + ExplorerItem(); + ExplorerItem(Int32 id, String original, String renamed, Int32 type, UInt32 depth, Boolean checked); Int32 Id { get; }; String IdStr { get; }; String Original; String Renamed; + Double Indentation { get; }; + String ImagePath { get; }; Int32 Type; Boolean Checked; - Windows.Foundation.Collections.IObservableVector Children; } } diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItemTemplateSelector.cpp b/src/modules/powerrename/PowerRenameUILib/ExplorerItemTemplateSelector.cpp deleted file mode 100644 index 500c7eb3df..0000000000 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItemTemplateSelector.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "pch.h" -#include "ExplorerItemTemplateSelector.h" -#include "ExplorerItemTemplateSelector.g.cpp" - -namespace winrt::PowerRenameUILib::implementation -{ - Windows::UI::Xaml::DataTemplate ExplorerItemTemplateSelector::SelectTemplateCore(IInspectable const& item) - { - ExplorerItem explorerItem = (ExplorerItem&)item; - return explorerItem.Type() == 0 ? m_folderTemplate : m_fileTemplate; - } - - Windows::UI::Xaml::DataTemplate ExplorerItemTemplateSelector::SelectTemplateCore(IInspectable const&, Windows::UI::Xaml::DependencyObject const&) - { - return Windows::UI::Xaml::DataTemplate(); - } - - winrt::Windows::UI::Xaml::DataTemplate ExplorerItemTemplateSelector::FolderTemplate() - { - return m_folderTemplate; - } - - void ExplorerItemTemplateSelector::FolderTemplate(winrt::Windows::UI::Xaml::DataTemplate const& value) - { - m_folderTemplate = value; - } - - winrt::Windows::UI::Xaml::DataTemplate ExplorerItemTemplateSelector::FileTemplate() - { - return m_fileTemplate; - } - - void ExplorerItemTemplateSelector::FileTemplate(winrt::Windows::UI::Xaml::DataTemplate const& value) - { - m_fileTemplate = value; - } -} diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItemTemplateSelector.h b/src/modules/powerrename/PowerRenameUILib/ExplorerItemTemplateSelector.h deleted file mode 100644 index 35c46638a2..0000000000 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItemTemplateSelector.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include "ExplorerItemTemplateSelector.g.h" - -namespace winrt::PowerRenameUILib::implementation -{ - struct ExplorerItemTemplateSelector : ExplorerItemTemplateSelectorT - { - ExplorerItemTemplateSelector() = default; - - Windows::UI::Xaml::DataTemplate SelectTemplateCore(IInspectable const&); - Windows::UI::Xaml::DataTemplate SelectTemplateCore(IInspectable const&, Windows::UI::Xaml::DependencyObject const&); - - winrt::Windows::UI::Xaml::DataTemplate FolderTemplate(); - void FolderTemplate(winrt::Windows::UI::Xaml::DataTemplate const& value); - winrt::Windows::UI::Xaml::DataTemplate FileTemplate(); - void FileTemplate(winrt::Windows::UI::Xaml::DataTemplate const& value); - - private: - Windows::UI::Xaml::DataTemplate m_folderTemplate{ nullptr }; - Windows::UI::Xaml::DataTemplate m_fileTemplate{ nullptr }; - }; -} -namespace winrt::PowerRenameUILib::factory_implementation -{ - struct ExplorerItemTemplateSelector : ExplorerItemTemplateSelectorT - { - }; -} diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItemTemplateSelector.idl b/src/modules/powerrename/PowerRenameUILib/ExplorerItemTemplateSelector.idl deleted file mode 100644 index f31cf94294..0000000000 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItemTemplateSelector.idl +++ /dev/null @@ -1,11 +0,0 @@ -namespace PowerRenameUILib -{ - [bindable] - [default_interface] runtimeclass ExplorerItemTemplateSelector : Windows.UI.Xaml.Controls.DataTemplateSelector - { - ExplorerItemTemplateSelector(); - - Windows.UI.Xaml.DataTemplate FolderTemplate; - Windows.UI.Xaml.DataTemplate FileTemplate; - } -} diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.cpp b/src/modules/powerrename/PowerRenameUILib/MainWindow.cpp index d6c82b9fd2..8ca0d2e6af 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.cpp +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.cpp @@ -163,18 +163,11 @@ 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(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(id, original, renamed, type, depth, checked); + m_explorerItems.Append(newItem); + m_explorerItemsMap[id] = newItem; } void MainWindow::UpdateExplorerItem(int32_t id, hstring const& newName) @@ -208,43 +201,12 @@ namespace winrt::PowerRenameUILib::implementation PowerRenameUILib::ExplorerItem MainWindow::FindById(int32_t id) { - auto fakeRoot = winrt::make(0, L"Fake", L"", 0, false); - fakeRoot.Children(m_explorerItems); - return FindById(fakeRoot, id); + return m_explorerItemsMap.contains(id) ? m_explorerItemsMap[id] : 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(ExplorerItem::ExplorerItemType::Folder)) - { - 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(ExplorerItem::ExplorerItemType::Folder)) - { - for (auto c : node.Children()) - { - ToggleAll(c, checked); - } - } + std::for_each(m_explorerItems.begin(), m_explorerItems.end(), [checked](auto item) { item.Checked(checked); }); } void MainWindow::Checked_ids(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const&) @@ -252,7 +214,7 @@ namespace winrt::PowerRenameUILib::implementation auto checkbox = sender.as(); auto id = std::stoi(std::wstring{ checkbox.Name() }); auto item = FindById(id); - if (checkbox.IsChecked().GetBoolean() != item.Checked()) + if (item != NULL && checkbox.IsChecked().GetBoolean() != item.Checked()) { m_uiUpdatesItem.Checked(checkbox.IsChecked().GetBoolean()); m_uiUpdatesItem.ChangedExplorerItemId(id); @@ -263,9 +225,7 @@ namespace winrt::PowerRenameUILib::implementation { if (checkBox_selectAll().IsChecked().GetBoolean() != m_allSelected) { - auto fakeRoot = winrt::make(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; } @@ -278,6 +238,7 @@ namespace winrt::PowerRenameUILib::implementation if (!m_uiUpdatesItem.ShowAll()) { m_explorerItems.Clear(); + m_explorerItemsMap.clear(); m_uiUpdatesItem.ShowAll(true); } } @@ -289,6 +250,7 @@ namespace winrt::PowerRenameUILib::implementation if (m_uiUpdatesItem.ShowAll()) { m_explorerItems.Clear(); + m_explorerItemsMap.clear(); m_uiUpdatesItem.ShowAll(false); } } diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.h b/src/modules/powerrename/PowerRenameUILib/MainWindow.h index b017ca3ac6..15e3bd05f2 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.h +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.h @@ -7,7 +7,7 @@ #include "MainWindow.g.h" #include "PatternSnippet.h" #include "ExplorerItem.h" -#include "ExplorerItemTemplateSelector.h" +#include namespace winrt::PowerRenameUILib::implementation { @@ -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); @@ -61,13 +61,13 @@ namespace winrt::PowerRenameUILib::implementation private: 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); + inline PowerRenameUILib::ExplorerItem FindById(int32_t id); + void ToggleAll(bool checked); winrt::Windows::Foundation::Collections::IObservableVector m_searchMRU; winrt::Windows::Foundation::Collections::IObservableVector m_replaceMRU; winrt::Windows::Foundation::Collections::IObservableVector m_explorerItems; + std::map m_explorerItemsMap; winrt::Windows::Foundation::Collections::IObservableVector m_searchRegExShortcuts; winrt::Windows::Foundation::Collections::IObservableVector m_dateTimeShortcuts; diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.idl b/src/modules/powerrename/PowerRenameUILib/MainWindow.idl index 344ccf8ebc..00c65a531e 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.idl +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.idl @@ -14,6 +14,8 @@ namespace PowerRenameUILib void CloseUIWindow(Boolean closeUIWindow); Boolean ButtonRenameEnabled; void Rename(); + String OriginalCount; + String RenamedCount; } [default_interface] runtimeclass MainWindow : Windows.UI.Xaml.Controls.UserControl @@ -50,7 +52,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); diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml b/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml index 88336778b8..ae272846a8 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml @@ -1,78 +1,6 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -82,27 +10,45 @@ - + - + - - - - + - - + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + @@ -239,20 +218,20 @@ Extension only - - - + + + - + - - - - + + + + @@ -260,29 +239,38 @@ - + - + + - + + +