2022-08-24 16:47:27 +08:00
|
|
|
|
#include "pch.h"
|
2021-10-25 21:40:19 +08:00
|
|
|
|
#include "ExplorerItem.h"
|
2022-08-24 16:47:27 +08:00
|
|
|
|
#if __has_include("ExplorerItem.g.cpp")
|
2021-10-25 21:40:19 +08:00
|
|
|
|
#include "ExplorerItem.g.cpp"
|
2022-08-24 16:47:27 +08:00
|
|
|
|
#endif
|
2021-10-25 21:40:19 +08:00
|
|
|
|
|
2022-08-24 16:47:27 +08:00
|
|
|
|
using namespace winrt;
|
|
|
|
|
using namespace Microsoft::UI::Xaml;
|
|
|
|
|
using namespace Microsoft::Windows::ApplicationModel::Resources;
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
2021-11-17 17:57:22 +08:00
|
|
|
|
const wchar_t fileImagePath[] = L"ms-appx:///Assets/file.png";
|
|
|
|
|
const wchar_t folderImagePath[] = L"ms-appx:///Assets/folder.png";
|
2022-08-24 16:47:27 +08:00
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-17 17:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 22:38:12 +08:00
|
|
|
|
namespace winrt::PowerRenameUI::implementation
|
2021-10-25 21:40:19 +08:00
|
|
|
|
{
|
2023-07-14 00:42:08 +08:00
|
|
|
|
DependencyProperty ExplorerItem::_CheckedProperty{ nullptr };
|
|
|
|
|
|
|
|
|
|
void ExplorerItem::_InitializeProperties()
|
|
|
|
|
{
|
|
|
|
|
if (!_CheckedProperty)
|
|
|
|
|
{
|
|
|
|
|
_CheckedProperty =
|
|
|
|
|
DependencyProperty::Register(
|
|
|
|
|
L"Checked",
|
|
|
|
|
xaml_typename<bool>(),
|
|
|
|
|
xaml_typename<PowerRenameUI::ExplorerItem>(),
|
|
|
|
|
PropertyMetadata{ box_value(true) });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExplorerItem::ExplorerItem()
|
|
|
|
|
{
|
|
|
|
|
_InitializeProperties();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 17:57:22 +08:00
|
|
|
|
ExplorerItem::ExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, uint32_t depth, bool checked) :
|
2023-07-14 00:42:08 +08:00
|
|
|
|
m_id{ id }, m_idStr{ std::to_wstring(id) }, m_original{ original }, m_renamed{ renamed }, m_type{ type }, m_depth{ depth }
|
2021-10-25 21:40:19 +08:00
|
|
|
|
{
|
2023-07-14 00:42:08 +08:00
|
|
|
|
_InitializeProperties();
|
|
|
|
|
|
2021-11-17 17:57:22 +08:00
|
|
|
|
m_imagePath = (m_type == static_cast<UINT>(ExplorerItemType::Folder)) ? folderImagePath : fileImagePath;
|
2023-07-14 00:42:08 +08:00
|
|
|
|
Checked(checked);
|
2021-10-25 21:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t ExplorerItem::Id()
|
|
|
|
|
{
|
|
|
|
|
return m_id;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 00:42:08 +08:00
|
|
|
|
void ExplorerItem::Id(const int32_t value)
|
|
|
|
|
{
|
|
|
|
|
if (m_id != value)
|
|
|
|
|
{
|
|
|
|
|
m_id = value;
|
|
|
|
|
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Id" });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-25 21:40:19 +08:00
|
|
|
|
hstring ExplorerItem::IdStr()
|
|
|
|
|
{
|
|
|
|
|
return m_idStr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 00:42:08 +08:00
|
|
|
|
void ExplorerItem::IdStr(hstring const& value)
|
|
|
|
|
{
|
|
|
|
|
if (m_idStr != value)
|
|
|
|
|
{
|
|
|
|
|
m_idStr = value;
|
|
|
|
|
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"IdStr" });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-25 21:40:19 +08:00
|
|
|
|
hstring ExplorerItem::Original()
|
|
|
|
|
{
|
|
|
|
|
return m_original;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExplorerItem::Original(hstring const& value)
|
|
|
|
|
{
|
|
|
|
|
if (m_original != value)
|
|
|
|
|
{
|
|
|
|
|
m_original = value;
|
2022-05-11 22:38:12 +08:00
|
|
|
|
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Original" });
|
2021-10-25 21:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hstring ExplorerItem::Renamed()
|
|
|
|
|
{
|
|
|
|
|
return m_renamed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExplorerItem::Renamed(hstring const& value)
|
|
|
|
|
{
|
|
|
|
|
if (m_renamed != value)
|
|
|
|
|
{
|
|
|
|
|
m_renamed = value;
|
2022-05-11 22:38:12 +08:00
|
|
|
|
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Renamed" });
|
2021-10-25 21:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 16:47:27 +08:00
|
|
|
|
double ExplorerItem::Indentation()
|
|
|
|
|
{
|
2021-11-17 17:57:22 +08:00
|
|
|
|
return static_cast<double>(m_depth) * 12;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 00:42:08 +08:00
|
|
|
|
void ExplorerItem::Indentation(double value)
|
2021-11-17 17:57:22 +08:00
|
|
|
|
{
|
2023-07-14 00:42:08 +08:00
|
|
|
|
if (m_depth != value)
|
|
|
|
|
{
|
|
|
|
|
m_depth = static_cast<uint32_t>(value / 12);
|
|
|
|
|
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Indentation" });
|
|
|
|
|
}
|
2021-11-17 17:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 00:42:08 +08:00
|
|
|
|
hstring ExplorerItem::ImagePath()
|
2021-10-25 21:40:19 +08:00
|
|
|
|
{
|
2023-07-14 00:42:08 +08:00
|
|
|
|
return m_imagePath;
|
2021-10-25 21:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 00:42:08 +08:00
|
|
|
|
void ExplorerItem::ImagePath(hstring const& value)
|
2021-10-25 21:40:19 +08:00
|
|
|
|
{
|
2023-07-14 00:42:08 +08:00
|
|
|
|
if (m_imagePath != value)
|
2021-10-25 21:40:19 +08:00
|
|
|
|
{
|
2023-07-14 00:42:08 +08:00
|
|
|
|
m_imagePath = value;
|
|
|
|
|
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"ImagePath" });
|
2021-10-25 21:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 00:42:08 +08:00
|
|
|
|
int32_t ExplorerItem::Type()
|
2021-10-25 21:40:19 +08:00
|
|
|
|
{
|
2023-07-14 00:42:08 +08:00
|
|
|
|
return m_type;
|
2021-10-25 21:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 00:42:08 +08:00
|
|
|
|
void ExplorerItem::Type(int32_t value)
|
2021-10-25 21:40:19 +08:00
|
|
|
|
{
|
2023-07-14 00:42:08 +08:00
|
|
|
|
if (m_type != value)
|
2021-10-25 21:40:19 +08:00
|
|
|
|
{
|
2023-07-14 00:42:08 +08:00
|
|
|
|
m_type = value;
|
|
|
|
|
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Type" });
|
2021-10-25 21:40:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 16:47:27 +08:00
|
|
|
|
int32_t ExplorerItem::State()
|
2021-12-02 20:02:12 +08:00
|
|
|
|
{
|
2022-08-24 16:47:27 +08:00
|
|
|
|
return static_cast<int32_t>(m_state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExplorerItem::State(int32_t value)
|
|
|
|
|
{
|
|
|
|
|
m_state = static_cast<PowerRenameItemRenameStatus>(value);
|
|
|
|
|
ErrorMessageTxt().Text(StateToErrorMessage());
|
|
|
|
|
|
|
|
|
|
if (m_renamed == L"")
|
|
|
|
|
{
|
|
|
|
|
VisualStateManager::GoToState(*this, L"Normal", false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VisualStateManager::GoToState(*this, PowerRenameItemRenameStatusToString(m_state), false);
|
|
|
|
|
}
|
2021-12-02 20:02:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 22:38:12 +08:00
|
|
|
|
winrt::event_token ExplorerItem::PropertyChanged(winrt::Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler)
|
2021-10-25 21:40:19 +08:00
|
|
|
|
{
|
|
|
|
|
return m_propertyChanged.add(handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExplorerItem::PropertyChanged(winrt::event_token const& token) noexcept
|
|
|
|
|
{
|
|
|
|
|
m_propertyChanged.remove(token);
|
|
|
|
|
}
|
2022-08-24 16:47:27 +08:00
|
|
|
|
|
|
|
|
|
std::wstring ExplorerItem::StateToErrorMessage()
|
|
|
|
|
{
|
2023-03-31 16:43:27 +08:00
|
|
|
|
static auto factory = winrt::get_activation_factory<ResourceManager, IResourceManagerFactory>();
|
|
|
|
|
static ResourceManager manager = factory.CreateInstance(L"resources.pri");
|
2023-07-14 00:42:08 +08:00
|
|
|
|
static auto invalid_char_error = manager.MainResourceMap().GetValue(L"Resources/ErrorMessage_InvalidChar").ValueAsString();
|
2023-03-31 16:43:27 +08:00
|
|
|
|
static auto name_too_long_error = manager.MainResourceMap().GetValue(L"Resources/ErrorMessage_FileNameTooLong").ValueAsString();
|
2022-08-24 16:47:27 +08:00
|
|
|
|
|
|
|
|
|
switch (m_state)
|
|
|
|
|
{
|
|
|
|
|
case PowerRenameItemRenameStatus::ItemNameInvalidChar:
|
|
|
|
|
{
|
2023-03-31 16:43:27 +08:00
|
|
|
|
return std::wstring{ invalid_char_error };
|
2022-08-24 16:47:27 +08:00
|
|
|
|
}
|
|
|
|
|
case PowerRenameItemRenameStatus::ItemNameTooLong:
|
|
|
|
|
{
|
2023-03-31 16:43:27 +08:00
|
|
|
|
return std::wstring{ name_too_long_error };
|
2022-08-24 16:47:27 +08:00
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-25 21:40:19 +08:00
|
|
|
|
}
|