diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index c58de58b59d..d1bf48ed796 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -327,6 +327,15 @@ void Pane::_ControlConnectionStateChangedHandler(const TermControl& /*sender*/, if ((mode == winrt::TerminalApp::CloseOnExitMode::Always) || (mode == winrt::TerminalApp::CloseOnExitMode::Graceful && newConnectionState == ConnectionState::Closed)) { + // We need to call Restore on the root of the tree, or at least our + // parent, to get us re-added ot their content. However, we also + // want to close our content here too, and remove it from the UI + // tree. + + // if (_zoomed) + // { + // Restore(shared_from_this()); + // }; _ClosedHandlers(nullptr, nullptr); } } diff --git a/src/cascadia/TerminalApp/Tab.cpp b/src/cascadia/TerminalApp/Tab.cpp index f7d33efd754..7d8461f0ba8 100644 --- a/src/cascadia/TerminalApp/Tab.cpp +++ b/src/cascadia/TerminalApp/Tab.cpp @@ -511,6 +511,41 @@ namespace winrt::TerminalApp::implementation tab->_RecalculateAndApplyTabColor(); } }); + + pane->Closed([weakThis](auto&& /*s*/, auto && /*e*/) -> winrt::fire_and_forget { + if (auto tab{ weakThis.get() }) + { + if (tab->_zoomedPane) + { + co_await winrt::resume_foreground(tab->GetRootElement().Dispatcher()); + tab->ExitZoom(); + tab->Content(tab->GetRootElement()); + // if (tab->_focused) + // { + // tab->_Focus(); + // } + // tab->_UpdateActivePane(tab->_rootPane->GetActivePane()); + } + + // OKAY I see what's happening here the ActivePaneChanged + // Handler in TerminalPage doesn't re-attach the tab content to + // the tree, it just updates hte title of the window. + // + // So when the pane is `exit`ed, the pane's control is removed + // and re-attached to the parent grid, which _isn't in the XAML + // tree_. And no one can go tell the TerminalPage that it needs + // to re set up the tab content again. + // + // The Page _manually_ does this in a few places, when various + // pane actions are about to take place, it'll unzoom. It would + // be way easier if the Tab could just manage the content of the + // page. + // + // Or if the Tab just had a Content that was observable, that + // when that changed, the page would auto readjust. That does + // sound like a LOT of work though. + } + }); } // Method Description: diff --git a/src/cascadia/TerminalApp/Tab.h b/src/cascadia/TerminalApp/Tab.h index 3b52488f5d0..63503d24a5b 100644 --- a/src/cascadia/TerminalApp/Tab.h +++ b/src/cascadia/TerminalApp/Tab.h @@ -84,6 +84,8 @@ namespace winrt::TerminalApp::implementation // This is needed since Tab is going to be managing its own SwitchToTab command. OBSERVABLE_GETSET_PROPERTY(uint32_t, TabViewIndex, _PropertyChangedHandlers, 0); + OBSERVABLE_GETSET_PROPERTY(winrt::Windows::UI::Xaml::UIElement, Content, _PropertyChangedHandlers, nullptr); + private: std::shared_ptr _rootPane{ nullptr }; std::shared_ptr _activePane{ nullptr }; diff --git a/src/cascadia/TerminalApp/Tab.idl b/src/cascadia/TerminalApp/Tab.idl index ceb52a55f8f..959486f0776 100644 --- a/src/cascadia/TerminalApp/Tab.idl +++ b/src/cascadia/TerminalApp/Tab.idl @@ -11,5 +11,7 @@ namespace TerminalApp Windows.UI.Xaml.Controls.IconSource IconSource { get; }; Command SwitchToTabCommand { get; }; UInt32 TabViewIndex { get; }; + + Windows.UI.Xaml.UIElement Content { get; }; } } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 8dc7142a3f0..be04d94c7cd 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -1160,6 +1160,16 @@ namespace winrt::TerminalApp::implementation { page->_UpdateTitle(*tab); } + else if (args.PropertyName() == L"Content") + { + if (tab == page->_GetFocusedTab()) + { + page->_tabContent.Children().Clear(); + page->_tabContent.Children().Append(tab->Content()); + + tab->SetFocused(true); + } + } } });