mirror of
https://github.com/microsoft/terminal.git
synced 2026-05-19 03:10:49 +00:00
make sure to actually update the xaml lists as well.
This commit is contained in:
@@ -99,11 +99,21 @@ namespace TerminalAppLocalTests
|
||||
}
|
||||
|
||||
private:
|
||||
void _logCommandNames(std::unordered_map<winrt::hstring, winrt::TerminalApp::Command>& commands)
|
||||
void _logCommandNames(std::unordered_map<winrt::hstring, winrt::TerminalApp::Command>& commands, const int indentation = 1)
|
||||
{
|
||||
Log::Comment(L"Commands:");
|
||||
for (auto& nameAndCommand : commands)
|
||||
{
|
||||
Log::Comment(fmt::format(L"{}", nameAndCommand.first).c_str());
|
||||
Log::Comment(fmt::format(L"{0:>{1}}* {2}->{3}",
|
||||
L"",
|
||||
indentation,
|
||||
nameAndCommand.first,
|
||||
nameAndCommand.second.Name())
|
||||
.c_str());
|
||||
|
||||
winrt::com_ptr<implementation::Command> cmdImpl;
|
||||
cmdImpl.copy_from(winrt::get_self<implementation::Command>(nameAndCommand.second));
|
||||
_logCommandNames(cmdImpl->_subcommands, indentation + 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -2623,6 +2633,7 @@ namespace TerminalAppLocalTests
|
||||
}
|
||||
|
||||
settings._ValidateSettings();
|
||||
_logCommandNames(commands);
|
||||
|
||||
VERIFY_ARE_EQUAL(0u, settings._warnings.size());
|
||||
VERIFY_ARE_EQUAL(3u, commands.size());
|
||||
@@ -2752,6 +2763,7 @@ namespace TerminalAppLocalTests
|
||||
}
|
||||
|
||||
settings._ValidateSettings();
|
||||
_logCommandNames(commands);
|
||||
|
||||
VERIFY_ARE_EQUAL(0u, settings._warnings.size());
|
||||
VERIFY_ARE_EQUAL(3u, commands.size());
|
||||
@@ -2883,6 +2895,7 @@ namespace TerminalAppLocalTests
|
||||
}
|
||||
|
||||
settings._ValidateSettings();
|
||||
_logCommandNames(commands);
|
||||
|
||||
VERIFY_ARE_EQUAL(0u, settings._warnings.size());
|
||||
VERIFY_ARE_EQUAL(3u, commands.size());
|
||||
@@ -3004,6 +3017,7 @@ namespace TerminalAppLocalTests
|
||||
|
||||
auto& commands = settings._globals.GetCommands();
|
||||
settings._ValidateSettings();
|
||||
_logCommandNames(commands);
|
||||
|
||||
VERIFY_ARE_EQUAL(0u, settings._warnings.size());
|
||||
VERIFY_ARE_EQUAL(1u, commands.size());
|
||||
@@ -3111,6 +3125,7 @@ namespace TerminalAppLocalTests
|
||||
|
||||
auto& commands = settings._globals.GetCommands();
|
||||
settings._ValidateSettings();
|
||||
_logCommandNames(commands);
|
||||
|
||||
VERIFY_ARE_EQUAL(0u, settings._warnings.size());
|
||||
VERIFY_ARE_EQUAL(1u, commands.size());
|
||||
@@ -3248,6 +3263,7 @@ namespace TerminalAppLocalTests
|
||||
|
||||
auto& commands = settings._globals.GetCommands();
|
||||
settings._ValidateSettings();
|
||||
_logCommandNames(commands);
|
||||
|
||||
VERIFY_ARE_EQUAL(0u, settings._warnings.size());
|
||||
|
||||
@@ -3398,6 +3414,7 @@ namespace TerminalAppLocalTests
|
||||
|
||||
auto& commands = settings._globals.GetCommands();
|
||||
settings._ValidateSettings();
|
||||
_logCommandNames(commands);
|
||||
|
||||
VERIFY_ARE_EQUAL(0u, settings._warnings.size());
|
||||
VERIFY_ARE_EQUAL(1u, commands.size());
|
||||
@@ -3509,6 +3526,7 @@ namespace TerminalAppLocalTests
|
||||
|
||||
auto& commands = settings._globals.GetCommands();
|
||||
settings._ValidateSettings();
|
||||
_logCommandNames(commands);
|
||||
|
||||
VERIFY_ARE_EQUAL(0u, settings._warnings.size());
|
||||
VERIFY_ARE_EQUAL(1u, commands.size());
|
||||
|
||||
@@ -53,6 +53,11 @@ namespace winrt::TerminalApp::implementation
|
||||
// - The bound keychord, if this ActionAndArgs is bound to a key, otherwise nullptr.
|
||||
KeyChord AppKeyBindings::GetKeyBindingForActionWithArgs(TerminalApp::ActionAndArgs const& actionAndArgs)
|
||||
{
|
||||
if (actionAndArgs == nullptr)
|
||||
{
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
for (auto& kv : _keyShortcuts)
|
||||
{
|
||||
const auto action = kv.second.Action();
|
||||
|
||||
@@ -120,60 +120,44 @@ namespace winrt::TerminalApp::implementation
|
||||
// Return Value:
|
||||
// - the newly constructed Command object.
|
||||
winrt::com_ptr<Command> Command::FromJson(const Json::Value& json,
|
||||
std::vector<::TerminalApp::SettingsLoadWarnings>& warnings,
|
||||
const bool /*postExpansion*/)
|
||||
std::vector<::TerminalApp::SettingsLoadWarnings>& warnings)
|
||||
{
|
||||
auto result = winrt::make_self<Command>();
|
||||
|
||||
// bool iterable = false;
|
||||
bool nested = false;
|
||||
// if (!postExpansion)
|
||||
if (const auto iterateOnJson{ json[JsonKey(IterateOnKey)] })
|
||||
{
|
||||
if (const auto iterateOnJson{ json[JsonKey(IterateOnKey)] })
|
||||
auto s = iterateOnJson.asString();
|
||||
if (s == IterateOnProfilesValue)
|
||||
{
|
||||
auto s = iterateOnJson.asString();
|
||||
if (s == IterateOnProfilesValue)
|
||||
{
|
||||
result->_IterateOn = ExpandCommandType::Profiles;
|
||||
// iterable = true;
|
||||
}
|
||||
result->_IterateOn = ExpandCommandType::Profiles;
|
||||
}
|
||||
}
|
||||
|
||||
// For iterable commands, we'll make another pass at parsing them once
|
||||
// the json is patched. So ignore parsing sub-commands for now. Commands
|
||||
// will only be marked iterable on the first pass.
|
||||
// if (!iterable)
|
||||
if (const auto nestedCommandsJson{ json[JsonKey(CommandsKey)] })
|
||||
{
|
||||
if (const auto nestedCommandsJson{ json[JsonKey(CommandsKey)] })
|
||||
{
|
||||
auto nestedWarnings = Command::LayerJson(result->_subcommands, nestedCommandsJson);
|
||||
// It's possible that the nested commands have some warnings
|
||||
warnings.insert(warnings.end(), nestedWarnings.begin(), nestedWarnings.end());
|
||||
auto nestedWarnings = Command::LayerJson(result->_subcommands, nestedCommandsJson);
|
||||
// It's possible that the nested commands have some warnings
|
||||
warnings.insert(warnings.end(), nestedWarnings.begin(), nestedWarnings.end());
|
||||
|
||||
// Add all the commands we've parsed to the observable vector we
|
||||
// have, so we can access them in XAML.
|
||||
for (auto& nameAndCommand : result->_subcommands)
|
||||
{
|
||||
auto command = nameAndCommand.second;
|
||||
result->_nestedCommandsView.Append(command);
|
||||
}
|
||||
nested = true;
|
||||
}
|
||||
|
||||
// TODO: else if (hasKey(CommandKey) )
|
||||
// {
|
||||
// // { name: "foo", commands: null } will land in this case, which
|
||||
// // should also be used for unbinding.
|
||||
// return nullptr;
|
||||
// }
|
||||
nested = true;
|
||||
}
|
||||
|
||||
// TODO: else if (hasKey(CommandKey) )
|
||||
// {
|
||||
// // { name: "foo", commands: null } will land in this case, which
|
||||
// // should also be used for unbinding.
|
||||
// return nullptr;
|
||||
// }
|
||||
|
||||
// TODO GH#6644: iconPath not implemented quite yet. Can't seem to get
|
||||
// the binding quite right. Additionally, do we want it to be an image,
|
||||
// or a FontIcon? I've had difficulty binding either/or.
|
||||
|
||||
// If we're a nested command, we can ignore the current command.
|
||||
// If we're a nested command, we can ignore the current action.
|
||||
if (!nested)
|
||||
{
|
||||
if (const auto actionJson{ json[JsonKey(ActionKey)] })
|
||||
@@ -334,6 +318,7 @@ namespace winrt::TerminalApp::implementation
|
||||
{
|
||||
std::vector<winrt::hstring> commandsToRemove;
|
||||
std::vector<winrt::TerminalApp::Command> commandsToAdd;
|
||||
|
||||
// First, collect up all the commands that need replacing.
|
||||
for (auto nameAndCmd : commands)
|
||||
{
|
||||
@@ -361,6 +346,30 @@ namespace winrt::TerminalApp::implementation
|
||||
}
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
// - Initialize our ObservableVector of NestedCommands, recursively. This
|
||||
// will build the vector of nested Commands that XAML can access.
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// Return Value:
|
||||
// - <none>
|
||||
void Command::_createView()
|
||||
{
|
||||
_nestedCommandsView.Clear();
|
||||
|
||||
// Add all the commands we've parsed to the observable vector we
|
||||
// have, so we can access them in XAML.
|
||||
for (auto& nameAndCommand : _subcommands)
|
||||
{
|
||||
auto command = nameAndCommand.second;
|
||||
_nestedCommandsView.Append(command);
|
||||
|
||||
winrt::com_ptr<winrt::TerminalApp::implementation::Command> cmd;
|
||||
cmd.copy_from(winrt::get_self<winrt::TerminalApp::implementation::Command>(command));
|
||||
cmd->_createView();
|
||||
}
|
||||
}
|
||||
|
||||
// Function Description:
|
||||
// - Attempts to expand the given command into many commands, if the command
|
||||
// has `"iterateOn": "profiles"` set.
|
||||
@@ -392,6 +401,8 @@ namespace winrt::TerminalApp::implementation
|
||||
if (!expandable->_subcommands.empty())
|
||||
{
|
||||
ExpandCommands(expandable->_subcommands, profiles, warnings);
|
||||
|
||||
expandable->_createView();
|
||||
}
|
||||
|
||||
if (expandable->_IterateOn == ExpandCommandType::None)
|
||||
@@ -440,7 +451,7 @@ namespace winrt::TerminalApp::implementation
|
||||
}
|
||||
|
||||
// Pass the new json back though FromJson, to get the new expanded value.
|
||||
if (auto newCmd{ Command::FromJson(newJsonValue, warnings, true) })
|
||||
if (auto newCmd{ Command::FromJson(newJsonValue, warnings) })
|
||||
{
|
||||
newCommands.push_back(*newCmd);
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ namespace winrt::TerminalApp::implementation
|
||||
Command();
|
||||
|
||||
static winrt::com_ptr<Command> FromJson(const Json::Value& json,
|
||||
std::vector<::TerminalApp::SettingsLoadWarnings>& warnings,
|
||||
const bool postExpansion = false);
|
||||
std::vector<::TerminalApp::SettingsLoadWarnings>& warnings);
|
||||
|
||||
static void ExpandCommands(std::unordered_map<winrt::hstring, winrt::TerminalApp::Command>& commands,
|
||||
const std::vector<::TerminalApp::Profile>& profiles,
|
||||
@@ -69,6 +68,7 @@ namespace winrt::TerminalApp::implementation
|
||||
static std::vector<winrt::TerminalApp::Command> _expandCommand(winrt::com_ptr<Command> expandable,
|
||||
const std::vector<::TerminalApp::Profile>& profiles,
|
||||
std::vector<::TerminalApp::SettingsLoadWarnings>& warnings);
|
||||
void _createView();
|
||||
|
||||
friend class TerminalAppLocalTests::SettingsTests;
|
||||
friend class TerminalAppLocalTests::CommandTests;
|
||||
|
||||
@@ -176,6 +176,13 @@ namespace winrt::TerminalApp::implementation
|
||||
|
||||
void CommandPalette::_updateUIForStackChange()
|
||||
{
|
||||
if (_searchBox().Text().empty())
|
||||
{
|
||||
// Manually call _filterTextChanged, because setting the text to the
|
||||
// empty string won't update it for us (as it won't actually change value.)
|
||||
_filterTextChanged(nullptr, nullptr);
|
||||
}
|
||||
|
||||
_searchBox().Text(L"");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user