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

Code before:
    {
        if (args.PropertyName() != L"WindowName")
        {
            co_return;
        }
        auto weakThis{ get_weak() };
        // On the foreground thread, raise property changed notifications, and
        // display the success toast.
        co_await wil::resume_foreground(Dispatcher());
        if (auto page{ weakThis.get() })
        {
            // DON'T display the confirmation if this is the name we were
            // given on startup!
            if (page->_startupState == StartupState::Initialized)
            {
                page->IdentifyWindow();
            }
        }
    }

    void TerminalPage::_onTabDragStarting(winrt::Microsoft::UI::Xaml::Controls::TabView sender,
                                          winrt::Microsoft::UI::Xaml::Controls::TabViewTabDragStartingEventArgs e)
    {
        // Get the tab impl from this event.
        auto eventTab = e.Tab();
        auto tabBase = _GetTabByTabViewItem(eventTab);
        winrt::com_ptr<TabBase> tabImpl;
        tabImpl.copy_from(winrt::get_self<TabBase>(tabBase));
        if (tabImpl)
        {
            // First: stash the tab we started dragging.
            // We're going to be asked for this.
            _stashedDraggedTab = tabImpl;

            // Into the DataPackage, let's stash our own window ID.
            const winrt::hstring id{ fmt::format(L"{}", _WindowProperties.WindowId()) };

            // Get our PID
            const winrt::hstring pid{ fmt::format(L"{}", GetCurrentProcessId()) };

            e.Data().Properties().Insert(L"windowId", winrt::box_value(id));
            e.Data().Properties().Insert(L"pid", winrt::box_value(pid));
            e.Data().RequestedOperation(DataPackageOperation::Move);

            // The next thing that will happen:
            //  * Another TerminalPage will get a TabStripDragOver, then get a
            //    TabStripDrop
            //    * This will be handled by the _other_ page asking the monarch
            //      to ask us to send our content to them.
            //  * We'll get a TabDroppedOutside to indicate that this tab was
            //    dropped _not_ on a TabView.

Review comment (suggestion):
```suggestion
        const auto eventTab = e.Tab();
        const auto tabBase = _GetTabByTabViewItem(eventTab);
```

Code after:
        else
        {
            // DON'T use Transparent here - if it's "Transparent", then it won't
            // be able to hittest for clicks, and then clicking on the border
            // will eat focus.
            _paneResources.unfocusedBorderBrush = SolidColorBrush{ Colors::Black() };
        }
    }

    void TerminalPage::WindowActivated(const bool activated)
    {
        // Stash if we're activated. Use that when we reload
        // the settings, change active panes, etc.
        _activated = activated;
        _updateThemeColors();
    }

    void TerminalPage::_ContextMenuOpened(const IInspectable& sender,
                                          const IInspectable& /*args*/)
    {
        _PopulateContextMenu(sender, false /*withSelection*/);
    }
    void TerminalPage::_SelectionMenuOpened(const IInspectable& sender,
                                            const IInspectable& /*args*/)
    {
        _PopulateContextMenu(sender, true /*withSelection*/);
    }

    void TerminalPage::_PopulateContextMenu(const IInspectable& sender,
                                            const bool /*withSelection*/)
    {
        // withSelection can be used to add actions that only appear if there's
        // selected text, like "search the web". In this initial draft, it's not
        // actually augmented by the TerminalPage, so it's left commented out.

        const auto& menu{ sender.try_as<MUX::Controls::CommandBarFlyout>() };
        if (!menu)
        {
            return;
        }

        // Helper lambda for dispatching an ActionAndArgs onto the
        // ShortcutActionDispatch. Used below to wire up each menu entry to the
        // respective action.

        auto weak = get_weak();
        auto makeCallback = [weak](const ActionAndArgs& actionAndArgs) {
            return [weak, actionAndArgs](auto&&, auto&&) {
                if (auto page{ weak.get() })
                {
                    page->_actionDispatch->DoAction(actionAndArgs);