add metakey / shortcut to open settings

main
Mike Fix 5 years ago
parent c163299b77
commit cc5c2ab94a

@ -1,5 +1,6 @@
import React from 'react' import React from 'react'
import omitBy from 'lodash.omitby' import omitBy from 'lodash.omitby'
import { useKeyboardListener } from '@dawnlabs/tacklebox'
import ThemeSelect from './ThemeSelect' import ThemeSelect from './ThemeSelect'
import FontSelect from './FontSelect' import FontSelect from './FontSelect'
@ -14,6 +15,15 @@ import { COLORS, DEFAULT_PRESETS } from '../lib/constants'
import { toggle, getPresets, savePresets, generateId, fileToJSON } from '../lib/util' import { toggle, getPresets, savePresets, generateId, fileToJSON } from '../lib/util'
import SettingsIcon from './svg/Settings' import SettingsIcon from './svg/Settings'
function KeyboardShortcut({ handle }) {
useKeyboardListener('/', e => {
if (e.metaKey) {
handle()
}
})
return null
}
const WindowSettings = React.memo( const WindowSettings = React.memo(
({ ({
onChange, onChange,
@ -233,6 +243,7 @@ class Settings extends React.PureComponent {
} }
settingsRef = React.createRef() settingsRef = React.createRef()
menuRef = React.createRef()
componentDidMount() { componentDidMount() {
const storedPresets = getPresets(localStorage) || [] const storedPresets = getPresets(localStorage) || []
@ -376,6 +387,14 @@ class Settings extends React.PureComponent {
return ( return (
<div className="settings-container" ref={this.settingsRef}> <div className="settings-container" ref={this.settingsRef}>
<KeyboardShortcut
handle={() => {
toggleVisibility()
if (!isVisible) {
this.menuRef.current.focus()
}
}}
/>
<Button <Button
title="Settings Menu" title="Settings Menu"
border border
@ -408,7 +427,7 @@ class Settings extends React.PureComponent {
applied={!!previousSettings} applied={!!previousSettings}
/> />
<div className="settings-bottom"> <div className="settings-bottom">
<div className="settings-menu"> <div className="settings-menu" ref={this.menuRef} tabIndex={-1}>
<MenuButton name="Window" select={this.selectMenu} selected={selectedMenu} /> <MenuButton name="Window" select={this.selectMenu} selected={selectedMenu} />
<MenuButton name="Type" select={this.selectMenu} selected={selectedMenu} /> <MenuButton name="Type" select={this.selectMenu} selected={selectedMenu} />
<MenuButton name="Misc" select={this.selectMenu} selected={selectedMenu} /> <MenuButton name="Misc" select={this.selectMenu} selected={selectedMenu} />

Loading…
Cancel
Save