2021-12-12 00:41:44 +01:00
|
|
|
#include "content/views/view_provider_settings.hpp"
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
#include <content/popups/popup_notification.hpp>
|
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
ViewProviderSettings::ViewProviderSettings() : hex::View("hex.builtin.view.provider_settings.name") {
|
2022-01-24 20:53:17 +01:00
|
|
|
EventManager::subscribe<EventProviderCreated>(this, [](hex::prv::Provider *provider) {
|
2023-03-07 16:03:34 +01:00
|
|
|
if (provider->hasLoadInterface() && !provider->shouldSkipLoadInterface())
|
2021-12-12 00:41:44 +01:00
|
|
|
EventManager::post<RequestOpenPopup>(View::toWindowName("hex.builtin.view.provider_settings.load_popup"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewProviderSettings::~ViewProviderSettings() {
|
|
|
|
EventManager::unsubscribe<EventProviderCreated>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewProviderSettings::drawContent() {
|
2022-01-18 00:10:10 +01:00
|
|
|
if (ImGui::Begin(this->getName().c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
2021-12-12 00:41:44 +01:00
|
|
|
auto provider = hex::ImHexApi::Provider::get();
|
|
|
|
|
|
|
|
if (provider != nullptr)
|
|
|
|
provider->drawInterface();
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2023-03-16 16:48:15 +01:00
|
|
|
bool settingsValid = provider->drawLoadInterface();
|
2021-12-12 00:41:44 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2023-03-16 16:48:15 +01:00
|
|
|
ImGui::BeginDisabled(!settingsValid);
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::Button("hex.builtin.common.open"_lang)) {
|
2022-08-14 10:07:45 +02:00
|
|
|
if (provider->open()) {
|
2022-09-04 11:16:20 +02:00
|
|
|
EventManager::post<EventProviderOpened>(provider);
|
2021-12-12 00:41:44 +01:00
|
|
|
ImGui::CloseCurrentPopup();
|
2022-08-14 10:07:45 +02:00
|
|
|
}
|
2022-07-30 22:34:23 +02:00
|
|
|
else {
|
2023-03-21 10:33:00 +01:00
|
|
|
auto errorMessage = provider->getErrorMessage();
|
|
|
|
if (errorMessage.empty()) {
|
2023-04-08 00:58:53 +02:00
|
|
|
PopupError::open("hex.builtin.view.provider_settings.load_error"_lang);
|
2023-03-21 10:33:00 +01:00
|
|
|
} else {
|
2023-04-08 00:58:53 +02:00
|
|
|
PopupError::open(hex::format("hex.builtin.view.provider_settings.load_error_details"_lang, errorMessage));
|
2023-03-21 10:33:00 +01:00
|
|
|
}
|
2023-01-03 16:34:22 +01:00
|
|
|
TaskManager::doLater([=] { ImHexApi::Provider::remove(provider); });
|
2022-07-30 22:34:23 +02:00
|
|
|
}
|
2021-12-12 00:41:44 +01:00
|
|
|
}
|
2023-03-16 16:48:15 +01:00
|
|
|
ImGui::EndDisabled();
|
2021-12-12 00:41:44 +01:00
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::Button("hex.builtin.common.cancel"_lang)) {
|
2021-12-12 00:41:44 +01:00
|
|
|
ImGui::CloseCurrentPopup();
|
2023-01-03 16:34:22 +01:00
|
|
|
TaskManager::doLater([=] { ImHexApi::Provider::remove(provider); });
|
2021-12-12 00:41:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-10 21:05:37 +01:00
|
|
|
bool ViewProviderSettings::hasViewMenuItemEntry() const {
|
2021-12-12 00:41:44 +01:00
|
|
|
return this->isAvailable();
|
|
|
|
}
|
|
|
|
|
2022-01-10 21:05:37 +01:00
|
|
|
bool ViewProviderSettings::isAvailable() const {
|
2021-12-12 00:41:44 +01:00
|
|
|
auto provider = hex::ImHexApi::Provider::get();
|
|
|
|
|
2023-01-01 19:14:57 +01:00
|
|
|
return provider != nullptr && provider->hasInterface() && provider->isAvailable();
|
2021-12-12 00:41:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|