diff --git a/src/composables/actions.ts b/src/composables/actions.ts index beb0a9a3d..3b60452f1 100644 --- a/src/composables/actions.ts +++ b/src/composables/actions.ts @@ -5,6 +5,7 @@ import { useRulerStore } from '../store/tools/rulers'; import { usePolygonStore } from '../store/tools/polygons'; import { Action } from '../constants'; import { useKeyboardShortcutsStore } from '../store/keyboard-shortcuts'; +import { useDatasetStore } from '../store/datasets'; const applyLabelOffset = (offset: number) => () => { const toolToStore = { @@ -36,6 +37,14 @@ const showKeyboardShortcuts = () => { keyboardStore.settingsOpen = !keyboardStore.settingsOpen; }; +const changeNextImage = () => () => { + useDatasetStore().changeNextImage(); +}; + +const changePreviousImage = () => () => { + useDatasetStore().changePreviousImage(); +}; + export const ACTION_TO_FUNC = { windowLevel: setTool(Tools.WindowLevel), pan: setTool(Tools.Pan), @@ -51,6 +60,9 @@ export const ACTION_TO_FUNC = { decrementLabel: applyLabelOffset(-1), incrementLabel: applyLabelOffset(1), + changeNextImage: changeNextImage(), + changePreviousImage: changePreviousImage(), + mergeNewPolygon: () => {}, // acts as a modifier key rather than immediate effect, so no-op showKeyboardShortcuts, diff --git a/src/config.ts b/src/config.ts index 5c4375c68..1bb755822 100644 --- a/src/config.ts +++ b/src/config.ts @@ -302,5 +302,8 @@ export const ACTION_TO_KEY = { decrementLabel: 'q', incrementLabel: 'w', + changeNextImage: 'arrowright', + changePreviousImage: 'arrowleft', + showKeyboardShortcuts: '?', } satisfies Record; diff --git a/src/constants.ts b/src/constants.ts index ebc62ce11..5d4062f7d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -60,6 +60,13 @@ export const ACTIONS = { readable: 'Activate next Label', }, + changeNextImage: { + readable: 'Next Image', + }, + changePreviousImage: { + readable: 'Previous Image', + }, + mergeNewPolygon: { readable: 'Hold down to merge new polygons with overlapping polygons', }, diff --git a/src/store/datasets.ts b/src/store/datasets.ts index e8f7e387f..7b59f213b 100644 --- a/src/store/datasets.ts +++ b/src/store/datasets.ts @@ -57,6 +57,37 @@ export const useDatasetStore = defineStore('dataset', () => { } } + function changeNextImage() { + if (!primaryImageID.value) return; + + const currentImageID = primaryImageID.value; + const { idList } = imageStore; + const maxIdx = idList.length - 1; + + let currentIdx = idList.indexOf(currentImageID); + if (currentIdx >= maxIdx) { + // Reset Idx to -1 as it will be increased later + currentIdx = -1; + } + + setPrimarySelection(idList[currentIdx + 1]); + } + + function changePreviousImage() { + if (!primaryImageID.value) return; + + const currentImageID = primaryImageID.value; + const { idList } = imageStore; + const maxIdx = idList.length - 1; + + let currentIdx = idList.indexOf(currentImageID); + if (currentIdx <= 0) { + currentIdx = maxIdx + 1; + } + + setPrimarySelection(idList[currentIdx - 1]); + } + async function serialize(stateFile: StateFile) { await dicomStore.serialize(stateFile); await imageStore.serialize(stateFile); @@ -87,6 +118,8 @@ export const useDatasetStore = defineStore('dataset', () => { primaryDataset, idsAsSelections, setPrimarySelection, + changeNextImage, + changePreviousImage, serialize, remove, };