Skip to content

Commit

Permalink
works??
Browse files Browse the repository at this point in the history
  • Loading branch information
PankajBhojwani committed Apr 24, 2024
1 parent c134402 commit 22ab936
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
4 changes: 3 additions & 1 deletion src/cascadia/TerminalApp/TabBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ namespace winrt::TerminalApp::implementation
// - <none>
void TabBase::_UpdateSwitchToTabKeyChord()
{
const auto keyChord = _actionMap ? _actionMap.GetKeyBindingForAction(ShortcutAction::SwitchToTab, SwitchToTabArgs{ _TabViewIndex }) : nullptr;
const auto id = fmt::format(FMT_COMPILE(L"Terminal.SwitchToTab{}"), _TabViewIndex);
const auto keyChord{ _actionMap.GetKeyBindingForAction2(id) };
//const auto keyChord = _actionMap ? _actionMap.GetKeyBindingForAction(ShortcutAction::SwitchToTab, SwitchToTabArgs{ _TabViewIndex }) : nullptr;
const auto keyChordText = keyChord ? KeyChordSerialization::ToString(keyChord) : L"";

if (_keyChord == keyChordText)
Expand Down
10 changes: 7 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,8 @@ namespace winrt::TerminalApp::implementation
newTabFlyout.Items().Append(settingsItem);

auto actionMap = _settings.ActionMap();
const auto settingsKeyChord{ actionMap.GetKeyBindingForAction(ShortcutAction::OpenSettings, OpenSettingsArgs{ SettingsTarget::SettingsUI }) };
//const auto settingsKeyChord{ actionMap.GetKeyBindingForAction(ShortcutAction::OpenSettings, OpenSettingsArgs{ SettingsTarget::SettingsUI }) };
const auto settingsKeyChord{ actionMap.GetKeyBindingForAction2(L"Terminal.OpenSettingsUI") };
if (settingsKeyChord)
{
_SetAcceleratorForMenuItem(settingsItem, settingsKeyChord);
Expand All @@ -847,7 +848,8 @@ namespace winrt::TerminalApp::implementation
commandPaletteFlyout.Click({ this, &TerminalPage::_CommandPaletteButtonOnClick });
newTabFlyout.Items().Append(commandPaletteFlyout);

const auto commandPaletteKeyChord{ actionMap.GetKeyBindingForAction(ShortcutAction::ToggleCommandPalette) };
//const auto commandPaletteKeyChord{ actionMap.GetKeyBindingForAction(ShortcutAction::ToggleCommandPalette) };
const auto commandPaletteKeyChord{ actionMap.GetKeyBindingForAction2(L"Terminal.ToggleCommandPalette") };
if (commandPaletteKeyChord)
{
_SetAcceleratorForMenuItem(commandPaletteFlyout, commandPaletteKeyChord);
Expand Down Expand Up @@ -1022,7 +1024,9 @@ namespace winrt::TerminalApp::implementation
// NewTab(ProfileIndex=N) action
NewTerminalArgs newTerminalArgs{ profileIndex };
NewTabArgs newTabArgs{ newTerminalArgs };
auto profileKeyChord{ _settings.ActionMap().GetKeyBindingForAction(ShortcutAction::NewTab, newTabArgs) };
//auto profileKeyChord{ _settings.ActionMap().GetKeyBindingForAction(ShortcutAction::NewTab, newTabArgs) };
const auto id = fmt::format(FMT_COMPILE(L"Terminal.OpenNewTabProfile{}"), profileIndex);
const auto profileKeyChord{ _settings.ActionMap().GetKeyBindingForAction2(id) };

// make sure we find one to display
if (profileKeyChord)
Expand Down
41 changes: 27 additions & 14 deletions src/cascadia/TerminalSettingsModel/ActionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// ActionMap should never point to nullptr
FAIL_FAST_IF_NULL(cmd);

// todo: stage 1 - not sure if we need this? _ActionMap2 doesn't contain invalid commands I'm p sure
// todo: stage 3 - not sure if we need this? _ActionMap2 doesn't contain invalid commands I'm p sure
return !cmd.HasNestedCommands() && cmd.ActionAndArgs().Action() == ShortcutAction::Invalid ?
nullptr : // explicitly unbound
cmd;
Expand Down Expand Up @@ -235,7 +235,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// an invalid state for the `ActionMap`
IMapView<hstring, Model::Command> ActionMap::NameMap()
{
// todo: stage 1 (done, edit return)
// todo: stage 1 (done)
if (!_NameMapCache)
{
// populate _NameMapCache
Expand All @@ -254,7 +254,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

_NameMapCache2 = single_threaded_map(std::move(nameMap2));
}
return _NameMapCache.GetView();
return _NameMapCache2.GetView();
}

// Method Description:
Expand Down Expand Up @@ -450,7 +450,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

IMapView<Control::KeyChord, Model::Command> ActionMap::GlobalHotkeys()
{
// todo: stage 1 (done, edit return)
// todo: stage 1 (done)
if (!_GlobalHotkeysCache)
{
_RefreshKeyBindingCaches();
Expand All @@ -459,12 +459,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
_RefreshKeyBindingCaches2();
}
return _GlobalHotkeysCache.GetView();
return _GlobalHotkeysCache2.GetView();
}

IMapView<Control::KeyChord, Model::Command> ActionMap::KeyBindings()
{
// todo: stage 1 (done, edit return)
// todo: stage 1 (done)
if (!_KeyBindingMapCache)
{
_RefreshKeyBindingCaches();
Expand All @@ -473,7 +473,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
_RefreshKeyBindingCaches2();
}
return _KeyBindingMapCache.GetView();
return _KeyBindingMapCache2.GetView();
}

void ActionMap::_RefreshKeyBindingCaches()
Expand Down Expand Up @@ -622,6 +622,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

// KeyChord --> ID
actionMap->_KeyMap = _KeyMap;
actionMap->_KeyMap2 = _KeyMap2;

// ID --> Command
actionMap->_ActionMap.reserve(_ActionMap.size());
Expand Down Expand Up @@ -1016,9 +1017,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// We use the fact that the ..Internal call returns nullptr for explicitly unbound
// key chords, and nullopt for keychord that are not bound - it allows us to distinguish
// between unbound and lack of binding.
// todo: stage 1 (done, edit return)
//return _GetActionByKeyChordInternal2(keys) == nullptr;
return _GetActionByKeyChordInternal(keys) == nullptr;
// todo: stage 1 (done)
return _GetActionByKeyChordInternal2(keys) == nullptr;
//return _GetActionByKeyChordInternal(keys) == nullptr;
}

// Method Description:
Expand All @@ -1030,9 +1031,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// - nullptr if the key chord doesn't exist
Model::Command ActionMap::GetActionByKeyChord(const Control::KeyChord& keys) const
{
// todo: stage 1 (done, edit return)
//return _GetActionByKeyChordInternal2(keys).value_or(nullptr);
return _GetActionByKeyChordInternal(keys).value_or(nullptr);
// todo: stage 1 (done)
return _GetActionByKeyChordInternal2(keys).value_or(nullptr);
//return _GetActionByKeyChordInternal(keys).value_or(nullptr);
}

// Method Description:
Expand Down Expand Up @@ -1092,6 +1093,18 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return nullptr;
}
}

// the command was not bound in this layer,
// ask my parents
for (const auto& parent : _parents)
{
const auto& inheritedCmd{ parent->_GetActionByKeyChordInternal2(keys) };
if (inheritedCmd)
{
return *inheritedCmd;
}
}

// we did not find the keychord in our map, its not bound and not explicity unbound either
return std::nullopt;
}
Expand Down Expand Up @@ -1190,7 +1203,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
}
_fixUpsAppliedDuringLoad = true;
// todo: stage 1 - probably don't need this as a return value anymore?
// todo: stage 3 - probably don't need this as a return value anymore?
return fixedUp;
}

Expand Down
32 changes: 16 additions & 16 deletions src/cascadia/TerminalSettingsModel/ActionMapSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

Json::Value ActionMap::ToJson() const
{
// todo: stage 1 (done, need to uncomment)
// todo: stage 1 (done)
Json::Value actionList{ Json::ValueType::arrayValue };

// Command serializes to an array of JSON objects.
Expand All @@ -102,26 +102,26 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
};

//auto toJson2 = [&actionList](const Model::Command& cmd) {
// const auto cmdImpl{ winrt::get_self<implementation::Command>(cmd) };
// const auto& cmdJsonArray{ cmdImpl->ToJson2() };
// for (const auto& cmdJson : cmdJsonArray)
// {
// actionList.append(cmdJson);
// }
//};
auto toJson2 = [&actionList](const Model::Command& cmd) {
const auto cmdImpl{ winrt::get_self<implementation::Command>(cmd) };
const auto& cmdJsonArray{ cmdImpl->ToJson2() };
for (const auto& cmdJson : cmdJsonArray)
{
actionList.append(cmdJson);
}
};

// Serialize all standard Command objects in the current layer
for (const auto& [_, cmd] : _ActionMap)
{
toJson(cmd);
}

//for (const auto& [_, cmd] : _ActionMap2)
//for (const auto& [_, cmd] : _ActionMap)
//{
// toJson2(cmd);
// toJson(cmd);
//}

for (const auto& [_, cmd] : _ActionMap2)
{
toJson2(cmd);
}

// Serialize all nested Command objects added in the current layer
for (const auto& [_, cmd] : _NestedCommands)
{
Expand Down

0 comments on commit 22ab936

Please sign in to comment.