Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsEditor/Profiles.cpp (C++)

Code before:
            _UpdateFontList();
        }
    }

    void Profiles::_UpdateFontList()
    try
    {
        // initialize font list
        _FontList = single_threaded_observable_vector<hstring>();

        // get a DWriteFactory
        ::IUnknown* unknownFactory;
        THROW_IF_FAILED(DWriteCreateFactory(
            DWRITE_FACTORY_TYPE_SHARED,
            __uuidof(::IDWriteFactory),
            &unknownFactory));

        ::IDWriteFactory* dwriteFactory;
        THROW_IF_FAILED(unknownFactory->QueryInterface(&dwriteFactory));

        com_ptr<::IDWriteFactory> factory{};
        factory.attach(dwriteFactory);

        // get the font collection; subscribe to updates
        com_ptr<::IDWriteFontCollection> fontCollection;
        THROW_IF_FAILED(factory->GetSystemFontCollection(fontCollection.put(), TRUE));

        for (UINT32 i = 0; i < fontCollection->GetFontFamilyCount(); ++i)
        {
            try
            {
                // get the font
                com_ptr<::IDWriteFontFamily> fontFamily;
                THROW_IF_FAILED(fontCollection->GetFontFamily(i, fontFamily.put()));

                // get the font's localized names
                com_ptr<::IDWriteLocalizedStrings> localizedFamilyNames;
                THROW_IF_FAILED(fontFamily->GetFamilyNames(localizedFamilyNames.put()));

                // use our current locale to find the correct name
                BOOL exists{ FALSE };
                UINT32 index;
                HRESULT hr;
                wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
                if (GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH))
                {
                    hr = localizedFamilyNames->FindLocaleName(localeName, &index, &exists);
                }
                if (SUCCEEDED(hr) && !exists)
                {
                    hr = localizedFamilyNames->FindLocaleName(L"en-us", &index, &exists);

Review comment (bug):
If this first bit fails, should we reset the _FontList to nullptr, so we try building it again?

Code after:
    // Method Description:
    // - Searches through our list of monospace fonts to determine if the settings model's current font face is a monospace font
    // - NOTE: This is information stored from DWrite in _UpdateFontList()
    bool ProfileViewModel::UsingMonospaceFont() const noexcept
    {
        bool result{ false };
        const auto currentFont{ FontFace() };
        for (const auto& font : _MonospaceFontList)
        {
            if (font.LocalizedName() == currentFont)
            {
                result = true;
            }
        }
        return result;
    }

    // Method Description:
    // - Determines whether we should show the list of all the fonts, or we should just show monospace fonts
    bool ProfileViewModel::ShowAllFonts() const noexcept
    {
        // - _ShowAllFonts is directly bound to the checkbox. So this is the user set value.
        // - If we are not using a monospace font, show all of the fonts so that the ComboBox is still properly bound
        return _ShowAllFonts || !UsingMonospaceFont();
    }

    void ProfileViewModel::ShowAllFonts(const bool& value)
    {
        if (_ShowAllFonts != value)
        {
            _ShowAllFonts = value;
            _NotifyChanges(L"ShowAllFonts");
        }
    }

    bool ProfileViewModel::CanDeleteProfile() const
    {
        const auto guid{ Guid() };
        if (IsBaseLayer())
        {
            return false;
        }
        else if (std::find(std::begin(InBoxProfileGuids), std::end(InBoxProfileGuids), guid) != std::end(InBoxProfileGuids))
        {
            // in-box profile
            return false;
        }
        else if (!Source().empty())
        {
            // dynamic profile
            return false;