Skip to content

Commit

Permalink
Add tab width modes: equal and titleLength (#3876)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
cinnamon-msft and carlos-zamora authored Jan 10, 2020
1 parent 8a21698 commit cbdfd0e
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 197 deletions.
393 changes: 197 additions & 196 deletions doc/cascadia/SettingsSchema.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@
"description": "When set to `true`, the window will snap to the nearest character boundary on resize. When `false`, the window will resize 'smoothly'",
"type": "boolean"
},
"tabWidthMode": {
"default": "equal",
"description": "Sets the width of the tabs.",
"enum": [
"equal",
"titleLength"
],
"type": "string"
},
"wordDelimiters": {
"default": " ./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}~?│",
"description": "Determines the delimiters used in a double click selection.",
Expand Down
56 changes: 56 additions & 0 deletions src/cascadia/TerminalApp/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace winrt::TerminalApp;
using namespace winrt::Windows::Data::Json;
using namespace winrt::Windows::UI::Xaml;
using namespace ::Microsoft::Console;
using namespace winrt::Microsoft::UI::Xaml::Controls;

static constexpr std::string_view KeybindingsKey{ "keybindings" };
static constexpr std::string_view DefaultProfileKey{ "defaultProfile" };
Expand All @@ -25,6 +26,9 @@ static constexpr std::string_view RowsToScrollKey{ "rowsToScroll" };
static constexpr std::string_view InitialPositionKey{ "initialPosition" };
static constexpr std::string_view ShowTitleInTitlebarKey{ "showTerminalTitleInTitlebar" };
static constexpr std::string_view RequestedThemeKey{ "requestedTheme" };
static constexpr std::string_view TabWidthModeKey{ "tabWidthMode" };
static constexpr std::wstring_view EqualTabWidthModeValue{ L"equal" };
static constexpr std::wstring_view TitleLengthTabWidthModeValue{ L"titleLength" };
static constexpr std::string_view ShowTabsInTitlebarKey{ "showTabsInTitlebar" };
static constexpr std::string_view WordDelimitersKey{ "wordDelimiters" };
static constexpr std::string_view CopyOnSelectKey{ "copyOnSelect" };
Expand All @@ -49,6 +53,7 @@ GlobalAppSettings::GlobalAppSettings() :
_showTitleInTitlebar{ true },
_showTabsInTitlebar{ true },
_requestedTheme{ ElementTheme::Default },
_tabWidthMode{ TabViewWidthMode::Equal },
_wordDelimiters{ DEFAULT_WORD_DELIMITERS },
_copyOnSelect{ false },
_launchMode{ LaunchMode::DefaultMode }
Expand Down Expand Up @@ -114,6 +119,16 @@ void GlobalAppSettings::SetRequestedTheme(const ElementTheme requestedTheme) noe
_requestedTheme = requestedTheme;
}

TabViewWidthMode GlobalAppSettings::GetTabWidthMode() const noexcept
{
return _tabWidthMode;
}

void GlobalAppSettings::SetTabWidthMode(const TabViewWidthMode tabWidthMode)
{
_tabWidthMode = tabWidthMode;
}

std::wstring GlobalAppSettings::GetWordDelimiters() const noexcept
{
return _wordDelimiters;
Expand Down Expand Up @@ -206,6 +221,7 @@ Json::Value GlobalAppSettings::ToJson() const
jsonObject[JsonKey(CopyOnSelectKey)] = _copyOnSelect;
jsonObject[JsonKey(LaunchModeKey)] = winrt::to_string(_SerializeLaunchMode(_launchMode));
jsonObject[JsonKey(RequestedThemeKey)] = winrt::to_string(_SerializeTheme(_requestedTheme));
jsonObject[JsonKey(TabWidthModeKey)] = winrt::to_string(_SerializeTabWidthMode(_tabWidthMode));
jsonObject[JsonKey(KeybindingsKey)] = _keybindings->ToJson();
jsonObject[JsonKey(SnapToGridOnResizeKey)] = _SnapToGridOnResize;

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

if (auto tabWidthMode{ json[JsonKey(TabWidthModeKey)] })
{
_tabWidthMode = _ParseTabWidthMode(GetWstringFromJson(tabWidthMode));
}

if (auto keybindings{ json[JsonKey(KeybindingsKey)] })
{
_keybindings->LayerJson(keybindings);
Expand Down Expand Up @@ -454,6 +475,41 @@ std::wstring_view GlobalAppSettings::_SerializeLaunchMode(const LaunchMode launc
}
}

// Method Description:
// - Helper function for converting the user-specified tab width
// to a TabViewWidthMode enum value
// Arguments:
// - tabWidthModeString: The string value from the settings file to parse
// Return Value:
// - The corresponding enum value which maps to the string provided by the user
TabViewWidthMode GlobalAppSettings::_ParseTabWidthMode(const std::wstring& tabWidthModeString) noexcept
{
if (tabWidthModeString == TitleLengthTabWidthModeValue)
{
return TabViewWidthMode::SizeToContent;
}
// default behavior for invalid data or EqualTabWidthValue
return TabViewWidthMode::Equal;
}

// Method Description:
// - Helper function for converting a TabViewWidthMode to its corresponding string
// value.
// Arguments:
// - tabWidthMode: The enum value to convert to a string.
// Return Value:
// - The string value for the given TabWidthMode
std::wstring_view GlobalAppSettings::_SerializeTabWidthMode(const TabViewWidthMode tabWidthMode) noexcept
{
switch (tabWidthMode)
{
case TabViewWidthMode::SizeToContent:
return TitleLengthTabWidthModeValue;
default:
return EqualTabWidthModeValue;
}
}

// Method Description:
// - Adds the given colorscheme to our map of schemes, using its name as the key.
// Arguments:
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/TerminalApp/GlobalAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class TerminalApp::GlobalAppSettings final

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

void SetTabWidthMode(const winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode tabWidthMode);

bool GetShowTabsInTitlebar() const noexcept;
void SetShowTabsInTitlebar(const bool showTabsInTitlebar) noexcept;

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

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

winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode GetTabWidthMode() const noexcept;

Json::Value ToJson() const;
static GlobalAppSettings FromJson(const Json::Value& json);
void LayerJson(const Json::Value& json);
Expand Down Expand Up @@ -100,12 +104,16 @@ class TerminalApp::GlobalAppSettings final
std::wstring _wordDelimiters;
bool _copyOnSelect;
winrt::Windows::UI::Xaml::ElementTheme _requestedTheme;
winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode _tabWidthMode;

winrt::TerminalApp::LaunchMode _launchMode;

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

static std::wstring_view _SerializeTabWidthMode(const winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode tabWidthMode) noexcept;
static winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode _ParseTabWidthMode(const std::wstring& tabWidthModeString) noexcept;

static void _ParseInitialPosition(const std::wstring& initialPosition,
std::optional<int32_t>& initialX,
std::optional<int32_t>& initialY) noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TabRowControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ the MIT License. See LICENSE in the project root for license information. -->
VerticalAlignment="Bottom"
HorizontalContentAlignment="Stretch"
IsAddTabButtonVisible="false"
TabWidthMode="SizeToContent"
TabWidthMode="Equal"
CanReorderTabs="True"
CanDragTabs="True"
AllowDropTabs="True">
Expand Down
9 changes: 9 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ namespace winrt::TerminalApp::implementation
_tabView.TabItemsChanged({ this, &TerminalPage::_OnTabItemsChanged });

_CreateNewTabFlyout();
_UpdateTabWidthMode();
_OpenNewTab(nullptr);

_tabContent.SizeChanged({ this, &TerminalPage::_OnContentSizeChanged });
Expand Down Expand Up @@ -695,6 +696,13 @@ namespace winrt::TerminalApp::implementation
}
}

// Method Description:
// - Handle changes to the tab width set by the user
void TerminalPage::_UpdateTabWidthMode()
{
_tabView.TabWidthMode(_settings->GlobalSettings().GetTabWidthMode());
}

// Method Description:
// - Handle changes in tab layout.
void TerminalPage::_UpdateTabView()
Expand Down Expand Up @@ -1416,6 +1424,7 @@ namespace winrt::TerminalApp::implementation
// profile, which might have changed
if (auto page{ weakThis.get() })
{
page->_UpdateTabWidthMode();
page->_CreateNewTabFlyout();
}
});
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 @@ -84,6 +84,7 @@ namespace winrt::TerminalApp::implementation
void _UpdateTitle(std::shared_ptr<Tab> tab);
void _UpdateTabIcon(std::shared_ptr<Tab> tab);
void _UpdateTabView();
void _UpdateTabWidthMode();
void _DuplicateTabViewItem();
void _RemoveTabViewItem(const Microsoft::UI::Xaml::Controls::TabViewItem& tabViewItem);
void _RemoveTabViewItemByIndex(uint32_t tabIndex);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"requestedTheme": "system",
"showTabsInTitlebar": true,
"showTerminalTitleInTitlebar": true,
"tabWidthMode": "equal",
"snapToGridOnResize": false,
"wordDelimiters": " /\\()\"'-.,:;<>~!@#$%^&*|+=[]{}~?\u2502",

Expand Down

0 comments on commit cbdfd0e

Please sign in to comment.