|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#include "Extensions.g.h" |
| 7 | +#include "ExtensionsViewModel.g.h" |
| 8 | +#include "ExtensionPackageViewModel.g.h" |
| 9 | +#include "FragmentExtensionViewModel.g.h" |
| 10 | +#include "FragmentProfileViewModel.g.h" |
| 11 | +#include "FragmentColorSchemeViewModel.g.h" |
| 12 | +#include "ExtensionPackageTemplateSelector.g.h" |
| 13 | +#include "ViewModelHelpers.h" |
| 14 | +#include "Utils.h" |
| 15 | + |
| 16 | +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation |
| 17 | +{ |
| 18 | + struct Extensions : public HasScrollViewer<Extensions>, ExtensionsT<Extensions> |
| 19 | + { |
| 20 | + public: |
| 21 | + Windows::UI::Xaml::Thickness CalculateMargin(bool hidden); |
| 22 | + |
| 23 | + Extensions(); |
| 24 | + |
| 25 | + void OnNavigatedTo(const Windows::UI::Xaml::Navigation::NavigationEventArgs& e); |
| 26 | + |
| 27 | + void ExtensionNavigator_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args); |
| 28 | + void NavigateToProfile_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args); |
| 29 | + void NavigateToColorScheme_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args); |
| 30 | + |
| 31 | + WINRT_PROPERTY(Editor::ExtensionsViewModel, ViewModel, nullptr); |
| 32 | + |
| 33 | + private: |
| 34 | + Editor::ExtensionPackageTemplateSelector _extensionPackageIdentifierTemplateSelector; |
| 35 | + }; |
| 36 | + |
| 37 | + struct ExtensionsViewModel : ExtensionsViewModelT<ExtensionsViewModel>, ViewModelHelper<ExtensionsViewModel> |
| 38 | + { |
| 39 | + public: |
| 40 | + ExtensionsViewModel(const Model::CascadiaSettings& settings, const Editor::ColorSchemesPageViewModel& colorSchemesPageVM); |
| 41 | + |
| 42 | + // Properties |
| 43 | + Windows::UI::Xaml::DataTemplate CurrentExtensionPackageIdentifierTemplate() const; |
| 44 | + bool IsExtensionView() const noexcept { return _CurrentExtensionPackage != nullptr; } |
| 45 | + bool NoExtensionPackages() const noexcept { return _extensionPackages.Size() == 0; } |
| 46 | + bool NoProfilesModified() const noexcept { return _profilesModifiedView.Size() == 0; } |
| 47 | + bool NoProfilesAdded() const noexcept { return _profilesAddedView.Size() == 0; } |
| 48 | + bool NoSchemesAdded() const noexcept { return _colorSchemesAddedView.Size() == 0; } |
| 49 | + bool DisplayBadge() const noexcept; |
| 50 | + |
| 51 | + // Views |
| 52 | + Windows::Foundation::Collections::IObservableVector<Editor::ExtensionPackageViewModel> ExtensionPackages() const noexcept { return _extensionPackages; } |
| 53 | + Windows::Foundation::Collections::IObservableVector<Editor::FragmentProfileViewModel> ProfilesModified() const noexcept { return _profilesModifiedView; } |
| 54 | + Windows::Foundation::Collections::IObservableVector<Editor::FragmentProfileViewModel> ProfilesAdded() const noexcept { return _profilesAddedView; } |
| 55 | + Windows::Foundation::Collections::IObservableVector<Editor::FragmentColorSchemeViewModel> ColorSchemesAdded() const noexcept { return _colorSchemesAddedView; } |
| 56 | + |
| 57 | + // Methods |
| 58 | + void LazyLoadExtensions(); |
| 59 | + void UpdateSettings(const Model::CascadiaSettings& settings, const Editor::ColorSchemesPageViewModel& colorSchemesPageVM); |
| 60 | + void NavigateToProfile(const guid profileGuid); |
| 61 | + void NavigateToColorScheme(const Editor::ColorSchemeViewModel& schemeVM); |
| 62 | + void MarkAsVisited(); |
| 63 | + |
| 64 | + static bool GetExtensionState(hstring extensionSource, const Model::CascadiaSettings& settings); |
| 65 | + static void SetExtensionState(hstring extensionSource, const Model::CascadiaSettings& settings, bool enableExt); |
| 66 | + |
| 67 | + til::typed_event<IInspectable, guid> NavigateToProfileRequested; |
| 68 | + til::typed_event<IInspectable, Editor::ColorSchemeViewModel> NavigateToColorSchemeRequested; |
| 69 | + |
| 70 | + VIEW_MODEL_OBSERVABLE_PROPERTY(Editor::ExtensionPackageViewModel, CurrentExtensionPackage, nullptr); |
| 71 | + WINRT_PROPERTY(Editor::ExtensionPackageTemplateSelector, ExtensionPackageIdentifierTemplateSelector, nullptr); |
| 72 | + |
| 73 | + private: |
| 74 | + Model::CascadiaSettings _settings; |
| 75 | + Editor::ColorSchemesPageViewModel _colorSchemesPageVM; |
| 76 | + Windows::Foundation::Collections::IObservableVector<Editor::ExtensionPackageViewModel> _extensionPackages; |
| 77 | + Windows::Foundation::Collections::IObservableVector<Editor::FragmentProfileViewModel> _profilesModifiedView; |
| 78 | + Windows::Foundation::Collections::IObservableVector<Editor::FragmentProfileViewModel> _profilesAddedView; |
| 79 | + Windows::Foundation::Collections::IObservableVector<Editor::FragmentColorSchemeViewModel> _colorSchemesAddedView; |
| 80 | + bool _extensionsLoaded; |
| 81 | + |
| 82 | + void _UpdateListViews(bool updateProfilesModified, bool updateProfilesAdded, bool updateColorSchemesAdded); |
| 83 | + }; |
| 84 | + |
| 85 | + struct ExtensionPackageViewModel : ExtensionPackageViewModelT<ExtensionPackageViewModel>, ViewModelHelper<ExtensionPackageViewModel> |
| 86 | + { |
| 87 | + public: |
| 88 | + ExtensionPackageViewModel(const Model::ExtensionPackage& pkg, const Model::CascadiaSettings& settings) : |
| 89 | + _package{ pkg }, |
| 90 | + _settings{ settings }, |
| 91 | + _fragmentExtensions{ single_threaded_observable_vector<Editor::FragmentExtensionViewModel>() } {} |
| 92 | + |
| 93 | + static bool SortAscending(const Editor::ExtensionPackageViewModel& lhs, const Editor::ExtensionPackageViewModel& rhs); |
| 94 | + |
| 95 | + void UpdateSettings(const Model::CascadiaSettings& settings); |
| 96 | + |
| 97 | + Model::ExtensionPackage Package() const noexcept { return _package; } |
| 98 | + hstring Scope() const noexcept; |
| 99 | + bool Enabled() const; |
| 100 | + void Enabled(bool val); |
| 101 | + hstring AccessibleName() const noexcept; |
| 102 | + Windows::Foundation::Collections::IObservableVector<Editor::FragmentExtensionViewModel> FragmentExtensions() { return _fragmentExtensions; } |
| 103 | + |
| 104 | + private: |
| 105 | + Model::ExtensionPackage _package; |
| 106 | + Model::CascadiaSettings _settings; |
| 107 | + Windows::Foundation::Collections::IObservableVector<Editor::FragmentExtensionViewModel> _fragmentExtensions; |
| 108 | + }; |
| 109 | + |
| 110 | + struct FragmentExtensionViewModel : FragmentExtensionViewModelT<FragmentExtensionViewModel>, ViewModelHelper<FragmentExtensionViewModel> |
| 111 | + { |
| 112 | + public: |
| 113 | + FragmentExtensionViewModel(const Model::FragmentSettings& fragment, |
| 114 | + std::vector<FragmentProfileViewModel>& profilesModified, |
| 115 | + std::vector<FragmentProfileViewModel>& profilesAdded, |
| 116 | + std::vector<FragmentColorSchemeViewModel>& colorSchemesAdded) : |
| 117 | + _fragment{ fragment }, |
| 118 | + _profilesModified{ single_threaded_vector(std::move(profilesModified)) }, |
| 119 | + _profilesAdded{ single_threaded_vector(std::move(profilesAdded)) }, |
| 120 | + _colorSchemesAdded{ single_threaded_vector(std::move(colorSchemesAdded)) } {} |
| 121 | + |
| 122 | + Model::FragmentSettings Fragment() const noexcept { return _fragment; } |
| 123 | + Windows::Foundation::Collections::IVectorView<FragmentProfileViewModel> ProfilesModified() const noexcept { return _profilesModified.GetView(); } |
| 124 | + Windows::Foundation::Collections::IVectorView<FragmentProfileViewModel> ProfilesAdded() const noexcept { return _profilesAdded.GetView(); } |
| 125 | + Windows::Foundation::Collections::IVectorView<FragmentColorSchemeViewModel> ColorSchemesAdded() const noexcept { return _colorSchemesAdded.GetView(); } |
| 126 | + |
| 127 | + private: |
| 128 | + Model::FragmentSettings _fragment; |
| 129 | + Windows::Foundation::Collections::IVector<FragmentProfileViewModel> _profilesModified; |
| 130 | + Windows::Foundation::Collections::IVector<FragmentProfileViewModel> _profilesAdded; |
| 131 | + Windows::Foundation::Collections::IVector<FragmentColorSchemeViewModel> _colorSchemesAdded; |
| 132 | + }; |
| 133 | + |
| 134 | + struct FragmentProfileViewModel : FragmentProfileViewModelT<FragmentProfileViewModel>, ViewModelHelper<FragmentProfileViewModel> |
| 135 | + { |
| 136 | + public: |
| 137 | + FragmentProfileViewModel(const Model::FragmentProfileEntry& entry, const Model::FragmentSettings& fragment, const Model::Profile& deducedProfile) : |
| 138 | + _entry{ entry }, |
| 139 | + _fragment{ fragment }, |
| 140 | + _deducedProfile{ deducedProfile } {} |
| 141 | + |
| 142 | + static bool SortAscending(const Editor::FragmentProfileViewModel& lhs, const Editor::FragmentProfileViewModel& rhs); |
| 143 | + |
| 144 | + Model::Profile Profile() const { return _deducedProfile; }; |
| 145 | + hstring SourceName() const { return _fragment.Source(); } |
| 146 | + hstring Json() const { return _entry.Json(); } |
| 147 | + hstring AccessibleName() const noexcept; |
| 148 | + |
| 149 | + private: |
| 150 | + Model::FragmentProfileEntry _entry; |
| 151 | + Model::FragmentSettings _fragment; |
| 152 | + Model::Profile _deducedProfile; |
| 153 | + }; |
| 154 | + |
| 155 | + struct FragmentColorSchemeViewModel : FragmentColorSchemeViewModelT<FragmentColorSchemeViewModel>, ViewModelHelper<FragmentColorSchemeViewModel> |
| 156 | + { |
| 157 | + public: |
| 158 | + FragmentColorSchemeViewModel(const Model::FragmentColorSchemeEntry& entry, const Model::FragmentSettings& fragment, const Editor::ColorSchemeViewModel& deducedSchemeVM) : |
| 159 | + _entry{ entry }, |
| 160 | + _fragment{ fragment }, |
| 161 | + _deducedSchemeVM{ deducedSchemeVM } {} |
| 162 | + |
| 163 | + static bool SortAscending(const Editor::FragmentColorSchemeViewModel& lhs, const Editor::FragmentColorSchemeViewModel& rhs); |
| 164 | + |
| 165 | + Editor::ColorSchemeViewModel ColorSchemeVM() const { return _deducedSchemeVM; }; |
| 166 | + hstring SourceName() const { return _fragment.Source(); } |
| 167 | + hstring Json() const { return _entry.Json(); } |
| 168 | + hstring AccessibleName() const noexcept; |
| 169 | + |
| 170 | + private: |
| 171 | + Model::FragmentColorSchemeEntry _entry; |
| 172 | + Model::FragmentSettings _fragment; |
| 173 | + Editor::ColorSchemeViewModel _deducedSchemeVM; |
| 174 | + }; |
| 175 | + |
| 176 | + struct ExtensionPackageTemplateSelector : public ExtensionPackageTemplateSelectorT<ExtensionPackageTemplateSelector> |
| 177 | + { |
| 178 | + public: |
| 179 | + ExtensionPackageTemplateSelector() = default; |
| 180 | + |
| 181 | + Windows::UI::Xaml::DataTemplate SelectTemplateCore(const Windows::Foundation::IInspectable& item, const Windows::UI::Xaml::DependencyObject& container); |
| 182 | + Windows::UI::Xaml::DataTemplate SelectTemplateCore(const Windows::Foundation::IInspectable& item); |
| 183 | + |
| 184 | + WINRT_PROPERTY(Windows::UI::Xaml::DataTemplate, DefaultTemplate, nullptr); |
| 185 | + WINRT_PROPERTY(Windows::UI::Xaml::DataTemplate, ComplexTemplate, nullptr); |
| 186 | + }; |
| 187 | +}; |
| 188 | + |
| 189 | +namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation |
| 190 | +{ |
| 191 | + BASIC_FACTORY(Extensions); |
| 192 | + BASIC_FACTORY(ExtensionPackageTemplateSelector); |
| 193 | +} |
0 commit comments