diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp index 7dff982e75..f76b8018bf 100644 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.cpp @@ -1,10 +1,42 @@ -#include "pch.h" +#include "pch.h" #include "ExplorerItem.h" +#if __has_include("ExplorerItem.g.cpp") #include "ExplorerItem.g.cpp" +#endif -namespace { +using namespace winrt; +using namespace Microsoft::UI::Xaml; +using namespace Microsoft::Windows::ApplicationModel::Resources; + +namespace +{ const wchar_t fileImagePath[] = L"ms-appx:///Assets/file.png"; const wchar_t folderImagePath[] = L"ms-appx:///Assets/folder.png"; + + std::wstring PowerRenameItemRenameStatusToString(PowerRenameItemRenameStatus status) + { + switch (status) + { + case PowerRenameItemRenameStatus::Init: + { + return L"Normal"; + } + case PowerRenameItemRenameStatus::ShouldRename: + { + return L"Highlight"; + } + case PowerRenameItemRenameStatus::ItemNameInvalidChar: + { + return L"Error"; + } + case PowerRenameItemRenameStatus::ItemNameTooLong: + { + return L"Error"; + } + default: + return L"Normal"; + } + } } namespace winrt::PowerRenameUI::implementation @@ -13,7 +45,6 @@ namespace winrt::PowerRenameUI::implementation m_id{ id }, m_idStr{ std::to_wstring(id) }, m_original{ original }, m_renamed{ renamed }, m_type{ type }, m_depth{ depth }, m_checked{ checked } { m_imagePath = (m_type == static_cast(ExplorerItemType::Folder)) ? folderImagePath : fileImagePath; - m_highlight = m_checked && !m_renamed.empty() ? Microsoft::UI::Xaml::Visibility::Visible : Microsoft::UI::Xaml::Visibility::Collapsed; } int32_t ExplorerItem::Id() @@ -51,17 +82,11 @@ namespace winrt::PowerRenameUI::implementation { m_renamed = value; m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Renamed" }); - - auto visibility = m_checked && !m_renamed.empty() ? Microsoft::UI::Xaml::Visibility::Visible : Microsoft::UI::Xaml::Visibility::Collapsed; - if (m_highlight != visibility) - { - m_highlight = visibility; - m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Highlight" }); - } } } - double ExplorerItem::Indentation() { + double ExplorerItem::Indentation() + { return static_cast(m_depth) * 12; } @@ -96,18 +121,35 @@ namespace winrt::PowerRenameUI::implementation m_checked = value; m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Checked" }); - auto visibility = m_checked && !m_renamed.empty() ? Microsoft::UI::Xaml::Visibility::Visible : Microsoft::UI::Xaml::Visibility::Collapsed; - if (m_highlight != visibility) + if (m_checked && !m_renamed.empty()) { - m_highlight = visibility; - m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Highlight" }); + VisualStateManager::GoToState(*this, PowerRenameItemRenameStatusToString(m_state), false); + } + else + { + VisualStateManager::GoToState(*this, L"Normal", false); } } } - Microsoft::UI::Xaml::Visibility ExplorerItem::Highlight() + int32_t ExplorerItem::State() { - return m_highlight; + return static_cast(m_state); + } + + void ExplorerItem::State(int32_t value) + { + m_state = static_cast(value); + ErrorMessageTxt().Text(StateToErrorMessage()); + + if (m_renamed == L"") + { + VisualStateManager::GoToState(*this, L"Normal", false); + } + else + { + VisualStateManager::GoToState(*this, PowerRenameItemRenameStatusToString(m_state), false); + } } winrt::event_token ExplorerItem::PropertyChanged(winrt::Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler) @@ -119,4 +161,26 @@ namespace winrt::PowerRenameUI::implementation { m_propertyChanged.remove(token); } + + std::wstring ExplorerItem::StateToErrorMessage() + { + auto factory = winrt::get_activation_factory(); + ResourceManager manager = factory.CreateInstance(L"resources.pri"); + + switch (m_state) + { + case PowerRenameItemRenameStatus::ItemNameInvalidChar: + { + return std::wstring{ manager.MainResourceMap().GetValue(L"Resources/ErrorMessage_InvalidChar").ValueAsString() }; + } + case PowerRenameItemRenameStatus::ItemNameTooLong: + { + return std::wstring{ manager.MainResourceMap().GetValue(L"Resources/ErrorMessage_FileNameTooLong").ValueAsString() }; + } + default: + return {}; + } + + } + } diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h index fdd3fbe931..d955c161b8 100644 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.h @@ -1,5 +1,11 @@ -#pragma once +#pragma once + +#include "winrt/Microsoft.UI.Xaml.h" +#include "winrt/Microsoft.UI.Xaml.Markup.h" +#include "winrt/Microsoft.UI.Xaml.Interop.h" +#include "winrt/Microsoft.UI.Xaml.Controls.Primitives.h" #include "ExplorerItem.g.h" +#include "PowerRenameInterfaces.h" namespace winrt::PowerRenameUI::implementation { @@ -10,7 +16,7 @@ namespace winrt::PowerRenameUI::implementation Folder = 0, File = 1 }; - + ExplorerItem() = default; ExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, uint32_t depth, bool checked); @@ -26,12 +32,14 @@ namespace winrt::PowerRenameUI::implementation void Type(int32_t value); bool Checked(); void Checked(bool value); - Microsoft::UI::Xaml::Visibility Highlight(); - Windows::Foundation::Collections::IObservableVector Children(); - winrt::event_token PropertyChanged(Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler); + int32_t State(); + void State(int32_t value); + winrt::event_token PropertyChanged(winrt::Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler); void PropertyChanged(winrt::event_token const& token) noexcept; - + private: + std::wstring StateToErrorMessage(); + int32_t m_id; hstring m_idStr; winrt::hstring m_original; @@ -40,10 +48,12 @@ namespace winrt::PowerRenameUI::implementation hstring m_imagePath; int32_t m_type; bool m_checked; - Microsoft::UI::Xaml::Visibility m_highlight; + PowerRenameItemRenameStatus m_state; winrt::event m_propertyChanged; + }; } + namespace winrt::PowerRenameUI::factory_implementation { struct ExplorerItem : ExplorerItemT diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl index 88c4d47c34..b302f4636b 100644 --- a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.idl @@ -1,6 +1,6 @@ namespace PowerRenameUI { - runtimeclass ExplorerItem : Microsoft.UI.Xaml.Data.INotifyPropertyChanged + [default_interface] runtimeclass ExplorerItem : Microsoft.UI.Xaml.Controls.UserControl, Microsoft.UI.Xaml.Data.INotifyPropertyChanged { ExplorerItem(); ExplorerItem(Int32 id, String original, String renamed, Int32 type, UInt32 depth, Boolean checked); @@ -12,6 +12,6 @@ namespace PowerRenameUI String ImagePath { get; }; Int32 Type; Boolean Checked; - Microsoft.UI.Xaml.Visibility Highlight { get; }; + Int32 State; } } diff --git a/src/modules/powerrename/PowerRenameUILib/ExplorerItem.xaml b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.xaml new file mode 100644 index 0000000000..e52a080939 --- /dev/null +++ b/src/modules/powerrename/PowerRenameUILib/ExplorerItem.xaml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.idl b/src/modules/powerrename/PowerRenameUILib/MainWindow.idl index 7d76457086..049fbcb9a4 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.idl +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.idl @@ -16,9 +16,5 @@ namespace PowerRenameUI String OriginalCount; String RenamedCount; - - 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); } } diff --git a/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml b/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml index 1406f4582a..ded88055ec 100644 --- a/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml +++ b/src/modules/powerrename/PowerRenameUILib/MainWindow.xaml @@ -2,18 +2,18 @@ x:Class="PowerRenameUI.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="using:PowerRenameUI" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:controls="using:Microsoft.UI.Xaml.Controls" - xmlns:muxc="using:Microsoft.UI.Xaml.Controls" xmlns:animatedVisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals" + xmlns:controls="using:Microsoft.UI.Xaml.Controls" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="using:PowerRenameUI" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:muxc="using:Microsoft.UI.Xaml.Controls" mc:Ignorable="d"> - + - + @@ -21,14 +21,15 @@ - + @@ -40,10 +41,26 @@ - - + + - + @@ -52,132 +69,128 @@ - + - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - + + - + - - + - - + + Filename + extension Filename only Extension only - - - + + + - + - - - - + + + + - + - + - + - -