diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 706a76f28..e1a524490 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -226,6 +226,9 @@ namespace hex { } void setCurrentProvider(u32 index) { + if (Task::getRunningTaskCount() > 0) + return; + if (index < s_providers.size()) { auto oldProvider = get(); s_currentProvider = index; @@ -238,6 +241,9 @@ namespace hex { } void add(prv::Provider *provider) { + if (Task::getRunningTaskCount() > 0) + return; + s_providers.push_back(provider); setCurrentProvider(s_providers.size() - 1); @@ -245,6 +251,9 @@ namespace hex { } void remove(prv::Provider *provider) { + if (Task::getRunningTaskCount() > 0) + return; + auto it = std::find(s_providers.begin(), s_providers.end(), provider); s_providers.erase(it); diff --git a/plugins/builtin/source/content/main_menu_items.cpp b/plugins/builtin/source/content/main_menu_items.cpp index b975cebf2..f141b3bf6 100644 --- a/plugins/builtin/source/content/main_menu_items.cpp +++ b/plugins/builtin/source/content/main_menu_items.cpp @@ -15,17 +15,20 @@ namespace hex::plugin::builtin { static bool g_demoWindowOpen = false; static void createFileMenu() { + ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.file", 1000); ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1050, [&] { - if (ImGui::MenuItem("hex.builtin.menu.file.open_file"_lang, "CTRL + O")) { + bool taskRunning = Task::getRunningTaskCount() > 0; + + if (ImGui::MenuItem("hex.builtin.menu.file.open_file"_lang, "CTRL + O", false, !taskRunning)) { fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { EventManager::post(path); }); } - if (ImGui::BeginMenu("hex.builtin.menu.file.open_other"_lang)) { + if (ImGui::BeginMenu("hex.builtin.menu.file.open_other"_lang, !taskRunning)) { for (const auto &unlocalizedProviderName : ContentRegistry::Provider::getEntries()) { if (ImGui::MenuItem(LangEntry(unlocalizedProviderName))) { @@ -40,13 +43,14 @@ namespace hex::plugin::builtin { /* File open, quit imhex */ ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1150, [&] { bool providerValid = ImHexApi::Provider::isValid(); + bool taskRunning = Task::getRunningTaskCount() > 0; - if (ImGui::MenuItem("hex.builtin.menu.file.close"_lang, "", false, providerValid)) { + if (ImGui::MenuItem("hex.builtin.menu.file.close"_lang, "", false, providerValid && !taskRunning)) { EventManager::post(); ImHexApi::Provider::remove(ImHexApi::Provider::get()); } - if (ImGui::MenuItem("hex.builtin.menu.file.quit"_lang, "", false)) { + if (ImGui::MenuItem("hex.builtin.menu.file.quit"_lang)) { ImHexApi::Common::closeImHex(); } }); @@ -55,8 +59,9 @@ namespace hex::plugin::builtin { ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1250, [&] { auto provider = ImHexApi::Provider::get(); bool providerValid = ImHexApi::Provider::isValid(); + bool taskRunning = Task::getRunningTaskCount() > 0; - if (ImGui::MenuItem("hex.builtin.menu.file.open_project"_lang, "")) { + if (ImGui::MenuItem("hex.builtin.menu.file.open_project"_lang, "", false, !taskRunning)) { fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"} }, [](const auto &path) { @@ -84,9 +89,10 @@ namespace hex::plugin::builtin { ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1300, [&] { auto provider = ImHexApi::Provider::get(); bool providerValid = ImHexApi::Provider::isValid(); + bool taskRunning = Task::getRunningTaskCount() > 0; /* Import */ - if (ImGui::BeginMenu("hex.builtin.menu.file.import"_lang)) { + if (ImGui::BeginMenu("hex.builtin.menu.file.import"_lang, !taskRunning)) { if (ImGui::MenuItem("hex.builtin.menu.file.import.base64"_lang)) { fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { @@ -300,10 +306,8 @@ namespace hex::plugin::builtin { static void createHelpMenu() { ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.help", 5000); - } - void registerMainMenuEntries() { createFileMenu(); createEditMenu(); diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index 8df0c7bea..1b8d814bd 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -227,6 +227,7 @@ namespace hex::plugin::builtin { ContentRegistry::Interface::addToolbarItem([] { auto provider = ImHexApi::Provider::get(); bool providerValid = provider != nullptr; + bool tasksRunning = Task::getRunningTaskCount() > 0; // Undo ImGui::BeginDisabled(!providerValid || !provider->canUndo()); @@ -246,14 +247,17 @@ namespace hex::plugin::builtin { ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); - // Create new file - if (ImGui::ToolBarButton(ICON_VS_FILE, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGray))) - EventManager::post("Create File"); - - // Open file - if (ImGui::ToolBarButton(ICON_VS_FOLDER_OPENED, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBrown))) - EventManager::post("Open File"); + ImGui::BeginDisabled(tasksRunning); + { + // Create new file + if (ImGui::ToolBarButton(ICON_VS_FILE, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGray))) + EventManager::post("Create File"); + // Open file + if (ImGui::ToolBarButton(ICON_VS_FOLDER_OPENED, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBrown))) + EventManager::post("Open File"); + } + ImGui::EndDisabled(); ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); @@ -295,7 +299,7 @@ namespace hex::plugin::builtin { ImGui::Spacing(); // Provider switcher - ImGui::BeginDisabled(!providerValid); + ImGui::BeginDisabled(!providerValid || tasksRunning); { auto &providers = ImHexApi::Provider::getProviders();