## Summary of the Pull Request This PR builds on the `ActionMap` PR (#6900) by leveraging `ActionMap` to serialize actions. From the top down, the process is now as follows: - `CascadiaSettings`: remove the hack of copying whatever we had for actions before. - `GlobalAppSettings`: serialize the `ActionMap` to `"actions": []` - `ActionMap`: iterate over the internal `_ActionMap` (list of actions) and serialize each `Command` - `Command`: **THIS IS WHERE THE MAGIC HAPPENS!** For _each_ key mapping, serialize an action. Only the first one needs to include the name and icon. - `ActionAndArgs`: Find the relevant `IActionArgs` parser and serialize the `ActionAndArgs`. - `ActionArgs`: **ANNOYING CHANGE** Serialize any args that are set. We _need_ each setting to be saved as a `std::optional`. As with inheritance, this allows us to distinguish an explicit setting to the default value (sometimes `null`) vs an implicit "give me the default value". This allows us to serialize only the relevant details of each action, rather than writing _all_ of the args. ## References - #8100: Inheritance/Layering for lists - This tracks layering and better serialization for color schemes _and_ actions. This PR resolves half of that issue. The next step is to apply the concepts used in this PR (and #9621) to solve the similar problem for color schemes. - #6900: Actions page ## Validation Steps Performed Tests added!
98 lines
3.8 KiB
C++
98 lines
3.8 KiB
C++
/*++
|
|
Copyright (c) Microsoft Corporation
|
|
Licensed under the MIT license.
|
|
|
|
Module Name:
|
|
- Command.h
|
|
|
|
Abstract:
|
|
- A command represents a single entry in the Command Palette. This is an object
|
|
that has a user facing "name" to display to the user, and an associated action
|
|
which can be dispatched.
|
|
|
|
- For more information, see GH#2046, #5400, #5674, and #6635
|
|
|
|
Author(s):
|
|
- Mike Griese - June 2020
|
|
|
|
--*/
|
|
#pragma once
|
|
|
|
#include "Command.g.h"
|
|
#include "TerminalWarnings.h"
|
|
#include "Profile.h"
|
|
#include "ActionAndArgs.h"
|
|
#include "../inc/cppwinrt_utils.h"
|
|
#include "SettingsTypes.h"
|
|
|
|
// fwdecl unittest classes
|
|
namespace SettingsModelLocalTests
|
|
{
|
|
class DeserializationTests;
|
|
class CommandTests;
|
|
};
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|
{
|
|
struct Command : CommandT<Command>
|
|
{
|
|
Command();
|
|
com_ptr<Command> Copy() const;
|
|
|
|
static winrt::com_ptr<Command> FromJson(const Json::Value& json,
|
|
std::vector<SettingsLoadWarnings>& warnings);
|
|
|
|
static void ExpandCommands(Windows::Foundation::Collections::IMap<winrt::hstring, Model::Command> commands,
|
|
Windows::Foundation::Collections::IVectorView<Model::Profile> profiles,
|
|
Windows::Foundation::Collections::IVectorView<Model::ColorScheme> schemes,
|
|
Windows::Foundation::Collections::IVector<SettingsLoadWarnings> warnings);
|
|
|
|
static std::vector<SettingsLoadWarnings> LayerJson(Windows::Foundation::Collections::IMap<winrt::hstring, Model::Command>& commands,
|
|
const Json::Value& json);
|
|
Json::Value ToJson() const;
|
|
|
|
bool HasNestedCommands() const;
|
|
bool IsNestedCommand() const noexcept;
|
|
Windows::Foundation::Collections::IMapView<winrt::hstring, Model::Command> NestedCommands() const;
|
|
|
|
bool HasName() const noexcept;
|
|
hstring Name() const noexcept;
|
|
void Name(const hstring& name);
|
|
|
|
Control::KeyChord Keys() const noexcept;
|
|
hstring KeyChordText() const noexcept;
|
|
std::vector<Control::KeyChord> KeyMappings() const noexcept;
|
|
void RegisterKey(const Control::KeyChord& keys);
|
|
void EraseKey(const Control::KeyChord& keys);
|
|
|
|
hstring IconPath() const noexcept;
|
|
void IconPath(const hstring& val);
|
|
|
|
winrt::Windows::UI::Xaml::Data::INotifyPropertyChanged::PropertyChanged_revoker propertyChangedRevoker;
|
|
|
|
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
|
|
WINRT_PROPERTY(ExpandCommandType, IterateOn, ExpandCommandType::None);
|
|
WINRT_PROPERTY(Model::ActionAndArgs, ActionAndArgs);
|
|
|
|
private:
|
|
Json::Value _originalJson;
|
|
Windows::Foundation::Collections::IMap<winrt::hstring, Model::Command> _subcommands{ nullptr };
|
|
std::vector<Control::KeyChord> _keyMappings;
|
|
std::optional<std::wstring> _name;
|
|
std::optional<std::wstring> _iconPath;
|
|
bool _nestedCommand{ false };
|
|
|
|
static std::vector<Model::Command> _expandCommand(Command* const expandable,
|
|
Windows::Foundation::Collections::IVectorView<Model::Profile> profiles,
|
|
Windows::Foundation::Collections::IVectorView<Model::ColorScheme> schemes,
|
|
Windows::Foundation::Collections::IVector<SettingsLoadWarnings>& warnings);
|
|
friend class SettingsModelLocalTests::DeserializationTests;
|
|
friend class SettingsModelLocalTests::CommandTests;
|
|
};
|
|
}
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation
|
|
{
|
|
BASIC_FACTORY(Command);
|
|
}
|