Made tools registry more in-line with the other APIs
This commit is contained in:
parent
95437b2afe
commit
0e32dd667d
@ -110,9 +110,14 @@ namespace hex {
|
||||
struct Tools {
|
||||
Tools() = delete;
|
||||
|
||||
static void add(const std::function<void()> &function);
|
||||
struct Entry {
|
||||
std::string name;
|
||||
std::function<void()> function;
|
||||
};
|
||||
|
||||
static std::vector<std::function<void()>>& getEntries();
|
||||
static void add(std::string_view name, const std::function<void()> &function);
|
||||
|
||||
static std::vector<Entry>& getEntries();
|
||||
};
|
||||
|
||||
/* Data Inspector Registry. Allows adding of new types to the data inspector */
|
||||
|
@ -51,7 +51,7 @@ namespace hex {
|
||||
static std::vector<ContentRegistry::CommandPaletteCommands::Entry> commandPaletteCommands;
|
||||
static std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> patternLanguageFunctions;
|
||||
static std::vector<View*> views;
|
||||
static std::vector<std::function<void()>> toolsEntries;
|
||||
static std::vector<ContentRegistry::Tools::Entry> toolsEntries;
|
||||
static std::vector<ContentRegistry::DataInspector::Entry> dataInspectorEntries;
|
||||
|
||||
static int mainArgc;
|
||||
|
@ -102,11 +102,11 @@ namespace hex {
|
||||
|
||||
/* Tools */
|
||||
|
||||
void ContentRegistry::Tools::add(const std::function<void()> &function) {
|
||||
getEntries().push_back(function);
|
||||
void ContentRegistry::Tools::add(std::string_view name, const std::function<void()> &function) {
|
||||
getEntries().emplace_back(Entry{ name.data(), function });
|
||||
}
|
||||
|
||||
std::vector<std::function<void()>>& ContentRegistry::Tools::getEntries() {
|
||||
std::vector<ContentRegistry::Tools::Entry>& ContentRegistry::Tools::getEntries() {
|
||||
return SharedData::toolsEntries;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace hex {
|
||||
std::vector<ContentRegistry::CommandPaletteCommands::Entry> SharedData::commandPaletteCommands;
|
||||
std::map<std::string, ContentRegistry::PatternLanguageFunctions::Function> SharedData::patternLanguageFunctions;
|
||||
std::vector<View*> SharedData::views;
|
||||
std::vector<std::function<void()>> SharedData::toolsEntries;
|
||||
std::vector<ContentRegistry::Tools::Entry> SharedData::toolsEntries;
|
||||
std::vector<ContentRegistry::DataInspector::Entry> SharedData::dataInspectorEntries;
|
||||
|
||||
int SharedData::mainArgc;
|
||||
|
@ -64,6 +64,12 @@ namespace hex {
|
||||
|
||||
return { };
|
||||
}, 2, 2);
|
||||
|
||||
ContentRegistry::Tools::add("Itanium/MSVC demangler", [this]{ this->drawDemangler(); });
|
||||
ContentRegistry::Tools::add("ASCII table", [this]{ this->drawASCIITable(); });
|
||||
ContentRegistry::Tools::add("Regex replacer", [this]{ this->drawRegexReplacer(); });
|
||||
ContentRegistry::Tools::add("Color picker", [this]{ this->drawColorPicker(); });
|
||||
ContentRegistry::Tools::add("Calculator", [this]{ this->drawMathEvaluator(); });
|
||||
}
|
||||
|
||||
ViewTools::~ViewTools() {
|
||||
@ -77,7 +83,6 @@ namespace hex {
|
||||
}
|
||||
|
||||
void ViewTools::drawDemangler() {
|
||||
if (ImGui::CollapsingHeader("Itanium/MSVC demangler")) {
|
||||
if (ImGui::InputText("Mangled name", this->m_mangledBuffer, 0xF'FFFF)) {
|
||||
this->m_demangledName = llvm::demangle(this->m_mangledBuffer);
|
||||
}
|
||||
@ -85,10 +90,8 @@ namespace hex {
|
||||
ImGui::InputText("Demangled name", this->m_demangledName.data(), this->m_demangledName.size(), ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::NewLine();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewTools::drawASCIITable() {
|
||||
if (ImGui::CollapsingHeader("ASCII table")) {
|
||||
ImGui::BeginTable("##asciitable", 4);
|
||||
ImGui::TableSetupColumn("");
|
||||
ImGui::TableSetupColumn("");
|
||||
@ -138,10 +141,8 @@ namespace hex {
|
||||
ImGui::Checkbox("Show octal", &this->m_asciiTableShowOctal);
|
||||
ImGui::NewLine();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewTools::drawRegexReplacer() {
|
||||
if (ImGui::CollapsingHeader("Regex replacer")) {
|
||||
bool shouldInvalidate;
|
||||
|
||||
shouldInvalidate = ImGui::InputText("Regex pattern", this->m_regexPattern, 0xF'FFFF);
|
||||
@ -156,22 +157,16 @@ namespace hex {
|
||||
|
||||
ImGui::InputTextMultiline("Output", this->m_regexOutput.data(), this->m_regexOutput.size(), ImVec2(0, 0), ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::NewLine();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ViewTools::drawColorPicker() {
|
||||
if (ImGui::CollapsingHeader("Color picker")) {
|
||||
ImGui::SetNextItemWidth(300.0F);
|
||||
ImGui::ColorPicker4("Color Picker", this->m_pickedColor.data(),
|
||||
ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHex);
|
||||
ImGui::NewLine();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewTools::drawMathEvaluator() {
|
||||
if (ImGui::CollapsingHeader("Calculator")) {
|
||||
if (ImGui::InputText("Input", this->m_mathInput, 0xFFFF, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
std::optional<long double> result;
|
||||
@ -300,22 +295,15 @@ namespace hex {
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ViewTools::drawContent() {
|
||||
if (ImGui::Begin("Tools", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
||||
|
||||
this->drawDemangler();
|
||||
this->drawASCIITable();
|
||||
this->drawRegexReplacer();
|
||||
this->drawMathEvaluator();
|
||||
this->drawColorPicker();
|
||||
|
||||
for (const auto& entries : ContentRegistry::Tools::getEntries())
|
||||
entries();
|
||||
|
||||
for (const auto& [name, function] : ContentRegistry::Tools::getEntries()) {
|
||||
if (ImGui::CollapsingHeader(name.c_str())) {
|
||||
function();
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user