8d81497eb7
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Add a new action that can contain multiple other actions. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #3992 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [x] Schema updated. * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments Creates a shortcut action that allows a list of actions to be specified as arguments. Steals a bunch of the serialization code from my other pr. Overall, because I had the serialization code written already, this was remarkably easy. I can't think of any combined action to be added to the defaults, so I think this is just a thing for the documentation unless someone else has a good example. I know there are lot of times when the recommended workaround is "make an action with commandline wt.exe ..." and this could be a good replacement for that, but that is all personalized. I didn't add this to the command line parsing, since the command line is already a way to run multiple actions. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Created a new command, confirmed that "Move right->down" showed up in the command palette, and that running it did the correct behavior (moving right one pane, then down one pane). ``` { "command": { "action": "multipleActions", "name": "Move right->down", "actions": [ {"action": "moveFocus", "direction": "right" }, {"action": "moveFocus", "direction": "down" }, ] } } ```
69 lines
2 KiB
C++
69 lines
2 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
|
|
|
#include "ActionAndArgs.g.h"
|
|
#include "ActionArgs.h"
|
|
#include "TerminalWarnings.h"
|
|
#include "../inc/cppwinrt_utils.h"
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|
{
|
|
struct ActionAndArgs : public ActionAndArgsT<ActionAndArgs>
|
|
{
|
|
static const std::map<std::string_view, ShortcutAction, std::less<>> ActionKeyNamesMap;
|
|
static winrt::com_ptr<ActionAndArgs> FromJson(const Json::Value& json,
|
|
std::vector<SettingsLoadWarnings>& warnings);
|
|
static Json::Value ToJson(const Model::ActionAndArgs& val);
|
|
|
|
ActionAndArgs() = default;
|
|
ActionAndArgs(ShortcutAction action);
|
|
ActionAndArgs(ShortcutAction action, IActionArgs args) :
|
|
_Action{ action },
|
|
_Args{ args } {};
|
|
com_ptr<ActionAndArgs> Copy() const;
|
|
|
|
hstring GenerateName() const;
|
|
|
|
WINRT_PROPERTY(ShortcutAction, Action, ShortcutAction::Invalid);
|
|
WINRT_PROPERTY(IActionArgs, Args, nullptr);
|
|
};
|
|
}
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation
|
|
{
|
|
BASIC_FACTORY(ActionAndArgs);
|
|
}
|
|
|
|
namespace Microsoft::Terminal::Settings::Model::JsonUtils
|
|
{
|
|
using namespace winrt::Microsoft::Terminal::Settings::Model;
|
|
|
|
template<>
|
|
struct ConversionTrait<ActionAndArgs>
|
|
{
|
|
ActionAndArgs FromJson(const Json::Value& json)
|
|
{
|
|
std::vector<SettingsLoadWarnings> v;
|
|
return *implementation::ActionAndArgs::FromJson(json, v);
|
|
}
|
|
|
|
bool CanConvert(const Json::Value& json) const
|
|
{
|
|
// commands without args might just be a string
|
|
return json.isString() || json.isObject();
|
|
}
|
|
|
|
Json::Value ToJson(const ActionAndArgs& val)
|
|
{
|
|
return implementation::ActionAndArgs::ToJson(val);
|
|
}
|
|
|
|
std::string TypeDescription() const
|
|
{
|
|
return "ActionAndArgs";
|
|
}
|
|
};
|
|
}
|