From d447166863504e4cff4e8fa90db960409214b299 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 2 Feb 2022 11:41:29 -0800 Subject: [PATCH 01/37] invoking rightmost breadcrumb does nothing --- .../TerminalSettingsEditor/MainPage.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index 3d5f00f1807..e456afdc277 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -476,15 +476,18 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void MainPage::BreadcrumbBar_ItemClicked(Microsoft::UI::Xaml::Controls::BreadcrumbBar const& /*sender*/, Microsoft::UI::Xaml::Controls::BreadcrumbBarItemClickedEventArgs const& args) { - const auto tag = args.Item().as()->Tag(); - const auto subPage = args.Item().as()->SubPage(); - if (const auto profileViewModel = tag.try_as()) + if (gsl::narrow_cast(args.Index()) < (_breadcrumbs.Size() - 1)) { - _Navigate(*profileViewModel, subPage); - } - else - { - _Navigate(tag.as(), subPage); + const auto tag = args.Item().as()->Tag(); + const auto subPage = args.Item().as()->SubPage(); + if (const auto profileViewModel = tag.try_as()) + { + _Navigate(*profileViewModel, subPage); + } + else + { + _Navigate(tag.as(), subPage); + } } } From 5430de6e098d330e35538bfa0902632bccafe47e Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 4 Feb 2022 10:13:20 -0800 Subject: [PATCH 02/37] partway through color scheme MVVM --- .../ColorSchemeViewModel.cpp | 44 +++++++++++++++++++ .../ColorSchemeViewModel.h | 33 ++++++++++++++ .../ColorSchemeViewModel.idl | 22 ++++++++++ .../TerminalSettingsEditor/ColorSchemes.cpp | 1 + .../TerminalSettingsEditor/ColorSchemes.h | 3 ++ .../TerminalSettingsEditor/ColorSchemes.idl | 6 ++- .../TerminalSettingsEditor/ColorSchemes.xaml | 36 +++++++++++++++ .../TerminalSettingsEditor/MainPage.cpp | 33 +++++++++----- .../TerminalSettingsEditor/MainPage.h | 2 + ...Microsoft.Terminal.Settings.Editor.vcxproj | 9 ++++ ...t.Terminal.Settings.Editor.vcxproj.filters | 1 + .../Resources/en-US/Resources.resw | 16 +++++++ 12 files changed, 194 insertions(+), 12 deletions(-) create mode 100644 src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp create mode 100644 src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h create mode 100644 src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp new file mode 100644 index 00000000000..1c108e9edae --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" +#include "ColorSchemeViewModel.h" +#include "ColorSchemeViewModel.g.cpp" + +#include +#include "..\WinRTUtils\inc\Utils.h" + +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation +{ + static constexpr uint8_t ColorTableDivider{ 8 }; + static constexpr uint8_t ColorTableSize{ 16 }; + + static constexpr std::wstring_view ForegroundColorTag{ L"Foreground" }; + static constexpr std::wstring_view BackgroundColorTag{ L"Background" }; + static constexpr std::wstring_view CursorColorTag{ L"CursorColor" }; + static constexpr std::wstring_view SelectionBackgroundColorTag{ L"SelectionBackground" }; + + ColorSchemeViewModel::ColorSchemeViewModel(Model::ColorScheme scheme) : + _CurrentNonBrightColorTable{ single_threaded_observable_vector() }, + _CurrentBrightColorTable { single_threaded_observable_vector() } + { + for (uint8_t i = 0; i < ColorTableSize; ++i) + { + til::color currentColor{ scheme.Table()[i] }; + const auto& entry{ winrt::make(i, currentColor) }; + if (i < ColorTableDivider) + { + _CurrentNonBrightColorTable.Append(entry); + } + else + { + _CurrentBrightColorTable.Append(entry); + } + } + + _CurrentForegroundColor = winrt::make(ForegroundColorTag, til::color(scheme.Foreground())); + _CurrentBackgroundColor = winrt::make(BackgroundColorTag, til::color(scheme.Background())); + _CurrentCursorColor = winrt::make(CursorColorTag, til::color(scheme.CursorColor())); + _CurrentSelectionBackgroundColor = winrt::make(SelectionBackgroundColorTag, til::color(scheme.SelectionBackground())); + } +} diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h new file mode 100644 index 00000000000..e34771c71d3 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +#include "ColorSchemeViewModel.g.h" +#include "Utils.h" +#include "ViewModelHelpers.h" +#include "ColorSchemes.h" + +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation +{ + struct ColorSchemeViewModel : ColorSchemeViewModelT, ViewModelHelper + { + public: + ColorSchemeViewModel(Model::ColorScheme scheme); + + WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); + + WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentNonBrightColorTable, nullptr); + WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentBrightColorTable, nullptr); + + WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentForegroundColor, _PropertyChangedHandlers, nullptr); + WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentBackgroundColor, _PropertyChangedHandlers, nullptr); + WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentCursorColor, _PropertyChangedHandlers, nullptr); + WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentSelectionBackgroundColor, _PropertyChangedHandlers, nullptr); + }; +}; + +namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation +{ + BASIC_FACTORY(ColorSchemeViewModel); +} diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl new file mode 100644 index 00000000000..93b3e0eff8b --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import "ColorSchemes.idl"; + +namespace Microsoft.Terminal.Settings.Editor +{ + runtimeclass ColorSchemeViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged + { + ColorSchemeViewModel(Microsoft.Terminal.Settings.Model.ColorScheme scheme); + + // Terminal Colors + Windows.Foundation.Collections.IVector CurrentNonBrightColorTable; + Windows.Foundation.Collections.IVector CurrentBrightColorTable; + + // System Colors + ColorTableEntry CurrentForegroundColor; + ColorTableEntry CurrentBackgroundColor; + ColorTableEntry CurrentCursorColor; + ColorTableEntry CurrentSelectionBackgroundColor; + } +} diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index 5e090848e20..005101b5fe2 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -227,6 +227,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation MUX::Controls::ColorChangedEventArgs const& args) { const til::color newColor{ args.NewColor() }; + if (const auto& picker{ sender.try_as() }) { if (const auto& tag{ picker.Tag() }) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h index d6837272915..6a4738ca18c 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h @@ -6,6 +6,7 @@ #include "ColorTableEntry.g.h" #include "ColorSchemes.g.h" #include "ColorSchemesPageNavigationState.g.h" +#include "ColorSchemeViewModel.h" #include "Utils.h" namespace winrt::Microsoft::Terminal::Settings::Editor::implementation @@ -18,6 +19,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_PROPERTY(Model::CascadiaSettings, Settings, nullptr); WINRT_PROPERTY(winrt::hstring, LastSelectedScheme, L""); + WINRT_PROPERTY(Windows::Foundation::Collections::IVector, AllColorSchemes, nullptr); }; struct ColorSchemes : public HasScrollViewer, ColorSchemesT @@ -43,6 +45,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentNonBrightColorTable, nullptr); WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentBrightColorTable, nullptr); WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, ColorSchemeList, nullptr); + WINRT_PROPERTY(Editor::ColorSchemeViewModel, ColorScheme, nullptr); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); WINRT_OBSERVABLE_PROPERTY(bool, IsRenaming, _PropertyChangedHandlers, nullptr); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl index c446502ce4b..7ab829803d8 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +import "ColorSchemeViewModel.idl"; + namespace Microsoft.Terminal.Settings.Editor { @@ -8,6 +10,7 @@ namespace Microsoft.Terminal.Settings.Editor { Microsoft.Terminal.Settings.Model.CascadiaSettings Settings; String LastSelectedScheme; + Windows.Foundation.Collections.IVector AllColorSchemes; }; [default_interface] runtimeclass ColorSchemes : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged @@ -18,6 +21,8 @@ namespace Microsoft.Terminal.Settings.Editor Boolean CanDeleteCurrentScheme { get; }; Boolean IsRenaming { get; }; + ColorSchemeViewModel ColorScheme { get; }; + // Terminal Colors Windows.Foundation.Collections.IVector CurrentNonBrightColorTable { get; }; Windows.Foundation.Collections.IVector CurrentBrightColorTable { get; }; @@ -28,7 +33,6 @@ namespace Microsoft.Terminal.Settings.Editor ColorTableEntry CurrentCursorColor; ColorTableEntry CurrentSelectionBackgroundColor; - Windows.Foundation.Collections.IObservableVector ColorSchemeList { get; }; } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index 4629cad1e0a..9c88d072322 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -96,6 +96,42 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index e456afdc277..e384f71a881 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -55,6 +55,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _InitializeProfilesList(); _colorSchemesNavState = winrt::make(_settingsClone); + _colorSchemesNavState.AllColorSchemes(_MakeColorSchemeVMsHelper(_settingsClone)); Automation::AutomationProperties::SetHelpText(SaveButton(), RS_(L"Settings_SaveSettingsButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip")); Automation::AutomationProperties::SetHelpText(ResetButton(), RS_(L"Settings_ResetSettingsButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip")); @@ -443,6 +444,19 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } + Windows::Foundation::Collections::IVector MainPage::_MakeColorSchemeVMsHelper(const Model::CascadiaSettings& settings) + { + Windows::Foundation::Collections::IVector AllColorSchemes{ single_threaded_observable_vector() }; + const auto& colorSchemeMap{ settings.GlobalSettings().ColorSchemes() }; + for (const auto& pair : colorSchemeMap) + { + const auto viewModel = Editor::ColorSchemeViewModel(pair.Value()); + AllColorSchemes.Append(viewModel); + } + return AllColorSchemes; + } + + void MainPage::OpenJsonTapped(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::TappedRoutedEventArgs const& /*args*/) { const CoreWindow window = CoreWindow::GetForCurrentThread(); @@ -476,18 +490,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void MainPage::BreadcrumbBar_ItemClicked(Microsoft::UI::Xaml::Controls::BreadcrumbBar const& /*sender*/, Microsoft::UI::Xaml::Controls::BreadcrumbBarItemClickedEventArgs const& args) { - if (gsl::narrow_cast(args.Index()) < (_breadcrumbs.Size() - 1)) + const auto tag = args.Item().as()->Tag(); + const auto subPage = args.Item().as()->SubPage(); + if (const auto profileViewModel = tag.try_as()) { - const auto tag = args.Item().as()->Tag(); - const auto subPage = args.Item().as()->SubPage(); - if (const auto profileViewModel = tag.try_as()) - { - _Navigate(*profileViewModel, subPage); - } - else - { - _Navigate(tag.as(), subPage); - } + _Navigate(*profileViewModel, subPage); + } + else + { + _Navigate(tag.as(), subPage); } } diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.h b/src/cascadia/TerminalSettingsEditor/MainPage.h index 2fea7ef72ed..d85c55ed73f 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.h +++ b/src/cascadia/TerminalSettingsEditor/MainPage.h @@ -63,6 +63,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void _Navigate(hstring clickedItemTag, BreadcrumbSubPage subPage); void _Navigate(const Editor::ProfileViewModel& profile, BreadcrumbSubPage subPage); + Windows::Foundation::Collections::IVector _MakeColorSchemeVMsHelper(const Model::CascadiaSettings& settings); + winrt::Microsoft::Terminal::Settings::Editor::ColorSchemesPageNavigationState _colorSchemesNavState{ nullptr }; Windows::UI::Xaml::Data::INotifyPropertyChanged::PropertyChanged_revoker _profileViewModelChangedRevoker; diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj index e508129eb35..2d22a138102 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj @@ -77,6 +77,10 @@ ProfileViewModel.idl Code + + ColorSchemeViewModel.idl + Code + Profiles_Base.xaml Code @@ -189,6 +193,10 @@ ProfileViewModel.idl Code + + ColorSchemeViewModel.idl + Code + Profiles_Base.xaml Code @@ -259,6 +267,7 @@ Code + Profiles_Base.xaml Code diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters index b7d94c4b700..0926568ce21 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters @@ -18,6 +18,7 @@ + Converters diff --git a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw index 0413a31b4b5..a80b1fa69ee 100644 --- a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw @@ -1246,6 +1246,22 @@ Both HTML and RTF An option to choose from for the "copy formatting" setting. Store both HTML and RTF data. + + Color scheme + Header for a control to select the color scheme to edit. + + + Add a new color scheme + Header for a control to add a new color scheme. + + + Customize selected color scheme + Header for a group of expanders that allow the user to edit the color scheme. + + + Rename color scheme + Header for a control to rename the currently selected color scheme. + Please choose a different name. An error message that appears when the user attempts to rename a color scheme to something invalid. This appears as the subtitle and provides guidance to fix the issue. From 447c1be9f20ba851d35999fe6c716a558fce0912 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 4 Feb 2022 13:07:32 -0800 Subject: [PATCH 03/37] main page now holds vector of csvms --- src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp | 1 + src/cascadia/TerminalSettingsEditor/ColorSchemes.h | 1 + src/cascadia/TerminalSettingsEditor/MainPage.cpp | 5 ++++- src/cascadia/TerminalSettingsEditor/MainPage.h | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index 005101b5fe2..f6452be6d68 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -92,6 +92,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void ColorSchemes::OnNavigatedTo(const NavigationEventArgs& e) { _State = e.Parameter().as(); + _AllColorSchemes = _State.AllColorSchemes(); _UpdateColorSchemeList(); // Initialize our color table view model with 16 dummy colors diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h index 6a4738ca18c..0193ac377b9 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h @@ -46,6 +46,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentBrightColorTable, nullptr); WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, ColorSchemeList, nullptr); WINRT_PROPERTY(Editor::ColorSchemeViewModel, ColorScheme, nullptr); + WINRT_PROPERTY(Windows::Foundation::Collections::IVector, AllColorSchemes, nullptr); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); WINRT_OBSERVABLE_PROPERTY(bool, IsRenaming, _PropertyChangedHandlers, nullptr); diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index e384f71a881..f029e101139 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -55,7 +55,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _InitializeProfilesList(); _colorSchemesNavState = winrt::make(_settingsClone); - _colorSchemesNavState.AllColorSchemes(_MakeColorSchemeVMsHelper(_settingsClone)); + _AllColorSchemes = _MakeColorSchemeVMsHelper(_settingsClone); + _colorSchemesNavState.AllColorSchemes(_AllColorSchemes); Automation::AutomationProperties::SetHelpText(SaveButton(), RS_(L"Settings_SaveSettingsButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip")); Automation::AutomationProperties::SetHelpText(ResetButton(), RS_(L"Settings_ResetSettingsButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip")); @@ -128,6 +129,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _InitializeProfilesList(); // Update the Nav State with the new version of the settings _colorSchemesNavState.Settings(_settingsClone); + _AllColorSchemes = _MakeColorSchemeVMsHelper(_settingsClone); + _colorSchemesNavState.AllColorSchemes(_AllColorSchemes); // We'll update the profile in the _profilesNavState whenever we actually navigate to one // now that the menuItems are repopulated, diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.h b/src/cascadia/TerminalSettingsEditor/MainPage.h index d85c55ed73f..6711ff33a01 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.h +++ b/src/cascadia/TerminalSettingsEditor/MainPage.h @@ -46,6 +46,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation private: Windows::Foundation::Collections::IObservableVector _breadcrumbs; + Windows::Foundation::Collections::IVector _AllColorSchemes; Model::CascadiaSettings _settingsSource; Model::CascadiaSettings _settingsClone; From 93b8ecbc0ca077ae43c0476c0e8699c451077a27 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Tue, 10 May 2022 16:13:12 -0700 Subject: [PATCH 04/37] need to update event handlers --- .../ColorSchemeViewModel.cpp | 54 +++++++++++++++- .../ColorSchemeViewModel.h | 24 ++++++- .../ColorSchemeViewModel.idl | 9 +++ .../TerminalSettingsEditor/ColorSchemes.cpp | 64 ++++++++++--------- .../TerminalSettingsEditor/ColorSchemes.h | 17 +---- .../TerminalSettingsEditor/ColorSchemes.idl | 10 +-- .../TerminalSettingsEditor/ColorSchemes.xaml | 33 +++++----- .../TerminalSettingsEditor/MainPage.cpp | 4 +- .../TerminalSettingsEditor/MainPage.h | 4 +- 9 files changed, 145 insertions(+), 74 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp index 1c108e9edae..156cc72eba3 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp @@ -18,10 +18,32 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation static constexpr std::wstring_view CursorColorTag{ L"CursorColor" }; static constexpr std::wstring_view SelectionBackgroundColorTag{ L"SelectionBackground" }; - ColorSchemeViewModel::ColorSchemeViewModel(Model::ColorScheme scheme) : + static const std::array TableColorNames = { + RS_(L"ColorScheme_Black/Header"), + RS_(L"ColorScheme_Red/Header"), + RS_(L"ColorScheme_Green/Header"), + RS_(L"ColorScheme_Yellow/Header"), + RS_(L"ColorScheme_Blue/Header"), + RS_(L"ColorScheme_Purple/Header"), + RS_(L"ColorScheme_Cyan/Header"), + RS_(L"ColorScheme_White/Header"), + RS_(L"ColorScheme_BrightBlack/Header"), + RS_(L"ColorScheme_BrightRed/Header"), + RS_(L"ColorScheme_BrightGreen/Header"), + RS_(L"ColorScheme_BrightYellow/Header"), + RS_(L"ColorScheme_BrightBlue/Header"), + RS_(L"ColorScheme_BrightPurple/Header"), + RS_(L"ColorScheme_BrightCyan/Header"), + RS_(L"ColorScheme_BrightWhite/Header") + }; + + ColorSchemeViewModel::ColorSchemeViewModel(const Model::ColorScheme scheme) : + _scheme{ scheme }, _CurrentNonBrightColorTable{ single_threaded_observable_vector() }, _CurrentBrightColorTable { single_threaded_observable_vector() } { + _Name = scheme.Name(); + for (uint8_t i = 0; i < ColorTableSize; ++i) { til::color currentColor{ scheme.Table()[i] }; @@ -40,5 +62,35 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _CurrentBackgroundColor = winrt::make(BackgroundColorTag, til::color(scheme.Background())); _CurrentCursorColor = winrt::make(CursorColorTag, til::color(scheme.CursorColor())); _CurrentSelectionBackgroundColor = winrt::make(SelectionBackgroundColorTag, til::color(scheme.SelectionBackground())); + + _CurrentForegroundColor.PropertyChanged([this](const IInspectable& /*sender*/, const PropertyChangedEventArgs& /*args*/) { + // FINISH THIS EVENT HANDLER SEE IF IT WORKS + // NEED TO ACTUALLY UPDATE THE SCHEME + }); + } + + ColorTableEntry::ColorTableEntry(uint8_t index, Windows::UI::Color color) + { + Name(TableColorNames[index]); + Tag(winrt::box_value(index)); + Color(color); + } + + ColorTableEntry::ColorTableEntry(std::wstring_view tag, Windows::UI::Color color) + { + Name(LocalizedNameForEnumName(L"ColorScheme_", tag, L"Text")); + Tag(winrt::box_value(tag)); + Color(color); + } + + Windows::UI::Color ColorTableEntry::Color() + { + return _color; + } + + void ColorTableEntry::Color(Windows::UI::Color newColor) + { + _color = newColor; + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Color" }); } } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h index e34771c71d3..8234602780f 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h @@ -13,10 +13,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation struct ColorSchemeViewModel : ColorSchemeViewModelT, ViewModelHelper { public: - ColorSchemeViewModel(Model::ColorScheme scheme); + ColorSchemeViewModel(const Model::ColorScheme scheme); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); + WINRT_PROPERTY(winrt::hstring, Name); + WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentNonBrightColorTable, nullptr); WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentBrightColorTable, nullptr); @@ -24,6 +26,26 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentBackgroundColor, _PropertyChangedHandlers, nullptr); WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentCursorColor, _PropertyChangedHandlers, nullptr); WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentSelectionBackgroundColor, _PropertyChangedHandlers, nullptr); + + private: + Model::ColorScheme _scheme; + }; + + struct ColorTableEntry : ColorTableEntryT + { + public: + ColorTableEntry(uint8_t index, Windows::UI::Color color); + ColorTableEntry(std::wstring_view tag, Windows::UI::Color color); + + Windows::UI::Color Color(); + void Color(Windows::UI::Color newColor); + + WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); + WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Name, _PropertyChangedHandlers); + WINRT_OBSERVABLE_PROPERTY(IInspectable, Tag, _PropertyChangedHandlers); + + private: + Windows::UI::Color _color; }; }; diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl index 93b3e0eff8b..7a2058efcaf 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl @@ -9,6 +9,8 @@ namespace Microsoft.Terminal.Settings.Editor { ColorSchemeViewModel(Microsoft.Terminal.Settings.Model.ColorScheme scheme); + String Name; + // Terminal Colors Windows.Foundation.Collections.IVector CurrentNonBrightColorTable; Windows.Foundation.Collections.IVector CurrentBrightColorTable; @@ -19,4 +21,11 @@ namespace Microsoft.Terminal.Settings.Editor ColorTableEntry CurrentCursorColor; ColorTableEntry CurrentSelectionBackgroundColor; } + + [default_interface] runtimeclass ColorTableEntry : Windows.UI.Xaml.Data.INotifyPropertyChanged + { + String Name { get; }; + IInspectable Tag; + Windows.UI.Color Color; + } } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index 0b542fc443a..21c58cefc50 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -112,10 +112,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _CurrentBrightColorTable.Append(entry); } } - _CurrentForegroundColor = winrt::make(ForegroundColorTag, Windows::UI::Color{ 0, 0, 0, 0 }); - _CurrentBackgroundColor = winrt::make(BackgroundColorTag, Windows::UI::Color{ 0, 0, 0, 0 }); - _CurrentCursorColor = winrt::make(CursorColorTag, Windows::UI::Color{ 0, 0, 0, 0 }); - _CurrentSelectionBackgroundColor = winrt::make(SelectionBackgroundColorTag, Windows::UI::Color{ 0, 0, 0, 0 }); // Try to look up the scheme that was navigated to. If we find it, immediately select it. const std::wstring lastNameFromNav{ _State.LastSelectedScheme() }; @@ -128,6 +124,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation auto scheme = *it; ColorSchemeComboBox().SelectedItem(scheme); } + else + { + ColorScheme(_AllColorSchemes.GetAt(0)); + } // populate color table grid const auto colorLabelStyle{ Resources().Lookup(winrt::box_value(L"ColorLabelStyle")).as() }; @@ -197,6 +197,32 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation IsRenaming(false); } + void ColorSchemes::ColorSchemeSelectionChanged2(const IInspectable& /*sender*/, + const SelectionChangedEventArgs& args) + { + // Update the color scheme this page is modifying + const auto colorScheme{ args.AddedItems().GetAt(0).try_as() }; + ColorScheme(*colorScheme); + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"ColorScheme" }); + //_UpdateColorTable(colorScheme); + + //_State.LastSelectedScheme(colorScheme.Name()); + + //// Set the text disclaimer for the text box + //hstring disclaimer{}; + //const std::wstring schemeName{ colorScheme.Name() }; + //if (std::find(std::begin(InBoxSchemes), std::end(InBoxSchemes), schemeName) != std::end(InBoxSchemes)) + //{ + // // load disclaimer for in-box profiles + // disclaimer = RS_(L"ColorScheme_DeleteButtonDisclaimerInBox"); + //} + //DeleteButtonDisclaimer().Text(disclaimer); + + //// Update the state of the page + //_PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"CanDeleteCurrentScheme" }); + //IsRenaming(false); + } + // Function Description: // - Updates the list of all color schemes available to choose from. // Arguments: @@ -249,23 +275,19 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { if (stringTag == ForegroundColorTag) { - CurrentColorScheme().Foreground(newColor); - _CurrentForegroundColor.Color(newColor); + ColorScheme().CurrentForegroundColor().Color(newColor); } else if (stringTag == BackgroundColorTag) { - CurrentColorScheme().Background(newColor); - _CurrentBackgroundColor.Color(newColor); + ColorScheme().CurrentBackgroundColor().Color(newColor); } else if (stringTag == CursorColorTag) { - CurrentColorScheme().CursorColor(newColor); - _CurrentCursorColor.Color(newColor); + ColorScheme().CurrentCursorColor().Color(newColor); } else if (stringTag == SelectionBackgroundColorTag) { - CurrentColorScheme().SelectionBackground(newColor); - _CurrentSelectionBackgroundColor.Color(newColor); + ColorScheme().CurrentSelectionBackgroundColor().Color(newColor); } } } @@ -431,23 +453,5 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _CurrentBrightColorTable.GetAt(i - ColorTableDivider).Color(currentColor); } } - _CurrentForegroundColor.Color(til::color{ colorScheme.Foreground() }); - _CurrentBackgroundColor.Color(til::color{ colorScheme.Background() }); - _CurrentCursorColor.Color(til::color{ colorScheme.CursorColor() }); - _CurrentSelectionBackgroundColor.Color(til::color{ colorScheme.SelectionBackground() }); - } - - ColorTableEntry::ColorTableEntry(uint8_t index, Windows::UI::Color color) - { - Name(TableColorNames[index]); - Tag(winrt::box_value(index)); - Color(color); - } - - ColorTableEntry::ColorTableEntry(std::wstring_view tag, Windows::UI::Color color) - { - Name(LocalizedNameForEnumName(L"ColorScheme_", tag, L"Text")); - Tag(winrt::box_value(tag)); - Color(color); } } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h index 3826ef94b81..2ff257d6d6a 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h @@ -19,7 +19,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_PROPERTY(Model::CascadiaSettings, Settings, nullptr); WINRT_PROPERTY(winrt::hstring, LastSelectedScheme, L""); - WINRT_PROPERTY(Windows::Foundation::Collections::IVector, AllColorSchemes, nullptr); + WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, AllColorSchemes, nullptr); }; struct ColorSchemes : public HasScrollViewer, ColorSchemesT @@ -29,6 +29,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void OnNavigatedTo(const winrt::Windows::UI::Xaml::Navigation::NavigationEventArgs& e); void ColorSchemeSelectionChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args); + void ColorSchemeSelectionChanged2(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args); void ColorPickerChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Microsoft::UI::Xaml::Controls::ColorChangedEventArgs& args); void AddNew_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); @@ -46,7 +47,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentBrightColorTable, nullptr); WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, ColorSchemeList, nullptr); WINRT_PROPERTY(Editor::ColorSchemeViewModel, ColorScheme, nullptr); - WINRT_PROPERTY(Windows::Foundation::Collections::IVector, AllColorSchemes, nullptr); + WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, AllColorSchemes, nullptr); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); WINRT_OBSERVABLE_PROPERTY(bool, IsRenaming, _PropertyChangedHandlers, nullptr); @@ -60,18 +61,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void _UpdateColorSchemeList(); void _RenameCurrentScheme(hstring newName); }; - - struct ColorTableEntry : ColorTableEntryT - { - public: - ColorTableEntry(uint8_t index, Windows::UI::Color color); - ColorTableEntry(std::wstring_view tag, Windows::UI::Color color); - - WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); - WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Name, _PropertyChangedHandlers); - WINRT_OBSERVABLE_PROPERTY(IInspectable, Tag, _PropertyChangedHandlers); - WINRT_OBSERVABLE_PROPERTY(Windows::UI::Color, Color, _PropertyChangedHandlers); - }; } namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl index 7ab829803d8..16232256c8d 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl @@ -10,7 +10,7 @@ namespace Microsoft.Terminal.Settings.Editor { Microsoft.Terminal.Settings.Model.CascadiaSettings Settings; String LastSelectedScheme; - Windows.Foundation.Collections.IVector AllColorSchemes; + Windows.Foundation.Collections.IObservableVector AllColorSchemes; }; [default_interface] runtimeclass ColorSchemes : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged @@ -34,12 +34,6 @@ namespace Microsoft.Terminal.Settings.Editor ColorTableEntry CurrentSelectionBackgroundColor; Windows.Foundation.Collections.IObservableVector ColorSchemeList { get; }; - } - - [default_interface] runtimeclass ColorTableEntry : Windows.UI.Xaml.Data.INotifyPropertyChanged - { - String Name { get; }; - IInspectable Tag; - Windows.UI.Color Color; + Windows.Foundation.Collections.IObservableVector AllColorSchemes { get; }; } } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index 8472bea3489..859e1cb1834 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -78,15 +78,20 @@ + + + - + @@ -115,10 +120,6 @@ - - @@ -127,12 +128,12 @@ Visibility="{x:Bind local:Converters.InvertedBooleanToVisibility(IsRenaming), Mode=OneWay}"> + ItemsSource="{x:Bind AllColorSchemes, Mode=OneWay}" + SelectedIndex="0" + SelectionChanged="ColorSchemeSelectionChanged2" + Style="{StaticResource ComboBoxSettingStyle}"> - + @@ -257,7 +258,7 @@ @@ -269,7 +270,7 @@ @@ -281,7 +282,7 @@ @@ -293,7 +294,7 @@ diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index 2a53eb03d6e..8cab0e08e98 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -448,9 +448,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } - Windows::Foundation::Collections::IVector MainPage::_MakeColorSchemeVMsHelper(const Model::CascadiaSettings& settings) + Windows::Foundation::Collections::IObservableVector MainPage::_MakeColorSchemeVMsHelper(const Model::CascadiaSettings& settings) { - Windows::Foundation::Collections::IVector AllColorSchemes{ single_threaded_observable_vector() }; + Windows::Foundation::Collections::IObservableVector AllColorSchemes{ single_threaded_observable_vector() }; const auto& colorSchemeMap{ settings.GlobalSettings().ColorSchemes() }; for (const auto& pair : colorSchemeMap) { diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.h b/src/cascadia/TerminalSettingsEditor/MainPage.h index d681e9ef7ee..e1e705648c0 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.h +++ b/src/cascadia/TerminalSettingsEditor/MainPage.h @@ -46,7 +46,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation private: Windows::Foundation::Collections::IObservableVector _breadcrumbs; - Windows::Foundation::Collections::IVector _AllColorSchemes; + Windows::Foundation::Collections::IObservableVector _AllColorSchemes; Model::CascadiaSettings _settingsSource; Model::CascadiaSettings _settingsClone; @@ -64,7 +64,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void _Navigate(hstring clickedItemTag, BreadcrumbSubPage subPage); void _Navigate(const Editor::ProfileViewModel& profile, BreadcrumbSubPage subPage, const bool focusDeleteButton = false); - Windows::Foundation::Collections::IVector _MakeColorSchemeVMsHelper(const Model::CascadiaSettings& settings); + Windows::Foundation::Collections::IObservableVector _MakeColorSchemeVMsHelper(const Model::CascadiaSettings& settings); winrt::Microsoft::Terminal::Settings::Editor::ColorSchemesPageNavigationState _colorSchemesNavState{ nullptr }; From 987002ee1e8ce7dcd16d2c9efffdc7db56c93c08 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 11 May 2022 14:32:51 -0700 Subject: [PATCH 05/37] propagate changes to scheme --- .../ColorSchemeViewModel.cpp | 45 +++++++++++++++++-- .../TerminalSettingsEditor/ColorSchemes.cpp | 9 ++-- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp index 156cc72eba3..8088a9ef9ce 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp @@ -44,10 +44,47 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { _Name = scheme.Name(); + const auto colorEntryChangedHandler = [&](const IInspectable& sender, const PropertyChangedEventArgs& args) { + if (const auto entry{ sender.try_as() }) + { + if (args.PropertyName() == L"Color") + { + const til::color newColor{ entry->Color() }; + if (const auto& tag{ entry->Tag() }) + { + if (const auto index{ tag.try_as() }) + { + _scheme.SetColorTableEntry(*index, newColor); + } + else if (const auto stringTag{ tag.try_as() }) + { + if (stringTag == ForegroundColorTag) + { + _scheme.Foreground(newColor); + } + else if (stringTag == BackgroundColorTag) + { + _scheme.Background(newColor); + } + else if (stringTag == CursorColorTag) + { + _scheme.CursorColor(newColor); + } + else if (stringTag == SelectionBackgroundColorTag) + { + _scheme.SelectionBackground(newColor); + } + } + } + } + } + }; + for (uint8_t i = 0; i < ColorTableSize; ++i) { til::color currentColor{ scheme.Table()[i] }; const auto& entry{ winrt::make(i, currentColor) }; + entry.PropertyChanged(colorEntryChangedHandler); if (i < ColorTableDivider) { _CurrentNonBrightColorTable.Append(entry); @@ -63,10 +100,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _CurrentCursorColor = winrt::make(CursorColorTag, til::color(scheme.CursorColor())); _CurrentSelectionBackgroundColor = winrt::make(SelectionBackgroundColorTag, til::color(scheme.SelectionBackground())); - _CurrentForegroundColor.PropertyChanged([this](const IInspectable& /*sender*/, const PropertyChangedEventArgs& /*args*/) { - // FINISH THIS EVENT HANDLER SEE IF IT WORKS - // NEED TO ACTUALLY UPDATE THE SCHEME - }); + _CurrentForegroundColor.PropertyChanged(colorEntryChangedHandler); + _CurrentBackgroundColor.PropertyChanged(colorEntryChangedHandler); + _CurrentCursorColor.PropertyChanged(colorEntryChangedHandler); + _CurrentSelectionBackgroundColor.PropertyChanged(colorEntryChangedHandler); } ColorTableEntry::ColorTableEntry(uint8_t index, Windows::UI::Color color) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index 21c58cefc50..0489c409d38 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -158,10 +158,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation Grid::SetColumn(label, 0); // regular color - setupColorControl(_CurrentNonBrightColorTable.GetAt(row), row, 1); + setupColorControl(ColorScheme().CurrentNonBrightColorTable().GetAt(row), row, 1); // bright color - setupColorControl(_CurrentBrightColorTable.GetAt(row), row, 2); + setupColorControl(ColorScheme().CurrentBrightColorTable().GetAt(row), row, 2); } } @@ -261,14 +261,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { if (const auto index{ tag.try_as() }) { - CurrentColorScheme().SetColorTableEntry(*index, newColor); if (index < ColorTableDivider) { - _CurrentNonBrightColorTable.GetAt(*index).Color(newColor); + ColorScheme().CurrentNonBrightColorTable().GetAt(*index).Color(newColor); } else { - _CurrentBrightColorTable.GetAt(*index - ColorTableDivider).Color(newColor); + ColorScheme().CurrentBrightColorTable().GetAt(*index - ColorTableDivider).Color(newColor); } } else if (const auto stringTag{ tag.try_as() }) From f5fef4ee84d478946e66455caf470abf65630376 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 18 May 2022 09:50:31 -0700 Subject: [PATCH 06/37] color table colors ... --- .../ColorSchemeViewModel.cpp | 12 ++++++++ .../ColorSchemeViewModel.h | 2 ++ .../ColorSchemeViewModel.idl | 2 ++ .../TerminalSettingsEditor/ColorSchemes.cpp | 28 ++++--------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp index 8088a9ef9ce..63629d54fd0 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp @@ -106,6 +106,18 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _CurrentSelectionBackgroundColor.PropertyChanged(colorEntryChangedHandler); } + Editor::ColorTableEntry ColorSchemeViewModel::ColorEntryAt(uint8_t index) + { + if (index < ColorTableDivider) + { + return _CurrentNonBrightColorTable.GetAt(index); + } + else + { + return _CurrentBrightColorTable.GetAt(index - ColorTableDivider); + } + } + ColorTableEntry::ColorTableEntry(uint8_t index, Windows::UI::Color color) { Name(TableColorNames[index]); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h index 8234602780f..bfbcb29a99d 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h @@ -15,6 +15,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation public: ColorSchemeViewModel(const Model::ColorScheme scheme); + Editor::ColorTableEntry ColorEntryAt(uint8_t index); + WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); WINRT_PROPERTY(winrt::hstring, Name); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl index 7a2058efcaf..1d5fce137d2 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl @@ -15,6 +15,8 @@ namespace Microsoft.Terminal.Settings.Editor Windows.Foundation.Collections.IVector CurrentNonBrightColorTable; Windows.Foundation.Collections.IVector CurrentBrightColorTable; + ColorTableEntry ColorEntryAt(UInt8 Index); + // System Colors ColorTableEntry CurrentForegroundColor; ColorTableEntry CurrentBackgroundColor; diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index 0489c409d38..e300c4b7d3c 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -95,24 +95,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _AllColorSchemes = _State.AllColorSchemes(); _UpdateColorSchemeList(); - // Initialize our color table view model with 16 dummy colors - // so that on a ColorScheme selection change, we can loop through - // each ColorTableEntry and just change its color. Performing a - // clear and 16 appends doesn't seem to update the color pickers - // very accurately. - for (uint8_t i = 0; i < TableColorNames.size(); ++i) - { - const auto& entry{ winrt::make(i, Windows::UI::Color{ 0, 0, 0, 0 }) }; - if (i < ColorTableDivider) - { - _CurrentNonBrightColorTable.Append(entry); - } - else - { - _CurrentBrightColorTable.Append(entry); - } - } - // Try to look up the scheme that was navigated to. If we find it, immediately select it. const std::wstring lastNameFromNav{ _State.LastSelectedScheme() }; const auto it = std::find_if(begin(_ColorSchemeList), @@ -133,13 +115,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation const auto colorLabelStyle{ Resources().Lookup(winrt::box_value(L"ColorLabelStyle")).as() }; const auto colorControlStyle{ Resources().Lookup(winrt::box_value(L"ColorControlStyle")).as() }; const auto colorTableEntryTemplate{ Resources().Lookup(winrt::box_value(L"ColorTableEntryTemplate")).as() }; - auto setupColorControl = [colorTableEntryTemplate, colorControlStyle, colorTableGrid{ ColorTableGrid() }](const auto&& colorRef, const uint32_t& row, const uint32_t& col) { + auto setupColorControl = [colorTableEntryTemplate, colorControlStyle, colorTableGrid{ ColorTableGrid() }, this](const uint32_t& row, const uint32_t& col) { ContentControl colorControl{}; colorControl.ContentTemplate(colorTableEntryTemplate); colorControl.Style(colorControlStyle); Data::Binding binding{}; - binding.Source(colorRef); + const auto bindingIndex = col == 1 ? row : row + ColorTableDivider; + binding.Source(this->ColorScheme().ColorEntryAt(gsl::narrow_cast(bindingIndex))); + binding.Mode(Data::BindingMode::TwoWay); colorControl.SetBinding(ContentControl::ContentProperty(), binding); @@ -158,10 +142,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation Grid::SetColumn(label, 0); // regular color - setupColorControl(ColorScheme().CurrentNonBrightColorTable().GetAt(row), row, 1); + setupColorControl(row, 1); // bright color - setupColorControl(ColorScheme().CurrentBrightColorTable().GetAt(row), row, 2); + setupColorControl(row, 2); } } From 152974da5ecb7ec32b4fc3254458fcb600e02812 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 20 May 2022 11:11:41 -0700 Subject: [PATCH 07/37] delete works --- .../ColorSchemeViewModel.cpp | 8 +- .../ColorSchemeViewModel.h | 20 ++- .../ColorSchemeViewModel.idl | 10 +- .../TerminalSettingsEditor/ColorSchemes.cpp | 169 +++--------------- .../TerminalSettingsEditor/ColorSchemes.h | 12 +- .../TerminalSettingsEditor/ColorSchemes.idl | 11 -- .../TerminalSettingsEditor/ColorSchemes.xaml | 143 ++++++++++----- .../TerminalSettingsEditor/MainPage.cpp | 12 ++ .../TerminalSettingsEditor/MainPage.h | 1 + 9 files changed, 179 insertions(+), 207 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp index 63629d54fd0..c699a99d60f 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp @@ -106,7 +106,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _CurrentSelectionBackgroundColor.PropertyChanged(colorEntryChangedHandler); } - Editor::ColorTableEntry ColorSchemeViewModel::ColorEntryAt(uint8_t index) + Editor::ColorTableEntry ColorSchemeViewModel::ColorEntryAt(uint32_t index) { if (index < ColorTableDivider) { @@ -118,6 +118,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } + void ColorSchemeViewModel::DeleteScheme() + { + auto deleteSchemeArgs{ winrt::make_self(Name()) }; + _DeleteColorSchemeHandlers(*this, *deleteSchemeArgs); + } + ColorTableEntry::ColorTableEntry(uint8_t index, Windows::UI::Color color) { Name(TableColorNames[index]); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h index bfbcb29a99d..38083a2da8e 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h @@ -3,6 +3,7 @@ #pragma once +#include "DeleteColorSchemeEventArgs.g.h" #include "ColorSchemeViewModel.g.h" #include "Utils.h" #include "ViewModelHelpers.h" @@ -15,7 +16,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation public: ColorSchemeViewModel(const Model::ColorScheme scheme); - Editor::ColorTableEntry ColorEntryAt(uint8_t index); + Editor::ColorTableEntry ColorEntryAt(uint32_t index); + + void DeleteScheme(); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); @@ -29,6 +32,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentCursorColor, _PropertyChangedHandlers, nullptr); WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentSelectionBackgroundColor, _PropertyChangedHandlers, nullptr); + TYPED_EVENT(DeleteColorScheme, Editor::ColorSchemeViewModel, Editor::DeleteColorSchemeEventArgs); + private: Model::ColorScheme _scheme; }; @@ -49,6 +54,19 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation private: Windows::UI::Color _color; }; + + struct DeleteColorSchemeEventArgs : + public DeleteColorSchemeEventArgsT + { + public: + DeleteColorSchemeEventArgs(winrt::hstring schemeName) : + _SchemeName(schemeName) {} + + winrt::hstring SchemeName() const noexcept { return _SchemeName; } + + private: + winrt::hstring _SchemeName; + }; }; namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl index 1d5fce137d2..680264ef51f 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl @@ -5,6 +5,11 @@ import "ColorSchemes.idl"; namespace Microsoft.Terminal.Settings.Editor { + runtimeclass DeleteColorSchemeEventArgs + { + String SchemeName { get; }; + } + runtimeclass ColorSchemeViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged { ColorSchemeViewModel(Microsoft.Terminal.Settings.Model.ColorScheme scheme); @@ -15,13 +20,16 @@ namespace Microsoft.Terminal.Settings.Editor Windows.Foundation.Collections.IVector CurrentNonBrightColorTable; Windows.Foundation.Collections.IVector CurrentBrightColorTable; - ColorTableEntry ColorEntryAt(UInt8 Index); + ColorTableEntry ColorEntryAt(UInt32 Index); // System Colors ColorTableEntry CurrentForegroundColor; ColorTableEntry CurrentBackgroundColor; ColorTableEntry CurrentCursorColor; ColorTableEntry CurrentSelectionBackgroundColor; + + void DeleteScheme(); + event Windows.Foundation.TypedEventHandler DeleteColorScheme; } [default_interface] runtimeclass ColorTableEntry : Windows.UI.Xaml.Data.INotifyPropertyChanged diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index e300c4b7d3c..aa3be08aba8 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -66,10 +66,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation L"Tango Light" }; - ColorSchemes::ColorSchemes() : - _ColorSchemeList{ single_threaded_observable_vector() }, - _CurrentNonBrightColorTable{ single_threaded_observable_vector() }, - _CurrentBrightColorTable{ single_threaded_observable_vector() } + ColorSchemes::ColorSchemes() { InitializeComponent(); @@ -93,60 +90,22 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { _State = e.Parameter().as(); _AllColorSchemes = _State.AllColorSchemes(); - _UpdateColorSchemeList(); - + ColorScheme(_AllColorSchemes.GetAt(0)); // Try to look up the scheme that was navigated to. If we find it, immediately select it. - const std::wstring lastNameFromNav{ _State.LastSelectedScheme() }; - const auto it = std::find_if(begin(_ColorSchemeList), - end(_ColorSchemeList), - [&lastNameFromNav](const auto& scheme) { return scheme.Name() == lastNameFromNav; }); - - if (it != end(_ColorSchemeList)) - { - auto scheme = *it; - ColorSchemeComboBox().SelectedItem(scheme); - } - else - { - ColorScheme(_AllColorSchemes.GetAt(0)); - } + //const std::wstring lastNameFromNav{ _State.LastSelectedScheme() }; + //const auto it = std::find_if(begin(_ColorSchemeList), + // end(_ColorSchemeList), + // [&lastNameFromNav](const auto& scheme) { return scheme.Name() == lastNameFromNav; }); - // populate color table grid - const auto colorLabelStyle{ Resources().Lookup(winrt::box_value(L"ColorLabelStyle")).as() }; - const auto colorControlStyle{ Resources().Lookup(winrt::box_value(L"ColorControlStyle")).as() }; - const auto colorTableEntryTemplate{ Resources().Lookup(winrt::box_value(L"ColorTableEntryTemplate")).as() }; - auto setupColorControl = [colorTableEntryTemplate, colorControlStyle, colorTableGrid{ ColorTableGrid() }, this](const uint32_t& row, const uint32_t& col) { - ContentControl colorControl{}; - colorControl.ContentTemplate(colorTableEntryTemplate); - colorControl.Style(colorControlStyle); - - Data::Binding binding{}; - const auto bindingIndex = col == 1 ? row : row + ColorTableDivider; - binding.Source(this->ColorScheme().ColorEntryAt(gsl::narrow_cast(bindingIndex))); - - binding.Mode(Data::BindingMode::TwoWay); - colorControl.SetBinding(ContentControl::ContentProperty(), binding); - - colorTableGrid.Children().Append(colorControl); - Grid::SetRow(colorControl, row); - Grid::SetColumn(colorControl, col); - }; - for (uint32_t row = 0; row < ColorTableGrid().RowDefinitions().Size(); ++row) - { - // color label - TextBlock label{}; - label.Text(TableColorNames[row]); - label.Style(colorLabelStyle); - ColorTableGrid().Children().Append(label); - Grid::SetRow(label, row); - Grid::SetColumn(label, 0); - - // regular color - setupColorControl(row, 1); - - // bright color - setupColorControl(row, 2); - } + //if (it != end(_ColorSchemeList)) + //{ + // auto scheme = *it; + // ColorSchemeComboBox().SelectedItem(scheme); + //} + //else + //{ + // ColorScheme(_AllColorSchemes.GetAt(0)); + //} } // Function Description: @@ -160,15 +119,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation const SelectionChangedEventArgs& args) { // Update the color scheme this page is modifying - const auto colorScheme{ args.AddedItems().GetAt(0).try_as() }; - CurrentColorScheme(colorScheme); - _UpdateColorTable(colorScheme); + const auto colorScheme{ args.AddedItems().GetAt(0).try_as() }; + ColorScheme(*colorScheme); - _State.LastSelectedScheme(colorScheme.Name()); + //_State.LastSelectedScheme(colorScheme.Name()); // Set the text disclaimer for the text box hstring disclaimer{}; - const std::wstring schemeName{ colorScheme.Name() }; + const std::wstring schemeName{ colorScheme->Name() }; if (std::find(std::begin(InBoxSchemes), std::end(InBoxSchemes), schemeName) != std::end(InBoxSchemes)) { // load disclaimer for in-box profiles @@ -181,49 +139,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation IsRenaming(false); } - void ColorSchemes::ColorSchemeSelectionChanged2(const IInspectable& /*sender*/, - const SelectionChangedEventArgs& args) - { - // Update the color scheme this page is modifying - const auto colorScheme{ args.AddedItems().GetAt(0).try_as() }; - ColorScheme(*colorScheme); - _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"ColorScheme" }); - //_UpdateColorTable(colorScheme); - - //_State.LastSelectedScheme(colorScheme.Name()); - - //// Set the text disclaimer for the text box - //hstring disclaimer{}; - //const std::wstring schemeName{ colorScheme.Name() }; - //if (std::find(std::begin(InBoxSchemes), std::end(InBoxSchemes), schemeName) != std::end(InBoxSchemes)) - //{ - // // load disclaimer for in-box profiles - // disclaimer = RS_(L"ColorScheme_DeleteButtonDisclaimerInBox"); - //} - //DeleteButtonDisclaimer().Text(disclaimer); - - //// Update the state of the page - //_PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"CanDeleteCurrentScheme" }); - //IsRenaming(false); - } - - // Function Description: - // - Updates the list of all color schemes available to choose from. - // Arguments: - // - - // Return Value: - // - - void ColorSchemes::_UpdateColorSchemeList() - { - // Surprisingly, though this is called every time we navigate to the page, - // the list does not keep growing on each navigation. - const auto& colorSchemeMap{ _State.Settings().GlobalSettings().ColorSchemes() }; - for (const auto& pair : colorSchemeMap) - { - _ColorSchemeList.Append(pair.Value()); - } - } - // Function Description: // - Called when a ColorPicker control has selected a new color. This is specifically // called by color pickers assigned to a color table entry. It takes the index @@ -279,7 +194,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation bool ColorSchemes::CanDeleteCurrentScheme() const { - if (const auto& scheme{ CurrentColorScheme() }) + if (const auto& scheme{ ColorScheme() }) { // Only allow this color scheme to be deleted if it's not provided in-box const std::wstring myName{ scheme.Name() }; @@ -290,14 +205,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void ColorSchemes::DeleteConfirmation_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/) { - const auto schemeName{ CurrentColorScheme().Name() }; - _State.Settings().GlobalSettings().RemoveColorScheme(schemeName); - - // This ensures that the JSON is updated with "Campbell", because the color scheme was deleted - _State.Settings().UpdateColorSchemeReferences(schemeName, L"Campbell"); + ColorScheme().DeleteScheme(); const auto removedSchemeIndex{ ColorSchemeComboBox().SelectedIndex() }; - if (static_cast(removedSchemeIndex) < _ColorSchemeList.Size() - 1) + if (static_cast(removedSchemeIndex) < _AllColorSchemes.Size() - 1) { // select same index ColorSchemeComboBox().SelectedIndex(removedSchemeIndex + 1); @@ -307,7 +218,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // select last color scheme (avoid out of bounds error) ColorSchemeComboBox().SelectedIndex(removedSchemeIndex - 1); } - _ColorSchemeList.RemoveAt(removedSchemeIndex); + _AllColorSchemes.RemoveAt(removedSchemeIndex); DeleteButton().Flyout().Hide(); @@ -335,7 +246,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _State.Settings().GlobalSettings().AddColorScheme(scheme); // Update current page - _ColorSchemeList.Append(scheme); + //_ColorSchemeList.Append(scheme); ColorSchemeComboBox().SelectedItem(scheme); } @@ -347,7 +258,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // - void ColorSchemes::Rename_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/) { - NameBox().Text(CurrentColorScheme().Name()); + NameBox().Text(ColorScheme().Name()); IsRenaming(true); NameBox().Focus(FocusState::Programmatic); NameBox().SelectAll(); @@ -385,7 +296,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void ColorSchemes::_RenameCurrentScheme(hstring newName) { // check if different name is already in use - const auto oldName{ CurrentColorScheme().Name() }; + const auto oldName{ ColorScheme().Name() }; if (newName != oldName && _State.Settings().GlobalSettings().ColorSchemes().HasKey(newName)) { // open the error tip @@ -399,42 +310,20 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } // update the settings model - CurrentColorScheme().Name(newName); + ColorScheme().Name(newName); _State.Settings().GlobalSettings().RemoveColorScheme(oldName); _State.Settings().GlobalSettings().AddColorScheme(CurrentColorScheme()); _State.Settings().UpdateColorSchemeReferences(oldName, newName); // update the UI RenameErrorTip().IsOpen(false); - CurrentColorScheme().Name(newName); + ColorScheme().Name(newName); IsRenaming(false); // The color scheme is renamed appropriately, but the ComboBox still shows the old name (until you open it) // We need to manually force the ComboBox to refresh itself. const auto selectedIndex{ ColorSchemeComboBox().SelectedIndex() }; - ColorSchemeComboBox().SelectedIndex((selectedIndex + 1) % ColorSchemeList().Size()); + ColorSchemeComboBox().SelectedIndex((selectedIndex + 1) % _AllColorSchemes.Size()); ColorSchemeComboBox().SelectedIndex(selectedIndex); } - - // Function Description: - // - Updates the currently modifiable color table based on the given current color scheme. - // Arguments: - // - colorScheme: the color scheme to retrieve the color table from - // Return Value: - // - - void ColorSchemes::_UpdateColorTable(const Model::ColorScheme& colorScheme) - { - for (uint8_t i = 0; i < TableColorNames.size(); ++i) - { - til::color currentColor{ colorScheme.Table()[i] }; - if (i < ColorTableDivider) - { - _CurrentNonBrightColorTable.GetAt(i).Color(currentColor); - } - else - { - _CurrentBrightColorTable.GetAt(i - ColorTableDivider).Color(currentColor); - } - } - } } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h index 2ff257d6d6a..d1d53007e4c 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h @@ -29,7 +29,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void OnNavigatedTo(const winrt::Windows::UI::Xaml::Navigation::NavigationEventArgs& e); void ColorSchemeSelectionChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args); - void ColorSchemeSelectionChanged2(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args); void ColorPickerChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Microsoft::UI::Xaml::Controls::ColorChangedEventArgs& args); void AddNew_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); @@ -43,22 +42,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_PROPERTY(Editor::ColorSchemesPageNavigationState, State, nullptr); WINRT_PROPERTY(Model::ColorScheme, CurrentColorScheme, nullptr); - WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentNonBrightColorTable, nullptr); - WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentBrightColorTable, nullptr); - WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, ColorSchemeList, nullptr); - WINRT_PROPERTY(Editor::ColorSchemeViewModel, ColorScheme, nullptr); + WINRT_OBSERVABLE_PROPERTY(Editor::ColorSchemeViewModel, ColorScheme, _PropertyChangedHandlers, nullptr); WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, AllColorSchemes, nullptr); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); WINRT_OBSERVABLE_PROPERTY(bool, IsRenaming, _PropertyChangedHandlers, nullptr); - WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentForegroundColor, _PropertyChangedHandlers, nullptr); - WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentBackgroundColor, _PropertyChangedHandlers, nullptr); - WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentCursorColor, _PropertyChangedHandlers, nullptr); - WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentSelectionBackgroundColor, _PropertyChangedHandlers, nullptr); private: - void _UpdateColorTable(const winrt::Microsoft::Terminal::Settings::Model::ColorScheme& colorScheme); - void _UpdateColorSchemeList(); void _RenameCurrentScheme(hstring newName); }; } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl index 16232256c8d..2bbf6a94fce 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl @@ -23,17 +23,6 @@ namespace Microsoft.Terminal.Settings.Editor ColorSchemeViewModel ColorScheme { get; }; - // Terminal Colors - Windows.Foundation.Collections.IVector CurrentNonBrightColorTable { get; }; - Windows.Foundation.Collections.IVector CurrentBrightColorTable { get; }; - - // System Colors - ColorTableEntry CurrentForegroundColor; - ColorTableEntry CurrentBackgroundColor; - ColorTableEntry CurrentCursorColor; - ColorTableEntry CurrentSelectionBackgroundColor; - - Windows.Foundation.Collections.IObservableVector ColorSchemeList { get; }; Windows.Foundation.Collections.IObservableVector AllColorSchemes { get; }; } } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index 859e1cb1834..42ceadfb6d4 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -83,43 +83,6 @@ Margin="{StaticResource StandardIndentMargin}" Style="{StaticResource DisclaimerStyle}" /> - - - - - - - - - - - - - - - - - - - @@ -130,7 +93,7 @@ @@ -229,6 +192,102 @@ + + + + + + + + + + + + + + + + @@ -258,7 +317,7 @@ @@ -270,7 +329,7 @@ @@ -282,7 +341,7 @@ @@ -294,7 +353,7 @@ diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index 8cab0e08e98..dd1f4e90a2d 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -455,6 +455,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation for (const auto& pair : colorSchemeMap) { const auto viewModel = Editor::ColorSchemeViewModel(pair.Value()); + viewModel.DeleteColorScheme({ this, &MainPage::_DeleteColorScheme }); AllColorSchemes.Append(viewModel); } return AllColorSchemes; @@ -612,6 +613,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _Navigate(newSelectedItem.try_as().Tag().try_as(), BreadcrumbSubPage::None, true); } + void MainPage::_DeleteColorScheme(const IInspectable /*sender*/, const Editor::DeleteColorSchemeEventArgs& args) + { + const auto name{ args.SchemeName() }; + + // Delete scheme from settings model + _settingsClone.GlobalSettings().RemoveColorScheme(name); + + // This ensures that the JSON is updated with "Campbell", because the color scheme was deleted + _settingsClone.UpdateColorSchemeReferences(name, L"Campbell"); + } + IObservableVector MainPage::Breadcrumbs() noexcept { return _breadcrumbs; diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.h b/src/cascadia/TerminalSettingsEditor/MainPage.h index e1e705648c0..5e5adefc925 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.h +++ b/src/cascadia/TerminalSettingsEditor/MainPage.h @@ -56,6 +56,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void _CreateAndNavigateToNewProfile(const uint32_t index, const Model::Profile& profile); winrt::Microsoft::UI::Xaml::Controls::NavigationViewItem _CreateProfileNavViewItem(const Editor::ProfileViewModel& profile); void _DeleteProfile(const Windows::Foundation::IInspectable sender, const Editor::DeleteProfileEventArgs& args); + void _DeleteColorScheme(const Windows::Foundation::IInspectable sender, const Editor::DeleteColorSchemeEventArgs& args); void _AddProfileHandler(const winrt::guid profileGuid); void _SetupProfileEventHandling(const winrt::Microsoft::Terminal::Settings::Editor::ProfilePageNavigationState state); From 65fc789a8f52aba1280dcfe8077d8869eea577f5 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Tue, 24 May 2022 15:17:13 -0700 Subject: [PATCH 08/37] page view model is up --- .../TerminalSettingsEditor/ColorSchemes.cpp | 35 +++++++------- .../TerminalSettingsEditor/ColorSchemes.h | 10 ++-- .../TerminalSettingsEditor/ColorSchemes.idl | 7 ++- .../TerminalSettingsEditor/ColorSchemes.xaml | 42 ++++++++-------- .../ColorSchemesPageViewModel.cpp | 48 +++++++++++++++++++ .../ColorSchemesPageViewModel.h | 37 ++++++++++++++ .../ColorSchemesPageViewModel.idl | 17 +++++++ .../TerminalSettingsEditor/MainPage.cpp | 12 ++--- ...Microsoft.Terminal.Settings.Editor.vcxproj | 9 ++++ ...t.Terminal.Settings.Editor.vcxproj.filters | 1 + 10 files changed, 164 insertions(+), 54 deletions(-) create mode 100644 src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp create mode 100644 src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h create mode 100644 src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index aa3be08aba8..5be48aaa8c7 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -89,8 +89,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void ColorSchemes::OnNavigatedTo(const NavigationEventArgs& e) { _State = e.Parameter().as(); - _AllColorSchemes = _State.AllColorSchemes(); - ColorScheme(_AllColorSchemes.GetAt(0)); + _ViewModel = _State.ViewModel(); // Try to look up the scheme that was navigated to. If we find it, immediately select it. //const std::wstring lastNameFromNav{ _State.LastSelectedScheme() }; //const auto it = std::find_if(begin(_ColorSchemeList), @@ -120,7 +119,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { // Update the color scheme this page is modifying const auto colorScheme{ args.AddedItems().GetAt(0).try_as() }; - ColorScheme(*colorScheme); + _ViewModel.RequestSetCurrentScheme(*colorScheme); //_State.LastSelectedScheme(colorScheme.Name()); @@ -162,30 +161,30 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { if (index < ColorTableDivider) { - ColorScheme().CurrentNonBrightColorTable().GetAt(*index).Color(newColor); + _ViewModel.CurrentScheme().CurrentNonBrightColorTable().GetAt(*index).Color(newColor); } else { - ColorScheme().CurrentBrightColorTable().GetAt(*index - ColorTableDivider).Color(newColor); + _ViewModel.CurrentScheme().CurrentBrightColorTable().GetAt(*index - ColorTableDivider).Color(newColor); } } else if (const auto stringTag{ tag.try_as() }) { if (stringTag == ForegroundColorTag) { - ColorScheme().CurrentForegroundColor().Color(newColor); + _ViewModel.CurrentScheme().CurrentForegroundColor().Color(newColor); } else if (stringTag == BackgroundColorTag) { - ColorScheme().CurrentBackgroundColor().Color(newColor); + _ViewModel.CurrentScheme().CurrentBackgroundColor().Color(newColor); } else if (stringTag == CursorColorTag) { - ColorScheme().CurrentCursorColor().Color(newColor); + _ViewModel.CurrentScheme().CurrentCursorColor().Color(newColor); } else if (stringTag == SelectionBackgroundColorTag) { - ColorScheme().CurrentSelectionBackgroundColor().Color(newColor); + _ViewModel.CurrentScheme().CurrentSelectionBackgroundColor().Color(newColor); } } } @@ -194,7 +193,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation bool ColorSchemes::CanDeleteCurrentScheme() const { - if (const auto& scheme{ ColorScheme() }) + if (const auto& scheme{ _ViewModel.CurrentScheme() }) { // Only allow this color scheme to be deleted if it's not provided in-box const std::wstring myName{ scheme.Name() }; @@ -205,10 +204,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void ColorSchemes::DeleteConfirmation_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/) { - ColorScheme().DeleteScheme(); + _ViewModel.CurrentScheme().DeleteScheme(); const auto removedSchemeIndex{ ColorSchemeComboBox().SelectedIndex() }; - if (static_cast(removedSchemeIndex) < _AllColorSchemes.Size() - 1) + if (static_cast(removedSchemeIndex) < ViewModel().AllColorSchemes().Size() - 1) { // select same index ColorSchemeComboBox().SelectedIndex(removedSchemeIndex + 1); @@ -218,7 +217,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // select last color scheme (avoid out of bounds error) ColorSchemeComboBox().SelectedIndex(removedSchemeIndex - 1); } - _AllColorSchemes.RemoveAt(removedSchemeIndex); + ViewModel().AllColorSchemes().RemoveAt(removedSchemeIndex); DeleteButton().Flyout().Hide(); @@ -258,7 +257,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // - void ColorSchemes::Rename_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/) { - NameBox().Text(ColorScheme().Name()); + NameBox().Text(_ViewModel.CurrentScheme().Name()); IsRenaming(true); NameBox().Focus(FocusState::Programmatic); NameBox().SelectAll(); @@ -296,7 +295,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void ColorSchemes::_RenameCurrentScheme(hstring newName) { // check if different name is already in use - const auto oldName{ ColorScheme().Name() }; + const auto oldName{ _ViewModel.CurrentScheme().Name() }; if (newName != oldName && _State.Settings().GlobalSettings().ColorSchemes().HasKey(newName)) { // open the error tip @@ -310,20 +309,20 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } // update the settings model - ColorScheme().Name(newName); + _ViewModel.CurrentScheme().Name(newName); _State.Settings().GlobalSettings().RemoveColorScheme(oldName); _State.Settings().GlobalSettings().AddColorScheme(CurrentColorScheme()); _State.Settings().UpdateColorSchemeReferences(oldName, newName); // update the UI RenameErrorTip().IsOpen(false); - ColorScheme().Name(newName); + _ViewModel.CurrentScheme().Name(newName); IsRenaming(false); // The color scheme is renamed appropriately, but the ComboBox still shows the old name (until you open it) // We need to manually force the ComboBox to refresh itself. const auto selectedIndex{ ColorSchemeComboBox().SelectedIndex() }; - ColorSchemeComboBox().SelectedIndex((selectedIndex + 1) % _AllColorSchemes.Size()); + ColorSchemeComboBox().SelectedIndex((selectedIndex + 1) % ViewModel().AllColorSchemes().Size()); ColorSchemeComboBox().SelectedIndex(selectedIndex); } } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h index d1d53007e4c..a51516bc7c2 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h @@ -7,6 +7,7 @@ #include "ColorSchemes.g.h" #include "ColorSchemesPageNavigationState.g.h" #include "ColorSchemeViewModel.h" +#include "ColorSchemesPageViewModel.h" #include "Utils.h" namespace winrt::Microsoft::Terminal::Settings::Editor::implementation @@ -14,12 +15,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation struct ColorSchemesPageNavigationState : ColorSchemesPageNavigationStateT { public: - ColorSchemesPageNavigationState(const Model::CascadiaSettings& settings) : - _Settings{ settings } {} + ColorSchemesPageNavigationState(const Editor::ColorSchemesPageViewModel& viewModel) : + _ViewModel{ viewModel } {} WINRT_PROPERTY(Model::CascadiaSettings, Settings, nullptr); WINRT_PROPERTY(winrt::hstring, LastSelectedScheme, L""); - WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, AllColorSchemes, nullptr); + WINRT_PROPERTY(Editor::ColorSchemesPageViewModel, ViewModel, nullptr); }; struct ColorSchemes : public HasScrollViewer, ColorSchemesT @@ -42,8 +43,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_PROPERTY(Editor::ColorSchemesPageNavigationState, State, nullptr); WINRT_PROPERTY(Model::ColorScheme, CurrentColorScheme, nullptr); - WINRT_OBSERVABLE_PROPERTY(Editor::ColorSchemeViewModel, ColorScheme, _PropertyChangedHandlers, nullptr); - WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, AllColorSchemes, nullptr); + WINRT_OBSERVABLE_PROPERTY(Editor::ColorSchemesPageViewModel, ViewModel, _PropertyChangedHandlers, nullptr); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); WINRT_OBSERVABLE_PROPERTY(bool, IsRenaming, _PropertyChangedHandlers, nullptr); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl index 2bbf6a94fce..ae469745ff8 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl @@ -2,6 +2,7 @@ // Licensed under the MIT license. import "ColorSchemeViewModel.idl"; +import "ColorSchemesPageViewModel.idl"; namespace Microsoft.Terminal.Settings.Editor { @@ -10,7 +11,7 @@ namespace Microsoft.Terminal.Settings.Editor { Microsoft.Terminal.Settings.Model.CascadiaSettings Settings; String LastSelectedScheme; - Windows.Foundation.Collections.IObservableVector AllColorSchemes; + ColorSchemesPageViewModel ViewModel; }; [default_interface] runtimeclass ColorSchemes : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged @@ -21,8 +22,6 @@ namespace Microsoft.Terminal.Settings.Editor Boolean CanDeleteCurrentScheme { get; }; Boolean IsRenaming { get; }; - ColorSchemeViewModel ColorScheme { get; }; - - Windows.Foundation.Collections.IObservableVector AllColorSchemes { get; }; + ColorSchemesPageViewModel ViewModel { get; }; } } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index 42ceadfb6d4..2e126c20e33 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -91,7 +91,7 @@ Visibility="{x:Bind local:Converters.InvertedBooleanToVisibility(IsRenaming), Mode=OneWay}"> @@ -195,97 +195,97 @@ @@ -317,7 +317,7 @@ @@ -329,7 +329,7 @@ @@ -341,7 +341,7 @@ @@ -353,7 +353,7 @@ diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp new file mode 100644 index 00000000000..d080ffa9688 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" +#include "ColorSchemesPageViewModel.h" +#include "ColorSchemesPageViewModel.g.cpp" + +#include +#include "..\WinRTUtils\inc\Utils.h" + +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation +{ + ColorSchemesPageViewModel::ColorSchemesPageViewModel(const Model::CascadiaSettings& settings) : + _settings{ settings } + { + _MakeColorSchemeVMsHelper(); + CurrentScheme(_AllColorSchemes.GetAt(0)); + } + + void ColorSchemesPageViewModel::RequestSetCurrentScheme(Editor::ColorSchemeViewModel scheme) + { + CurrentScheme(scheme); + } + + void ColorSchemesPageViewModel::_MakeColorSchemeVMsHelper() + { + Windows::Foundation::Collections::IObservableVector AllColorSchemes{ single_threaded_observable_vector() }; + const auto& colorSchemeMap{ _settings.GlobalSettings().ColorSchemes() }; + for (const auto& pair : colorSchemeMap) + { + const auto viewModel = Editor::ColorSchemeViewModel(pair.Value()); + viewModel.DeleteColorScheme({ this, &ColorSchemesPageViewModel::_DeleteColorScheme }); + AllColorSchemes.Append(viewModel); + } + _AllColorSchemes = AllColorSchemes; + } + + void ColorSchemesPageViewModel::_DeleteColorScheme(const IInspectable /*sender*/, const Editor::DeleteColorSchemeEventArgs& args) + { + const auto name{ args.SchemeName() }; + + // Delete scheme from settings model + _settings.GlobalSettings().RemoveColorScheme(name); + + // This ensures that the JSON is updated with "Campbell", because the color scheme was deleted + _settings.UpdateColorSchemeReferences(name, L"Campbell"); + } +} diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h new file mode 100644 index 00000000000..5e378a27d2e --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +#include "ColorSchemesPageViewModel.g.h" +#include "ColorSchemeViewModel.h" +#include "Utils.h" +#include "ViewModelHelpers.h" +#include "ColorSchemes.h" + +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation +{ + struct ColorSchemesPageViewModel : ColorSchemesPageViewModelT, ViewModelHelper + { + public: + ColorSchemesPageViewModel(const Model::CascadiaSettings& settings); + + void RequestSetCurrentScheme(Editor::ColorSchemeViewModel scheme); + + WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); + + WINRT_OBSERVABLE_PROPERTY(Editor::ColorSchemeViewModel, CurrentScheme, _PropertyChangedHandlers, nullptr); + WINRT_OBSERVABLE_PROPERTY(Windows::Foundation::Collections::IObservableVector, AllColorSchemes, _PropertyChangedHandlers, nullptr); + + private: + Model::CascadiaSettings _settings; + + void _MakeColorSchemeVMsHelper(); + void _DeleteColorScheme(const IInspectable /*sender*/, const Editor::DeleteColorSchemeEventArgs& args); + }; +}; + +namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation +{ + BASIC_FACTORY(ColorSchemesPageViewModel); +} diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl new file mode 100644 index 00000000000..d215faab7c0 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import "ColorSchemeViewModel.idl"; + +namespace Microsoft.Terminal.Settings.Editor +{ + runtimeclass ColorSchemesPageViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged + { + ColorSchemesPageViewModel(Microsoft.Terminal.Settings.Model.CascadiaSettings Settings); + + void RequestSetCurrentScheme(ColorSchemeViewModel scheme); + + ColorSchemeViewModel CurrentScheme { get; }; + Windows.Foundation.Collections.IObservableVector AllColorSchemes { get; }; + } +} diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index dd1f4e90a2d..f21a56ad396 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -54,9 +54,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _InitializeProfilesList(); - _colorSchemesNavState = winrt::make(_settingsClone); - _AllColorSchemes = _MakeColorSchemeVMsHelper(_settingsClone); - _colorSchemesNavState.AllColorSchemes(_AllColorSchemes); + _colorSchemesNavState = winrt::make(winrt::make(_settingsClone)); + //_AllColorSchemes = _MakeColorSchemeVMsHelper(_settingsClone); + //_colorSchemesNavState.AllColorSchemes(_AllColorSchemes); Automation::AutomationProperties::SetHelpText(SaveButton(), RS_(L"Settings_SaveSettingsButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip")); Automation::AutomationProperties::SetHelpText(ResetButton(), RS_(L"Settings_ResetSettingsButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip")); @@ -128,9 +128,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // Repopulate profile-related menu items _InitializeProfilesList(); // Update the Nav State with the new version of the settings - _colorSchemesNavState.Settings(_settingsClone); - _AllColorSchemes = _MakeColorSchemeVMsHelper(_settingsClone); - _colorSchemesNavState.AllColorSchemes(_AllColorSchemes); + _colorSchemesNavState.ViewModel(winrt::make(_settingsClone)); + //_AllColorSchemes = _MakeColorSchemeVMsHelper(_settingsClone); + //_colorSchemesNavState.AllColorSchemes(_AllColorSchemes); // We'll update the profile in the _profilesNavState whenever we actually navigate to one // now that the menuItems are repopulated, diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj index 6b69ea54168..ed3d7f20298 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj @@ -85,6 +85,10 @@ ColorSchemeViewModel.idl Code + + ColorSchemesPageViewModel.idl + Code + Profiles_Base.xaml Code @@ -201,6 +205,10 @@ ColorSchemeViewModel.idl Code + + ColorSchemesPageViewModel.idl + Code + Profiles_Base.xaml Code @@ -272,6 +280,7 @@ + Profiles_Base.xaml Code diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters index 0926568ce21..f4ed330ef0e 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters @@ -19,6 +19,7 @@ + Converters From a51c166e55277dcbc168de70ed286b53545bfeeb Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 25 May 2022 10:06:22 -0700 Subject: [PATCH 09/37] rename and delete work --- .../ColorSchemeViewModel.cpp | 17 +++-- .../ColorSchemeViewModel.h | 24 ++----- .../ColorSchemeViewModel.idl | 8 --- .../TerminalSettingsEditor/ColorSchemes.cpp | 50 +++++---------- .../TerminalSettingsEditor/ColorSchemes.h | 1 - .../TerminalSettingsEditor/ColorSchemes.idl | 1 - .../TerminalSettingsEditor/ColorSchemes.xaml | 4 +- .../ColorSchemesPageViewModel.cpp | 62 ++++++++++++++++--- .../ColorSchemesPageViewModel.h | 5 +- .../ColorSchemesPageViewModel.idl | 3 + .../TerminalSettingsEditor/MainPage.cpp | 24 ------- .../TerminalSettingsEditor/MainPage.h | 3 - 12 files changed, 90 insertions(+), 112 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp index c699a99d60f..3420c3aa0aa 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp @@ -106,6 +106,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _CurrentSelectionBackgroundColor.PropertyChanged(colorEntryChangedHandler); } + winrt::hstring ColorSchemeViewModel::Name() + { + return _Name; + } + + void ColorSchemeViewModel::Name(winrt::hstring newName) + { + _scheme.Name(newName); + _Name = newName; + } + Editor::ColorTableEntry ColorSchemeViewModel::ColorEntryAt(uint32_t index) { if (index < ColorTableDivider) @@ -118,12 +129,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } - void ColorSchemeViewModel::DeleteScheme() - { - auto deleteSchemeArgs{ winrt::make_self(Name()) }; - _DeleteColorSchemeHandlers(*this, *deleteSchemeArgs); - } - ColorTableEntry::ColorTableEntry(uint8_t index, Windows::UI::Color color) { Name(TableColorNames[index]); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h index 38083a2da8e..559814bd91b 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h @@ -3,7 +3,6 @@ #pragma once -#include "DeleteColorSchemeEventArgs.g.h" #include "ColorSchemeViewModel.g.h" #include "Utils.h" #include "ViewModelHelpers.h" @@ -16,14 +15,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation public: ColorSchemeViewModel(const Model::ColorScheme scheme); - Editor::ColorTableEntry ColorEntryAt(uint32_t index); + winrt::hstring Name(); + void Name(winrt::hstring newName); - void DeleteScheme(); + Editor::ColorTableEntry ColorEntryAt(uint32_t index); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); - WINRT_PROPERTY(winrt::hstring, Name); - WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentNonBrightColorTable, nullptr); WINRT_PROPERTY(Windows::Foundation::Collections::IVector, CurrentBrightColorTable, nullptr); @@ -32,9 +30,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentCursorColor, _PropertyChangedHandlers, nullptr); WINRT_OBSERVABLE_PROPERTY(Editor::ColorTableEntry, CurrentSelectionBackgroundColor, _PropertyChangedHandlers, nullptr); - TYPED_EVENT(DeleteColorScheme, Editor::ColorSchemeViewModel, Editor::DeleteColorSchemeEventArgs); - private: + winrt::hstring _Name; Model::ColorScheme _scheme; }; @@ -54,19 +51,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation private: Windows::UI::Color _color; }; - - struct DeleteColorSchemeEventArgs : - public DeleteColorSchemeEventArgsT - { - public: - DeleteColorSchemeEventArgs(winrt::hstring schemeName) : - _SchemeName(schemeName) {} - - winrt::hstring SchemeName() const noexcept { return _SchemeName; } - - private: - winrt::hstring _SchemeName; - }; }; namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl index 680264ef51f..84cae5a4413 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl @@ -5,11 +5,6 @@ import "ColorSchemes.idl"; namespace Microsoft.Terminal.Settings.Editor { - runtimeclass DeleteColorSchemeEventArgs - { - String SchemeName { get; }; - } - runtimeclass ColorSchemeViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged { ColorSchemeViewModel(Microsoft.Terminal.Settings.Model.ColorScheme scheme); @@ -27,9 +22,6 @@ namespace Microsoft.Terminal.Settings.Editor ColorTableEntry CurrentBackgroundColor; ColorTableEntry CurrentCursorColor; ColorTableEntry CurrentSelectionBackgroundColor; - - void DeleteScheme(); - event Windows.Foundation.TypedEventHandler DeleteColorScheme; } [default_interface] runtimeclass ColorTableEntry : Windows.UI.Xaml.Data.INotifyPropertyChanged diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index 5be48aaa8c7..d7328ba0aa0 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -133,8 +133,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } DeleteButtonDisclaimer().Text(disclaimer); - // Update the state of the page - _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"CanDeleteCurrentScheme" }); IsRenaming(false); } @@ -191,20 +189,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } - bool ColorSchemes::CanDeleteCurrentScheme() const - { - if (const auto& scheme{ _ViewModel.CurrentScheme() }) - { - // Only allow this color scheme to be deleted if it's not provided in-box - const std::wstring myName{ scheme.Name() }; - return std::find(std::begin(InBoxSchemes), std::end(InBoxSchemes), myName) == std::end(InBoxSchemes); - } - return false; - } - void ColorSchemes::DeleteConfirmation_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/) { - _ViewModel.CurrentScheme().DeleteScheme(); + _ViewModel.RequestDeleteCurrentScheme(); const auto removedSchemeIndex{ ColorSchemeComboBox().SelectedIndex() }; if (static_cast(removedSchemeIndex) < ViewModel().AllColorSchemes().Size() - 1) @@ -294,35 +281,26 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void ColorSchemes::_RenameCurrentScheme(hstring newName) { - // check if different name is already in use - const auto oldName{ _ViewModel.CurrentScheme().Name() }; - if (newName != oldName && _State.Settings().GlobalSettings().ColorSchemes().HasKey(newName)) + if (_ViewModel.RequestRenameCurrentScheme(newName)) + { + // update the UI + RenameErrorTip().IsOpen(false); + IsRenaming(false); + + // The color scheme is renamed appropriately, but the ComboBox still shows the old name (until you open it) + // We need to manually force the ComboBox to refresh itself. + const auto selectedIndex{ ColorSchemeComboBox().SelectedIndex() }; + ColorSchemeComboBox().SelectedIndex((selectedIndex + 1) % ViewModel().AllColorSchemes().Size()); + ColorSchemeComboBox().SelectedIndex(selectedIndex); + } + else { - // open the error tip RenameErrorTip().Target(NameBox()); RenameErrorTip().IsOpen(true); // focus the name box NameBox().Focus(FocusState::Programmatic); NameBox().SelectAll(); - return; } - - // update the settings model - _ViewModel.CurrentScheme().Name(newName); - _State.Settings().GlobalSettings().RemoveColorScheme(oldName); - _State.Settings().GlobalSettings().AddColorScheme(CurrentColorScheme()); - _State.Settings().UpdateColorSchemeReferences(oldName, newName); - - // update the UI - RenameErrorTip().IsOpen(false); - _ViewModel.CurrentScheme().Name(newName); - IsRenaming(false); - - // The color scheme is renamed appropriately, but the ComboBox still shows the old name (until you open it) - // We need to manually force the ComboBox to refresh itself. - const auto selectedIndex{ ColorSchemeComboBox().SelectedIndex() }; - ColorSchemeComboBox().SelectedIndex((selectedIndex + 1) % ViewModel().AllColorSchemes().Size()); - ColorSchemeComboBox().SelectedIndex(selectedIndex); } } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h index a51516bc7c2..1fac1f73679 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h @@ -38,7 +38,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void RenameCancel_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); void NameBox_PreviewKeyDown(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs& e); - bool CanDeleteCurrentScheme() const; void DeleteConfirmation_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); WINRT_PROPERTY(Editor::ColorSchemesPageNavigationState, State, nullptr); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl index ae469745ff8..e9fa470e063 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl @@ -19,7 +19,6 @@ namespace Microsoft.Terminal.Settings.Editor ColorSchemes(); ColorSchemesPageNavigationState State { get; }; - Boolean CanDeleteCurrentScheme { get; }; Boolean IsRenaming { get; }; ColorSchemesPageViewModel ViewModel { get; }; diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index 2e126c20e33..6caf3d16b7b 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -107,7 +107,7 @@ From 99936101b7bd09e0a9507f0a52fd3619d80d60dd Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 27 Jul 2022 15:05:11 -0700 Subject: [PATCH 31/37] selection changed to view model --- .../TerminalSettingsEditor/ColorSchemes.cpp | 27 ------------------- .../TerminalSettingsEditor/ColorSchemes.h | 1 - .../TerminalSettingsEditor/ColorSchemes.xaml | 5 ++-- .../ColorSchemesPageViewModel.cpp | 22 +++++++++++++++ .../ColorSchemesPageViewModel.h | 2 ++ .../ColorSchemesPageViewModel.idl | 2 ++ .../Resources/en-US/Resources.resw | 2 +- 7 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index 0a30b78ac60..2a65bae1878 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -53,33 +53,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation ColorSchemeComboBox().SelectedItem(_ViewModel.CurrentScheme()); } - // Function Description: - // - Called when a different color scheme is selected. Updates our current - // color scheme and updates our currently modifiable color table. - // Arguments: - // - args: The selection changed args that tells us what's the new color scheme selected. - // Return Value: - // - - void ColorSchemes::ColorSchemeSelectionChanged(const IInspectable& /*sender*/, - const SelectionChangedEventArgs& args) - { - // Update the color scheme this page is modifying - if (args.AddedItems().Size() > 0) - { - const auto colorScheme{ args.AddedItems().GetAt(0).try_as() }; - _ViewModel.RequestSetCurrentScheme(*colorScheme); - - // Set the text disclaimer for the text box - hstring disclaimer{}; - if (!_ViewModel.CanDeleteCurrentScheme()) - { - // load disclaimer for in-box profiles - disclaimer = RS_(L"ColorScheme_DeleteButtonDisclaimerInBox"); - } - DeleteButtonDisclaimer().Text(disclaimer); - } - } - void ColorSchemes::DeleteConfirmation_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/) { const auto removedSchemeIndex{ ColorSchemeComboBox().SelectedIndex() }; diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h index ba36c2170d6..87c587b6063 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h @@ -17,7 +17,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void OnNavigatedTo(const winrt::Windows::UI::Xaml::Navigation::NavigationEventArgs& e); - void ColorSchemeSelectionChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args); void AddNew_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); void Rename_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index 6242db51c4c..f59b69e3bdc 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -92,7 +92,7 @@ @@ -414,7 +414,8 @@ - diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp index 13619816e17..d76c6a76502 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp @@ -59,6 +59,28 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } + // Function Description: + // - Called when a different color scheme is selected. Updates our current + // color scheme and updates our currently modifiable color table. + // Arguments: + // - args: The selection changed args that tells us what's the new color scheme selected. + // Return Value: + // - + void ColorSchemesPageViewModel::ColorSchemeSelectionChanged(const IInspectable& /*sender*/, + const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args) + { + // Update the color scheme this page is modifying + if (args.AddedItems().Size() > 0) + { + const auto colorScheme{ args.AddedItems().GetAt(0).try_as() }; + + CurrentScheme(*colorScheme); + + // Update the state of the page + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"CanDeleteCurrentScheme" }); + } + } + void ColorSchemesPageViewModel::_MakeColorSchemeVMsHelper() { std::vector allColorSchemes; diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h index 2dd2e767f58..6ed70213d7c 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h @@ -17,6 +17,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation ColorSchemesPageViewModel(const Model::CascadiaSettings& settings); void UpdateSettings(const Model::CascadiaSettings& settings); + void ColorSchemeSelectionChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args); + void RequestSetCurrentScheme(Editor::ColorSchemeViewModel scheme); void RequestEnterRename(); bool RequestExitRename(bool saveChanges, winrt::hstring newName); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl index 471e41b13b3..93b664a763e 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl @@ -10,6 +10,8 @@ namespace Microsoft.Terminal.Settings.Editor ColorSchemesPageViewModel(Microsoft.Terminal.Settings.Model.CascadiaSettings settings); void UpdateSettings(Microsoft.Terminal.Settings.Model.CascadiaSettings settings); + void ColorSchemeSelectionChanged(IInspectable sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs args); + void RequestSetCurrentScheme(ColorSchemeViewModel scheme); void RequestEnterRename(); Boolean RequestExitRename(Boolean saveChanges, String newName); diff --git a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw index b6ed87e87c3..8ef86eb96d8 100644 --- a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw @@ -1210,7 +1210,7 @@ Rename Text label for a button that can be used to begin the renaming process. - + This color scheme cannot be deleted or renamed because it is included by default. Disclaimer presented next to the delete button when it is disabled. From 814b4e185a64289aa56c9f9af6226ab5038a79d5 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 27 Jul 2022 15:09:15 -0700 Subject: [PATCH 32/37] don't need request anymore --- .../TerminalSettingsEditor/ColorSchemesPageViewModel.cpp | 8 -------- .../TerminalSettingsEditor/ColorSchemesPageViewModel.h | 1 - .../TerminalSettingsEditor/ColorSchemesPageViewModel.idl | 1 - 3 files changed, 10 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp index d76c6a76502..bb8095f7974 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp @@ -101,14 +101,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _AllColorSchemes = single_threaded_observable_vector(std::move(allColorSchemes)); } - void ColorSchemesPageViewModel::RequestSetCurrentScheme(Editor::ColorSchemeViewModel scheme) - { - CurrentScheme(scheme); - - // Update the state of the page - _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"CanDeleteCurrentScheme" }); - } - void ColorSchemesPageViewModel::RequestEnterRename() { InRenameMode(true); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h index 6ed70213d7c..6cb652965cb 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h @@ -19,7 +19,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void ColorSchemeSelectionChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args); - void RequestSetCurrentScheme(Editor::ColorSchemeViewModel scheme); void RequestEnterRename(); bool RequestExitRename(bool saveChanges, winrt::hstring newName); void RequestDeleteCurrentScheme(); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl index 93b664a763e..c7c6bd106e7 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl @@ -12,7 +12,6 @@ namespace Microsoft.Terminal.Settings.Editor void ColorSchemeSelectionChanged(IInspectable sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs args); - void RequestSetCurrentScheme(ColorSchemeViewModel scheme); void RequestEnterRename(); Boolean RequestExitRename(Boolean saveChanges, String newName); void RequestDeleteCurrentScheme(); From 4eecaccd188c583c037907a4daed08131bce60b4 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 28 Jul 2022 09:57:33 -0700 Subject: [PATCH 33/37] current scheme fixes --- .../TerminalSettingsEditor/ColorSchemes.xaml | 2 +- .../ColorSchemesPageViewModel.cpp | 29 +++++++------------ .../ColorSchemesPageViewModel.h | 5 ++-- .../ColorSchemesPageViewModel.idl | 4 +-- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index f59b69e3bdc..68920637c48 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -92,7 +92,7 @@ diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp index bb8095f7974..93b5092f09b 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.cpp @@ -59,28 +59,21 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } - // Function Description: - // - Called when a different color scheme is selected. Updates our current - // color scheme and updates our currently modifiable color table. - // Arguments: - // - args: The selection changed args that tells us what's the new color scheme selected. - // Return Value: - // - - void ColorSchemesPageViewModel::ColorSchemeSelectionChanged(const IInspectable& /*sender*/, - const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args) + void ColorSchemesPageViewModel::CurrentScheme(const Editor::ColorSchemeViewModel& newSelectedScheme) { - // Update the color scheme this page is modifying - if (args.AddedItems().Size() > 0) + if (_CurrentScheme != newSelectedScheme) { - const auto colorScheme{ args.AddedItems().GetAt(0).try_as() }; - - CurrentScheme(*colorScheme); - - // Update the state of the page + _CurrentScheme = newSelectedScheme; + _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"CurrentScheme" }); _PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"CanDeleteCurrentScheme" }); } } + Editor::ColorSchemeViewModel ColorSchemesPageViewModel::CurrentScheme() + { + return _CurrentScheme; + } + void ColorSchemesPageViewModel::_MakeColorSchemeVMsHelper() { std::vector allColorSchemes; @@ -169,10 +162,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation bool ColorSchemesPageViewModel::CanDeleteCurrentScheme() const { - if (const auto& scheme{ CurrentScheme() }) + if (_CurrentScheme) { // Only allow this color scheme to be deleted if it's not provided in-box - return std::find(std::begin(InBoxSchemes), std::end(InBoxSchemes), scheme.Name()) == std::end(InBoxSchemes); + return std::find(std::begin(InBoxSchemes), std::end(InBoxSchemes), _CurrentScheme.Name()) == std::end(InBoxSchemes); } return false; } diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h index 6cb652965cb..80836332bec 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.h @@ -17,7 +17,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation ColorSchemesPageViewModel(const Model::CascadiaSettings& settings); void UpdateSettings(const Model::CascadiaSettings& settings); - void ColorSchemeSelectionChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Controls::SelectionChangedEventArgs& args); + void CurrentScheme(const Editor::ColorSchemeViewModel& newSelectedScheme); + Editor::ColorSchemeViewModel CurrentScheme(); void RequestEnterRename(); bool RequestExitRename(bool saveChanges, winrt::hstring newName); @@ -29,10 +30,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); WINRT_OBSERVABLE_PROPERTY(bool, InRenameMode, _PropertyChangedHandlers, false); - WINRT_OBSERVABLE_PROPERTY(Editor::ColorSchemeViewModel, CurrentScheme, _PropertyChangedHandlers, nullptr); WINRT_OBSERVABLE_PROPERTY(Windows::Foundation::Collections::IObservableVector, AllColorSchemes, _PropertyChangedHandlers, nullptr); private: + Editor::ColorSchemeViewModel _CurrentScheme{ nullptr }; Model::CascadiaSettings _settings; Windows::Foundation::Collections::IMap _viewModelToSchemeMap; diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl index c7c6bd106e7..b2d5809d731 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemesPageViewModel.idl @@ -10,14 +10,12 @@ namespace Microsoft.Terminal.Settings.Editor ColorSchemesPageViewModel(Microsoft.Terminal.Settings.Model.CascadiaSettings settings); void UpdateSettings(Microsoft.Terminal.Settings.Model.CascadiaSettings settings); - void ColorSchemeSelectionChanged(IInspectable sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs args); - void RequestEnterRename(); Boolean RequestExitRename(Boolean saveChanges, String newName); void RequestDeleteCurrentScheme(); ColorSchemeViewModel RequestAddNew(); - ColorSchemeViewModel CurrentScheme { get; }; + ColorSchemeViewModel CurrentScheme; Boolean CanDeleteCurrentScheme { get; }; Boolean InRenameMode { get; }; Windows.Foundation.Collections.IObservableVector AllColorSchemes { get; }; From e428e2bb46163930e73376ad3eadea17b2ffd158 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 28 Jul 2022 10:00:32 -0700 Subject: [PATCH 34/37] format --- src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index 68920637c48..80f750d92d6 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -415,9 +415,9 @@ + Style="{StaticResource DisclaimerStyle}" + Visibility="{x:Bind local:Converters.InvertedBooleanToVisibility(ViewModel.CanDeleteCurrentScheme), Mode=OneWay}" /> From 7a1b534bf05ecedb82add279a94959ae420f7d47 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 28 Jul 2022 10:19:12 -0700 Subject: [PATCH 35/37] remove request add new --- src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp | 6 ------ src/cascadia/TerminalSettingsEditor/ColorSchemes.h | 2 -- src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml | 2 +- .../TerminalSettingsEditor/ColorSchemesPageViewModel.cpp | 7 ++++++- .../TerminalSettingsEditor/ColorSchemesPageViewModel.h | 4 +++- .../TerminalSettingsEditor/ColorSchemesPageViewModel.idl | 3 ++- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index 2a65bae1878..be08eb3fb11 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -83,12 +83,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation ColorSchemeComboBox().Focus(FocusState::Programmatic); } - void ColorSchemes::AddNew_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/) - { - // Update current page - ColorSchemeComboBox().SelectedItem(_ViewModel.RequestAddNew()); - } - // Function Description: // - Pre-populates/focuses the name TextBox, updates the UI // Arguments: diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h index 87c587b6063..a70df37c2ab 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h @@ -17,8 +17,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void OnNavigatedTo(const winrt::Windows::UI::Xaml::Navigation::NavigationEventArgs& e); - void AddNew_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); - void Rename_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); void RenameAccept_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); void RenameCancel_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index 80f750d92d6..fb2abee15ab 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -151,7 +151,7 @@