Skip to content

Commit

Permalink
PRE-MERGE #13269 Rejuvenate the color schemes page in the SUI to foll…
Browse files Browse the repository at this point in the history
…ow Win 11 style guidelines
  • Loading branch information
DHowett committed Jul 12, 2022
2 parents 7a8defb + fbe2ebd commit 66a7bee
Show file tree
Hide file tree
Showing 25 changed files with 939 additions and 544 deletions.
10 changes: 8 additions & 2 deletions src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
ColorSchemeViewModel::ColorSchemeViewModel(const Model::ColorScheme scheme) :
ColorSchemeViewModel::ColorSchemeViewModel(const Model::ColorScheme scheme, const Editor::ColorSchemesPageViewModel parentPageVM) :
_scheme{ scheme },
_NonBrightColorTable{ single_threaded_observable_vector<Editor::ColorTableEntry>() },
_BrightColorTable{ single_threaded_observable_vector<Editor::ColorTableEntry>() }
_BrightColorTable{ single_threaded_observable_vector<Editor::ColorTableEntry>() },
_parentPageVM{ parentPageVM }
{
_Name = scheme.Name();

Expand Down Expand Up @@ -84,6 +85,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return _Name;
}

bool ColorSchemeViewModel::RequestRename(winrt::hstring newName)
{
return _parentPageVM.RequestRenameCurrentScheme(newName);
}

void ColorSchemeViewModel::Name(winrt::hstring newName)
{
_scheme.Name(newName);
Expand Down
6 changes: 5 additions & 1 deletion src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
struct ColorSchemeViewModel : ColorSchemeViewModelT<ColorSchemeViewModel>, ViewModelHelper<ColorSchemeViewModel>
{
public:
ColorSchemeViewModel(const Model::ColorScheme scheme);
ColorSchemeViewModel(const Model::ColorScheme scheme, const Editor::ColorSchemesPageViewModel parentPageVM);

winrt::hstring Name();
void Name(winrt::hstring newName);

bool RequestRename(winrt::hstring newName);

Editor::ColorTableEntry ColorEntryAt(uint32_t index);

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

WINRT_PROPERTY(bool, IsInBoxScheme);
WINRT_PROPERTY(Windows::Foundation::Collections::IVector<Editor::ColorTableEntry>, NonBrightColorTable, nullptr);
WINRT_PROPERTY(Windows::Foundation::Collections::IVector<Editor::ColorTableEntry>, BrightColorTable, nullptr);

Expand All @@ -41,6 +44,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
private:
winrt::hstring _Name;
Model::ColorScheme _scheme;
Editor::ColorSchemesPageViewModel _parentPageVM{ nullptr };
};

struct ColorTableEntry : ColorTableEntryT<ColorTableEntry>
Expand Down
6 changes: 5 additions & 1 deletion src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.idl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
// Licensed under the MIT license.

import "ColorSchemes.idl";
import "ColorSchemesPageViewModel.idl";

namespace Microsoft.Terminal.Settings.Editor
{
runtimeclass ColorSchemeViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
ColorSchemeViewModel(Microsoft.Terminal.Settings.Model.ColorScheme scheme);
ColorSchemeViewModel(Microsoft.Terminal.Settings.Model.ColorScheme scheme, ColorSchemesPageViewModel parentPageVM);

String Name;
Boolean IsInBoxScheme;

Boolean RequestRename(String newName);

// Terminal Colors
Windows.Foundation.Collections.IVector<ColorTableEntry> NonBrightColorTable;
Expand Down
103 changes: 11 additions & 92 deletions src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,16 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
InitializeComponent();

Automation::AutomationProperties::SetName(ColorSchemeComboBox(), RS_(L"ColorScheme_Name/Header"));
Automation::AutomationProperties::SetFullDescription(ColorSchemeComboBox(), RS_(L"ColorScheme_Name/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"));
ToolTipService::SetToolTip(ColorSchemeComboBox(), box_value(RS_(L"ColorScheme_Name/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip")));

Automation::AutomationProperties::SetName(RenameButton(), RS_(L"Rename/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"));

Automation::AutomationProperties::SetName(NameBox(), RS_(L"ColorScheme_Name/Header"));
Automation::AutomationProperties::SetFullDescription(NameBox(), RS_(L"ColorScheme_Name/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"));
ToolTipService::SetToolTip(NameBox(), box_value(RS_(L"ColorScheme_Name/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip")));

Automation::AutomationProperties::SetName(RenameAcceptButton(), RS_(L"RenameAccept/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"));
Automation::AutomationProperties::SetName(RenameCancelButton(), RS_(L"RenameCancel/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"));
Automation::AutomationProperties::SetName(AddNewButton(), RS_(L"ColorScheme_AddNewButton/Text"));
Automation::AutomationProperties::SetName(DeleteButton(), RS_(L"ColorScheme_DeleteButton/Text"));
}

void ColorSchemes::OnNavigatedTo(const NavigationEventArgs& e)
{
_ViewModel = e.Parameter().as<Editor::ColorSchemesPageViewModel>();
_ViewModel.RequestSetCurrentPage(ColorSchemesSubPage::Base);

ColorSchemeComboBox().SelectedItem(_ViewModel.CurrentScheme());
ColorSchemeListView().SelectedItem(_ViewModel.CurrentScheme());
}

// Function Description:
Expand All @@ -68,17 +57,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
const auto colorScheme{ args.AddedItems().GetAt(0).try_as<ColorSchemeViewModel>() };
_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);

IsRenaming(false);
}
}

Expand Down Expand Up @@ -136,17 +114,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

void ColorSchemes::DeleteConfirmation_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/)
{
const auto removedSchemeIndex{ ColorSchemeComboBox().SelectedIndex() };
const auto removedSchemeIndex{ ColorSchemeListView().SelectedIndex() };
_ViewModel.RequestDeleteCurrentScheme();
if (static_cast<uint32_t>(removedSchemeIndex) < ViewModel().AllColorSchemes().Size())
{
// select same index
ColorSchemeComboBox().SelectedIndex(removedSchemeIndex);
ColorSchemeListView().SelectedIndex(removedSchemeIndex);
}
else
{
// select last color scheme (avoid out of bounds error)
ColorSchemeComboBox().SelectedIndex(removedSchemeIndex - 1);
ColorSchemeListView().SelectedIndex(removedSchemeIndex - 1);
}
DeleteButton().Flyout().Hide();

Expand All @@ -161,80 +139,21 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// However, it seems even more useful for focus to ALWAYS land on the
// scheme dropdown box. This forces Narrator to read the name of the
// newly selected color scheme, which seemed more useful.
ColorSchemeComboBox().Focus(FocusState::Programmatic);
ColorSchemeListView().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:
// - <unused>
// Return Value:
// - <none>
void ColorSchemes::Rename_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/)
{
NameBox().Text(_ViewModel.CurrentScheme().Name());
_ViewModel.RequestEnterRename();
NameBox().Focus(FocusState::Programmatic);
NameBox().SelectAll();
}

void ColorSchemes::RenameAccept_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/)
{
_RenameCurrentScheme(NameBox().Text());
RenameButton().Focus(FocusState::Programmatic);
}

void ColorSchemes::RenameCancel_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/)
{
_ViewModel.RequestExitRename(false, {});
RenameErrorTip().IsOpen(false);
RenameButton().Focus(FocusState::Programmatic);
}

void ColorSchemes::NameBox_PreviewKeyDown(const IInspectable& /*sender*/, const winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs& e)
{
if (e.OriginalKey() == winrt::Windows::System::VirtualKey::Enter)
{
_RenameCurrentScheme(NameBox().Text());
e.Handled(true);
}
else if (e.OriginalKey() == winrt::Windows::System::VirtualKey::Escape)
if (const auto newSchemeVM{ _ViewModel.RequestAddNew() })
{
IsRenaming(false);
RenameErrorTip().IsOpen(false);
e.Handled(true);
ColorSchemeListView().SelectedItem(newSchemeVM);
ColorSchemeListView().ScrollIntoView(newSchemeVM);
}
ColorSchemeComboBox().Focus(FocusState::Programmatic);
}

void ColorSchemes::_RenameCurrentScheme(hstring newName)
void ColorSchemes::Edit_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*e*/)
{
if (_ViewModel.RequestExitRename(true, 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
{
RenameErrorTip().Target(NameBox());
RenameErrorTip().IsOpen(true);

// focus the name box
NameBox().Focus(FocusState::Programmatic);
NameBox().SelectAll();
}
_ViewModel.RequestSetCurrentPage(ColorSchemesSubPage::EditColorScheme);
}
}
10 changes: 1 addition & 9 deletions src/cascadia/TerminalSettingsEditor/ColorSchemes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void ColorSchemeSelectionChanged(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);

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);
void NameBox_PreviewKeyDown(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs& e);
void Edit_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e);

void DeleteConfirmation_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e);

WINRT_PROPERTY(Model::ColorScheme, CurrentColorScheme, nullptr);
WINRT_OBSERVABLE_PROPERTY(Editor::ColorSchemesPageViewModel, ViewModel, _PropertyChangedHandlers, nullptr);

WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
WINRT_OBSERVABLE_PROPERTY(bool, IsRenaming, _PropertyChangedHandlers, nullptr);

private:
void _RenameCurrentScheme(hstring newName);
};
}

Expand Down
2 changes: 0 additions & 2 deletions src/cascadia/TerminalSettingsEditor/ColorSchemes.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace Microsoft.Terminal.Settings.Editor
{
ColorSchemes();

Boolean IsRenaming { get; };

ColorSchemesPageViewModel ViewModel { get; };
}
}
Loading

0 comments on commit 66a7bee

Please sign in to comment.