Skip to content

Commit cbdfd0e

Browse files
Add tab width modes: equal and titleLength (#3876)
* tab sizing functionality * Update doc/cascadia/SettingsSchema.md Co-Authored-By: Carlos Zamora <[email protected]> * updated variable names to match spec * added to defaults.json * fixed merge conflict Co-authored-by: Carlos Zamora <[email protected]>
1 parent 8a21698 commit cbdfd0e

8 files changed

+282
-197
lines changed

doc/cascadia/SettingsSchema.md

+197-196
Large diffs are not rendered by default.

doc/cascadia/profiles.schema.json

+9
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,15 @@
323323
"description": "When set to `true`, the window will snap to the nearest character boundary on resize. When `false`, the window will resize 'smoothly'",
324324
"type": "boolean"
325325
},
326+
"tabWidthMode": {
327+
"default": "equal",
328+
"description": "Sets the width of the tabs.",
329+
"enum": [
330+
"equal",
331+
"titleLength"
332+
],
333+
"type": "string"
334+
},
326335
"wordDelimiters": {
327336
"default": " ./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}~?│",
328337
"description": "Determines the delimiters used in a double click selection.",

src/cascadia/TerminalApp/GlobalAppSettings.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using namespace winrt::TerminalApp;
1515
using namespace winrt::Windows::Data::Json;
1616
using namespace winrt::Windows::UI::Xaml;
1717
using namespace ::Microsoft::Console;
18+
using namespace winrt::Microsoft::UI::Xaml::Controls;
1819

1920
static constexpr std::string_view KeybindingsKey{ "keybindings" };
2021
static constexpr std::string_view DefaultProfileKey{ "defaultProfile" };
@@ -25,6 +26,9 @@ static constexpr std::string_view RowsToScrollKey{ "rowsToScroll" };
2526
static constexpr std::string_view InitialPositionKey{ "initialPosition" };
2627
static constexpr std::string_view ShowTitleInTitlebarKey{ "showTerminalTitleInTitlebar" };
2728
static constexpr std::string_view RequestedThemeKey{ "requestedTheme" };
29+
static constexpr std::string_view TabWidthModeKey{ "tabWidthMode" };
30+
static constexpr std::wstring_view EqualTabWidthModeValue{ L"equal" };
31+
static constexpr std::wstring_view TitleLengthTabWidthModeValue{ L"titleLength" };
2832
static constexpr std::string_view ShowTabsInTitlebarKey{ "showTabsInTitlebar" };
2933
static constexpr std::string_view WordDelimitersKey{ "wordDelimiters" };
3034
static constexpr std::string_view CopyOnSelectKey{ "copyOnSelect" };
@@ -49,6 +53,7 @@ GlobalAppSettings::GlobalAppSettings() :
4953
_showTitleInTitlebar{ true },
5054
_showTabsInTitlebar{ true },
5155
_requestedTheme{ ElementTheme::Default },
56+
_tabWidthMode{ TabViewWidthMode::Equal },
5257
_wordDelimiters{ DEFAULT_WORD_DELIMITERS },
5358
_copyOnSelect{ false },
5459
_launchMode{ LaunchMode::DefaultMode }
@@ -114,6 +119,16 @@ void GlobalAppSettings::SetRequestedTheme(const ElementTheme requestedTheme) noe
114119
_requestedTheme = requestedTheme;
115120
}
116121

122+
TabViewWidthMode GlobalAppSettings::GetTabWidthMode() const noexcept
123+
{
124+
return _tabWidthMode;
125+
}
126+
127+
void GlobalAppSettings::SetTabWidthMode(const TabViewWidthMode tabWidthMode)
128+
{
129+
_tabWidthMode = tabWidthMode;
130+
}
131+
117132
std::wstring GlobalAppSettings::GetWordDelimiters() const noexcept
118133
{
119134
return _wordDelimiters;
@@ -206,6 +221,7 @@ Json::Value GlobalAppSettings::ToJson() const
206221
jsonObject[JsonKey(CopyOnSelectKey)] = _copyOnSelect;
207222
jsonObject[JsonKey(LaunchModeKey)] = winrt::to_string(_SerializeLaunchMode(_launchMode));
208223
jsonObject[JsonKey(RequestedThemeKey)] = winrt::to_string(_SerializeTheme(_requestedTheme));
224+
jsonObject[JsonKey(TabWidthModeKey)] = winrt::to_string(_SerializeTabWidthMode(_tabWidthMode));
209225
jsonObject[JsonKey(KeybindingsKey)] = _keybindings->ToJson();
210226
jsonObject[JsonKey(SnapToGridOnResizeKey)] = _SnapToGridOnResize;
211227

@@ -291,6 +307,11 @@ void GlobalAppSettings::LayerJson(const Json::Value& json)
291307
_requestedTheme = _ParseTheme(GetWstringFromJson(requestedTheme));
292308
}
293309

310+
if (auto tabWidthMode{ json[JsonKey(TabWidthModeKey)] })
311+
{
312+
_tabWidthMode = _ParseTabWidthMode(GetWstringFromJson(tabWidthMode));
313+
}
314+
294315
if (auto keybindings{ json[JsonKey(KeybindingsKey)] })
295316
{
296317
_keybindings->LayerJson(keybindings);
@@ -454,6 +475,41 @@ std::wstring_view GlobalAppSettings::_SerializeLaunchMode(const LaunchMode launc
454475
}
455476
}
456477

478+
// Method Description:
479+
// - Helper function for converting the user-specified tab width
480+
// to a TabViewWidthMode enum value
481+
// Arguments:
482+
// - tabWidthModeString: The string value from the settings file to parse
483+
// Return Value:
484+
// - The corresponding enum value which maps to the string provided by the user
485+
TabViewWidthMode GlobalAppSettings::_ParseTabWidthMode(const std::wstring& tabWidthModeString) noexcept
486+
{
487+
if (tabWidthModeString == TitleLengthTabWidthModeValue)
488+
{
489+
return TabViewWidthMode::SizeToContent;
490+
}
491+
// default behavior for invalid data or EqualTabWidthValue
492+
return TabViewWidthMode::Equal;
493+
}
494+
495+
// Method Description:
496+
// - Helper function for converting a TabViewWidthMode to its corresponding string
497+
// value.
498+
// Arguments:
499+
// - tabWidthMode: The enum value to convert to a string.
500+
// Return Value:
501+
// - The string value for the given TabWidthMode
502+
std::wstring_view GlobalAppSettings::_SerializeTabWidthMode(const TabViewWidthMode tabWidthMode) noexcept
503+
{
504+
switch (tabWidthMode)
505+
{
506+
case TabViewWidthMode::SizeToContent:
507+
return TitleLengthTabWidthModeValue;
508+
default:
509+
return EqualTabWidthModeValue;
510+
}
511+
}
512+
457513
// Method Description:
458514
// - Adds the given colorscheme to our map of schemes, using its name as the key.
459515
// Arguments:

src/cascadia/TerminalApp/GlobalAppSettings.h

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class TerminalApp::GlobalAppSettings final
5252

5353
void SetRequestedTheme(const winrt::Windows::UI::Xaml::ElementTheme requestedTheme) noexcept;
5454

55+
void SetTabWidthMode(const winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode tabWidthMode);
56+
5557
bool GetShowTabsInTitlebar() const noexcept;
5658
void SetShowTabsInTitlebar(const bool showTabsInTitlebar) noexcept;
5759

@@ -70,6 +72,8 @@ class TerminalApp::GlobalAppSettings final
7072

7173
winrt::Windows::UI::Xaml::ElementTheme GetRequestedTheme() const noexcept;
7274

75+
winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode GetTabWidthMode() const noexcept;
76+
7377
Json::Value ToJson() const;
7478
static GlobalAppSettings FromJson(const Json::Value& json);
7579
void LayerJson(const Json::Value& json);
@@ -100,12 +104,16 @@ class TerminalApp::GlobalAppSettings final
100104
std::wstring _wordDelimiters;
101105
bool _copyOnSelect;
102106
winrt::Windows::UI::Xaml::ElementTheme _requestedTheme;
107+
winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode _tabWidthMode;
103108

104109
winrt::TerminalApp::LaunchMode _launchMode;
105110

106111
static winrt::Windows::UI::Xaml::ElementTheme _ParseTheme(const std::wstring& themeString) noexcept;
107112
static std::wstring_view _SerializeTheme(const winrt::Windows::UI::Xaml::ElementTheme theme) noexcept;
108113

114+
static std::wstring_view _SerializeTabWidthMode(const winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode tabWidthMode) noexcept;
115+
static winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode _ParseTabWidthMode(const std::wstring& tabWidthModeString) noexcept;
116+
109117
static void _ParseInitialPosition(const std::wstring& initialPosition,
110118
std::optional<int32_t>& initialX,
111119
std::optional<int32_t>& initialY) noexcept;

src/cascadia/TerminalApp/TabRowControl.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ the MIT License. See LICENSE in the project root for license information. -->
1414
VerticalAlignment="Bottom"
1515
HorizontalContentAlignment="Stretch"
1616
IsAddTabButtonVisible="false"
17-
TabWidthMode="SizeToContent"
17+
TabWidthMode="Equal"
1818
CanReorderTabs="True"
1919
CanDragTabs="True"
2020
AllowDropTabs="True">

src/cascadia/TerminalApp/TerminalPage.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ namespace winrt::TerminalApp::implementation
127127
_tabView.TabItemsChanged({ this, &TerminalPage::_OnTabItemsChanged });
128128

129129
_CreateNewTabFlyout();
130+
_UpdateTabWidthMode();
130131
_OpenNewTab(nullptr);
131132

132133
_tabContent.SizeChanged({ this, &TerminalPage::_OnContentSizeChanged });
@@ -695,6 +696,13 @@ namespace winrt::TerminalApp::implementation
695696
}
696697
}
697698

699+
// Method Description:
700+
// - Handle changes to the tab width set by the user
701+
void TerminalPage::_UpdateTabWidthMode()
702+
{
703+
_tabView.TabWidthMode(_settings->GlobalSettings().GetTabWidthMode());
704+
}
705+
698706
// Method Description:
699707
// - Handle changes in tab layout.
700708
void TerminalPage::_UpdateTabView()
@@ -1416,6 +1424,7 @@ namespace winrt::TerminalApp::implementation
14161424
// profile, which might have changed
14171425
if (auto page{ weakThis.get() })
14181426
{
1427+
page->_UpdateTabWidthMode();
14191428
page->_CreateNewTabFlyout();
14201429
}
14211430
});

src/cascadia/TerminalApp/TerminalPage.h

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ namespace winrt::TerminalApp::implementation
8484
void _UpdateTitle(std::shared_ptr<Tab> tab);
8585
void _UpdateTabIcon(std::shared_ptr<Tab> tab);
8686
void _UpdateTabView();
87+
void _UpdateTabWidthMode();
8788
void _DuplicateTabViewItem();
8889
void _RemoveTabViewItem(const Microsoft::UI::Xaml::Controls::TabViewItem& tabViewItem);
8990
void _RemoveTabViewItemByIndex(uint32_t tabIndex);

src/cascadia/TerminalApp/defaults.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"requestedTheme": "system",
88
"showTabsInTitlebar": true,
99
"showTerminalTitleInTitlebar": true,
10+
"tabWidthMode": "equal",
1011
"snapToGridOnResize": false,
1112
"wordDelimiters": " /\\()\"'-.,:;<>~!@#$%^&*|+=[]{}~?\u2502",
1213

0 commit comments

Comments
 (0)