This was the only thing blocking me from signing off on #9224 in 1.7. ! CHANGE WARNING ! If we bind to `T.S.M.Command`s in XAML, then the compiler gets _very angry_ at us. It generates two different versions of `GetReferenceTypeMember_Icon` in `XamlTypeInfo.g.cpp`. Presumably because there's an Icon on a NavViewItem and an Icon on a Command. We don't really know why. Fortunately, the fix is "rename Command::Icon" to "Command::IconPath". It's dumb, but it works. Thanks for the help with that one Carlos ☺️ Unblocks #9224
51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#include "pch.h"
|
|
#include "ActionPaletteItem.h"
|
|
#include <LibraryResources.h>
|
|
|
|
#include "ActionPaletteItem.g.cpp"
|
|
|
|
using namespace winrt;
|
|
using namespace winrt::TerminalApp;
|
|
using namespace winrt::Windows::UI::Core;
|
|
using namespace winrt::Windows::UI::Xaml;
|
|
using namespace winrt::Windows::System;
|
|
using namespace winrt::Windows::Foundation;
|
|
using namespace winrt::Windows::Foundation::Collections;
|
|
using namespace winrt::Microsoft::Terminal::Settings::Model;
|
|
|
|
namespace winrt::TerminalApp::implementation
|
|
{
|
|
ActionPaletteItem::ActionPaletteItem(Microsoft::Terminal::Settings::Model::Command const& command) :
|
|
_Command(command)
|
|
{
|
|
Name(command.Name());
|
|
KeyChordText(command.KeyChordText());
|
|
Icon(command.IconPath());
|
|
|
|
_commandChangedRevoker = command.PropertyChanged(winrt::auto_revoke, [weakThis{ get_weak() }](auto& sender, auto& e) {
|
|
auto item{ weakThis.get() };
|
|
auto senderCommand{ sender.try_as<Microsoft::Terminal::Settings::Model::Command>() };
|
|
|
|
if (item && senderCommand)
|
|
{
|
|
auto changedProperty = e.PropertyName();
|
|
if (changedProperty == L"Name")
|
|
{
|
|
item->Name(senderCommand.Name());
|
|
}
|
|
else if (changedProperty == L"KeyChordText")
|
|
{
|
|
item->KeyChordText(senderCommand.KeyChordText());
|
|
}
|
|
else if (changedProperty == L"IconPath")
|
|
{
|
|
item->Icon(senderCommand.IconPath());
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|