Compare commits

..

No commits in common. "ab29303c2ea399cbb4a452265ec2012c6c2df225" and "d86be9d9b3895649548e5d45438a3de5156da059" have entirely different histories.

8 changed files with 16 additions and 43 deletions

View File

@ -126,7 +126,7 @@ namespace hex {
EVENT_DEF(RequestSelectionChange, Region);
EVENT_DEF(RequestAddBookmark, Region, std::string, std::string, color_t);
EVENT_DEF(RequestSetPatternLanguageCode, std::string);
EVENT_DEF(RequestUpdateWindowTitle);
EVENT_DEF(RequestChangeWindowTitle, std::string);
EVENT_DEF(RequestCloseImHex, bool);
EVENT_DEF(RequestRestartImHex);
EVENT_DEF(RequestOpenFile, std::fs::path);

View File

@ -34,8 +34,6 @@ namespace hex {
static bool store(std::optional<std::fs::path> filePath = std::nullopt);
static bool hasPath();
static void clearPath();
static std::fs::path getPath();
static void registerHandler(const Handler &handler) {
getHandlers().push_back(handler);

View File

@ -73,7 +73,7 @@ namespace hex {
}
ProjectFile::s_currProjectPath = filePath;
EventManager::post<RequestUpdateWindowTitle>();
return true;
}
@ -124,12 +124,4 @@ namespace hex {
return !ProjectFile::s_currProjectPath.empty();
}
void ProjectFile::clearPath() {
ProjectFile::s_currProjectPath.clear();
}
std::fs::path ProjectFile::getPath() {
return ProjectFile::s_currProjectPath;
}
}

View File

@ -115,19 +115,13 @@ namespace hex {
EventManager::post<EventWindowClosing>(this->m_window);
});
EventManager::subscribe<RequestUpdateWindowTitle>(this, [this]() {
EventManager::subscribe<RequestChangeWindowTitle>(this, [this](const std::string &windowTitle) {
std::string title = "ImHex";
if (ProjectFile::hasPath()) {
title += " - Project " + hex::limitStringLength(ProjectFile::getPath().stem().string(), 32);
if (ImHexApi::Provider::isDirty())
title += " (*)";
} else if (ImHexApi::Provider::isValid()) {
if (ImHexApi::Provider::isValid()) {
auto provider = ImHexApi::Provider::get();
if (provider != nullptr) {
title += " - " + hex::limitStringLength(provider->getName(), 32);
if (!windowTitle.empty() && provider != nullptr) {
title += " - " + hex::limitStringLength(windowTitle, 32);
if (provider->isDirty())
title += " (*)";
@ -183,7 +177,7 @@ namespace hex {
Window::~Window() {
EventManager::unsubscribe<EventProviderDeleted>(this);
EventManager::unsubscribe<RequestCloseImHex>(this);
EventManager::unsubscribe<RequestUpdateWindowTitle>(this);
EventManager::unsubscribe<RequestChangeWindowTitle>(this);
EventManager::unsubscribe<EventAbnormalTermination>(this);
EventManager::unsubscribe<RequestOpenPopup>(this);

View File

@ -44,14 +44,17 @@ namespace hex::plugin::builtin {
EventManager::subscribe<EventProviderChanged>([](hex::prv::Provider *oldProvider, hex::prv::Provider *newProvider) {
hex::unused(oldProvider);
hex::unused(newProvider);
EventManager::post<RequestUpdateWindowTitle>();
if (newProvider != nullptr && newProvider->isAvailable()) {
EventManager::post<RequestChangeWindowTitle>(newProvider->getName());
} else {
EventManager::post<RequestChangeWindowTitle>("");
}
});
EventManager::subscribe<EventProviderOpened>([](hex::prv::Provider *provider) {
if (provider != nullptr && ImHexApi::Provider::get() == provider)
EventManager::post<RequestUpdateWindowTitle>();
EventManager::post<RequestChangeWindowTitle>(provider->getName());
});
EventManager::subscribe<RequestOpenFile>(openFile);

View File

@ -1,7 +1,6 @@
#include <hex/ui/view.hpp>
#include <hex/api/project_file_manager.hpp>
#include <hex/helpers/logger.hpp>
namespace hex::plugin::builtin {
@ -16,12 +15,8 @@ namespace hex::plugin::builtin {
}
void saveProject() {
if (ImHexApi::Provider::isValid() && ProjectFile::hasPath()) {
if (!ProjectFile::store()) {
View::showErrorPopup("hex.builtin.popup.error.project.save"_lang);
} else {
log::debug("Project saved");
}
if (!ProjectFile::store()) {
View::showErrorPopup("hex.builtin.popup.error.project.save"_lang);
}
}

View File

@ -77,7 +77,7 @@ namespace hex::plugin::builtin {
openProject();
}
if (ImGui::MenuItem("hex.builtin.menu.file.save_project"_lang, "ALT + S", false, providerValid && ProjectFile::hasPath())) {
if (ImGui::MenuItem("hex.builtin.menu.file.save_project"_lang, "ALT + S", false, providerValid && provider->isWritable() && ProjectFile::hasPath())) {
saveProject();
}

View File

@ -500,15 +500,6 @@ 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, [&] {
if (ImGui::BeginMenu("hex.builtin.menu.file.open_recent"_lang, !s_recentProvidersUpdating && !s_recentProviders.empty())) {
// Copy to avoid changing list while iteration