From 8aa4402f884ceec3600b1745ac1aa107014f0526 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 13 Nov 2020 13:06:22 +0100 Subject: [PATCH] Don't show pattern editor when no file is loaded --- include/views/view_pattern.hpp | 8 ++++++-- source/main.cpp | 2 +- source/views/view_pattern.cpp | 30 +++++++++++++++++------------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/views/view_pattern.hpp b/include/views/view_pattern.hpp index aeeac61b5..d341e28fb 100644 --- a/include/views/view_pattern.hpp +++ b/include/views/view_pattern.hpp @@ -3,12 +3,15 @@ #include "parser/ast_node.hpp" #include "parser/parser.hpp" #include "parser/lexer.hpp" + #include "views/view.hpp" +#include "views/highlight.hpp" + +#include "providers/provider.hpp" #include #include -#include "views/highlight.hpp" #include "imfilebrowser.h" @@ -16,7 +19,7 @@ namespace hex { class ViewPattern : public View { public: - explicit ViewPattern(std::vector &highlights); + explicit ViewPattern(prv::Provider* &dataProvider, std::vector &highlights); ~ViewPattern() override; void createMenu() override; @@ -26,6 +29,7 @@ namespace hex { char *m_buffer; std::vector &m_highlights; + prv::Provider* &m_dataProvider; bool m_windowOpen = true; ImGui::FileBrowser m_fileBrowser; diff --git a/source/main.cpp b/source/main.cpp index 01b270805..3c56b53a6 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -20,7 +20,7 @@ int main() { // Create views window.addView(dataProvider, highlights); - window.addView(highlights); + window.addView(dataProvider, highlights); window.addView(dataProvider, highlights); window.addView(dataProvider); window.addView(dataProvider); diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index 0b516f88b..73c4f0ccb 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -5,7 +5,8 @@ namespace hex { - ViewPattern::ViewPattern(std::vector &highlights) : View(), m_highlights(highlights) { + ViewPattern::ViewPattern(prv::Provider* &dataProvider, std::vector &highlights) + : View(), m_dataProvider(dataProvider), m_highlights(highlights) { this->m_buffer = new char[0xFFFFFF]; std::memset(this->m_buffer, 0x00, 0xFFFFFF); } @@ -34,22 +35,25 @@ namespace hex { return; if (ImGui::Begin("Pattern", &this->m_windowOpen, ImGuiWindowFlags_None)) { - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + if (this->m_dataProvider != nullptr && this->m_dataProvider->isReadable()) { + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); - auto size = ImGui::GetWindowSize(); - size.y -= 50; - ImGui::InputTextMultiline("Pattern", this->m_buffer, 0xFFFF, size, ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_CallbackEdit, - [](ImGuiInputTextCallbackData* data) -> int { - auto _this = static_cast(data->UserData); + auto size = ImGui::GetWindowSize(); + size.y -= 50; + ImGui::InputTextMultiline("Pattern", this->m_buffer, 0xFFFF, size, + ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_CallbackEdit, + [](ImGuiInputTextCallbackData *data) -> int { + auto _this = static_cast(data->UserData); - _this->parsePattern(data->Buf); + _this->parsePattern(data->Buf); - return 0; - }, this - ); + return 0; + }, this + ); - ImGui::PopStyleVar(2); + ImGui::PopStyleVar(2); + } } ImGui::End();