feat: Expose tools through the command palette

This commit is contained in:
WerWolv
2025-08-15 17:30:48 +02:00
parent f921742dcc
commit ec2a01dfae

View File

@@ -1,6 +1,7 @@
#include <hex/api/imhex_api/hex_editor.hpp>
#include <hex/api/localization_manager.hpp>
#include <hex/api/content_registry/command_palette.hpp>
#include <hex/api/content_registry/tools.hpp>
#include <hex/api/content_registry/settings.hpp>
#include <hex/api/content_registry/user_interface.hpp>
#include <hex/api/content_registry/views.hpp>
@@ -441,6 +442,27 @@ namespace hex::plugin::builtin {
return fmt::format("Focus {} View", input.data());
});
ContentRegistry::CommandPalette::addHandler(
ContentRegistry::CommandPalette::Type::KeywordCommand,
"/tool",
[](const auto &input) {
std::vector<ContentRegistry::CommandPalette::impl::QueryResult> result;
for (const auto &toolEntry : ContentRegistry::Tools::impl::getEntries()) {
const auto name = Lang(toolEntry.unlocalizedName);
if (!hex::containsIgnoreCase(name, input) && !std::string("/tool").contains(input))
continue;
result.emplace_back(name, [&toolEntry](const auto &) {
ContentRegistry::CommandPalette::setDisplayedContent([&toolEntry](const auto) {
toolEntry.function();
});
});
}
return result;
},
[](const auto &input) { return input; });
}
}