diff --git a/src/modules/powerrename/PowerRenameUIHost/PowerRenameUIHost.cpp b/src/modules/powerrename/PowerRenameUIHost/PowerRenameUIHost.cpp index 9f1b94317e..bbc4c7fb73 100644 --- a/src/modules/powerrename/PowerRenameUIHost/PowerRenameUIHost.cpp +++ b/src/modules/powerrename/PowerRenameUIHost/PowerRenameUIHost.cpp @@ -64,7 +64,7 @@ AppWindow::AppWindow(HINSTANCE hInstance, std::vector files) noexc CComPtr 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""); + 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 parents{}; - UINT prevId = 0; - parents.push(0); - for (UINT i = 0; i < count; ++i) { CComPtr 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); } } } diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp index 8897dc9039..9018ff7088 100644 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp @@ -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(ExplorerItemType::Folder)) { @@ -51,6 +51,10 @@ namespace winrt::PowerRenameUILib::implementation } } + uint32_t ExplorerItem::Depth() { + return m_depth; + } + int32_t ExplorerItem::Type() { return m_type; diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h index f1d97d80ed..fbb0832837 100644 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h @@ -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 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..b215ad398a 100644 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl @@ -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 Children; diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.cpp b/src/modules/powerrename/PowerRenameUILib/MainWindow.cpp index d6c82b9fd2..16acf38981 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.cpp +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.cpp @@ -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(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); } 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(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(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(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(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; } diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.h b/src/modules/powerrename/PowerRenameUILib/MainWindow.h index b017ca3ac6..720c7175d3 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.h +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.h @@ -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 m_searchMRU; winrt::Windows::Foundation::Collections::IObservableVector m_replaceMRU; diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.idl b/src/modules/powerrename/PowerRenameUILib/MainWindow.idl index 344ccf8ebc..c7e3a73641 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.idl +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.idl @@ -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); diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml b/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml index 88336778b8..6660f8279b 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml @@ -3,53 +3,41 @@ - + - - - + - - - - + + + + + + - - - + - - - - - - - - - - - - - - + + + + + + - + @@ -112,34 +100,32 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + +