sys: Clear project context when closing all providers, Display project name in window title (#860)
* clear project context when closing all providers * Show project name on window title * refactor RequestChangeWindowTitle to RequestUpdateWindowTitle * add spaces
This commit is contained in:
parent
ed831c6fc9
commit
ab29303c2e
@ -126,7 +126,7 @@ namespace hex {
|
|||||||
EVENT_DEF(RequestSelectionChange, Region);
|
EVENT_DEF(RequestSelectionChange, Region);
|
||||||
EVENT_DEF(RequestAddBookmark, Region, std::string, std::string, color_t);
|
EVENT_DEF(RequestAddBookmark, Region, std::string, std::string, color_t);
|
||||||
EVENT_DEF(RequestSetPatternLanguageCode, std::string);
|
EVENT_DEF(RequestSetPatternLanguageCode, std::string);
|
||||||
EVENT_DEF(RequestChangeWindowTitle, std::string);
|
EVENT_DEF(RequestUpdateWindowTitle);
|
||||||
EVENT_DEF(RequestCloseImHex, bool);
|
EVENT_DEF(RequestCloseImHex, bool);
|
||||||
EVENT_DEF(RequestRestartImHex);
|
EVENT_DEF(RequestRestartImHex);
|
||||||
EVENT_DEF(RequestOpenFile, std::fs::path);
|
EVENT_DEF(RequestOpenFile, std::fs::path);
|
||||||
|
@ -34,6 +34,8 @@ namespace hex {
|
|||||||
static bool store(std::optional<std::fs::path> filePath = std::nullopt);
|
static bool store(std::optional<std::fs::path> filePath = std::nullopt);
|
||||||
|
|
||||||
static bool hasPath();
|
static bool hasPath();
|
||||||
|
static void clearPath();
|
||||||
|
static std::fs::path getPath();
|
||||||
|
|
||||||
static void registerHandler(const Handler &handler) {
|
static void registerHandler(const Handler &handler) {
|
||||||
getHandlers().push_back(handler);
|
getHandlers().push_back(handler);
|
||||||
|
@ -73,7 +73,7 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProjectFile::s_currProjectPath = filePath;
|
ProjectFile::s_currProjectPath = filePath;
|
||||||
|
EventManager::post<RequestUpdateWindowTitle>();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,4 +124,12 @@ namespace hex {
|
|||||||
return !ProjectFile::s_currProjectPath.empty();
|
return !ProjectFile::s_currProjectPath.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectFile::clearPath() {
|
||||||
|
ProjectFile::s_currProjectPath.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::fs::path ProjectFile::getPath() {
|
||||||
|
return ProjectFile::s_currProjectPath;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -115,13 +115,19 @@ namespace hex {
|
|||||||
EventManager::post<EventWindowClosing>(this->m_window);
|
EventManager::post<EventWindowClosing>(this->m_window);
|
||||||
});
|
});
|
||||||
|
|
||||||
EventManager::subscribe<RequestChangeWindowTitle>(this, [this](const std::string &windowTitle) {
|
EventManager::subscribe<RequestUpdateWindowTitle>(this, [this]() {
|
||||||
std::string title = "ImHex";
|
std::string title = "ImHex";
|
||||||
|
|
||||||
if (ImHexApi::Provider::isValid()) {
|
if (ProjectFile::hasPath()) {
|
||||||
|
title += " - Project " + hex::limitStringLength(ProjectFile::getPath().stem().string(), 32);
|
||||||
|
|
||||||
|
if (ImHexApi::Provider::isDirty())
|
||||||
|
title += " (*)";
|
||||||
|
|
||||||
|
} else if (ImHexApi::Provider::isValid()) {
|
||||||
auto provider = ImHexApi::Provider::get();
|
auto provider = ImHexApi::Provider::get();
|
||||||
if (!windowTitle.empty() && provider != nullptr) {
|
if (provider != nullptr) {
|
||||||
title += " - " + hex::limitStringLength(windowTitle, 32);
|
title += " - " + hex::limitStringLength(provider->getName(), 32);
|
||||||
|
|
||||||
if (provider->isDirty())
|
if (provider->isDirty())
|
||||||
title += " (*)";
|
title += " (*)";
|
||||||
@ -177,7 +183,7 @@ namespace hex {
|
|||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
EventManager::unsubscribe<EventProviderDeleted>(this);
|
EventManager::unsubscribe<EventProviderDeleted>(this);
|
||||||
EventManager::unsubscribe<RequestCloseImHex>(this);
|
EventManager::unsubscribe<RequestCloseImHex>(this);
|
||||||
EventManager::unsubscribe<RequestChangeWindowTitle>(this);
|
EventManager::unsubscribe<RequestUpdateWindowTitle>(this);
|
||||||
EventManager::unsubscribe<EventAbnormalTermination>(this);
|
EventManager::unsubscribe<EventAbnormalTermination>(this);
|
||||||
EventManager::unsubscribe<RequestOpenPopup>(this);
|
EventManager::unsubscribe<RequestOpenPopup>(this);
|
||||||
|
|
||||||
|
@ -44,17 +44,14 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
EventManager::subscribe<EventProviderChanged>([](hex::prv::Provider *oldProvider, hex::prv::Provider *newProvider) {
|
EventManager::subscribe<EventProviderChanged>([](hex::prv::Provider *oldProvider, hex::prv::Provider *newProvider) {
|
||||||
hex::unused(oldProvider);
|
hex::unused(oldProvider);
|
||||||
|
hex::unused(newProvider);
|
||||||
|
|
||||||
if (newProvider != nullptr && newProvider->isAvailable()) {
|
EventManager::post<RequestUpdateWindowTitle>();
|
||||||
EventManager::post<RequestChangeWindowTitle>(newProvider->getName());
|
|
||||||
} else {
|
|
||||||
EventManager::post<RequestChangeWindowTitle>("");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
EventManager::subscribe<EventProviderOpened>([](hex::prv::Provider *provider) {
|
EventManager::subscribe<EventProviderOpened>([](hex::prv::Provider *provider) {
|
||||||
if (provider != nullptr && ImHexApi::Provider::get() == provider)
|
if (provider != nullptr && ImHexApi::Provider::get() == provider)
|
||||||
EventManager::post<RequestChangeWindowTitle>(provider->getName());
|
EventManager::post<RequestUpdateWindowTitle>();
|
||||||
});
|
});
|
||||||
|
|
||||||
EventManager::subscribe<RequestOpenFile>(openFile);
|
EventManager::subscribe<RequestOpenFile>(openFile);
|
||||||
|
@ -500,6 +500,15 @@ namespace hex::plugin::builtin {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// clear project context if we go back to the welcome screen
|
||||||
|
EventManager::subscribe<EventProviderChanged>([](hex::prv::Provider *oldProvider, hex::prv::Provider *newProvider) {
|
||||||
|
hex::unused(oldProvider);
|
||||||
|
if (newProvider == nullptr) {
|
||||||
|
ProjectFile::clearPath();
|
||||||
|
EventManager::post<RequestUpdateWindowTitle>();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1075, [&] {
|
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1075, [&] {
|
||||||
if (ImGui::BeginMenu("hex.builtin.menu.file.open_recent"_lang, !s_recentProvidersUpdating && !s_recentProviders.empty())) {
|
if (ImGui::BeginMenu("hex.builtin.menu.file.open_recent"_lang, !s_recentProvidersUpdating && !s_recentProviders.empty())) {
|
||||||
// Copy to avoid changing list while iteration
|
// Copy to avoid changing list while iteration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user