-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8598ed7
commit 0ba01cc
Showing
12 changed files
with
437 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "Extensions.h" | ||
#include "Extensions.g.cpp" | ||
#include "ExtensionsViewModel.g.cpp" | ||
|
||
#include <LibraryResources.h> | ||
#include "..\WinRTUtils\inc\Utils.h" | ||
|
||
using namespace winrt::Windows::UI::Xaml; | ||
using namespace winrt::Windows::UI::Xaml::Controls; | ||
using namespace winrt::Windows::UI::Xaml::Navigation; | ||
|
||
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation | ||
{ | ||
Extensions::Extensions() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
void Extensions::OnNavigatedTo(const NavigationEventArgs& e) | ||
{ | ||
_ViewModel = e.Parameter().as<Editor::ExtensionsViewModel>(); | ||
} | ||
|
||
void Extensions::ExtensionLoaded(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& /*args*/) | ||
{ | ||
const auto& toggleSwitch = sender.as<Controls::ToggleSwitch>(); | ||
const auto& extensionSource = toggleSwitch.Tag().as<hstring>(); | ||
toggleSwitch.IsOn(_ViewModel.GetExtensionState(extensionSource)); | ||
} | ||
|
||
void Extensions::ExtensionToggled(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& /*args*/) | ||
{ | ||
const auto& toggleSwitch = sender.as<Controls::ToggleSwitch>(); | ||
const auto& extensionSource = toggleSwitch.Tag().as<hstring>(); | ||
_ViewModel.SetExtensionState(extensionSource, toggleSwitch.IsOn()); | ||
} | ||
|
||
ExtensionsViewModel::ExtensionsViewModel(const Model::CascadiaSettings& settings) : | ||
_settings{ settings } | ||
{ | ||
std::vector<IInspectable> fragmentExtensions; | ||
fragmentExtensions.reserve(settings.FragmentExtensions().Size()); | ||
|
||
std::vector<IInspectable> profilesModified; | ||
std::vector<IInspectable> profilesAdded; | ||
std::vector<IInspectable> colorSchemesAdded; | ||
for (const auto&& fragExt : settings.FragmentExtensions()) | ||
{ | ||
fragmentExtensions.push_back(fragExt); | ||
|
||
for (const auto&& profile : fragExt.ModifiedProfilesView()) | ||
{ | ||
profilesModified.push_back(profile); | ||
} | ||
|
||
for (const auto&& profile : fragExt.NewProfilesView()) | ||
{ | ||
profilesAdded.push_back(profile); | ||
} | ||
|
||
for (const auto&& scheme : fragExt.ColorSchemesView()) | ||
{ | ||
colorSchemesAdded.push_back(scheme); | ||
} | ||
} | ||
|
||
_fragmentExtensions = single_threaded_observable_vector<IInspectable>(std::move(fragmentExtensions)); | ||
_profilesModified = single_threaded_observable_vector<IInspectable>(std::move(profilesModified)); | ||
_profilesAdded = single_threaded_observable_vector<IInspectable>(std::move(profilesAdded)); | ||
_colorSchemesAdded = single_threaded_observable_vector<IInspectable>(std::move(colorSchemesAdded)); | ||
} | ||
|
||
// Returns true if the extension is enabled, false otherwise | ||
bool ExtensionsViewModel::GetExtensionState(hstring extensionSource) const | ||
{ | ||
if (const auto& disabledExtensions = _DisabledProfileSources()) | ||
{ | ||
uint32_t ignored; | ||
return !disabledExtensions.IndexOf(extensionSource, ignored); | ||
} | ||
// "disabledProfileSources" not defined --> all extensions are enabled | ||
return true; | ||
} | ||
|
||
// Enable/Disable an extension | ||
void ExtensionsViewModel::SetExtensionState(hstring extensionSource, bool enableExt) | ||
{ | ||
// get the current status of the extension | ||
uint32_t idx; | ||
bool currentlyEnabled = true; | ||
const auto& disabledExtensions = _DisabledProfileSources(); | ||
if (disabledExtensions) | ||
{ | ||
currentlyEnabled = !disabledExtensions.IndexOf(extensionSource, idx); | ||
} | ||
|
||
// current status mismatches the desired status, | ||
// update the list of disabled extensions | ||
if (currentlyEnabled != enableExt) | ||
{ | ||
// If we're disabling an extension and we don't have "disabledProfileSources" defined, | ||
// create it in the model directly | ||
if (!disabledExtensions && !enableExt) | ||
{ | ||
std::vector<hstring> disabledProfileSources{ extensionSource }; | ||
_settings.GlobalSettings().DisabledProfileSources(single_threaded_vector<hstring>(std::move(disabledProfileSources))); | ||
return; | ||
} | ||
|
||
// Update the list of disabled extensions | ||
if (enableExt) | ||
{ | ||
disabledExtensions.RemoveAt(idx); | ||
} | ||
else | ||
{ | ||
disabledExtensions.Append(extensionSource); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "Extensions.g.h" | ||
#include "ExtensionsViewModel.g.h" | ||
#include "ViewModelHelpers.h" | ||
#include "Utils.h" | ||
|
||
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation | ||
{ | ||
struct Extensions : public HasScrollViewer<Extensions>, ExtensionsT<Extensions> | ||
{ | ||
public: | ||
Extensions(); | ||
|
||
void OnNavigatedTo(const Windows::UI::Xaml::Navigation::NavigationEventArgs& e); | ||
void ExtensionLoaded(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args); | ||
void ExtensionToggled(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args); | ||
|
||
WINRT_PROPERTY(Editor::ExtensionsViewModel, ViewModel, nullptr); | ||
}; | ||
|
||
struct ExtensionsViewModel : ExtensionsViewModelT<ExtensionsViewModel>, ViewModelHelper<ExtensionsViewModel> | ||
{ | ||
public: | ||
ExtensionsViewModel(const Model::CascadiaSettings& settings); | ||
|
||
// Views | ||
Windows::Foundation::Collections::IVectorView<IInspectable> FragmentExtensions() const noexcept { return _fragmentExtensions.GetView(); } | ||
Windows::Foundation::Collections::IVectorView<IInspectable> ProfilesModified() const noexcept { return _profilesModified.GetView(); } | ||
Windows::Foundation::Collections::IVectorView<IInspectable> ProfilesAdded() const noexcept { return _profilesAdded.GetView(); } | ||
Windows::Foundation::Collections::IVectorView<IInspectable> ColorSchemesAdded() const noexcept { return _colorSchemesAdded.GetView(); } | ||
|
||
bool GetExtensionState(hstring extensionSource) const; | ||
void SetExtensionState(hstring extensionSource, bool enableExt); | ||
|
||
private: | ||
Model::CascadiaSettings _settings; | ||
Windows::Foundation::Collections::IVector<IInspectable> _fragmentExtensions; | ||
Windows::Foundation::Collections::IVector<IInspectable> _profilesModified; | ||
Windows::Foundation::Collections::IVector<IInspectable> _profilesAdded; | ||
Windows::Foundation::Collections::IVector<IInspectable> _colorSchemesAdded; | ||
|
||
Windows::Foundation::Collections::IVector<hstring> _DisabledProfileSources() const noexcept { return _settings.GlobalSettings().DisabledProfileSources(); } | ||
}; | ||
}; | ||
|
||
namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation | ||
{ | ||
BASIC_FACTORY(Extensions); | ||
BASIC_FACTORY(ExtensionsViewModel); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
namespace Microsoft.Terminal.Settings.Editor | ||
{ | ||
[default_interface] runtimeclass Extensions : Windows.UI.Xaml.Controls.Page | ||
{ | ||
Extensions(); | ||
ExtensionsViewModel ViewModel { get; }; | ||
} | ||
|
||
[default_interface] runtimeclass ExtensionsViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged | ||
{ | ||
ExtensionsViewModel(Microsoft.Terminal.Settings.Model.CascadiaSettings settings); | ||
|
||
// Views | ||
Windows.Foundation.Collections.IVectorView<IInspectable> FragmentExtensions { get; }; | ||
Windows.Foundation.Collections.IVectorView<IInspectable> ProfilesModified { get; }; | ||
Windows.Foundation.Collections.IVectorView<IInspectable> ProfilesAdded { get; }; | ||
Windows.Foundation.Collections.IVectorView<IInspectable> ColorSchemesAdded { get; }; | ||
|
||
// Methods | ||
Boolean GetExtensionState(String extensionSource); | ||
void SetExtensionState(String extensionSource, Boolean enableExt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<!-- | ||
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under | ||
the MIT License. See LICENSE in the project root for license information. | ||
--> | ||
<Page x:Class="Microsoft.Terminal.Settings.Editor.Extensions" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="using:Microsoft.Terminal.Settings.Editor" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:model="using:Microsoft.Terminal.Settings.Model" | ||
xmlns:mtu="using:Microsoft.Terminal.UI" | ||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls" | ||
mc:Ignorable="d"> | ||
|
||
<Page.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="CommonResources.xaml" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Page.Resources> | ||
|
||
<StackPanel Style="{StaticResource SettingsStackStyle}" | ||
Spacing="20"> | ||
<StackPanel> | ||
<!-- Grouping: Active Extensions --> | ||
<TextBlock x:Uid="Globals_ActiveExtensionsHeader" | ||
Style="{StaticResource TextBlockSubHeaderStyle}" /> | ||
<ItemsControl ItemsSource="{x:Bind ViewModel.FragmentExtensions, Mode=OneWay}"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate x:DataType="model:FragmentSettings"> | ||
<local:SettingContainer Header="{x:Bind Source}"> | ||
<ToggleSwitch Toggled="ExtensionToggled" | ||
Loaded="ExtensionLoaded" | ||
Tag="{x:Bind Source}" | ||
Style="{StaticResource ToggleSwitchInExpanderStyle}" /> | ||
</local:SettingContainer> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
|
||
</StackPanel> | ||
|
||
<StackPanel> | ||
<!-- Grouping: Modified Profiles --> | ||
<TextBlock x:Uid="Globals_ModifiedProfilesHeader" | ||
Style="{StaticResource TextBlockSubHeaderStyle}" /> | ||
<TextBlock FontStyle="Italic">Coming soon!</TextBlock> | ||
|
||
<!--TODO CARLOS: ItemsRepeater of Expanders--> | ||
|
||
</StackPanel> | ||
|
||
<StackPanel> | ||
<!-- Grouping: Added Profiles --> | ||
<TextBlock x:Uid="Globals_AddedProfilesHeader" | ||
Style="{StaticResource TextBlockSubHeaderStyle}" /> | ||
<TextBlock FontStyle="Italic">Coming soon!</TextBlock> | ||
|
||
<!--TODO CARLOS: ItemsRepeater of Expanders--> | ||
|
||
</StackPanel> | ||
|
||
<StackPanel> | ||
<!-- Grouping: Added Color Schemes --> | ||
<TextBlock x:Uid="Globals_AddedColorSchemesHeader" | ||
Style="{StaticResource TextBlockSubHeaderStyle}" /> | ||
<TextBlock FontStyle="Italic">Coming soon!</TextBlock> | ||
|
||
<!--TODO CARLOS: ItemsRepeater of Expanders--> | ||
|
||
</StackPanel> | ||
</StackPanel> | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.