This works to prompt before splitting a pane
This commit is contained in:
parent
7f29e1e268
commit
9b32681ae1
|
@ -251,45 +251,6 @@ namespace winrt::TerminalApp::implementation
|
|||
// - existingConnection: optionally receives a connection from the outside world instead of attempting to create one
|
||||
void TerminalPage::_CreateNewTabWithProfileAndSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult settings, TerminalConnection::ITerminalConnection existingConnection)
|
||||
{
|
||||
bool doAdminWarning = true;
|
||||
;
|
||||
const auto& cmdline{ settings.DefaultSettings().Commandline() };
|
||||
if (_isElevated())
|
||||
{
|
||||
auto allowedCommandlines{ ElevatedState::SharedInstance().AllowedCommandlines() };
|
||||
bool commandlineWasAllowed = false;
|
||||
|
||||
if (allowedCommandlines)
|
||||
{
|
||||
for (const auto& approved : allowedCommandlines)
|
||||
{
|
||||
if (approved == cmdline)
|
||||
{
|
||||
commandlineWasAllowed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
allowedCommandlines = winrt::single_threaded_vector<winrt::hstring>();
|
||||
}
|
||||
doAdminWarning = !commandlineWasAllowed;
|
||||
// if (!commandlineWasAllowed)
|
||||
// {
|
||||
// ContentDialogResult warningResult = co_await _ShowCommandlineApproveWarning();
|
||||
// if (warningResult != ContentDialogResult::Primary)
|
||||
// {
|
||||
// co_return;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// allowedCommandlines.Append(cmdline);
|
||||
// }
|
||||
// ElevatedState::SharedInstance().AllowedCommandlines(allowedCommandlines);
|
||||
// }
|
||||
}
|
||||
|
||||
// Initialize the new tab
|
||||
// Create a connection based on the values in our settings object if we weren't given one.
|
||||
auto connection = existingConnection ? existingConnection : _CreateConnectionFromSettings(profile, settings.DefaultSettings());
|
||||
|
@ -320,6 +281,9 @@ namespace winrt::TerminalApp::implementation
|
|||
// This way, when we do a settings reload we just update the parent and the overrides remain
|
||||
auto term = _InitControl(settings, connection);
|
||||
WUX::Controls::UserControl controlToAdd{ term };
|
||||
|
||||
const auto& cmdline{ settings.DefaultSettings().Commandline() };
|
||||
const bool doAdminWarning = _shouldPromptForCommandline(cmdline);
|
||||
if (doAdminWarning)
|
||||
{
|
||||
auto warningControl{ winrt::make_self<implementation::AdminWarningPlaceholder>(term, cmdline) };
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "DebugTapConnection.h"
|
||||
#include "SettingsTab.h"
|
||||
#include "RenameWindowRequestedArgs.g.cpp"
|
||||
#include "AdminWarningPlaceholder.h"
|
||||
#include "../inc/WindowingBehavior.h"
|
||||
|
||||
#include <til/latch.h>
|
||||
|
@ -1310,6 +1311,29 @@ namespace winrt::TerminalApp::implementation
|
|||
return true;
|
||||
}
|
||||
|
||||
bool TerminalPage::_shouldPromptForCommandline(const winrt::hstring& cmdline) const
|
||||
{
|
||||
bool doAdminWarning = true;
|
||||
if (_isElevated())
|
||||
{
|
||||
bool commandlineWasAllowed = false;
|
||||
|
||||
if (const auto& allowedCommandlines{ ElevatedState::SharedInstance().AllowedCommandlines() })
|
||||
{
|
||||
for (const auto& approved : allowedCommandlines)
|
||||
{
|
||||
if (approved == cmdline)
|
||||
{
|
||||
commandlineWasAllowed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
doAdminWarning = !commandlineWasAllowed;
|
||||
}
|
||||
return doAdminWarning;
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Split the focused pane either horizontally or vertically, and place the
|
||||
// given TermControl into the newly created pane.
|
||||
|
@ -1425,13 +1449,24 @@ namespace winrt::TerminalApp::implementation
|
|||
}
|
||||
|
||||
auto newControl = _InitControl(controlSettings, controlConnection);
|
||||
WUX::Controls::UserControl controlToAdd{ newControl };
|
||||
|
||||
const auto& cmdline{ controlSettings.DefaultSettings().Commandline() };
|
||||
const bool doAdminWarning = _shouldPromptForCommandline(cmdline);
|
||||
if (doAdminWarning)
|
||||
{
|
||||
auto warningControl{ winrt::make_self<implementation::AdminWarningPlaceholder>(newControl, cmdline) };
|
||||
warningControl->PrimaryButtonClicked({ get_weak(), &TerminalPage::_adminWarningPrimaryClicked });
|
||||
warningControl->CancelButtonClicked({ get_weak(), &TerminalPage::_adminWarningCancelClicked });
|
||||
controlToAdd = *warningControl;
|
||||
}
|
||||
|
||||
// Hookup our event handlers to the new terminal
|
||||
_RegisterTerminalEvents(newControl);
|
||||
|
||||
_UnZoomIfNeeded();
|
||||
|
||||
tab.SplitPane(realSplitType, splitSize, profile, newControl);
|
||||
tab.SplitPane(realSplitType, splitSize, profile, controlToAdd);
|
||||
|
||||
// After GH#6586, the control will no longer focus itself
|
||||
// automatically when it's finished being laid out. Manually focus
|
||||
|
|
|
@ -363,6 +363,7 @@ namespace winrt::TerminalApp::implementation
|
|||
|
||||
winrt::Microsoft::Terminal::Settings::Model::Profile GetClosestProfileForDuplicationOfProfile(const winrt::Microsoft::Terminal::Settings::Model::Profile& profile) const noexcept;
|
||||
|
||||
bool _shouldPromptForCommandline(const winrt::hstring& cmdline) const;
|
||||
void _adminWarningPrimaryClicked(const winrt::TerminalApp::AdminWarningPlaceholder& sender,
|
||||
const winrt::Windows::UI::Xaml::RoutedEventArgs& args);
|
||||
void _adminWarningCancelClicked(const winrt::TerminalApp::AdminWarningPlaceholder& sender,
|
||||
|
|
Loading…
Reference in a new issue