///////////////////////////////////////////////////////////// // // pgAdmin 4 - PostgreSQL Tools // // Copyright (C) 2013 - 2025, The pgAdmin Development Team // This software is released under the PostgreSQL Licence // ////////////////////////////////////////////////////////////// import { Box, ToggleButtonGroup } from '@mui/material'; import React, { useMemo } from 'react'; import { InputText, ToggleCheckButton } from './FormComponents'; import PropTypes from 'prop-types'; import { isMac } from '../keyboard_shortcuts'; import gettext from 'sources/gettext'; export default function KeyboardShortcuts({ value, onChange, fields, name }) { const keyCid = `key-${name}`; const keyhelpid = `h${keyCid}`; const hasKeys = useMemo(()=>{ return fields?.some((f)=>['shift', 'control', 'alt'].includes(f.name)); }, [fields]); const onKeyDown = (e) => { let newVal = { ...value }; let _val = e.key; if (e.keyCode == 32) { _val = 'Space'; } newVal.key = { char: _val, key_code: e.keyCode }; onChange(newVal); }; const onChangeButton = (k, v)=>{ onChange({ ...value, [k]: v, }); }; const onChangeCtrl = (_e, val)=>{ if(val == null) { onChange({ ...value, ctrl_is_meta: false, control: false, }); } else if(val == 'ctrl_is_meta') { onChange({ ...value, [val]: true, control: true, }); } else if(val == 'control') { onChange({ ...value, [val]: true, ctrl_is_meta: false, }); } else { onChange({ ...value, [val]: true, }); } }; let ctrlValue = value?.control ? 'control' : ''; if(ctrlValue && value?.ctrl_is_meta && isMac()) { ctrlValue = 'ctrl_is_meta'; } return ( {hasKeys && <> { onChangeButton('shift', val.length != 0 ); }}> {isMac() && } { onChangeButton('alt', val.length != 0); }}> } ); } KeyboardShortcuts.propTypes = { value: PropTypes.object, onChange: PropTypes.func, fields: PropTypes.array, name: PropTypes.string, };