const vectors, rename to typeHint

This commit is contained in:
Pankaj Bhojwani 2025-08-13 16:41:36 -07:00
parent da0a7a0fa0
commit c5dd430bdf
3 changed files with 66 additions and 67 deletions

View File

@ -394,10 +394,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
public:
NewTerminalArgs(int32_t& profileIndex) :
_ProfileIndex{ profileIndex }
{
NEW_TERMINAL_ARGS(APPEND_ARG_DESCRIPTION);
};
_ProfileIndex{ profileIndex },
_argDescriptors(INIT_ARG_DESCRIPTORS(NEW_TERMINAL_ARGS)) {};
hstring GenerateName() const { return GenerateName(GetLibraryResourceLoader().ResourceContext()); }
hstring GenerateName(const winrt::Windows::ApplicationModel::Resources::Core::ResourceContext&) const;
hstring ToCommandline() const;
@ -477,7 +475,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
copy->_Elevate = _Elevate;
copy->_ReloadEnvironmentVariables = _ReloadEnvironmentVariables;
copy->_ContentId = _ContentId;
copy->_argDescriptors = _argDescriptors;
return *copy;
}
size_t Hash() const
@ -667,31 +664,26 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
struct SplitPaneArgs : public SplitPaneArgsT<SplitPaneArgs>
{
SplitPaneArgs(){
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
SplitPaneArgs() :
_argDescriptors(INIT_ARG_DESCRIPTORS(SPLIT_PANE_ARGS)) {};
SplitPaneArgs(SplitType splitMode, SplitDirection direction, float size, const Model::INewContentArgs& terminalArgs) :
_SplitMode{ splitMode },
_SplitDirection{ direction },
_SplitSize{ size },
_ContentArgs{ terminalArgs } {
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
_ContentArgs{ terminalArgs },
_argDescriptors(INIT_ARG_DESCRIPTORS(SPLIT_PANE_ARGS)) {};
SplitPaneArgs(SplitDirection direction, float size, const Model::INewContentArgs& terminalArgs) :
_SplitDirection{ direction },
_SplitSize{ size },
_ContentArgs{ terminalArgs } {
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
_ContentArgs{ terminalArgs },
_argDescriptors(INIT_ARG_DESCRIPTORS(SPLIT_PANE_ARGS)) {};
SplitPaneArgs(SplitDirection direction, const Model::INewContentArgs& terminalArgs) :
_SplitDirection{ direction },
_ContentArgs{ terminalArgs } {
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
_ContentArgs{ terminalArgs },
_argDescriptors(INIT_ARG_DESCRIPTORS(SPLIT_PANE_ARGS)) {};
SplitPaneArgs(SplitType splitMode) :
_SplitMode{ splitMode } {
SPLIT_PANE_ARGS(APPEND_ARG_DESCRIPTION)
};
_SplitMode{ splitMode },
_argDescriptors(INIT_ARG_DESCRIPTORS(SPLIT_PANE_ARGS)) {};
SPLIT_PANE_ARGS(DECLARE_ARGS);
WINRT_PROPERTY(Model::INewContentArgs, ContentArgs, Model::NewTerminalArgs{});
@ -749,7 +741,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
copy->_ContentArgs = _ContentArgs.Copy();
copy->_SplitMode = _SplitMode;
copy->_SplitSize = _SplitSize;
copy->_argDescriptors = _argDescriptors;
return *copy;
}
size_t Hash() const
@ -813,7 +804,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
}
private:
std::vector<ArgDescriptor> _argDescriptors;
const std::vector<ArgDescriptor> _argDescriptors;
};
struct NewWindowArgs : public NewWindowArgsT<NewWindowArgs>

View File

@ -18,7 +18,7 @@ namespace Microsoft.Terminal.Settings.Model
String Name;
String Type;
Boolean Required;
ArgTypeHint Tag;
ArgTypeHint TypeHint;
};
interface IActionArgsDescriptorAccess

View File

@ -54,16 +54,16 @@ struct InitListPlaceholder
// expanded. Pretty critical for tracking down extraneous commas, etc.
// Property definitions, and JSON keys
#define DECLARE_ARGS(type, name, jsonKey, required, tag, ...) \
static constexpr std::string_view name##Key{ jsonKey }; \
#define DECLARE_ARGS(type, name, jsonKey, required, typeHint, ...) \
static constexpr std::string_view name##Key{ jsonKey }; \
ACTION_ARG(type, name, ##__VA_ARGS__);
// Parameters to the non-default ctor
#define CTOR_PARAMS(type, name, jsonKey, required, tag, ...) \
#define CTOR_PARAMS(type, name, jsonKey, required, typeHint, ...) \
const type &name##Param,
// initializers in the ctor
#define CTOR_INIT(type, name, jsonKey, required, tag, ...) \
#define CTOR_INIT(type, name, jsonKey, required, typeHint, ...) \
_##name{ name##Param },
#define ARG_DESC_STRINGIFY2(x) #x
@ -73,40 +73,46 @@ struct InitListPlaceholder
#define LOCALIZED_NAME(name) ARG_DESC_WIDEN(ARG_DESC_STRINGIFY(name##Localized))
// append this argument's description to the internal vector
#define APPEND_ARG_DESCRIPTION(type, name, jsonKey, required, tag, ...) \
_argDescriptors.push_back({ RS_(LOCALIZED_NAME(name)), L## #type, std::wstring_view(L## #required) != L"false", tag });
#define APPEND_ARG_DESCRIPTION(type, name, jsonKey, required, typeHint, ...) \
temp.push_back({ RS_(LOCALIZED_NAME(name)), L## #type, std::wstring_view(L## #required) != L"false", typeHint });
#define INIT_ARG_DESCRIPTORS(argsMacro) \
([&]() { \
std::vector<ArgDescriptor> temp; \
argsMacro(APPEND_ARG_DESCRIPTION) return temp; \
}())
// check each property in the Equals() method. You'll note there's a stray
// `true` in the definition of Equals() below, that's to deal with trailing
// commas
#define EQUALS_ARGS(type, name, jsonKey, required, tag, ...) \
#define EQUALS_ARGS(type, name, jsonKey, required, typeHint, ...) \
&&(otherAsUs->_##name == _##name)
// getter and setter for each property by index
#define GET_ARG_BY_INDEX(type, name, jsonKey, required, tag, ...) \
if (index == curIndex++) \
{ \
if (_##name.has_value()) \
{ \
return winrt::box_value(_##name.value()); \
} \
else \
{ \
return winrt::box_value(static_cast<type>(__VA_ARGS__)); \
} \
#define GET_ARG_BY_INDEX(type, name, jsonKey, required, typeHint, ...) \
if (index == curIndex++) \
{ \
if (_##name.has_value()) \
{ \
return winrt::box_value(_##name.value()); \
} \
else \
{ \
return winrt::box_value(static_cast<type>(__VA_ARGS__)); \
} \
}
#define SET_ARG_BY_INDEX(type, name, jsonKey, required, tag, ...) \
if (index == curIndex++) \
{ \
if (value) \
{ \
_##name = winrt::unbox_value<type>(value); \
} \
else \
{ \
_##name = std::nullopt; \
} \
#define SET_ARG_BY_INDEX(type, name, jsonKey, required, typeHint, ...) \
if (index == curIndex++) \
{ \
if (value) \
{ \
_##name = winrt::unbox_value<type>(value); \
} \
else \
{ \
_##name = std::nullopt; \
} \
}
// JSON deserialization. If the parameter is required to pass any validation,
@ -116,7 +122,7 @@ struct InitListPlaceholder
// the bit
// args->ResizeDirection() == ResizeDirection::None
// is used as the conditional for the validation here.
#define FROM_JSON_ARGS(type, name, jsonKey, required, tag, ...) \
#define FROM_JSON_ARGS(type, name, jsonKey, required, typeHint, ...) \
JsonUtils::GetValueForKey(json, jsonKey, args->_##name); \
if (required) \
{ \
@ -124,17 +130,17 @@ struct InitListPlaceholder
}
// JSON serialization
#define TO_JSON_ARGS(type, name, jsonKey, required, tag, ...) \
#define TO_JSON_ARGS(type, name, jsonKey, required, typeHint, ...) \
JsonUtils::SetValueForKey(json, jsonKey, args->_##name);
// Copy each property in the Copy() method
#define COPY_ARGS(type, name, jsonKey, required, tag, ...) \
#define COPY_ARGS(type, name, jsonKey, required, typeHint, ...) \
copy->_##name = _##name;
// hash each property in Hash(). You'll note there's a stray `0` in the
// definition of Hash() below, that's to deal with trailing commas (or in this
// case, leading.)
#define HASH_ARGS(type, name, jsonKey, required, tag, ...) \
#define HASH_ARGS(type, name, jsonKey, required, typeHint, ...) \
h.write(name());
// Use ACTION_ARGS_STRUCT when you've got no other customizing to do.
@ -149,17 +155,18 @@ struct InitListPlaceholder
// * GlobalSummonArgs has the QuakeModeFromJson helper
#define ACTION_ARG_BODY(className, argsMacro) \
className(){ argsMacro(APPEND_ARG_DESCRIPTION) }; \
className() : _argDescriptors(INIT_ARG_DESCRIPTORS(argsMacro)) {}; \
\
className( \
argsMacro(CTOR_PARAMS) InitListPlaceholder = {}) : \
argsMacro(CTOR_INIT) _placeholder{} { \
argsMacro(APPEND_ARG_DESCRIPTION) \
}; \
argsMacro(CTOR_INIT) \
_placeholder{}, \
_argDescriptors(INIT_ARG_DESCRIPTORS(argsMacro)) {}; \
argsMacro(DECLARE_ARGS); \
\
private: \
InitListPlaceholder _placeholder; \
std::vector<ArgDescriptor> _argDescriptors; \
const std::vector<ArgDescriptor> _argDescriptors; \
\
public: \
hstring GenerateName() const \
@ -199,7 +206,6 @@ public:
{ \
auto copy{ winrt::make_self<className>() }; \
argsMacro(COPY_ARGS); \
copy->_argDescriptors = _argDescriptors; \
return *copy; \
} \
size_t Hash() const \
@ -228,17 +234,19 @@ public:
}
#define PARTIAL_ACTION_ARG_BODY(className, argsMacro) \
className(){ argsMacro(APPEND_ARG_DESCRIPTION) }; \
className() : \
_argDescriptors(INIT_ARG_DESCRIPTORS(argsMacro)) {}; \
\
className( \
argsMacro(CTOR_PARAMS) InitListPlaceholder = {}) : \
argsMacro(CTOR_INIT) _placeholder{} { \
argsMacro(APPEND_ARG_DESCRIPTION) \
}; \
argsMacro(CTOR_INIT) \
_placeholder{}, \
_argDescriptors(INIT_ARG_DESCRIPTORS(argsMacro)) {}; \
argsMacro(DECLARE_ARGS); \
\
private: \
InitListPlaceholder _placeholder; \
std::vector<ArgDescriptor> _argDescriptors; \
const std::vector<ArgDescriptor> _argDescriptors; \
\
public: \
uint32_t GetArgCount() const \