This commit is contained in:
Stephen Hewitt 2025-12-12 21:55:49 -07:00 committed by GitHub
commit 3d7236f6f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 7 deletions

View File

@ -64,6 +64,7 @@ namespace hex::plugin::builtin {
void convertToDirectAccess();
private:
void fileChangedCallback();
void handleFileChange();
bool open(bool memoryMapped);

View File

@ -237,7 +237,8 @@ namespace hex::plugin::builtin {
void registerMenuItems();
void registerHandlers();
void handleFileChange(prv::Provider *provider);
void fileChangedCallback(prv::Provider *provider, const std::fs::path &path);
void handleFileChange(prv::Provider *provider, const std::fs::path &path);
void openPatternFile(bool trackFile);
void savePatternToCurrentFile(bool trackFile);

View File

@ -277,7 +277,7 @@ namespace hex::plugin::builtin {
m_data = m_file.readVectorAtomic(0x00, m_fileSize);
if (!m_data.empty()) {
m_changeTracker = wolv::io::ChangeTracker(m_file);
m_changeTracker.startTracking([this]{ this->handleFileChange(); });
m_changeTracker.startTracking([this]{ this->fileChangedCallback(); });
m_file.close();
m_loadedIntoMemory = true;
}
@ -364,6 +364,14 @@ namespace hex::plugin::builtin {
this->open(true);
}
// WARNING: this function is called from the context of a worker thread!
void FileProvider::fileChangedCallback() {
// Arrange for a call from the UI thread
TaskManager::doLater(
[this]{this->handleFileChange();}
);
}
void FileProvider::handleFileChange() {
if (m_ignoreNextChangeEvent) {
m_ignoreNextChangeEvent = false;

View File

@ -1613,7 +1613,7 @@ namespace hex::plugin::builtin {
m_sourceCode.get(provider) = code;
if (trackFile) {
m_changeTracker.get(provider) = wolv::io::ChangeTracker(file);
m_changeTracker.get(provider).startTracking([this, provider]{ this->handleFileChange(provider); });
m_changeTracker.get(provider).startTracking([this, provider, path]{ this->fileChangedCallback(provider, path); });
}
m_textHighlighter.m_needsToUpdateColors = false;
TaskManager::createBackgroundTask("hex.builtin.task.parsing_pattern", [this, code, provider](auto&) { this->parsePattern(code, provider); });
@ -2534,7 +2534,15 @@ namespace hex::plugin::builtin {
});
}
void ViewPatternEditor::handleFileChange(prv::Provider *provider) {
// WARNING: this function is called from the context of a worker thread!
void ViewPatternEditor::fileChangedCallback(prv::Provider *provider, const std::fs::path &path) {
// Arrange for a call from the UI thread
TaskManager::doLater(
[this, provider, path]{this->handleFileChange(provider, path);}
);
}
void ViewPatternEditor::handleFileChange(prv::Provider *provider, const std::fs::path &path) {
if (m_ignoreNextChangeEvent.get(provider)) {
m_ignoreNextChangeEvent.get(provider) = false;
return;
@ -2545,9 +2553,10 @@ namespace hex::plugin::builtin {
}
m_changeEventAcknowledgementPending.get(provider) = true;
hex::ui::BannerButton::open(ICON_VS_INFO, "hex.builtin.provider.file.reload_changes", ImColor(66, 104, 135), "hex.builtin.provider.file.reload_changes.reload", [this, provider] {
m_changeEventAcknowledgementPending.get(provider) = false;
hex::ui::BannerButton::open(ICON_VS_INFO, "hex.builtin.provider.file.reload_changes", ImColor(66, 104, 135), "hex.builtin.provider.file.reload_changes.reload", [this, provider, path] {
loadPatternFile(path, provider, true);
});
m_changeEventAcknowledgementPending.get(provider) = false;
}
void ViewPatternEditor::openPatternFile(bool trackFile) {
@ -2617,7 +2626,7 @@ namespace hex::plugin::builtin {
if (trackFile) {
m_changeTracker.get(provider) = wolv::io::ChangeTracker(file);
m_changeTracker.get(provider).startTracking([this, provider]{ this->handleFileChange(provider); });
m_changeTracker.get(provider).startTracking([this, provider, path]{ this->fileChangedCallback(provider, path); });
m_ignoreNextChangeEvent.get(provider) = true;
}
}