Repository: microsoft/terminal
File: src/cascadia/TerminalApp/ActionPreviewHandlers.cpp (C++)

Code before:
        }
    }

    void TerminalPage::_PreviewAdjustOpacity(const Settings::Model::AdjustOpacityArgs& args)
    {
        const auto backup = _restorePreviewFuncs.empty();

        _ApplyToActiveControls([&](const auto& control) {
            // Stash a copy of the original opacity.
            auto originalOpacity{ control.BackgroundOpacity() };

            // Apply the new opacity
            control.AdjustOpacity(args.Opacity() / 100.0, args.Relative());

            if (backup)
            {
                _restorePreviewFuncs.emplace_back([=]() {
                    // On dismiss:
                    // Don't adjust relatively, just set outright.
                    control.AdjustOpacity(originalOpacity, false);
                });
            }
        });
    }

    void TerminalPage::_PreviewAction(const Settings::Model::ActionAndArgs& args)
    {
        switch (args.Action())
        {
        case ShortcutAction::SetColorScheme:
        {
            _PreviewColorScheme(args.Args().try_as<SetColorSchemeArgs>());
            break;
        }
        case ShortcutAction::AdjustOpacity:
        {
            _PreviewAdjustOpacity(args.Args().try_as<AdjustOpacityArgs>());
            break;
        }
        }

        // GH#9818 Other ideas for actions that could be preview-able:
        // * Set Font size
        // * Set acrylic true/false/opacity?
        // * SetPixelShaderPath?
        // * SetWindowTheme (light/dark/system/<some theme from #3327>)?

        // Stash this action, so we know what to do when we're done
        // previewing.
        _lastPreviewedAction = args;
    }

Review comment (refactor):
Does it make sense to call this function from `_PreviewActionHandler` to deduplicate the code?

Code after:
        }
    }

    void TerminalPage::_PreviewAdjustOpacity(const Settings::Model::AdjustOpacityArgs& args)
    {
        const auto backup = _restorePreviewFuncs.empty();

        _ApplyToActiveControls([&](const auto& control) {
            // Stash a copy of the original opacity.
            auto originalOpacity{ control.BackgroundOpacity() };

            // Apply the new opacity
            control.AdjustOpacity(args.Opacity() / 100.0, args.Relative());

            if (backup)
            {
                _restorePreviewFuncs.emplace_back([=]() {
                    // On dismiss:
                    // Don't adjust relatively, just set outright.
                    control.AdjustOpacity(originalOpacity, false);
                });
            }
        });
    }

    void TerminalPage::_PreviewAction(const Settings::Model::ActionAndArgs& args)
    {
        switch (args.Action())
        {
        case ShortcutAction::SetColorScheme:
            _PreviewColorScheme(args.Args().try_as<SetColorSchemeArgs>());
            break;
        case ShortcutAction::AdjustOpacity:
            _PreviewAdjustOpacity(args.Args().try_as<AdjustOpacityArgs>());
            break;
        }

        // GH#9818 Other ideas for actions that could be preview-able:
        // * Set Font size
        // * Set acrylic true/false/opacity?
        // * SetPixelShaderPath?
        // * SetWindowTheme (light/dark/system/<some theme from #3327>)?

        // Stash this action, so we know what to do when we're done
        // previewing.
        _lastPreviewedAction = args;
    }

    // Method Description:
    // - Handler for the CommandPalette::PreviewAction event. The Command
    //   Palette will raise this even when an action is selected, but _not_