mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 21:05:56 -05:00
impr: Make long running tasks not freeze ImHex, fix saving non-continuous providers
Fixes #1454
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex/ui/popup.hpp>
|
||||
|
||||
#include <hex/api/localization_manager.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
class PopupBlockingTask : public Popup<PopupBlockingTask> {
|
||||
public:
|
||||
PopupBlockingTask(TaskHolder &&task) : hex::Popup<PopupBlockingTask>("hex.builtin.popup.blocking_task.title", false), m_task(std::move(task)) { }
|
||||
|
||||
void drawContent() override {
|
||||
ImGui::TextUnformatted("hex.builtin.popup.blocking_task.desc"_lang);
|
||||
ImGui::Separator();
|
||||
|
||||
if (this->m_task.getProgress() == 0)
|
||||
ImGuiExt::TextSpinner("");
|
||||
else
|
||||
ImGui::ProgressBar(this->m_task.getProgress() / 100.0F);
|
||||
|
||||
ImGui::NewLine();
|
||||
if (ImGui::ButtonEx("hex.builtin.common.cancel"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0)) || ImGui::IsKeyDown(ImGuiKey_Escape))
|
||||
this->m_task.interrupt();
|
||||
|
||||
if (!this->m_task.isRunning()) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] ImGuiWindowFlags getFlags() const override {
|
||||
return ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove;
|
||||
}
|
||||
|
||||
private:
|
||||
TaskHolder m_task;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -490,6 +490,8 @@
|
||||
"hex.builtin.popup.exit_application.desc": "You have unsaved changes made to your Project.\nAre you sure you want to exit?",
|
||||
"hex.builtin.popup.exit_application.title": "Exit Application?",
|
||||
"hex.builtin.popup.waiting_for_tasks.title": "Waiting for Tasks",
|
||||
"hex.builtin.popup.blocking_task.title": "Running Task",
|
||||
"hex.builtin.popup.blocking_task.desc": "A task is currently executing.",
|
||||
"hex.builtin.popup.save_layout.title": "Save Layout",
|
||||
"hex.builtin.popup.save_layout.desc": "Enter a name under which to save the current layout.",
|
||||
"hex.builtin.popup.waiting_for_tasks.desc": "There are still tasks running in the background.\nImHex will close after they are finished.",
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <content/popups/popup_file_chooser.hpp>
|
||||
|
||||
#include <imgui_internal.h>
|
||||
#include <content/popups/popup_blocking_task.hpp>
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
@@ -692,7 +693,10 @@ namespace hex::plugin::builtin {
|
||||
|
||||
static void saveAs() {
|
||||
fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) {
|
||||
ImHexApi::Provider::get()->saveAs(path);
|
||||
auto provider = ImHexApi::Provider::get();
|
||||
PopupBlockingTask::open(TaskManager::createTask("Saving...", TaskManager::NoProgress, [=](Task &){
|
||||
provider->saveAs(path);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -759,8 +759,8 @@ namespace hex::plugin::builtin::ui {
|
||||
ImGuiExt::TextFormatted("{}:", "hex.builtin.hex_editor.data_size"_lang);
|
||||
ImGui::SameLine();
|
||||
ImGuiExt::TextFormattedSelectable("0x{0:08X} (0x{1:X} | {2})",
|
||||
this->m_provider->getActualSize(),
|
||||
this->m_provider->getActualSize(),
|
||||
this->m_provider->getBaseAddress(),
|
||||
this->m_provider->getBaseAddress() + this->m_provider->getActualSize(),
|
||||
this->m_showHumanReadableUnits
|
||||
? hex::toByteString(this->m_provider->getActualSize())
|
||||
: hex::format("{}", this->m_provider->getActualSize())
|
||||
|
||||
Reference in New Issue
Block a user