previewing too is good

This commit is contained in:
Mike Griese 2021-11-08 11:03:27 -06:00
parent 645610865c
commit 0c33dca1e8
6 changed files with 52 additions and 3 deletions

View file

@ -49,8 +49,9 @@ namespace winrt::TerminalApp::implementation
switch (_lastPreviewedCommand.ActionAndArgs().Action())
{
case ShortcutAction::SetColorScheme:
case ShortcutAction::AdjustOpacity:
{
_EndPreviewColorScheme();
_RunRestorePreviews();
break;
}
}
@ -65,7 +66,7 @@ namespace winrt::TerminalApp::implementation
// - <none>
// Return Value:
// - <none>
void TerminalPage::_EndPreviewColorScheme()
void TerminalPage::_RunRestorePreviews()
{
for (const auto& f : _restorePreviewFuncs)
{
@ -109,6 +110,30 @@ namespace winrt::TerminalApp::implementation
}
}
void TerminalPage::_PreviewAdjustOpacity(const Settings::Model::AdjustOpacityArgs& args)
{
// if (const auto& scheme{ _settings.GlobalSettings().ColorSchemes().TryLookup(args.SchemeName()) })
// {
// Clear the saved preview funcs because we don't need to add a restore each time
// the preview color changes, we only need to be able to restore the last one.
_restorePreviewFuncs.clear();
_ApplyToActiveControls([&](const auto& control) {
// Stash a copy of the original scheme.
auto originalOpacity{ control.BackgroundOpacity() };
// Apply the new opacity
control.AdjustOpacity(args.Opacity(), args.Relative());
_restorePreviewFuncs.emplace_back([=]() {
// On dismiss:
// Don't adjust relatively, just set outright.
control.AdjustOpacity(::base::saturated_cast<int>(originalOpacity*100), false);
});
});
// }
}
// Method Description:
// - Handler for the CommandPalette::PreviewAction event. The Command
// Palette will raise this even when an action is selected, but _not_
@ -140,6 +165,11 @@ namespace winrt::TerminalApp::implementation
_PreviewColorScheme(args.ActionAndArgs().Args().try_as<SetColorSchemeArgs>());
break;
}
case ShortcutAction::AdjustOpacity:
{
_PreviewAdjustOpacity(args.ActionAndArgs().Args().try_as<AdjustOpacityArgs>());
break;
}
}
// GH#9818 Other ideas for actions that could be preview-able:

View file

@ -383,8 +383,9 @@ namespace winrt::TerminalApp::implementation
void _PreviewActionHandler(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::Command& args);
void _EndPreview();
void _EndPreviewColorScheme();
void _RunRestorePreviews();
void _PreviewColorScheme(const Microsoft::Terminal::Settings::Model::SetColorSchemeArgs& args);
void _PreviewAdjustOpacity(const Microsoft::Terminal::Settings::Model::AdjustOpacityArgs& args);
winrt::Microsoft::Terminal::Settings::Model::Command _lastPreviewedCommand{ nullptr };
std::vector<std::function<void()>> _restorePreviewFuncs{};

View file

@ -24,5 +24,6 @@ namespace Microsoft.Terminal.Control
Microsoft.Terminal.TerminalConnection.ConnectionState ConnectionState { get; };
Microsoft.Terminal.Core.Scheme ColorScheme { get; set; };
};
}

View file

@ -2658,4 +2658,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_core.AdjustOpacity(opacity, relative);
}
// - You'd think this should just be "Opacity", but UIElement already
// defines an "Opacity", which we're actually not setting at all. We're
// not overriding or changing _that_ value. Callers that want the opacity
// set by the settings should call this instead.
double TermControl::BackgroundOpacity() const
{
return _core.Opacity();
}
}

View file

@ -58,6 +58,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
int BufferHeight() const;
bool BracketedPasteEnabled() const noexcept;
double BackgroundOpacity() const;
#pragma endregion
void ScrollViewport(int viewTop);

View file

@ -74,5 +74,12 @@ namespace Microsoft.Terminal.Control
String ReadEntireBuffer();
void AdjustOpacity(Int32 Opacity, Boolean relative);
// You'd think this should just be "Opacity", but UIElement already
// defines an "Opacity", which we're actually not setting at all. We're
// not overriding or changing _that_ value. Callers that want the
// opacity set by the settings should call this instead.
Double BackgroundOpacity { get; };
}
}