From be69ddc5db5d37a0f882e4a53fadb497c1ce9840 Mon Sep 17 00:00:00 2001 From: Laurent Chauvin Date: Wed, 19 Jun 2024 11:37:37 -0400 Subject: [PATCH 1/2] feat(KeyboardShortcut): Add left and right arrow to cycle through images --- src/composables/actions.ts | 12 ++++++++++++ src/config.ts | 3 +++ src/constants.ts | 7 +++++++ src/store/datasets.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/src/composables/actions.ts b/src/composables/actions.ts index d481aa4d7..5096e57a9 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 = true; }; +const changeNextImage = () => () => { + useDatasetStore().changeNextImage(); +}; + +const changePreviousImage = () => () => { + useDatasetStore().changePreviousImage(); +}; + export const ACTION_TO_FUNC = { windowLevel: setTool(Tools.WindowLevel), pan: setTool(Tools.Pan), @@ -51,5 +60,8 @@ export const ACTION_TO_FUNC = { decrementLabel: applyLabelOffset(-1), incrementLabel: applyLabelOffset(1), + changeNextImage: changeNextImage(), + changePreviousImage: changePreviousImage(), + showKeyboardShortcuts, } as const satisfies Record void>; diff --git a/src/config.ts b/src/config.ts index fb564eeee..b223011c2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -301,5 +301,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 8212207b9..171cd2a10 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', + }, + showKeyboardShortcuts: { readable: 'Show keyboard shortcuts dialog', }, 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, }; From e92dd521d7c52cf9e3c6417f3fc048491584618f Mon Sep 17 00:00:00 2001 From: Laurent Chauvin Date: Thu, 10 Oct 2024 12:22:20 -0400 Subject: [PATCH 2/2] Fix capitalization issue --- src/config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index 6220f16d1..1bb755822 100644 --- a/src/config.ts +++ b/src/config.ts @@ -302,8 +302,8 @@ export const ACTION_TO_KEY = { decrementLabel: 'q', incrementLabel: 'w', - changeNextImage: 'ArrowRight', - changePreviousImage: 'ArrowLeft', + changeNextImage: 'arrowright', + changePreviousImage: 'arrowleft', showKeyboardShortcuts: '?', } satisfies Record;