From 2d9285819306904502f32a179073973c2af38dc1 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 21 Jan 2024 21:29:03 +0100 Subject: [PATCH] feat: Allow switching to other providers through command palette --- .../content/command_palette_commands.cpp | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index 8b63dd864..a0d207cb2 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -1,12 +1,15 @@ #include +#include #include #include #include #include +#include #include +#include #include namespace hex::plugin::builtin { @@ -312,6 +315,32 @@ namespace hex::plugin::builtin { return hex::format("Menu Item: {}", input.data()); }); + ContentRegistry::CommandPaletteCommands::addHandler( + ContentRegistry::CommandPaletteCommands::Type::SymbolCommand, + ".", + [](const auto &input) { + std::vector result; + + u32 index = 0; + for (const auto &provider : ImHexApi::Provider::getProviders()) { + ON_SCOPE_EXIT { index += 1; }; + + auto name = provider->getName(); + if (!hex::containsIgnoreCase(name, input)) + continue; + + result.emplace_back(ContentRegistry::CommandPaletteCommands::impl::QueryResult { + provider->getName(), + [&provider, index](const auto&) { ImHexApi::Provider::setCurrentProvider(index); } + }); + } + + return result; + }, + [](auto input) { + return hex::format("Provider: {}", input.data()); + }); + ContentRegistry::CommandPaletteCommands::add( ContentRegistry::CommandPaletteCommands::Type::SymbolCommand, "%",