Skip to content

Commit

Permalink
goin back to good ol' GetStrongTabImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
leonMSFT committed Sep 30, 2020
1 parent 8882f66 commit 3fdb0f1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
<Project>{ca5cad1a-44bd-4ac7-ac72-f16e576fdd12}</Project>
</ProjectReference>

<ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalSettingsEditor\Microsoft.Terminal.Settings.Editor.vcxproj" />

</ItemGroup>

<PropertyGroup>
Expand Down
51 changes: 42 additions & 9 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ namespace winrt::TerminalApp::implementation
{
if (auto index{ _GetFocusedTabIndex() })
{
if (auto terminalTab = _tabs.GetAt(*index).try_as<TerminalApp::TerminalTab>())
if (auto terminalTab = _GetStrongTabImpl(*index))
{
try
{
Expand Down Expand Up @@ -1297,7 +1297,7 @@ namespace winrt::TerminalApp::implementation
{
if (auto index{ _GetFocusedTabIndex() })
{
if (auto terminalTab = _tabs.GetAt(*index).try_as<TerminalTab>())
if (auto terminalTab = _GetStrongTabImpl(*index))
{
_UnZoomIfNeeded();
terminalTab->NavigateFocus(direction);
Expand All @@ -1309,7 +1309,7 @@ namespace winrt::TerminalApp::implementation
{
if (auto index{ _GetFocusedTabIndex() })
{
if (auto terminalTab = _tabs.GetAt(*index).try_as<TerminalTab>())
if (auto terminalTab = _GetStrongTabImpl(*index))
{
return terminalTab->GetActiveTerminalControl();
}
Expand Down Expand Up @@ -1389,7 +1389,7 @@ namespace winrt::TerminalApp::implementation
{
if (auto index{ _GetFocusedTabIndex() })
{
if (auto terminalTab = _tabs.GetAt(*index).try_as<TerminalTab>())
if (auto terminalTab = _GetStrongTabImpl(*index))
{
_UnZoomIfNeeded();
terminalTab->ClosePane();
Expand Down Expand Up @@ -1433,7 +1433,7 @@ namespace winrt::TerminalApp::implementation
{
if (auto index{ _GetFocusedTabIndex() })
{
if (auto terminalTab = _tabs.GetAt(*index).try_as<TerminalTab>())
if (auto terminalTab = _GetStrongTabImpl(*index))
{
terminalTab->Scroll(delta);
}
Expand Down Expand Up @@ -1469,7 +1469,7 @@ namespace winrt::TerminalApp::implementation
return;
}

auto focusedTab = _tabs.GetAt(*indexOpt).try_as<TerminalTab>();
auto focusedTab = _GetStrongTabImpl(*indexOpt);

// Do nothing if the focused tab isn't a TerminalTab
if (!focusedTab)
Expand Down Expand Up @@ -1552,7 +1552,7 @@ namespace winrt::TerminalApp::implementation
{
if (auto index{ _GetFocusedTabIndex() })
{
if (auto terminalTab = _tabs.GetAt(*index).try_as<TerminalTab>())
if (auto terminalTab = _GetStrongTabImpl(*index))
{
_UnZoomIfNeeded();
terminalTab->ResizePane(direction);
Expand All @@ -1577,7 +1577,7 @@ namespace winrt::TerminalApp::implementation
return;
}

if (auto terminalTab = _tabs.GetAt(*indexOpt).try_as<TerminalTab>())
if (auto terminalTab = _GetStrongTabImpl(*indexOpt))
{
delta = std::clamp(delta, -1, 1);
const auto control = _GetActiveControl();
Expand Down Expand Up @@ -1694,7 +1694,7 @@ namespace winrt::TerminalApp::implementation
{
if (auto index{ _GetFocusedTabIndex() })
{
if (auto terminalTab = _tabs.GetAt(*index).try_as<TerminalTab>())
if (auto terminalTab = _GetStrongTabImpl(*index))
{
return terminalTab->CalcSnappedDimension(widthOrHeight, dimension);
}
Expand Down Expand Up @@ -2590,6 +2590,39 @@ namespace winrt::TerminalApp::implementation
_tabView.SelectedItem(tabViewItem);
}

// Method Description:
// - Returns a com_ptr to the implementation type of the tab at the given index
// Arguments:
// - index: an unsigned integer index to a tab in _tabs
// Return Value:
// - a com_ptr to the implementation type of the Tab
winrt::com_ptr<TerminalTab> TerminalPage::_GetStrongTabImpl(const uint32_t index) const
{
if (auto tab = _tabs.GetAt(index).try_as<TerminalApp::TerminalTab>())
{
winrt::com_ptr<TerminalTab> tabImpl;
tabImpl.copy_from(winrt::get_self<TerminalTab>(tab));
return tabImpl;
}
else
{
return nullptr;
}
}

// Method Description:
// - Returns a com_ptr to the implementation type of the given projected Tab
// Arguments:
// - tab: the projected type of a Tab
// Return Value:
// - a com_ptr to the implementation type of the Tab
winrt::com_ptr<TerminalTab> TerminalPage::_GetStrongTabImpl(const ::winrt::TerminalApp::TerminalTab& tab) const
{
winrt::com_ptr<TerminalTab> tabImpl;
tabImpl.copy_from(winrt::get_self<TerminalTab>(tab));
return tabImpl;
}

// -------------------------------- WinRT Events ---------------------------------
// Winrt events need a method for adding a callback to the event and removing the callback.
// These macros will define them both for you.
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ namespace winrt::TerminalApp::implementation
TerminalApp::CascadiaSettings _settings{ nullptr };

Windows::Foundation::Collections::IObservableVector<TerminalApp::ITab> _tabs;
winrt::com_ptr<TerminalTab> _GetStrongTabImpl(const uint32_t index) const;
winrt::com_ptr<TerminalTab> _GetStrongTabImpl(const ::winrt::TerminalApp::TerminalTab& tab) const;
void _UpdateTabIndices();

bool _isInFocusMode{ false };
Expand Down

1 comment on commit 3fdb0f1

@github-actions

This comment was marked as resolved.

Please sign in to comment.