Skip to content

Commit

Permalink
polish more now that we don't need hyperlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Feb 17, 2021
1 parent f8c4081 commit 500c38e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 76 deletions.
15 changes: 2 additions & 13 deletions src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw
Expand Up @@ -814,24 +814,13 @@
<data name="ColorScheme_RenameErrorTip.Title" xml:space="preserve">
<value>This color scheme name is already in use.</value>
</data>
<data name="SettingContainer_OverrideIntro" xml:space="preserve">
<value>This overrides the value from {}.</value>
<comment>"{}" is the object being overridden. Generally, it will be the name of another profile.</comment>
</data>
<data name="SettingContainer_ResetButtonHelpText" xml:space="preserve">
<value>Reset</value>
</data>
<data name="SettingContainer_OverrideTargetGenerator" xml:space="preserve">
<value>an autogenerated profile</value>
</data>
<data name="Globals_FocusFollowMouse.Header" xml:space="preserve">
<value>Enable Focus Follow Mouse mode</value>
</data>
<data name="Globals_FocusFollowMouse.HelpText" xml:space="preserve">
<value>When checked, the terminal will the focus pane on mouse hover.</value>
</data>
<data name="SettingContainer_OverrideTarget" xml:space="preserve">
<value>a lower layer</value>
<comment>This is the object of "SettingContainer_OverrideIntro".</comment>
<data name="SettingContainer_OverrideMessageBaseLayer" xml:space="preserve">
<value>Reset to base layer value</value>
</data>
</root>
114 changes: 52 additions & 62 deletions src/cascadia/TerminalSettingsEditor/SettingContainer.cpp
Expand Up @@ -68,7 +68,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
// update visibility for override message and reset button
const auto& obj{ d.try_as<Editor::SettingContainer>() };
get_self<SettingContainer>(obj)->_UpdateOverrideMessage();
get_self<SettingContainer>(obj)->_UpdateOverrideSystem();
}

void SettingContainer::OnApplyTemplate()
Expand Down Expand Up @@ -107,17 +107,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
});

// apply name (automation property)
Automation::AutomationProperties::SetName(child, RS_(L"SettingContainer_ResetButtonHelpText"));

// apply help text (automation property)
// NOTE: this can only be set _once_. Automation clients do not detect any changes.
// As a result, we're using the more generic version of the override message.
const hstring overrideMsg{ fmt::format(std::wstring_view{ RS_(L"SettingContainer_OverrideIntro") }, RS_(L"SettingContainer_OverrideTarget")) };
Automation::AutomationProperties::SetHelpText(child, overrideMsg);
Automation::AutomationProperties::SetName(child, RS_(L"SettingContainer_OverrideMessageBaseLayer"));
}
}

_UpdateOverrideMessage();
_UpdateOverrideSystem();

if (const auto& content{ Content() })
{
Expand All @@ -144,7 +138,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}

void SettingContainer::_UpdateOverrideMessage()
// Method Description:
// - Updates the override system visibility and text
// Arguments:
// - <none>
void SettingContainer::_UpdateOverrideSystem()
{
if (const auto& child{ GetTemplateChild(L"ResetButton") })
{
Expand All @@ -154,65 +152,27 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
// We want to be smart about showing the override system.
// Don't just show it if the user explicitly set the setting.
// If this flag is set, we'll hide the entire override system.
bool hideOverrideSystem = false;
// If the tooltip is empty, we'll hide the entire override system.
hstring tooltip;

const std::wstring templateText{ RS_(L"SettingContainer_OverrideIntro") };
const auto pos{ templateText.find(L"{}") };
std::wstring tooltip{};
if (pos != std::wstring::npos)
const auto& settingSrc{ SettingOverrideSource() };
if (!settingSrc)
{
// Append Message Prefix
tooltip = templateText.substr(0, pos);

// Append Message Target
{
const auto& settingSrc{ SettingOverrideSource() };
if (!settingSrc)
{
// no source; we're using the system-default value
hideOverrideSystem = true;
}
else if (const auto& profile{ settingSrc.try_as<Model::Profile>() })
{
const auto originTag{ profile.Origin() };
if (originTag == Model::OriginTag::InBox)
{
// in-box profile
hideOverrideSystem = true;
}
else if (originTag == Model::OriginTag::Generated)
{
// from a dynamic profile generator
// TODO #1690: add special handling for proto-extensions here
hideOverrideSystem = true;
}
else
{
// base layer
// TODO GH#3818: When we add profile inheritance as a setting,
// we'll need an extra conditional check to see if this
// is the base layer or some other profile
tooltip += RS_(L"Nav_ProfileDefaults/Content");
}
}
else
{
// unknown source
hideOverrideSystem = true;
}
}

// Append Message Suffix
tooltip += templateText.substr(pos + 2, templateText.npos);
// no source; we're using the system-default value
tooltip = L"";
}
else if (const auto& profile{ settingSrc.try_as<Model::Profile>() })
{
tooltip = _GenerateOverrideSystem(profile);
}
else
{
// '{}' was not found
hideOverrideSystem = true;
// unknown source
tooltip = L"";
}

Controls::ToolTipService::SetToolTip(button, box_value(tooltip));
button.Visibility(hideOverrideSystem ? Visibility::Collapsed : Visibility::Visible);
button.Visibility(tooltip.empty() ? Visibility::Collapsed : Visibility::Visible);
}
else
{
Expand All @@ -222,4 +182,34 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}
}

// Method Description:
// - Helper function for generating the override message
// Arguments:
// - profile: the profile that defines the setting (aka SettingOverrideSource)
// Return Value:
// - text specifying where the setting was defined. If empty, we don't want to show the system.
hstring SettingContainer::_GenerateOverrideSystem(const Model::Profile& profile)
{
const auto originTag{ profile.Origin() };
if (originTag == Model::OriginTag::InBox)
{
// in-box profile
return L"";
}
else if (originTag == Model::OriginTag::Generated)
{
// from a dynamic profile generator
// TODO #1690: add special handling for proto-extensions here
return L"";
}
else
{
// base layer
// TODO GH#3818: When we add profile inheritance as a setting,
// we'll need an extra conditional check to see if this
// is the base layer or some other profile
return RS_(L"SettingContainer_OverrideMessageBaseLayer");
}
}
}
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsEditor/SettingContainer.h
Expand Up @@ -59,7 +59,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
private:
static void _InitializeProperties();
static void _OnHasSettingValueChanged(Windows::UI::Xaml::DependencyObject const& d, Windows::UI::Xaml::DependencyPropertyChangedEventArgs const& e);
void _UpdateOverrideMessage();
static hstring _GenerateOverrideSystem(const Model::Profile& profile);
void _UpdateOverrideSystem();
};
}

Expand Down

0 comments on commit 500c38e

Please sign in to comment.