2020-12-16 22:43:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/views/view.hpp>
|
2020-12-16 22:43:07 +01:00
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <imgui.h>
|
2020-12-16 22:43:07 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <tuple>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
namespace hex::plugin::builtin {
|
2020-12-16 22:43:07 +01:00
|
|
|
|
|
|
|
namespace prv { class Provider; }
|
|
|
|
|
|
|
|
class ViewCommandPalette : public View {
|
|
|
|
public:
|
|
|
|
ViewCommandPalette();
|
|
|
|
~ViewCommandPalette() override;
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void drawContent() override;
|
|
|
|
void drawMenu() override;
|
2021-01-27 14:26:24 +01:00
|
|
|
bool isAvailable() override { return true; }
|
2021-02-08 19:56:04 +01:00
|
|
|
bool shouldProcess() override { return true; }
|
2020-12-16 22:43:07 +01:00
|
|
|
|
2021-04-16 19:43:54 +02:00
|
|
|
bool handleShortcut(bool keys[512], bool ctrl, bool shift, bool alt) override;
|
2020-12-16 22:43:07 +01:00
|
|
|
|
|
|
|
bool hasViewMenuItemEntry() override { return false; }
|
|
|
|
ImVec2 getMinSize() override { return ImVec2(400, 100); }
|
|
|
|
ImVec2 getMaxSize() override { return ImVec2(400, 100); }
|
|
|
|
|
|
|
|
private:
|
2021-02-08 19:56:04 +01:00
|
|
|
enum class MatchType {
|
|
|
|
NoMatch,
|
|
|
|
InfoMatch,
|
|
|
|
PartialMatch,
|
|
|
|
PerfectMatch
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CommandResult {
|
|
|
|
std::string displayResult;
|
|
|
|
std::string matchedCommand;
|
|
|
|
std::function<void(std::string)> executeCallback;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool m_commandPaletteOpen = false;
|
2020-12-16 22:43:07 +01:00
|
|
|
bool m_justOpened = false;
|
2021-02-08 19:56:04 +01:00
|
|
|
bool m_focusInputTextBox = false;
|
|
|
|
|
2020-12-16 22:43:07 +01:00
|
|
|
std::vector<char> m_commandBuffer;
|
2021-02-08 19:56:04 +01:00
|
|
|
std::vector<CommandResult> m_lastResults;
|
2020-12-16 22:43:07 +01:00
|
|
|
std::string m_exactResult;
|
|
|
|
|
2021-02-08 19:56:04 +01:00
|
|
|
void focusInputTextBox() {
|
|
|
|
this->m_focusInputTextBox = true;
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
std::vector<CommandResult> getCommandResults(const std::string &command);
|
2020-12-16 22:43:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|