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

Code before:

    void TerminalPage::_onTabStripDragOver(winrt::Windows::Foundation::IInspectable /*sender*/,
                                           winrt::Windows::UI::Xaml::DragEventArgs e)
    {
        // We must mark that we can accept the drag/drop. The system will never
        // call TabStripDrop on us if we don't indicate that we're willing.
        if (e.DataView().Properties().HasKey(L"windowId"))
        {
            e.AcceptedOperation(DataPackageOperation::Move);
        }

        // You may think to yourself, this is a great place to increase the
        // width of the TabView artificially, to make room for the new tab item.
        // However, we'll never get a message that the tab left the tab view
        // (without being dropped). So there's no good way to resize back down.
    }

    // Method Description:
    // - Called on the TARGET of a tab drag/drop. We'll unpack the DataPackage
    //   to find who the tab came from. We'll then ask the Monarch to ask the
    //   sender to move that tab to us.
    winrt::fire_and_forget TerminalPage::_onTabStripDrop(winrt::Windows::Foundation::IInspectable /*sender*/,
                                                         winrt::Windows::UI::Xaml::DragEventArgs e)
    {
        // Get the PID and make sure it is the same as ours.
        if (auto pidObj{ e.DataView().Properties().TryLookup(L"pid") })
        {
            const auto pidStr{ winrt::unbox_value<winrt::hstring>(pidObj) };
            uint32_t pidNum;
            if (Utils::StringToUint(pidStr.c_str(), pidNum))
            {
                if (pidNum != GetCurrentProcessId())
                {
                    // The PID doesn't match ours. We can't handle this drop.
                    co_return;
                }
            }
        }
        else
        {
            // No PID? We can't handle this drop. Bail.
            co_return;
        }

        auto windowIdObj{ e.DataView().Properties().TryLookup(L"windowId") };
        if (windowIdObj == nullptr)
        {
            // No windowId? Bail.
            co_return;
        }
        const auto windowId{ winrt::unbox_value<winrt::hstring>(windowIdObj) };

Review comment (suggestion):
```suggestion
        if (const auto pidObj{ e.DataView().Properties().TryLookup(L"pid") })
```

Code after:

        auto makeItem = [&menu, &makeCallback](const winrt::hstring& label,
                                               const winrt::hstring& icon,
                                               const auto& action) {
            AppBarButton button{};

            if (!icon.empty())
            {
                auto iconElement = IconPathConverter::IconWUX(icon);
                Automation::AutomationProperties::SetAccessibilityView(iconElement, Automation::Peers::AccessibilityView::Raw);
                button.Icon(iconElement);
            }

            button.Label(label);
            button.Click(makeCallback(action));
            menu.SecondaryCommands().Append(button);
        };

        // Wire up each item to the action that should be performed. By actually
        // connecting these to actions, we ensure the implementation is
        // consistent. This also leaves room for customizing this menu with
        // actions in the future.

        makeItem(RS_(L"SplitPaneText"), L"\xF246", ActionAndArgs{ ShortcutAction::SplitPane, SplitPaneArgs{ SplitType::Duplicate } });
        makeItem(RS_(L"DuplicateTabText"), L"\xF5ED", ActionAndArgs{ ShortcutAction::DuplicateTab, nullptr });

        // Only wire up "Close Pane" if there's multiple panes.
        if (_GetFocusedTabImpl()->GetLeafPaneCount() > 1)
        {
            makeItem(RS_(L"PaneClose"), L"\xE89F", ActionAndArgs{ ShortcutAction::ClosePane, nullptr });
        }

        makeItem(RS_(L"TabClose"), L"\xE711", ActionAndArgs{ ShortcutAction::CloseTab, CloseTabArgs{ _GetFocusedTabIndex().value() } });
    }

    // Handler for our WindowProperties's PropertyChanged event. We'll use this
    // to pop the "Identify Window" toast when the user renames our window.
    winrt::fire_and_forget TerminalPage::_windowPropertyChanged(const IInspectable& /*sender*/,
                                                                const WUX::Data::PropertyChangedEventArgs& args)
    {
        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