Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1536 - Feature Request - Duplicate tab #1685

Merged
merged 9 commits into from
Jul 2, 2019
15 changes: 15 additions & 0 deletions src/cascadia/TerminalApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ namespace winrt::TerminalApp::implementation
// They should all be hooked up here, regardless of whether or not
// there's an actual keychord for them.
bindings.NewTab([this]() { _OpenNewTab(std::nullopt); });
bindings.DuplicateTab([this]() { _DuplicateTabViewItem(); });
bindings.CloseTab([this]() { _CloseFocusedTab(); });
bindings.NewTabWithProfile([this](const auto index) { _OpenNewTab({ index }); });
bindings.ScrollUp([this]() { _Scroll(-1); });
Expand Down Expand Up @@ -1165,6 +1166,20 @@ namespace winrt::TerminalApp::implementation
}
}

// Method Description:
// - Duplicates the current focused tab
void App::_DuplicateTabViewItem()
{
int focusedTabIndex = _GetFocusedTabIndex();
dnagl marked this conversation as resolved.
Show resolved Hide resolved
auto _tab = _tabs.at(focusedTabIndex);

auto profileGuid = _tab->GetFocusedProfile();
auto settings = _settings->MakeSettings(profileGuid);

_CreateNewTabFromSettings(profileGuid.value(), settings);

}

// Method Description:
// - Removes the tab (both TerminalControl and XAML)
// Arguments:
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace winrt::TerminalApp::implementation
void _CreateNewTabFromSettings(GUID profileGuid, winrt::Microsoft::Terminal::Settings::TerminalSettings settings);

void _OpenNewTab(std::optional<int> profileIndex);
void _DuplicateTabViewItem();
void _CloseFocusedTab();
void _SelectNextTab(const bool bMoveRight);
void _SelectTab(const int tabIndex);
Expand Down
6 changes: 5 additions & 1 deletion src/cascadia/TerminalApp/AppKeyBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ namespace winrt::TerminalApp::implementation
case ShortcutAction::NewTab:
_NewTabHandlers();
return true;
case ShortcutAction::DuplicateTab:
_DuplicateTabHandlers();
return true;
case ShortcutAction::OpenSettings:
_OpenSettingsHandlers();
return true;
Expand Down Expand Up @@ -218,14 +221,15 @@ namespace winrt::TerminalApp::implementation
DEFINE_EVENT(AppKeyBindings, CopyText, _CopyTextHandlers, TerminalApp::CopyTextEventArgs);
DEFINE_EVENT(AppKeyBindings, PasteText, _PasteTextHandlers, TerminalApp::PasteTextEventArgs);
DEFINE_EVENT(AppKeyBindings, NewTab, _NewTabHandlers, TerminalApp::NewTabEventArgs);
DEFINE_EVENT(AppKeyBindings, DuplicateTab, _DuplicateTabHandlers, TerminalApp::DuplicateTabEventArgs);
DEFINE_EVENT(AppKeyBindings, NewTabWithProfile, _NewTabWithProfileHandlers, TerminalApp::NewTabWithProfileEventArgs);
DEFINE_EVENT(AppKeyBindings, NewWindow, _NewWindowHandlers, TerminalApp::NewWindowEventArgs);
DEFINE_EVENT(AppKeyBindings, CloseWindow, _CloseWindowHandlers, TerminalApp::CloseWindowEventArgs);
DEFINE_EVENT(AppKeyBindings, CloseTab, _CloseTabHandlers, TerminalApp::CloseTabEventArgs);
DEFINE_EVENT(AppKeyBindings, SwitchToTab, _SwitchToTabHandlers, TerminalApp::SwitchToTabEventArgs);
DEFINE_EVENT(AppKeyBindings, NextTab, _NextTabHandlers, TerminalApp::NextTabEventArgs);
DEFINE_EVENT(AppKeyBindings, PrevTab, _PrevTabHandlers, TerminalApp::PrevTabEventArgs);
DEFINE_EVENT(AppKeyBindings, SplitVertical, _SplitVerticalHandlers, TerminalApp::SplitVerticalEventArgs);
DEFINE_EVENT(AppKeyBindings, SplitVertical, _SplitVerticalHandlers, TerminalApp::SplitVerticalEventArgs);
miniksa marked this conversation as resolved.
Show resolved Hide resolved
DEFINE_EVENT(AppKeyBindings, SplitHorizontal, _SplitHorizontalHandlers, TerminalApp::SplitHorizontalEventArgs);
DEFINE_EVENT(AppKeyBindings, IncreaseFontSize, _IncreaseFontSizeHandlers, TerminalApp::IncreaseFontSizeEventArgs);
DEFINE_EVENT(AppKeyBindings, DecreaseFontSize, _DecreaseFontSizeHandlers, TerminalApp::DecreaseFontSizeEventArgs);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppKeyBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace winrt::TerminalApp::implementation
DECLARE_EVENT(CopyText, _CopyTextHandlers, TerminalApp::CopyTextEventArgs);
DECLARE_EVENT(PasteText, _PasteTextHandlers, TerminalApp::PasteTextEventArgs);
DECLARE_EVENT(NewTab, _NewTabHandlers, TerminalApp::NewTabEventArgs);
DECLARE_EVENT(DuplicateTab, _DuplicateTabHandlers, TerminalApp::DuplicateTabEventArgs);
DECLARE_EVENT(NewTabWithProfile, _NewTabWithProfileHandlers, TerminalApp::NewTabWithProfileEventArgs);
DECLARE_EVENT(NewWindow, _NewWindowHandlers, TerminalApp::NewWindowEventArgs);
DECLARE_EVENT(CloseWindow, _CloseWindowHandlers, TerminalApp::CloseWindowEventArgs);
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/AppKeyBindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace TerminalApp
CopyTextWithoutNewlines,
PasteText,
NewTab,
DuplicateTab,
dnagl marked this conversation as resolved.
Show resolved Hide resolved
NewTabProfile0,
NewTabProfile1,
NewTabProfile2,
Expand Down Expand Up @@ -46,6 +47,7 @@ namespace TerminalApp
delegate void CopyTextEventArgs(Boolean trimWhitespace);
delegate void PasteTextEventArgs();
delegate void NewTabEventArgs();
delegate void DuplicateTabEventArgs();
dnagl marked this conversation as resolved.
Show resolved Hide resolved
delegate void NewTabWithProfileEventArgs(Int32 profileIndex);
delegate void NewWindowEventArgs();
delegate void CloseWindowEventArgs();
Expand Down Expand Up @@ -74,6 +76,7 @@ namespace TerminalApp
event CopyTextEventArgs CopyText;
event PasteTextEventArgs PasteText;
event NewTabEventArgs NewTab;
event DuplicateTabEventArgs DuplicateTab;
event NewTabWithProfileEventArgs NewTabWithProfile;
event NewWindowEventArgs NewWindow;
event CloseWindowEventArgs CloseWindow;
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static constexpr std::string_view CopyTextKey{ "copy" };
static constexpr std::string_view CopyTextWithoutNewlinesKey{ "copyTextWithoutNewlines" };
static constexpr std::string_view PasteTextKey{ "paste" };
static constexpr std::string_view NewTabKey{ "newTab" };
static constexpr std::string_view DuplicateTabKey{ "duplicateTab" };
static constexpr std::string_view NewTabWithProfile0Key{ "newTabProfile0" };
static constexpr std::string_view NewTabWithProfile1Key{ "newTabProfile1" };
static constexpr std::string_view NewTabWithProfile2Key{ "newTabProfile2" };
Expand Down Expand Up @@ -64,6 +65,7 @@ static const std::map<std::string_view, ShortcutAction, std::less<>> commandName
{ CopyTextWithoutNewlinesKey, ShortcutAction::CopyTextWithoutNewlines },
{ PasteTextKey, ShortcutAction::PasteText },
{ NewTabKey, ShortcutAction::NewTab },
{ DuplicateTabKey, ShortcutAction::DuplicateTab },
{ NewTabWithProfile0Key, ShortcutAction::NewTabProfile0 },
{ NewTabWithProfile1Key, ShortcutAction::NewTabProfile1 },
{ NewTabWithProfile2Key, ShortcutAction::NewTabProfile2 },
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ void CascadiaSettings::_CreateDefaultKeybindings()
keyBindings.SetKeyBinding(ShortcutAction::NewTab,
KeyChord{ KeyModifiers::Ctrl,
static_cast<int>('T') });
keyBindings.SetKeyBinding(ShortcutAction::DuplicateTab,
KeyChord{ KeyModifiers::Ctrl | KeyModifiers::Shift,
static_cast<int>('D') });

keyBindings.SetKeyBinding(ShortcutAction::CloseTab,
KeyChord{ KeyModifiers::Ctrl,
Expand Down