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

TSE: Replace TSM.Profile with a ProfileViewModel #8552

Merged
merged 2 commits into from
Dec 11, 2020

Conversation

DHowett
Copy link
Member

@DHowett DHowett commented Dec 11, 2020

It's generally accepted that in a graphical application you'll follow a
design pattern. The one this moves us towards is "MVVM" -- Model, View,
View Model.

In an ideal world, all of our display smarts would be in the
ViewModel and the View would literally just be XAML. This moves us
closer to that reality.

The only thing the Profile page ViewModel does right now is proxy
requests through to the Profile behind it while adding some basic
invalidation logic and detection of a setting being set to its current
value.

We have to do this because (1) MVVM is better and (2) separation of
concerns dictates that TSM::Profile should not have a
Windows.UI.Xaml dependency (in IPropertyChangedNotifier). It therefore
cannot conform to Xaml's notion of what a ViewModel should be.

I've done this by introducing a heap of code-generating macros and a
template that work together to make the process of adding more settings
easier (if not "easy").

We are eventually going to need to do this for all of the existing TSM
model objects. In an ideal world, even our navigation would be driven
through a viewmodel that supports a notion of an "active page".

All I've done so far is break ProfilesPage's dependency on Profile entirely.
Weird how that works.

Fixes "browse buttons do not actually update the profile"
Fixes "we need to have convoluted local overrides that update the
visibility of things like AcrylicOpacity"
Fixes "we'll eventually need a way to update a preview TermControl"
Fixes "we have no idea how we're going to update the Discard/Apply
buttons or the unsaved changes label"

Having a PVM that notifies on icon/name change will also make it easier
for the MainPage to update its NavViewItems.

It's generally accepted that in a graphical application you'll follow a
design pattern. The one this moves us towards is "MVVM" -- Model, View,
View Model.

In an ideal world, _all of our display smarts_ would be in the
ViewModel and the View would literally just be XAML. This moves us
closer to that reality.

The only thing the Profile page ViewModel does right now is proxy
requests through to the Profile behind it while adding some basic
invalidation logic and detection of a setting being set to its current
value.

We have to do this because (1) MVVM is better and (2) separation of
concerns dictates that TSM::Profile should **not** have a
Windows.UI.Xaml dependency (in IPropertyChangedNotifier). It therefore
**cannot** conform to Xaml's notion of what a ViewModel should be.

I've done this by introducing a heap of code-generating macros and a
template that work together to make the process of adding more settings
easier (if not "easy").

We are eventually going to need to do this for all of the existing TSM
model objects. In an ideal world, even our navigation would be driven
through a viewmodel that supports a notion of an "active page".

All I've done so far is break ProfilesPage's dependency on Profile entirely.
Weird how that works.

Fixes "browse buttons do not actually update the profile"
Fixes "we need to have convoluted local overrides that update the
  visiblity of things like AcrylicOpacity"
Fixes "we'll eventually need a way to update a preview TermControl"
Fixes "we have no idea how we're going to update the Discard/Apply
  buttons or the unsaved changes label"

Having a PVM that notifies on icon/name change will also make it easier
for the MainPage to update its NavViewItems.
if (name() != value) \
{ \
target.name(value); \
_NotifyChanges(L"Has" #name, L#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.

this notifies for "HasX" and "X" simultaneously

Copy link
Member

Choose a reason for hiding this comment

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

omg, a macro for a template. You've gone wild with power hahaha

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I guess I understand why we need this, I just, hate it. Whatever, we java now boys.

@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
Copy link
Member

Choose a reason for hiding this comment

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

.idl.h? what the heck

Copy link
Member

Choose a reason for hiding this comment

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

YOU CAN DEFINE MACROS FOR THE IDL

Copy link
Member

Choose a reason for hiding this comment

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

WHAT

Copy link
Member Author

Choose a reason for hiding this comment

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

YEP! I'm using .idl.h as a signal/suggestion, not a contract.


PERMANENT_OBSERVABLE_PROJECTED_SETTING(_profile, Guid);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_profile, ConnectionType);
OBSERVABLE_PROJECTED_SETTING(_profile, Name);
Copy link
Member

Choose a reason for hiding this comment

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

as happy as these new macros make me, I friggin hate that there's another place we'll need to make sure to add the setting to. Chalk this up as another reason to have AddATerminalSetting.md

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 know.

Copy link
Member

Choose a reason for hiding this comment

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

I'll actually go ahead and add AddATerminalSetting.md to my follow-up tasks.

namespace Microsoft.Terminal.Settings.Editor
{
runtimeclass ProfileViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged
Copy link
Member

Choose a reason for hiding this comment

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

Am I dumb for thinking there could be an IProfile that defines all these, then Profile and ProfileViewModel implement that? So these could be defined in a single source of truth?

Copy link
Member Author

Choose a reason for hiding this comment

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

My gut tells me the interface would be good now, but bad in the future. As we implement UI-driven features that diverge from the representation in the settings model (which we will, make no mistake), we'll have to add things to this idl manually anyway.

Already, this is incorrect. We should move the bindable enum stuff up to the ViewModel because it's a viewmodel of an enum value, and make the active values in the ProfileViewModel use EnumEntries for enum fields. Much of the logic that is in the Profiles page CodeBehind should be here.

This is just a start, and I think doing the interface thing would take us on the wrong path. What do you think?

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 the redundancy sucks. FromJson, ToJson, Clone, Copy, TSM idl, TSE idl, TSE xaml, IControlSettings, ICoreSettings, IAppearanceConfig. It's awful.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense to me

@DHowett
Copy link
Member Author

DHowett commented Dec 11, 2020

The SA failure is because feature/sui has not merged main, and so this has not merged main.

if (name() != value) \
{ \
target.name(value); \
_NotifyChanges(L"Has" #name, L#name); \
Copy link
Member

Choose a reason for hiding this comment

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

omg, a macro for a template. You've gone wild with power hahaha


PERMANENT_OBSERVABLE_PROJECTED_SETTING(_profile, Guid);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_profile, ConnectionType);
OBSERVABLE_PROJECTED_SETTING(_profile, Name);
Copy link
Member

Choose a reason for hiding this comment

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

I'll actually go ahead and add AddATerminalSetting.md to my follow-up tasks.

@@ -30,13 +30,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
private:
Model::CascadiaSettings _settingsSource;
Model::CascadiaSettings _settingsClone;
winrt::Windows::Foundation::Collections::IMap<Model::Profile, winrt::Microsoft::UI::Xaml::Controls::NavigationViewItem> _profileToNavItemMap;
Copy link
Member

Choose a reason for hiding this comment

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

oh geez, I must've added that in on accident. My bad!

@DHowett DHowett merged commit 74a85db into feature/settings-ui Dec 11, 2020
@DHowett DHowett deleted the dev/duhowett/tsvm_pvm branch December 11, 2020 18:24
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