feat: Added quick "save project" action (#826)
* add quick -save project- action * translation for -save project as- added * removed machine translations; header file name extension fixed * moved openProject() for consistency
This commit is contained in:
parent
8e696e3fc4
commit
4aa314b3ab
@ -33,6 +33,8 @@ namespace hex {
|
||||
static bool load(const std::fs::path &filePath);
|
||||
static bool store(std::optional<std::fs::path> filePath = std::nullopt);
|
||||
|
||||
static bool hasPath();
|
||||
|
||||
static void registerHandler(const Handler &handler) {
|
||||
getHandlers().push_back(handler);
|
||||
}
|
||||
|
@ -113,9 +113,15 @@ namespace hex {
|
||||
tar.write(MetadataPath, metadataContent);
|
||||
}
|
||||
|
||||
ProjectFile::s_currProjectPath = filePath.value();
|
||||
|
||||
ImHexApi::Provider::resetDirty();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ProjectFile::hasPath() {
|
||||
return !ProjectFile::s_currProjectPath.empty();
|
||||
}
|
||||
|
||||
}
|
@ -24,6 +24,7 @@ add_library(${PROJECT_NAME} SHARED
|
||||
source/content/events.cpp
|
||||
source/content/hashes.cpp
|
||||
source/content/shortcuts.cpp
|
||||
source/content/global_actions.cpp
|
||||
|
||||
source/content/providers/file_provider.cpp
|
||||
source/content/providers/gdb_provider.cpp
|
||||
|
7
plugins/builtin/include/content/global_actions.hpp
Normal file
7
plugins/builtin/include/content/global_actions.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
void openProject();
|
||||
void saveProject();
|
||||
void saveProjectAs();
|
||||
}
|
35
plugins/builtin/source/content/global_actions.cpp
Normal file
35
plugins/builtin/source/content/global_actions.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
#include <hex/ui/view.hpp>
|
||||
#include <hex/api/project_file_manager.hpp>
|
||||
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
void openProject() {
|
||||
fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"} },
|
||||
[](const auto &path) {
|
||||
if (!ProjectFile::load(path)) {
|
||||
View::showErrorPopup("hex.builtin.popup.error.project.load"_lang);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void saveProject() {
|
||||
if (!ProjectFile::store()) {
|
||||
View::showErrorPopup("hex.builtin.popup.error.project.save"_lang);
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
View::showErrorPopup("hex.builtin.popup.error.project.save"_lang);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/crypto.hpp>
|
||||
#include <hex/helpers/patches.hpp>
|
||||
#include "content/global_actions.hpp"
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
@ -73,26 +74,15 @@ namespace hex::plugin::builtin {
|
||||
bool taskRunning = TaskManager::getRunningTaskCount() > 0;
|
||||
|
||||
if (ImGui::MenuItem("hex.builtin.menu.file.open_project"_lang, "", false, !taskRunning)) {
|
||||
fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"}
|
||||
},
|
||||
[](const auto &path) {
|
||||
if (!ProjectFile::load(path)) {
|
||||
View::showErrorPopup("hex.builtin.popup.error.project.load"_lang);
|
||||
}
|
||||
});
|
||||
openProject();
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("hex.builtin.menu.file.save_project"_lang, "", false, providerValid && provider->isWritable())) {
|
||||
fs::openFileBrowser(fs::DialogMode::Save, { {"Project File", "hexproj"} },
|
||||
[](std::fs::path path) {
|
||||
if (path.extension() != ".hexproj") {
|
||||
path.replace_extension(".hexproj");
|
||||
}
|
||||
if (ImGui::MenuItem("hex.builtin.menu.file.save_project"_lang, "ALT + S", false, providerValid && provider->isWritable() && ProjectFile::hasPath())) {
|
||||
saveProject();
|
||||
}
|
||||
|
||||
if (!ProjectFile::store(path)) {
|
||||
View::showErrorPopup("hex.builtin.popup.error.project.save"_lang);
|
||||
}
|
||||
});
|
||||
if (ImGui::MenuItem("hex.builtin.menu.file.save_project_as"_lang, "ALT + SHIFT + S", false, providerValid && provider->isWritable())) {
|
||||
saveProjectAs();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <hex/api/event.hpp>
|
||||
|
||||
#include <hex/providers/provider.hpp>
|
||||
#include "content/global_actions.hpp"
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
@ -32,6 +33,16 @@ namespace hex::plugin::builtin {
|
||||
ImHexApi::Provider::remove(provider, true);
|
||||
}
|
||||
});
|
||||
|
||||
// Save project
|
||||
ShortcutManager::addGlobalShortcut(ALT + Keys::S, [] {
|
||||
saveProject();
|
||||
});
|
||||
|
||||
// Save project as...
|
||||
ShortcutManager::addGlobalShortcut(ALT + SHIFT + Keys::S, [] {
|
||||
saveProjectAs();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -163,7 +163,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.menu.file.reload_file", "Datei neu laden" },
|
||||
{ "hex.builtin.menu.file.quit", "ImHex Beenden" },
|
||||
{ "hex.builtin.menu.file.open_project", "Projekt öffnen..." },
|
||||
{ "hex.builtin.menu.file.save_project", "Projekt speichern..." },
|
||||
{ "hex.builtin.menu.file.save_project", "Projekt speichern" },
|
||||
{ "hex.builtin.menu.file.save_project_as", "Projekt speichern unter..." },
|
||||
{ "hex.builtin.menu.file.import", "Importieren..." },
|
||||
{ "hex.builtin.menu.file.import.base64", "Base64 Datei" },
|
||||
{ "hex.builtin.menu.file.import.base64.popup.import_error", "Datei ist nicht in einem korrekten Base64 Format!" },
|
||||
|
@ -165,7 +165,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.menu.file.reload_file", "Reload File" },
|
||||
{ "hex.builtin.menu.file.quit", "Quit ImHex" },
|
||||
{ "hex.builtin.menu.file.open_project", "Open Project..." },
|
||||
{ "hex.builtin.menu.file.save_project", "Save Project..." },
|
||||
{ "hex.builtin.menu.file.save_project", "Save Project" },
|
||||
{ "hex.builtin.menu.file.save_project_as", "Save Project As..." },
|
||||
{ "hex.builtin.menu.file.import", "Import..." },
|
||||
{ "hex.builtin.menu.file.import.base64", "Base64 File" },
|
||||
{ "hex.builtin.menu.file.import.base64.popup.import_error", "File is not in a valid Base64 format!" },
|
||||
|
@ -164,7 +164,8 @@ namespace hex::plugin::builtin {
|
||||
//{ "hex.builtin.menu.file.reload_file", "Reload File" },
|
||||
{ "hex.builtin.menu.file.quit", "Uscita ImHex" },
|
||||
{ "hex.builtin.menu.file.open_project", "Apri un Progetto..." },
|
||||
{ "hex.builtin.menu.file.save_project", "Salva Progetto..." },
|
||||
{ "hex.builtin.menu.file.save_project", "Salva Progetto" },
|
||||
//{ "hex.builtin.menu.file.save_project_as", "Save Project As..." },
|
||||
{ "hex.builtin.menu.file.import", "Importa..." },
|
||||
{ "hex.builtin.menu.file.import.base64", "Base64 File" },
|
||||
//{ "hex.builtin.menu.file.import.base64.popup.import_error", "File is not in a valid Base64 format!" },
|
||||
|
@ -164,7 +164,8 @@ namespace hex::plugin::builtin {
|
||||
//{ "hex.builtin.menu.file.reload_file", "Reload File" },
|
||||
{ "hex.builtin.menu.file.quit", "ImHexを終了" },
|
||||
{ "hex.builtin.menu.file.open_project", "プロジェクトを開く…" },
|
||||
{ "hex.builtin.menu.file.save_project", "プロジェクトを保存…" },
|
||||
{ "hex.builtin.menu.file.save_project", "プロジェクトを保存" },
|
||||
//{ "hex.builtin.menu.file.save_project_as", "Save Project As..." },
|
||||
{ "hex.builtin.view.hex_editor.menu.file.load_encoding_file", "カスタムエンコードを読み込む…" },
|
||||
{ "hex.builtin.menu.file.import", "インポート…" },
|
||||
{ "hex.builtin.menu.file.import.base64", "Base64ファイル" },
|
||||
|
@ -164,7 +164,8 @@ namespace hex::plugin::builtin {
|
||||
//{ "hex.builtin.menu.file.reload_file", "Reload File" },
|
||||
{ "hex.builtin.menu.file.quit", "ImHex 종료하기" },
|
||||
{ "hex.builtin.menu.file.open_project", "프로젝트 열기..." },
|
||||
{ "hex.builtin.menu.file.save_project", "프로젝트 저장..." },
|
||||
{ "hex.builtin.menu.file.save_project", "프로젝트 저장" },
|
||||
//{ "hex.builtin.menu.file.save_project_as", "Save Project As..." },
|
||||
{ "hex.builtin.menu.file.import", "가져오기..." },
|
||||
{ "hex.builtin.menu.file.import.base64", "Base64 파일" },
|
||||
{ "hex.builtin.menu.file.import.base64.popup.import_error", "파일이 올바른 Base64 형식이 아닙니다!" },
|
||||
|
@ -164,7 +164,8 @@ namespace hex::plugin::builtin {
|
||||
//{ "hex.builtin.menu.file.reload_file", "Reload File" },
|
||||
{ "hex.builtin.menu.file.quit", "Sair do ImHex" },
|
||||
{ "hex.builtin.menu.file.open_project", "Abrir Projeto..." },
|
||||
{ "hex.builtin.menu.file.save_project", "Salvar Projeto..." },
|
||||
{ "hex.builtin.menu.file.save_project", "Salvar Projeto" },
|
||||
//{ "hex.builtin.menu.file.save_project_as", "Save Project As..." },
|
||||
{ "hex.builtin.menu.file.import", "Importar..." },
|
||||
{ "hex.builtin.menu.file.import.base64", "Arquivo Base64" },
|
||||
{ "hex.builtin.menu.file.import.base64.popup.import_error", "Esse arquivo não é baseado em um formato Base64 valido!" },
|
||||
|
@ -164,7 +164,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.menu.file.reload_file", "重新加载文件" },
|
||||
{ "hex.builtin.menu.file.quit", "退出 ImHex" },
|
||||
{ "hex.builtin.menu.file.open_project", "打开项目..." },
|
||||
{ "hex.builtin.menu.file.save_project", "保存项目..." },
|
||||
{ "hex.builtin.menu.file.save_project", "保存项目" },
|
||||
//{ "hex.builtin.menu.file.save_project_as", "Save Project As..." },
|
||||
{ "hex.builtin.menu.file.import", "导入..." },
|
||||
{ "hex.builtin.menu.file.import.base64", "Base64 文件" },
|
||||
{ "hex.builtin.menu.file.import.base64.popup.import_error", "文件不是有效的 Base64 格式!" },
|
||||
|
@ -164,7 +164,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.menu.file.reload_file", "重新載入檔案" },
|
||||
{ "hex.builtin.menu.file.quit", "退出 ImHex" },
|
||||
{ "hex.builtin.menu.file.open_project", "開啟專案..." },
|
||||
{ "hex.builtin.menu.file.save_project", "儲存專案..." },
|
||||
{ "hex.builtin.menu.file.save_project", "儲存專案" },
|
||||
//{ "hex.builtin.menu.file.save_project_as", "Save Project As..." },
|
||||
{ "hex.builtin.menu.file.import", "匯入..." },
|
||||
{ "hex.builtin.menu.file.import.base64", "Base64 檔案" },
|
||||
{ "hex.builtin.menu.file.import.base64.popup.import_error", "檔案並非有效的 Base64 格式!" },
|
||||
|
Loading…
x
Reference in New Issue
Block a user