2023-11-10 20:47:08 +01:00
|
|
|
#pragma once
|
|
|
|
|
2023-11-07 15:31:54 +01:00
|
|
|
#include <hex/ui/popup.hpp>
|
|
|
|
|
2023-11-21 14:38:01 +01:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2023-11-07 15:31:54 +01:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
class PopupUnsavedChanges : public Popup<PopupUnsavedChanges> {
|
|
|
|
public:
|
2024-04-23 21:01:58 +02:00
|
|
|
PopupUnsavedChanges(std::string message, std::function<void()> yesFunction, std::function<void()> noFunction, std::function<void()> cancelFunction)
|
2023-12-23 21:09:41 +01:00
|
|
|
: hex::Popup<PopupUnsavedChanges>("hex.ui.common.question", false),
|
2023-11-07 15:31:54 +01:00
|
|
|
m_message(std::move(message)),
|
2024-04-23 21:01:58 +02:00
|
|
|
m_yesFunction(std::move(yesFunction)), m_noFunction(std::move(noFunction)), m_cancelFunction(std::move(cancelFunction)) { }
|
2023-11-07 15:31:54 +01:00
|
|
|
|
|
|
|
void drawContent() override {
|
2023-12-19 13:10:25 +01:00
|
|
|
ImGuiExt::TextFormattedWrapped("{}", m_message.c_str());
|
2023-11-07 15:31:54 +01:00
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
if (ImGui::BeginTable("##unsaved_providers", 1, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 4))) {
|
|
|
|
for (const auto &provider : ImHexApi::Provider::impl::getClosingProviders()) {
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(provider->getName().c_str());
|
|
|
|
}
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
auto width = ImGui::GetWindowWidth();
|
2024-04-23 21:01:58 +02:00
|
|
|
ImGui::SetCursorPosX((width / 10) * 0.5);
|
|
|
|
if (ImGui::Button("hex.ui.common.yes"_lang, ImVec2(width / 4, 0))) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_yesFunction();
|
2023-11-07 15:31:54 +01:00
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2024-04-23 21:01:58 +02:00
|
|
|
ImGui::SetCursorPosX((width / 10) * 3.75);
|
|
|
|
if (ImGui::Button("hex.ui.common.no"_lang, ImVec2(width / 4, 0)) || ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_noFunction();
|
2023-11-07 15:31:54 +01:00
|
|
|
this->close();
|
|
|
|
}
|
2024-04-23 21:01:58 +02:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetCursorPosX((width / 10) * 7);
|
|
|
|
if (ImGui::Button("hex.ui.common.cancel"_lang, ImVec2(width / 4, 0)) || ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
|
|
|
m_cancelFunction();
|
|
|
|
this->close();
|
|
|
|
}
|
2023-11-07 15:31:54 +01:00
|
|
|
|
|
|
|
ImGui::SetWindowPos((ImHexApi::System::getMainWindowSize() - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImGuiWindowFlags getFlags() const override {
|
|
|
|
return ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImVec2 getMinSize() const override {
|
|
|
|
return scaled({ 400, 100 });
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ImVec2 getMaxSize() const override {
|
2023-11-25 12:43:48 +01:00
|
|
|
return scaled({ 600, 600 });
|
2023-11-07 15:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_message;
|
2024-04-23 21:01:58 +02:00
|
|
|
std::function<void()> m_yesFunction, m_noFunction, m_cancelFunction;
|
2023-11-07 15:31:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|