2021-10-04 14:42:46 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
2020-12-11 22:34:21 +01:00
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Profiles.g.h"
|
|
|
|
#include "ProfilePageNavigationState.g.h"
|
2020-12-18 00:14:07 +01:00
|
|
|
#include "DeleteProfileEventArgs.g.h"
|
2020-12-11 22:34:21 +01:00
|
|
|
#include "ProfileViewModel.g.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
#include "ViewModelHelpers.h"
|
2021-07-09 22:43:58 +02:00
|
|
|
#include "Appearances.h"
|
2020-12-11 22:34:21 +01:00
|
|
|
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|
|
|
{
|
|
|
|
struct ProfileViewModel : ProfileViewModelT<ProfileViewModel>, ViewModelHelper<ProfileViewModel>
|
|
|
|
{
|
|
|
|
public:
|
2021-05-17 04:26:47 +02:00
|
|
|
ProfileViewModel(const Model::Profile& profile, const Model::CascadiaSettings& settings);
|
|
|
|
|
|
|
|
Model::TerminalSettings TermSettings() const;
|
2020-12-11 22:34:21 +01:00
|
|
|
|
2021-08-04 00:25:23 +02:00
|
|
|
void SetAcrylicOpacityPercentageValue(double value)
|
|
|
|
{
|
2021-10-04 14:42:46 +02:00
|
|
|
Opacity(winrt::Microsoft::Terminal::Settings::Editor::Converters::PercentageValueToPercentage(value));
|
2021-10-07 13:39:20 +02:00
|
|
|
|
|
|
|
// GH#11372: If we're on Windows 10, and someone wants opacity, then
|
|
|
|
// we'll turn acrylic on for them. Opacity doesn't work without
|
|
|
|
// acrylic on Windows 10.
|
|
|
|
//
|
|
|
|
// BODGY: CascadiaSettings's function IsDefaultTerminalAvailable
|
|
|
|
// is basically a "are we on Windows 11" check, because defterm
|
|
|
|
// only works on Win11. So we'll use that.
|
|
|
|
//
|
|
|
|
// Remove when we can remove the rest of GH#11285
|
2021-10-29 16:06:43 +02:00
|
|
|
if (value < 100.0 &&
|
|
|
|
!winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings::IsDefaultTerminalAvailable())
|
2021-10-07 13:39:20 +02:00
|
|
|
{
|
|
|
|
UseAcrylic(true);
|
|
|
|
}
|
2021-08-04 00:25:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void SetPadding(double value)
|
|
|
|
{
|
|
|
|
Padding(to_hstring(value));
|
|
|
|
}
|
|
|
|
|
2021-03-08 17:45:12 +01:00
|
|
|
// starting directory
|
2021-01-23 00:46:41 +01:00
|
|
|
bool UseParentProcessDirectory();
|
|
|
|
void UseParentProcessDirectory(const bool useParent);
|
|
|
|
bool UseCustomStartingDirectory();
|
2021-01-18 23:34:07 +01:00
|
|
|
|
2021-03-08 17:45:12 +01:00
|
|
|
// font face
|
|
|
|
static void UpdateFontList() noexcept;
|
|
|
|
Windows::Foundation::Collections::IObservableVector<Editor::Font> CompleteFontList() const noexcept;
|
|
|
|
Windows::Foundation::Collections::IObservableVector<Editor::Font> MonospaceFontList() const noexcept;
|
|
|
|
|
|
|
|
// general profile knowledge
|
2021-05-21 19:34:25 +02:00
|
|
|
winrt::guid OriginalProfileGuid() const noexcept;
|
2021-03-08 17:45:12 +01:00
|
|
|
bool CanDeleteProfile() const;
|
2021-07-09 22:43:58 +02:00
|
|
|
Editor::AppearanceViewModel DefaultAppearance();
|
2021-07-14 01:33:22 +02:00
|
|
|
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();
|
|
|
|
|
2021-03-04 20:27:03 +01:00
|
|
|
WINRT_PROPERTY(bool, IsBaseLayer, false);
|
2020-12-18 00:14:07 +01:00
|
|
|
|
2020-12-11 22:34:21 +01:00
|
|
|
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_profile, Guid);
|
|
|
|
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_profile, ConnectionType);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, Name);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, Source);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, Hidden);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, Icon);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, CloseOnExit);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, TabTitle);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, TabColor);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, SuppressApplicationTitle);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, UseAcrylic);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, ScrollState);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, Padding);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, Commandline);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, StartingDirectory);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, AntialiasingMode);
|
2021-04-09 00:46:16 +02:00
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile.DefaultAppearance(), Foreground);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile.DefaultAppearance(), Background);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile.DefaultAppearance(), SelectionBackground);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile.DefaultAppearance(), CursorColor);
|
2021-09-20 19:08:13 +02:00
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile.DefaultAppearance(), Opacity);
|
2020-12-11 22:34:21 +01:00
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, HistorySize);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, SnapOnInput);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, AltGrAliasing);
|
|
|
|
OBSERVABLE_PROJECTED_SETTING(_profile, BellStyle);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Model::Profile _profile;
|
2021-05-21 19:34:25 +02:00
|
|
|
winrt::guid _originalProfileGuid;
|
2021-01-18 23:34:07 +01:00
|
|
|
winrt::hstring _lastBgImagePath;
|
2021-01-23 00:46:41 +01:00
|
|
|
winrt::hstring _lastStartingDirectoryPath;
|
2021-07-09 22:43:58 +02:00
|
|
|
Editor::AppearanceViewModel _defaultAppearanceViewModel;
|
2021-03-08 17:45:12 +01:00
|
|
|
|
|
|
|
static Windows::Foundation::Collections::IObservableVector<Editor::Font> _MonospaceFontList;
|
|
|
|
static Windows::Foundation::Collections::IObservableVector<Editor::Font> _FontList;
|
|
|
|
|
|
|
|
static Editor::Font _GetFont(com_ptr<IDWriteLocalizedStrings> localizedFamilyNames);
|
2021-05-17 04:26:47 +02:00
|
|
|
|
|
|
|
Model::CascadiaSettings _appSettings;
|
2021-07-14 01:33:22 +02:00
|
|
|
Editor::AppearanceViewModel _unfocusedAppearanceViewModel;
|
2020-12-11 22:34:21 +01:00
|
|
|
};
|
|
|
|
|
2020-12-18 00:14:07 +01:00
|
|
|
struct DeleteProfileEventArgs :
|
|
|
|
public DeleteProfileEventArgsT<DeleteProfileEventArgs>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DeleteProfileEventArgs(guid profileGuid) :
|
|
|
|
_ProfileGuid(profileGuid) {}
|
|
|
|
|
|
|
|
guid ProfileGuid() const noexcept { return _ProfileGuid; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
guid _ProfileGuid{};
|
|
|
|
};
|
|
|
|
|
2020-12-11 22:34:21 +01:00
|
|
|
struct ProfilePageNavigationState : ProfilePageNavigationStateT<ProfilePageNavigationState>
|
|
|
|
{
|
|
|
|
public:
|
2021-01-26 00:06:33 +01:00
|
|
|
ProfilePageNavigationState(const Editor::ProfileViewModel& viewModel,
|
|
|
|
const Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme>& schemes,
|
|
|
|
const Editor::ProfilePageNavigationState& lastState,
|
|
|
|
const IHostedInWindow& windowRoot) :
|
2020-12-11 22:34:21 +01:00
|
|
|
_Profile{ viewModel },
|
2021-07-14 01:33:22 +02:00
|
|
|
_Schemes{ schemes },
|
2020-12-11 22:34:21 +01:00
|
|
|
_WindowRoot{ windowRoot }
|
|
|
|
{
|
2021-05-07 06:13:06 +02:00
|
|
|
// If there was a previous nav state copy the selected pivot from it.
|
2021-01-26 00:06:33 +01:00
|
|
|
if (lastState)
|
|
|
|
{
|
2021-05-07 06:13:06 +02:00
|
|
|
_LastActivePivot = lastState.LastActivePivot();
|
2021-01-26 00:06:33 +01:00
|
|
|
}
|
2021-07-09 22:43:58 +02:00
|
|
|
viewModel.DefaultAppearance().Schemes(schemes);
|
|
|
|
viewModel.DefaultAppearance().WindowRoot(windowRoot);
|
2021-07-14 01:33:22 +02:00
|
|
|
|
|
|
|
if (viewModel.UnfocusedAppearance())
|
|
|
|
{
|
|
|
|
viewModel.UnfocusedAppearance().Schemes(schemes);
|
|
|
|
viewModel.UnfocusedAppearance().WindowRoot(windowRoot);
|
|
|
|
}
|
2020-12-11 22:34:21 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 00:14:07 +01:00
|
|
|
void DeleteProfile();
|
2021-07-14 01:33:22 +02:00
|
|
|
void CreateUnfocusedAppearance();
|
|
|
|
void DeleteUnfocusedAppearance();
|
2020-12-18 00:14:07 +01:00
|
|
|
|
2021-07-14 01:33:22 +02:00
|
|
|
Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme> Schemes() { return _Schemes; }
|
|
|
|
void Schemes(const Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme>& val) { _Schemes = val; }
|
2020-12-18 00:14:07 +01:00
|
|
|
TYPED_EVENT(DeleteProfile, Editor::ProfilePageNavigationState, Editor::DeleteProfileEventArgs);
|
2021-03-04 20:27:03 +01:00
|
|
|
WINRT_PROPERTY(IHostedInWindow, WindowRoot, nullptr);
|
|
|
|
WINRT_PROPERTY(Editor::ProfilesPivots, LastActivePivot, Editor::ProfilesPivots::General);
|
|
|
|
WINRT_PROPERTY(Editor::ProfileViewModel, Profile, nullptr);
|
2021-07-14 01:33:22 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme> _Schemes;
|
2020-12-11 22:34:21 +01:00
|
|
|
};
|
|
|
|
|
Manually dismiss popups when the window moves, or the SUI scrolls (#10922)
## Summary of the Pull Request
BODGY!
This solution was suggested in https://github.com/microsoft/microsoft-ui-xaml/issues/4554#issuecomment-887815332.
When the window moves, or when a ScrollViewer scrolls, dismiss any popups that are visible. This happens automagically when an app is a real XAML app, but it doesn't work for XAML Islands.
## References
* upstream at https://github.com/microsoft/microsoft-ui-xaml/issues/4554
## PR Checklist
* [x] Closes #9320
* [x] I work here
* [ ] Tests added/passed
* [ ] Requires documentation to be updated
## Detailed Description of the Pull Request / Additional comments
Unfortunately, we've got a bunch of scroll viewers in our SUI. So I did something bodgyx2 to make our life a little easier.
`DismissAllPopups` can be used to dismiss all popups for a particular UI element. However, we've got a bunch of pages with scroll viewers that may or may not have popups in them. Rather than define the same exact body for all their `ViewChanging` events, the `HasScrollViewer` struct will just do it for you!
Inside the `HasScrollViewer` stuct, we can't get at the `XamlRoot()` that our subclass implements. I mean, _we_ can, but when XAML does it's codegen, _XAML_ won't be able to figure it out.
Fortunately for us, we don't need to! The sender is a UIElement, so we can just get _their_ `XamlRoot()`.
So, you can fix this for any SUI page with just a simple
```diff
- <ScrollViewer>
+ <ScrollViewer ViewChanging="ViewChanging">
```
```diff
- struct AddProfile : AddProfileT<AddProfile>
+ struct AddProfile : public HasScrollViewer<AddProfile>, AddProfileT<AddProfile>
```
## Validation Steps Performed
* the window doesn't close when you move it
* the popups _do_ close when you move the window
* the popups close when you scroll any SUI page
2021-08-16 15:41:17 +02:00
|
|
|
struct Profiles : public HasScrollViewer<Profiles>, ProfilesT<Profiles>
|
2020-12-11 22:34:21 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Profiles();
|
|
|
|
|
2021-01-13 19:08:40 +01:00
|
|
|
void OnNavigatedTo(const Windows::UI::Xaml::Navigation::NavigationEventArgs& e);
|
2021-02-08 19:04:43 +01:00
|
|
|
void OnNavigatedFrom(const Windows::UI::Xaml::Navigation::NavigationEventArgs& e);
|
2020-12-11 22:34:21 +01:00
|
|
|
|
2021-05-25 00:51:03 +02:00
|
|
|
// bell style bits
|
|
|
|
bool IsBellStyleFlagSet(const uint32_t flag);
|
|
|
|
void SetBellStyleAudible(winrt::Windows::Foundation::IReference<bool> on);
|
|
|
|
void SetBellStyleWindow(winrt::Windows::Foundation::IReference<bool> on);
|
|
|
|
void SetBellStyleTaskbar(winrt::Windows::Foundation::IReference<bool> on);
|
|
|
|
|
2021-01-13 19:08:40 +01:00
|
|
|
fire_and_forget Commandline_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
|
|
|
|
fire_and_forget StartingDirectory_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
|
|
|
|
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);
|
2021-01-26 00:06:33 +01:00
|
|
|
void Pivot_SelectionChanged(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
|
2021-07-14 01:33:22 +02:00
|
|
|
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);
|
2020-12-11 22:34:21 +01:00
|
|
|
|
|
|
|
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
|
|
|
|
|
2021-03-04 20:27:03 +01:00
|
|
|
WINRT_PROPERTY(Editor::ProfilePageNavigationState, State, nullptr);
|
2021-03-17 21:47:24 +01:00
|
|
|
GETSET_BINDABLE_ENUM_SETTING(AntiAliasingMode, Microsoft::Terminal::Control::TextAntialiasingMode, State().Profile, AntialiasingMode);
|
2021-01-13 19:08:40 +01:00
|
|
|
GETSET_BINDABLE_ENUM_SETTING(CloseOnExitMode, Microsoft::Terminal::Settings::Model::CloseOnExitMode, State().Profile, CloseOnExit);
|
2021-03-17 21:47:24 +01:00
|
|
|
GETSET_BINDABLE_ENUM_SETTING(ScrollState, Microsoft::Terminal::Control::ScrollbarState, State().Profile, ScrollState);
|
2020-12-11 22:34:21 +01:00
|
|
|
|
|
|
|
private:
|
2021-02-08 19:04:43 +01:00
|
|
|
void _UpdateBIAlignmentControl(const int32_t val);
|
|
|
|
|
2020-12-11 22:34:21 +01:00
|
|
|
std::array<Windows::UI::Xaml::Controls::Primitives::ToggleButton, 9> _BIAlignmentButtons;
|
2021-02-08 19:04:43 +01:00
|
|
|
Windows::UI::Xaml::Data::INotifyPropertyChanged::PropertyChanged_revoker _ViewModelChangedRevoker;
|
2021-07-09 22:43:58 +02:00
|
|
|
Windows::UI::Xaml::Data::INotifyPropertyChanged::PropertyChanged_revoker _AppearanceViewModelChangedRevoker;
|
2021-05-17 04:26:47 +02:00
|
|
|
|
|
|
|
Microsoft::Terminal::Control::TermControl _previewControl;
|
2020-12-11 22:34:21 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation
|
|
|
|
{
|
|
|
|
BASIC_FACTORY(Profiles);
|
|
|
|
}
|