[PowerRename] Cleanup and fix for renaming to empty string (#19691)
* Add UI items using OnItemAdded callback * Simplify ToggleAll() logic * Simplify items' Checkbox logic * Do not allow renaming to empty string * Simplify ShowAll/ShowRenamed logic * Simplify rename button logic
This commit is contained in:
Родитель
6ef439bda4
Коммит
1fe9d95322
|
@ -121,9 +121,7 @@
|
|||
Height="28"
|
||||
Grid.Column="1"
|
||||
XYFocusKeyboardNavigation="Enabled"
|
||||
Checked="Checked_ids"
|
||||
IsTabStop="True"
|
||||
Unchecked="Checked_ids"
|
||||
Content=""
|
||||
Name="{x:Bind IdStr}"
|
||||
AutomationProperties.Name="{x:Bind Original}"
|
||||
|
@ -355,7 +353,7 @@
|
|||
|
||||
|
||||
|
||||
<muxc:SplitButton Grid.Row="2" Style="{StaticResource SplitAccentButtonStyle}" Grid.Column="0" Margin="0,0,12,1" x:Name="button_rename" x:Uid="ButtonApply" Click="button_rename_Click" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsEnabled="{x:Bind UIUpdatesItem.ButtonRenameEnabled, Mode=OneWay}">
|
||||
<muxc:SplitButton Grid.Row="2" Style="{StaticResource SplitAccentButtonStyle}" Grid.Column="0" Margin="0,0,12,1" x:Name="button_rename" x:Uid="ButtonApply" Click="button_rename_Click" HorizontalAlignment="Right" VerticalAlignment="Bottom">
|
||||
<muxc:SplitButton.KeyboardAccelerators>
|
||||
<KeyboardAccelerator Key="Enter" />
|
||||
<KeyboardAccelerator Key="Enter" Modifiers="Control" />
|
||||
|
|
|
@ -185,7 +185,6 @@ namespace winrt::PowerRenameUI::implementation
|
|||
}
|
||||
try
|
||||
{
|
||||
PopulateExplorerItems();
|
||||
UpdateCounts();
|
||||
SetHandlers();
|
||||
ReadSettings();
|
||||
|
@ -195,7 +194,7 @@ namespace winrt::PowerRenameUI::implementation
|
|||
Logger::error("Exception thrown during explorer items population: {}", std::string{ e.what() });
|
||||
}
|
||||
|
||||
m_uiUpdatesItem.ButtonRenameEnabled(false);
|
||||
button_rename().IsEnabled(false);
|
||||
InitAutoComplete();
|
||||
SearchReplaceChanged();
|
||||
}
|
||||
|
@ -203,6 +202,15 @@ namespace winrt::PowerRenameUI::implementation
|
|||
void MainWindow::AddExplorerItem(int32_t id, hstring const& original, hstring const& renamed, int32_t type, uint32_t depth, bool checked)
|
||||
{
|
||||
auto newItem = winrt::make<PowerRenameUI::implementation::ExplorerItem>(id, original, renamed, type, depth, checked);
|
||||
newItem.PropertyChanged([this](Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs const& e) {
|
||||
auto item = sender.as<ExplorerItem>();
|
||||
std::wstring property{ e.PropertyName() };
|
||||
|
||||
if (item && property == L"Checked")
|
||||
{
|
||||
ToggleItem(item->Id(), item->Checked());
|
||||
}
|
||||
});
|
||||
m_explorerItems.Append(newItem);
|
||||
m_explorerItemsMap[id] = newItem;
|
||||
}
|
||||
|
@ -241,29 +249,11 @@ namespace winrt::PowerRenameUI::implementation
|
|||
return m_explorerItemsMap.contains(id) ? m_explorerItemsMap[id] : NULL;
|
||||
}
|
||||
|
||||
void MainWindow::ToggleAll(bool 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::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
||||
{
|
||||
auto checkbox = sender.as<Microsoft::UI::Xaml::Controls::CheckBox>();
|
||||
auto id = std::stoi(std::wstring{ checkbox.Name() });
|
||||
auto item = FindById(id);
|
||||
if (item != NULL && checkbox.IsChecked().GetBoolean() != item.Checked())
|
||||
{
|
||||
m_uiUpdatesItem.Checked(checkbox.IsChecked().GetBoolean());
|
||||
m_uiUpdatesItem.ChangedExplorerItemId(id);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::SelectAll(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
||||
{
|
||||
if (checkBox_selectAll().IsChecked().GetBoolean() != m_allSelected)
|
||||
{
|
||||
ToggleAll(checkBox_selectAll().IsChecked().GetBoolean());
|
||||
m_uiUpdatesItem.ToggleAll();
|
||||
ToggleAll();
|
||||
m_allSelected = !m_allSelected;
|
||||
}
|
||||
}
|
||||
|
@ -272,11 +262,16 @@ namespace winrt::PowerRenameUI::implementation
|
|||
{
|
||||
button_showAll().IsChecked(true);
|
||||
button_showRenamed().IsChecked(false);
|
||||
if (!m_uiUpdatesItem.ShowAll())
|
||||
|
||||
DWORD filter = 0;
|
||||
m_prManager->GetFilter(&filter);
|
||||
if (filter != PowerRenameFilters::None)
|
||||
{
|
||||
m_explorerItems.Clear();
|
||||
m_explorerItemsMap.clear();
|
||||
m_uiUpdatesItem.ShowAll(true);
|
||||
m_prManager->SwitchFilter(0);
|
||||
PopulateExplorerItems();
|
||||
UpdateCounts();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,11 +279,16 @@ namespace winrt::PowerRenameUI::implementation
|
|||
{
|
||||
button_showRenamed().IsChecked(true);
|
||||
button_showAll().IsChecked(false);
|
||||
if (m_uiUpdatesItem.ShowAll())
|
||||
|
||||
DWORD filter = 0;
|
||||
m_prManager->GetFilter(&filter);
|
||||
if (filter != PowerRenameFilters::ShouldRename)
|
||||
{
|
||||
m_explorerItems.Clear();
|
||||
m_explorerItemsMap.clear();
|
||||
m_uiUpdatesItem.ShowAll(false);
|
||||
m_prManager->SwitchFilter(0);
|
||||
PopulateExplorerItems();
|
||||
UpdateCounts();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,14 +308,12 @@ namespace winrt::PowerRenameUI::implementation
|
|||
|
||||
void MainWindow::button_rename_Click(winrt::Microsoft::UI::Xaml::Controls::SplitButton const&, winrt::Microsoft::UI::Xaml::Controls::SplitButtonClickEventArgs const&)
|
||||
{
|
||||
m_uiUpdatesItem.CloseUIWindow(false);
|
||||
m_uiUpdatesItem.Rename();
|
||||
Rename(false);
|
||||
}
|
||||
|
||||
void MainWindow::MenuFlyoutItem_Click(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
||||
{
|
||||
m_uiUpdatesItem.CloseUIWindow(true);
|
||||
m_uiUpdatesItem.Rename();
|
||||
Rename(true);
|
||||
}
|
||||
|
||||
void MainWindow::OpenDocs(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
||||
|
@ -556,26 +554,6 @@ namespace winrt::PowerRenameUI::implementation
|
|||
{
|
||||
_TRACER_;
|
||||
|
||||
m_uiUpdatesItem.PropertyChanged([&](auto const&, auto const& e) {
|
||||
std::wstring property{ e.PropertyName() };
|
||||
if (property == L"ShowAll")
|
||||
{
|
||||
SwitchView();
|
||||
}
|
||||
else if (property == L"ChangedItemId")
|
||||
{
|
||||
ToggleItem(m_uiUpdatesItem.ChangedExplorerItemId(), m_uiUpdatesItem.Checked());
|
||||
}
|
||||
else if (property == L"ToggleAll")
|
||||
{
|
||||
ToggleAll();
|
||||
}
|
||||
else if (property == L"Rename")
|
||||
{
|
||||
Rename(m_uiUpdatesItem.CloseUIWindow());
|
||||
}
|
||||
});
|
||||
|
||||
// AutoSuggestBox Search
|
||||
textBox_search().TextChanged([&](auto const&, auto const&) {
|
||||
SearchReplaceChanged();
|
||||
|
@ -739,6 +717,10 @@ namespace winrt::PowerRenameUI::implementation
|
|||
if (SUCCEEDED(m_prManager->GetItemByIndex(i, &spItem)))
|
||||
{
|
||||
spItem->PutSelected(selected);
|
||||
int id = 0;
|
||||
spItem->GetId(&id);
|
||||
auto item = FindById(id);
|
||||
item.Checked(selected);
|
||||
}
|
||||
}
|
||||
UpdateCounts();
|
||||
|
@ -965,15 +947,35 @@ namespace winrt::PowerRenameUI::implementation
|
|||
m_renamingCount = renamingCount;
|
||||
|
||||
// Update Rename button state
|
||||
m_uiUpdatesItem.ButtonRenameEnabled(renamingCount > 0);
|
||||
button_rename().IsEnabled(renamingCount > 0);
|
||||
}
|
||||
|
||||
m_uiUpdatesItem.OriginalCount(std::to_wstring(m_explorerItems.Size()));
|
||||
m_uiUpdatesItem.RenamedCount(std::to_wstring(m_renamingCount));
|
||||
}
|
||||
|
||||
HRESULT MainWindow::OnItemAdded(_In_ IPowerRenameItem*)
|
||||
HRESULT MainWindow::OnItemAdded(_In_ IPowerRenameItem* renameItem)
|
||||
{
|
||||
int id = 0;
|
||||
renameItem->GetId(&id);
|
||||
|
||||
PWSTR originalName = nullptr;
|
||||
renameItem->GetOriginalName(&originalName);
|
||||
PWSTR newName = nullptr;
|
||||
renameItem->GetNewName(&newName);
|
||||
|
||||
bool selected;
|
||||
renameItem->GetSelected(&selected);
|
||||
|
||||
UINT depth = 0;
|
||||
renameItem->GetDepth(&depth);
|
||||
|
||||
bool isFolder = false;
|
||||
winrt::check_hresult(renameItem->GetIsFolder(&isFolder));
|
||||
|
||||
AddExplorerItem(
|
||||
id, originalName, newName == nullptr ? hstring{} : hstring{ newName }, isFolder ? 0 : 1, depth, selected);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,6 @@ namespace winrt::PowerRenameUI::implementation
|
|||
void AppendSearchMRU(hstring const& value);
|
||||
void AppendReplaceMRU(hstring const& value);
|
||||
|
||||
void Checked_ids(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
|
||||
void SelectAll(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
|
||||
void ShowAll(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
|
||||
void ShowRenamed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
|
||||
|
@ -97,7 +96,6 @@ namespace winrt::PowerRenameUI::implementation
|
|||
bool m_allSelected;
|
||||
PowerRenameUI::UIUpdates m_uiUpdatesItem;
|
||||
inline PowerRenameUI::ExplorerItem FindById(int32_t id);
|
||||
void ToggleAll(bool checked);
|
||||
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<hstring> m_searchMRUList;
|
||||
winrt::Windows::Foundation::Collections::IObservableVector<hstring> m_replaceMRUList;
|
||||
|
|
|
@ -4,46 +4,10 @@
|
|||
|
||||
namespace winrt::PowerRenameUI::implementation
|
||||
{
|
||||
UIUpdates::UIUpdates() :
|
||||
m_showAll{ true }, m_changedItemId{ -1 }, m_checked{ true }, m_closeUIWindow{ false }, m_buttonRenameEnabled{ false }
|
||||
UIUpdates::UIUpdates()
|
||||
{
|
||||
}
|
||||
|
||||
bool UIUpdates::ShowAll()
|
||||
{
|
||||
return m_showAll;
|
||||
}
|
||||
|
||||
void UIUpdates::ShowAll(bool value)
|
||||
{
|
||||
if (m_showAll != value)
|
||||
{
|
||||
m_showAll = value;
|
||||
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"ShowAll" });
|
||||
}
|
||||
}
|
||||
|
||||
int32_t UIUpdates::ChangedExplorerItemId()
|
||||
{
|
||||
return m_changedItemId;
|
||||
}
|
||||
|
||||
void UIUpdates::ChangedExplorerItemId(int32_t value)
|
||||
{
|
||||
m_changedItemId = value;
|
||||
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"ChangedItemId" });
|
||||
}
|
||||
|
||||
bool UIUpdates::Checked()
|
||||
{
|
||||
return m_checked;
|
||||
}
|
||||
|
||||
void UIUpdates::Checked(bool value)
|
||||
{
|
||||
m_checked = value;
|
||||
}
|
||||
|
||||
winrt::event_token UIUpdates::PropertyChanged(Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler)
|
||||
{
|
||||
return m_propertyChanged.add(handler);
|
||||
|
@ -54,16 +18,6 @@ namespace winrt::PowerRenameUI::implementation
|
|||
m_propertyChanged.remove(token);
|
||||
}
|
||||
|
||||
void UIUpdates::ToggleAll()
|
||||
{
|
||||
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"ToggleAll" });
|
||||
}
|
||||
|
||||
void UIUpdates::Rename()
|
||||
{
|
||||
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"Rename" });
|
||||
}
|
||||
|
||||
hstring UIUpdates::OriginalCount()
|
||||
{
|
||||
return m_originalCount;
|
||||
|
@ -91,28 +45,4 @@ namespace winrt::PowerRenameUI::implementation
|
|||
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"RenamedCount" });
|
||||
}
|
||||
}
|
||||
|
||||
bool UIUpdates::CloseUIWindow()
|
||||
{
|
||||
return m_closeUIWindow;
|
||||
}
|
||||
|
||||
void UIUpdates::CloseUIWindow(bool closeUIWindow)
|
||||
{
|
||||
m_closeUIWindow = closeUIWindow;
|
||||
}
|
||||
|
||||
bool UIUpdates::ButtonRenameEnabled()
|
||||
{
|
||||
return m_buttonRenameEnabled;
|
||||
}
|
||||
|
||||
void UIUpdates::ButtonRenameEnabled(bool value)
|
||||
{
|
||||
if (m_buttonRenameEnabled != value)
|
||||
{
|
||||
m_buttonRenameEnabled = value;
|
||||
m_propertyChanged(*this, Microsoft::UI::Xaml::Data::PropertyChangedEventArgs{ L"ButtonRenameEnabled" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,31 +7,14 @@ namespace winrt::PowerRenameUI::implementation
|
|||
{
|
||||
UIUpdates();
|
||||
|
||||
bool ShowAll();
|
||||
void ShowAll(bool value);
|
||||
int32_t ChangedExplorerItemId();
|
||||
void ChangedExplorerItemId(int32_t value);
|
||||
bool Checked();
|
||||
void Checked(bool value);
|
||||
winrt::event_token PropertyChanged(winrt::Microsoft::UI::Xaml::Data::PropertyChangedEventHandler const& handler);
|
||||
void PropertyChanged(winrt::event_token const& token) noexcept;
|
||||
void ToggleAll();
|
||||
bool CloseUIWindow();
|
||||
void CloseUIWindow(bool closeUIWindow);
|
||||
bool ButtonRenameEnabled();
|
||||
void ButtonRenameEnabled(bool value);
|
||||
void Rename();
|
||||
hstring OriginalCount();
|
||||
void OriginalCount(hstring value);
|
||||
hstring RenamedCount();
|
||||
void RenamedCount(hstring value);
|
||||
|
||||
private:
|
||||
bool m_showAll;
|
||||
int32_t m_changedItemId;
|
||||
bool m_checked;
|
||||
bool m_closeUIWindow;
|
||||
bool m_buttonRenameEnabled;
|
||||
hstring m_originalCount;
|
||||
hstring m_renamedCount;
|
||||
winrt::event<Microsoft::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged;
|
||||
|
|
|
@ -3,14 +3,6 @@ namespace PowerRenameUI
|
|||
runtimeclass UIUpdates : Microsoft.UI.Xaml.Data.INotifyPropertyChanged
|
||||
{
|
||||
UIUpdates();
|
||||
Boolean ShowAll;
|
||||
Int32 ChangedExplorerItemId;
|
||||
Boolean Checked;
|
||||
void ToggleAll();
|
||||
Boolean CloseUIWindow();
|
||||
void CloseUIWindow(Boolean closeUIWindow);
|
||||
Boolean ButtonRenameEnabled;
|
||||
void Rename();
|
||||
String OriginalCount;
|
||||
String RenamedCount;
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ IFACEMETHODIMP CPowerRenameItem::ShouldRenameItem(_In_ DWORD flags, _Out_ bool*
|
|||
{
|
||||
// Should we perform a rename on this item given its
|
||||
// state and the options that were set?
|
||||
bool hasChanged = m_newName != nullptr && (lstrcmp(m_originalName, m_newName) != 0);
|
||||
bool hasChanged = m_newName != nullptr && (lstrcmp(m_originalName, m_newName) != 0) && (lstrcmp(L"", m_newName) != 0);
|
||||
bool excludeBecauseFolder = (m_isFolder && (flags & PowerRenameFlags::ExcludeFolders));
|
||||
bool excludeBecauseFile = (!m_isFolder && (flags & PowerRenameFlags::ExcludeFiles));
|
||||
bool excludeBecauseSubFolderContent = (m_depth > 0 && (flags & PowerRenameFlags::ExcludeSubfolders));
|
||||
|
|
Загрузка…
Ссылка в новой задаче