Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(KeyboardShortcut): Add left and right arrow to cycle through images #611

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/composables/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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),
Expand All @@ -51,5 +60,8 @@ export const ACTION_TO_FUNC = {
decrementLabel: applyLabelOffset(-1),
incrementLabel: applyLabelOffset(1),

changeNextImage: changeNextImage(),
changePreviousImage: changePreviousImage(),

showKeyboardShortcuts,
} as const satisfies Record<Action, () => void>;
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,8 @@ export const ACTION_TO_KEY = {
decrementLabel: 'q',
incrementLabel: 'w',

changeNextImage: 'ArrowRight',
changePreviousImage: 'ArrowLeft',

showKeyboardShortcuts: '?',
} satisfies Record<Action, string>;
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
33 changes: 33 additions & 0 deletions src/store/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -87,6 +118,8 @@ export const useDatasetStore = defineStore('dataset', () => {
primaryDataset,
idsAsSelections,
setPrimarySelection,
changeNextImage,
changePreviousImage,
serialize,
remove,
};
Expand Down
Loading