Add miscellaneous simple settings to the settings UI

This commit is contained in:
Carlos Zamora 2024-09-12 14:29:04 -07:00
parent 6196a3d0f7
commit c895a7379f
16 changed files with 197 additions and 26 deletions

View File

@ -573,11 +573,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}
double AppearanceViewModel::LineHeight() const
double AppearanceViewModel::_extractCellSizeValue(const hstring val) const
{
const auto fontInfo = _appearance.SourceProfile().FontInfo();
const auto cellHeight = fontInfo.CellHeight();
const auto str = cellHeight.c_str();
const auto str = val.c_str();
auto& errnoRef = errno; // Nonzero cost, pay it once.
errnoRef = 0;
@ -588,29 +586,49 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return str == end || errnoRef == ERANGE ? NAN : value;
}
double AppearanceViewModel::LineHeight() const
{
const auto cellHeight = _appearance.SourceProfile().FontInfo().CellHeight();
return _extractCellSizeValue(cellHeight);
}
double AppearanceViewModel::CellWidth() const
{
const auto cellWidth = _appearance.SourceProfile().FontInfo().CellHeight();
return _extractCellSizeValue(cellWidth);
}
#define CELL_SIZE_SETTER(modelName, viewModelName) \
std::wstring str; \
\
if (value >= 0.1 && value <= 10.0) \
{ \
str = fmt::format(FMT_STRING(L"{:.6g}"), value); \
} \
\
const auto fontInfo = _appearance.SourceProfile().FontInfo(); \
\
if (fontInfo.modelName() != str) \
{ \
if (str.empty()) \
{ \
fontInfo.Clear##modelName(); \
} \
else \
{ \
fontInfo.modelName(str); \
} \
_NotifyChanges(L"Has" #viewModelName, L## #viewModelName); \
}
void AppearanceViewModel::LineHeight(const double value)
{
std::wstring str;
CELL_SIZE_SETTER(CellHeight, LineHeight);
}
if (value >= 0.1 && value <= 10.0)
{
str = fmt::format(FMT_STRING(L"{:.6g}"), value);
}
const auto fontInfo = _appearance.SourceProfile().FontInfo();
if (fontInfo.CellHeight() != str)
{
if (str.empty())
{
fontInfo.ClearCellHeight();
}
else
{
fontInfo.CellHeight(str);
}
_NotifyChanges(L"HasLineHeight", L"LineHeight");
}
void AppearanceViewModel::CellWidth(const double value)
{
CELL_SIZE_SETTER(CellWidth, CellWidth);
}
bool AppearanceViewModel::HasLineHeight() const
@ -619,17 +637,34 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return fontInfo.HasCellHeight();
}
bool AppearanceViewModel::HasCellWidth() const
{
const auto fontInfo = _appearance.SourceProfile().FontInfo();
return fontInfo.HasCellWidth();
}
void AppearanceViewModel::ClearLineHeight()
{
LineHeight(NAN);
}
void AppearanceViewModel::ClearCellWidth()
{
CellWidth(NAN);
}
Model::FontConfig AppearanceViewModel::LineHeightOverrideSource() const
{
const auto fontInfo = _appearance.SourceProfile().FontInfo();
return fontInfo.CellHeightOverrideSource();
}
Model::FontConfig AppearanceViewModel::CellWidthOverrideSource() const
{
const auto fontInfo = _appearance.SourceProfile().FontInfo();
return fontInfo.CellWidthOverrideSource();
}
void AppearanceViewModel::SetFontWeightFromDouble(double fontWeight)
{
FontWeight(winrt::Microsoft::Terminal::UI::Converters::DoubleToFontWeight(fontWeight));

View File

@ -92,6 +92,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void ClearLineHeight();
Model::FontConfig LineHeightOverrideSource() const;
double CellWidth() const;
void CellWidth(const double value);
bool HasCellWidth() const;
void ClearCellWidth();
Model::FontConfig CellWidthOverrideSource() const;
void SetFontWeightFromDouble(double fontWeight);
const FontFaceDependentsData& FontFaceDependents();
@ -161,6 +167,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void _deleteAllFontKeyValuePairs(FontSettingIndex index);
void _addMenuFlyoutItemToUnused(FontSettingIndex index, Windows::UI::Xaml::Controls::MenuFlyoutItemBase item);
double _extractCellSizeValue(const hstring val) const;
Model::AppearanceConfig _appearance;
winrt::hstring _lastBgImagePath;
std::optional<FontFaceDependentsData> _fontFaceDependents;

View File

@ -62,6 +62,7 @@ namespace Microsoft.Terminal.Settings.Editor
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(String, FontFace);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Single, FontSize);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Double, LineHeight);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Double, CellWidth);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Windows.UI.Text.FontWeight, FontWeight);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Boolean, EnableBuiltinGlyphs);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Boolean, EnableColorGlyphs);

View File

@ -264,6 +264,22 @@
Value="{x:Bind Appearance.LineHeight, Mode=TwoWay}" />
</local:SettingContainer>
<!-- Cell Width -->
<local:SettingContainer x:Uid="Profile_CellWidth"
ClearSettingValue="{x:Bind Appearance.ClearCellWidth}"
HasSettingValue="{x:Bind Appearance.HasCellWidth, Mode=OneWay}"
SettingOverrideSource="{x:Bind Appearance.CellWidthOverrideSource, Mode=OneWay}"
Visibility="{x:Bind Appearance.IsDefault, Mode=OneWay}">
<muxc:NumberBox x:Name="_cellWidthBox"
x:Uid="Profile_CellWidthBox"
LargeChange="0.1"
Maximum="10"
Minimum="0.1"
SmallChange="0.1"
Style="{StaticResource NumberBoxSettingStyle}"
Value="{x:Bind Appearance.CellWidth, Mode=TwoWay}" />
</local:SettingContainer>
<!-- Font Weight -->
<local:SettingContainer x:Uid="Profile_FontWeight"
ClearSettingValue="{x:Bind Appearance.ClearFontWeight}"

View File

@ -129,5 +129,17 @@
<ToggleSwitch IsOn="{x:Bind ViewModel.AutoHideWindow, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
<!-- Show Admin Shield -->
<local:SettingContainer x:Uid="Globals_ShowAdminShield">
<ToggleSwitch IsOn="{x:Bind ViewModel.ShowAdminShield, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
<!-- Enable Unfocused Acrylic -->
<local:SettingContainer x:Uid="Globals_EnableUnfocusedAcrylic">
<ToggleSwitch IsOn="{x:Bind ViewModel.EnableUnfocusedAcrylic, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
</StackPanel>
</Page>

View File

@ -49,6 +49,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, AutoHideWindow);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, AlwaysShowNotificationIcon);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, MinimizeToNotificationArea);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, ShowAdminShield);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, EnableUnfocusedAcrylic);
private:
Model::GlobalAppSettings _GlobalSettings;

View File

@ -38,5 +38,7 @@ namespace Microsoft.Terminal.Settings.Editor
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, AutoHideWindow);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, AlwaysShowNotificationIcon);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, MinimizeToNotificationArea);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, ShowAdminShield);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, EnableUnfocusedAcrylic);
}
}

View File

@ -88,9 +88,25 @@
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
<!-- Search Web Default Query URL -->
<local:SettingContainer x:Uid="Globals_SearchWebDefaultQueryUrl"
CurrentValue="{x:Bind ViewModel.SearchWebDefaultQueryUrl, Mode=OneWay}"
Style="{StaticResource ExpanderSettingContainerStyle}">
<TextBox IsSpellCheckEnabled="False"
Style="{StaticResource TextBoxSettingStyle}"
Text="{x:Bind ViewModel.SearchWebDefaultQueryUrl, Mode=TwoWay}" />
</local:SettingContainer>
<!-- Confirm Close All Tabs -->
<local:SettingContainer x:Uid="Globals_ConfirmCloseAllTabs">
<ToggleSwitch IsOn="{x:Bind ViewModel.ConfirmCloseAllTabs, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
<!-- Enable Color Selection -->
<local:SettingContainer x:Uid="Globals_EnableColorSelection">
<ToggleSwitch IsOn="{x:Bind ViewModel.EnableColorSelection, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
</StackPanel>
</Page>

View File

@ -26,8 +26,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, SnapToGridOnResize);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, FocusFollowMouse);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, DetectURLs);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, SearchWebDefaultQueryUrl);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, WordDelimiters);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, ConfirmCloseAllTabs);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, EnableColorSelection);
private:
Model::GlobalAppSettings _GlobalSettings;

View File

@ -23,7 +23,9 @@ namespace Microsoft.Terminal.Settings.Editor
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, SnapToGridOnResize);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, FocusFollowMouse);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, DetectURLs);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(String, SearchWebDefaultQueryUrl);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(String, WordDelimiters);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, ConfirmCloseAllTabs);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, EnableColorSelection);
}
}

View File

@ -120,6 +120,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
OBSERVABLE_PROJECTED_SETTING(_profile, ShowMarks);
OBSERVABLE_PROJECTED_SETTING(_profile, AutoMarkPrompts);
OBSERVABLE_PROJECTED_SETTING(_profile, RepositionCursorWithMouse);
OBSERVABLE_PROJECTED_SETTING(_profile, RainbowSuggestions);
OBSERVABLE_PROJECTED_SETTING(_profile, AnswerbackMessage);
WINRT_PROPERTY(bool, IsBaseLayer, false);
WINRT_PROPERTY(bool, FocusDeleteButton, false);

View File

@ -111,5 +111,7 @@ namespace Microsoft.Terminal.Settings.Editor
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, ShowMarks);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, AutoMarkPrompts);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, RepositionCursorWithMouse);
OBSERVABLE_PROJECTED_PROFILE_SETTING(Boolean, RainbowSuggestions);
OBSERVABLE_PROJECTED_PROFILE_SETTING(String, AnswerbackMessage);
}
}

View File

@ -165,6 +165,25 @@
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
<!-- RainbowSuggestions -->
<local:SettingContainer x:Uid="Profile_RainbowSuggestions"
ClearSettingValue="{x:Bind Profile.ClearRainbowSuggestions}"
HasSettingValue="{x:Bind Profile.HasRainbowSuggestions, Mode=OneWay}"
SettingOverrideSource="{x:Bind Profile.RainbowSuggestionsOverrideSource, Mode=OneWay}">
<ToggleSwitch IsOn="{x:Bind Profile.RainbowSuggestions, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
<!-- Answerback Message -->
<local:SettingContainer x:Uid="Profile_AnswerbackMessage"
ClearSettingValue="{x:Bind Profile.ClearAnswerbackMessage}"
CurrentValue="{x:Bind Profile.AnswerbackMessage, Mode=OneWay}"
HasSettingValue="{x:Bind Profile.HasAnswerbackMessage, Mode=OneWay}"
SettingOverrideSource="{x:Bind Profile.AnswerbackMessageOverrideSource, Mode=OneWay}"
Style="{StaticResource ExpanderSettingContainerStyle}">
<TextBox Style="{StaticResource TextBoxSettingStyle}"
Text="{x:Bind Profile.AnswerbackMessage, Mode=TwoWay}" />
</local:SettingContainer>
</StackPanel>
</Grid>
</Page>

View File

@ -281,6 +281,14 @@
<value>Automatically detect URLs and make them clickable</value>
<comment>Header for a control to toggle whether the terminal should automatically detect URLs and make them clickable, or not.</comment>
</data>
<data name="Globals_SearchWebDefaultQueryUrl.Header" xml:space="preserve">
<value>Query URL for "Search web" action</value>
<comment>Header for a control to set the query URL when using the "search web" action.</comment>
</data>
<data name="Globals_SearchWebDefaultQueryUrl.HelpText" xml:space="preserve">
<value>"%s" is replaced with the selected text.</value>
<comment>{Locked="%s"} Additional text presented near "Globals_SearchWebDefaultQueryUrl.Header".</comment>
</data>
<data name="Globals_TrimBlockSelection.Header" xml:space="preserve">
<value>Remove trailing white-space in rectangular selection</value>
<comment>Header for a control to toggle whether a text selected with block selection should be trimmed of white spaces when copied to the clipboard, or not.</comment>
@ -932,18 +940,34 @@
<value>Line height</value>
<comment>Header for a control that sets the text line height.</comment>
</data>
<data name="Profile_CellWidth.Header" xml:space="preserve">
<value>Cell width</value>
<comment>Header for a control that sets the text character width.</comment>
</data>
<data name="Profile_LineHeightBox.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Line height</value>
<comment>Header for a control that sets the text line height.</comment>
</data>
<data name="Profile_CellWidthBox.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Cell width</value>
<comment>Header for a control that sets the text character width.</comment>
</data>
<data name="Profile_LineHeight.HelpText" xml:space="preserve">
<value>Override the line height of the terminal. Measured as a multiple of the font size. The default value depends on your font and is usually around 1.2.</value>
<comment>A description for what the "line height" setting does. Presented near "Profile_LineHeight".</comment>
</data>
<data name="Profile_CellWidth.HelpText" xml:space="preserve">
<value>Override the cell width of the terminal. Measured as a multiple of the font size. The default value depends on your font and is usually around 1.2.</value>
<comment>A description for what the "cell width" setting does. Presented near "Profile_CellWidth".</comment>
</data>
<data name="Profile_LineHeightBox.PlaceholderText" xml:space="preserve">
<value>1.2</value>
<comment>"1.2" is a decimal number.</comment>
</data>
<data name="Profile_CellWidthBox.PlaceholderText" xml:space="preserve">
<value>1.2</value>
<comment>"1.2" is a decimal number.</comment>
</data>
<data name="Profile_EnableBuiltinGlyphs.Header" xml:space="preserve">
<value>Builtin Glyphs</value>
<comment>The main label of a toggle. When enabled, certain characters (glyphs) are replaced with better looking ones.</comment>
@ -1156,10 +1180,18 @@
<value>Tab title</value>
<comment>Header for a control to determine the title of the tab. This is represented using a text box.</comment>
</data>
<data name="Profile_AnswerbackMessage.Header" xml:space="preserve">
<value>ENQ response</value>
<comment>{Locked=ENQ} Header for a control to determine the response to the ENQ escape sequence. This is represented using a text box.</comment>
</data>
<data name="Profile_TabTitle.HelpText" xml:space="preserve">
<value>Replaces the profile name as the title to pass to the shell on startup.</value>
<comment>A description for what the "tab title" setting does. Presented near "Profile_TabTitle".</comment>
</data>
<data name="Profile_AnswerbackMessage.HelpText" xml:space="preserve">
<value>The response that is sent when an ENQ control character is received.</value>
<comment>{Locked=ENQ} A description for what the "tab title" setting does. Presented near "Profile_TabTitle".</comment>
</data>
<data name="Profile_UnfocusedAppearanceTextBlock.Text" xml:space="preserve">
<value>Unfocused appearance</value>
<comment>The header for the section where the unfocused appearance settings can be changed.</comment>
@ -1839,4 +1871,20 @@
<value>Non-monospace fonts:</value>
<comment>This is a label that is followed by a list of proportional fonts.</comment>
</data>
<data name="Profile_RainbowSuggestions.Header" xml:space="preserve">
<value>Display suggestions UI preview text with rainbow formatting</value>
<comment>This is a label for a setting that, when enabled, applies a rainbow coloring to the preview text from the suggestions UI.</comment>
</data>
<data name="Globals_EnableColorSelection.Header" xml:space="preserve">
<value>Experimental: Add key bindings to color selected text</value>
<comment>Header for a control to toggle adding a set of key bindings that can be used to apply coloring to selected text in a terminal session.</comment>
</data>
<data name="Globals_EnableUnfocusedAcrylic.Header" xml:space="preserve">
<value>Allow acrylic background in unfocused windows</value>
<comment>Header for a control to toggle allowing unfocused windows to have an acrylic background.</comment>
</data>
<data name="Globals_ShowAdminShield.Header" xml:space="preserve">
<value>Display a shield in the title bar for sessions as Admin</value>
<comment>Header for a control to toggle displaying a shield in the title bar of the app. "Admin" refers to elevated sessions like "run as Admin"</comment>
</data>
</root>

View File

@ -92,14 +92,14 @@ Author(s):
X(hstring, TabTitle, "tabTitle") \
X(Model::BellStyle, BellStyle, "bellStyle", BellStyle::Audible) \
X(IEnvironmentVariableMap, EnvironmentVariables, "environment", nullptr) \
X(bool, RightClickContextMenu, "experimental.rightClickContextMenu", false) \
X(bool, RightClickContextMenu, "rightClickContextMenu", false) \
X(Windows::Foundation::Collections::IVector<winrt::hstring>, BellSound, "bellSound", nullptr) \
X(bool, Elevate, "elevate", false) \
X(bool, AutoMarkPrompts, "autoMarkPrompts", true) \
X(bool, ShowMarks, "showMarksOnScrollbar", false) \
X(bool, RepositionCursorWithMouse, "experimental.repositionCursorWithMouse", false) \
X(bool, ReloadEnvironmentVariables, "compatibility.reloadEnvironmentVariables", true) \
X(bool, RainbowSuggestions, "experimental.rainbowSuggestions", false)
X(bool, RainbowSuggestions, "rainbowSuggestions", false)
// Intentionally omitted Profile settings:
// * Name

View File

@ -36,6 +36,8 @@ static constexpr std::string_view UnfocusedAppearanceKey{ "unfocusedAppearance"
static constexpr std::string_view LegacyAutoMarkPromptsKey{ "experimental.autoMarkPrompts" };
static constexpr std::string_view LegacyShowMarksKey{ "experimental.showMarksOnScrollbar" };
static constexpr std::string_view LegacyRightClickContextMenuKey{ "experimental.rightClickContextMenu" };
static constexpr std::string_view LegacyRainbowSuggestionsKey{ "experimental.rainbowSuggestions" };
Profile::Profile(guid guid) noexcept :
_Guid(guid)
@ -196,6 +198,8 @@ void Profile::LayerJson(const Json::Value& json)
// Done _before_ the MTSM_PROFILE_SETTINGS, which have the updated keys.
JsonUtils::GetValueForKey(json, LegacyShowMarksKey, _ShowMarks);
JsonUtils::GetValueForKey(json, LegacyAutoMarkPromptsKey, _AutoMarkPrompts);
JsonUtils::GetValueForKey(json, LegacyRightClickContextMenuKey, _RightClickContextMenu);
JsonUtils::GetValueForKey(json, LegacyRainbowSuggestionsKey, _RainbowSuggestions);
#define PROFILE_SETTINGS_LAYER_JSON(type, name, jsonKey, ...) \
JsonUtils::GetValueForKey(json, jsonKey, _##name); \