Skip to content

Commit

Permalink
Added Close Pane to Context Menu (#15198)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request
Adding a 'Close Pane' menu item in the context menu.

## References and Relevant Issues
#13580 

## Detailed Description of the Pull Request / Additional comments
If a user decides to split a tab to create multiple panes through the
context menu, they should be able to then close the pane via the context
menu too. This PR introduces a new context menu item, 'Close Pane', that
only appears when a user has 2 or more panes in a tab. When a user
clicks close pane, the _active_pane will be closed.

## Validation Steps Performed

![close_pane_terminal](https://user-images.githubusercontent.com/98557455/232649000-8b521070-4f1b-4da9-8092-6ff802e91e2c.gif)

As it's my first PR, I still need to understand how to go through the
testing suite.

## PR Checklist
- [x] Closes #13580 
- [ ] Tests added/passed
- [ ] Documentation updated
- If checked, please file a pull request on [our docs
repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
- [ ] Schema updated (if necessary)

---------

Co-authored-by: Carlos Zamora <carlos.zamora@microsoft.com>
  • Loading branch information
joadoumie and carlos-zamora authored Apr 26, 2023
1 parent a49b5a6 commit ca5834e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -763,15 +763,12 @@
</data>
<data name="AboutDialog_CheckingForUpdatesLabel.Text" xml:space="preserve">
<value>Checking for updates...</value>
<comment></comment>
</data>
<data name="AboutDialog_UpdateAvailableLabel.Text" xml:space="preserve">
<value>An update is available.</value>
<comment></comment>
</data>
<data name="AboutDialog_InstallUpdateButton.Content" xml:space="preserve">
<value>Install now</value>
<comment></comment>
</data>
<data name="DuplicateRemainingProfilesEntry" xml:space="preserve">
<value>The "newTabMenu" field contains more than one entry of type "remainingProfiles". Only the first one will be considered.</value>
Expand Down Expand Up @@ -820,4 +817,10 @@
<data name="NewTabMenuFolderEmpty" xml:space="preserve">
<value>Empty...</value>
</data>
</root>
<data name="ClosePaneText" xml:space="preserve">
<value>Close Pane</value>
</data>
<data name="ClosePaneToolTip" xml:space="preserve">
<value>Close the active pane if multiple panes are present</value>
</data>
</root>
28 changes: 28 additions & 0 deletions src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace winrt::TerminalApp::implementation
_rootPane = rootPane;
_activePane = nullptr;

_closePaneMenuItem.Visibility(WUX::Visibility::Collapsed);

auto firstId = _nextPaneId;

_rootPane->WalkTree([&](std::shared_ptr<Pane> pane) {
Expand Down Expand Up @@ -517,6 +519,9 @@ namespace winrt::TerminalApp::implementation
// original pane first.
auto [original, newPane] = _activePane->Split(splitType, splitSize, pane);

// After split, Close Pane Menu Item should be visible
_closePaneMenuItem.Visibility(WUX::Visibility::Visible);

// The active pane has an id if it is a leaf
if (activePaneId)
{
Expand Down Expand Up @@ -1071,6 +1076,11 @@ namespace winrt::TerminalApp::implementation
_mruPanes.insert(_mruPanes.begin(), paneId.value());
}

if (_rootPane->GetLeafPaneCount() == 1)
{
_closePaneMenuItem.Visibility(WUX::Visibility::Collapsed);
}

_RecalculateAndApplyReadOnly();

// Raise our own ActivePaneChanged event.
Expand Down Expand Up @@ -1326,6 +1336,23 @@ namespace winrt::TerminalApp::implementation
Automation::AutomationProperties::SetHelpText(splitTabMenuItem, splitTabToolTip);
}

Controls::MenuFlyoutItem closePaneMenuItem = _closePaneMenuItem;
{
// "Close Pane"
closePaneMenuItem.Click([weakThis](auto&&, auto&&) {
if (auto tab{ weakThis.get() })
{
tab->ClosePane();
}
});
closePaneMenuItem.Text(RS_(L"ClosePaneText"));

const auto closePaneToolTip = RS_(L"ClosePaneToolTip");

WUX::Controls::ToolTipService::SetToolTip(closePaneMenuItem, box_value(closePaneToolTip));
Automation::AutomationProperties::SetHelpText(closePaneMenuItem, closePaneToolTip);
}

Controls::MenuFlyoutItem exportTabMenuItem;
{
// "Export Tab"
Expand Down Expand Up @@ -1377,6 +1404,7 @@ namespace winrt::TerminalApp::implementation
contextMenuFlyout.Items().Append(renameTabMenuItem);
contextMenuFlyout.Items().Append(duplicateTabMenuItem);
contextMenuFlyout.Items().Append(splitTabMenuItem);
contextMenuFlyout.Items().Append(closePaneMenuItem);
contextMenuFlyout.Items().Append(exportTabMenuItem);
contextMenuFlyout.Items().Append(findMenuItem);
contextMenuFlyout.Items().Append(menuSeparator);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TerminalTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ namespace winrt::TerminalApp::implementation
std::shared_ptr<Pane> _activePane{ nullptr };
std::shared_ptr<Pane> _zoomedPane{ nullptr };

Windows::UI::Xaml::Controls::MenuFlyoutItem _closePaneMenuItem;

winrt::hstring _lastIconPath{};
std::optional<winrt::Windows::UI::Color> _runtimeTabColor{};
winrt::TerminalApp::TabHeaderControl _headerControl{};
Expand Down

0 comments on commit ca5834e

Please sign in to comment.