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

Represent inheritance in Settings UI #8919

Merged
18 commits merged into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
61 changes: 36 additions & 25 deletions src/cascadia/TerminalSettingsEditor/SettingContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
elem.Visibility(newVal ? Visibility::Visible : Visibility::Collapsed);
}
}

// update the automation property
if (auto content{ obj.Content() })
{
// apply override message as help text (automation property)
if (const auto overrideMsg{ winrt::get_self<implementation::SettingContainer>(obj)->_GenerateOverrideMessageText() })
{
Automation::AutomationProperties::SetHelpText(obj, *overrideMsg);
}
}
}

void SettingContainer::OnApplyTemplate()
{
// This message is only populated if `HasSettingValue` is true.
const auto overrideMsg{ _GenerateOverrideMessageText() };

if (auto child{ GetTemplateChild(L"ResetButton") })
{
if (auto button{ child.try_as<Controls::Button>() })
Expand All @@ -98,12 +91,35 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// resulting in inheriting the setting value from the parent.
button.Click([=](auto&&, auto&&) {
_ClearSettingValueHandlers(*this, nullptr);

// move the focus to the child control
if (auto content{ Content() })
{
if (auto control{ content.try_as<Controls::Control>() })
{
control.Focus(FocusState::Programmatic);
return;
}
else if (auto panel{ content.try_as<Controls::Panel>() })
{
for (auto panelChild : panel.Children())
{
if (auto panelControl{ panelChild.try_as<Controls::Control>() })
{
panelControl.Focus(FocusState::Programmatic);
return;
}
}
}
// if we get here, we didn't find something to reasonably focus to.
}
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
});

// apply tooltip and help text (automation property)
const auto& helpText{ RS_(L"SettingContainer_ResetButtonHelpText") };
Controls::ToolTipService::SetToolTip(child, box_value(helpText));
Automation::AutomationProperties::SetName(child, helpText);
// apply tooltip and name (automation property)
const auto& name{ RS_(L"SettingContainer_ResetButtonHelpText") };
Controls::ToolTipService::SetToolTip(child, box_value(name));
Automation::AutomationProperties::SetName(child, name);
Automation::AutomationProperties::SetHelpText(child, overrideMsg);

// initialize visibility for reset button
button.Visibility(HasSettingValue() ? Visibility::Visible : Visibility::Collapsed);
Expand All @@ -114,11 +130,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
if (auto tb{ child.try_as<Controls::TextBlock>() })
{
if (const auto overrideMsg{ _GenerateOverrideMessageText() })
const auto overrideMsg{ _GenerateOverrideMessageText() };
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
if (!overrideMsg.empty())
{
// Create the override message
// TODO GH#6800: the override target will be replaced with hyperlink/text directing the user to another profile.
tb.Text(*_GenerateOverrideMessageText());
tb.Text(overrideMsg);

// initialize visibility for reset button
tb.Visibility(Visibility::Visible);
Expand All @@ -145,12 +162,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}

// apply override message as help text (automation property)
if (auto overrideMsg{ _GenerateOverrideMessageText() })
{
Automation::AutomationProperties::SetHelpText(obj, *overrideMsg);
}

// apply help text as tooltip and full description (automation property)
const auto& helpText{ HelpText() };
if (!helpText.empty())
Expand All @@ -162,12 +173,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}

std::optional<std::wstring> SettingContainer::_GenerateOverrideMessageText()
hstring SettingContainer::_GenerateOverrideMessageText()
{
if (HasSettingValue())
{
return fmt::format(std::wstring_view{ RS_(L"SettingContainer_OverrideIntro") }, RS_(L"SettingContainer_OverrideTarget"));
return hstring{ fmt::format(std::wstring_view{ RS_(L"SettingContainer_OverrideIntro") }, RS_(L"SettingContainer_OverrideTarget")) };
}
return std::nullopt;
return {};
}
}
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsEditor/SettingContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ 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);
std::optional<std::wstring> _GenerateOverrideMessageText();
hstring _GenerateOverrideMessageText();
};
}

Expand Down