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

Code before:
            contentFrame().Navigate(xaml_typename<Editor::ColorSchemes>(), _colorSchemesNavState);
        }
        else if (clickedItemTag == globalAppearanceTag)
        {
            contentFrame().Navigate(xaml_typename<Editor::GlobalAppearance>(), winrt::make<GlobalAppearancePageNavigationState>(_settingsClone.GlobalSettings()));
        }
        else if (clickedItemTag == addProfileTag)
        {
            auto addProfileState{ winrt::make<AddProfilePageNavigationState>(_settingsClone) };
            addProfileState.AddNew([weakThis = get_weak()](auto&& profileGuid) {
                if (auto self{ weakThis.get() })
                {
                    uint32_t insertIndex;
                    auto selectedItem{ self->SettingsNav().SelectedItem() };
                    auto menuItems{ self->SettingsNav().MenuItems() };
                    menuItems.IndexOf(selectedItem, insertIndex);
                    if (profileGuid != winrt::guid{})
                    {
                        const auto profile = self->_settingsClone.FindProfile(profileGuid);
                        const auto duplicated = self->_settingsClone.DuplicateProfile(profile);
                        self->_CreateAndNavigateToNewProfile(insertIndex, duplicated);
                    }
                    else
                    {
                        self->_CreateAndNavigateToNewProfile(insertIndex, nullptr);
                    }
                }
            });
            contentFrame().Navigate(xaml_typename<Editor::AddProfile>(), addProfileState);
        }
    }

    // Method Description:
    // - updates the content frame to present a view of the profile page
    // - NOTE: this does not update the selected item.
    // Arguments:
    // - profile - the profile object we are getting a view of
    void MainPage::_Navigate(const Editor::ProfileViewModel& profile)
    {
        _lastProfilesNavState = winrt::make<ProfilePageNavigationState>(profile,
                                                                        _settingsClone.GlobalSettings().ColorSchemes(),
                                                                        _lastProfilesNavState,
                                                                        *this);

        // Add an event handler for when the user wants to delete a profile.
        _lastProfilesNavState.DeleteProfile({ this, &MainPage::_DeleteProfile });

        contentFrame().Navigate(xaml_typename<Editor::Profiles>(), _lastProfilesNavState);
    }

    void MainPage::OpenJsonTapped(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::TappedRoutedEventArgs const& /*args*/)

Review comment (refactor):
meh, sprinkle some comments in here. It's not immediately obvious that `winrt::guid{}` is the special arg value that indicates "make a new profile, don't duplicate one"

Code after:
        else if (clickedItemTag == interactionTag)
        {
            contentFrame().Navigate(xaml_typename<Editor::Interaction>(), winrt::make<InteractionPageNavigationState>(_settingsClone.GlobalSettings()));
        }
        else if (clickedItemTag == renderingTag)
        {
            contentFrame().Navigate(xaml_typename<Editor::Rendering>(), winrt::make<RenderingPageNavigationState>(_settingsClone.GlobalSettings()));
        }
        else if (clickedItemTag == actionsTag)
        {
            auto actionsState{ winrt::make<ActionsPageNavigationState>(_settingsClone) };
            actionsState.OpenJson([weakThis = get_weak()](auto&&, auto&& arg) {
                if (auto self{ weakThis.get() })
                {
                    self->_OpenJsonHandlers(nullptr, arg);
                }
            });
            contentFrame().Navigate(xaml_typename<Editor::Actions>(), actionsState);
        }
        else if (clickedItemTag == colorSchemesTag)
        {
            contentFrame().Navigate(xaml_typename<Editor::ColorSchemes>(), _colorSchemesNavState);
        }
        else if (clickedItemTag == globalAppearanceTag)
        {
            contentFrame().Navigate(xaml_typename<Editor::GlobalAppearance>(), winrt::make<GlobalAppearancePageNavigationState>(_settingsClone.GlobalSettings()));
        }
        else if (clickedItemTag == addProfileTag)
        {
            auto addProfileState{ winrt::make<AddProfilePageNavigationState>(_settingsClone) };
            addProfileState.AddNew({ get_weak(), &MainPage::_AddProfileHandler });
            contentFrame().Navigate(xaml_typename<Editor::AddProfile>(), addProfileState);
        }
    }

    // Method Description:
    // - updates the content frame to present a view of the profile page
    // - NOTE: this does not update the selected item.
    // Arguments:
    // - profile - the profile object we are getting a view of
    void MainPage::_Navigate(const Editor::ProfileViewModel& profile)
    {
        _lastProfilesNavState = winrt::make<ProfilePageNavigationState>(profile,
                                                                        _settingsClone.GlobalSettings().ColorSchemes(),
                                                                        _lastProfilesNavState,
                                                                        *this);

        // Add an event handler for when the user wants to delete a profile.
        _lastProfilesNavState.DeleteProfile({ this, &MainPage::_DeleteProfile });

        contentFrame().Navigate(xaml_typename<Editor::Profiles>(), _lastProfilesNavState);