Skip to content

Fix broken reset button on some profile settings#12275

Merged
2 commits merged intomainfrom
dev/cazamor/bugfix-sui-mvvm-reset-btn
Jan 28, 2022
Merged

Fix broken reset button on some profile settings#12275
2 commits merged intomainfrom
dev/cazamor/bugfix-sui-mvvm-reset-btn

Conversation

@carlos-zamora
Copy link
Member

Summary of the Pull Request

This fixes a bug where several settings would not show the reset button. The root cause of this issue is two fold:

  1. Hooking up CurrentXXX
    • GETSET_BINDABLE_ENUM_SETTING was hooked up to the settings model profile object instead of the view model profile object. Since the settings model has no PropertyChanged system, any changes were directly being applied to the setting, but not notifying the view model (and thus, the view, by extension) to update themselves.
    • This fix required me to slightly modify the macro. Rather than using two parameters (object and function name), I used one parameter (path to getter/setter).
  2. Responding to the PropertyChanged notifications
    • Now that we're actually dispatching the PropertyChanged notifications, we need to actually respond to them. This behavior was defined in Profiles::OnNavigatedTo() in the PropertyChanged() handler. Funny enough, that code was still there, it just didn't do anything because it was trying to notify that Profiles::CurrentXXX changed. This is invalid because CurrentXXX got moved to ProfileViewModel.
    • The fix here was pretty easy. Just move the property changed handler to ProfileViewModel's PropertyChanged handler that is defined in the ctor.

References

Bug introduced in #11877

Validation Steps Performed

✅ Profile termination behavior
✅ Bell notification style
✅ Text antialiasing
✅ Scrollbar visibility

Comment on lines +118 to +133
else if (viewModelProperty == L"AntialiasingMode")
{
_NotifyChanges(L"CurrentAntiAliasingMode");
}
else if (viewModelProperty == L"CloseOnExit")
{
_NotifyChanges(L"CurrentCloseOnExitMode");
}
else if (viewModelProperty == L"BellStyle")
{
_NotifyChanges(L"IsBellStyleFlagSet");
}
else if (viewModelProperty == L"ScrollState")
{
_NotifyChanges(L"CurrentScrollState");
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got moved over from Profiles.cpp.

This is step 2 of my PR description.

Comment on lines +109 to +111
GETSET_BINDABLE_ENUM_SETTING(AntiAliasingMode, Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode);
GETSET_BINDABLE_ENUM_SETTING(CloseOnExitMode, Microsoft::Terminal::Settings::Model::CloseOnExitMode, CloseOnExit);
GETSET_BINDABLE_ENUM_SETTING(ScrollState, Microsoft::Terminal::Control::ScrollbarState, ScrollState);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to move this down so that it could find the getters/setters defined in the OBSERVABLE_PROJECTED_SETTING macros above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to leave a comment that says "don't shuffle this section up or you're gonna have a bad time?"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, if somebody moves them, the errors are pretty clear. So I think it's fine.

Comment on lines +52 to +71
#define GETSET_BINDABLE_ENUM_SETTING(name, enumType, viewModelSettingGetSet) \
public: \
winrt::Windows::Foundation::Collections::IObservableVector<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry> name##List() \
{ \
return _##name##List; \
} \
\
winrt::Windows::Foundation::IInspectable Current##name() \
{ \
return winrt::box_value<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>(_##name##Map.Lookup(viewModelSettingGetSet())); \
} \
\
void Current##name(const winrt::Windows::Foundation::IInspectable& enumEntry) \
{ \
if (auto ee = enumEntry.try_as<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>()) \
{ \
auto setting = winrt::unbox_value<enumType>(ee.EnumValue()); \
viewModelSettingGetSet(setting); \
} \
} \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is what I was talking about in step 1 of my PR description.

Opacity(1.0);
}
}
else if (viewModelProperty == L"AntialiasingMode")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checking... the property is "Antialiasing" (with the "A" of "aliasing") being lowercase while the Notification string is "AntiAliasing" (with a capital "A")?

It may very well have already been like that and you just copy/pasted... but I'm just checking as it stood out to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was actually really surprised this worked haha.

Comment on lines +109 to +111
GETSET_BINDABLE_ENUM_SETTING(AntiAliasingMode, Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode);
GETSET_BINDABLE_ENUM_SETTING(CloseOnExitMode, Microsoft::Terminal::Settings::Model::CloseOnExitMode, CloseOnExit);
GETSET_BINDABLE_ENUM_SETTING(ScrollState, Microsoft::Terminal::Control::ScrollbarState, ScrollState);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to leave a comment that says "don't shuffle this section up or you're gonna have a bad time?"

// and propagate those changes to the UI
_ViewModelChangedRevoker = _Profile.PropertyChanged(winrt::auto_revoke, [=](auto&&, const PropertyChangedEventArgs& args) {
const auto settingName{ args.PropertyName() };
if (settingName == L"AntialiasingMode")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah look the case mismatch was over here too. Ah well.

@DHowett
Copy link
Member

DHowett commented Jan 27, 2022

build is failing but i am going to mark automerge anyway -- let's get this in!

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 27, 2022
@ghost
Copy link

ghost commented Jan 27, 2022

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 8 hours, a condition that will be fulfilled in about 6 hours 39 minutes. No worries though, I will be back when the time is right! 😉

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@DHowett
Copy link
Member

DHowett commented Jan 27, 2022

@msftbot merge this in 5 minutes

@ghost
Copy link

ghost commented Jan 27, 2022

Hello @DHowett!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I won't merge this pull request until after the UTC date Thu, 27 Jan 2022 23:32:25 GMT, which is in 5 minutes

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@ghost ghost merged commit 2db4cba into main Jan 28, 2022
@ghost ghost deleted the dev/cazamor/bugfix-sui-mvvm-reset-btn branch January 28, 2022 00:13
zadjii-msft pushed a commit that referenced this pull request Mar 3, 2022
This fixes a bug where several settings would not show the reset button. The root cause of this issue is two fold:
1. Hooking up `CurrentXXX`
   - `GETSET_BINDABLE_ENUM_SETTING` was hooked up to the **settings** model profile object instead of the **view** model profile object. Since the settings model has no `PropertyChanged` system, any changes were directly being applied to the setting, but not notifying the view model (and thus, the view, by extension) to update themselves.
   - This fix required me to slightly modify the macro. Rather than using two parameters (object and function name), I used one parameter (path to getter/setter).
2. Responding to the `PropertyChanged` notifications
   - Now that we're actually dispatching the `PropertyChanged` notifications, we need to actually respond to them. This behavior was defined in `Profiles::OnNavigatedTo()` in the `PropertyChanged()` handler. Funny enough, that code was still there, it just didn't do anything because it was trying to notify that `Profiles::CurrentXXX` changed. This is invalid because `CurrentXXX` got moved to `ProfileViewModel`.
   - The fix here was pretty easy. Just move the property changed handler to `ProfileViewModel`'s `PropertyChanged` handler that is defined in the ctor.

Bug introduced in #11877

✅ Profile termination behavior
✅ Bell notification style
✅ Text antialiasing
✅ Scrollbar visibility
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AutoMerge Marked for automatic merge by the bot when requirements are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants