Add openTabRenamer
action (#7462)
Adds a `ShortcutAction` to allow editing the tab title via the TextBox (just like double-clicking the tab, but triggered from a key binding or command palette). * This implements "scenario 3" outlined in zadjii-msft's comment: https://github.com/microsoft/terminal/pull/6557#issuecomment-646153274 * The `openTabRenamer` action name is taken from the discussion in this PR: https://github.com/microsoft/terminal/pull/6567#issuecomment-646319010 Related to #6256 (but doesn't address pane renaming)
This commit is contained in:
parent
1c97d20c13
commit
8e3f27f8fb
1
.github/actions/spell-check/expect/5757ec679b03a4240130c3c53766c91bbc5cd6a7.txt
vendored
Normal file
1
.github/actions/spell-check/expect/5757ec679b03a4240130c3c53766c91bbc5cd6a7.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
renamer
|
|
@ -66,6 +66,7 @@
|
|||
"paste",
|
||||
"prevTab",
|
||||
"renameTab",
|
||||
"openTabRenamer",
|
||||
"resetFontSize",
|
||||
"resizePane",
|
||||
"scrollDown",
|
||||
|
|
|
@ -403,6 +403,17 @@ namespace winrt::TerminalApp::implementation
|
|||
args.Handled(true);
|
||||
}
|
||||
|
||||
void TerminalPage::_HandleOpenTabRenamer(const IInspectable& /*sender*/,
|
||||
const ActionEventArgs& args)
|
||||
{
|
||||
auto activeTab = _GetFocusedTab();
|
||||
if (activeTab)
|
||||
{
|
||||
activeTab->ActivateTabRenamer();
|
||||
}
|
||||
args.Handled(true);
|
||||
}
|
||||
|
||||
void TerminalPage::_HandleExecuteCommandline(const IInspectable& /*sender*/,
|
||||
const ActionEventArgs& actionArgs)
|
||||
{
|
||||
|
|
|
@ -212,6 +212,11 @@ namespace winrt::TerminalApp::implementation
|
|||
_RenameTabHandlers(*this, eventArgs);
|
||||
break;
|
||||
}
|
||||
case ShortcutAction::OpenTabRenamer:
|
||||
{
|
||||
_OpenTabRenamerHandlers(*this, eventArgs);
|
||||
break;
|
||||
}
|
||||
case ShortcutAction::ExecuteCommandline:
|
||||
{
|
||||
_ExecuteCommandlineHandlers(*this, eventArgs);
|
||||
|
|
|
@ -56,6 +56,7 @@ namespace winrt::TerminalApp::implementation
|
|||
TYPED_EVENT(SetTabColor, TerminalApp::ShortcutActionDispatch, Microsoft::Terminal::Settings::Model::ActionEventArgs);
|
||||
TYPED_EVENT(OpenTabColorPicker, TerminalApp::ShortcutActionDispatch, Microsoft::Terminal::Settings::Model::ActionEventArgs);
|
||||
TYPED_EVENT(RenameTab, TerminalApp::ShortcutActionDispatch, Microsoft::Terminal::Settings::Model::ActionEventArgs);
|
||||
TYPED_EVENT(OpenTabRenamer, TerminalApp::ShortcutActionDispatch, Microsoft::Terminal::Settings::Model::ActionEventArgs);
|
||||
TYPED_EVENT(ExecuteCommandline, TerminalApp::ShortcutActionDispatch, Microsoft::Terminal::Settings::Model::ActionEventArgs);
|
||||
TYPED_EVENT(CloseOtherTabs, TerminalApp::ShortcutActionDispatch, Microsoft::Terminal::Settings::Model::ActionEventArgs);
|
||||
TYPED_EVENT(CloseTabsAfter, TerminalApp::ShortcutActionDispatch, Microsoft::Terminal::Settings::Model::ActionEventArgs);
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace TerminalApp
|
|||
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, Microsoft.Terminal.Settings.Model.ActionEventArgs> SetTabColor;
|
||||
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, Microsoft.Terminal.Settings.Model.ActionEventArgs> OpenTabColorPicker;
|
||||
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, Microsoft.Terminal.Settings.Model.ActionEventArgs> RenameTab;
|
||||
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, Microsoft.Terminal.Settings.Model.ActionEventArgs> OpenTabRenamer;
|
||||
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, Microsoft.Terminal.Settings.Model.ActionEventArgs> ExecuteCommandline;
|
||||
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, Microsoft.Terminal.Settings.Model.ActionEventArgs> CloseOtherTabs;
|
||||
event Windows.Foundation.TypedEventHandler<ShortcutActionDispatch, Microsoft.Terminal.Settings.Model.ActionEventArgs> CloseTabsAfter;
|
||||
|
|
|
@ -53,8 +53,7 @@ namespace winrt::TerminalApp::implementation
|
|||
_tabViewItem.DoubleTapped([weakThis = get_weak()](auto&& /*s*/, auto&& /*e*/) {
|
||||
if (auto tab{ weakThis.get() })
|
||||
{
|
||||
tab->_inRename = true;
|
||||
tab->_UpdateTabHeader();
|
||||
tab->ActivateTabRenamer();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -398,6 +397,20 @@ namespace winrt::TerminalApp::implementation
|
|||
_UpdateTitle();
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Show a TextBox in the Header to allow the user to set a string
|
||||
// to use as an override for the tab's text
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - <none>
|
||||
void Tab::ActivateTabRenamer()
|
||||
{
|
||||
_inRename = true;
|
||||
_receivedKeyDown = false;
|
||||
_UpdateTabHeader();
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Register any event handlers that we may need with the given TermControl.
|
||||
// This should be called on each and every TermControl that we add to the tree
|
||||
|
@ -577,8 +590,7 @@ namespace winrt::TerminalApp::implementation
|
|||
renameTabMenuItem.Click([weakThis](auto&&, auto&&) {
|
||||
if (auto tab{ weakThis.get() })
|
||||
{
|
||||
tab->_inRename = true;
|
||||
tab->_UpdateTabHeader();
|
||||
tab->ActivateTabRenamer();
|
||||
}
|
||||
});
|
||||
renameTabMenuItem.Text(RS_(L"RenameTabText"));
|
||||
|
@ -755,6 +767,14 @@ namespace winrt::TerminalApp::implementation
|
|||
}
|
||||
});
|
||||
|
||||
// We'll only process the KeyUp event if we received an initial KeyDown event first.
|
||||
// Avoids issue immediately closing the tab rename when we see the enter KeyUp event that was
|
||||
// sent to the command palette to trigger the openTabRenamer action in the first place.
|
||||
tabTextBox.KeyDown([weakThis](const IInspectable&, Input::KeyRoutedEventArgs const&) {
|
||||
auto tab{ weakThis.get() };
|
||||
tab->_receivedKeyDown = true;
|
||||
});
|
||||
|
||||
// NOTE: (Preview)KeyDown does not work here. If you use that, we'll
|
||||
// remove the TextBox from the UI tree, then the following KeyUp
|
||||
// will bubble to the NewTabButton, which we don't want to have
|
||||
|
@ -762,7 +782,7 @@ namespace winrt::TerminalApp::implementation
|
|||
tabTextBox.KeyUp([weakThis](const IInspectable& sender, Input::KeyRoutedEventArgs const& e) {
|
||||
auto tab{ weakThis.get() };
|
||||
auto textBox{ sender.try_as<Controls::TextBox>() };
|
||||
if (tab && textBox)
|
||||
if (tab && textBox && tab->_receivedKeyDown)
|
||||
{
|
||||
switch (e.OriginalKey())
|
||||
{
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace winrt::TerminalApp::implementation
|
|||
|
||||
void SetTabText(winrt::hstring title);
|
||||
void ResetTabText();
|
||||
void ActivateTabRenamer();
|
||||
|
||||
std::optional<winrt::Windows::UI::Color> GetTabColor();
|
||||
|
||||
|
@ -101,6 +102,7 @@ namespace winrt::TerminalApp::implementation
|
|||
winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _closeTabsAfterMenuItem{};
|
||||
|
||||
bool _focused{ false };
|
||||
bool _receivedKeyDown{ false };
|
||||
winrt::Microsoft::UI::Xaml::Controls::TabViewItem _tabViewItem{ nullptr };
|
||||
|
||||
winrt::hstring _runtimeTabText{};
|
||||
|
|
|
@ -908,6 +908,7 @@ namespace winrt::TerminalApp::implementation
|
|||
_actionDispatch->SetTabColor({ this, &TerminalPage::_HandleSetTabColor });
|
||||
_actionDispatch->OpenTabColorPicker({ this, &TerminalPage::_HandleOpenTabColorPicker });
|
||||
_actionDispatch->RenameTab({ this, &TerminalPage::_HandleRenameTab });
|
||||
_actionDispatch->OpenTabRenamer({ this, &TerminalPage::_HandleOpenTabRenamer });
|
||||
_actionDispatch->ExecuteCommandline({ this, &TerminalPage::_HandleExecuteCommandline });
|
||||
_actionDispatch->CloseOtherTabs({ this, &TerminalPage::_HandleCloseOtherTabs });
|
||||
_actionDispatch->CloseTabsAfter({ this, &TerminalPage::_HandleCloseTabsAfter });
|
||||
|
|
|
@ -256,6 +256,7 @@ namespace winrt::TerminalApp::implementation
|
|||
void _HandleSetTabColor(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args);
|
||||
void _HandleOpenTabColorPicker(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args);
|
||||
void _HandleRenameTab(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args);
|
||||
void _HandleOpenTabRenamer(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args);
|
||||
void _HandleExecuteCommandline(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args);
|
||||
void _HandleToggleCommandPalette(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args);
|
||||
void _HandleCloseOtherTabs(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args);
|
||||
|
|
|
@ -27,6 +27,7 @@ static constexpr std::string_view OpenTabColorPickerKey{ "openTabColorPicker" };
|
|||
static constexpr std::string_view PasteTextKey{ "paste" };
|
||||
static constexpr std::string_view PrevTabKey{ "prevTab" };
|
||||
static constexpr std::string_view RenameTabKey{ "renameTab" };
|
||||
static constexpr std::string_view OpenTabRenamerKey{ "openTabRenamer" };
|
||||
static constexpr std::string_view ResetFontSizeKey{ "resetFontSize" };
|
||||
static constexpr std::string_view ResizePaneKey{ "resizePane" };
|
||||
static constexpr std::string_view ScrolldownKey{ "scrollDown" };
|
||||
|
@ -84,6 +85,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
{ PasteTextKey, ShortcutAction::PasteText },
|
||||
{ PrevTabKey, ShortcutAction::PrevTab },
|
||||
{ RenameTabKey, ShortcutAction::RenameTab },
|
||||
{ OpenTabRenamerKey, ShortcutAction::OpenTabRenamer },
|
||||
{ ResetFontSizeKey, ShortcutAction::ResetFontSize },
|
||||
{ ResizePaneKey, ShortcutAction::ResizePane },
|
||||
{ ScrolldownKey, ShortcutAction::ScrollDown },
|
||||
|
@ -277,6 +279,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
{ ShortcutAction::PasteText, RS_(L"PasteTextCommandKey") },
|
||||
{ ShortcutAction::PrevTab, RS_(L"PrevTabCommandKey") },
|
||||
{ ShortcutAction::RenameTab, RS_(L"ResetTabNameCommandKey") },
|
||||
{ ShortcutAction::OpenTabRenamer, RS_(L"OpenTabRenamerCommandKey") },
|
||||
{ ShortcutAction::ResetFontSize, RS_(L"ResetFontSizeCommandKey") },
|
||||
{ ShortcutAction::ResizePane, RS_(L"ResizePaneCommandKey") },
|
||||
{ ShortcutAction::ScrollDown, RS_(L"ScrollDownCommandKey") },
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace Microsoft.Terminal.Settings.Model
|
|||
SetTabColor,
|
||||
OpenTabColorPicker,
|
||||
RenameTab,
|
||||
OpenTabRenamer,
|
||||
ExecuteCommandline,
|
||||
ToggleCommandPalette,
|
||||
CloseOtherTabs,
|
||||
|
|
|
@ -259,6 +259,9 @@
|
|||
<data name="ResetTabNameCommandKey" xml:space="preserve">
|
||||
<value>Reset tab title</value>
|
||||
</data>
|
||||
<data name="OpenTabRenamerCommandKey" xml:space="preserve">
|
||||
<value>Rename tab title...</value>
|
||||
</data>
|
||||
<data name="ResizePaneCommandKey" xml:space="preserve">
|
||||
<value>Resize pane</value>
|
||||
</data>
|
||||
|
|
|
@ -287,6 +287,8 @@
|
|||
{ "command": "find", "keys": "ctrl+shift+f" },
|
||||
{ "command": "toggleRetroEffect" },
|
||||
{ "command": "openTabColorPicker" },
|
||||
{ "command": "renameTab" },
|
||||
{ "command": "openTabRenamer" },
|
||||
{ "command": "commandPalette", "keys":"ctrl+shift+p" },
|
||||
|
||||
// Tab Management
|
||||
|
|
Loading…
Reference in a new issue