impr: Handle read-only files more gracefully
This commit is contained in:
parent
9bfdfa149e
commit
4d91e7f347
@ -43,11 +43,17 @@ namespace hex::prv {
|
||||
}
|
||||
|
||||
void Provider::write(u64 offset, const void *buffer, size_t size) {
|
||||
if (!this->isWritable())
|
||||
return;
|
||||
|
||||
EventProviderDataModified::post(this, offset, size, static_cast<const u8*>(buffer));
|
||||
this->markDirty();
|
||||
}
|
||||
|
||||
void Provider::save() {
|
||||
if (!this->isWritable())
|
||||
return;
|
||||
|
||||
EventProviderSaved::post(this);
|
||||
}
|
||||
void Provider::saveAs(const std::fs::path &path) {
|
||||
|
@ -89,8 +89,12 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
|
||||
EventProviderOpened::subscribe([](hex::prv::Provider *provider) {
|
||||
if (provider != nullptr && ImHexApi::Provider::get() == provider)
|
||||
if (provider != nullptr && ImHexApi::Provider::get() == provider) {
|
||||
RequestUpdateWindowTitle::post();
|
||||
|
||||
if (!provider->isWritable())
|
||||
ui::ToastInfo::open("hex.builtin.popup.error.read_only"_lang);
|
||||
}
|
||||
});
|
||||
|
||||
RequestOpenFile::subscribe(openFile);
|
||||
|
@ -264,11 +264,10 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
// Enter editing mode when double-clicking the row
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && editingFunction.has_value()) {
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && editingFunction.has_value() && m_selectedProvider->isWritable()) {
|
||||
editing = true;
|
||||
m_editingValue = copyValue;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Handle editing mode
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace hex::plugin::builtin {
|
||||
(*m_patternDrawer)->jumpToPattern(pattern);
|
||||
});
|
||||
|
||||
m_patternDrawer.setOnCreateCallback([this](prv::Provider *, auto &drawer) {
|
||||
m_patternDrawer.setOnCreateCallback([this](prv::Provider *provider, auto &drawer) {
|
||||
drawer = std::make_unique<ui::PatternDrawer>();
|
||||
|
||||
drawer->setSelectionCallback([](const pl::ptrn::Pattern *pattern) {
|
||||
@ -47,6 +47,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
drawer->setTreeStyle(m_treeStyle);
|
||||
drawer->enableRowColoring(m_rowColoring);
|
||||
drawer->enablePatternEditing(provider->isWritable());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ namespace hex::ui {
|
||||
void setTreeStyle(TreeStyle style) { m_treeStyle = style; }
|
||||
void setSelectionCallback(std::function<void(const pl::ptrn::Pattern *)> callback) { m_selectionCallback = std::move(callback); }
|
||||
void enableRowColoring(bool enabled) { m_rowColoring = enabled; }
|
||||
void enablePatternEditing(bool enabled) { m_editingEnabled = enabled; }
|
||||
void reset();
|
||||
|
||||
void jumpToPattern(const pl::ptrn::Pattern *pattern) { m_jumpToPattern = pattern; }
|
||||
@ -103,6 +104,7 @@ namespace hex::ui {
|
||||
|
||||
TreeStyle m_treeStyle = TreeStyle::Default;
|
||||
bool m_rowColoring = false;
|
||||
bool m_editingEnabled = false;
|
||||
pl::ptrn::Pattern *m_currVisualizedPattern = nullptr;
|
||||
const pl::ptrn::Pattern *m_jumpToPattern = nullptr;
|
||||
|
||||
|
@ -411,7 +411,7 @@ namespace hex::ui {
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && m_editingEnabled) {
|
||||
m_editingPattern = &pattern;
|
||||
m_editingPatternOffset = pattern.getOffset();
|
||||
AchievementManager::unlockAchievement("hex.builtin.achievement.patterns", "hex.builtin.achievement.patterns.modify_data.name");
|
||||
|
Loading…
Reference in New Issue
Block a user