1
0
mirror of synced 2025-01-18 09:04:52 +01:00

Don't show pattern editor when no file is loaded

This commit is contained in:
WerWolv 2020-11-13 13:06:22 +01:00
parent 295b32b890
commit 8aa4402f88
3 changed files with 24 additions and 16 deletions

View File

@ -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 <concepts>
#include <cstring>
#include "views/highlight.hpp"
#include "imfilebrowser.h"
@ -16,7 +19,7 @@ namespace hex {
class ViewPattern : public View {
public:
explicit ViewPattern(std::vector<Highlight> &highlights);
explicit ViewPattern(prv::Provider* &dataProvider, std::vector<Highlight> &highlights);
~ViewPattern() override;
void createMenu() override;
@ -26,6 +29,7 @@ namespace hex {
char *m_buffer;
std::vector<Highlight> &m_highlights;
prv::Provider* &m_dataProvider;
bool m_windowOpen = true;
ImGui::FileBrowser m_fileBrowser;

View File

@ -20,7 +20,7 @@ int main() {
// Create views
window.addView<hex::ViewHexEditor>(dataProvider, highlights);
window.addView<hex::ViewPattern>(highlights);
window.addView<hex::ViewPattern>(dataProvider, highlights);
window.addView<hex::ViewPatternData>(dataProvider, highlights);
window.addView<hex::ViewHashes>(dataProvider);
window.addView<hex::ViewInformation>(dataProvider);

View File

@ -5,7 +5,8 @@
namespace hex {
ViewPattern::ViewPattern(std::vector<Highlight> &highlights) : View(), m_highlights(highlights) {
ViewPattern::ViewPattern(prv::Provider* &dataProvider, std::vector<Highlight> &highlights)
: View(), m_dataProvider(dataProvider), m_highlights(highlights) {
this->m_buffer = new char[0xFFFFFF];
std::memset(this->m_buffer, 0x00, 0xFFFFFF);
}
@ -34,12 +35,14 @@ namespace hex {
return;
if (ImGui::Begin("Pattern", &this->m_windowOpen, ImGuiWindowFlags_None)) {
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,
ImGui::InputTextMultiline("Pattern", this->m_buffer, 0xFFFF, size,
ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_CallbackEdit,
[](ImGuiInputTextCallbackData *data) -> int {
auto _this = static_cast<ViewPattern *>(data->UserData);
@ -51,6 +54,7 @@ namespace hex {
ImGui::PopStyleVar(2);
}
}
ImGui::End();
this->m_fileBrowser.Display();