From 1b665fa1b37b06615111f4dbeaa655a106796826 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 27 Nov 2023 15:48:46 +0100 Subject: [PATCH] fix: Loading files into memory --- lib/libimhex/include/hex/providers/undo_redo/stack.hpp | 6 ++++++ .../builtin/source/content/providers/file_provider.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/libimhex/include/hex/providers/undo_redo/stack.hpp b/lib/libimhex/include/hex/providers/undo_redo/stack.hpp index 39021a549..3ab22cd2c 100644 --- a/lib/libimhex/include/hex/providers/undo_redo/stack.hpp +++ b/lib/libimhex/include/hex/providers/undo_redo/stack.hpp @@ -44,6 +44,12 @@ namespace hex::prv::undo { const std::vector> &getUndoneOperations() const { return this->m_redoStack; } + + void reset() { + this->m_undoStack.clear(); + this->m_redoStack.clear(); + } + private: [[nodiscard]] Operation* getLastOperation() const { return this->m_undoStack.back().get(); diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index 3007f964b..5d1d664ba 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -201,7 +201,7 @@ namespace hex::plugin::builtin { return { { "hex.builtin.provider.file.menu.open_folder"_lang, [this] { fs::openFolderWithSelectionExternal(this->m_path); } }, { "hex.builtin.provider.file.menu.open_file"_lang, [this] { fs::openFileExternal(this->m_path); } }, - { "hex.builtin.provider.file.menu.into_memory"_lang, [this] { this->convertToMemoryFile(); } } + { "hex.builtin.provider.file.menu.into_memory"_lang, [this] { this->convertToMemoryFile(); } } }; } @@ -313,7 +313,11 @@ namespace hex::plugin::builtin { } memoryProvider->markDirty(true); - ImHexApi::Provider::remove(this, false); + memoryProvider->getUndoStack().reset(); + + TaskManager::runWhenTasksFinished([this]{ + ImHexApi::Provider::remove(this, false); + }); }); } }