Line data Source code
1 : import { computed, reactive } from 'vue'
2 :
3 : import EditKeybindingContent from '@/platform/keybindings/components/EditKeybindingContent.vue'
4 : import EditKeybindingFooter from '@/platform/keybindings/components/EditKeybindingFooter.vue'
5 : import EditKeybindingHeader from '@/platform/keybindings/components/EditKeybindingHeader.vue'
6 : import { EDIT_KEYBINDING_DIALOG_KEY } from '@/platform/keybindings/components/editKeybindingDialogState'
7 : import type { EditKeybindingDialogState } from '@/platform/keybindings/components/editKeybindingDialogState'
8 : import type { KeyComboImpl } from '@comfyorg/keybindings/keyCombo'
9 : import type { KeybindingImpl } from '@comfyorg/keybindings/keybinding'
10 : import { useKeybindingStore } from '@comfyorg/keybindings/keybindingStore'
11 : import { useDialogService } from '@/services/dialogService'
12 :
13 39 : export function useEditKeybindingDialog() {
14 39 : const { showSmallLayoutDialog } = useDialogService()
15 39 : const keybindingStore = useKeybindingStore()
16 :
17 13 : function show(options: {
18 : commandId: string
19 : commandLabel: string
20 : currentCombo: KeyComboImpl | null
21 : mode?: 'edit' | 'add'
22 : existingBinding?: KeybindingImpl | null
23 : }) {
24 13 : const dialogState = reactive<EditKeybindingDialogState>({
25 : commandId: options.commandId,
26 : newCombo: options.currentCombo,
27 : currentCombo: options.currentCombo,
28 : mode: options.mode ?? 'edit',
29 : existingBinding: options.existingBinding ?? null
30 : })
31 :
32 13 : const existingKeybindingOnCombo = computed(() => {
33 30 : if (!dialogState.newCombo) return null
34 30 : if (dialogState.currentCombo?.equals(dialogState.newCombo)) return null
35 17 : return keybindingStore.getKeybinding(dialogState.newCombo)
36 : })
37 :
38 17 : function onUpdateCombo(combo: KeyComboImpl) {
39 17 : dialogState.newCombo = combo
40 : }
41 :
42 13 : showSmallLayoutDialog({
43 : key: EDIT_KEYBINDING_DIALOG_KEY,
44 : headerComponent: EditKeybindingHeader,
45 : footerComponent: EditKeybindingFooter,
46 : component: EditKeybindingContent,
47 : props: {
48 : dialogState,
49 : onUpdateCombo,
50 : commandLabel: options.commandLabel,
51 : existingKeybindingOnCombo
52 : },
53 : headerProps: {},
54 : footerProps: { dialogState, existingKeybindingOnCombo }
55 : })
56 : }
57 :
58 39 : return { show }
59 : }
|