diff --git a/include/views/view.hpp b/include/views/view.hpp index 4c502e10b..2b9892e48 100644 --- a/include/views/view.hpp +++ b/include/views/view.hpp @@ -30,6 +30,28 @@ namespace hex { View::s_eventManager.post(eventType, userData); } + static void drawCommonInterfaces() { + if (ImGui::BeginPopupModal("Error", nullptr, ImGuiWindowFlags_NoResize)) { + ImGui::NewLine(); + if (ImGui::BeginChild("##scrolling", ImVec2(300, 100))) { + ImGui::SetCursorPosX((300 - ImGui::CalcTextSize(View::s_errorMessage.c_str(), nullptr, false).x) / 2.0F); + ImGui::TextWrapped("%s", View::s_errorMessage.c_str()); + ImGui::EndChild(); + } + ImGui::NewLine(); + ImGui::SetCursorPosX(75); + if (ImGui::Button("Okay", ImVec2(150, 20))) + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); + } + } + + static void showErrorPopup(std::string_view errorMessage) { + View::s_errorMessage = errorMessage; + + ImGui::OpenPopup("Error"); + } + bool& getWindowOpenState() { return this->m_windowOpen; } @@ -59,6 +81,8 @@ namespace hex { static inline EventManager s_eventManager; static inline std::vector> s_deferedCalls; + + static inline std::string s_errorMessage; }; } \ No newline at end of file diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index ae36e80bb..42e51005a 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -262,6 +262,7 @@ namespace hex { this->m_dataProvider = new prv::FileProvider(path); this->m_memoryEditor.ReadOnly = !this->m_dataProvider->isWritable(); + View::postEvent(Events::FileLoaded); View::postEvent(Events::DataChanged); } diff --git a/source/window.cpp b/source/window.cpp index 629e3bea1..5d05c7211 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -88,6 +88,8 @@ namespace hex { view->createView(); } + View::drawCommonInterfaces(); + #ifdef DEBUG if (this->m_demoWindowOpen) ImGui::ShowDemoWindow(&this->m_demoWindowOpen);