1
0
mirror of synced 2024-11-28 09:30:51 +01:00

Fixed some popups not appearing when no views are open

This commit is contained in:
WerWolv 2021-02-07 14:29:13 +01:00
parent 15bcf71aaf
commit 8e7bfb7f1a
6 changed files with 59 additions and 51 deletions

View File

@ -25,6 +25,7 @@ namespace hex {
~ViewHexEditor() override;
void drawContent() override;
void drawAlwaysVisible() override;
void drawMenu() override;
bool handleShortcut(int key, int mods) override;

View File

@ -23,6 +23,7 @@ namespace hex {
~ViewPattern() override;
void drawMenu() override;
void drawAlwaysVisible() override;
void drawContent() override;
private:

View File

@ -21,6 +21,7 @@ namespace hex {
virtual ~View() = default;
virtual void drawContent() = 0;
virtual void drawAlwaysVisible() { }
virtual void drawMenu();
virtual bool handleShortcut(int key, int mods);
virtual bool isAvailable();

View File

@ -206,7 +206,40 @@ namespace hex {
this->drawSearchPopup();
this->drawGotoPopup();
}
}
static void save() {
auto provider = SharedData::currentProvider;
for (const auto &[address, value] : provider->getPatches())
provider->writeRaw(address, &value, sizeof(u8));
}
static void saveAs() {
View::openFileBrowser("Save As", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, "*.*", [](auto path) {
FILE *file = fopen(path.c_str(), "wb");
if (file != nullptr) {
std::vector<u8> buffer(0xFF'FFFF, 0x00);
size_t bufferSize = buffer.size();
fseek(file, 0, SEEK_SET);
auto provider = SharedData::currentProvider;
for (u64 offset = 0; offset < provider->getActualSize(); offset += bufferSize) {
if (bufferSize > provider->getActualSize() - offset)
bufferSize = provider->getActualSize() - offset;
provider->read(offset, buffer.data(), bufferSize);
fwrite(buffer.data(), 1, bufferSize, file);
}
fclose(file);
}
});
}
void ViewHexEditor::drawAlwaysVisible() {
auto provider = SharedData::currentProvider;
if (ImGui::BeginPopupModal("Save Changes", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
constexpr auto Message = "You have unsaved changes made to your Project.\nAre you sure you want to exit?";
@ -285,36 +318,6 @@ namespace hex {
}
}
static void save() {
auto provider = SharedData::currentProvider;
for (const auto &[address, value] : provider->getPatches())
provider->writeRaw(address, &value, sizeof(u8));
}
static void saveAs() {
View::openFileBrowser("Save As", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, "*.*", [](auto path) {
FILE *file = fopen(path.c_str(), "wb");
if (file != nullptr) {
std::vector<u8> buffer(0xFF'FFFF, 0x00);
size_t bufferSize = buffer.size();
fseek(file, 0, SEEK_SET);
auto provider = SharedData::currentProvider;
for (u64 offset = 0; offset < provider->getActualSize(); offset += bufferSize) {
if (bufferSize > provider->getActualSize() - offset)
bufferSize = provider->getActualSize() - offset;
provider->read(offset, buffer.data(), bufferSize);
fwrite(buffer.data(), 1, bufferSize, file);
}
fclose(file);
}
});
};
void ViewHexEditor::drawMenu() {
auto provider = SharedData::currentProvider;

View File

@ -257,9 +257,9 @@ namespace hex {
View::discardNavigationRequests();
}
ImGui::End();
}
void ViewPattern::drawAlwaysVisible() {
if (ImGui::BeginPopupModal("Accept Pattern", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::TextWrapped("One or more patterns compatible with this data type has been found");

View File

@ -148,6 +148,8 @@ namespace hex {
View::getDeferedCalls().clear();
for (auto &view : ContentRegistry::Views::getEntries()) {
view->drawAlwaysVisible();
if (!view->isAvailable() || !view->getWindowOpenState())
continue;
@ -275,7 +277,7 @@ namespace hex {
for (auto &view : ContentRegistry::Views::getEntries())
anyViewOpen = anyViewOpen || (view->getWindowOpenState() && view->isAvailable());
if (!anyViewOpen) {
if (!anyViewOpen && SharedData::currentProvider == nullptr) {
char title[256];
ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("MainDock"));
if (ImGui::Begin(title)) {