1
0
mirror of synced 2024-11-28 09:30:51 +01:00

impr: Improve code quality

This commit is contained in:
WerWolv 2023-01-30 10:42:07 +01:00
parent 6b645192d4
commit 55d7d7c026
5 changed files with 9 additions and 28 deletions

View File

@ -22,7 +22,6 @@ namespace hex::plugin::builtin {
class PopupGoto : public ViewHexEditor::Popup { class PopupGoto : public ViewHexEditor::Popup {
public: public:
void draw(ViewHexEditor *editor) override { void draw(ViewHexEditor *editor) override {
ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.file.goto"_lang); ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.file.goto"_lang);
if (ImGui::BeginTabBar("goto_tabs")) { if (ImGui::BeginTabBar("goto_tabs")) {
@ -109,7 +108,6 @@ namespace hex::plugin::builtin {
void draw(ViewHexEditor *editor) override { void draw(ViewHexEditor *editor) override {
ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.file.select"_lang); ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.file.select"_lang);
if (ImGui::BeginTabBar("select_tabs")) { if (ImGui::BeginTabBar("select_tabs")) {
if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.select.offset.region"_lang)) { if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.select.offset.region"_lang)) {
u64 inputA = this->m_region.getStartAddress(); u64 inputA = this->m_region.getStartAddress();
u64 inputB = this->m_region.getEndAddress(); u64 inputB = this->m_region.getEndAddress();
@ -336,9 +334,7 @@ namespace hex::plugin::builtin {
class PopupBaseAddress : public ViewHexEditor::Popup { class PopupBaseAddress : public ViewHexEditor::Popup {
public: public:
explicit PopupBaseAddress(u64 baseAddress) : m_baseAddress(baseAddress) { explicit PopupBaseAddress(u64 baseAddress) : m_baseAddress(baseAddress) { }
}
void draw(ViewHexEditor *editor) override { void draw(ViewHexEditor *editor) override {
ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.edit.set_base"_lang); ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.edit.set_base"_lang);
@ -547,7 +543,6 @@ namespace hex::plugin::builtin {
ImGui::SetNextWindowPos(ImGui::GetWindowPos() + ImGui::GetWindowContentRegionMin() - ImGui::GetStyle().WindowPadding, ImGuiCond_Appearing); ImGui::SetNextWindowPos(ImGui::GetWindowPos() + ImGui::GetWindowContentRegionMin() - ImGui::GetStyle().WindowPadding, ImGuiCond_Appearing);
if (ImGui::BeginPopup("##hex_editor_popup", ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize |ImGuiWindowFlags_NoTitleBar)) { if (ImGui::BeginPopup("##hex_editor_popup", ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize |ImGuiWindowFlags_NoTitleBar)) {
// Force close the popup when user is editing an input // Force close the popup when user is editing an input
if(ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Escape))){ if(ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Escape))){
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
@ -568,7 +563,6 @@ namespace hex::plugin::builtin {
ImGui::OpenPopup("hex.builtin.menu.edit"_lang); ImGui::OpenPopup("hex.builtin.menu.edit"_lang);
if (ImGui::BeginPopup("hex.builtin.menu.edit"_lang)) { if (ImGui::BeginPopup("hex.builtin.menu.edit"_lang)) {
bool needsSeparator = false; bool needsSeparator = false;
for (auto &[priority, menuItem] : ContentRegistry::Interface::getMenuItems()) { for (auto &[priority, menuItem] : ContentRegistry::Interface::getMenuItems()) {
if (menuItem.unlocalizedName != "hex.builtin.menu.edit") if (menuItem.unlocalizedName != "hex.builtin.menu.edit")
@ -586,7 +580,6 @@ namespace hex::plugin::builtin {
} }
void ViewHexEditor::drawContent() { void ViewHexEditor::drawContent() {
if (ImGui::Begin(View::toWindowName(this->getUnlocalizedName()).c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { if (ImGui::Begin(View::toWindowName(this->getUnlocalizedName()).c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
this->m_hexEditor.setProvider(ImHexApi::Provider::get()); this->m_hexEditor.setProvider(ImHexApi::Provider::get());
@ -675,7 +668,6 @@ namespace hex::plugin::builtin {
} }
void ViewHexEditor::registerShortcuts() { void ViewHexEditor::registerShortcuts() {
// Save operations // Save operations
ShortcutManager::addShortcut(this, CTRLCMD + Keys::S, [] { ShortcutManager::addShortcut(this, CTRLCMD + Keys::S, [] {
save(); save();
@ -779,7 +771,6 @@ namespace hex::plugin::builtin {
this->setSelection(selection.getStartAddress() + this->m_hexEditor.getBytesPerRow(), selection.getEndAddress()); this->setSelection(selection.getStartAddress() + this->m_hexEditor.getBytesPerRow(), selection.getEndAddress());
this->m_hexEditor.scrollToSelection(); this->m_hexEditor.scrollToSelection();
this->m_hexEditor.jumpIfOffScreen(); this->m_hexEditor.jumpIfOffScreen();
}); });
ShortcutManager::addShortcut(this, SHIFT + Keys::Left, [this] { ShortcutManager::addShortcut(this, SHIFT + Keys::Left, [this] {
auto selection = getSelection(); auto selection = getSelection();
@ -989,7 +980,6 @@ namespace hex::plugin::builtin {
auto &customEncoding = this->m_hexEditor.getCustomEncoding(); auto &customEncoding = this->m_hexEditor.getCustomEncoding();
if (ImGui::MenuItem("hex.builtin.view.hex_editor.copy.custom_encoding"_lang, "", false, customEncoding.has_value())) { if (ImGui::MenuItem("hex.builtin.view.hex_editor.copy.custom_encoding"_lang, "", false, customEncoding.has_value())) {
std::vector<u8> buffer(customEncoding->getLongestSequence(), 0x00); std::vector<u8> buffer(customEncoding->getLongestSequence(), 0x00);
std::string string; std::string string;

View File

@ -155,9 +155,7 @@ namespace hex::plugin::builtin::ui {
if (padding.is_number()) if (padding.is_number())
this->m_characterCellPadding = static_cast<int>(padding); this->m_characterCellPadding = static_cast<int>(padding);
} }
}); });
} }
HexEditor::~HexEditor() { HexEditor::~HexEditor() {
@ -277,7 +275,6 @@ namespace hex::plugin::builtin::ui {
shouldExitEditingMode = asciiVisualizer.drawEditing(*this->m_editingAddress, this->m_editingBytes.data(), this->m_editingBytes.size(), this->m_upperCaseHex, this->m_enteredEditingMode); shouldExitEditingMode = asciiVisualizer.drawEditing(*this->m_editingAddress, this->m_editingBytes.data(), this->m_editingBytes.size(), this->m_upperCaseHex, this->m_enteredEditingMode);
if (shouldExitEditingMode || this->m_shouldModifyValue) { if (shouldExitEditingMode || this->m_shouldModifyValue) {
this->m_provider->write(*this->m_editingAddress, this->m_editingBytes.data(), this->m_editingBytes.size()); this->m_provider->write(*this->m_editingAddress, this->m_editingBytes.data(), this->m_editingBytes.size());
if (!this->m_selectionChanged && !ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { if (!this->m_selectionChanged && !ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
@ -378,7 +375,6 @@ namespace hex::plugin::builtin::ui {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (this->m_provider != nullptr && this->m_provider->isReadable()) { if (this->m_provider != nullptr && this->m_provider->isReadable()) {
const auto isCurrRegionValid = [this](u64 address){ const auto isCurrRegionValid = [this](u64 address){
auto &[currRegion, currRegionValid] = this->m_currValidRegion; auto &[currRegion, currRegionValid] = this->m_currValidRegion;
if (!Region{ address, 1 }.isWithin(currRegion)) { if (!Region{ address, 1 }.isWithin(currRegion)) {
@ -396,7 +392,6 @@ namespace hex::plugin::builtin::ui {
// Loop over rows // Loop over rows
for (u64 y = u64(clipper.DisplayStart); y < u64(clipper.DisplayEnd); y++) { for (u64 y = u64(clipper.DisplayStart); y < u64(clipper.DisplayEnd); y++) {
// Draw address column // Draw address column
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@ -610,7 +605,6 @@ namespace hex::plugin::builtin::ui {
} }
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::PopID(); ImGui::PopID();
} }
// Scroll to the cursor if it's either at the top or bottom edge of the screen // Scroll to the cursor if it's either at the top or bottom edge of the screen
@ -623,7 +617,6 @@ namespace hex::plugin::builtin::ui {
if (i128(this->m_selectionEnd.value() - this->m_provider->getBaseAddress() - this->m_provider->getCurrentPageAddress()) <= (i64(clipper.DisplayStart + 3) * this->m_bytesPerRow)) { if (i128(this->m_selectionEnd.value() - this->m_provider->getBaseAddress() - this->m_provider->getCurrentPageAddress()) <= (i64(clipper.DisplayStart + 3) * this->m_bytesPerRow)) {
this->m_shouldScrollToSelection = false; this->m_shouldScrollToSelection = false;
ImGui::SetScrollHereY(fractionPerLine * 5); ImGui::SetScrollHereY(fractionPerLine * 5);
} }
} else if (y == (u64(clipper.DisplayEnd) - 1)) { } else if (y == (u64(clipper.DisplayEnd) - 1)) {
if (i128(this->m_selectionEnd.value() - this->m_provider->getBaseAddress() - this->m_provider->getCurrentPageAddress()) >= (i64(clipper.DisplayEnd - 2) * this->m_bytesPerRow)) { if (i128(this->m_selectionEnd.value() - this->m_provider->getBaseAddress() - this->m_provider->getCurrentPageAddress()) >= (i64(clipper.DisplayEnd - 2) * this->m_bytesPerRow)) {
@ -645,7 +638,6 @@ namespace hex::plugin::builtin::ui {
this->jumpToSelection(false); this->jumpToSelection(false);
if ((newSelection.getEndAddress()) > u64(clipper.DisplayEnd * this->m_bytesPerRow)) if ((newSelection.getEndAddress()) > u64(clipper.DisplayEnd * this->m_bytesPerRow))
this->jumpToSelection(false); this->jumpToSelection(false);
} }
} }
} }
@ -759,7 +751,6 @@ namespace hex::plugin::builtin::ui {
ImGui::EndTable(); ImGui::EndTable();
} }
} }
ImGui::EndChild(); ImGui::EndChild();
} }