2022-11-25 10:47:11 +01:00
|
|
|
|
|
|
|
#include <hex/ui/view.hpp>
|
|
|
|
#include <hex/api/project_file_manager.hpp>
|
2023-01-07 17:16:43 +01:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2022-11-25 10:47:11 +01:00
|
|
|
|
2023-12-26 00:22:47 +01:00
|
|
|
#include <toasts/toast_notification.hpp>
|
2022-11-25 10:47:11 +01:00
|
|
|
|
2023-07-28 00:01:49 +02:00
|
|
|
#include <wolv/utils/string.hpp>
|
|
|
|
|
2022-11-25 10:47:11 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
void openProject() {
|
|
|
|
fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"} },
|
|
|
|
[](const auto &path) {
|
|
|
|
if (!ProjectFile::load(path)) {
|
2023-12-26 00:22:47 +01:00
|
|
|
ui::ToastError::open(hex::format("hex.builtin.popup.error.project.load"_lang, wolv::util::toUTF8String(path)));
|
2022-11-25 10:47:11 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveProject() {
|
2023-01-07 17:16:43 +01:00
|
|
|
if (ImHexApi::Provider::isValid() && ProjectFile::hasPath()) {
|
|
|
|
if (!ProjectFile::store()) {
|
2023-12-26 00:22:47 +01:00
|
|
|
ui::ToastError::open("hex.builtin.popup.error.project.save"_lang);
|
2023-01-07 17:16:43 +01:00
|
|
|
} else {
|
|
|
|
log::debug("Project saved");
|
|
|
|
}
|
2022-11-25 10:47:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveProjectAs() {
|
|
|
|
fs::openFileBrowser(fs::DialogMode::Save, { {"Project File", "hexproj"} },
|
|
|
|
[](std::fs::path path) {
|
|
|
|
if (path.extension() != ".hexproj") {
|
|
|
|
path.replace_extension(".hexproj");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ProjectFile::store(path)) {
|
2023-12-26 00:22:47 +01:00
|
|
|
ui::ToastError::open("hex.builtin.popup.error.project.save"_lang);
|
2022-11-25 10:47:11 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|