mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-27 23:37:05 -05:00
feat: Add Open Source File option to custom data inspector rows
This commit is contained in:
@@ -56,7 +56,7 @@ namespace hex::plugin::builtin {
|
||||
void drawInspectorRows();
|
||||
void drawInspectorRow(InspectorCacheEntry& entry);
|
||||
|
||||
ContentRegistry::DataInspector::impl::DisplayFunction createPatternErrorDisplayFunction();
|
||||
ContentRegistry::DataInspector::impl::DisplayFunction createPatternErrorDisplayFunction(const std::fs::path &path);
|
||||
|
||||
private:
|
||||
bool m_shouldInvalidate = true;
|
||||
|
||||
@@ -781,6 +781,7 @@
|
||||
"hex.builtin.view.data_inspector.custom_row.title": "Adding custom rows",
|
||||
"hex.builtin.view.data_inspector.custom_row.hint": "It's possible to define custom data inspector rows by placing pattern language scripts in the <ImHex>/scripts/inspectors folder.\n\nCheck the documentation for more information.",
|
||||
"hex.builtin.view.data_inspector.toggle_endianness": "Toggle Endianness",
|
||||
"hex.builtin.view.data_inspector.open_pattern": "Open Source File",
|
||||
"hex.builtin.view.data_processor.continuous_evaluation": "Continuous Evaluation",
|
||||
"hex.builtin.view.data_processor.help_text": "Right click to add a new node",
|
||||
"hex.builtin.view.data_processor.menu.file.load_processor": "Load data processor...",
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace hex::plugin::builtin {
|
||||
void ViewDataInspector::executeInspector(const std::string& code, const std::fs::path& path, const std::map<std::string, pl::core::Token::Literal>& inVariables) {
|
||||
if (m_runtime.executeString(code, pl::api::Source::DefaultSource, {}, inVariables, true) != 0) {
|
||||
|
||||
auto displayFunction = createPatternErrorDisplayFunction();
|
||||
auto displayFunction = createPatternErrorDisplayFunction(path);
|
||||
|
||||
// Insert the inspector containing the error message into the list
|
||||
m_workData.emplace_back(
|
||||
@@ -226,7 +226,13 @@ namespace hex::plugin::builtin {
|
||||
|
||||
try {
|
||||
// Set up the display function using the pattern's formatter
|
||||
auto displayFunction = [pattern,value = pattern->getFormattedValue()] {
|
||||
auto displayFunction = [pattern, value = pattern->getFormattedValue(), path] {
|
||||
ContentRegistry::DataInspector::drawMenuItems([&] {
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.data_inspector.open_pattern"_lang, ICON_VS_FOLDER_OPENED)) {
|
||||
fs::openFileExternal(path);
|
||||
}
|
||||
});
|
||||
|
||||
auto drawer = ui::VisualizerDrawer();
|
||||
if (const auto &inlineVisualizeArgs = pattern->getAttributeArguments("hex::inline_visualize"); !inlineVisualizeArgs.empty()) {
|
||||
drawer.drawVisualizer(ContentRegistry::PatternLanguage::impl::getInlineVisualizers(), inlineVisualizeArgs, *pattern, true);
|
||||
@@ -603,7 +609,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
}
|
||||
|
||||
ContentRegistry::DataInspector::impl::DisplayFunction ViewDataInspector::createPatternErrorDisplayFunction() {
|
||||
ContentRegistry::DataInspector::impl::DisplayFunction ViewDataInspector::createPatternErrorDisplayFunction(const std::fs::path &path) {
|
||||
// Generate error message
|
||||
std::string errorMessage;
|
||||
if (const auto &compileErrors = m_runtime.getCompileErrors(); !compileErrors.empty()) {
|
||||
@@ -615,7 +621,13 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
// Create a dummy display function that displays the error message
|
||||
auto displayFunction = [errorMessage = std::move(errorMessage)] {
|
||||
auto displayFunction = [errorMessage = std::move(errorMessage), path] {
|
||||
ContentRegistry::DataInspector::drawMenuItems([&, path] {
|
||||
if (ImGui::MenuItemEx("hex.builtin.view.data_inspector.open_pattern"_lang, ICON_VS_FOLDER_OPENED)) {
|
||||
fs::openFileExternal(path);
|
||||
}
|
||||
});
|
||||
|
||||
ImGuiExt::HelpHover(
|
||||
errorMessage.c_str(),
|
||||
"hex.builtin.view.data_inspector.execution_error"_lang,
|
||||
|
||||
Reference in New Issue
Block a user