Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CascadiaSettings::Copy() #7877

Merged
merged 5 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spell-check/dictionary/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ RSHIFT
rx
serializer
SIZENS
subcmd
spsc
STDCPP
syscall
Expand Down
85 changes: 85 additions & 0 deletions src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ namespace SettingsModelLocalTests
TEST_METHOD(TestUnbindNestedCommand);
TEST_METHOD(TestRebindNestedCommand);

TEST_METHOD(TestCopy);

TEST_CLASS_SETUP(ClassSetup)
{
InitializeJsonReader();
Expand Down Expand Up @@ -2347,4 +2349,87 @@ namespace SettingsModelLocalTests
}
}

void DeserializationTests::TestCopy()
{
const std::string settingsJson{ R"(
{
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"initialCols": 50,
"profiles":
[
{
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Custom Profile",
"fontFace": "Cascadia Code"
}
],
"schemes":
[
{
"name": "Campbell, but for a test",
"foreground": "#CCCCCC",
"background": "#0C0C0C",
"cursorColor": "#FFFFFF",
"black": "#0C0C0C",
"red": "#C50F1F",
"green": "#13A10E",
"yellow": "#C19C00",
"blue": "#0037DA",
"purple": "#881798",
"cyan": "#3A96DD",
"white": "#CCCCCC",
"brightBlack": "#767676",
"brightRed": "#E74856",
"brightGreen": "#16C60C",
"brightYellow": "#F9F1A5",
"brightBlue": "#3B78FF",
"brightPurple": "#B4009E",
"brightCyan": "#61D6D6",
"brightWhite": "#F2F2F2"
}
],
"actions":
[
{ "command": "openSettings", "keys": "ctrl+," },
{ "command": { "action": "openSettings", "target": "defaultsFile" }, "keys": "ctrl+alt+," },

{
"name": { "key": "SetColorSchemeParentCommandName" },
"commands": [
{
"iterateOn": "schemes",
"name": "${scheme.name}",
"command": { "action": "setColorScheme", "colorScheme": "${scheme.name}" }
}
]
}
]
})" };

VerifyParseSucceeded(settingsJson);

auto settings{ winrt::make_self<implementation::CascadiaSettings>() };
settings->_ParseJsonString(settingsJson, false);
settings->LayerJson(settings->_userSettings);
settings->_ValidateSettings();

const auto copy{ settings->Copy() };
const auto copyImpl{ winrt::get_self<implementation::CascadiaSettings>(copy) };

// test globals
VERIFY_ARE_EQUAL(settings->_globals->DefaultProfile(), copyImpl->_globals->DefaultProfile());

// test profiles
VERIFY_ARE_EQUAL(settings->_profiles.Size(), copyImpl->_profiles.Size());
VERIFY_ARE_EQUAL(settings->_profiles.GetAt(0).Name(), copyImpl->_profiles.GetAt(0).Name());

// test schemes
const auto schemeName{ L"Campbell, but for a test" };
VERIFY_ARE_EQUAL(settings->_globals->_colorSchemes.Size(), copyImpl->_globals->_colorSchemes.Size());
VERIFY_ARE_EQUAL(settings->_globals->_colorSchemes.HasKey(schemeName), copyImpl->_globals->_colorSchemes.HasKey(schemeName));

// test actions
VERIFY_ARE_EQUAL(settings->_globals->_keymap->_keyShortcuts.size(), copyImpl->_globals->_keymap->_keyShortcuts.size());
VERIFY_ARE_EQUAL(settings->_globals->_commands.Size(), copyImpl->_globals->_commands.Size());
}
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 8 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
}

com_ptr<ActionAndArgs> ActionAndArgs::Copy() const
{
auto copy{ winrt::make_self<ActionAndArgs>() };
copy->_Action = _Action;
copy->_Args = _Args.Copy();
return copy;
}

winrt::hstring ActionAndArgs::GenerateName() const
{
// Use a magic static to initialize this map, because we won't be able
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
ActionAndArgs(ShortcutAction action, IActionArgs args) :
_Action{ action },
_Args{ args } {};
com_ptr<ActionAndArgs> Copy() const;

hstring GenerateName() const;

Expand Down
104 changes: 104 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, ProfileKey, args->_Profile);
return *args;
}
Model::NewTerminalArgs Copy() const
{
auto copy{ winrt::make_self<NewTerminalArgs>() };
copy->_Commandline = _Commandline;
copy->_StartingDirectory = _StartingDirectory;
copy->_TabTitle = _TabTitle;
copy->_ProfileIndex = _ProfileIndex;
copy->_Profile = _Profile;
return *copy;
}
};

struct CopyTextArgs : public CopyTextArgsT<CopyTextArgs>
Expand Down Expand Up @@ -121,6 +131,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, CopyFormattingKey, args->_CopyFormatting);
return { *args, {} };
}

IActionArgs Copy() const
{
auto copy{ winrt::make_self<CopyTextArgs>() };
copy->_SingleLine = _SingleLine;
copy->_CopyFormatting = _CopyFormatting;
return copy.as<IActionArgs>();
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
}
};

struct NewTabArgs : public NewTabArgsT<NewTabArgs>
Expand Down Expand Up @@ -149,6 +167,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
args->_TerminalArgs = NewTerminalArgs::FromJson(json);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<NewTabArgs>() };
copy->_TerminalArgs = _TerminalArgs.Copy();
return copy.as<IActionArgs>();
}
};

struct SwitchToTabArgs : public SwitchToTabArgsT<SwitchToTabArgs>
Expand Down Expand Up @@ -179,6 +203,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, TabIndexKey, args->_TabIndex);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<SwitchToTabArgs>() };
copy->_TabIndex = _TabIndex;
return copy.as<IActionArgs>();
}
};

struct ResizePaneArgs : public ResizePaneArgsT<ResizePaneArgs>
Expand Down Expand Up @@ -214,6 +244,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return { *args, {} };
}
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<ResizePaneArgs>() };
copy->_Direction = _Direction;
return copy.as<IActionArgs>();
}
};

struct MoveFocusArgs : public MoveFocusArgsT<MoveFocusArgs>
Expand Down Expand Up @@ -249,6 +285,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return { *args, {} };
}
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<MoveFocusArgs>() };
copy->_Direction = _Direction;
return copy.as<IActionArgs>();
}
};

struct AdjustFontSizeArgs : public AdjustFontSizeArgsT<AdjustFontSizeArgs>
Expand Down Expand Up @@ -277,6 +319,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, AdjustFontSizeDelta, args->_Delta);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<AdjustFontSizeArgs>() };
copy->_Delta = _Delta;
return copy.as<IActionArgs>();
}
};

struct SendInputArgs : public SendInputArgsT<SendInputArgs>
Expand Down Expand Up @@ -308,6 +356,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<SendInputArgs>() };
copy->_Input = _Input;
return copy.as<IActionArgs>();
}
};

struct SplitPaneArgs : public SplitPaneArgsT<SplitPaneArgs>
Expand Down Expand Up @@ -347,6 +401,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, SplitModeKey, args->_SplitMode);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<SplitPaneArgs>() };
copy->_SplitStyle = _SplitStyle;
copy->_TerminalArgs = _TerminalArgs.Copy();
copy->_SplitMode = _SplitMode;
return copy.as<IActionArgs>();
}
};

struct OpenSettingsArgs : public OpenSettingsArgsT<OpenSettingsArgs>
Expand Down Expand Up @@ -375,6 +437,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, TargetKey, args->_Target);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<OpenSettingsArgs>() };
copy->_Target = _Target;
return copy.as<IActionArgs>();
}
};

struct SetColorSchemeArgs : public SetColorSchemeArgsT<SetColorSchemeArgs>
Expand Down Expand Up @@ -407,6 +475,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<SetColorSchemeArgs>() };
copy->_SchemeName = _SchemeName;
return copy.as<IActionArgs>();
}
};

struct SetTabColorArgs : public SetTabColorArgsT<SetTabColorArgs>
Expand Down Expand Up @@ -438,6 +512,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<SetTabColorArgs>() };
copy->_TabColor = _TabColor;
return copy.as<IActionArgs>();
}
};

struct RenameTabArgs : public RenameTabArgsT<RenameTabArgs>
Expand Down Expand Up @@ -466,6 +546,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, TitleKey, args->_Title);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<RenameTabArgs>() };
copy->_Title = _Title;
return copy.as<IActionArgs>();
}
};

struct ExecuteCommandlineArgs : public ExecuteCommandlineArgsT<ExecuteCommandlineArgs>
Expand Down Expand Up @@ -500,6 +586,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<ExecuteCommandlineArgs>() };
copy->_Commandline = _Commandline;
return copy.as<IActionArgs>();
}
};

struct CloseOtherTabsArgs : public CloseOtherTabsArgsT<CloseOtherTabsArgs>
Expand Down Expand Up @@ -528,6 +620,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, IndexKey, args->_Index);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<CloseOtherTabsArgs>() };
copy->_Index = _Index;
return copy.as<IActionArgs>();
}
};

struct CloseTabsAfterArgs : public CloseTabsAfterArgsT<CloseTabsAfterArgs>
Expand Down Expand Up @@ -556,6 +654,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
JsonUtils::GetValueForKey(json, IndexKey, args->_Index);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<CloseTabsAfterArgs>() };
copy->_Index = _Index;
return copy.as<IActionArgs>();
}
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Terminal.Settings.Model
{
Boolean Equals(IActionArgs other);
String GenerateName();
IActionArgs Copy();
};

interface IActionEventArgs
Expand Down Expand Up @@ -48,6 +49,7 @@ namespace Microsoft.Terminal.Settings.Model
[default_interface] runtimeclass NewTerminalArgs {
NewTerminalArgs();
NewTerminalArgs(Int32 profileIndex);
NewTerminalArgs Copy();

String Commandline;
String StartingDirectory;
Expand Down
23 changes: 23 additions & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ CascadiaSettings::CascadiaSettings(winrt::hstring json) :
_ValidateSettings();
}

winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings CascadiaSettings::Copy() const
{
// dynamic profile generators added by default
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
auto settings{ winrt::make_self<CascadiaSettings>() };
settings->_globals = _globals->Copy();
for (const auto profile : _profiles)
{
auto profImpl{ winrt::get_self<Profile>(profile) };
settings->_profiles.Append(*profImpl->Copy());
}
for (auto warning : _warnings)
{
settings->_warnings.Append(warning);
}
settings->_loadError = _loadError;
settings->_deserializationErrorMessage = _deserializationErrorMessage;
settings->_userSettingsString = _userSettingsString;
settings->_userSettings = _userSettings;
settings->_defaultSettings = _defaultSettings;
settings->_userDefaultProfileSettings = _userDefaultProfileSettings;
return *settings;
}

// Method Description:
// - Finds a profile that matches the given GUID. If there is no profile in this
// settings object that matches, returns nullptr.
Expand Down
Loading