1
0
mirror of synced 2024-11-24 15:50:16 +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

@ -38,7 +38,7 @@ jobs:
path: |
build/CMakeCache.txt
key: ${{ runner.os }}-analysis-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
- name: ⬇️ Install dependencies
run: |
sudo apt update

View File

@ -34,7 +34,7 @@ jobs:
- name: 🗜️ Create tarball from sources with dependencies
run: tar --exclude-vcs -czvf Full.Sources.tar.gz ImHex
- name: ⬇️ Download artifacts from latest workflow
uses: dawidd6/action-download-artifact@v2
with:
@ -43,7 +43,7 @@ jobs:
branch: ${{ github.event.release.target_commitish }}
workflow_conclusion: success
skip_unpack: true
- name: 🗜️ Unzip files when needed
run: |
for zipfile in ./*.zip
@ -71,14 +71,14 @@ jobs:
- name: ✒️ Prepare PKGBUILD
run: |
cp ImHex/dist/Arch/PKGBUILD .
hash=`md5sum imhex-${{env.IMHEX_VERSION}}-ArchLinux.pkg.tar.zst-x86_64 | cut -d ' ' -f 1`
sed -i 's/%version%/${{env.IMHEX_VERSION}}/g' PKGBUILD
sed -i "s/(SKIP)/($hash)/g" PKGBUILD
- name: ⬆️ Publish AUR package
# I couldn't make the condition in the env directly for some reason
env:
AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
@ -113,7 +113,7 @@ jobs:
tag: ImHex-v${{env.IMHEX_VERSION}}
repo: ImHex-Patterns
token: ${{ secrets.RELEASE_TOKEN }}
- name: ✉️ Update C++ Plugin Template
uses: peter-evans/repository-dispatch@v2
env:

View File

@ -28,7 +28,7 @@ jobs:
key: ${{ runner.os }}-tests-${{ secrets.CACHE_VERSION }}-build-${{ github.run_id }}
restore-keys: ${{ runner.os }}-tests-${{ secrets.CACHE_VERSION }}-build
max-size: 50M
- name: 📜 Restore CMakeCache
uses: actions/cache@v3
@ -36,7 +36,7 @@ jobs:
path: |
build/CMakeCache.txt
key: ${{ runner.os }}-tests-${{ secrets.CACHE_VERSION }}-build-${{ hashFiles('**/CMakeLists.txt') }}
- name: ⬇️ Install dependencies
run: |
sudo apt update

View File

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

View File

@ -155,9 +155,7 @@ namespace hex::plugin::builtin::ui {
if (padding.is_number())
this->m_characterCellPadding = static_cast<int>(padding);
}
});
}
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);
if (shouldExitEditingMode || this->m_shouldModifyValue) {
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)) {
@ -378,7 +375,6 @@ namespace hex::plugin::builtin::ui {
ImGui::TableNextColumn();
if (this->m_provider != nullptr && this->m_provider->isReadable()) {
const auto isCurrRegionValid = [this](u64 address){
auto &[currRegion, currRegionValid] = this->m_currValidRegion;
if (!Region{ address, 1 }.isWithin(currRegion)) {
@ -396,7 +392,6 @@ namespace hex::plugin::builtin::ui {
// Loop over rows
for (u64 y = u64(clipper.DisplayStart); y < u64(clipper.DisplayEnd); y++) {
// Draw address column
ImGui::TableNextRow();
ImGui::TableNextColumn();
@ -610,7 +605,6 @@ namespace hex::plugin::builtin::ui {
}
ImGui::PopStyleVar();
ImGui::PopID();
}
// 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)) {
this->m_shouldScrollToSelection = false;
ImGui::SetScrollHereY(fractionPerLine * 5);
}
} 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)) {
@ -645,7 +638,6 @@ namespace hex::plugin::builtin::ui {
this->jumpToSelection(false);
if ((newSelection.getEndAddress()) > u64(clipper.DisplayEnd * this->m_bytesPerRow))
this->jumpToSelection(false);
}
}
}
@ -759,7 +751,6 @@ namespace hex::plugin::builtin::ui {
ImGui::EndTable();
}
}
ImGui::EndChild();
}