ui: Added recent files to File menu
This commit is contained in:
parent
1e6b493b41
commit
8a485575f5
@ -53,8 +53,6 @@ namespace hex {
|
|||||||
double m_lastFrameTime;
|
double m_lastFrameTime;
|
||||||
|
|
||||||
static inline std::tuple<int, int> s_currShortcut = { -1, -1 };
|
static inline std::tuple<int, int> s_currShortcut = { -1, -1 };
|
||||||
|
|
||||||
std::list<std::string> m_recentFiles;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -153,6 +153,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.view.hexeditor.script.file.title", "Loader Script: Datei öffnen" },
|
{ "hex.view.hexeditor.script.file.title", "Loader Script: Datei öffnen" },
|
||||||
|
|
||||||
{ "hex.view.hexeditor.menu.file.open_file", "Datei öffnen..." },
|
{ "hex.view.hexeditor.menu.file.open_file", "Datei öffnen..." },
|
||||||
|
{ "hex.view.hexeditor.menu.file.open_recent", "Kürzlich geöffnete Dateien"},
|
||||||
{ "hex.view.hexeditor.menu.file.save", "Speichern" },
|
{ "hex.view.hexeditor.menu.file.save", "Speichern" },
|
||||||
{ "hex.view.hexeditor.menu.file.save_as", "Speichern unter..." },
|
{ "hex.view.hexeditor.menu.file.save_as", "Speichern unter..." },
|
||||||
{ "hex.view.hexeditor.menu.file.close", "Schliessen" },
|
{ "hex.view.hexeditor.menu.file.close", "Schliessen" },
|
||||||
|
@ -153,6 +153,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.view.hexeditor.script.file.title", "Loader Script: Open File" },
|
{ "hex.view.hexeditor.script.file.title", "Loader Script: Open File" },
|
||||||
|
|
||||||
{ "hex.view.hexeditor.menu.file.open_file", "Open File..." },
|
{ "hex.view.hexeditor.menu.file.open_file", "Open File..." },
|
||||||
|
{ "hex.view.hexeditor.menu.file.open_recent", "Open Recent"},
|
||||||
{ "hex.view.hexeditor.menu.file.save", "Save" },
|
{ "hex.view.hexeditor.menu.file.save", "Save" },
|
||||||
{ "hex.view.hexeditor.menu.file.save_as", "Save As..." },
|
{ "hex.view.hexeditor.menu.file.save_as", "Save As..." },
|
||||||
{ "hex.view.hexeditor.menu.file.close", "Close" },
|
{ "hex.view.hexeditor.menu.file.close", "Close" },
|
||||||
|
@ -136,6 +136,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.view.hexeditor.name", "Hex editor" },
|
{ "hex.view.hexeditor.name", "Hex editor" },
|
||||||
{ "hex.view.hexeditor.save_changes", "Salva le modifiche" },
|
{ "hex.view.hexeditor.save_changes", "Salva le modifiche" },
|
||||||
{ "hex.view.hexeditor.open_file", "Apri File" },
|
{ "hex.view.hexeditor.open_file", "Apri File" },
|
||||||
|
{ "hex.view.hexeditor.menu.file.open_recent", "File recenti" },
|
||||||
{ "hex.view.hexeditor.open_project", "Apri i Progetti" },
|
{ "hex.view.hexeditor.open_project", "Apri i Progetti" },
|
||||||
{ "hex.view.hexeditor.save_project", "Salva i Progetti" },
|
{ "hex.view.hexeditor.save_project", "Salva i Progetti" },
|
||||||
{ "hex.view.hexeditor.save_data", "Salva i Dati" },
|
{ "hex.view.hexeditor.save_data", "Salva i Dati" },
|
||||||
@ -155,7 +156,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.view.hexeditor.menu.file.open_file", "Apri File..." },
|
{ "hex.view.hexeditor.menu.file.open_file", "Apri File..." },
|
||||||
{ "hex.view.hexeditor.menu.file.save", "Salva" },
|
{ "hex.view.hexeditor.menu.file.save", "Salva" },
|
||||||
{ "hex.view.hexeditor.menu.file.save_as", "Salva come..." },
|
{ "hex.view.hexeditor.menu.file.save_as", "Salva come..." },
|
||||||
// { "hex.view.hexeditor.menu.file.close", "" },
|
{ "hex.view.hexeditor.menu.file.close", "Chiudi" },
|
||||||
{ "hex.view.hexeditor.menu.file.open_project", "Apri un Progetto..." },
|
{ "hex.view.hexeditor.menu.file.open_project", "Apri un Progetto..." },
|
||||||
{ "hex.view.hexeditor.menu.file.save_project", "Salva Progetto..." },
|
{ "hex.view.hexeditor.menu.file.save_project", "Salva Progetto..." },
|
||||||
{ "hex.view.hexeditor.menu.file.load_encoding_file", "Carica una codifica personalizzata..." },
|
{ "hex.view.hexeditor.menu.file.load_encoding_file", "Carica una codifica personalizzata..." },
|
||||||
@ -512,7 +513,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.builtin.setting.interface.color.classic", "Classico" },
|
{ "hex.builtin.setting.interface.color.classic", "Classico" },
|
||||||
{ "hex.builtin.setting.interface.language", "Lingua" },
|
{ "hex.builtin.setting.interface.language", "Lingua" },
|
||||||
{ "hex.builtin.setting.interface.fps", "Limite FPS" },
|
{ "hex.builtin.setting.interface.fps", "Limite FPS" },
|
||||||
// { "hex.builtin.setting.interface.highlight_alpha", "" },
|
{ "hex.builtin.setting.interface.highlight_alpha", "Evidenziazione dell'opacità" },
|
||||||
|
|
||||||
{ "hex.builtin.provider.file.path", "Percorso del File" },
|
{ "hex.builtin.provider.file.path", "Percorso del File" },
|
||||||
{ "hex.builtin.provider.file.size", "Dimensione" },
|
{ "hex.builtin.provider.file.size", "Dimensione" },
|
||||||
|
@ -69,6 +69,8 @@ namespace hex {
|
|||||||
static std::vector<ContentRegistry::DataProcessorNode::Entry> dataProcessorNodes;
|
static std::vector<ContentRegistry::DataProcessorNode::Entry> dataProcessorNodes;
|
||||||
static u32 dataProcessorNodeIdCounter;
|
static u32 dataProcessorNodeIdCounter;
|
||||||
|
|
||||||
|
static std::list<std::string> recentFilePaths;
|
||||||
|
|
||||||
static int mainArgc;
|
static int mainArgc;
|
||||||
static char **mainArgv;
|
static char **mainArgv;
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ namespace hex {
|
|||||||
std::vector<ContentRegistry::DataProcessorNode::Entry> SharedData::dataProcessorNodes;
|
std::vector<ContentRegistry::DataProcessorNode::Entry> SharedData::dataProcessorNodes;
|
||||||
u32 SharedData::dataProcessorNodeIdCounter = 1;
|
u32 SharedData::dataProcessorNodeIdCounter = 1;
|
||||||
|
|
||||||
|
std::list<std::string> SharedData::recentFilePaths;
|
||||||
|
|
||||||
int SharedData::mainArgc;
|
int SharedData::mainArgc;
|
||||||
char **SharedData::mainArgv;
|
char **SharedData::mainArgv;
|
||||||
|
|
||||||
|
@ -130,6 +130,7 @@ namespace hex {
|
|||||||
|
|
||||||
EventManager::subscribe<EventFileDropped>(this, [this](const std::string &filePath) {
|
EventManager::subscribe<EventFileDropped>(this, [this](const std::string &filePath) {
|
||||||
this->openFile(filePath);
|
this->openFile(filePath);
|
||||||
|
this->getWindowOpenState() = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
EventManager::subscribe<RequestSelectionChange>(this, [this](Region region) {
|
EventManager::subscribe<RequestSelectionChange>(this, [this](Region region) {
|
||||||
@ -144,7 +145,7 @@ namespace hex {
|
|||||||
});
|
});
|
||||||
|
|
||||||
EventManager::subscribe<EventProjectFileLoad>(this, [this]() {
|
EventManager::subscribe<EventProjectFileLoad>(this, [this]() {
|
||||||
this->openFile(ProjectFile::getFilePath());
|
EventManager::post<EventFileDropped>(ProjectFile::getFilePath());
|
||||||
});
|
});
|
||||||
|
|
||||||
EventManager::subscribe<EventWindowClosing>(this, [](GLFWwindow *window) {
|
EventManager::subscribe<EventWindowClosing>(this, [](GLFWwindow *window) {
|
||||||
@ -321,7 +322,7 @@ namespace hex {
|
|||||||
confirmButtons("hex.common.load"_lang, "hex.common.cancel"_lang,
|
confirmButtons("hex.common.load"_lang, "hex.common.cancel"_lang,
|
||||||
[this, &provider] {
|
[this, &provider] {
|
||||||
if (!this->m_loaderScriptScriptPath.empty() && !this->m_loaderScriptFilePath.empty()) {
|
if (!this->m_loaderScriptScriptPath.empty() && !this->m_loaderScriptFilePath.empty()) {
|
||||||
this->openFile(this->m_loaderScriptFilePath);
|
EventManager::post<EventFileDropped>(this->m_loaderScriptFilePath);
|
||||||
LoaderScript::setFilePath(this->m_loaderScriptFilePath);
|
LoaderScript::setFilePath(this->m_loaderScriptFilePath);
|
||||||
LoaderScript::setDataProvider(provider);
|
LoaderScript::setDataProvider(provider);
|
||||||
LoaderScript::processFile(this->m_loaderScriptScriptPath);
|
LoaderScript::processFile(this->m_loaderScriptScriptPath);
|
||||||
@ -363,11 +364,20 @@ namespace hex {
|
|||||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.open_file"_lang, "CTRL + O")) {
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.open_file"_lang, "CTRL + O")) {
|
||||||
|
|
||||||
View::openFileBrowser("hex.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [this](auto path) {
|
View::openFileBrowser("hex.view.hexeditor.open_file"_lang, DialogMode::Open, { }, [this](auto path) {
|
||||||
this->openFile(path);
|
EventManager::post<EventFileDropped>(path);
|
||||||
this->getWindowOpenState() = true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::BeginMenu("hex.view.hexeditor.menu.file.open_recent"_lang, !SharedData::recentFilePaths.empty())) {
|
||||||
|
for (auto &path : SharedData::recentFilePaths) {
|
||||||
|
if (ImGui::MenuItem(std::filesystem::path(path).filename().string().c_str())) {
|
||||||
|
EventManager::post<EventFileDropped>(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save"_lang, "CTRL + S", false, provider != nullptr && provider->isWritable())) {
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.save"_lang, "CTRL + S", false, provider != nullptr && provider->isWritable())) {
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
@ -376,7 +386,7 @@ namespace hex {
|
|||||||
saveAs();
|
saveAs();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.close", "", false, provider != nullptr && provider->isAvailable())) {
|
if (ImGui::MenuItem("hex.view.hexeditor.menu.file.close"_lang, "", false, provider != nullptr && provider->isAvailable())) {
|
||||||
EventManager::post<EventFileUnloaded>();
|
EventManager::post<EventFileUnloaded>();
|
||||||
delete SharedData::currentProvider;
|
delete SharedData::currentProvider;
|
||||||
SharedData::currentProvider = nullptr;
|
SharedData::currentProvider = nullptr;
|
||||||
@ -388,7 +398,6 @@ namespace hex {
|
|||||||
View::openFileBrowser("hex.view.hexeditor.menu.file.open_project"_lang, DialogMode::Open, { { "Project File", "hexproj" } }, [this](auto path) {
|
View::openFileBrowser("hex.view.hexeditor.menu.file.open_project"_lang, DialogMode::Open, { { "Project File", "hexproj" } }, [this](auto path) {
|
||||||
ProjectFile::load(path);
|
ProjectFile::load(path);
|
||||||
EventManager::post<EventProjectFileLoad>();
|
EventManager::post<EventProjectFileLoad>();
|
||||||
this->getWindowOpenState() = true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
#include <imgui_imhex_extensions.h>
|
#include <imgui_imhex_extensions.h>
|
||||||
#include <implot.h>
|
#include <implot.h>
|
||||||
#include <implot_internal.h>
|
|
||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
|
@ -112,11 +112,11 @@ namespace hex {
|
|||||||
});
|
});
|
||||||
|
|
||||||
EventManager::subscribe<EventFileLoaded>(this, [this](const std::string &path){
|
EventManager::subscribe<EventFileLoaded>(this, [this](const std::string &path){
|
||||||
this->m_recentFiles.push_front(path);
|
SharedData::recentFilePaths.push_front(path);
|
||||||
|
|
||||||
{
|
{
|
||||||
std::list<std::string> uniques;
|
std::list<std::string> uniques;
|
||||||
for (auto &file : this->m_recentFiles) {
|
for (auto &file : SharedData::recentFilePaths) {
|
||||||
|
|
||||||
bool exists = false;
|
bool exists = false;
|
||||||
for (auto &unique : uniques) {
|
for (auto &unique : uniques) {
|
||||||
@ -130,12 +130,12 @@ namespace hex {
|
|||||||
if (uniques.size() > 5)
|
if (uniques.size() > 5)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this->m_recentFiles = uniques;
|
SharedData::recentFilePaths = uniques;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::vector<std::string> recentFilesVector;
|
std::vector<std::string> recentFilesVector;
|
||||||
std::copy(this->m_recentFiles.begin(), this->m_recentFiles.end(), std::back_inserter(recentFilesVector));
|
std::copy(SharedData::recentFilePaths.begin(), SharedData::recentFilePaths.end(), std::back_inserter(recentFilesVector));
|
||||||
|
|
||||||
ContentRegistry::Settings::write("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files", recentFilesVector);
|
ContentRegistry::Settings::write("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files", recentFilesVector);
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ namespace hex {
|
|||||||
EventManager::post<EventSettingsChanged>();
|
EventManager::post<EventSettingsChanged>();
|
||||||
|
|
||||||
for (const auto &path : ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files"))
|
for (const auto &path : ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files"))
|
||||||
this->m_recentFiles.push_back(path);
|
SharedData::recentFilePaths.push_back(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
@ -430,8 +430,8 @@ namespace hex {
|
|||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::TextUnformatted("hex.welcome.start.recent"_lang);
|
ImGui::TextUnformatted("hex.welcome.start.recent"_lang);
|
||||||
{
|
{
|
||||||
if (!this->m_recentFiles.empty()) {
|
if (!SharedData::recentFilePaths.empty()) {
|
||||||
for (auto &path : this->m_recentFiles) {
|
for (auto &path : SharedData::recentFilePaths) {
|
||||||
if (ImGui::BulletHyperlink(std::filesystem::path(path).filename().string().c_str())) {
|
if (ImGui::BulletHyperlink(std::filesystem::path(path).filename().string().c_str())) {
|
||||||
EventManager::post<EventFileDropped>(path);
|
EventManager::post<EventFileDropped>(path);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user