Skip to content

Commit

Permalink
feat(KeyboardShortcuts): add readable action listings
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Oct 10, 2023
1 parent 9cdbcf9 commit 78bdac7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 18 deletions.
9 changes: 8 additions & 1 deletion src/components/KeyboardShortcuts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@
import { computed } from 'vue';
import { actionToKey } from '@/src/composables/useKeyboardShortcuts';
import { useKeyboardShortcutsStore } from '@/src/store/keyboard-shortcuts';
import { ACTIONS } from '@/src/constants';
import CloseableDialog from './CloseableDialog.vue';
import { getEntries } from '../utils';
const keyboardStore = useKeyboardShortcutsStore();
const bindings = computed(() => Object.entries(actionToKey.value));
const bindings = computed(() =>
getEntries(actionToKey.value).map(([action, key]) => [
ACTIONS[action].readable,
key,
])
);
</script>
8 changes: 8 additions & 0 deletions src/composables/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRectangleStore } from '../store/tools/rectangles';
import { useRulerStore } from '../store/tools/rulers';
import { usePolygonStore } from '../store/tools/polygons';
import { Action } from '../constants';
import { useKeyboardShortcutsStore } from '../store/keyboard-shortcuts';

const applyLabelOffset = (offset: number) => () => {
const toolToStore = {
Expand All @@ -30,6 +31,11 @@ const setTool = (tool: Tools) => () => {
useToolStore().setCurrentTool(tool);
};

const showKeyboardShortcuts = () => {
const keyboardStore = useKeyboardShortcutsStore();
keyboardStore.settingsOpen = true;
};

export const ACTION_TO_FUNC = {
windowLevel: setTool(Tools.WindowLevel),
pan: setTool(Tools.Pan),
Expand All @@ -44,4 +50,6 @@ export const ACTION_TO_FUNC = {

decrementLabel: applyLabelOffset(-1),
incrementLabel: applyLabelOffset(1),

showKeyboardShortcuts,
} as const satisfies Record<Action, () => void>;
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,6 @@ export const ACTION_TO_KEY = {

decrementLabel: 'q',
incrementLabel: 'w',

showKeyboardShortcuts: '?',
} satisfies Record<Action, string>;
60 changes: 43 additions & 17 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,48 @@ export const Messages = {

export const ANNOTATION_TOOL_HANDLE_RADIUS = 10; // pixels

export const ACTIONS = [
// set the current tool
'windowLevel',
'pan',
'zoom',
'ruler',
'paint',
'rectangle',
'crosshairs',
'crop',
'polygon',
'select',
export const ACTIONS = {
windowLevel: {
readable: 'Activate Window/Level tool',
},
pan: {
readable: 'Activate Pan tool',
},
zoom: {
readable: 'Activate Zoom tool',
},
ruler: {
readable: 'Activate Ruler tool',
},
paint: {
readable: 'Activate Paint tool',
},
rectangle: {
readable: 'Activate Rectangle tool',
},
crosshairs: {
readable: 'Activate Crosshairs tool',
},
crop: {
readable: 'Activate Crop tool',
},
polygon: {
readable: 'Activate Polygon tool',
},
select: {
readable: 'Activate Select tool',
},

// change the current label for the current tool
'decrementLabel',
'incrementLabel',
] as const;
decrementLabel: {
readable: 'Activate previous Label',
},
incrementLabel: {
readable: 'Activate next Label',
},

showKeyboardShortcuts: {
readable: 'Show keyboard shortcuts dialog',
},
} as const;

export type Action = (typeof ACTIONS)[number];
export type Action = keyof typeof ACTIONS;

0 comments on commit 78bdac7

Please sign in to comment.