Skip to content

Commit

Permalink
Add miscellaneous simple settings to the settings UI (#17923)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request
Adds the following settings to the settings UI:
- $profile.RainbowSuggestions
- $profile.CellWidth
- $global.SearchWebDefaultQueryUrl
- $global.EnableColorSelection
- $global.ShowAdminShield
- $global.EnableUnfocusedAcrylic

Additionally, the following settings have graduated from experimental 🎓:
- $profile.rightClickContextMenu

Part of #10000
  • Loading branch information
carlos-zamora authored Oct 10, 2024
1 parent 4386bf0 commit 0b4d3d5
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 24 deletions.
81 changes: 58 additions & 23 deletions src/cascadia/TerminalSettingsEditor/Appearances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}

double AppearanceViewModel::LineHeight() const
double AppearanceViewModel::_parseCellSizeValue(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;
Expand All @@ -588,29 +586,49 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return str == end || errnoRef == ERANGE ? NAN : value;
}

void AppearanceViewModel::LineHeight(const double value)
double AppearanceViewModel::LineHeight() const
{
std::wstring str;
const auto cellHeight = _appearance.SourceProfile().FontInfo().CellHeight();
return _parseCellSizeValue(cellHeight);
}

if (value >= 0.1 && value <= 10.0)
{
str = fmt::format(FMT_STRING(L"{:.6g}"), value);
}
double AppearanceViewModel::CellWidth() const
{
const auto cellWidth = _appearance.SourceProfile().FontInfo().CellWidth();
return _parseCellSizeValue(cellWidth);
}

const auto fontInfo = _appearance.SourceProfile().FontInfo();
#define CELL_SIZE_SETTER(modelName, viewModelName) \
std::wstring str; \
\
if (value >= 0.1 && value <= 10.0) \
{ \
str = fmt::format(FMT_COMPILE(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); \
}

if (fontInfo.CellHeight() != str)
{
if (str.empty())
{
fontInfo.ClearCellHeight();
}
else
{
fontInfo.CellHeight(str);
}
_NotifyChanges(L"HasLineHeight", L"LineHeight");
}
void AppearanceViewModel::LineHeight(const double value)
{
CELL_SIZE_SETTER(CellHeight, LineHeight);
}

void AppearanceViewModel::CellWidth(const double value)
{
CELL_SIZE_SETTER(CellWidth, CellWidth);
}

bool AppearanceViewModel::HasLineHeight() const
Expand All @@ -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));
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 _parseCellSizeValue(const hstring& val) const;

Model::AppearanceConfig _appearance;
winrt::hstring _lastBgImagePath;
std::optional<FontFaceDependentsData> _fontFaceDependents;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
12 changes: 12 additions & 0 deletions src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,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>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,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);
}
}
15 changes: 15 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Interaction.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@
<ToggleSwitch IsOn="{x:Bind ViewModel.DetectURLs, Mode=TwoWay}"
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>

<!-- Enable Color Selection -->
<local:SettingContainer x:Uid="Globals_EnableColorSelection">
<ToggleSwitch IsOn="{x:Bind ViewModel.EnableColorSelection, Mode=TwoWay}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
</StackPanel>

<StackPanel Style="{StaticResource SettingsStackStyle}">
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsEditor/InteractionViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ 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, InputServiceWarning);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, WarnAboutLargePaste);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, WarnAboutMultiLinePaste);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, EnableColorSelection);

private:
Model::GlobalAppSettings _GlobalSettings;
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsEditor/InteractionViewModel.idl
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ 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, InputServiceWarning);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, WarnAboutLargePaste);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, WarnAboutMultiLinePaste);
PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, EnableColorSelection);
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/ProfileViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ 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);

WINRT_PROPERTY(bool, IsBaseLayer, false);
WINRT_PROPERTY(bool, FocusDeleteButton, false);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ 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);
}
}
8 changes: 8 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Profiles_Advanced.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@
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>
</StackPanel>
</Grid>
</Page>
44 changes: 44 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,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>Default URL to use for the "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>The placeholder "%s" will replaced with the search query.</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>
Expand Down Expand Up @@ -945,18 +953,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 0.6.</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>0.6</value>
<comment>"0.6" 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>
Expand Down Expand Up @@ -1865,4 +1889,24 @@
<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>Experimental: Display suggested input in rainbow colors</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_EnableColorSelection.HelpText" xml:space="preserve">
<value>These key bindings can highlight the selected text or all instances of the selected text with a specified color.</value>
<comment>Additional text 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. Presented near "Globals_EnableColorSelection.Header".</comment>
</data>
<data name="Globals_EnableUnfocusedAcrylic.Header" xml:space="preserve">
<value>Allow acrylic material 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 when Windows Terminal is running as Administrator</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>
Loading

0 comments on commit 0b4d3d5

Please sign in to comment.