1
0
mirror of synced 2024-12-04 20:17:57 +01:00
ImHex/plugins/builtin/source/content/views/view_provider_settings.cpp

86 lines
3.2 KiB
C++
Raw Normal View History

#include "content/views/view_provider_settings.hpp"
#include <content/popups/popup_notification.hpp>
#include <hex/api/content_registry.hpp>
namespace hex::plugin::builtin {
ViewProviderSettings::ViewProviderSettings() : hex::View("hex.builtin.view.provider_settings.name") {
2023-11-10 20:47:08 +01:00
EventManager::subscribe<EventProviderCreated>(this, [](const hex::prv::Provider *provider) {
if (provider->hasLoadInterface() && !provider->shouldSkipLoadInterface())
EventManager::post<RequestOpenPopup>(View::toWindowName("hex.builtin.view.provider_settings.load_popup"));
});
ContentRegistry::Interface::addSidebarItem(ICON_VS_SERVER_PROCESS, [] {
auto provider = hex::ImHexApi::Provider::get();
if (provider != nullptr)
provider->drawInterface();
},
[] {
auto provider = hex::ImHexApi::Provider::get();
return provider != nullptr && provider->hasInterface() && provider->isAvailable();
});
}
ViewProviderSettings::~ViewProviderSettings() {
EventManager::unsubscribe<EventProviderCreated>(this);
}
void ViewProviderSettings::drawContent() {
}
void ViewProviderSettings::drawAlwaysVisible() {
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F));
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.provider_settings.load_popup").c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
auto provider = hex::ImHexApi::Provider::get();
if (provider != nullptr) {
bool settingsValid = provider->drawLoadInterface();
ImGui::NewLine();
ImGui::Separator();
ImGui::BeginDisabled(!settingsValid);
if (ImGui::Button("hex.builtin.common.open"_lang)) {
if (provider->open()) {
EventManager::post<EventProviderOpened>(provider);
ImGui::CloseCurrentPopup();
}
2022-07-30 22:34:23 +02:00
else {
ImGui::CloseCurrentPopup();
auto errorMessage = provider->getErrorMessage();
if (errorMessage.empty()) {
PopupError::open("hex.builtin.view.provider_settings.load_error"_lang);
} else {
PopupError::open(hex::format("hex.builtin.view.provider_settings.load_error_details"_lang, errorMessage));
}
TaskManager::doLater([=] { ImHexApi::Provider::remove(provider); });
2022-07-30 22:34:23 +02:00
}
}
ImGui::EndDisabled();
ImGui::SameLine();
if (ImGui::Button("hex.builtin.common.cancel"_lang)) {
ImGui::CloseCurrentPopup();
TaskManager::doLater([=] { ImHexApi::Provider::remove(provider); });
}
}
ImGui::EndPopup();
}
}
2022-01-10 21:05:37 +01:00
bool ViewProviderSettings::hasViewMenuItemEntry() const {
return false;
}
2022-01-10 21:05:37 +01:00
bool ViewProviderSettings::isAvailable() const {
return false;
}
}