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

Add support for setting a profile's tab title #1358

Merged
merged 7 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/cascadia/SettingsSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Properties listed below are specific to each unique profile.
| `foreground` | Optional | String | Sets the foreground color of the profile. Overrides `foreground` set in color scheme if `colorscheme` is set. Uses hex color format: `"#rrggbb"`. |
| `icon` | Optional | String | Image file location of the icon used in the profile. Displays within the tab and the dropdown menu. |
| `scrollbarState` | Optional | String | Defines the visibility of the scrollbar. Possible values: `"visible"`, `"hidden"` |
| `tabTitle` | Optional | String | Overrides default title of the tab. |

## Schemes
Properties listed below are specific to each color scheme. [ColorTool](https:/microsoft/terminal/tree/master/src/tools/ColorTool) is a great tool you can use to create and explore new color schemes. All colors use hex color format.
Expand Down
20 changes: 14 additions & 6 deletions src/cascadia/TerminalApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ namespace winrt::TerminalApp::implementation
for (auto& tab : _tabs)
{
_UpdateTabIcon(tab);
_UpdateTitle(tab);
}

_root.Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [this]() {
Expand Down Expand Up @@ -733,14 +734,21 @@ namespace winrt::TerminalApp::implementation
void App::_UpdateTitle(std::shared_ptr<Tab> tab)
{
auto newTabTitle = tab->GetFocusedTitle();
const auto lastFocusedProfile = tab->GetFocusedProfile().value();
const auto* const matchingProfile = _settings->FindProfile(lastFocusedProfile);

const auto tabTitle = matchingProfile->GetTabTitle();

// Checks if tab title has been set in the profile settings and
// updates accordingly.

const auto newActualTitle = tabTitle.empty() ? newTabTitle : tabTitle;

// TODO #608: If the settings don't want the terminal's text in the
// tab, then display something else.
tab->SetTabText(newTabTitle);
tab->SetTabText(winrt::to_hstring(newActualTitle.data()));
if (_settings->GlobalSettings().GetShowTitleInTitlebar() &&
tab->IsFocused())
{
_titleChangeHandlers(newTabTitle);
_titleChangeHandlers(newActualTitle);
}
}

Expand Down Expand Up @@ -933,14 +941,14 @@ namespace winrt::TerminalApp::implementation
// Add the new tab to the list of our tabs.
auto newTab = _tabs.emplace_back(std::make_shared<Tab>(profileGuid, term));

const auto* const profile = _settings->FindProfile(profileGuid);

// Hookup our event handlers to the new terminal
_RegisterTerminalEvents(term, newTab);

auto tabViewItem = newTab->GetTabViewItem();
_tabView.Items().Append(tabViewItem);

const auto* const profile = _settings->FindProfile(profileGuid);

// Set this profile's tab to the icon the user specified
if (profile != nullptr && profile->HasIcon())
{
Expand Down
40 changes: 40 additions & 0 deletions src/cascadia/TerminalApp/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static constexpr std::string_view ColorSchemeKeyOld{ "colorscheme" };
static constexpr std::string_view ForegroundKey{ "foreground" };
static constexpr std::string_view BackgroundKey{ "background" };
static constexpr std::string_view ColorTableKey{ "colorTable" };
static constexpr std::string_view TabTitleKey{ "tabTitle" };
static constexpr std::string_view HistorySizeKey{ "historySize" };
static constexpr std::string_view SnapOnInputKey{ "snapOnInput" };
static constexpr std::string_view CursorColorKey{ "cursorColor" };
Expand Down Expand Up @@ -71,6 +72,7 @@ Profile::Profile(const winrt::guid& guid) :
_defaultForeground{},
_defaultBackground{},
_colorTable{},
_tabTitle{},
_historySize{ DEFAULT_HISTORY_SIZE },
_snapOnInput{ true },
_cursorColor{ DEFAULT_CURSOR_COLOR },
Expand Down Expand Up @@ -271,6 +273,11 @@ Json::Value Profile::ToJson() const
root[JsonKey(IconKey)] = icon;
}

if (_tabTitle)
{
root[JsonKey(TabTitleKey)] = winrt::to_string(_tabTitle.value());
}

if (_startingDirectory)
{
root[JsonKey(StartingDirectoryKey)] = winrt::to_string(_startingDirectory.value());
Expand Down Expand Up @@ -369,6 +376,10 @@ Profile Profile::FromJson(const Json::Value& json)
{
result._cursorShape = _ParseCursorShape(GetWstringFromJson(cursorShape));
}
if (auto tabTitle{ json[JsonKey(TabTitleKey)] })
{
result._tabTitle = GetWstringFromJson(tabTitle);
}

// Control Settings
if (auto commandline{ json[JsonKey(CommandlineKey)] })
Expand Down Expand Up @@ -477,6 +488,15 @@ bool Profile::HasIcon() const noexcept
return _icon.has_value();
}

// Method Description
// - Sets this profile's tab title.
// Arguments:
// - tabTitle: the tab title
void Profile::SetTabTitle(std::wstring tabTitle) noexcept
cinnamon-msft marked this conversation as resolved.
Show resolved Hide resolved
{
_tabTitle = tabTitle;
}

// Method Description:
// - Sets this profile's icon path.
// Arguments:
Expand Down Expand Up @@ -508,6 +528,26 @@ std::wstring_view Profile::GetName() const noexcept
return _name;
}

// Method Description:
// - Returns true if profile's custom tab title is set, if one is set. Otherwise returns false.
// Return Value:
// - true if this profile's custom tab title is set. Otherwise returns false.
bool Profile::HasTabTitle() const noexcept
cinnamon-msft marked this conversation as resolved.
Show resolved Hide resolved
{
return _tabTitle.has_value();
}

// Method Description:
// - Returns the custom tab title, if one is set. Otherwise returns the empty string.
// Return Value:
// - this profile's custom tab title, if one is set. Otherwise returns the empty string.
std::wstring_view Profile::GetTabTitle() const noexcept
cinnamon-msft marked this conversation as resolved.
Show resolved Hide resolved
{
return HasTabTitle() ?
std::wstring_view{ _tabTitle.value().c_str(), _tabTitle.value().size() } :
std::wstring_view{ L"", 0 };
}

bool Profile::GetCloseOnExit() const noexcept
{
return _closeOnExit;
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ class TerminalApp::Profile final

GUID GetGuid() const noexcept;
std::wstring_view GetName() const noexcept;
bool HasTabTitle() const noexcept;
std::wstring_view GetTabTitle() const noexcept;

void SetFontFace(std::wstring fontFace) noexcept;
void SetColorScheme(std::optional<std::wstring> schemeName) noexcept;
void SetTabTitle(std::wstring tabTitle) noexcept;
void SetAcrylicOpacity(double opacity) noexcept;
void SetCommandline(std::wstring cmdline) noexcept;
void SetStartingDirectory(std::wstring startingDirectory) noexcept;
Expand Down Expand Up @@ -71,6 +74,7 @@ class TerminalApp::Profile final
std::optional<uint32_t> _defaultForeground;
std::optional<uint32_t> _defaultBackground;
std::array<uint32_t, COLOR_TABLE_SIZE> _colorTable;
std::optional<std::wstring> _tabTitle;
int32_t _historySize;
bool _snapOnInput;
uint32_t _cursorColor;
Expand Down