Skip to content

Commit

Permalink
Add an action for immediately restarting a connection (#15241)
Browse files Browse the repository at this point in the history
Adds an action for immediately restarting the connection. I suspect
most folks that wanted #3726 will be happy just with the
<kbd>enter</kbd> solution from #14060, but this will work without having
to `exit` the client. Just, relaunch whatever the commandline is. Easy
peasy.

Closes #3726.

Obsoletes #14549
  • Loading branch information
zadjii-msft authored Apr 28, 2023
1 parent 0d6642a commit 70e44c7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,4 +1228,17 @@ namespace winrt::TerminalApp::implementation
args.Handled(handled);
}
}

void TerminalPage::_HandleRestartConnection(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
if (const auto activeTab{ _GetFocusedTabImpl() })
{
if (const auto activePane{ activeTab->GetActivePane() })
{
_restartPaneConnection(activePane);
}
}
args.Handled(true);
}
}
18 changes: 10 additions & 8 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2979,18 +2979,20 @@ namespace winrt::TerminalApp::implementation
original->SetActive();
}

resultPane->RestartTerminalRequested([this](const auto& pane) {
auto connection = _duplicateConnectionForRestart(pane);
if (connection)
{
pane->GetTerminalControl().Connection(connection);
connection.Start();
}
});
resultPane->RestartTerminalRequested({ get_weak(), &TerminalPage::_restartPaneConnection });

return resultPane;
}

void TerminalPage::_restartPaneConnection(const std::shared_ptr<Pane>& pane)
{
if (const auto& connection{ _duplicateConnectionForRestart(pane) })
{
pane->GetTerminalControl().Connection(connection);
connection.Start();
}
}

// Method Description:
// - Sets background image and applies its settings (stretch, opacity and alignment)
// - Checks path validity
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ namespace winrt::TerminalApp::implementation
void _CreateNewTabFromPane(std::shared_ptr<Pane> pane, uint32_t insertPosition = -1);
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettings settings, const bool inheritCursor);
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _duplicateConnectionForRestart(std::shared_ptr<Pane> pane);
void _restartPaneConnection(const std::shared_ptr<Pane>& pane);

winrt::fire_and_forget _OpenNewWindow(const Microsoft::Terminal::Settings::Model::NewTerminalArgs newTerminalArgs);

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static constexpr std::string_view ToggleBlockSelectionKey{ "toggleBlockSelection
static constexpr std::string_view SwitchSelectionEndpointKey{ "switchSelectionEndpoint" };
static constexpr std::string_view ColorSelectionKey{ "experimental.colorSelection" };
static constexpr std::string_view ExpandSelectionToWordKey{ "expandSelectionToWord" };
static constexpr std::string_view RestartConnectionKey{ "restartConnection" };

static constexpr std::string_view ActionKey{ "action" };

Expand Down Expand Up @@ -418,6 +419,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::SwitchSelectionEndpoint, RS_(L"SwitchSelectionEndpointCommandKey") },
{ ShortcutAction::ColorSelection, MustGenerate },
{ ShortcutAction::ExpandSelectionToWord, RS_(L"ExpandSelectionToWordCommandKey") },
{ ShortcutAction::RestartConnection, RS_(L"RestartConnectionKey") },
};
}();

Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsModel/AllShortcutActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
ON_ALL_ACTIONS(SwitchSelectionEndpoint) \
ON_ALL_ACTIONS(ColorSelection) \
ON_ALL_ACTIONS(ExpandSelectionToWord) \
ON_ALL_ACTIONS(CloseOtherPanes)
ON_ALL_ACTIONS(CloseOtherPanes) \
ON_ALL_ACTIONS(RestartConnection)

#define ALL_SHORTCUT_ACTIONS_WITH_ARGS \
ON_ALL_ACTIONS_WITH_ARGS(AdjustFontSize) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@
<data name="CloseOtherPanesCommandKey" xml:space="preserve">
<value>Close all other panes</value>
</data>
<data name="RestartConnectionKey" xml:space="preserve">
<value>Restart connection</value>
</data>
<data name="SelectOutputNextCommandKey" xml:space="preserve">
<value>Select next command output</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@
{ "command": { "action": "movePane", "index": 6 } },
{ "command": { "action": "movePane", "index": 7 } },
{ "command": { "action": "movePane", "index": 8 } },
{ "command": "restartConnection" },

// Clipboard Integration
{ "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+shift+c" },
Expand Down

0 comments on commit 70e44c7

Please sign in to comment.