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>
|
2023-11-14 15:55:34 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2023-04-08 00:58:53 +02:00
|
|
|
|
2021-12-12 00:41:44 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
ViewProviderSettings::ViewProviderSettings() : View::Modal("hex.builtin.view.provider_settings.name") {
|
2023-11-10 20:47:08 +01:00
|
|
|
EventManager::subscribe<EventProviderCreated>(this, [](const 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"));
|
|
|
|
});
|
2023-11-14 15:55:34 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2021-12-12 00:41:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewProviderSettings::~ViewProviderSettings() {
|
|
|
|
EventManager::unsubscribe<EventProviderCreated>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewProviderSettings::drawContent() {
|
2023-11-21 13:47:50 +01:00
|
|
|
auto provider = hex::ImHexApi::Provider::get();
|
|
|
|
if (provider != nullptr) {
|
|
|
|
bool settingsValid = provider->drawLoadInterface();
|
2021-12-12 00:41:44 +01:00
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
2021-12-12 00:41:44 +01:00
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
ImGui::BeginDisabled(!settingsValid);
|
|
|
|
if (ImGui::Button("hex.builtin.common.open"_lang)) {
|
|
|
|
if (provider->open()) {
|
|
|
|
EventManager::post<EventProviderOpened>(provider);
|
|
|
|
ImGui::CloseCurrentPopup();
|
2021-12-12 00:41:44 +01:00
|
|
|
}
|
2023-11-21 13:47:50 +01:00
|
|
|
else {
|
2021-12-12 00:41:44 +01:00
|
|
|
ImGui::CloseCurrentPopup();
|
2023-11-21 13:47:50 +01:00
|
|
|
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));
|
|
|
|
}
|
2023-01-03 16:34:22 +01:00
|
|
|
TaskManager::doLater([=] { ImHexApi::Provider::remove(provider); });
|
2021-12-12 00:41:44 +01:00
|
|
|
}
|
|
|
|
}
|
2023-11-21 13:47:50 +01:00
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
2021-12-12 00:41:44 +01:00
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
if (ImGui::Button("hex.builtin.common.cancel"_lang)) {
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
TaskManager::doLater([=] { ImHexApi::Provider::remove(provider); });
|
|
|
|
}
|
2021-12-12 00:41:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-10 21:05:37 +01:00
|
|
|
bool ViewProviderSettings::hasViewMenuItemEntry() const {
|
2023-11-14 15:55:34 +01:00
|
|
|
return false;
|
2021-12-12 00:41:44 +01:00
|
|
|
}
|
|
|
|
|
2023-11-14 15:55:34 +01:00
|
|
|
}
|