improv: made the text editors to be per provider. (#2255)

The recent update that made importing patterns undoable had the side
effect of undoing tab changes as well. When working on a fix for that it
became clear that the undo/redo stacks were being shared by all
providers so that you could undo changes done in a separate file. The
problem was fixed by making the text editors (and the console editors as
well) to be per provider which gives better control on things like
breakpoints and selections and a more robust focusing system that
preserves the cursor positions and removes the need to click on a
pattern to start editing. There are a lot of changes, but they are
mostly all the uses of text editors being now coded differently to
manage the providers. File imports are still undoable, but switching
providers is not.
Further changes suggested by reviewer were implemented namely a mull provider was being used and there was a get function missing which prevented the use of the preferred syntax.
This commit is contained in:
paxcut
2025-05-17 11:26:54 -07:00
committed by GitHub
parent d263962a06
commit 57c2d84122
4 changed files with 188 additions and 160 deletions

View File

@@ -34,18 +34,18 @@ namespace hex::plugin::builtin {
class PatternSourceCode {
public:
const std::string& get(prv::Provider *provider) {
const std::string& get(prv::Provider *provider) const {
if (m_synced)
return m_sharedSource;
return m_perProviderSource.get(provider);
}
void set(prv::Provider *provider, std::string source) {
source = wolv::util::trim(source);
std::string& get(prv::Provider *provider) {
if (m_synced)
return m_sharedSource;
m_perProviderSource.set(source, provider);
m_sharedSource = std::move(source);
return m_perProviderSource.get(provider);
}
bool isSynced() const {
@@ -233,10 +233,10 @@ namespace hex::plugin::builtin {
std::atomic<u32> m_runningEvaluators = 0;
std::atomic<u32> m_runningParsers = 0;
bool m_hasUnevaluatedChanges = false;
PerProvider<bool> m_hasUnevaluatedChanges;
std::chrono::time_point<std::chrono::steady_clock> m_lastEditorChangeTime;
TextEditor m_textEditor, m_consoleEditor;
PerProvider<TextEditor> m_textEditor, m_consoleEditor;
std::atomic<bool> m_consoleNeedsUpdate = false;
std::atomic<bool> m_dangerousFunctionCalled = false;
@@ -259,6 +259,8 @@ namespace hex::plugin::builtin {
PerProvider<TextEditor::Coordinates> m_cursorPosition;
PerProvider<TextEditor::Coordinates> m_consoleCursorPosition;
PerProvider<bool> m_cursorNeedsUpdate;
PerProvider<bool> m_consoleCursorNeedsUpdate;
PerProvider<TextEditor::Selection> m_selection;
PerProvider<TextEditor::Selection> m_consoleSelection;
PerProvider<size_t> m_consoleLongestLineLength;
@@ -379,11 +381,12 @@ namespace hex::plugin::builtin {
};
std::function<void()> m_exportPatternFile = [this] {
auto provider = ImHexApi::Provider::get();
fs::openFileBrowser(
fs::DialogMode::Save, { {"Pattern", "hexpat"} },
[this](const auto &path) {
[this, provider](const auto &path) {
wolv::io::File file(path, wolv::io::File::Mode::Create);
file.writeString(wolv::util::trim(m_textEditor.GetText()));
file.writeString(wolv::util::trim(m_textEditor.get(provider).GetText()));
}
);
};