diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 10a7f8cfa3..cda04cf6f8 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -8,6 +8,7 @@ #include "../WinRTUtils/inc/WtExeUtils.h" #include "../../types/inc/utils.hpp" #include "Utils.h" +#include using namespace winrt::Windows::ApplicationModel::DataTransfer; using namespace winrt::Windows::UI::Xaml; @@ -189,7 +190,8 @@ namespace winrt::TerminalApp::implementation } else if (const auto& realArgs = args.ActionArgs().try_as()) { - if (const auto& newTerminalArgs{ realArgs.TerminalArgs() }) + const auto& newTerminalArgs{ realArgs.TerminalArgs() }; + if (newTerminalArgs) { if (const auto index = realArgs.TerminalArgs().ProfileIndex()) { @@ -204,7 +206,19 @@ namespace winrt::TerminalApp::implementation _SplitPane(realArgs.SplitDirection(), // This is safe, we're already filtering so the value is (0, 1) ::base::saturated_cast(realArgs.SplitSize()), - _MakePane(realArgs.TerminalArgs(), realArgs.SplitMode() == SplitType::Duplicate)); + _MakePane(newTerminalArgs, realArgs.SplitMode() == SplitType::Duplicate)); + + if (!_processingCommandlineArgs) + { + if (auto autoPeer = Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this)) + { + autoPeer.RaiseNotificationEvent( + Automation::Peers::AutomationNotificationKind::ActionCompleted, + Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent, + fmt::format(std::wstring_view{ RS_(L"SplitPaneAnnouncement") }, _settings.GetProfileForArgs(newTerminalArgs).Name()), + L"NewSplitPane" /* unique name for this notification category */); + } + } args.Handled(true); } } @@ -378,7 +392,21 @@ namespace winrt::TerminalApp::implementation } } - LOG_IF_FAILED(_OpenNewTab(realArgs.TerminalArgs())); + const auto& newTerminalArgs = realArgs.TerminalArgs(); + LOG_IF_FAILED(_OpenNewTab(newTerminalArgs)); + if (!_processingCommandlineArgs) + { + if (auto autoPeer = Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this)) + { + // we can't check if this is a leaf pane, + // but getting the profile returns null if we aren't, so that works! + autoPeer.RaiseNotificationEvent( + Automation::Peers::AutomationNotificationKind::ActionCompleted, + Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent, + fmt::format(std::wstring_view{ RS_(L"NewTabAnnouncement") }, _settings.GetProfileForArgs(newTerminalArgs).Name()), + L"NewTab" /* unique name for this notification category */); + } + } args.Handled(true); } } diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index 4f9ef8b174..689294ec24 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -288,20 +288,6 @@ namespace winrt::TerminalApp::implementation { auto newTabImpl = winrt::make_self(pane); _InitializeTab(newTabImpl); - - if (_autoPeer) - { - // we can't check if this is a leaf pane, - // but getting the profile returns null if we aren't, so that works! - if (const auto profile{ pane->GetProfile() }) - { - _autoPeer.RaiseNotificationEvent( - Automation::Peers::AutomationNotificationKind::ActionCompleted, - Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent, - fmt::format(std::wstring_view{ RS_(L"NewTabAnnouncement") }, profile.Name()), - L"NewTab" /* unique name for this notification category */); - } - } } } @@ -384,6 +370,17 @@ namespace winrt::TerminalApp::implementation newTab->SetTabText(runtimeTabText); } } + + if (auto autoPeer = Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this)) + { + // we can't check if this is a leaf pane, + // but getting the profile returns null if we aren't, so that works! + autoPeer.RaiseNotificationEvent( + Automation::Peers::AutomationNotificationKind::ActionCompleted, + Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent, + fmt::format(std::wstring_view{ RS_(L"NewTabAnnouncement") }, _settings.FindProfile(_settings.GlobalSettings().DefaultProfile()).Name()), + L"NewTab" /* unique name for this notification category */); + } } CATCH_LOG(); } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 8efbe6ca50..b353ad4bd3 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -302,8 +302,7 @@ namespace winrt::TerminalApp::implementation Automation::Peers::AutomationPeer TerminalPage::OnCreateAutomationPeer() { - _autoPeer = Automation::Peers::FrameworkElementAutomationPeer(*this); - return _autoPeer; + return Automation::Peers::FrameworkElementAutomationPeer(*this); } // Method Description; @@ -636,6 +635,11 @@ namespace winrt::TerminalApp::implementation if (auto page{ weakThis.get() }) { + page->_processingCommandlineArgs = true; + auto finishProcessing = wil::scope_exit([&page]() { + page->_processingCommandlineArgs = false; + }); + for (const auto& action : actions) { if (auto page{ weakThis.get() }) @@ -1038,10 +1042,29 @@ namespace winrt::TerminalApp::implementation this->_SplitPane(SplitDirection::Automatic, 0.5f, newPane); + + if (auto autoPeer = Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this)) + { + autoPeer.RaiseNotificationEvent( + Automation::Peers::AutomationNotificationKind::ActionCompleted, + Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent, + fmt::format(std::wstring_view{ RS_(L"SplitPaneAnnouncement") }, _settings.GetProfileForArgs(newTerminalArgs).Name()), + L"NewSplitPane" /* unique name for this notification category */); + } } else { _CreateNewTabFromPane(newPane); + if (auto autoPeer = Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this)) + { + // we can't check if this is a leaf pane, + // but getting the profile returns null if we aren't, so that works! + autoPeer.RaiseNotificationEvent( + Automation::Peers::AutomationNotificationKind::ActionCompleted, + Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent, + fmt::format(std::wstring_view{ RS_(L"NewTabAnnouncement") }, _settings.GetProfileForArgs(newTerminalArgs).Name()), + L"NewTab" /* unique name for this notification category */); + } } } } @@ -1855,20 +1878,6 @@ namespace winrt::TerminalApp::implementation _UnZoomIfNeeded(); tab.SplitPane(*realSplitType, splitSize, newPane); - if (_autoPeer) - { - // we can't check if this is a leaf pane, - // but getting the profile returns null if we aren't, so that works! - if (const auto profile{ newPane->GetProfile() }) - { - _autoPeer.RaiseNotificationEvent( - Automation::Peers::AutomationNotificationKind::ActionCompleted, - Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent, - fmt::format(std::wstring_view{ RS_(L"SplitPaneAnnouncement") }, profile.Name()), - L"NewSplitPane" /* unique name for this notification category */); - } - } - // After GH#6586, the control will no longer focus itself // automatically when it's finished being laid out. Manually focus // the control here instead. diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 5ae471b7ca..e77cf6f521 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -163,7 +163,6 @@ namespace winrt::TerminalApp::implementation private: friend struct TerminalPageT; // for Xaml to bind events - Windows::UI::Xaml::Automation::Peers::AutomationPeer _autoPeer{ nullptr }; std::optional _hostingHwnd; // If you add controls here, but forget to null them either here or in @@ -204,6 +203,7 @@ namespace winrt::TerminalApp::implementation bool _activated{ false }; bool _visible{ true }; + bool _processingCommandlineArgs{ false }; std::vector> _previouslyClosedPanesAndTabs{};