mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
feat: Added all menu items to command palette
This commit is contained in:
@@ -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());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user