Fixed some popups not appearing when no views are open
This commit is contained in:
parent
15bcf71aaf
commit
8e7bfb7f1a
@ -25,6 +25,7 @@ namespace hex {
|
||||
~ViewHexEditor() override;
|
||||
|
||||
void drawContent() override;
|
||||
void drawAlwaysVisible() override;
|
||||
void drawMenu() override;
|
||||
bool handleShortcut(int key, int mods) override;
|
||||
|
||||
|
@ -23,6 +23,7 @@ namespace hex {
|
||||
~ViewPattern() override;
|
||||
|
||||
void drawMenu() override;
|
||||
void drawAlwaysVisible() override;
|
||||
void drawContent() override;
|
||||
|
||||
private:
|
||||
|
@ -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();
|
||||
|
@ -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?";
|
||||
@ -248,18 +281,18 @@ namespace hex {
|
||||
ImGui::NewLine();
|
||||
|
||||
confirmButtons("Load", "Cancel",
|
||||
[this, &provider] {
|
||||
if (!this->m_loaderScriptScriptPath.empty() && !this->m_loaderScriptFilePath.empty()) {
|
||||
this->openFile(this->m_loaderScriptFilePath);
|
||||
LoaderScript::setFilePath(this->m_loaderScriptFilePath);
|
||||
LoaderScript::setDataProvider(provider);
|
||||
LoaderScript::processFile(this->m_loaderScriptScriptPath);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
},
|
||||
[] {
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
[this, &provider] {
|
||||
if (!this->m_loaderScriptScriptPath.empty() && !this->m_loaderScriptFilePath.empty()) {
|
||||
this->openFile(this->m_loaderScriptFilePath);
|
||||
LoaderScript::setFilePath(this->m_loaderScriptFilePath);
|
||||
LoaderScript::setDataProvider(provider);
|
||||
LoaderScript::processFile(this->m_loaderScriptScriptPath);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
},
|
||||
[] {
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
);
|
||||
|
||||
ImGui::EndPopup();
|
||||
@ -271,12 +304,12 @@ namespace hex {
|
||||
ImGui::NewLine();
|
||||
|
||||
confirmButtons("Set", "Cancel",
|
||||
[this, &provider]{
|
||||
provider->setBaseAddress(strtoull(this->m_baseAddressBuffer, nullptr, 16));
|
||||
ImGui::CloseCurrentPopup();
|
||||
}, []{
|
||||
ImGui::CloseCurrentPopup();
|
||||
});
|
||||
[this, &provider]{
|
||||
provider->setBaseAddress(strtoull(this->m_baseAddressBuffer, nullptr, 16));
|
||||
ImGui::CloseCurrentPopup();
|
||||
}, []{
|
||||
ImGui::CloseCurrentPopup();
|
||||
});
|
||||
|
||||
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
||||
ImGui::CloseCurrentPopup();
|
||||
@ -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;
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user