terminal/src/cascadia/TerminalApp/TerminalWarnings.h
Mike Griese dcc2799457
Add support for iterable, nested commands (#6856)
## Summary of the Pull Request

This PR adds support for both _nested_ and _iterable_ commands in the Command palette.
![nested-commands-000](https://user-images.githubusercontent.com/18356694/87072916-2d991c00-c1e2-11ea-8917-a70e8b8b9803.gif)

* **Nested commands**: These are commands that include additional sub-commands. When the user selects on of these, the palette will update to only show the nested commands.
* **Iterable commands**: These are commands what allow the user to define only a single command, which is repeated once for every profile. (in the future, also repeated for color schemes, themes, etc.)

The above gif uses the following json:

```json
        {
            "name": "Split Pane...",
            "commands": [
                {
                    "iterateOn": "profiles",
                    "name": "Split with ${profile.name}...",
                    "commands": [
                        { "command": { "action": "splitPane", "profile": "${profile.name}", "split": "automatic" } },
                        { "command": { "action": "splitPane", "profile": "${profile.name}", "split": "vertical" } },
                        { "command": { "action": "splitPane", "profile": "${profile.name}", "split": "horizontal" } }
                    ]
                }
            ]
        },
```

## References

## PR Checklist
* [x] Closes #3994
* [x] I work here
* [x] Tests added/passed
* [ ] Requires documentation to be updated - Sure does, but we'll finish polishing this first.

## Detailed Description of the Pull Request / Additional comments

We've now gotta keep the original json for a command around, so that once we know what all the profiles will be, we can expand the commands that need it. 

We've also got to parse commands recursively, because they might have any number of child commands.

These together made the command parsing a _lot_ more complicated, but it feels good so far.

## Validation Steps Performed
* wrote a bunch of tests
* Played with it a bunch
2020-08-13 21:22:46 +00:00

69 lines
2.1 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- TerminalWarnings.h
Abstract:
- This file contains definitions for warnings, errors and exceptions used by the
Windows Terminal
Author(s):
- Mike Griese - August 2019
--*/
#pragma once
namespace TerminalApp
{
// SettingsLoadWarnings are scenarios where the settings contained
// information we knew was invalid, but we could recover from.
enum class SettingsLoadWarnings : uint32_t
{
MissingDefaultProfile = 0,
DuplicateProfile = 1,
UnknownColorScheme = 2,
InvalidBackgroundImage = 3,
InvalidIcon = 4,
AtLeastOneKeybindingWarning = 5,
TooManyKeysForChord = 6,
MissingRequiredParameter = 7,
LegacyGlobalsProperty = 8,
FailedToParseCommandJson = 9,
WARNINGS_SIZE // IMPORTANT: This MUST be the last value in this enum. It's an unused placeholder.
};
// SettingsLoadWarnings are scenarios where the settings had invalid state
// that we could not recover from.
enum class SettingsLoadErrors : uint32_t
{
NoProfiles = 0,
AllProfilesHidden = 1,
ERRORS_SIZE // IMPORTANT: This MUST be the last value in this enum. It's an unused placeholder.
};
// This is a helper class to wrap up a SettingsLoadErrors into a proper
// exception type.
class SettingsException : public std::runtime_error
{
public:
explicit SettingsException(const SettingsLoadErrors& error) :
std::runtime_error{ nullptr },
_error{ error } {};
// We don't use the what() method - we want to be able to display
// localizable error messages. Catchers of this exception should use
// _GetErrorText (in App.cpp) to get the localized exception string.
const char* what() const override
{
return "Exception while loading or validating Terminal settings";
};
SettingsLoadErrors Error() const noexcept { return _error; };
private:
const SettingsLoadErrors _error;
};
};