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

Code before:
    {
        _useDefaultLaunchPosition = useDefaultPosition;
        if (useDefaultPosition)
        {
            InitialPosX(NAN);
            InitialPosY(NAN);
            _NotifyChanges(L"InitialPosX", L"InitialPosY");
        }
        _NotifyChanges(L"UseDefaultLaunchPosition", L"LaunchParametersCurrentValue");
    }

    bool LaunchViewModel::UseDefaultLaunchPosition()
    {
        return _useDefaultLaunchPosition;
    }

    winrt::Windows::Foundation::IInspectable LaunchViewModel::CurrentLaunchMode()
    {
        return winrt::box_value<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>(_LaunchModeMap.Lookup(_Settings.GlobalSettings().LaunchMode()));
    }

    void LaunchViewModel::CurrentLaunchMode(const winrt::Windows::Foundation::IInspectable& enumEntry)
    {
        if (auto ee = enumEntry.try_as<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>())
        {
            auto setting = winrt::unbox_value<LaunchMode>(ee.EnumValue());
            _Settings.GlobalSettings().LaunchMode(setting);
            _NotifyChanges(L"LaunchParametersCurrentValue");
        }
    }

    winrt::Windows::Foundation::IInspectable LaunchViewModel::CurrentDefaultProfile()
    {
        const auto defaultProfileGuid{ _Settings.GlobalSettings().DefaultProfile() };
        return winrt::box_value(_Settings.FindProfile(defaultProfileGuid));
    }

    void LaunchViewModel::CurrentDefaultProfile(const IInspectable& value)
    {
        const auto profile{ winrt::unbox_value<Model::Profile>(value) };
        _Settings.GlobalSettings().DefaultProfile(profile.Guid());
    }

    winrt::Windows::Foundation::Collections::IObservableVector<Model::Profile> LaunchViewModel::DefaultProfiles() const
    {
        const auto allProfiles = _Settings.AllProfiles();

        std::vector<Model::Profile> profiles;
        profiles.reserve(allProfiles.Size());

        // Remove profiles from the selection which have been explicitly deleted.

Review comment (suggestion):
```suggestion
        if (const auto ee = enumEntry.try_as<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>())
        {
            const auto setting = winrt::unbox_value<LaunchMode>(ee.EnumValue());
```

Code after:
    {
        return winrt::box_value<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>(_LaunchModeMap.Lookup(_Settings.GlobalSettings().LaunchMode()));
    }

    void LaunchViewModel::CurrentLaunchMode(const winrt::Windows::Foundation::IInspectable& enumEntry)
    {
        if (const auto ee = enumEntry.try_as<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>())
        {
            const auto setting = winrt::unbox_value<LaunchMode>(ee.EnumValue());
            _Settings.GlobalSettings().LaunchMode(setting);
            _NotifyChanges(L"LaunchParametersCurrentValue");
        }
    }

    winrt::Windows::Foundation::Collections::IObservableVector<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry> LaunchViewModel::LaunchModeList()
    {
        return _LaunchModeList;
    }

    winrt::Windows::Foundation::IInspectable LaunchViewModel::CurrentDefaultProfile()
    {
        const auto defaultProfileGuid{ _Settings.GlobalSettings().DefaultProfile() };
        return winrt::box_value(_Settings.FindProfile(defaultProfileGuid));
    }

    void LaunchViewModel::CurrentDefaultProfile(const IInspectable& value)
    {
        const auto profile{ winrt::unbox_value<Model::Profile>(value) };
        _Settings.GlobalSettings().DefaultProfile(profile.Guid());
    }

    winrt::Windows::Foundation::Collections::IObservableVector<Model::Profile> LaunchViewModel::DefaultProfiles() const
    {
        const auto allProfiles = _Settings.AllProfiles();

        std::vector<Model::Profile> profiles;
        profiles.reserve(allProfiles.Size());

        // Remove profiles from the selection which have been explicitly deleted.
        // We do want to show hidden profiles though, as they are just hidden
        // from menus, but still work as the startup profile for instance.
        for (const auto& profile : allProfiles)
        {
            if (!profile.Deleted())
            {
                profiles.emplace_back(profile);
            }
        }

        return winrt::single_threaded_observable_vector(std::move(profiles));
    }