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

Allow creating and editing unfocused appearances in the SUI #10317

Merged
41 commits merged into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b923b4b
initial
PankajBhojwani Apr 30, 2021
85a6392
hm
PankajBhojwani May 4, 2021
d750d56
cursor shape/height mostly work
PankajBhojwani May 5, 2021
ad35c70
remove navigated to
PankajBhojwani May 5, 2021
5920408
Color scheme ish
PankajBhojwani May 6, 2021
7eea902
background image stuff ish
PankajBhojwani May 6, 2021
f5078b8
bg image
PankajBhojwani May 10, 2021
f6cf9dd
Remove can delete appearance for now
PankajBhojwani May 10, 2021
0800d64
format
PankajBhojwani May 10, 2021
81a8b8b
dependency callback
PankajBhojwani May 11, 2021
f179248
font stuff
PankajBhojwani May 11, 2021
c8ee89f
format
PankajBhojwani May 11, 2021
62db2fa
comment
PankajBhojwani May 11, 2021
5f047a1
deduplicate file picker
PankajBhojwani May 11, 2021
6c7d997
Remove color scheme from profiles
PankajBhojwani May 11, 2021
3c3fede
abstract
PankajBhojwani May 12, 2021
05666f2
font lists back in profile, ref to profile
PankajBhojwani May 14, 2021
ef71e80
format
PankajBhojwani May 14, 2021
3dca0dd
conflict
PankajBhojwani May 17, 2021
e384b00
conflict, updates from merge main
PankajBhojwani May 21, 2021
8e604ba
format, rearrange
PankajBhojwani May 21, 2021
9ac1407
conflict
PankajBhojwani Jun 1, 2021
901d4bb
% sign changes
PankajBhojwani Jun 15, 2021
7e0264d
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Jun 18, 2021
f5b5bb9
move file/image picker to utils.h/cpp
PankajBhojwani Jun 18, 2021
fbfdb2d
tabstop false
PankajBhojwani Jun 18, 2021
6177c26
format
PankajBhojwani Jun 18, 2021
e04d9fa
ok
PankajBhojwani May 14, 2021
720d715
tryna create
PankajBhojwani May 14, 2021
6aab43a
create a new unfocused appearance
PankajBhojwani Jun 3, 2021
3e97289
delete unfocused appearance
PankajBhojwani Jun 3, 2021
8631907
hide font things for unfocused
PankajBhojwani Jun 3, 2021
0d8649c
dont need this
PankajBhojwani Jun 3, 2021
10dda55
border, send settings update notifications once upon creation
PankajBhojwani Jun 4, 2021
fd71d30
dont need if
PankajBhojwani Jun 7, 2021
8b8cf55
remove expander, buttons instead
PankajBhojwani Jun 11, 2021
9a6d580
format
PankajBhojwani Jun 11, 2021
5c4f5d6
conflit
PankajBhojwani Jul 13, 2021
eb9cb96
localize
PankajBhojwani Jul 13, 2021
b6698e6
Format
PankajBhojwani Jul 13, 2021
38f761d
til feature
PankajBhojwani Jul 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"UsingMonospaceFont" });
}
});

// make sure to send all the property changed events once here
// we do this in the case an old appearance was deleted and then a new one is created,
// the old settings need to be updated in xaml
Comment on lines +261 to +263
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... could we somehow detect something like "AppearanceChanged"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what's happening here already! (Note that we only get here from the _ViewModelChanged event)

The thing is the Appearances object (not the view model) has some settings that xaml binds to (like CurrentColorScheme) that hang around even if the view model is deleted, then when a new view model is created we need to tell xaml that these settings may have changed

_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentCursorShape" });
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"IsVintageCursor" });
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentColorScheme" });
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentBackgroundImageStretchMode" });
_UpdateBIAlignmentControl(static_cast<int32_t>(Appearance().BackgroundImageAlignment()));
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentFontWeight" });
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"IsCustomFontWeight" });
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentFontFace" });
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"ShowAllFonts" });
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"UsingMonospaceFont" });
}
}

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme> Schemes() { return _Schemes; }
void Schemes(const Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme>& val) { _Schemes = val; }

WINRT_PROPERTY(bool, IsDefault, false);
WINRT_PROPERTY(IHostedInWindow, WindowRoot, nullptr);

// These settings are not defined in AppearanceConfig, so we grab them
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.idl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace Microsoft.Terminal.Settings.Editor

runtimeclass AppearanceViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
Boolean IsDefault;

Boolean UseDesktopBGImage;
Boolean BackgroundImageSettingsVisible { get; };

Expand Down
9 changes: 6 additions & 3 deletions src/cascadia/TerminalSettingsEditor/Appearances.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
<local:SettingContainer x:Uid="Profile_FontFace"
ClearSettingValue="{x:Bind Appearance.ClearFontFace}"
HasSettingValue="{x:Bind Appearance.HasFontFace, Mode=OneWay}"
SettingOverrideSource="{x:Bind Appearance.FontFaceOverrideSource, Mode=OneWay}">
SettingOverrideSource="{x:Bind Appearance.FontFaceOverrideSource, Mode=OneWay}"
Visibility="{x:Bind Appearance.IsDefault, Mode=OneWay}">
<StackPanel>
<!--
Binding the ItemsSource to a separate variable that switches between the
Expand Down Expand Up @@ -104,7 +105,8 @@
<local:SettingContainer x:Uid="Profile_FontSize"
ClearSettingValue="{x:Bind Appearance.ClearFontSize}"
HasSettingValue="{x:Bind Appearance.HasFontSize, Mode=OneWay}"
SettingOverrideSource="{x:Bind Appearance.FontSizeOverrideSource, Mode=OneWay}">
SettingOverrideSource="{x:Bind Appearance.FontSizeOverrideSource, Mode=OneWay}"
Visibility="{x:Bind Appearance.IsDefault, Mode=OneWay}">
<muxc:NumberBox AcceptsExpression="False"
LargeChange="10"
Maximum="128"
Expand All @@ -119,7 +121,8 @@
x:Uid="Profile_FontWeight"
ClearSettingValue="{x:Bind Appearance.ClearFontWeight}"
HasSettingValue="{x:Bind Appearance.HasFontWeight, Mode=OneWay}"
SettingOverrideSource="{x:Bind Appearance.FontWeightOverrideSource, Mode=OneWay}">
SettingOverrideSource="{x:Bind Appearance.FontWeightOverrideSource, Mode=OneWay}"
Visibility="{x:Bind Appearance.IsDefault, Mode=OneWay}">
<StackPanel>
<ComboBox x:Name="FontWeightComboBox"
ItemTemplate="{StaticResource EnumComboBoxItemTemplate}"
Expand Down
75 changes: 74 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
_profile{ profile },
_defaultAppearanceViewModel{ winrt::make<implementation::AppearanceViewModel>(profile.DefaultAppearance().try_as<AppearanceConfig>()) },
_originalProfileGuid{ profile.Guid() },
_appSettings{ appSettings }
_appSettings{ appSettings },
_unfocusedAppearanceViewModel{ nullptr }
{
// Add a property changed handler to our own property changed event.
// This propagates changes from the settings model to anybody listening to our
Expand Down Expand Up @@ -63,6 +64,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
UpdateFontList();
}

if (profile.HasUnfocusedAppearance())
{
_unfocusedAppearanceViewModel = winrt::make<implementation::AppearanceViewModel>(profile.UnfocusedAppearance().try_as<AppearanceConfig>());
}

_defaultAppearanceViewModel.IsDefault(true);
}

Model::TerminalSettings ProfileViewModel::TermSettings() const
Expand Down Expand Up @@ -239,6 +247,51 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return _defaultAppearanceViewModel;
}

bool ProfileViewModel::HasUnfocusedAppearance()
{
return _profile.HasUnfocusedAppearance();
}

bool ProfileViewModel::EditableUnfocusedAppearance()
{
if constexpr (Feature_EditableUnfocusedAppearance::IsEnabled())
Copy link
Member

Choose a reason for hiding this comment

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

This is the same as "return Feature_x::IsEnabled()"

Copy link
Member

Choose a reason for hiding this comment

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

Curious: isn't this technically faster because of the if constexpr? I suppose straight up returning IsEnabled() wouldn't be much slower haha, unless it's inline/constexpr? idk much about this stuff hahaha

Copy link
Member

@DHowett DHowett Jul 14, 2021

Choose a reason for hiding this comment

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

No. The compiler is smart enough to optimize...

if (true) { return true; }
return false;

into

return true;

on its own.

{
return true;
}
return false;
}

bool ProfileViewModel::ShowUnfocusedAppearance()
{
return EditableUnfocusedAppearance() && HasUnfocusedAppearance();
}

void ProfileViewModel::CreateUnfocusedAppearance(const Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme>& schemes,
const IHostedInWindow& windowRoot)
{
_profile.CreateUnfocusedAppearance();

_unfocusedAppearanceViewModel = winrt::make<implementation::AppearanceViewModel>(_profile.UnfocusedAppearance().try_as<AppearanceConfig>());
_unfocusedAppearanceViewModel.Schemes(schemes);
_unfocusedAppearanceViewModel.WindowRoot(windowRoot);

_NotifyChanges(L"UnfocusedAppearance", L"HasUnfocusedAppearance");
}

void ProfileViewModel::DeleteUnfocusedAppearance()
{
_profile.DeleteUnfocusedAppearance();

_unfocusedAppearanceViewModel = nullptr;

_NotifyChanges(L"HasUnfocusedAppearance");
Copy link
Member

Choose a reason for hiding this comment

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

Why do you not also need to notify UnfocusedAppearance here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The control's visibility gets set to false from the HasUnfocusedAppearance notification, so XAML never even tries to access the UnfocusedAppearance

}

Editor::AppearanceViewModel ProfileViewModel::UnfocusedAppearance()
{
return _unfocusedAppearanceViewModel;
}

bool ProfileViewModel::UseParentProcessDirectory()
{
return StartingDirectory().empty();
Expand Down Expand Up @@ -291,6 +344,16 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
_DeleteProfileHandlers(*this, *deleteProfileArgs);
}

void ProfilePageNavigationState::CreateUnfocusedAppearance()
{
_Profile.CreateUnfocusedAppearance(_Schemes, _WindowRoot);
}

void ProfilePageNavigationState::DeleteUnfocusedAppearance()
{
_Profile.DeleteUnfocusedAppearance();
}

PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
Profiles::Profiles() :
_previewControl{ Control::TermControl(Model::TerminalSettings{}, make<PreviewConnection>()) }
{
Expand Down Expand Up @@ -423,6 +486,16 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
state->DeleteProfile();
}

void Profiles::CreateUnfocusedAppearance_Click(IInspectable const& /*sender*/, RoutedEventArgs const& /*e*/)
{
_State.CreateUnfocusedAppearance();
}

void Profiles::DeleteUnfocusedAppearance_Click(IInspectable const& /*sender*/, RoutedEventArgs const& /*e*/)
{
_State.DeleteUnfocusedAppearance();
}

fire_and_forget Profiles::Icon_Click(IInspectable const&, RoutedEventArgs const&)
{
auto lifetime = get_strong();
Expand Down
26 changes: 26 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
winrt::guid OriginalProfileGuid() const noexcept;
bool CanDeleteProfile() const;
Editor::AppearanceViewModel DefaultAppearance();
Editor::AppearanceViewModel UnfocusedAppearance();
bool HasUnfocusedAppearance();
bool EditableUnfocusedAppearance();
bool ShowUnfocusedAppearance();

void CreateUnfocusedAppearance(const Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme>& schemes,
const IHostedInWindow& windowRoot);
void DeleteUnfocusedAppearance();

WINRT_PROPERTY(bool, IsBaseLayer, false);

PERMANENT_OBSERVABLE_PROJECTED_SETTING(_profile, Guid);
Expand Down Expand Up @@ -77,6 +86,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
static Editor::Font _GetFont(com_ptr<IDWriteLocalizedStrings> localizedFamilyNames);

Model::CascadiaSettings _appSettings;
Editor::AppearanceViewModel _unfocusedAppearanceViewModel;
};

struct DeleteProfileEventArgs :
Expand All @@ -100,6 +110,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
const Editor::ProfilePageNavigationState& lastState,
const IHostedInWindow& windowRoot) :
_Profile{ viewModel },
_Schemes{ schemes },
_WindowRoot{ windowRoot }
{
// If there was a previous nav state copy the selected pivot from it.
Expand All @@ -109,14 +120,27 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
viewModel.DefaultAppearance().Schemes(schemes);
viewModel.DefaultAppearance().WindowRoot(windowRoot);

if (viewModel.UnfocusedAppearance())
{
viewModel.UnfocusedAppearance().Schemes(schemes);
viewModel.UnfocusedAppearance().WindowRoot(windowRoot);
}
}

void DeleteProfile();
void CreateUnfocusedAppearance();
void DeleteUnfocusedAppearance();

Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme> Schemes() { return _Schemes; }
void Schemes(const Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme>& val) { _Schemes = val; }
TYPED_EVENT(DeleteProfile, Editor::ProfilePageNavigationState, Editor::DeleteProfileEventArgs);
WINRT_PROPERTY(IHostedInWindow, WindowRoot, nullptr);
WINRT_PROPERTY(Editor::ProfilesPivots, LastActivePivot, Editor::ProfilesPivots::General);
WINRT_PROPERTY(Editor::ProfileViewModel, Profile, nullptr);

private:
Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme> _Schemes;
};

struct Profiles : ProfilesT<Profiles>
Expand All @@ -138,6 +162,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
fire_and_forget Icon_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
void DeleteConfirmation_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
void Pivot_SelectionChanged(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
void CreateUnfocusedAppearance_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
void DeleteUnfocusedAppearance_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);

WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);

Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Profiles.idl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ namespace Microsoft.Terminal.Settings.Editor
Boolean UseCustomStartingDirectory { get; };
AppearanceViewModel DefaultAppearance { get; };
Guid OriginalProfileGuid { get; };
Boolean HasUnfocusedAppearance { get; };
Boolean EditableUnfocusedAppearance { get; };
Boolean ShowUnfocusedAppearance { get; };
AppearanceViewModel UnfocusedAppearance { get; };

void CreateUnfocusedAppearance(Windows.Foundation.Collections.IMapView<String, Microsoft.Terminal.Settings.Model.ColorScheme> Schemes, IHostedInWindow WindowRoot);
void DeleteUnfocusedAppearance();

OBSERVABLE_PROJECTED_PROFILE_SETTING(String, Name);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Guid, Guid);
Expand Down Expand Up @@ -74,6 +81,9 @@ namespace Microsoft.Terminal.Settings.Editor
ProfileViewModel Profile;
ProfilesPivots LastActivePivot;

void CreateUnfocusedAppearance();
void DeleteUnfocusedAppearance();

Comment on lines +84 to +86
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 probably remove these two functions and just go through the profile instead, right? These don't feel like they should be a part of the navigation state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately we need some way to pass the list of color schemes and the window root to the profile view model for it to create an appearance view model. The PVM doesn't have the list of color schemes nor the window root, only the navigation state does.

event Windows.Foundation.TypedEventHandler<ProfilePageNavigationState, DeleteProfileEventArgs> DeleteProfile;
};

Expand Down
Loading