Skip to content

Commit 290c79a

Browse files
author
Laurent Chauvin
committed
feat: Keyboard shortcut to delete current image and clear scene
1 parent 6df6e6e commit 290c79a

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

src/composables/actions.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Action } from '../constants';
88
import { useKeyboardShortcutsStore } from '../store/keyboard-shortcuts';
99
import { useCurrentImage } from './useCurrentImage';
1010
import { useSliceConfig } from './useSliceConfig';
11+
import { useDatasetStore } from '../store/datasets';
1112

1213
const applyLabelOffset = (offset: number) => () => {
1314
const toolToStore = {
@@ -47,6 +48,19 @@ const changeSlice = (offset: number) => () => {
4748
currentSlice.value += offset;
4849
};
4950

51+
const clearScene = () => () => {
52+
const datasetStore = useDatasetStore();
53+
datasetStore.removeAll();
54+
};
55+
56+
const deleteCurrentImage = () => () => {
57+
const datasetStore = useDatasetStore();
58+
datasetStore.remove(datasetStore.primaryImageID!);
59+
60+
// Automatically select next image
61+
datasetStore.setPrimarySelection(datasetStore.idsAsSelections[0]);
62+
};
63+
5064
export const ACTION_TO_FUNC = {
5165
windowLevel: setTool(Tools.WindowLevel),
5266
pan: setTool(Tools.Pan),
@@ -65,6 +79,9 @@ export const ACTION_TO_FUNC = {
6579
decrementLabel: applyLabelOffset(-1),
6680
incrementLabel: applyLabelOffset(1),
6781

82+
deleteCurrentImage: deleteCurrentImage(),
83+
clearScene: clearScene(),
84+
6885
mergeNewPolygon: () => {}, // acts as a modifier key rather than immediate effect, so no-op
6986

7087
showKeyboardShortcuts,

src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ export const ACTION_TO_KEY = {
287287
decrementLabel: 'q',
288288
incrementLabel: 'w',
289289

290+
deleteCurrentImage: 'ctrl+d',
291+
clearScene: 'ctrl+w',
292+
290293
showKeyboardShortcuts: '?',
291294
} satisfies Record<Action, string>;
292295

src/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ export const ACTIONS = {
6767
readable: 'Activate next Label',
6868
},
6969

70+
deleteCurrentImage: {
71+
readable: 'Remove current active image',
72+
},
73+
74+
clearScene: {
75+
readable: 'Clear scene',
76+
},
77+
7078
mergeNewPolygon: {
7179
readable: 'Hold to merge new polygons with overlapping polygons',
7280
},

src/store/datasets.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useFileStore } from './datasets-files';
1212
import { StateFile } from '../io/state-file/schema';
1313
import { useErrorMessage } from '../composables/useErrorMessage';
1414
import { useLayersStore } from './datasets-layers';
15+
import { useModelStore } from './datasets-models';
1516

1617
export const DataType = {
1718
Image: 'Image',
@@ -23,6 +24,7 @@ export const useDatasetStore = defineStore('dataset', () => {
2324
const dicomStore = useDICOMStore();
2425
const fileStore = useFileStore();
2526
const layersStore = useLayersStore();
27+
const modelStore = useModelStore();
2628

2729
// --- state --- //
2830

@@ -81,6 +83,19 @@ export const useDatasetStore = defineStore('dataset', () => {
8183
layersStore.remove(id);
8284
};
8385

86+
const removeAll = () => {
87+
// Create a copy to avoid iteration issue while removing data
88+
const imageIdCopy = [...imageStore.idList];
89+
imageIdCopy.forEach((id) => {
90+
remove(id);
91+
});
92+
93+
const modelIdCopy = [...modelStore.idList];
94+
modelIdCopy.forEach((id) => {
95+
remove(id);
96+
});
97+
};
98+
8499
return {
85100
primaryImageID,
86101
primarySelection,
@@ -89,5 +104,6 @@ export const useDatasetStore = defineStore('dataset', () => {
89104
setPrimarySelection,
90105
serialize,
91106
remove,
107+
removeAll,
92108
};
93109
});

0 commit comments

Comments
 (0)