feat: Added all menu items to command palette

This commit is contained in:
WerWolv
2023-03-20 14:11:43 +01:00
parent 39e8d557e8
commit 6e23560e80
4 changed files with 81 additions and 0 deletions

View File

@@ -52,6 +52,34 @@ namespace hex::plugin::builtin {
[](auto input) {
hex::runCommand(input);
});
ContentRegistry::CommandPaletteCommands::addHandler(
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
">",
[](const auto &input) {
std::vector<ContentRegistry::CommandPaletteCommands::QueryResult> result;
for (const auto &[priority, entry] : ContentRegistry::Interface::getMenuItems()) {
if (!entry.enabledCallback())
continue;
std::vector<std::string> names;
std::transform(entry.unlocalizedNames.begin(), entry.unlocalizedNames.end(), std::back_inserter(names), [](auto &name) { return LangEntry(name); });
if (auto combined = wolv::util::combineStrings(names, " -> "); hex::containsIgnoreCase(combined, input) && !combined.contains(ContentRegistry::Interface::impl::SeparatorValue) && !combined.contains(ContentRegistry::Interface::impl::SubMenuValue)) {
result.emplace_back(ContentRegistry::CommandPaletteCommands::QueryResult {
std::move(combined),
[entry](const auto&) { entry.callback(); }
});
}
}
return result;
},
[](auto input) {
return hex::format("Menu Item: {}", input.data());
});
}
}

View File

@@ -122,6 +122,26 @@ namespace hex::plugin::builtin {
}
}
for (const auto &handler : ContentRegistry::CommandPaletteCommands::getHandlers()) {
const auto &[type, command, queryCallback, displayCallback] = handler;
auto processedInput = input;
if (processedInput.starts_with(command))
processedInput = processedInput.substr(command.length());
for (const auto &[description, callback] : queryCallback(processedInput)) {
if (type == ContentRegistry::CommandPaletteCommands::Type::SymbolCommand) {
if (auto [match, value] = MatchCommand(input, command); match != MatchType::NoMatch) {
results.push_back({ hex::format("{} ({})", command, description), "", callback });
}
} else if (type == ContentRegistry::CommandPaletteCommands::Type::KeywordCommand) {
if (auto [match, value] = MatchCommand(input, command + " "); match != MatchType::NoMatch) {
results.push_back({ hex::format("{} ({})", command, description), "", callback });
}
}
}
}
return results;
}