Skip to content

Commit

Permalink
add comment & combine lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Jul 2, 2021
1 parent 9b896ce commit 3499a72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/cascadia/TerminalSettingsEditor/Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

void Actions::_ViewModelModifyKeyBindingHandler(const Editor::KeyBindingViewModel& senderVM, const Editor::ModifyKeyBindingEventArgs& args)
{
// If the key chord was changed,
// update the settings model and view model appropriately
auto attemptRebindKeys = [=]() {
auto applyChangesToSettingsModel = [=]() {
// If the key chord was changed,
// update the settings model and view model appropriately
if (args.OldKeys().Modifiers() != args.NewKeys().Modifiers() || args.OldKeys().Vkey() != args.NewKeys().Vkey())
{
// update settings model
Expand All @@ -266,11 +266,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
auto senderVMImpl{ get_self<KeyBindingViewModel>(senderVM) };
senderVMImpl->Keys(args.NewKeys());
}
};

// If the action was changed,
// update the settings model and view model appropriately
auto attemptSetAction = [=]() {
// If the action was changed,
// update the settings model and view model appropriately
if (args.OldActionName() != args.NewActionName())
{
// convert the action's name into a view model.
Expand Down Expand Up @@ -318,8 +316,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
senderVM.AcceptChangesFlyout(nullptr);

// update settings model and view model
attemptRebindKeys();
attemptSetAction();
applyChangesToSettingsModel();
senderVM.ToggleEditMode();
});

Expand All @@ -337,8 +334,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}

// update settings model and view model
attemptRebindKeys();
attemptSetAction();
applyChangesToSettingsModel();

// We NEED to toggle the edit mode here,
// so that if nothing changed, we still exit
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// ProposedAction: the entry selected by the combo box; may disagree with the settings model.
// CurrentAction: the combo box item that maps to the settings model value.
// AvailableActions: the list of options in the combo box; both actions above must be in this list.
// NOTE: ProposedAction and CurrentAction may disagree mainly due to the "edit mode" system in place.
// Current Action serves as...
// 1 - a record of what to set ProposedAction to on a cancellation
// 2 - a form of translation between ProposedAction and the settings model
// We would also need an ActionMap reference to remove this, but this is a better separation
// of responsibilities.
VIEW_MODEL_OBSERVABLE_PROPERTY(IInspectable, ProposedAction);
VIEW_MODEL_OBSERVABLE_PROPERTY(hstring, CurrentAction);
WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector<hstring>, AvailableActions, nullptr);
Expand Down

0 comments on commit 3499a72

Please sign in to comment.