ux: Show currently loaded file name in window name

This commit is contained in:
WerWolv 2021-03-29 22:44:23 +02:00
parent f263685e44
commit 0cc7004d0d
3 changed files with 15 additions and 0 deletions

View File

@ -110,6 +110,7 @@ namespace hex {
EVENT_DEF(RequestSelectionChange, Region);
EVENT_DEF(RequestAddBookmark, ImHexApi::Bookmarks::Entry);
EVENT_DEF(RequestAppendPatternLanguageCode, std::string);
EVENT_DEF(RequestChangeWindowTitle, std::string);
EVENT_DEF(RequestCloseImHex);
}

View File

@ -14,6 +14,8 @@
#undef __STRICT_ANSI__
#include <cstdio>
#include <filesystem>
namespace hex {
ViewHexEditor::ViewHexEditor(std::vector<lang::PatternData*> &patternData)
@ -171,6 +173,10 @@ namespace hex {
});
}
});
EventManager::subscribe<EventFileLoaded>(this, [](std::string path) {
EventManager::post<RequestChangeWindowTitle>(std::filesystem::path(path).filename().string());
});
}
ViewHexEditor::~ViewHexEditor() {

View File

@ -138,6 +138,13 @@ namespace hex {
glfwSetWindowShouldClose(this->m_window, true);
});
EventManager::subscribe<RequestChangeWindowTitle>(this, [this](std::string windowTitle) {
if (windowTitle.empty())
glfwSetWindowTitle(this->m_window, "ImHex");
else
glfwSetWindowTitle(this->m_window, ("ImHex - " + windowTitle).c_str());
});
this->initPlugins();
ContentRegistry::Settings::load();
@ -163,6 +170,7 @@ namespace hex {
EventManager::unsubscribe<EventSettingsChanged>(this);
EventManager::unsubscribe<EventFileLoaded>(this);
EventManager::unsubscribe<RequestCloseImHex>(this);
EventManager::unsubscribe<RequestChangeWindowTitle>(this);
}
void Window::loop() {