Skip to content

Commit

Permalink
Allow a TerminalTab to have a UserControl
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Sep 1, 2021
1 parent ed1cf2a commit 1ee3522
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
30 changes: 16 additions & 14 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ namespace winrt::TerminalApp::implementation
// - profile: profile settings for this connection
// - settings: the TerminalSettings object to use to create the TerminalControl with.
// - existingConnection: optionally receives a connection from the outside world instead of attempting to create one
winrt::fire_and_forget TerminalPage::_CreateNewTabWithProfileAndSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult settings, TerminalConnection::ITerminalConnection existingConnection)
void TerminalPage::_CreateNewTabWithProfileAndSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult settings, TerminalConnection::ITerminalConnection existingConnection)
{
bool doAdminWarning = false;
if (_isElevated())
{
auto cmdline{ settings.DefaultSettings().Commandline() };
Expand All @@ -271,19 +272,20 @@ namespace winrt::TerminalApp::implementation
{
allowedCommandlines = winrt::single_threaded_vector<winrt::hstring>();
}
if (!commandlineWasAllowed)
{
ContentDialogResult warningResult = co_await _ShowCommandlineApproveWarning();
if (warningResult != ContentDialogResult::Primary)
{
co_return;
}
else
{
allowedCommandlines.Append(cmdline);
}
ElevatedState::SharedInstance().AllowedCommandlines(allowedCommandlines);
}
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
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace winrt::TerminalApp::implementation
void _OpenNewTabDropdown();
HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr);
void _CreateNewTabFromPane(std::shared_ptr<Pane> pane);
winrt::fire_and_forget _CreateNewTabWithProfileAndSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult settings, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr);
void _CreateNewTabWithProfileAndSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult settings, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr);
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettings settings);

winrt::fire_and_forget _OpenNewWindow(const bool elevate, const Microsoft::Terminal::Settings::Model::NewTerminalArgs newTerminalArgs);
Expand Down
11 changes: 8 additions & 3 deletions src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace winrt

namespace winrt::TerminalApp::implementation
{
TerminalTab::TerminalTab(const Profile& profile, const TermControl& control)
TerminalTab::TerminalTab(const Profile& profile, const WUX::Controls::UserControl& control)
{
_rootPane = std::make_shared<Pane>(profile, control, true);

Expand Down Expand Up @@ -449,7 +449,7 @@ namespace winrt::TerminalApp::implementation
void TerminalTab::SplitPane(SplitState splitType,
const float splitSize,
const Profile& profile,
TermControl& control)
const WUX::Controls::UserControl& control)
{
// Make sure to take the ID before calling Split() - Split() will clear out the active pane's ID
const auto activePaneId = _activePane->Id();
Expand All @@ -471,7 +471,8 @@ namespace winrt::TerminalApp::implementation

// Add a event handlers to the new panes' GotFocus event. When the pane
// gains focus, we'll mark it as the new active pane.
_AttachEventHandlersToControl(second->Id().value(), control);
const auto& termControl{ control.try_as<TermControl>() };
_AttachEventHandlersToControl(second->Id().value(), termControl);
_AttachEventHandlersToPane(first);
_AttachEventHandlersToPane(second);

Expand Down Expand Up @@ -804,6 +805,10 @@ namespace winrt::TerminalApp::implementation
// - <none>
void TerminalTab::_AttachEventHandlersToControl(const uint32_t paneId, const TermControl& control)
{
if (!control)
{
return;
}
auto weakThis{ get_weak() };
auto dispatcher = TabViewItem().Dispatcher();
ControlEventTokens events{};
Expand Down
5 changes: 3 additions & 2 deletions src/cascadia/TerminalApp/TerminalTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace winrt::TerminalApp::implementation
struct TerminalTab : TerminalTabT<TerminalTab, TabBase>
{
public:
TerminalTab(const winrt::Microsoft::Terminal::Settings::Model::Profile& profile, const winrt::Microsoft::Terminal::Control::TermControl& control);
TerminalTab(const winrt::Microsoft::Terminal::Settings::Model::Profile& profile,
const winrt::Windows::UI::Xaml::Controls::UserControl& control);
TerminalTab(std::shared_ptr<Pane> rootPane);

// Called after construction to perform the necessary setup, which relies on weak_ptr
Expand All @@ -41,7 +42,7 @@ namespace winrt::TerminalApp::implementation
void SplitPane(winrt::Microsoft::Terminal::Settings::Model::SplitState splitType,
const float splitSize,
const winrt::Microsoft::Terminal::Settings::Model::Profile& profile,
winrt::Microsoft::Terminal::Control::TermControl& control);
const winrt::Windows::UI::Xaml::Controls::UserControl& control);

void ToggleSplitOrientation();
winrt::fire_and_forget UpdateIcon(const winrt::hstring iconPath);
Expand Down

0 comments on commit 1ee3522

Please sign in to comment.