1
0
mirror of synced 2024-09-25 03:58:27 +02:00

ui: Added recent files to File menu

This commit is contained in:
WerWolv 2021-04-13 08:41:59 +02:00
parent 1e6b493b41
commit 8a485575f5
9 changed files with 42 additions and 29 deletions

View File

@ -53,8 +53,6 @@ namespace hex {
double m_lastFrameTime;
static inline std::tuple<int, int> s_currShortcut = { -1, -1 };
std::list<std::string> m_recentFiles;
};
}

View File

@ -153,6 +153,7 @@ namespace hex::plugin::builtin {
{ "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_recent", "Kürzlich geöffnete Dateien"},
{ "hex.view.hexeditor.menu.file.save", "Speichern" },
{ "hex.view.hexeditor.menu.file.save_as", "Speichern unter..." },
{ "hex.view.hexeditor.menu.file.close", "Schliessen" },

View File

@ -153,6 +153,7 @@ namespace hex::plugin::builtin {
{ "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_recent", "Open Recent"},
{ "hex.view.hexeditor.menu.file.save", "Save" },
{ "hex.view.hexeditor.menu.file.save_as", "Save As..." },
{ "hex.view.hexeditor.menu.file.close", "Close" },

View File

@ -136,6 +136,7 @@ namespace hex::plugin::builtin {
{ "hex.view.hexeditor.name", "Hex editor" },
{ "hex.view.hexeditor.save_changes", "Salva le modifiche" },
{ "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.save_project", "Salva i Progetti" },
{ "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.save", "Salva" },
{ "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.save_project", "Salva Progetto..." },
{ "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.language", "Lingua" },
{ "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.size", "Dimensione" },

View File

@ -69,6 +69,8 @@ namespace hex {
static std::vector<ContentRegistry::DataProcessorNode::Entry> dataProcessorNodes;
static u32 dataProcessorNodeIdCounter;
static std::list<std::string> recentFilePaths;
static int mainArgc;
static char **mainArgv;

View File

@ -25,6 +25,8 @@ namespace hex {
std::vector<ContentRegistry::DataProcessorNode::Entry> SharedData::dataProcessorNodes;
u32 SharedData::dataProcessorNodeIdCounter = 1;
std::list<std::string> SharedData::recentFilePaths;
int SharedData::mainArgc;
char **SharedData::mainArgv;

View File

@ -130,6 +130,7 @@ namespace hex {
EventManager::subscribe<EventFileDropped>(this, [this](const std::string &filePath) {
this->openFile(filePath);
this->getWindowOpenState() = true;
});
EventManager::subscribe<RequestSelectionChange>(this, [this](Region region) {
@ -144,7 +145,7 @@ namespace hex {
});
EventManager::subscribe<EventProjectFileLoad>(this, [this]() {
this->openFile(ProjectFile::getFilePath());
EventManager::post<EventFileDropped>(ProjectFile::getFilePath());
});
EventManager::subscribe<EventWindowClosing>(this, [](GLFWwindow *window) {
@ -319,18 +320,18 @@ namespace hex {
ImGui::NewLine();
confirmButtons("hex.common.load"_lang, "hex.common.cancel"_lang,
[this, &provider] {
if (!this->m_loaderScriptScriptPath.empty() && !this->m_loaderScriptFilePath.empty()) {
this->openFile(this->m_loaderScriptFilePath);
LoaderScript::setFilePath(this->m_loaderScriptFilePath);
LoaderScript::setDataProvider(provider);
LoaderScript::processFile(this->m_loaderScriptScriptPath);
ImGui::CloseCurrentPopup();
}
},
[] {
ImGui::CloseCurrentPopup();
}
[this, &provider] {
if (!this->m_loaderScriptScriptPath.empty() && !this->m_loaderScriptFilePath.empty()) {
EventManager::post<EventFileDropped>(this->m_loaderScriptFilePath);
LoaderScript::setFilePath(this->m_loaderScriptFilePath);
LoaderScript::setDataProvider(provider);
LoaderScript::processFile(this->m_loaderScriptScriptPath);
ImGui::CloseCurrentPopup();
}
},
[] {
ImGui::CloseCurrentPopup();
}
);
ImGui::EndPopup();
@ -363,11 +364,20 @@ namespace hex {
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) {
this->openFile(path);
this->getWindowOpenState() = true;
EventManager::post<EventFileDropped>(path);
});
}
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())) {
save();
}
@ -376,7 +386,7 @@ namespace hex {
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>();
delete SharedData::currentProvider;
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) {
ProjectFile::load(path);
EventManager::post<EventProjectFileLoad>();
this->getWindowOpenState() = true;
});
}

View File

@ -14,7 +14,6 @@
#include <imgui_imhex_extensions.h>
#include <implot.h>
#include <implot_internal.h>
namespace hex {

View File

@ -112,11 +112,11 @@ namespace hex {
});
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;
for (auto &file : this->m_recentFiles) {
for (auto &file : SharedData::recentFilePaths) {
bool exists = false;
for (auto &unique : uniques) {
@ -130,12 +130,12 @@ namespace hex {
if (uniques.size() > 5)
break;
}
this->m_recentFiles = uniques;
SharedData::recentFilePaths = uniques;
}
{
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);
}
@ -158,7 +158,7 @@ namespace hex {
EventManager::post<EventSettingsChanged>();
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() {
@ -430,8 +430,8 @@ namespace hex {
ImGui::TableNextColumn();
ImGui::TextUnformatted("hex.welcome.start.recent"_lang);
{
if (!this->m_recentFiles.empty()) {
for (auto &path : this->m_recentFiles) {
if (!SharedData::recentFilePaths.empty()) {
for (auto &path : SharedData::recentFilePaths) {
if (ImGui::BulletHyperlink(std::filesystem::path(path).filename().string().c_str())) {
EventManager::post<EventFileDropped>(path);
break;