callback instead

This commit is contained in:
Pankaj Bhojwani 2025-08-21 16:13:55 -07:00
parent ea360191b5
commit 890671ab34
4 changed files with 15 additions and 8 deletions

View File

@ -661,7 +661,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
const auto copiedCmd = winrt::get_self<Command>(cmd)->Copy();
actionMap->_ActionMap.emplace(actionID, *copiedCmd);
copiedCmd->IDChanged({ actionMap.get(), &ActionMap::_CommandIDChangedHandler });
}
// Name --> Command
@ -781,7 +780,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
}
}
cmd.IDChanged({ this, &ActionMap::_CommandIDChangedHandler });
cmdImpl->SetIDChangedCallback([this](const Model::Command senderCmd, const std::wstring_view oldID) {
_CommandIDChangedHandler(senderCmd, winrt::hstring{ oldID });
});
_ActionMap.insert_or_assign(cmdID, cmd);
}
}

View File

@ -105,6 +105,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
command->_name = _name;
command->_Origin = _Origin;
command->_ID = _ID;
command->_pfnIDChanged = _pfnIDChanged;
command->_ActionAndArgs = *get_self<implementation::ActionAndArgs>(_ActionAndArgs)->Copy();
command->_icon = _icon;
command->_IterateOn = _IterateOn;
@ -216,7 +217,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
const auto oldID = _ID;
_ID = ID;
IDChanged.raise(*this, oldID);
if (_pfnIDChanged)
{
_pfnIDChanged(*this, std::wstring_view{ oldID });
}
}
void Command::GenerateID()
@ -237,6 +241,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return _IDWasGenerated;
}
void Command::SetIDChangedCallback(std::function<void(const Model::Command, const std::wstring_view)> pfn) noexcept
{
_pfnIDChanged.swap(pfn);
}
void Command::Name(const hstring& value)
{
if (!_name.has_value() || _name->name != value)

View File

@ -85,6 +85,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
void ID(const hstring& ID) noexcept;
void GenerateID();
bool IDWasGenerated();
void SetIDChangedCallback(std::function<void(const Model::Command, const std::wstring_view)> pfn) noexcept;
IMediaResource Icon() const noexcept;
void Icon(const IMediaResource& val);
@ -102,15 +103,13 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
WINRT_PROPERTY(OriginTag, Origin);
WINRT_PROPERTY(winrt::hstring, Description, L"");
public:
til::typed_event<Model::Command, winrt::hstring> IDChanged;
private:
Json::Value _originalJson;
Windows::Foundation::Collections::IMap<winrt::hstring, Model::Command> _subcommands{ nullptr };
std::optional<CommandNameOrResource> _name;
std::wstring _ID;
bool _IDWasGenerated{ false };
std::function<void(const Model::Command, const std::wstring_view)> _pfnIDChanged;
std::optional<IMediaResource> _icon;
bool _nestedCommand{ false };

View File

@ -55,7 +55,5 @@ namespace Microsoft.Terminal.Settings.Model
static IVector<Command> ParsePowerShellMenuComplete(String json, Int32 replaceLength);
static IVector<Command> HistoryToCommands(IVector<String> commandHistory, String commandline, Boolean directories, String iconPath);
event Windows.Foundation.TypedEventHandler<Command, String> IDChanged;
}
}