1 #pragma once 2 3 #include <hex.hpp> 4 #include <hex/views/view.hpp> 5 6 #include <imgui.h> 7 #include <hex/lang/pattern_data.hpp> 8 9 #include <vector> 10 #include <tuple> 11 #include <cstdio> 12 13 namespace hex { 14 15 namespace prv { class Provider; } 16 17 class ViewCommandPalette : public View { 18 public: 19 ViewCommandPalette(); 20 ~ViewCommandPalette() override; 21 22 void drawContent() override; 23 void drawMenu() override; isAvailable()24 bool isAvailable() override { return true; } shouldProcess()25 bool shouldProcess() override { return true; } 26 27 bool handleShortcut(int key, int mods) override; 28 hasViewMenuItemEntry()29 bool hasViewMenuItemEntry() override { return false; } getMinSize()30 ImVec2 getMinSize() override { return ImVec2(400, 100); } getMaxSize()31 ImVec2 getMaxSize() override { return ImVec2(400, 100); } 32 33 private: 34 enum class MatchType { 35 NoMatch, 36 InfoMatch, 37 PartialMatch, 38 PerfectMatch 39 }; 40 41 struct CommandResult { 42 std::string displayResult; 43 std::string matchedCommand; 44 std::function<void(std::string)> executeCallback; 45 }; 46 47 bool m_commandPaletteOpen = false; 48 bool m_justOpened = false; 49 bool m_focusInputTextBox = false; 50 51 std::vector<char> m_commandBuffer; 52 std::vector<CommandResult> m_lastResults; 53 std::string m_exactResult; 54 focusInputTextBox()55 void focusInputTextBox() { 56 this->m_focusInputTextBox = true; 57 } 58 59 std::vector<CommandResult> getCommandResults(std::string_view command); 60 }; 61 62 }