From f4b187bd051e89c5cbc1a7c4d3452e8152137680 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 18 Aug 2020 09:06:12 -0700 Subject: [PATCH] Make GlobalAppSettings a WinRT object --- .../ColorSchemeTests.cpp | 46 +++--- .../LocalTests_TerminalApp/SettingsTests.cpp | 135 ++++++++-------- src/cascadia/TerminalApp/AppLogic.cpp | 6 +- src/cascadia/TerminalApp/CascadiaSettings.cpp | 40 ++--- src/cascadia/TerminalApp/CascadiaSettings.h | 6 +- .../CascadiaSettingsSerialization.cpp | 9 +- src/cascadia/TerminalApp/Command.h | 2 +- .../TerminalApp/GlobalAppSettings.cpp | 69 ++++---- src/cascadia/TerminalApp/GlobalAppSettings.h | 150 +++++++++--------- .../TerminalApp/GlobalAppSettings.idl | 56 +++++++ src/cascadia/TerminalApp/Profile.cpp | 9 +- src/cascadia/TerminalApp/Profile.h | 4 +- src/cascadia/TerminalApp/Profile.idl | 5 + src/cascadia/TerminalApp/SettingsTypes.h | 2 +- .../TerminalApp/TerminalAppLib.vcxproj | 9 +- .../TerminalAppLib.vcxproj.filters | 3 + src/cascadia/TerminalApp/TerminalPage.cpp | 8 +- src/cascadia/TerminalApp/TerminalPage.h | 2 +- .../TerminalSettingsSerializationHelpers.h | 8 +- 19 files changed, 322 insertions(+), 247 deletions(-) create mode 100644 src/cascadia/TerminalApp/GlobalAppSettings.idl diff --git a/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp b/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp index ab56263cad0..93593fb6816 100644 --- a/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/ColorSchemeTests.cpp @@ -195,7 +195,7 @@ namespace TerminalAppLocalTests CascadiaSettings settings; - VERIFY_ARE_EQUAL(0u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(0u, settings._globals.GetColorSchemes().Size()); VERIFY_IS_NULL(settings._FindMatchingColorScheme(scheme0Json)); VERIFY_IS_NULL(settings._FindMatchingColorScheme(scheme1Json)); VERIFY_IS_NULL(settings._FindMatchingColorScheme(scheme2Json)); @@ -203,15 +203,15 @@ namespace TerminalAppLocalTests settings._LayerOrCreateColorScheme(scheme0Json); { - for (auto& kv : settings._globals._colorSchemes) + for (auto kv : settings._globals.GetColorSchemes()) { Log::Comment(NoThrowString().Format( - L"kv:%s->%s", kv.first.data(), kv.second.Name().data())); + L"kv:%s->%s", kv.Key().data(), kv.Value().Name().data())); } - VERIFY_ARE_EQUAL(1u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(1u, settings._globals.GetColorSchemes().Size()); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme0") != settings._globals._colorSchemes.end()); - auto scheme0Proj = settings._globals._colorSchemes.find(L"scheme0")->second; + VERIFY_IS_TRUE(settings._globals.GetColorSchemes().HasKey(L"scheme0")); + auto scheme0Proj = settings._globals.GetColorSchemes().Lookup(L"scheme0"); auto scheme0 = winrt::get_self(scheme0Proj); VERIFY_IS_NOT_NULL(settings._FindMatchingColorScheme(scheme0Json)); @@ -225,13 +225,13 @@ namespace TerminalAppLocalTests settings._LayerOrCreateColorScheme(scheme1Json); { - VERIFY_ARE_EQUAL(2u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(2u, settings._globals.GetColorSchemes().Size()); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme0") != settings._globals._colorSchemes.end()); - auto scheme0Proj = settings._globals._colorSchemes.find(L"scheme0")->second; + VERIFY_IS_TRUE(settings._globals.GetColorSchemes().HasKey(L"scheme0")); + auto scheme0Proj = settings._globals.GetColorSchemes().Lookup(L"scheme0"); auto scheme0 = winrt::get_self(scheme0Proj); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme1") != settings._globals._colorSchemes.end()); - auto scheme1Proj = settings._globals._colorSchemes.find(L"scheme1")->second; + VERIFY_IS_TRUE(settings._globals.GetColorSchemes().HasKey(L"scheme1")); + auto scheme1Proj = settings._globals.GetColorSchemes().Lookup(L"scheme1"); auto scheme1 = winrt::get_self(scheme1Proj); VERIFY_IS_NOT_NULL(settings._FindMatchingColorScheme(scheme0Json)); @@ -246,13 +246,13 @@ namespace TerminalAppLocalTests settings._LayerOrCreateColorScheme(scheme2Json); { - VERIFY_ARE_EQUAL(2u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(2u, settings._globals.GetColorSchemes().Size()); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme0") != settings._globals._colorSchemes.end()); - auto scheme0Proj = settings._globals._colorSchemes.find(L"scheme0")->second; + VERIFY_IS_TRUE(settings._globals.GetColorSchemes().HasKey(L"scheme0")); + auto scheme0Proj = settings._globals.GetColorSchemes().Lookup(L"scheme0"); auto scheme0 = winrt::get_self(scheme0Proj); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme1") != settings._globals._colorSchemes.end()); - auto scheme1Proj = settings._globals._colorSchemes.find(L"scheme1")->second; + VERIFY_IS_TRUE(settings._globals.GetColorSchemes().HasKey(L"scheme1")); + auto scheme1Proj = settings._globals.GetColorSchemes().Lookup(L"scheme1"); auto scheme1 = winrt::get_self(scheme1Proj); VERIFY_IS_NOT_NULL(settings._FindMatchingColorScheme(scheme0Json)); @@ -267,16 +267,16 @@ namespace TerminalAppLocalTests settings._LayerOrCreateColorScheme(scheme3Json); { - VERIFY_ARE_EQUAL(3u, settings._globals.GetColorSchemes().size()); + VERIFY_ARE_EQUAL(3u, settings._globals.GetColorSchemes().Size()); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme0") != settings._globals._colorSchemes.end()); - auto scheme0Proj = settings._globals._colorSchemes.find(L"scheme0")->second; + VERIFY_IS_TRUE(settings._globals.GetColorSchemes().HasKey(L"scheme0")); + auto scheme0Proj = settings._globals.GetColorSchemes().Lookup(L"scheme0"); auto scheme0 = winrt::get_self(scheme0Proj); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"scheme1") != settings._globals._colorSchemes.end()); - auto scheme1Proj = settings._globals._colorSchemes.find(L"scheme1")->second; + VERIFY_IS_TRUE(settings._globals.GetColorSchemes().HasKey(L"scheme1")); + auto scheme1Proj = settings._globals.GetColorSchemes().Lookup(L"scheme1"); auto scheme1 = winrt::get_self(scheme1Proj); - VERIFY_IS_TRUE(settings._globals._colorSchemes.find(L"") != settings._globals._colorSchemes.end()); - auto scheme2Proj = settings._globals._colorSchemes.find(L"")->second; + VERIFY_IS_TRUE(settings._globals.GetColorSchemes().HasKey(L"")); + auto scheme2Proj = settings._globals.GetColorSchemes().Lookup(L""); auto scheme2 = winrt::get_self(scheme2Proj); VERIFY_IS_NOT_NULL(settings._FindMatchingColorScheme(scheme0Json)); diff --git a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp index bb3ba94906a..b774dcddb0a 100644 --- a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp @@ -106,7 +106,7 @@ namespace TerminalAppLocalTests } private: - void _logCommandNames(winrt::Windows::Foundation::Collections::IMap& commands, const int indentation = 1) + void _logCommandNames(winrt::Windows::Foundation::Collections::IMapView commands, const int indentation = 1) { if (indentation == 1) { @@ -125,7 +125,7 @@ namespace TerminalAppLocalTests cmdImpl.copy_from(winrt::get_self(nameAndCommand.Value())); if (cmdImpl->HasNestedCommands()) { - _logCommandNames(cmdImpl->_subcommands, indentation + 2); + _logCommandNames(cmdImpl->_subcommands.GetView(), indentation + 2); } } } @@ -522,16 +522,16 @@ namespace TerminalAppLocalTests CascadiaSettings settings; settings.LayerJson(settings0Json); - VERIFY_ARE_EQUAL(true, settings._globals._AlwaysShowTabs); - VERIFY_ARE_EQUAL(120, settings._globals._InitialCols); - VERIFY_ARE_EQUAL(30, settings._globals._InitialRows); - VERIFY_ARE_EQUAL(true, settings._globals._ShowTabsInTitlebar); + VERIFY_ARE_EQUAL(true, settings._globals.AlwaysShowTabs()); + VERIFY_ARE_EQUAL(120, settings._globals.InitialCols()); + VERIFY_ARE_EQUAL(30, settings._globals.InitialRows()); + VERIFY_ARE_EQUAL(true, settings._globals.ShowTabsInTitlebar()); settings.LayerJson(settings1Json); - VERIFY_ARE_EQUAL(true, settings._globals._AlwaysShowTabs); - VERIFY_ARE_EQUAL(240, settings._globals._InitialCols); - VERIFY_ARE_EQUAL(60, settings._globals._InitialRows); - VERIFY_ARE_EQUAL(false, settings._globals._ShowTabsInTitlebar); + VERIFY_ARE_EQUAL(true, settings._globals.AlwaysShowTabs()); + VERIFY_ARE_EQUAL(240, settings._globals.InitialCols()); + VERIFY_ARE_EQUAL(60, settings._globals.InitialRows()); + VERIFY_ARE_EQUAL(false, settings._globals.ShowTabsInTitlebar()); } void SettingsTests::ValidateProfileOrdering() @@ -1330,7 +1330,7 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); - VERIFY_ARE_EQUAL(2u, settings._globals._colorSchemes.size()); + VERIFY_ARE_EQUAL(2u, settings._globals.GetColorSchemes().Size()); VERIFY_ARE_EQUAL(L"schemeOne", settings._profiles.at(0).ColorSchemeName()); VERIFY_ARE_EQUAL(L"InvalidSchemeName", settings._profiles.at(1).ColorSchemeName()); @@ -1342,7 +1342,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::UnknownColorScheme, settings._warnings.at(0)); VERIFY_ARE_EQUAL(3u, settings._profiles.size()); - VERIFY_ARE_EQUAL(2u, settings._globals._colorSchemes.size()); + VERIFY_ARE_EQUAL(2u, settings._globals.GetColorSchemes().Size()); VERIFY_ARE_EQUAL(L"schemeOne", settings._profiles.at(0).ColorSchemeName()); VERIFY_ARE_EQUAL(L"Campbell", settings._profiles.at(1).ColorSchemeName()); @@ -1554,7 +1554,7 @@ namespace TerminalAppLocalTests VERIFY_IS_FALSE(settings._userDefaultProfileSettings == Json::Value::null); settings.LayerJson(settings._userSettings); - VERIFY_ARE_EQUAL(guid1String, settings._globals._unparsedDefaultProfile); + VERIFY_ARE_EQUAL(guid1String, settings._globals.UnparsedDefaultProfile()); VERIFY_ARE_EQUAL(2u, settings._profiles.size()); VERIFY_ARE_EQUAL(2345, settings._profiles.at(0).HistorySize()); @@ -1612,7 +1612,7 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); - VERIFY_ARE_EQUAL(guid1String, settings._globals._unparsedDefaultProfile); + VERIFY_ARE_EQUAL(guid1String, settings._globals.UnparsedDefaultProfile()); VERIFY_ARE_EQUAL(4u, settings._profiles.size()); VERIFY_ARE_EQUAL(guid1, settings._profiles.at(2).Guid()); @@ -1794,12 +1794,13 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); settings._ValidateSettings(); - auto appKeyBindings = settings._globals._keybindings; + auto appKeyBindingsProj = settings._globals.GetKeybindings(); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); const auto profile2Guid = settings._profiles.at(2).Guid(); VERIFY_ARE_NOT_EQUAL(winrt::guid({ 0 }), profile2Guid); + const auto appKeyBindings = winrt::get_self(appKeyBindingsProj); VERIFY_ARE_EQUAL(12u, appKeyBindings->_keyShortcuts.size()); { @@ -2241,14 +2242,14 @@ namespace TerminalAppLocalTests settings.LayerJson(settings._userSettings); VERIFY_ARE_EQUAL(6u, settings._profiles.size()); - VERIFY_ARE_EQUAL(2u, settings._globals._colorSchemes.size()); + VERIFY_ARE_EQUAL(2u, settings._globals.GetColorSchemes().Size()); - auto terminalSettings0 = winrt::get_self(settings._profiles[0])->CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings1 = winrt::get_self(settings._profiles[1])->CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings2 = winrt::get_self(settings._profiles[2])->CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings3 = winrt::get_self(settings._profiles[3])->CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings4 = winrt::get_self(settings._profiles[4])->CreateTerminalSettings(settings._globals._colorSchemes); - auto terminalSettings5 = winrt::get_self(settings._profiles[5])->CreateTerminalSettings(settings._globals._colorSchemes); + auto terminalSettings0 = winrt::get_self(settings._profiles[0])->CreateTerminalSettings(settings._globals.GetColorSchemes()); + auto terminalSettings1 = winrt::get_self(settings._profiles[1])->CreateTerminalSettings(settings._globals.GetColorSchemes()); + auto terminalSettings2 = winrt::get_self(settings._profiles[2])->CreateTerminalSettings(settings._globals.GetColorSchemes()); + auto terminalSettings3 = winrt::get_self(settings._profiles[3])->CreateTerminalSettings(settings._globals.GetColorSchemes()); + auto terminalSettings4 = winrt::get_self(settings._profiles[4])->CreateTerminalSettings(settings._globals.GetColorSchemes()); + auto terminalSettings5 = winrt::get_self(settings._profiles[5])->CreateTerminalSettings(settings._globals.GetColorSchemes()); VERIFY_ARE_EQUAL(ARGB(0, 0x12, 0x34, 0x56), terminalSettings0.CursorColor()); // from color scheme VERIFY_ARE_EQUAL(DEFAULT_CURSOR_COLOR, terminalSettings1.CursorColor()); // default @@ -2283,12 +2284,13 @@ namespace TerminalAppLocalTests const auto settingsObject = VerifyParseSucceeded(badSettings); auto settings = CascadiaSettings::FromJson(settingsObject); - VERIFY_ARE_EQUAL(0u, settings->_globals._keybindings->_keyShortcuts.size()); + const auto globalsImpl = winrt::get_self(settings->_globals); + VERIFY_ARE_EQUAL(0u, globalsImpl->_keybindings->_keyShortcuts.size()); - VERIFY_ARE_EQUAL(3u, settings->_globals._keybindingsWarnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::TooManyKeysForChord, settings->_globals._keybindingsWarnings.at(0)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(1)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(2)); + VERIFY_ARE_EQUAL(3u, globalsImpl->_keybindingsWarnings.size()); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::TooManyKeysForChord, globalsImpl->_keybindingsWarnings.at(0)); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, globalsImpl->_keybindingsWarnings.at(1)); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, globalsImpl->_keybindingsWarnings.at(2)); settings->_ValidateKeybindings(); @@ -2325,17 +2327,18 @@ namespace TerminalAppLocalTests auto settings = CascadiaSettings::FromJson(settingsObject); - VERIFY_ARE_EQUAL(0u, settings->_globals._keybindings->_keyShortcuts.size()); + auto globalsImpl = winrt::get_self(settings->_globals); + VERIFY_ARE_EQUAL(0u, globalsImpl->_keybindings->_keyShortcuts.size()); - for (const auto& warning : settings->_globals._keybindingsWarnings) + for (const auto& warning : globalsImpl->_keybindingsWarnings) { Log::Comment(NoThrowString().Format( L"warning:%d", warning)); } - VERIFY_ARE_EQUAL(3u, settings->_globals._keybindingsWarnings.size()); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(0)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(1)); - VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, settings->_globals._keybindingsWarnings.at(2)); + VERIFY_ARE_EQUAL(3u, globalsImpl->_keybindingsWarnings.size()); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, globalsImpl->_keybindingsWarnings.at(0)); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, globalsImpl->_keybindingsWarnings.at(1)); + VERIFY_ARE_EQUAL(::TerminalApp::SettingsLoadWarnings::MissingRequiredParameter, globalsImpl->_keybindingsWarnings.at(2)); settings->_ValidateKeybindings(); @@ -2465,7 +2468,7 @@ namespace TerminalAppLocalTests const auto profile2Guid = settings._profiles.at(2).Guid(); VERIFY_ARE_NOT_EQUAL(winrt::guid(GUID{ 0 }), profile2Guid); - auto appKeyBindings = settings._globals._keybindings; + auto appKeyBindings = winrt::get_self(settings._globals.GetKeybindings()); VERIFY_ARE_EQUAL(5u, appKeyBindings->_keyShortcuts.size()); // A/D, B, C, E will be in the list of commands, for 4 total. @@ -2665,7 +2668,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -2686,8 +2689,8 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile()); } - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals.GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); @@ -2795,7 +2798,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -2816,8 +2819,8 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(L"${profile.name}", realArgs.TerminalArgs().Profile()); } - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals.GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); @@ -2927,7 +2930,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -2949,8 +2952,8 @@ namespace TerminalAppLocalTests } settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals.GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); @@ -3068,10 +3071,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals.GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); @@ -3176,10 +3179,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals.GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); @@ -3315,10 +3318,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals.GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); @@ -3337,7 +3340,7 @@ namespace TerminalAppLocalTests VERIFY_IS_TRUE(commandImpl->HasNestedCommands()); VERIFY_ARE_EQUAL(3u, commandImpl->_subcommands.Size()); - _logCommandNames(commandImpl->_subcommands); + _logCommandNames(commandImpl->_subcommands.GetView()); { winrt::hstring childCommandName{ fmt::format(L"Split pane, profile: {}", name) }; auto childCommandProj = commandImpl->_subcommands.Lookup(childCommandName); @@ -3468,10 +3471,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals.GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); @@ -3581,10 +3584,10 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); settings._ValidateSettings(); - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals.GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(1u, expandedCommands.Size()); @@ -3613,7 +3616,7 @@ namespace TerminalAppLocalTests VERIFY_IS_TRUE(commandImpl->HasNestedCommands()); VERIFY_ARE_EQUAL(3u, commandImpl->_subcommands.Size()); - _logCommandNames(commandImpl->_subcommands); + _logCommandNames(commandImpl->_subcommands.GetView()); { winrt::hstring childCommandName{ fmt::format(L"Split pane, profile: {}", name) }; auto childCommandProj = commandImpl->_subcommands.Lookup(childCommandName); @@ -3742,7 +3745,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); settings._ValidateSettings(); _logCommandNames(commands); @@ -3819,7 +3822,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); settings._ValidateSettings(); _logCommandNames(commands); @@ -3902,7 +3905,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); settings._ValidateSettings(); _logCommandNames(commands); @@ -3998,7 +4001,7 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(3u, settings.GetProfiles().size()); - auto& commands = settings._globals.GetCommands(); + auto commands = settings._globals.GetCommands(); VERIFY_ARE_EQUAL(1u, commands.Size()); { @@ -4019,8 +4022,8 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(L"${scheme.name}", realArgs.TerminalArgs().Profile()); } - auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands.GetView(), settings.GetProfiles(), settings._globals.GetColorSchemes()); - _logCommandNames(expandedCommands); + auto expandedCommands = implementation::TerminalPage::_ExpandCommands(commands, settings.GetProfiles(), settings._globals.GetColorSchemes()); + _logCommandNames(expandedCommands.GetView()); VERIFY_ARE_EQUAL(0u, settings._warnings.size()); VERIFY_ARE_EQUAL(3u, expandedCommands.Size()); diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index d7adb4f2456..f5f6873a2dd 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -569,10 +569,10 @@ namespace winrt::TerminalApp::implementation LoadSettings(); } - const auto initialPosition{ _settings->GlobalSettings().InitialPosition() }; + const auto globals{ _settings->GlobalSettings() }; winrt::Windows::Foundation::Point point{ - /* X */ gsl::narrow_cast(initialPosition.x.value_or(defaultInitialX)), - /* Y */ gsl::narrow_cast(initialPosition.y.value_or(defaultInitialY)) + /* X */ gsl::narrow_cast(globals.HasInitialPositionX() ? globals.InitialPositionX() : defaultInitialX), + /* Y */ gsl::narrow_cast(globals.HasInitialPositionY() ? globals.InitialPositionY() : defaultInitialY) }; return point; diff --git a/src/cascadia/TerminalApp/CascadiaSettings.cpp b/src/cascadia/TerminalApp/CascadiaSettings.cpp index faf28d0662b..8da4e244c24 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettings.cpp @@ -115,7 +115,7 @@ AppKeyBindings CascadiaSettings::GetKeybindings() const noexcept // - // Return Value: // - a reference to our global settings -GlobalAppSettings& CascadiaSettings::GlobalSettings() +winrt::TerminalApp::GlobalAppSettings CascadiaSettings::GlobalSettings() { return _globals; } @@ -227,9 +227,9 @@ void CascadiaSettings::_ValidateProfilesHaveGuid() void CascadiaSettings::_ResolveDefaultProfile() { const auto unparsedDefaultProfile{ GlobalSettings().UnparsedDefaultProfile() }; - if (unparsedDefaultProfile) + if (!unparsedDefaultProfile.empty()) { - auto maybeParsedDefaultProfile{ _GetProfileGuidByName(*unparsedDefaultProfile) }; + auto maybeParsedDefaultProfile{ _GetProfileGuidByName(unparsedDefaultProfile) }; auto defaultProfileGuid{ til::coalesce_value(maybeParsedDefaultProfile, GUID{}) }; GlobalSettings().DefaultProfile(defaultProfileGuid); } @@ -404,15 +404,11 @@ void CascadiaSettings::_ValidateAllSchemesExist() bool foundInvalidScheme = false; for (auto& profile : _profiles) { - auto schemeName = profile.ColorSchemeName(); - if (!schemeName.empty()) + const auto schemeName = profile.ColorSchemeName(); + if (!_globals.GetColorSchemes().HasKey(schemeName)) { - const auto found = _globals.GetColorSchemes().find(schemeName.c_str()); - if (found == _globals.GetColorSchemes().end()) - { - profile.ColorSchemeName({ L"Campbell" }); - foundInvalidScheme = true; - } + profile.ColorSchemeName({ L"Campbell" }); + foundInvalidScheme = true; } } @@ -661,7 +657,8 @@ std::optional CascadiaSettings::_GetProfileGuidByIndex(std::optional // - void CascadiaSettings::_ValidateKeybindings() { - auto keybindingWarnings = _globals.GetKeybindingsWarnings(); + auto globalsImpl = winrt::get_self(_globals); + auto keybindingWarnings = globalsImpl->GetKeybindingsWarnings(); if (!keybindingWarnings.empty()) { @@ -746,16 +743,8 @@ const ColorScheme CascadiaSettings::GetColorSchemeForProfile(const GUID profileG { return nullptr; } - auto schemeName = !profile.ColorSchemeName().empty() ? profile.ColorSchemeName() : L"\0"; - auto scheme = _globals.GetColorSchemes().find(schemeName.c_str()); - if (scheme != _globals.GetColorSchemes().end()) - { - return scheme->second; - } - else - { - return nullptr; - } + auto schemeName = profile.ColorSchemeName(); + return _globals.GetColorSchemes().TryLookup(schemeName); } // Method Description: @@ -768,13 +757,10 @@ const ColorScheme CascadiaSettings::GetColorSchemeForProfile(const GUID profileG // Return Value: // - true iff we found a matching scheme for the name schemeName bool CascadiaSettings::ApplyColorScheme(winrt::Microsoft::Terminal::TerminalControl::IControlSettings& settings, - std::wstring_view schemeName) + winrt::hstring schemeName) { - std::wstring name{ schemeName }; - auto schemeAndName = _globals.GetColorSchemes().find(name); - if (schemeAndName != _globals.GetColorSchemes().end()) + if (auto scheme{ _globals.GetColorSchemes().TryLookup(schemeName) }) { - const auto& scheme = schemeAndName->second; scheme.ApplyScheme(settings); return true; } diff --git a/src/cascadia/TerminalApp/CascadiaSettings.h b/src/cascadia/TerminalApp/CascadiaSettings.h index 1e26c257c9c..39f4551b7ce 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.h +++ b/src/cascadia/TerminalApp/CascadiaSettings.h @@ -67,7 +67,7 @@ class TerminalApp::CascadiaSettings final std::tuple BuildSettings(const winrt::TerminalApp::NewTerminalArgs& newTerminalArgs) const; winrt::TerminalApp::TerminalSettings BuildSettings(GUID profileGuid) const; - GlobalAppSettings& GlobalSettings(); + winrt::TerminalApp::GlobalAppSettings GlobalSettings(); gsl::span GetProfiles() const noexcept; @@ -84,10 +84,10 @@ class TerminalApp::CascadiaSettings final std::vector& GetWarnings(); - bool ApplyColorScheme(winrt::Microsoft::Terminal::TerminalControl::IControlSettings& settings, std::wstring_view schemeName); + bool ApplyColorScheme(winrt::Microsoft::Terminal::TerminalControl::IControlSettings& settings, winrt::hstring schemeName); private: - GlobalAppSettings _globals; + winrt::TerminalApp::GlobalAppSettings _globals; std::vector _profiles; std::vector _warnings; diff --git a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp index 1b8650c3578..b39d0d86a41 100644 --- a/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp @@ -560,7 +560,8 @@ std::unique_ptr CascadiaSettings::FromJson(const Json::Value& // void CascadiaSettings::LayerJson(const Json::Value& json) { - _globals.LayerJson(json); + auto globals = winrt::get_self(_globals); + globals->LayerJson(json); if (auto schemes{ json[SchemesKey.data()] }) { @@ -728,11 +729,9 @@ winrt::com_ptr CascadiaSettings::_FindMatchingColor { if (auto schemeName = implementation::ColorScheme::GetNameFromJson(schemeJson)) { - auto& schemes = _globals.GetColorSchemes(); - auto iterator = schemes.find(*schemeName); - if (iterator != schemes.end()) + if (auto scheme{ _globals.GetColorSchemes().TryLookup(*schemeName) }) { - return winrt::get_self(iterator->second)->get_strong(); + return winrt::get_self(scheme)->get_strong(); } } return nullptr; diff --git a/src/cascadia/TerminalApp/Command.h b/src/cascadia/TerminalApp/Command.h index c98f968c6b0..6f3d374c1d1 100644 --- a/src/cascadia/TerminalApp/Command.h +++ b/src/cascadia/TerminalApp/Command.h @@ -60,7 +60,7 @@ namespace winrt::TerminalApp::implementation OBSERVABLE_GETSET_PROPERTY(winrt::hstring, KeyChordText, _PropertyChangedHandlers); OBSERVABLE_GETSET_PROPERTY(winrt::Windows::UI::Xaml::Controls::IconSource, IconSource, _PropertyChangedHandlers, nullptr); - GETSET_PROPERTY(::TerminalApp::ExpandCommandType, IterateOn, ::TerminalApp::ExpandCommandType::None); + GETSET_PROPERTY(ExpandCommandType, IterateOn, ExpandCommandType::None); private: Json::Value _originalJson; diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.cpp b/src/cascadia/TerminalApp/GlobalAppSettings.cpp index 4cbba508b1f..cbf57321cb7 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalApp/GlobalAppSettings.cpp @@ -9,8 +9,10 @@ #include "JsonUtils.h" #include "TerminalSettingsSerializationHelpers.h" +#include "GlobalAppSettings.g.cpp" + using namespace TerminalApp; -using namespace winrt::TerminalApp; +using namespace winrt::TerminalApp::implementation; using namespace winrt::Windows::UI::Xaml; using namespace ::Microsoft::Console; using namespace winrt::Microsoft::UI::Xaml::Controls; @@ -51,10 +53,9 @@ static constexpr bool debugFeaturesDefault{ false }; #endif GlobalAppSettings::GlobalAppSettings() : - _keybindings{ winrt::make_self() }, + _keybindings{ winrt::make_self() }, _keybindingsWarnings{}, - _colorSchemes{}, - _unparsedDefaultProfile{ std::nullopt }, + _unparsedDefaultProfile{ }, _defaultProfile{}, _InitialRows{ DEFAULT_ROWS }, _InitialCols{ DEFAULT_COLS }, @@ -62,41 +63,37 @@ GlobalAppSettings::GlobalAppSettings() : _DebugFeaturesEnabled{ debugFeaturesDefault } { _commands = winrt::single_threaded_map(); + _colorSchemes = winrt::single_threaded_map(); } GlobalAppSettings::~GlobalAppSettings() { } -std::unordered_map& GlobalAppSettings::GetColorSchemes() noexcept -{ - return _colorSchemes; -} - -const std::unordered_map& GlobalAppSettings::GetColorSchemes() const noexcept +winrt::Windows::Foundation::Collections::IMapView GlobalAppSettings::GetColorSchemes() noexcept { - return _colorSchemes; + return _colorSchemes.GetView(); } -void GlobalAppSettings::DefaultProfile(const GUID defaultProfile) noexcept +void GlobalAppSettings::DefaultProfile(const winrt::guid defaultProfile) noexcept { - _unparsedDefaultProfile.reset(); + _unparsedDefaultProfile.clear(); _defaultProfile = defaultProfile; } -GUID GlobalAppSettings::DefaultProfile() const +winrt::guid GlobalAppSettings::DefaultProfile() const { // If we have an unresolved default profile, we should likely explode. - THROW_HR_IF(E_INVALIDARG, _unparsedDefaultProfile.has_value()); + THROW_HR_IF(E_INVALIDARG, !_unparsedDefaultProfile.empty()); return _defaultProfile; } -std::optional GlobalAppSettings::UnparsedDefaultProfile() const +winrt::hstring GlobalAppSettings::UnparsedDefaultProfile() const { return _unparsedDefaultProfile; } -AppKeyBindings GlobalAppSettings::GetKeybindings() const noexcept +winrt::TerminalApp::AppKeyBindings GlobalAppSettings::GetKeybindings() const noexcept { return *_keybindings; } @@ -107,7 +104,7 @@ AppKeyBindings GlobalAppSettings::GetKeybindings() const noexcept // - settings: a TerminalSettings object to add global property values to. // Return Value: // - -void GlobalAppSettings::ApplyToSettings(TerminalSettings& settings) const noexcept +void GlobalAppSettings::ApplyToSettings(TerminalApp::TerminalSettings settings) const noexcept { settings.KeyBindings(GetKeybindings()); settings.InitialRows(_InitialRows); @@ -126,10 +123,10 @@ void GlobalAppSettings::ApplyToSettings(TerminalSettings& settings) const noexce // - json: an object which should be a serialization of a GlobalAppSettings object. // Return Value: // - a new GlobalAppSettings instance created from the values in `json` -GlobalAppSettings GlobalAppSettings::FromJson(const Json::Value& json) +winrt::com_ptr GlobalAppSettings::FromJson(const Json::Value& json) { - GlobalAppSettings result; - result.LayerJson(json); + auto result = winrt::make_self(); + result->LayerJson(json); return result; } @@ -145,7 +142,7 @@ void GlobalAppSettings::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, InitialColsKey, _InitialCols); - JsonUtils::GetValueForKey(json, InitialPositionKey, _InitialPosition); + JsonUtils::GetValueForKey(json, InitialPositionKey, _initialPosition); JsonUtils::GetValueForKey(json, ShowTitleInTitlebarKey, _ShowTitleInTitlebar); @@ -214,10 +211,9 @@ void GlobalAppSettings::LayerJson(const Json::Value& json) // - scheme: the color scheme to add // Return Value: // - -void GlobalAppSettings::AddColorScheme(ColorScheme scheme) +void GlobalAppSettings::AddColorScheme(winrt::TerminalApp::ColorScheme scheme) { - std::wstring name{ scheme.Name() }; - _colorSchemes[name] = std::move(scheme); + _colorSchemes.Insert(scheme.Name(), scheme); } // Method Description: @@ -234,12 +230,27 @@ std::vector GlobalAppSettings::GetKeybindings return _keybindingsWarnings; } -const winrt::Windows::Foundation::Collections::IMap& GlobalAppSettings::GetCommands() const noexcept +winrt::Windows::Foundation::Collections::IMapView GlobalAppSettings::GetCommands() noexcept +{ + return _commands.GetView(); +} + +bool GlobalAppSettings::HasInitialPositionX() const +{ + return _initialPosition.x.has_value(); +} + +bool GlobalAppSettings::HasInitialPositionY() const +{ + return _initialPosition.y.has_value(); +} + +int32_t GlobalAppSettings::InitialPositionX() const { - return _commands; + return _initialPosition.x.value(); } -winrt::Windows::Foundation::Collections::IMap& GlobalAppSettings::GetCommands() noexcept +int32_t GlobalAppSettings::InitialPositionY() const { - return _commands; + return _initialPosition.y.value(); } diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.h b/src/cascadia/TerminalApp/GlobalAppSettings.h index d78d15a8e34..b3d5c969069 100644 --- a/src/cascadia/TerminalApp/GlobalAppSettings.h +++ b/src/cascadia/TerminalApp/GlobalAppSettings.h @@ -14,11 +14,13 @@ Author(s): --*/ #pragma once -#include "AppKeyBindings.h" -#include "Command.h" + +#include "GlobalAppSettings.g.h" #include "SettingsTypes.h" -#include "ColorScheme.g.h" +#include "AppKeyBindings.h" +#include "Command.h" +#include "ColorScheme.h" // fwdecl unittest classes namespace TerminalAppLocalTests @@ -27,73 +29,79 @@ namespace TerminalAppLocalTests class ColorSchemeTests; }; -namespace TerminalApp +namespace winrt::TerminalApp::implementation { - class GlobalAppSettings; -}; - -class TerminalApp::GlobalAppSettings final + struct GlobalAppSettings : GlobalAppSettingsT + { + public: + GlobalAppSettings(); + ~GlobalAppSettings(); + + Windows::Foundation::Collections::IMapView GetColorSchemes() noexcept; + void AddColorScheme(TerminalApp::ColorScheme scheme); + + TerminalApp::AppKeyBindings GetKeybindings() const noexcept; + + static com_ptr FromJson(const Json::Value& json); + void LayerJson(const Json::Value& json); + + void ApplyToSettings(TerminalApp::TerminalSettings settings) const noexcept; + + std::vector<::TerminalApp::SettingsLoadWarnings> GetKeybindingsWarnings() const; + + Windows::Foundation::Collections::IMapView GetCommands() noexcept; + + // These are implemented manually to handle the string/GUID exchange + // by higher layers in the app. + void DefaultProfile(const guid defaultProfile) noexcept; + guid DefaultProfile() const; + hstring UnparsedDefaultProfile() const; + + bool HasInitialPositionX() const; + bool HasInitialPositionY() const; + int32_t InitialPositionX() const; + int32_t InitialPositionY() const; + + GETSET_PROPERTY(int32_t, InitialRows); // default value set in constructor + GETSET_PROPERTY(int32_t, InitialCols); // default value set in constructor + GETSET_PROPERTY(bool, AlwaysShowTabs, true); + GETSET_PROPERTY(bool, ShowTitleInTitlebar, true); + GETSET_PROPERTY(bool, ConfirmCloseAllTabs, true); + GETSET_PROPERTY(winrt::Windows::UI::Xaml::ElementTheme, Theme, winrt::Windows::UI::Xaml::ElementTheme::Default); + GETSET_PROPERTY(winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, TabWidthMode, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode::Equal); + GETSET_PROPERTY(bool, ShowTabsInTitlebar, true); + GETSET_PROPERTY(hstring, WordDelimiters); // default value set in constructor + GETSET_PROPERTY(bool, CopyOnSelect, false); + GETSET_PROPERTY(winrt::Microsoft::Terminal::TerminalControl::CopyFormat, CopyFormatting, 0); + GETSET_PROPERTY(bool, WarnAboutLargePaste, true); + GETSET_PROPERTY(bool, WarnAboutMultiLinePaste, true); + GETSET_PROPERTY(winrt::TerminalApp::LaunchMode, LaunchMode, winrt::TerminalApp::LaunchMode::DefaultMode); + GETSET_PROPERTY(bool, SnapToGridOnResize, true); + GETSET_PROPERTY(bool, ForceFullRepaintRendering, false); + GETSET_PROPERTY(bool, SoftwareRendering, false); + GETSET_PROPERTY(bool, ForceVTInput, false); + GETSET_PROPERTY(bool, DebugFeaturesEnabled); // default value set in constructor + GETSET_PROPERTY(bool, StartOnUserLogin, false); + GETSET_PROPERTY(bool, AlwaysOnTop, false); + GETSET_PROPERTY(bool, UseTabSwitcher, true); + + private: + hstring _unparsedDefaultProfile; + guid _defaultProfile; + LaunchPosition _initialPosition; + + com_ptr _keybindings; + std::vector<::TerminalApp::SettingsLoadWarnings> _keybindingsWarnings; + + Windows::Foundation::Collections::IMap _colorSchemes; + Windows::Foundation::Collections::IMap _commands; + + friend class TerminalAppLocalTests::SettingsTests; + friend class TerminalAppLocalTests::ColorSchemeTests; + }; +} + +namespace winrt::TerminalApp::factory_implementation { -public: - GlobalAppSettings(); - ~GlobalAppSettings(); - - std::unordered_map& GetColorSchemes() noexcept; - const std::unordered_map& GetColorSchemes() const noexcept; - void AddColorScheme(winrt::TerminalApp::ColorScheme scheme); - - winrt::TerminalApp::AppKeyBindings GetKeybindings() const noexcept; - - static GlobalAppSettings FromJson(const Json::Value& json); - void LayerJson(const Json::Value& json); - - void ApplyToSettings(winrt::TerminalApp::TerminalSettings& settings) const noexcept; - - std::vector GetKeybindingsWarnings() const; - - const winrt::Windows::Foundation::Collections::IMap& GetCommands() const noexcept; - winrt::Windows::Foundation::Collections::IMap& GetCommands() noexcept; - - // These are implemented manually to handle the string/GUID exchange - // by higher layers in the app. - void DefaultProfile(const GUID defaultProfile) noexcept; - GUID DefaultProfile() const; - std::optional UnparsedDefaultProfile() const; - - GETSET_PROPERTY(int32_t, InitialRows); // default value set in constructor - GETSET_PROPERTY(int32_t, InitialCols); // default value set in constructor - GETSET_PROPERTY(bool, AlwaysShowTabs, true); - GETSET_PROPERTY(bool, ShowTitleInTitlebar, true); - GETSET_PROPERTY(bool, ConfirmCloseAllTabs, true); - GETSET_PROPERTY(winrt::Windows::UI::Xaml::ElementTheme, Theme, winrt::Windows::UI::Xaml::ElementTheme::Default); - GETSET_PROPERTY(winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, TabWidthMode, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode::Equal); - GETSET_PROPERTY(bool, ShowTabsInTitlebar, true); - GETSET_PROPERTY(std::wstring, WordDelimiters); // default value set in constructor - GETSET_PROPERTY(bool, CopyOnSelect, false); - GETSET_PROPERTY(winrt::Microsoft::Terminal::TerminalControl::CopyFormat, CopyFormatting, 0); - GETSET_PROPERTY(bool, WarnAboutLargePaste, true); - GETSET_PROPERTY(bool, WarnAboutMultiLinePaste, true); - GETSET_PROPERTY(LaunchPosition, InitialPosition); - GETSET_PROPERTY(winrt::TerminalApp::LaunchMode, LaunchMode, winrt::TerminalApp::LaunchMode::DefaultMode); - GETSET_PROPERTY(bool, SnapToGridOnResize, true); - GETSET_PROPERTY(bool, ForceFullRepaintRendering, false); - GETSET_PROPERTY(bool, SoftwareRendering, false); - GETSET_PROPERTY(bool, ForceVTInput, false); - GETSET_PROPERTY(bool, DebugFeaturesEnabled); // default value set in constructor - GETSET_PROPERTY(bool, StartOnUserLogin, false); - GETSET_PROPERTY(bool, AlwaysOnTop, false); - GETSET_PROPERTY(bool, UseTabSwitcher, true); - -private: - std::optional _unparsedDefaultProfile; - GUID _defaultProfile; - - winrt::com_ptr _keybindings; - std::vector<::TerminalApp::SettingsLoadWarnings> _keybindingsWarnings; - - std::unordered_map _colorSchemes; - winrt::Windows::Foundation::Collections::IMap _commands; - - friend class TerminalAppLocalTests::SettingsTests; - friend class TerminalAppLocalTests::ColorSchemeTests; -}; + BASIC_FACTORY(GlobalAppSettings); +} diff --git a/src/cascadia/TerminalApp/GlobalAppSettings.idl b/src/cascadia/TerminalApp/GlobalAppSettings.idl new file mode 100644 index 00000000000..28fd74ab243 --- /dev/null +++ b/src/cascadia/TerminalApp/GlobalAppSettings.idl @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import "AppLogic.idl"; +import "ColorScheme.idl"; +import "AppKeybindings.idl"; +import "Command.idl"; +import "TerminalSettings.idl"; + +namespace TerminalApp +{ + [default_interface] runtimeclass GlobalAppSettings { + GlobalAppSettings(); + + Guid DefaultProfile; + String UnparsedDefaultProfile(); + + Int32 InitialRows; + Int32 InitialCols; + Boolean AlwaysShowTabs; + Boolean ShowTitleInTitlebar; + Boolean ConfirmCloseAllTabs; + Windows.UI.Xaml.ElementTheme Theme; + Microsoft.UI.Xaml.Controls.TabViewWidthMode TabWidthMode; + Boolean ShowTabsInTitlebar; + String WordDelimiters; + Boolean CopyOnSelect; + Microsoft.Terminal.TerminalControl.CopyFormat CopyFormatting; + Boolean WarnAboutLargePaste; + Boolean WarnAboutMultiLinePaste; + LaunchMode LaunchMode; + Boolean SnapToGridOnResize; + Boolean ForceFullRepaintRendering; + Boolean SoftwareRendering; + Boolean ForceVTInput; + Boolean DebugFeaturesEnabled; + Boolean StartOnUserLogin; + Boolean AlwaysOnTop; + Boolean UseTabSwitcher; + + Boolean HasInitialPositionX(); + Boolean HasInitialPositionY(); + Int32 InitialPositionX { get; }; + Int32 InitialPositionY { get; }; + + + Windows.Foundation.Collections.IMapView GetColorSchemes(); + void AddColorScheme(ColorScheme scheme); + + AppKeyBindings GetKeybindings(); + + Windows.Foundation.Collections.IMapView GetCommands(); + + void ApplyToSettings(TerminalSettings settings); + } +} diff --git a/src/cascadia/TerminalApp/Profile.cpp b/src/cascadia/TerminalApp/Profile.cpp index c4e4c68e823..01f9003c4e5 100644 --- a/src/cascadia/TerminalApp/Profile.cpp +++ b/src/cascadia/TerminalApp/Profile.cpp @@ -84,9 +84,9 @@ Profile::~Profile() // - schemes: a list of schemes to look for our color scheme in, if we have one. // Return Value: // - a new TerminalSettings object with our settings in it. -winrt::TerminalApp::TerminalSettings Profile::CreateTerminalSettings(const std::unordered_map& schemes) const +winrt::TerminalApp::TerminalSettings Profile::CreateTerminalSettings(const Collections::IMapView& schemes) const { - winrt::TerminalApp::TerminalSettings terminalSettings{}; + auto terminalSettings = winrt::make(); // Fill in the Terminal Setting's CoreSettings from the profile terminalSettings.HistorySize(_HistorySize); @@ -124,10 +124,9 @@ winrt::TerminalApp::TerminalSettings Profile::CreateTerminalSettings(const std:: if (!_ColorSchemeName.empty()) { - const auto found = schemes.find(_ColorSchemeName.c_str()); - if (found != schemes.end()) + if (const auto found{ schemes.TryLookup(_ColorSchemeName) }) { - found->second.ApplyScheme(terminalSettings); + found.ApplyScheme(terminalSettings); } } if (_Foreground) diff --git a/src/cascadia/TerminalApp/Profile.h b/src/cascadia/TerminalApp/Profile.h index d60c4f5c741..3f09f592fe2 100644 --- a/src/cascadia/TerminalApp/Profile.h +++ b/src/cascadia/TerminalApp/Profile.h @@ -16,7 +16,7 @@ Author(s): #pragma once #include "Profile.g.h" -#include "ColorScheme.g.h" +#include "TerminalSettings.h" #include "../inc/cppwinrt_utils.h" #include "JsonUtils.h" @@ -48,7 +48,7 @@ namespace winrt::TerminalApp::implementation ~Profile(); - TerminalApp::TerminalSettings CreateTerminalSettings(const std::unordered_map& schemes) const; + TerminalApp::TerminalSettings CreateTerminalSettings(const Windows::Foundation::Collections::IMapView& schemes) const; Json::Value GenerateStub() const; static com_ptr FromJson(const Json::Value& json); diff --git a/src/cascadia/TerminalApp/Profile.idl b/src/cascadia/TerminalApp/Profile.idl index fe8cd4c3107..4b5e9189cf5 100644 --- a/src/cascadia/TerminalApp/Profile.idl +++ b/src/cascadia/TerminalApp/Profile.idl @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +import "TerminalSettings.idl"; +import "ColorScheme.idl"; + namespace TerminalApp { enum CloseOnExitMode @@ -14,6 +17,8 @@ namespace TerminalApp Profile(); Profile(Windows.Foundation.IReference guid); + TerminalSettings CreateTerminalSettings(Windows.Foundation.Collections.IMapView schemes); + String Name; Boolean HasGuid(); Guid Guid; diff --git a/src/cascadia/TerminalApp/SettingsTypes.h b/src/cascadia/TerminalApp/SettingsTypes.h index 946b1951cba..6bca55bc86d 100644 --- a/src/cascadia/TerminalApp/SettingsTypes.h +++ b/src/cascadia/TerminalApp/SettingsTypes.h @@ -11,7 +11,7 @@ Module Name: #pragma once -namespace TerminalApp +namespace winrt::TerminalApp { struct LaunchPosition { diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj index a562ed31e30..f4a0ee3c25e 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj @@ -107,7 +107,9 @@ ColorScheme.idl - + + GlobalAppSettings.idl + Profile.idl @@ -188,7 +190,9 @@ ColorScheme.idl - + + GlobalAppSettings.idl + Profile.idl @@ -281,6 +285,7 @@ + diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters index 3a2e600fd71..347c2e138cd 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters @@ -154,6 +154,9 @@ settings + + settings + diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 5a623685019..3418e651c64 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -2070,16 +2070,16 @@ namespace winrt::TerminalApp::implementation // - IMap TerminalPage::_ExpandCommands(IMapView commandsToExpand, gsl::span profiles, - const std::unordered_map& schemes) + IMapView schemes) { std::vector<::TerminalApp::SettingsLoadWarnings> warnings; std::vector sortedSchemes; - sortedSchemes.reserve(schemes.size()); + sortedSchemes.reserve(schemes.Size()); for (const auto& nameAndScheme : schemes) { - sortedSchemes.push_back(nameAndScheme.second); + sortedSchemes.push_back(nameAndScheme.Value()); } std::sort(sortedSchemes.begin(), sortedSchemes.end(), @@ -2108,7 +2108,7 @@ namespace winrt::TerminalApp::implementation // - void TerminalPage::_UpdateCommandsForPalette() { - IMap copyOfCommands = _ExpandCommands(_settings->GlobalSettings().GetCommands().GetView(), + IMap copyOfCommands = _ExpandCommands(_settings->GlobalSettings().GetCommands(), _settings->GetProfiles(), _settings->GlobalSettings().GetColorSchemes()); diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index b30682ada54..00f18a4cc1c 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -138,7 +138,7 @@ namespace winrt::TerminalApp::implementation void _UpdateCommandsForPalette(); static winrt::Windows::Foundation::Collections::IMap _ExpandCommands(Windows::Foundation::Collections::IMapView commandsToExpand, gsl::span profiles, - const std::unordered_map& schemes); + Windows::Foundation::Collections::IMapView schemes); void _DuplicateTabViewItem(); void _RemoveTabViewItem(const Microsoft::UI::Xaml::Controls::TabViewItem& tabViewItem); diff --git a/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h b/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h index deb7856063a..39e0c7df1f6 100644 --- a/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h +++ b/src/cascadia/TerminalApp/TerminalSettingsSerializationHelpers.h @@ -184,7 +184,7 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode) }; }; -JSON_ENUM_MAPPER(::TerminalApp::ExpandCommandType) +JSON_ENUM_MAPPER(winrt::TerminalApp::ExpandCommandType) { JSON_MAPPINGS(2) = { pair_type{ "profiles", ValueType::Profiles }, @@ -226,11 +226,11 @@ JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::TerminalControl::CopyFormat) // (abc, 100): if a value is not valid, we treat it as default // (100, 100, 100): we only read the first two values, this is equivalent to (100, 100) template<> -struct ::TerminalApp::JsonUtils::ConversionTrait<::TerminalApp::LaunchPosition> +struct ::TerminalApp::JsonUtils::ConversionTrait<::winrt::TerminalApp::LaunchPosition> { - ::TerminalApp::LaunchPosition FromJson(const Json::Value& json) + ::winrt::TerminalApp::LaunchPosition FromJson(const Json::Value& json) { - ::TerminalApp::LaunchPosition ret; + ::winrt::TerminalApp::LaunchPosition ret; std::string initialPosition{ json.asString() }; static constexpr char singleCharDelim = ','; std::stringstream tokenStream(initialPosition);