Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply MVVM for global settings in SUI #11853

Closed
wants to merge 5 commits into from
Closed

Conversation

carlos-zamora
Copy link
Member

Summary of the Pull Request

Introduces and uses GlobalSettingsViewModel as the view model for global settings in the settings UI. This makes it so that we don't actually store the XXXNavigationState on the page objects. Instead, we store the view model. The view model also stores some additional useful information like enum entry lists, current enum entry values, and getters for the settings model.

References

#9207 - Apply MVVM

Detailed Description of the Pull Request / Additional comments

Really this just involved me moving stuff into GlobalSettingsViewModel. There should be no change in functionality.

Validation Steps Performed

Changed some global settings and saved/discarded changes. Verified correct behavior from that.

src/cascadia/TerminalSettingsEditor/GlobalAppearance.idl Outdated Show resolved Hide resolved
#include "GlobalSettingsViewModel.g.h"
#include "Utils.h"
#include "ViewModelHelpers.h"
#include "..\TerminalSettingsModel\MTSMSettings.h"
Copy link
Member Author

Choose a reason for hiding this comment

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

I know... I really shouldn't just grab this from TerminalSettingsModel, but it lets me use the X-Macro and it's so nice! Should I move this to inc or something? I feel like it's fine.

Copy link
Member

Choose a reason for hiding this comment

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

I feel like it's fine. I think the traditional OS code style would be

TerminalSettingsModel/ -> contains the actual soure
  - inc/ -> has shared headers like MTSMSettings.h
  - lib/ -> builds the .lib
  - dll/ -> builds the .dll

but honestly, meh

Comment on lines 76 to +78
<ComboBox x:Name="DefaultTerminal"
ItemsSource="{x:Bind State.Settings.DefaultTerminals}"
SelectedItem="{x:Bind State.Settings.CurrentDefaultTerminal, Mode=TwoWay}"
ItemsSource="{x:Bind AppSettings.DefaultTerminals}"
SelectedItem="{x:Bind AppSettings.CurrentDefaultTerminal, Mode=TwoWay}"
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 one is weird. We need CascadiaSettings for defterm. But Globals already has a reference to CascadiaSettings. For now, I've been passing it in separately to the navigation state and storing a reference to it on the page. Long term, we should be using CascadiaSettingsViewModel instead, I think. But idk if this abstraction is right. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

meh, this is fine, I don't think it's much worse than it was before

src/cascadia/TerminalSettingsEditor/Utils.h Outdated Show resolved Hide resolved
_NotifyChanges(L"Has" #name, L## #name); \
} \
} \
#define _GET_SETTING_FUNC(target, name) \
Copy link
Member Author

Choose a reason for hiding this comment

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

A bit annoyed by this change. I wanted to use OBSERVABLE_PROJECTED_SETTING for Default Profile (I think?), but the ClearXXX function wasn't valid. So I had to break things up a bit here.

Copy link
Member

Choose a reason for hiding this comment

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

wait isn't that why we have the PERMANENT variant of OBSERVABLE...? Like, Name and Guid cannot be cleared.

Copy link
Member

Choose a reason for hiding this comment

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

yea this is probably the only one I'm not signing off over. Not blocking, over, but it is a little weird

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, the exact problem is that DefaultProfile only has a getter and a setter (because we do that dance where we get the unparsed default profile, but we always have a default profile). So it doesn't use inheritance at all.

The PERMANENT variant gets rid of ClearXXX, but still uses the HasXXX API. I could introduce a third macro called GET_SET_XXX that would just expose the getter/setter. Idk how valuable that would be though tbh.

@carlos-zamora
Copy link
Member Author

Closing this PR because we want to make an MVVM class for each page for consistency. @PankajBhojwani will take it over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants