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

Code before:
    //   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) };

        // Convert the windowId to a number
        uint32_t src;
        if (!Utils::StringToUint(windowId.c_str(), src))
        {
            // Failed to convert the windowId to a number. Bail.
            co_return;
        }

        // Figure out where in the tab strip we're dropping this tab. Add that
        // index to the request. This is largely taken from the WinUI sample
        // app.

        // We need to be on OUR UI thread to figure out where we dropped
        auto weakThis{ get_weak() };
        co_await wil::resume_foreground(Dispatcher());
        if (const auto& page{ weakThis.get() })
        {
            // First we need to get the position in the List to drop to

Review comment (suggestion):
```suggestion
        const auto windowIdObj{ e.DataView().Properties().TryLookup(L"windowId") };
```

Code after:
        // 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
            // given on startup!
            if (page->_startupState == StartupState::Initialized)
            {
                page->IdentifyWindow();
            }
        }
    }

    void TerminalPage::_onTabDragStarting(const winrt::Microsoft::UI::Xaml::Controls::TabView&,
                                          const winrt::Microsoft::UI::Xaml::Controls::TabViewTabDragStartingEventArgs& e)
    {
        // Get the tab impl from this event.
        const auto eventTab = e.Tab();
        const 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.