2021-08-29 14:18:45 +02:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2023-11-21 14:38:01 +01:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2023-11-30 14:40:07 +01:00
|
|
|
#include <hex/api/shortcut_manager.hpp>
|
2021-09-08 15:18:24 +02:00
|
|
|
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
#include <hex/helpers/fmt.hpp>
|
|
|
|
|
2023-12-01 14:07:10 +01:00
|
|
|
#include <wolv/math_eval/math_evaluator.hpp>
|
2023-07-09 12:53:31 +02:00
|
|
|
#include <wolv/utils/string.hpp>
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
void registerCommandPaletteCommands() {
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
ContentRegistry::CommandPaletteCommands::add(
|
2022-01-24 20:53:17 +01:00
|
|
|
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
|
2023-12-06 16:20:06 +01:00
|
|
|
"=",
|
2022-01-24 20:53:17 +01:00
|
|
|
"hex.builtin.command.calc.desc",
|
|
|
|
[](auto input) {
|
2023-12-01 14:07:10 +01:00
|
|
|
wolv::math_eval::MathEvaluator<long double> evaluator;
|
2022-01-24 20:53:17 +01:00
|
|
|
evaluator.registerStandardVariables();
|
|
|
|
evaluator.registerStandardFunctions();
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
std::optional<long double> result = evaluator.evaluate(input);
|
2022-01-24 20:53:17 +01:00
|
|
|
if (result.has_value())
|
2023-12-06 16:20:06 +01:00
|
|
|
return hex::format("{0} = {1}", input.data(), result.value());
|
2022-05-27 20:42:07 +02:00
|
|
|
else if (evaluator.hasError())
|
|
|
|
return hex::format("Error: {}", *evaluator.getLastError());
|
2022-01-24 20:53:17 +01:00
|
|
|
else
|
|
|
|
return std::string("???");
|
|
|
|
});
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
ContentRegistry::CommandPaletteCommands::add(
|
2022-01-24 20:53:17 +01:00
|
|
|
ContentRegistry::CommandPaletteCommands::Type::KeywordCommand,
|
|
|
|
"/web",
|
|
|
|
"hex.builtin.command.web.desc",
|
|
|
|
[](auto input) {
|
|
|
|
return hex::format("hex.builtin.command.web.result"_lang, input.data());
|
|
|
|
},
|
|
|
|
[](auto input) {
|
|
|
|
hex::openWebpage(input);
|
|
|
|
});
|
2021-02-08 19:56:04 +01:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
ContentRegistry::CommandPaletteCommands::add(
|
2022-01-24 20:53:17 +01:00
|
|
|
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
|
|
|
|
"$",
|
|
|
|
"hex.builtin.command.cmd.desc",
|
|
|
|
[](auto input) {
|
|
|
|
return hex::format("hex.builtin.command.cmd.result"_lang, input.data());
|
|
|
|
},
|
|
|
|
[](auto input) {
|
2023-10-21 20:40:24 +02:00
|
|
|
hex::executeCommand(input);
|
2022-01-24 20:53:17 +01:00
|
|
|
});
|
2023-03-20 14:11:43 +01:00
|
|
|
|
|
|
|
ContentRegistry::CommandPaletteCommands::addHandler(
|
|
|
|
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
|
|
|
|
">",
|
|
|
|
[](const auto &input) {
|
2023-03-21 15:33:43 +01:00
|
|
|
std::vector<ContentRegistry::CommandPaletteCommands::impl::QueryResult> result;
|
2023-03-20 14:11:43 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
for (const auto &[priority, entry] : ContentRegistry::Interface::impl::getMenuItems()) {
|
2023-03-20 14:11:43 +01:00
|
|
|
if (!entry.enabledCallback())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::vector<std::string> names;
|
2023-11-21 14:38:01 +01:00
|
|
|
std::transform(entry.unlocalizedNames.begin(), entry.unlocalizedNames.end(), std::back_inserter(names), [](auto &name) { return Lang(name); });
|
2023-03-20 14:11:43 +01:00
|
|
|
|
|
|
|
if (auto combined = wolv::util::combineStrings(names, " -> "); hex::containsIgnoreCase(combined, input) && !combined.contains(ContentRegistry::Interface::impl::SeparatorValue) && !combined.contains(ContentRegistry::Interface::impl::SubMenuValue)) {
|
2023-03-21 15:33:43 +01:00
|
|
|
result.emplace_back(ContentRegistry::CommandPaletteCommands::impl::QueryResult {
|
2023-03-20 14:11:43 +01:00
|
|
|
std::move(combined),
|
2023-11-18 14:34:33 +01:00
|
|
|
[&entry](const auto&) { entry.callback(); }
|
2023-03-20 14:11:43 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
[](auto input) {
|
|
|
|
return hex::format("Menu Item: {}", input.data());
|
|
|
|
});
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|