From e2273770a061a1390ad017d243c5c00acf1a3900 Mon Sep 17 00:00:00 2001 From: serd2011 <45919738+serd2011@users.noreply.github.com> Date: Sat, 2 Jul 2022 22:05:31 +0300 Subject: [PATCH 1/2] Added setting for new tab position --- .../TerminalSettingsEditor/GlobalAppearance.cpp | 1 + .../TerminalSettingsEditor/GlobalAppearance.h | 1 + .../TerminalSettingsEditor/GlobalAppearance.idl | 3 +++ .../TerminalSettingsEditor/GlobalAppearance.xaml | 9 +++++++++ .../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 ++++++++ 11 files changed, 49 insertions(+) diff --git a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.cpp b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.cpp index b34bf0a1e95..6e1aae276b6 100644 --- a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.cpp +++ b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.cpp @@ -46,6 +46,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation InitializeComponent(); INITIALIZE_BINDABLE_ENUM_SETTING(Theme, ElementTheme, winrt::Windows::UI::Xaml::ElementTheme, L"Globals_Theme", L"Content"); + 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"); } diff --git a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.h b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.h index 7e48178baf4..32cadc3e2b8 100644 --- a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.h +++ b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.h @@ -27,6 +27,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation WINRT_PROPERTY(Editor::GlobalAppearancePageNavigationState, State, nullptr); GETSET_BINDABLE_ENUM_SETTING(Theme, winrt::Windows::UI::Xaml::ElementTheme, State().Globals().Theme); + GETSET_BINDABLE_ENUM_SETTING(NewTabPosition, Model::NewTabPosition, State().Globals().NewTabPosition); GETSET_BINDABLE_ENUM_SETTING(TabWidthMode, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, State().Globals().TabWidthMode); public: diff --git a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.idl b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.idl index 7e3483140ab..8962747c62f 100644 --- a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.idl +++ b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.idl @@ -23,6 +23,9 @@ namespace Microsoft.Terminal.Settings.Editor IInspectable CurrentTheme; 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/GlobalAppearance.xaml b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml index 2d15f1c2103..c274e1d860a 100644 --- a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml +++ b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml @@ -54,6 +54,15 @@ Style="{StaticResource ToggleSwitchInExpanderStyle}" /> + + + + + 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 51386e6be34..102ea04e9d7 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl @@ -41,6 +41,12 @@ namespace Microsoft.Terminal.Settings.Model PersistedWindowLayout, }; + enum NewTabPosition + { + AtTheEnd, + AfterCurrentTab, + }; + [default_interface] runtimeclass GlobalAppSettings { Guid DefaultProfile; @@ -51,6 +57,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 e425bdfd877..61aac9cdb47 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, Language, "language") \ diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h index 9dd273ee3c9..7d94737676e 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) = { From b691b96f9958a7881736c9708a8359345ac2741d Mon Sep 17 00:00:00 2001 From: serd2011 <45919738+serd2011@users.noreply.github.com> Date: Sat, 2 Jul 2022 22:50:46 +0300 Subject: [PATCH 2/2] Added new tab position functionality --- src/cascadia/TerminalApp/TabManagement.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index 47cfa70d7b2..cb114071f76 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); @@ -220,7 +230,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() })