Skip to content

Commit

Permalink
Add openTabRenamer action (#7462)
Browse files Browse the repository at this point in the history
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:
  #6557 (comment)

* The `openTabRenamer` action name is taken from the discussion in this
  PR:
  #6567 (comment)

Related to #6256 (but doesn't address pane renaming)
  • Loading branch information
Coridyn committed Oct 28, 2020
1 parent 1c97d20 commit 8e3f27f
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
renamer
1 change: 1 addition & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"paste",
"prevTab",
"renameTab",
"openTabRenamer",
"resetFontSize",
"resizePane",
"scrollDown",
Expand Down
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalApp/ShortcutActionDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/ShortcutActionDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/ShortcutActionDispatch.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 25 additions & 5 deletions src/cascadia/TerminalApp/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -755,14 +767,22 @@ 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
// happen.
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())
{
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/Tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace winrt::TerminalApp::implementation

void SetTabText(winrt::hstring title);
void ResetTabText();
void ActivateTabRenamer();

std::optional<winrt::Windows::UI::Color> GetTabColor();

Expand Down Expand Up @@ -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{};
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
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 @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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") },
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/KeyMapping.idl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace Microsoft.Terminal.Settings.Model
SetTabColor,
OpenTabColorPicker,
RenameTab,
OpenTabRenamer,
ExecuteCommandline,
ToggleCommandPalette,
CloseOtherTabs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e3f27f

Please sign in to comment.