impr: Save most of the hex editor settings

#2398
This commit is contained in:
WerWolv
2025-08-11 21:03:18 +02:00
parent e9d95c78f6
commit 09b2e20a3d
5 changed files with 125 additions and 4 deletions

View File

@@ -573,6 +573,40 @@ namespace hex::plugin::builtin {
showHighlights = value.get<bool>(true);
});
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.gray_out_zeros", [this](const ContentRegistry::Settings::SettingsValue &value) {
m_hexEditor.enableGrayOutZeros(value.get<bool>(true));
});
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.upper_case_hex", [this](const ContentRegistry::Settings::SettingsValue &value) {
m_hexEditor.enableUpperCaseHex(value.get<bool>(true));
});
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.show_ascii", [this](const ContentRegistry::Settings::SettingsValue &value) {
m_hexEditor.enableShowAscii(value.get<bool>(true));
});
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.show_extended_ascii", [this](const ContentRegistry::Settings::SettingsValue &value) {
m_hexEditor.enableShowExtendedAscii(value.get<bool>(true));
});
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.minimap", [this](const ContentRegistry::Settings::SettingsValue &value) {
m_hexEditor.setMiniMapVisualizer(value.get<std::string>(""));
});
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.minimap_width", [this](const ContentRegistry::Settings::SettingsValue &value) {
m_hexEditor.setMiniMapWidth(value.get<int>(m_hexEditor.getMiniMapWidth()));
});
ContentRegistry::Settings::onSave([this] {
ContentRegistry::Settings::write<int>("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.bytes_per_row", m_hexEditor.getBytesPerRow());
ContentRegistry::Settings::write<bool>("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.gray_out_zeros", m_hexEditor.shouldGrayOutZeros());
ContentRegistry::Settings::write<bool>("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.upper_case_hex", m_hexEditor.shouldUpperCaseHex());
ContentRegistry::Settings::write<bool>("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.show_ascii", m_hexEditor.shouldShowAscii());
ContentRegistry::Settings::write<bool>("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.show_extended_ascii", m_hexEditor.shouldShowExtendedAscii());
ContentRegistry::Settings::write<std::string>("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.minimap", m_hexEditor.getMiniMapVisualizer().value_or(""));
ContentRegistry::Settings::write<int>("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.minimap_width", m_hexEditor.getMiniMapWidth());
});
m_hexEditor.setBackgroundHighlightCallback([this](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
if (!showHighlights)
return std::nullopt;
@@ -659,8 +693,7 @@ namespace hex::plugin::builtin {
EventProviderChanged::unsubscribe(this);
EventProviderOpened::unsubscribe(this);
EventHighlightingChanged::unsubscribe(this);
ContentRegistry::Settings::write<int>("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.bytes_per_row", m_hexEditor.getBytesPerRow());
EventImHexClosing::unsubscribe(this);
}
void ViewHexEditor::drawPopup() {
@@ -1138,7 +1171,9 @@ namespace hex::plugin::builtin {
}
});
m_hexEditor.setBytesPerRow(ContentRegistry::Settings::read<int>("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.bytes_per_row", m_hexEditor.getBytesPerRow()));
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.bytes_per_row", [this](const ContentRegistry::Settings::SettingsValue &value) {
m_hexEditor.setBytesPerRow(value.get<int>(m_hexEditor.getBytesPerRow()));
});
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.highlight_color", [this](const ContentRegistry::Settings::SettingsValue &value) {
m_hexEditor.setSelectionColor(value.get<int>(0x60C08080));
});

View File

@@ -233,14 +233,34 @@ namespace hex::ui {
m_upperCaseHex = upperCaseHex;
}
bool shouldUpperCaseHex() const {
return m_upperCaseHex;
}
void enableGrayOutZeros(bool grayOutZeros) {
m_grayOutZero = grayOutZeros;
}
bool shouldGrayOutZeros() const {
return m_grayOutZero;
}
void enableShowAscii(bool showAscii) {
m_showAscii = showAscii;
}
bool shouldShowAscii() const {
return m_showAscii;
}
void enableShowExtendedAscii(bool showExtendedAscii) {
m_showExtendedAscii = showExtendedAscii;
}
bool shouldShowExtendedAscii() const {
return m_showExtendedAscii;
}
void enableSyncScrolling(bool syncScrolling) {
m_scrollPosition.setSynced(syncScrolling);
}
@@ -253,6 +273,39 @@ namespace hex::ui {
m_characterCellPadding = characterCellPadding;
}
void setMiniMapWidth(int miniMapWidth) {
m_miniMapWidth = miniMapWidth;
}
[[nodiscard]] bool isMiniMapVisible() const {
return m_showMiniMap;
}
int getMiniMapWidth() const {
return m_miniMapWidth;
}
std::optional<std::string> getMiniMapVisualizer() const {
if (!m_showMiniMap)
return std::nullopt;
return m_miniMapVisualizer->unlocalizedName;
}
void setMiniMapVisualizer(const UnlocalizedString &miniMapVisualizerName) {
if (miniMapVisualizerName.empty()) {
m_showMiniMap = false;
m_miniMapVisualizer = nullptr;
} else {
for (const auto &visualizer : ContentRegistry::HexEditor::impl::getMiniMapVisualizers()) {
if (visualizer->unlocalizedName == miniMapVisualizerName) {
m_miniMapVisualizer = visualizer;
m_showMiniMap = true;
return;
}
}
}
}
[[nodiscard]] const std::optional<EncodingFile>& getCustomEncoding() const {
return m_currCustomEncoding;
}