Merge branch 'dev/pabhoj/settings_model_reflection' into dev/pabhoj/settings_actions_editor

This commit is contained in:
Pankaj Bhojwani 2025-08-25 15:19:36 -07:00
commit 41ae7130cf
9 changed files with 16 additions and 18 deletions

View File

@ -1229,18 +1229,18 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
UpdateCommandID(foundCmd, foundCmdNewID);
}
}
cmd.ID(newID);
winrt::get_self<implementation::Command>(cmd)->ID(newID);
// update _ActionMap with the ID change
_ActionMap.erase(oldID);
_ActionMap.emplace(newID, cmd);
// update _KeyMap so that all keys that pointed to the old ID now point to the new ID
std::unordered_set<KeyChord, KeyChordHash, KeyChordEquality> keysToRemap{};
std::vector<KeyChord> keysToRemap;
for (const auto& [keys, cmdID] : _KeyMap)
{
if (cmdID == oldID)
{
keysToRemap.insert(keys);
keysToRemap.push_back(keys);
}
}
for (const auto& keys : keysToRemap)
@ -1248,7 +1248,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
_KeyMap.erase(keys);
_KeyMap.emplace(keys, newID);
}
PropagateCommandIDChanged.raise(cmd, oldID);
}
_RefreshKeyBindingCaches();
}

View File

@ -105,8 +105,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
void ResolveMediaResourcesWithBasePath(const winrt::hstring& basePath, const Model::MediaResourceResolver& resolver);
til::typed_event<Model::Command, winrt::hstring> PropagateCommandIDChanged;
private:
Model::Command _GetActionByID(const winrt::hstring& actionID) const;
std::optional<winrt::hstring> _GetActionIdByKeyChordInternal(const Control::KeyChord& keys) const;

View File

@ -34,8 +34,6 @@ namespace Microsoft.Terminal.Settings.Model
IVector<Command> ExpandedCommands { get; };
Windows.Foundation.IAsyncOperation<IVector<Command> > FilterToSnippets(String CurrentCommandline, String CurrentWorkingDirectory);
event Windows.Foundation.TypedEventHandler<Command, String> PropagateCommandIDChanged;
};
runtimeclass ActionMap : IActionMapView
@ -47,6 +45,5 @@ namespace Microsoft.Terminal.Settings.Model
void AddKeyBinding(Microsoft.Terminal.Control.KeyChord keys, String cmdID);
void RegisterKeyBinding(Microsoft.Terminal.Control.KeyChord keys, ActionAndArgs action);
void AddSendInputAction(String name, String input, Microsoft.Terminal.Control.KeyChord keys);
void UpdateCommandID(Command cmd, String newID);
}
}

View File

@ -1258,3 +1258,8 @@ void CascadiaSettings::ExpandCommands()
{
_globals->ExpandCommands(ActiveProfiles().GetView(), GlobalSettings().ColorSchemes());
}
void CascadiaSettings::UpdateCommandID(const Model::Command& cmd, winrt::hstring newID)
{
_globals->UpdateCommandID(cmd, newID);
}

View File

@ -191,6 +191,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
void CurrentDefaultTerminal(const Model::DefaultTerminal& terminal);
void ExpandCommands();
void UpdateCommandID(const Model::Command& cmd, winrt::hstring newID);
void ResolveMediaResources() { _validateMediaResources(); }
void LogSettingChanges(bool isJsonLoad) const;

View File

@ -64,6 +64,7 @@ namespace Microsoft.Terminal.Settings.Model
DefaultTerminal CurrentDefaultTerminal;
void ExpandCommands();
void UpdateCommandID(Command cmd, String newID);
void ResolveMediaResources();
}

View File

@ -41,7 +41,7 @@ namespace Microsoft.Terminal.Settings.Model
String Name;
Boolean HasName();
String LanguageNeutralName { get; };
String ID;
String ID { get; };
void GenerateID();
String Description { get; };

View File

@ -62,8 +62,7 @@ winrt::com_ptr<GlobalAppSettings> GlobalAppSettings::Copy() const
globals->_UnparsedDefaultProfile = _UnparsedDefaultProfile;
globals->_defaultProfile = _defaultProfile;
globals->_actionMap = _actionMap->Copy();
globals->_actionMap->PropagateCommandIDChanged({ globals.get(), &GlobalAppSettings::_CommandIDChangedHandler });
globals->_actionMap = _actionMap->Copy();
globals->_keybindingsWarnings = _keybindingsWarnings;
#define GLOBAL_SETTINGS_COPY(type, name, jsonKey, ...) \
@ -146,7 +145,6 @@ winrt::com_ptr<GlobalAppSettings> GlobalAppSettings::FromJson(const Json::Value&
{
auto result = winrt::make_self<GlobalAppSettings>();
result->LayerJson(json, origin);
result->_actionMap->PropagateCommandIDChanged({ result.get(), &GlobalAppSettings::_CommandIDChangedHandler });
return result;
}
@ -461,12 +459,12 @@ void GlobalAppSettings::_logSettingSet(const std::string_view& setting)
}
}
void GlobalAppSettings::_CommandIDChangedHandler(const Model::Command& senderCmd, const winrt::hstring& oldID)
void GlobalAppSettings::UpdateCommandID(const Model::Command& cmd, const winrt::hstring& newID)
{
const auto oldID = cmd.ID();
_actionMap->UpdateCommandID(cmd, newID);
if (_NewTabMenu)
{
const auto newID = senderCmd.ID();
// Recursive lambda function to look through all the new tab menu entries and update IDs accordingly
std::function<void(const Model::NewTabMenuEntry&)> recursiveEntryIdUpdate;
recursiveEntryIdUpdate = [&](const Model::NewTabMenuEntry& entry) {

View File

@ -47,6 +47,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
Model::ColorScheme DuplicateColorScheme(const Model::ColorScheme& scheme);
Model::ActionMap ActionMap() const noexcept;
void UpdateCommandID(const Model::Command& cmd, const winrt::hstring& newID);
static com_ptr<GlobalAppSettings> FromJson(const Json::Value& json, const OriginTag origin = OriginTag::None);
void LayerJson(const Json::Value& json, const OriginTag origin);
@ -104,8 +105,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
Windows::Foundation::Collections::IMap<winrt::hstring, Model::ColorScheme> _colorSchemes{ winrt::single_threaded_map<winrt::hstring, Model::ColorScheme>() };
Windows::Foundation::Collections::IMap<winrt::hstring, Model::Theme> _themes{ winrt::single_threaded_map<winrt::hstring, Model::Theme>() };
void _CommandIDChangedHandler(const Model::Command& senderCmd, const winrt::hstring& oldID);
void _logSettingSet(const std::string_view& setting);
void _logSettingIfSet(const std::string_view& setting, const bool isSet);
};