From 55dd4af9cb7ad197fb87c661f24a5e4de3ba0929 Mon Sep 17 00:00:00 2001 From: Sergey <45919738+serd2011@users.noreply.github.com> Date: Sat, 9 Jul 2022 00:46:01 +0300 Subject: [PATCH] Add ability to select where new tab will appear (#13421) ## Summary of the Pull Request Adds ability to select where new tab will appear: at the end or after currently selected tab. ## PR Checklist * [x] Closes #12955 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] 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. * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Detailed Description of the Pull Request / Additional comments PR adds setting "NewTabPosition" in global appearances with dropdown list and uses it then creating new tabs. This setting does not affect settings tab position (should it?). There should also be a documentation update, I'm just waiting to see if this change even acceptable. ## Validation Steps Performed --- src/cascadia/TerminalApp/TabManagement.cpp | 14 ++++++++++++-- .../TerminalSettingsEditor/GlobalAppearance.xaml | 9 +++++++++ .../GlobalAppearanceViewModel.cpp | 1 + .../GlobalAppearanceViewModel.h | 1 + .../GlobalAppearanceViewModel.idl | 3 +++ .../Resources/en-US/Resources.resw | 16 ++++++++++++++++ .../TerminalSettingsModel/EnumMappings.cpp | 1 + .../TerminalSettingsModel/EnumMappings.h | 1 + .../TerminalSettingsModel/EnumMappings.idl | 1 + .../TerminalSettingsModel/GlobalAppSettings.idl | 7 +++++++ .../TerminalSettingsModel/MTSMSettings.h | 1 + .../TerminalSettingsSerializationHelpers.h | 8 ++++++++ 12 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index e1631e1a229..332b8331292 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -125,8 +125,18 @@ namespace winrt::TerminalApp::implementation { newTabImpl->Initialize(); + uint32_t insertPosition = _tabs.Size(); + if (_settings.GlobalSettings().NewTabPosition() == NewTabPosition::AfterCurrentTab) + { + auto currentTabIndex = _GetFocusedTabIndex(); + if (currentTabIndex.has_value()) + { + insertPosition = currentTabIndex.value() + 1; + } + } + // Add the new tab to the list of our tabs. - _tabs.Append(*newTabImpl); + _tabs.InsertAt(insertPosition, *newTabImpl); _mruTabs.Append(*newTabImpl); newTabImpl->SetDispatch(*_actionDispatch); @@ -222,7 +232,7 @@ namespace winrt::TerminalApp::implementation }); auto tabViewItem = newTabImpl->TabViewItem(); - _tabView.TabItems().Append(tabViewItem); + _tabView.TabItems().InsertAt(insertPosition, tabViewItem); // Set this tab's icon to the icon from the user's profile if (const auto profile{ newTabImpl->GetFocusedProfile() }) diff --git a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml index 1674679e888..bf540a81465 100644 --- a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml +++ b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml @@ -60,6 +60,15 @@ Style="{StaticResource ToggleSwitchInExpanderStyle}" /> + + + + + () } { + INITIALIZE_BINDABLE_ENUM_SETTING(NewTabPosition, NewTabPosition, NewTabPosition, L"Globals_NewTabPosition", L"Content"); INITIALIZE_BINDABLE_ENUM_SETTING(TabWidthMode, TabViewWidthMode, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, L"Globals_TabWidthMode", L"Content"); _UpdateThemeList(); } diff --git a/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.h b/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.h index 2e8a803221e..9256537430f 100644 --- a/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.h @@ -16,6 +16,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, ThemeList, nullptr); + GETSET_BINDABLE_ENUM_SETTING(NewTabPosition, Model::NewTabPosition, _GlobalSettings.NewTabPosition); GETSET_BINDABLE_ENUM_SETTING(TabWidthMode, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, _GlobalSettings.TabWidthMode); public: diff --git a/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.idl b/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.idl index 436a9cbc0a4..8d14d618be1 100644 --- a/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.idl @@ -20,6 +20,9 @@ namespace Microsoft.Terminal.Settings.Editor static String ThemeNameConverter(Microsoft.Terminal.Settings.Model.Theme theme); Windows.Foundation.Collections.IObservableVector ThemeList { get; }; + IInspectable CurrentNewTabPosition; + Windows.Foundation.Collections.IObservableVector NewTabPositionList { get; }; + IInspectable CurrentTabWidthMode; Windows.Foundation.Collections.IObservableVector TabWidthModeList { get; }; diff --git a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw index 09954874cec..83f32f0fca0 100644 --- a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw @@ -235,6 +235,22 @@ When disabled, the tab bar will appear when a new tab is created. A description for what the "always show tabs" setting does. Presented near "Globals_AlwaysShowTabs.Header". + + Position of the new tab + Header for a control to select position of new tab. + + + Specifies position of the new tab + A description for what the "Position of the new tab" setting does. + + + At the end + An option to choose from for the "Position of the new tab" setting. When selected new tab appears at the end. + + + After current tab + An option to choose from for the "Position of the new tab" setting. When selected new tab appears after currently selected tab. + Automatically copy selection to clipboard Header for a control to toggle whether selected text should be copied to the clipboard automatically, or not. diff --git a/src/cascadia/TerminalSettingsModel/EnumMappings.cpp b/src/cascadia/TerminalSettingsModel/EnumMappings.cpp index 3b592c2a2aa..7b660b64097 100644 --- a/src/cascadia/TerminalSettingsModel/EnumMappings.cpp +++ b/src/cascadia/TerminalSettingsModel/EnumMappings.cpp @@ -31,6 +31,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { // Global Settings DEFINE_ENUM_MAP(winrt::Windows::UI::Xaml::ElementTheme, ElementTheme); + DEFINE_ENUM_MAP(Model::NewTabPosition, NewTabPosition); DEFINE_ENUM_MAP(winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, TabViewWidthMode); DEFINE_ENUM_MAP(Model::FirstWindowPreference, FirstWindowPreference); DEFINE_ENUM_MAP(Model::LaunchMode, LaunchMode); diff --git a/src/cascadia/TerminalSettingsModel/EnumMappings.h b/src/cascadia/TerminalSettingsModel/EnumMappings.h index 00f3b4ff124..ac5a1b19722 100644 --- a/src/cascadia/TerminalSettingsModel/EnumMappings.h +++ b/src/cascadia/TerminalSettingsModel/EnumMappings.h @@ -27,6 +27,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // Global Settings static winrt::Windows::Foundation::Collections::IMap ElementTheme(); + static winrt::Windows::Foundation::Collections::IMap NewTabPosition(); static winrt::Windows::Foundation::Collections::IMap TabViewWidthMode(); static winrt::Windows::Foundation::Collections::IMap FirstWindowPreference(); static winrt::Windows::Foundation::Collections::IMap LaunchMode(); diff --git a/src/cascadia/TerminalSettingsModel/EnumMappings.idl b/src/cascadia/TerminalSettingsModel/EnumMappings.idl index 341f5699c25..0c2a3a84ce7 100644 --- a/src/cascadia/TerminalSettingsModel/EnumMappings.idl +++ b/src/cascadia/TerminalSettingsModel/EnumMappings.idl @@ -9,6 +9,7 @@ namespace Microsoft.Terminal.Settings.Model [default_interface] runtimeclass EnumMappings { // Global Settings static Windows.Foundation.Collections.IMap ElementTheme { get; }; + static Windows.Foundation.Collections.IMap NewTabPosition { get; }; static Windows.Foundation.Collections.IMap TabViewWidthMode { get; }; static Windows.Foundation.Collections.IMap FirstWindowPreference { get; }; static Windows.Foundation.Collections.IMap LaunchMode { get; }; diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl index d14f2ab8276..9e6564740f1 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl @@ -42,6 +42,12 @@ namespace Microsoft.Terminal.Settings.Model PersistedWindowLayout, }; + enum NewTabPosition + { + AtTheEnd, + AfterCurrentTab, + }; + [default_interface] runtimeclass GlobalAppSettings { Guid DefaultProfile; @@ -50,6 +56,7 @@ namespace Microsoft.Terminal.Settings.Model INHERITABLE_SETTING(Int32, InitialRows); INHERITABLE_SETTING(Int32, InitialCols); INHERITABLE_SETTING(Boolean, AlwaysShowTabs); + INHERITABLE_SETTING(NewTabPosition, NewTabPosition); INHERITABLE_SETTING(Boolean, ShowTitleInTitlebar); INHERITABLE_SETTING(Boolean, ConfirmCloseAllTabs); INHERITABLE_SETTING(String, Language); diff --git a/src/cascadia/TerminalSettingsModel/MTSMSettings.h b/src/cascadia/TerminalSettingsModel/MTSMSettings.h index 5aded2c6ee5..c7abda9a29a 100644 --- a/src/cascadia/TerminalSettingsModel/MTSMSettings.h +++ b/src/cascadia/TerminalSettingsModel/MTSMSettings.h @@ -31,6 +31,7 @@ Author(s): X(bool, TrimBlockSelection, "trimBlockSelection", true) \ X(bool, DetectURLs, "experimental.detectURLs", true) \ X(bool, AlwaysShowTabs, "alwaysShowTabs", true) \ + X(Model::NewTabPosition, NewTabPosition, "newTabPosition", Model::NewTabPosition::AtTheEnd) \ X(bool, ShowTitleInTitlebar, "showTerminalTitleInTitlebar", true) \ X(bool, ConfirmCloseAllTabs, "confirmCloseAllTabs", true) \ X(hstring, Theme, "theme") \ diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h index 75e3fb63c1a..50a17a5abb2 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h @@ -209,6 +209,14 @@ JSON_ENUM_MAPPER(::winrt::Windows::UI::Xaml::ElementTheme) }; }; +JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::NewTabPosition) +{ + JSON_MAPPINGS(2) = { + pair_type{ "atTheEnd", ValueType::AtTheEnd }, + pair_type{ "afterCurrentTab", ValueType::AfterCurrentTab }, + }; +}; + JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::FirstWindowPreference) { JSON_MAPPINGS(2) = {