Skip to content

Commit

Permalink
Added jump to selection start/end actions on HexViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorthiz committed Oct 18, 2024
1 parent 944f935 commit 0565c76
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {MenuItem} from "@imengyu/vue3-context-menu/lib/ContextMenuDefine";
import {h} from "vue";
import {useCurrentBinaryFileStore} from "../../../../Stores/CurrentBinaryFileStore";
import {BarsArrowDownIcon, BarsArrowUpIcon} from "@heroicons/vue/16/solid";
import {useHexViewerConfigStore} from "../../Store/HexViewerConfigStore";

export const HexViewerCtxActionJumpToSelection = (jumpToEnd: boolean = false): MenuItem => {
const currentBinaryFileStore = useCurrentBinaryFileStore();

const action = () => {
const hexViewerStore = useHexViewerConfigStore();
const jumpIndex = jumpToEnd
? currentBinaryFileStore.selectionEnd
: currentBinaryFileStore.selectionStart;
hexViewerStore.jumpToAddress(jumpIndex);
};

return {
label: jumpToEnd ? "Jump to selection end" : "Jump to selection start",
onClick: action,
customClass: "context-menu-item",
disabled: currentBinaryFileStore.selectionStart === -1 || currentBinaryFileStore.selectionEnd === -1,
icon: () => h(jumpToEnd ? BarsArrowDownIcon : BarsArrowUpIcon)
};
};
5 changes: 4 additions & 1 deletion src/Components/HexViewer/ContextMenu/HexViewerContextMenu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {MenuOptions} from "@imengyu/vue3-context-menu";
import {HexViewerCtxActionDownloadSelection} from "./Actions/HexViewerCtxActionDownloadSelection";
import {HexViewerCtxActionExportToJson} from "./Actions/HexViewerCtxActionExportToJson";
import {HexViewerCtxActionJumpToSelection} from "./Actions/HexViewerCtxActionJumpToSelection";

export const prepareContextMenuOptions = (e: MouseEvent): MenuOptions => {
return {
Expand All @@ -12,7 +13,9 @@ export const prepareContextMenuOptions = (e: MouseEvent): MenuOptions => {
items: [
HexViewerCtxActionDownloadSelection(),
HexViewerCtxActionExportToJson(false),
HexViewerCtxActionExportToJson(true)
HexViewerCtxActionExportToJson(true),
HexViewerCtxActionJumpToSelection(),
HexViewerCtxActionJumpToSelection(true)
]
};
};
6 changes: 5 additions & 1 deletion src/Components/HexViewer/HexViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ currentBinaryFileStore.$onAction(({name, store, args}) => {
|| handleOnPageReloadScrollToSelection(name, store, args, scrollTo);
});
hexViewerConfigStore.$onAction(({name, store, args}) => {
if(name !== "jumpToAddress") return;
const jumpIndex = args[0] as number;
scrollTo(Math.floor(jumpIndex / store.rowSize));
})
</script>

Expand Down
2 changes: 2 additions & 0 deletions src/Components/HexViewer/Store/HexViewerConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ export const useHexViewerConfigStore = defineStore("HexViewerStore", {
this.useHexForAddresses = addressMode;
serializeConfigToLocalStorage(this);
},
jumpToAddress(address: number) {
},
}
});

0 comments on commit 0565c76

Please sign in to comment.