Skip to content
New issue

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

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

Already on GitHub? # to your account

Delete image shortcut #713

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions docs/mouse_controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## Data management

| Shortcut | Action |
| -------- | ------ |
| Shortcut | Action |
| -------- | --------------------- |
| Ctrl + . | Delete Current Image |
| Ctrl + / | Clear all data |

## Slice

Expand Down
4 changes: 3 additions & 1 deletion src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ export default defineComponent({
const { currentImageMetadata, isImageLoading } = useCurrentImage();
const defaultImageMetadataName = defaultImageMetadata().name;
watch(currentImageMetadata, (newMetadata) => {
let prefix = '';
if (
newMetadata?.name &&
// wait until we get a real name, but if we never do, show default name
(newMetadata.name !== defaultImageMetadataName || !isImageLoading)
) {
document.title = `${newMetadata.name} - VolView`;
prefix = `${newMetadata.name} -`;
}
document.title = `${prefix}VolView`;
});

// --- parse URL -- //
Expand Down
17 changes: 17 additions & 0 deletions src/composables/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Action } from '../constants';
import { useKeyboardShortcutsStore } from '../store/keyboard-shortcuts';
import { useCurrentImage } from './useCurrentImage';
import { useSliceConfig } from './useSliceConfig';
import { useDatasetStore } from '../store/datasets';

const applyLabelOffset = (offset: number) => () => {
const toolToStore = {
Expand Down Expand Up @@ -47,6 +48,19 @@ const changeSlice = (offset: number) => () => {
currentSlice.value += offset;
};

const clearScene = () => () => {
const datasetStore = useDatasetStore();
datasetStore.removeAll();
};

const deleteCurrentImage = () => () => {
const datasetStore = useDatasetStore();
datasetStore.remove(datasetStore.primaryImageID);

// Automatically select next image
datasetStore.setPrimarySelection(datasetStore.idsAsSelections[0]);
};

export const ACTION_TO_FUNC = {
windowLevel: setTool(Tools.WindowLevel),
pan: setTool(Tools.Pan),
Expand All @@ -65,6 +79,9 @@ export const ACTION_TO_FUNC = {
decrementLabel: applyLabelOffset(-1),
incrementLabel: applyLabelOffset(1),

deleteCurrentImage: deleteCurrentImage(),
clearScene: clearScene(),

mergeNewPolygon: () => {}, // acts as a modifier key rather than immediate effect, so no-op

showKeyboardShortcuts,
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ export const ACTION_TO_KEY = {
decrementLabel: 'q',
incrementLabel: 'w',

deleteCurrentImage: 'ctrl+.',
clearScene: 'ctrl+/',

showKeyboardShortcuts: '?',
} satisfies Record<Action, string>;

Expand Down
8 changes: 8 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export const ACTIONS = {
readable: 'Activate next Label',
},

deleteCurrentImage: {
readable: 'Remove current active image',
},

clearScene: {
readable: 'Clear scene',
},

mergeNewPolygon: {
readable: 'Hold to merge new polygons with overlapping polygons',
},
Expand Down
20 changes: 19 additions & 1 deletion src/store/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useFileStore } from './datasets-files';
import { StateFile } from '../io/state-file/schema';
import { useErrorMessage } from '../composables/useErrorMessage';
import { useLayersStore } from './datasets-layers';
import { useModelStore } from './datasets-models';

export const DataType = {
Image: 'Image',
Expand All @@ -23,6 +24,7 @@ export const useDatasetStore = defineStore('dataset', () => {
const dicomStore = useDICOMStore();
const fileStore = useFileStore();
const layersStore = useLayersStore();
const modelStore = useModelStore();

// --- state --- //

Expand Down Expand Up @@ -67,7 +69,9 @@ export const useDatasetStore = defineStore('dataset', () => {
}
}

const remove = (id: string) => {
const remove = (id: string | null) => {
if (!id) return;

if (id === primarySelection.value) {
primarySelection.value = null;
}
Expand All @@ -81,6 +85,19 @@ export const useDatasetStore = defineStore('dataset', () => {
layersStore.remove(id);
};

const removeAll = () => {
// Create a copy to avoid iteration issue while removing data
const imageIdCopy = [...imageStore.idList];
imageIdCopy.forEach((id) => {
remove(id);
});

const modelIdCopy = [...modelStore.idList];
modelIdCopy.forEach((id) => {
remove(id);
});
};

return {
primaryImageID,
primarySelection,
Expand All @@ -89,5 +106,6 @@ export const useDatasetStore = defineStore('dataset', () => {
setPrimarySelection,
serialize,
remove,
removeAll,
};
});
Loading