Skip to content

Commit

Permalink
this is contrived
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Apr 4, 2024
1 parent 07562d5 commit 893b25e
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/ScratchpadContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace winrt::TerminalApp::implementation

INewContentArgs ScratchpadContent::GetNewTerminalArgs(const BuildStartupKind /* kind */) const
{
return GenericContentArgs(L"scratchpad");
return *winrt::make_self<BaseContentArgs>(L"scratchpad");
}

winrt::hstring ScratchpadContent::Icon() const
Expand Down
50 changes: 50 additions & 0 deletions src/cascadia/TerminalApp/ScratchpadContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once
#include "winrt/TerminalApp.h"
#include "../TerminalSettingsModel/HashUtils.h"

namespace winrt::TerminalApp::implementation
{
Expand Down Expand Up @@ -42,4 +43,53 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::UI::Xaml::Controls::Grid _root{ nullptr };
winrt::Windows::UI::Xaml::Controls::TextBox _box{ nullptr };
};

struct BaseContentArgs : public winrt::implements<BaseContentArgs, winrt::Microsoft::Terminal::Settings::Model::INewContentArgs>
{
BaseContentArgs(winrt::hstring type) :
Type{ type } {}
BaseContentArgs() :
BaseContentArgs(L"") {}
til::property<winrt::hstring> Type;

static constexpr std::string_view TypeKey{ "type" };

public:
bool Equals(winrt::Microsoft::Terminal::Settings::Model::INewContentArgs other) const
{
return other.Type() == Type();
}
size_t Hash() const
{
til::hasher h;
Hash(h);
return h.finalize();
}
void Hash(til::hasher& h) const
{
h.write(Type());
}
winrt::Microsoft::Terminal::Settings::Model::INewContentArgs Copy() const
{
auto copy{ winrt::make_self<BaseContentArgs>() };
copy->Type(Type());
return *copy;
}
winrt::hstring GenerateName() const
{
return winrt::hstring{ L"type: " } + Type();
}
// static Json::Value ToJson(const winrt::com_ptr<BaseContentArgs> args)
// {
// if (!val)
// {
// return {};
// }
// // auto args{ get_self<BaseContentArgs>(val) };
// Json::Value json{ Json::ValueType::objectValue };
// JsonUtils::SetValueForKey(json, TypeKey, args.Type());
// return json;
// }
};

}
1 change: 0 additions & 1 deletion src/cascadia/TerminalSettingsModel/ActionArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "ActionArgs.h"

#include "ActionEventArgs.g.cpp"
#include "GenericContentArgs.g.cpp"
#include "NewTerminalArgs.g.cpp"
#include "CopyTextArgs.g.cpp"
#include "NewTabArgs.g.cpp"
Expand Down
33 changes: 17 additions & 16 deletions src/cascadia/TerminalSettingsModel/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// HEY YOU: When adding ActionArgs types, make sure to add the corresponding
// *.g.cpp to ActionArgs.cpp!
#include "ActionEventArgs.g.h"
#include "GenericContentArgs.g.h"
#include "NewTerminalArgs.g.h"
#include "CopyTextArgs.g.h"
#include "NewTabArgs.g.h"
Expand Down Expand Up @@ -296,7 +295,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
WINRT_PROPERTY(bool, Handled, false);
};

struct GenericContentArgs : public GenericContentArgsT<GenericContentArgs>
struct GenericContentArgs : public winrt::implements<GenericContentArgs, INewContentArgs>
{
GenericContentArgs(winrt::hstring type) :
_Type{ type } {}
Expand Down Expand Up @@ -333,17 +332,17 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
return winrt::hstring{ L"type: " } + Type();
}
static Json::Value ToJson(const Model::GenericContentArgs& val)
{
if (!val)
{
return {};
}
auto args{ get_self<GenericContentArgs>(val) };
Json::Value json{ Json::ValueType::objectValue };
JsonUtils::SetValueForKey(json, TypeKey, args->_Type);
return json;
}
// static Json::Value ToJson(const Model::GenericContentArgs& val)
// {
// if (!val)
// {
// return {};
// }
// auto args{ get_self<GenericContentArgs>(val) };
// Json::Value json{ Json::ValueType::objectValue };
// JsonUtils::SetValueForKey(json, TypeKey, args->_Type);
// return json;
// }
};

// Although it may _seem_ like NewTerminalArgs can use ACTION_ARG_BODY, it
Expand Down Expand Up @@ -522,8 +521,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

// For now, we don't support any other concrete types of content
// with args. Just return a placeholder.
auto base{ winrt::make_self<GenericContentArgs>(contentArgs.Type()) };
return GenericContentArgs::ToJson(*base);
// auto base{ winrt::make_self<GenericContentArgs>(contentArgs.Type()) };
// return GenericContentArgs::ToJson(*base);
Json::Value json{ Json::ValueType::objectValue };
JsonUtils::SetValueForKey(json, "type", contentArgs.Type());
return json;
}

}
Expand Down Expand Up @@ -918,7 +920,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation
{
BASIC_FACTORY(ActionEventArgs);
BASIC_FACTORY(GenericContentArgs);
BASIC_FACTORY(CopyTextArgs);
BASIC_FACTORY(SwitchToTabArgs);
BASIC_FACTORY(NewTerminalArgs);
Expand Down
5 changes: 0 additions & 5 deletions src/cascadia/TerminalSettingsModel/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ namespace Microsoft.Terminal.Settings.Model
String GenerateName();
};

[default_interface] runtimeclass GenericContentArgs : INewContentArgs{
GenericContentArgs();
GenericContentArgs(String type);
};

[default_interface] runtimeclass NewTerminalArgs : INewContentArgs{
NewTerminalArgs();
NewTerminalArgs(Int32 profileIndex);
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ namespace SettingsModelUnitTests
{
Log::Comment(L"These are two actions with different content args. They should have different hashes for their terminal args.");
const auto actionMap = winrt::make_self<implementation::ActionMap>();
actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": { "action": "newTab", } , "keys": ["ctrl+c"] } ])"));
actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": { "action": "newTab", "index": 0 } , "keys": ["ctrl+shift+c"] } ])"));
actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": { "action": "newTab", } , "keys": ["ctrl+c"] } ])"), OriginTag::None);
actionMap->LayerJson(VerifyParseSucceeded(R"([ { "command": { "action": "newTab", "index": 0 } , "keys": ["ctrl+shift+c"] } ])"), OriginTag::None);
VERIFY_ARE_EQUAL(2u, actionMap->_ActionMap.size());

KeyChord ctrlC{ VirtualKeyModifiers::Control, static_cast<int32_t>('C'), 0 };
Expand Down

0 comments on commit 893b25e

Please sign in to comment.