don't notify on commandline args; don't cache autoPeer

This commit is contained in:
Carlos Zamora
2022-07-28 16:08:54 -07:00
parent 0473430282
commit fd19751aef
4 changed files with 68 additions and 34 deletions

View File

@@ -8,6 +8,7 @@
#include "../WinRTUtils/inc/WtExeUtils.h"
#include "../../types/inc/utils.hpp"
#include "Utils.h"
#include <LibraryResources.h>
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<SplitPaneArgs>())
{
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<float>(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);
}
}

View File

@@ -288,20 +288,6 @@ namespace winrt::TerminalApp::implementation
{
auto newTabImpl = winrt::make_self<TerminalTab>(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();
}

View File

@@ -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.

View File

@@ -163,7 +163,6 @@ namespace winrt::TerminalApp::implementation
private:
friend struct TerminalPageT<TerminalPage>; // for Xaml to bind events
Windows::UI::Xaml::Automation::Peers::AutomationPeer _autoPeer{ nullptr };
std::optional<HWND> _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<std::vector<Microsoft::Terminal::Settings::Model::ActionAndArgs>> _previouslyClosedPanesAndTabs{};