I think this is pretty close, but we're gonna wait on this one

fixes #6160

  [3:12 PM] Dustin Howett
    > we're gonna have to reason about what happens when we start keeping disconnected leaves (for user settings purposes)
    >
    > like, they will exist and they can be the default profile but we need a sane fallback
    >
    > and that will help us detect that there was a source but no generata

  So I'm stashing this until later after the elements of #9997 merge
This commit is contained in:
Mike Griese 2021-08-17 15:17:30 -05:00
parent 68294f863d
commit d486ccf244
7 changed files with 62 additions and 0 deletions

View file

@ -49,6 +49,7 @@ static const std::array<std::wstring_view, static_cast<uint32_t>(SettingsLoadWar
USES_RESOURCE(L"InvalidSplitSize"),
USES_RESOURCE(L"FailedToParseStartupActions"),
USES_RESOURCE(L"FailedToParseSubCommands"),
USES_RESOURCE(L"DidNotFindDynamicDefaultProfile"),
};
static const std::array<std::wstring_view, static_cast<uint32_t>(SettingsLoadErrors::ERRORS_SIZE)> settingsLoadErrorsLabels {
USES_RESOURCE(L"NoProfilesText"),
@ -488,6 +489,22 @@ namespace winrt::TerminalApp::implementation
warningsTextBlock.Inlines().Append(legacyGlobalsLink);
}
else if (warning == SettingsLoadWarnings::DidNotFindDynamicDefaultProfile)
{
// Add the URL here too
const auto linkLabel = RS_(L"DynamicDefaultProfileHrefLabel");
const auto uriValue = RS_(L"DynamicDefaultProfileHrefUrl");
winrt::Windows::UI::Xaml::Documents::Run legacyGlobalsLinkText;
winrt::Windows::UI::Xaml::Documents::Hyperlink legacyGlobalsLink;
winrt::Windows::Foundation::Uri linkUri{ uriValue };
legacyGlobalsLinkText.Text(linkLabel);
legacyGlobalsLink.NavigateUri(linkUri);
legacyGlobalsLink.Inlines().Append(legacyGlobalsLinkText);
warningsTextBlock.Inlines().Append(legacyGlobalsLink);
}
warningsTextBlock.Inlines().Append(Documents::LineBreak{});
}

View file

@ -232,6 +232,18 @@
<data name="FailedToParseSubCommands" xml:space="preserve">
<value>&#x2022; Failed to parse all subcommands of nested command.</value>
</data>
<data name="DidNotFindDynamicDefaultProfile" xml:space="preserve">
<value>&#x2022; We detected your default profile is a dynamic profile that did not generate. The original source of this profile may no longer exist.
</value>
<comment>{Locked="&#x2022;"} This glyph is a bullet, used in a bulleted list.</comment>
</data>
<data name="DynamicDefaultProfileHrefUrl" xml:space="preserve">
<value>https://go.microsoft.com/fwlink/?linkid=2170601</value>
<comment>{Locked}This is a FWLink, so it will be localized with the fwlink tool</comment>
</data>
<data name="DynamicDefaultProfileHrefLabel" xml:space="preserve">
<value>For more info, see this web page.</value>
</data>
<data name="MissingRequiredParameter" xml:space="preserve">
<value>&#x2022; Found a keybinding that was missing a required parameter value. This keybinding will be ignored.</value>
<comment>{Locked="&#x2022;"} This glyph is a bullet, used in a bulleted list.</comment>

View file

@ -532,6 +532,7 @@ void CascadiaSettings::_ValidateDefaultProfileExists()
if (nullDefaultProfile || defaultProfileNotInProfiles)
{
// TODO! Don't add the warning if we already have a DidNotFindDynamicDefaultProfile warning.
_warnings.Append(Microsoft::Terminal::Settings::Model::SettingsLoadWarnings::MissingDefaultProfile);
// Use the first profile as the new default

View file

@ -942,6 +942,31 @@ void CascadiaSettings::_LayerOrCreateProfile(const Json::Value& profileJson)
profile->LayerJson(profileJson);
_allProfiles.Append(*profile);
}
else
{
// TODO!
const auto guid = Profile::GetGuidOrGenerateForJson(profileJson);
try
{
// This might throw
if (guid == _globals->DefaultProfile())
{
_warnings.Append(SettingsLoadWarnings::DidNotFindDynamicDefaultProfile);
}
}
catch (...)
{
// if it did, then the DefaultProfile isn't valid. It might be the name of the profile!
if (GlobalSettings().HasUnparsedDefaultProfile())
{
const auto unparsedDefaultProfile{ GlobalSettings().UnparsedDefaultProfile() };
if (Profile::GetNameForJson(profileJson) == unparsedDefaultProfile)
{
_warnings.Append(SettingsLoadWarnings::DidNotFindDynamicDefaultProfile);
}
}
}
}
}
if (profile && _userDefaultProfileSettings)

View file

@ -516,6 +516,11 @@ winrt::guid Profile::GetGuidOrGenerateForJson(const Json::Value& json) noexcept
return Profile::_GenerateGuidForProfile(name, source);
}
winrt::hstring Profile::GetNameForJson(const Json::Value& json) noexcept
{
return JsonUtils::GetValueForKey<hstring>(json, NameKey);
}
// Method Description:
// - Create a new serialized JsonObject from an instance of this class
// Arguments:

View file

@ -100,6 +100,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
hstring EvaluatedStartingDirectory() const;
static guid GetGuidOrGenerateForJson(const Json::Value& json) noexcept;
static hstring GetNameForJson(const Json::Value& json) noexcept;
Model::IAppearanceConfig DefaultAppearance();
Model::FontConfig FontInfo();

View file

@ -22,6 +22,7 @@ namespace Microsoft.Terminal.Settings.Model
InvalidSplitSize = 12,
FailedToParseStartupActions = 13,
FailedToParseSubCommands = 14,
DidNotFindDynamicDefaultProfile = 15,
WARNINGS_SIZE // IMPORTANT: This MUST be the last value in this enum. It's an unused placeholder.
};