impr: Make unsaved changes popup behave more like in other applications

This commit is contained in:
WerWolv
2024-04-23 21:01:58 +02:00
parent 7ec245925a
commit fd61e757f0
9 changed files with 103 additions and 27 deletions

View File

@@ -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");