mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
impr: Make unsaved changes popup behave more like in other applications
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <hex/ui/view.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <content/global_actions.hpp>
|
||||
|
||||
#include <content/providers/file_provider.hpp>
|
||||
|
||||
@@ -80,17 +81,30 @@ namespace hex::plugin::builtin {
|
||||
if (provider->isDirty()) {
|
||||
*shouldClose = false;
|
||||
PopupUnsavedChanges::open("hex.builtin.popup.close_provider.desc"_lang,
|
||||
[]{
|
||||
for (const auto &provider : ImHexApi::Provider::impl::getClosingProviders())
|
||||
ImHexApi::Provider::remove(provider, true);
|
||||
[]{
|
||||
const bool projectSaved = ProjectFile::hasPath() ? saveProject() : saveProjectAs();
|
||||
if (projectSaved) {
|
||||
for (const auto &provider : ImHexApi::Provider::impl::getClosingProviders())
|
||||
ImHexApi::Provider::remove(provider, true);
|
||||
|
||||
if (imhexClosing)
|
||||
ImHexApi::System::closeImHex(true);
|
||||
},
|
||||
[] {
|
||||
ImHexApi::Provider::impl::resetClosingProvider();
|
||||
imhexClosing = false;
|
||||
}
|
||||
if (imhexClosing)
|
||||
ImHexApi::System::closeImHex(true);
|
||||
} else {
|
||||
ImHexApi::Provider::impl::resetClosingProvider();
|
||||
imhexClosing = false;
|
||||
}
|
||||
},
|
||||
[] {
|
||||
for (const auto &provider : ImHexApi::Provider::impl::getClosingProviders())
|
||||
ImHexApi::Provider::remove(provider, true);
|
||||
|
||||
if (imhexClosing)
|
||||
ImHexApi::System::closeImHex(true);
|
||||
},
|
||||
[] {
|
||||
ImHexApi::Provider::impl::resetClosingProvider();
|
||||
imhexClosing = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
#include <content/global_actions.hpp>
|
||||
#include <hex/ui/view.hpp>
|
||||
#include <hex/api/project_file_manager.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
@@ -18,18 +19,25 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
}
|
||||
|
||||
void saveProject() {
|
||||
if (ImHexApi::Provider::isValid() && ProjectFile::hasPath()) {
|
||||
bool saveProject() {
|
||||
if (!ImHexApi::Provider::isValid())
|
||||
return false;
|
||||
|
||||
if (ProjectFile::hasPath()) {
|
||||
if (!ProjectFile::store()) {
|
||||
ui::ToastError::open("hex.builtin.popup.error.project.save"_lang);
|
||||
return false;
|
||||
} else {
|
||||
log::debug("Project saved");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return saveProjectAs();
|
||||
}
|
||||
}
|
||||
|
||||
void saveProjectAs() {
|
||||
fs::openFileBrowser(fs::DialogMode::Save, { {"Project File", "hexproj"} },
|
||||
bool saveProjectAs() {
|
||||
return fs::openFileBrowser(fs::DialogMode::Save, { {"Project File", "hexproj"} },
|
||||
[](std::fs::path path) {
|
||||
if (path.extension() != ".hexproj") {
|
||||
path.replace_extension(".hexproj");
|
||||
|
||||
Reference in New Issue
Block a user