Skip to content

Commit

Permalink
Store and expose hidden profiles (#8070)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request
This PR replaces `CascadiaSettings::_profiles` with...
- `_allProfiles`: the list of all available profiles in the settings model (i.e. settings.json, dynamic profiles, etc...)
- `_activeProfiles`: the list of all non-hidden profiles (used for the new tab dropdown)

## References
#8018: maintaining a list of all profiles allows us to serialize hidden profiles
#1564: Settings UI can link to `AllProfiles()` instead of `ActiveProfiles()` to expose hidden profiles

## PR Checklist
* [x] Closes #4139 
* [x] Tests added/passed

## Validation Steps Performed
Deploy and testing succeeded
  • Loading branch information
carlos-zamora authored Oct 28, 2020
1 parent e21f9f5 commit 242833f
Show file tree
Hide file tree
Showing 10 changed files with 595 additions and 578 deletions.
639 changes: 320 additions & 319 deletions src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,55 +256,55 @@ namespace SettingsModelLocalTests

auto settings = winrt::make_self<implementation::CascadiaSettings>();

VERIFY_ARE_EQUAL(0u, settings->_profiles.Size());
VERIFY_ARE_EQUAL(0u, settings->_allProfiles.Size());
VERIFY_IS_NULL(settings->_FindMatchingProfile(profile0Json));
VERIFY_IS_NULL(settings->_FindMatchingProfile(profile1Json));
VERIFY_IS_NULL(settings->_FindMatchingProfile(profile2Json));
VERIFY_IS_NULL(settings->_FindMatchingProfile(profile3Json));
VERIFY_IS_NULL(settings->_FindMatchingProfile(profile4Json));

settings->_LayerOrCreateProfile(profile0Json);
VERIFY_ARE_EQUAL(1u, settings->_profiles.Size());
VERIFY_ARE_EQUAL(1u, settings->_allProfiles.Size());
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile0Json));
VERIFY_IS_NULL(settings->_FindMatchingProfile(profile1Json));
VERIFY_IS_NULL(settings->_FindMatchingProfile(profile2Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile3Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile4Json));

settings->_LayerOrCreateProfile(profile1Json);
VERIFY_ARE_EQUAL(2u, settings->_profiles.Size());
VERIFY_ARE_EQUAL(2u, settings->_allProfiles.Size());
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile0Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile1Json));
VERIFY_IS_NULL(settings->_FindMatchingProfile(profile2Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile3Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile4Json));

settings->_LayerOrCreateProfile(profile2Json);
VERIFY_ARE_EQUAL(3u, settings->_profiles.Size());
VERIFY_ARE_EQUAL(3u, settings->_allProfiles.Size());
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile0Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile1Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile2Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile3Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile4Json));
VERIFY_ARE_EQUAL(L"profile0", settings->_profiles.GetAt(0).Name());
VERIFY_ARE_EQUAL(L"profile0", settings->_allProfiles.GetAt(0).Name());

settings->_LayerOrCreateProfile(profile3Json);
VERIFY_ARE_EQUAL(3u, settings->_profiles.Size());
VERIFY_ARE_EQUAL(3u, settings->_allProfiles.Size());
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile0Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile1Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile2Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile3Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile4Json));
VERIFY_ARE_EQUAL(L"profile3", settings->_profiles.GetAt(0).Name());
VERIFY_ARE_EQUAL(L"profile3", settings->_allProfiles.GetAt(0).Name());

settings->_LayerOrCreateProfile(profile4Json);
VERIFY_ARE_EQUAL(3u, settings->_profiles.Size());
VERIFY_ARE_EQUAL(3u, settings->_allProfiles.Size());
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile0Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile1Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile2Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile3Json));
VERIFY_IS_NOT_NULL(settings->_FindMatchingProfile(profile4Json));
VERIFY_ARE_EQUAL(L"profile4", settings->_profiles.GetAt(0).Name());
VERIFY_ARE_EQUAL(L"profile4", settings->_allProfiles.GetAt(0).Name());
}

}
58 changes: 29 additions & 29 deletions src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ namespace TerminalAppLocalTests
CascadiaSettings settings{ til::u8u16(settingsJson) };

auto keymap = settings.GlobalSettings().KeyMap();
VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

const auto profile2Guid = settings.Profiles().GetAt(2).Guid();
const auto profile2Guid = settings.ActiveProfiles().GetAt(2).Guid();
VERIFY_ARE_NOT_EQUAL(winrt::guid{}, profile2Guid);

VERIFY_ARE_EQUAL(12u, keymap.Size());
Expand Down Expand Up @@ -478,8 +478,8 @@ namespace TerminalAppLocalTests
CascadiaSettings settings{ til::u8u16(settingsString) };

VERIFY_ARE_EQUAL(2u, settings.Warnings().Size());
VERIFY_ARE_EQUAL(2u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(settings.GlobalSettings().DefaultProfile(), settings.Profiles().GetAt(0).Guid());
VERIFY_ARE_EQUAL(2u, settings.ActiveProfiles().Size());
VERIFY_ARE_EQUAL(settings.GlobalSettings().DefaultProfile(), settings.ActiveProfiles().GetAt(0).Guid());
try
{
const auto [guid, termSettings] = winrt::TerminalApp::implementation::TerminalSettings::BuildSettings(settings, nullptr, nullptr);
Expand Down Expand Up @@ -540,7 +540,7 @@ namespace TerminalAppLocalTests

CascadiaSettings settings{ til::u8u16(settings0String) };

VERIFY_ARE_EQUAL(6u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(6u, settings.ActiveProfiles().Size());
VERIFY_ARE_EQUAL(2u, settings.GlobalSettings().ColorSchemes().Size());

auto createTerminalSettings = [&](const auto& profile, const auto& schemes) {
Expand All @@ -549,12 +549,12 @@ namespace TerminalAppLocalTests
return terminalSettings;
};

auto terminalSettings0 = createTerminalSettings(settings.Profiles().GetAt(0), settings.GlobalSettings().ColorSchemes());
auto terminalSettings1 = createTerminalSettings(settings.Profiles().GetAt(1), settings.GlobalSettings().ColorSchemes());
auto terminalSettings2 = createTerminalSettings(settings.Profiles().GetAt(2), settings.GlobalSettings().ColorSchemes());
auto terminalSettings3 = createTerminalSettings(settings.Profiles().GetAt(3), settings.GlobalSettings().ColorSchemes());
auto terminalSettings4 = createTerminalSettings(settings.Profiles().GetAt(4), settings.GlobalSettings().ColorSchemes());
auto terminalSettings5 = createTerminalSettings(settings.Profiles().GetAt(5), settings.GlobalSettings().ColorSchemes());
auto terminalSettings0 = createTerminalSettings(settings.ActiveProfiles().GetAt(0), settings.GlobalSettings().ColorSchemes());
auto terminalSettings1 = createTerminalSettings(settings.ActiveProfiles().GetAt(1), settings.GlobalSettings().ColorSchemes());
auto terminalSettings2 = createTerminalSettings(settings.ActiveProfiles().GetAt(2), settings.GlobalSettings().ColorSchemes());
auto terminalSettings3 = createTerminalSettings(settings.ActiveProfiles().GetAt(3), settings.GlobalSettings().ColorSchemes());
auto terminalSettings4 = createTerminalSettings(settings.ActiveProfiles().GetAt(4), settings.GlobalSettings().ColorSchemes());
auto terminalSettings5 = createTerminalSettings(settings.ActiveProfiles().GetAt(5), settings.GlobalSettings().ColorSchemes());

VERIFY_ARE_EQUAL(ARGB(0, 0x12, 0x34, 0x56), terminalSettings0->CursorColor()); // from color scheme
VERIFY_ARE_EQUAL(DEFAULT_CURSOR_COLOR, terminalSettings1->CursorColor()); // default
Expand Down Expand Up @@ -609,7 +609,7 @@ namespace TerminalAppLocalTests

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());

VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

auto commands = settings.GlobalSettings().Commands();
VERIFY_ARE_EQUAL(1u, commands.Size());
Expand All @@ -632,7 +632,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile());
}

auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.Profiles().GetView(), settings.GlobalSettings().ColorSchemes());
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes());
_logCommandNames(expandedCommands.GetView());

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
Expand Down Expand Up @@ -736,7 +736,7 @@ namespace TerminalAppLocalTests

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());

VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

auto commands = settings.GlobalSettings().Commands();
VERIFY_ARE_EQUAL(1u, commands.Size());
Expand All @@ -759,7 +759,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile());
}

auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.Profiles().GetView(), settings.GlobalSettings().ColorSchemes());
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes());
_logCommandNames(expandedCommands.GetView());

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
Expand Down Expand Up @@ -865,7 +865,7 @@ namespace TerminalAppLocalTests

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());

VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

auto commands = settings.GlobalSettings().Commands();
VERIFY_ARE_EQUAL(1u, commands.Size());
Expand All @@ -888,7 +888,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile());
}

auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.Profiles().GetView(), settings.GlobalSettings().ColorSchemes());
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes());
_logCommandNames(expandedCommands.GetView());

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
Expand Down Expand Up @@ -1002,10 +1002,10 @@ namespace TerminalAppLocalTests
CascadiaSettings settings{ til::u8u16(settingsJson) };

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

auto commands = settings.GlobalSettings().Commands();
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.Profiles().GetView(), settings.GlobalSettings().ColorSchemes());
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes());
_logCommandNames(expandedCommands.GetView());

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
Expand Down Expand Up @@ -1097,10 +1097,10 @@ namespace TerminalAppLocalTests
CascadiaSettings settings{ til::u8u16(settingsJson) };

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

auto commands = settings.GlobalSettings().Commands();
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.Profiles().GetView(), settings.GlobalSettings().ColorSchemes());
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes());
_logCommandNames(expandedCommands.GetView());

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
Expand Down Expand Up @@ -1220,10 +1220,10 @@ namespace TerminalAppLocalTests
CascadiaSettings settings{ til::u8u16(settingsJson) };

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

auto commands = settings.GlobalSettings().Commands();
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.Profiles().GetView(), settings.GlobalSettings().ColorSchemes());
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes());
_logCommandNames(expandedCommands.GetView());

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
Expand Down Expand Up @@ -1357,10 +1357,10 @@ namespace TerminalAppLocalTests
CascadiaSettings settings{ til::u8u16(settingsJson) };

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

auto commands = settings.GlobalSettings().Commands();
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.Profiles().GetView(), settings.GlobalSettings().ColorSchemes());
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes());
_logCommandNames(expandedCommands.GetView());

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
Expand Down Expand Up @@ -1460,10 +1460,10 @@ namespace TerminalAppLocalTests
CascadiaSettings settings{ til::u8u16(settingsJson) };

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

auto commands = settings.GlobalSettings().Commands();
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.Profiles().GetView(), settings.GlobalSettings().ColorSchemes());
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes());
_logCommandNames(expandedCommands.GetView());

VERIFY_ARE_EQUAL(0u, settings.Warnings().Size());
Expand Down Expand Up @@ -1602,7 +1602,7 @@ namespace TerminalAppLocalTests
// we add a warning saying "the color scheme is unknown"
VERIFY_ARE_EQUAL(1u, settings.Warnings().Size());

VERIFY_ARE_EQUAL(3u, settings.Profiles().Size());
VERIFY_ARE_EQUAL(3u, settings.ActiveProfiles().Size());

auto commands = settings.GlobalSettings().Commands();
VERIFY_ARE_EQUAL(1u, commands.Size());
Expand All @@ -1625,7 +1625,7 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(L"${scheme.name}", realArgs.TerminalArgs().Profile());
}

auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.Profiles().GetView(), settings.GlobalSettings().ColorSchemes());
auto expandedCommands = winrt::TerminalApp::implementation::TerminalPage::_ExpandCommands(commands, settings.ActiveProfiles().GetView(), settings.GlobalSettings().ColorSchemes());
_logCommandNames(expandedCommands.GetView());

// This is the same warning as above
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/Jumplist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ winrt::fire_and_forget Jumplist::UpdateJumplist(const CascadiaSettings& settings
THROW_IF_FAILED(jumplistItems->Clear());

// Update the list of profiles.
THROW_IF_FAILED(_updateProfiles(jumplistItems.get(), strongSettings.Profiles().GetView()));
THROW_IF_FAILED(_updateProfiles(jumplistItems.get(), strongSettings.ActiveProfiles().GetView()));

// TODO GH#1571: Add items from the future customizable new tab dropdown as well.
// This could either replace the default profiles, or be added alongside them.
Expand Down
8 changes: 4 additions & 4 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ namespace winrt::TerminalApp::implementation

const auto defaultProfileGuid = _settings.GlobalSettings().DefaultProfile();
// the number of profiles should not change in the loop for this to work
auto const profileCount = gsl::narrow_cast<int>(_settings.Profiles().Size());
auto const profileCount = gsl::narrow_cast<int>(_settings.ActiveProfiles().Size());
for (int profileIndex = 0; profileIndex < profileCount; profileIndex++)
{
const auto profile = _settings.Profiles().GetAt(profileIndex);
const auto profile = _settings.ActiveProfiles().GetAt(profileIndex);
auto profileMenuItem = WUX::Controls::MenuFlyoutItem{};

// Add the keyboard shortcuts based on the number of profiles defined
Expand Down Expand Up @@ -2066,7 +2066,7 @@ namespace winrt::TerminalApp::implementation
_HookupKeyBindings(_settings.KeyMap());

// Refresh UI elements
auto profiles = _settings.Profiles();
auto profiles = _settings.ActiveProfiles();
for (const auto& profile : profiles)
{
const auto profileGuid = profile.Guid();
Expand Down Expand Up @@ -2179,7 +2179,7 @@ namespace winrt::TerminalApp::implementation
void TerminalPage::_UpdateCommandsForPalette()
{
IMap<winrt::hstring, Command> copyOfCommands = _ExpandCommands(_settings.GlobalSettings().Commands(),
_settings.Profiles().GetView(),
_settings.ActiveProfiles().GetView(),
_settings.GlobalSettings().ColorSchemes());

_recursiveUpdateCommandKeybindingLabels(_settings, copyOfCommands.GetView());
Expand Down
Loading

0 comments on commit 242833f

Please sign in to comment.