From d3a227d0bcbb9506222790ce7cd2410ca8b91824 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 22 Aug 2021 21:43:31 +0200 Subject: [PATCH] sys: Fixed open webpage command, added run command --- .../content/command_palette_commands.cpp | 10 ++++++++ .../libimhex/include/hex/helpers/utils.hpp | 3 ++- plugins/libimhex/source/helpers/utils.cpp | 25 ++++++++++++++++--- source/views/view_command_palette.cpp | 2 +- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index ba765dcfa..4412c4988 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -37,6 +37,16 @@ namespace hex::plugin::builtin { hex::openWebpage(input); }); + hex::ContentRegistry::CommandPaletteCommands::add( + hex::ContentRegistry::CommandPaletteCommands::Type::SymbolCommand, + "$", "hex.builtin.command.cmd.desc", + [](auto input) { + return hex::format("hex.builtin.command.cmd.result"_lang, input.data()); + }, + [](auto input) { + hex::runCommand(input); + }); + } } \ No newline at end of file diff --git a/plugins/libimhex/include/hex/helpers/utils.hpp b/plugins/libimhex/include/hex/helpers/utils.hpp index 7a1cb88bf..6f2211fab 100644 --- a/plugins/libimhex/include/hex/helpers/utils.hpp +++ b/plugins/libimhex/include/hex/helpers/utils.hpp @@ -181,7 +181,8 @@ namespace hex { std::string toByteString(u64 bytes); std::string makePrintable(char c); - void openWebpage(std::string_view url); + void runCommand(const std::string &command); + void openWebpage(std::string url); template inline std::string format(std::string_view format, Args ... args) { diff --git a/plugins/libimhex/source/helpers/utils.cpp b/plugins/libimhex/source/helpers/utils.cpp index 03aa0a1e8..edcbe305a 100644 --- a/plugins/libimhex/source/helpers/utils.cpp +++ b/plugins/libimhex/source/helpers/utils.cpp @@ -175,14 +175,31 @@ namespace hex { return result; } - void openWebpage(std::string_view url) { + void runCommand(const std::string &command) { #if defined(OS_WINDOWS) - system(hex::format("start {0}", url.data()).c_str()); + system(hex::format("start {0}", command).c_str()); #elif defined(OS_MACOS) - system(hex::format("open {0}", url.data()).c_str()); + system(hex::format("open {0}", command).c_str()); #elif defined(OS_LINUX) - system(hex::format("xdg-open {0}", url.data()).c_str()); + system(hex::format("xdg-open {0}", command).c_str()); + #else + #warning "Unknown OS, can't open webpages" + #endif + + } + + void openWebpage(std::string url) { + + if (!url.starts_with("http://") && !url.starts_with("https://")) + url = "https://" + url; + + #if defined(OS_WINDOWS) + system(hex::format("start {0}", url).c_str()); + #elif defined(OS_MACOS) + system(hex::format("open {0}", url).c_str()); + #elif defined(OS_LINUX) + system(hex::format("xdg-open {0}", url).c_str()); #else #warning "Unknown OS, can't open webpages" #endif diff --git a/source/views/view_command_palette.cpp b/source/views/view_command_palette.cpp index da592f825..bbfd954a5 100644 --- a/source/views/view_command_palette.cpp +++ b/source/views/view_command_palette.cpp @@ -22,7 +22,7 @@ namespace hex { ImGui::CloseCurrentPopup(); ImGui::PushItemWidth(-1); - if (ImGui::InputText("##nolabel", this->m_commandBuffer.data(), this->m_commandBuffer.size(), ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_EnterReturnsTrue, + if (ImGui::InputText("##command_input", this->m_commandBuffer.data(), this->m_commandBuffer.size(), ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_EnterReturnsTrue, [](ImGuiInputTextCallbackData *callbackData) -> int { auto _this = static_cast(callbackData->UserData); _this->m_lastResults = _this->getCommandResults(callbackData->Buf);