Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show a preview of the control in the SUI #9527

Merged
merged 34 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
655e277
initial
PankajBhojwani Mar 17, 2021
df21383
conflict
PankajBhojwani Mar 18, 2021
8fb913b
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Mar 18, 2021
4573552
nits
PankajBhojwani Mar 22, 2021
fb498a2
merge main, remove input, move preview to above pivot
PankajBhojwani Apr 5, 2021
e169044
preview text with color, update the control size with the window size
PankajBhojwani Apr 5, 2021
bab15fa
format
PankajBhojwani Apr 5, 2021
40b8dab
reduce height, make not focusable
PankajBhojwani Apr 8, 2021
3884568
conflict
PankajBhojwani Apr 13, 2021
ae344fc
no more localized text, control-style preview text
PankajBhojwani Apr 13, 2021
69f88aa
remove visual state manager
PankajBhojwani Apr 13, 2021
4929ac5
disable cursor blinking
PankajBhojwani Apr 13, 2021
24e2f4d
fake tab
PankajBhojwani Apr 14, 2021
d0d85bd
format
PankajBhojwani Apr 14, 2021
0ab99f2
tab color
PankajBhojwani Apr 19, 2021
db1fd7f
tab display name
PankajBhojwani Apr 19, 2021
e0a300f
notify xaml
PankajBhojwani Apr 19, 2021
bf90b2e
move to under appearance, smaller width, scrolls
PankajBhojwani Apr 22, 2021
1a09e83
nits
PankajBhojwani Apr 22, 2021
61ca463
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Apr 23, 2021
1352f13
manually implement setter for settings to reduce diff
PankajBhojwani Apr 23, 2021
fe634d0
fix extra space
PankajBhojwani Apr 26, 2021
33607fe
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Apr 26, 2021
2f205c1
constrain width
PankajBhojwani Apr 26, 2021
e8bc850
Remove tab display name
PankajBhojwani Apr 28, 2021
78d96a6
1px border
PankajBhojwani Apr 30, 2021
53ab5f7
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Apr 30, 2021
0a4b532
format
PankajBhojwani Apr 30, 2021
40bdb2d
fix padding issue
PankajBhojwani May 3, 2021
a539f5c
use TC width/height, border brush
PankajBhojwani May 5, 2021
40f353b
conflict, brush
PankajBhojwani May 12, 2021
540bdf6
format
PankajBhojwani May 12, 2021
1d171d1
remove padding fix
PankajBhojwani May 12, 2021
64708e4
Update src/cascadia/TerminalSettingsEditor/PreviewConnection.cpp
DHowett May 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _settings;
}

void TermControl::Settings(IControlSettings newSettings)
{
_settings = newSettings;
}

Windows::Foundation::IReference<winrt::Windows::UI::Color> TermControl::TabColor() noexcept
{
// NOTE TO FUTURE READERS: TabColor is down in the Core for the
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const Windows::UI::Xaml::Thickness GetPadding();

IControlSettings Settings() const;
void Settings(IControlSettings newSettings);
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved

static Windows::Foundation::Size GetProposedDimensions(IControlSettings const& settings, const uint32_t dpi);
static Windows::Foundation::Size GetProposedDimensions(const winrt::Windows::Foundation::Size& initialSizeInChars,
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.Terminal.Control

void UpdateSettings();

Microsoft.Terminal.Control.IControlSettings Settings { get; };
Microsoft.Terminal.Control.IControlSettings Settings;
Microsoft.Terminal.Control.IControlAppearance UnfocusedAppearance;

event FontSizeChangedEventArgs FontSizeChanged;
Expand Down
8 changes: 4 additions & 4 deletions src/cascadia/TerminalSettingsEditor/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ static const std::wstring_view globalAppearanceTag{ L"GlobalAppearance_Nav" };

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
static Editor::ProfileViewModel _viewModelForProfile(const Model::Profile& profile)
static Editor::ProfileViewModel _viewModelForProfile(const Model::Profile& profile, const Model::CascadiaSettings& appSettings)
{
return winrt::make<implementation::ProfileViewModel>(profile);
return winrt::make<implementation::ProfileViewModel>(profile, appSettings);
}

MainPage::MainPage(const CascadiaSettings& settings) :
Expand Down Expand Up @@ -368,7 +368,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// profile changes.
for (const auto& profile : _settingsClone.AllProfiles())
{
auto navItem = _CreateProfileNavViewItem(_viewModelForProfile(profile));
auto navItem = _CreateProfileNavViewItem(_viewModelForProfile(profile, _settingsClone));
SettingsNav().MenuItems().Append(navItem);
}

Expand All @@ -388,7 +388,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void MainPage::_CreateAndNavigateToNewProfile(const uint32_t index, const Model::Profile& profile)
{
const auto newProfile{ profile ? profile : _settingsClone.CreateNewProfile() };
const auto profileViewModel{ _viewModelForProfile(newProfile) };
const auto profileViewModel{ _viewModelForProfile(newProfile, _settingsClone) };
const auto navItem{ _CreateProfileNavViewItem(profileViewModel) };
SettingsNav().MenuItems().InsertAt(index, navItem);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<DependentUpon>SettingContainer.idl</DependentUpon>
</ClInclude>
<ClInclude Include="Utils.h" />
<ClInclude Include="PreviewConnection.h" />
</ItemGroup>
<!-- ========================= XAML files ======================== -->
<ItemGroup>
Expand Down Expand Up @@ -208,6 +209,9 @@
<DependentUpon>SettingContainer.idl</DependentUpon>
</ClCompile>
<ClCompile Include="Utils.cpp" />
<ClCompile Include="PreviewConnection.cpp">
<DependentUpon>PreviewConnection.h</DependentUpon>
</ClCompile>
</ItemGroup>
<!-- ========================= idl Files ======================== -->
<ItemGroup>
Expand Down
38 changes: 38 additions & 0 deletions src/cascadia/TerminalSettingsEditor/PreviewConnection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "PreviewConnection.h"
#include <LibraryResources.h>

using namespace ::winrt::Microsoft::Terminal::TerminalConnection;
using namespace ::winrt::Windows::Foundation;

static constexpr std::wstring_view PreviewText{ L"Windows Terminal\r\nCopyright (c) Microsoft Corporation.\r\n\nC:\\Windows\\Terminal> " };
DHowett marked this conversation as resolved.
Show resolved Hide resolved

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
PreviewConnection::PreviewConnection() noexcept
{
}

void PreviewConnection::Start() noexcept
{
// First send a sequence to disable cursor blinking
_TerminalOutputHandlers(L"\x1b[?12l");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very clever. we do also remove the cursor when it loses focus, though, too.

Copy link
Contributor Author

@PankajBhojwani PankajBhojwani Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the preview control is no longer enabled nor focusable (see Profiles.cpp lines 484-485) - so the cursor just stays on and with this sequence it doesn't blink

// Send the preview text
_TerminalOutputHandlers(PreviewText);
}

void PreviewConnection::WriteInput(hstring const& /*data*/)
{
}

void PreviewConnection::Resize(uint32_t /*rows*/, uint32_t /*columns*/) noexcept
{
}
Comment on lines +31 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure to test what happens when you resize the window and the TermControl doesn't fit (or resizes). Idk how difficult it would be to add reflow, but I'm guessing we need something here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflow will be impossible. On resize, the connection should simply clear the terminal and re-print the entire preview text.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this is that resize is a destructive operation when content is pushed off the top of the screen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method still needs to be implemented for that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method still needs to be implemented for that right?

Ah it actually doesn't! The connection doesn't need to do anything

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, no.. on resize, the connection must re-print the entire preview text. Resize with reflow destroys the content that goes off the top of the screen, and the connection needs to clear the screen and put it back. Now, since we never resize the control this isn't going to be a problem... but do keep it in mind.


void PreviewConnection::Close() noexcept
{
}
}
35 changes: 35 additions & 0 deletions src/cascadia/TerminalSettingsEditor/PreviewConnection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
//
// Module Name:
// - PreviewConnection.h
//
// Abstract:
// - This class is used to initialize the preview TermControl in the Settings UI
//
// Author:
// - Pankaj Bhojwani March-2021

#pragma once

#include <winrt/Microsoft.Terminal.TerminalConnection.h>
#include "../../inc/cppwinrt_utils.h"

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
class PreviewConnection : public winrt::implements<PreviewConnection, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection>
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
{
public:
PreviewConnection() noexcept;

void Start() noexcept;
void WriteInput(hstring const& data);
void Resize(uint32_t rows, uint32_t columns) noexcept;
void Close() noexcept;

winrt::Microsoft::Terminal::TerminalConnection::ConnectionState State() const noexcept { return winrt::Microsoft::Terminal::TerminalConnection::ConnectionState::Connected; }

WINRT_CALLBACK(TerminalOutput, winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler);
TYPED_EVENT(StateChanged, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection, IInspectable);
};
}
28 changes: 25 additions & 3 deletions src/cascadia/TerminalSettingsEditor/Profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "pch.h"
#include "Profiles.h"
#include "PreviewConnection.h"
#include "Profiles.g.cpp"
#include "EnumEntry.h"

Expand Down Expand Up @@ -85,9 +86,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Windows::Foundation::Collections::IObservableVector<Editor::Font> ProfileViewModel::_MonospaceFontList{ nullptr };
Windows::Foundation::Collections::IObservableVector<Editor::Font> ProfileViewModel::_FontList{ nullptr };

ProfileViewModel::ProfileViewModel(const Model::Profile& profile) :
ProfileViewModel::ProfileViewModel(const Model::Profile& profile, const Model::CascadiaSettings& appSettings) :
_profile{ profile },
_ShowAllFonts{ false }
_ShowAllFonts{ false },
_appSettings{ appSettings }
{
// Add a property changed handler to our own property changed event.
// This propagates changes from the settings model to anybody listening to our
Expand Down Expand Up @@ -147,6 +149,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}

Model::TerminalSettings ProfileViewModel::TermSettings() const
{
return Model::TerminalSettings::CreateWithProfileByID(_appSettings, _profile.Guid(), nullptr).DefaultSettings();
}

// Method Description:
// - Updates the lists of fonts and sorts them alphabetically
void ProfileViewModel::UpdateFontList() noexcept
Expand Down Expand Up @@ -428,7 +435,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}

Profiles::Profiles() :
_ColorSchemeList{ single_threaded_observable_vector<ColorScheme>() }
_ColorSchemeList{ single_threaded_observable_vector<ColorScheme>() },
_previewControl{ Control::TermControl(Model::TerminalSettings{}, make<PreviewConnection>()) }
{
InitializeComponent();

Expand Down Expand Up @@ -472,6 +480,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Automation::AutomationProperties::SetFullDescription(ShowAllFontsCheckbox(), unbox_value<hstring>(showAllFontsCheckboxTooltip));

Automation::AutomationProperties::SetName(DeleteButton(), RS_(L"Profile_DeleteButton/Text"));

_previewControl.IsEnabled(false);
_previewControl.AllowFocusWhenDisabled(false);
ControlPreview().Child(_previewControl);
}

IInspectable Profiles::CurrentFontFace() const
Expand Down Expand Up @@ -596,10 +608,20 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
_UpdateBIAlignmentControl(static_cast<int32_t>(_State.Profile().BackgroundImageAlignment()));
}
_previewControl.Settings(_State.Profile().TermSettings());
_previewControl.UpdateSettings();
});

// Navigate to the pivot in the provided navigation state
ProfilesPivot().SelectedIndex(static_cast<int>(_State.LastActivePivot()));

_previewControl.Settings(_State.Profile().TermSettings());
// There is a possibility that the control has not fully initialized yet,
// so wait for it to initialize before updating the settings (so we know
// that the renderer is set up)
_previewControl.Initialized([&](auto&& /*s*/, auto&& /*e*/) {
_previewControl.UpdateSettings();
});
}

void Profiles::OnNavigatedFrom(const NavigationEventArgs& /*e*/)
Expand Down
8 changes: 7 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
struct ProfileViewModel : ProfileViewModelT<ProfileViewModel>, ViewModelHelper<ProfileViewModel>
{
public:
ProfileViewModel(const Model::Profile& profile);
ProfileViewModel(const Model::Profile& profile, const Model::CascadiaSettings& settings);

Model::TerminalSettings TermSettings() const;

// background image
bool UseDesktopBGImage();
Expand Down Expand Up @@ -110,6 +112,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
static Windows::Foundation::Collections::IObservableVector<Editor::Font> _FontList;

static Editor::Font _GetFont(com_ptr<IDWriteLocalizedStrings> localizedFamilyNames);

Model::CascadiaSettings _appSettings;
};

struct DeleteProfileEventArgs :
Expand Down Expand Up @@ -207,6 +211,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Editor::EnumEntry _CustomFontWeight{ nullptr };
std::array<Windows::UI::Xaml::Controls::Primitives::ToggleButton, 9> _BIAlignmentButtons;
Windows::UI::Xaml::Data::INotifyPropertyChanged::PropertyChanged_revoker _ViewModelChangedRevoker;

Microsoft::Terminal::Control::TermControl _previewControl;
};
};

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/Profiles.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microsoft.Terminal.Settings.Editor
{
Windows.Foundation.Collections.IObservableVector<Font> CompleteFontList { get; };
Windows.Foundation.Collections.IObservableVector<Font> MonospaceFontList { get; };
Microsoft.Terminal.Settings.Model.TerminalSettings TermSettings { get; };

Boolean CanDeleteProfile { get; };
Boolean UsingMonospaceFont { get; };
Expand Down
8 changes: 7 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Profiles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<TextBlock FontFamily="{x:Bind Name}"
Text="{x:Bind LocalizedName}" />
</DataTemplate>

<local:ColorToBrushConverter x:Key="ColorToBrushConverter" />
<local:PercentageConverter x:Key="PercentageConverter" />
<local:FontWeightConverter x:Key="FontWeightConverter" />
Expand Down Expand Up @@ -238,6 +237,13 @@
<ScrollViewer>
<StackPanel>
<StackPanel Style="{StaticResource PivotStackStyle}">
<!-- Control Preview -->
<Border x:Name="ControlPreview"
Width="350"
Height="160"
BorderBrush="{ThemeResource SystemControlForegroundBaseMediumLowBrush}"
BorderThickness="1" />

<!-- Grouping: Text -->
<TextBlock x:Uid="Profile_TextHeader"
Style="{StaticResource SubtitleTextBlockStyle}" />
Expand Down