Add accelerator shortcut in the tooltip for searching events panel

This commit is contained in:
Florian Rival
2018-08-13 21:21:02 +02:00
parent 10ef38978d
commit bbb541ce48
3 changed files with 28 additions and 25 deletions

View File

@@ -6,6 +6,7 @@ import ToolbarIcon from '../UI/ToolbarIcon';
import IconMenu from '../UI/Menu/IconMenu';
import { mapFor } from '../Utils/MapFor';
import flatten from 'lodash/flatten';
import { adaptAcceleratorString } from '../UI/AcceleratorString';
const gd = global.gd;
export class Toolbar extends PureComponent {
@@ -122,7 +123,7 @@ export class Toolbar extends PureComponent {
<ToolbarIcon
onClick={() => this.props.onToggleSearchPanel()}
src="res/ribbon_default/search32.png"
tooltip={t('Search in events')}
tooltip={`${t('Search in events')} ${adaptAcceleratorString('CmdOrCtrl+F')}`}
/>
{this.props.onOpenSettings && <ToolbarSeparator />}
{this.props.onOpenSettings && (

View File

@@ -0,0 +1,25 @@
// @flow
import { isMacLike, isMobile } from '../Utils/Platform';
export const adaptAcceleratorString = (accelerator: string): string => {
if (isMobile()) {
return ''; // Do not display accelerators on mobile devices
} else if (isMacLike()) {
return accelerator
.replace(/CmdOrCtrl\+/, '⌘')
.replace(/CommandOrControl\+/, '⌘')
.replace(/Super\+/, '⌘')
.replace(/Shift\+/, '⇧')
.replace(/Alt\+/, '⌥')
.replace(/Option\+/, '⌥')
.replace(/Delete/, '⌦')
.replace(/Backspace/, '⌫');
} else {
return accelerator
.replace(/CmdOrCtrl\+/, 'Ctrl+')
.replace(/CommandOrControl\+/, 'Ctrl+')
.replace(/Super\+/, 'Win+')
.replace(/Option\+/, 'Alt+')
.replace(/Delete/, 'DEL');
}
};

View File

@@ -1,30 +1,7 @@
import React from 'react';
import MenuItem from 'material-ui/MenuItem';
import Divider from 'material-ui/Divider';
import { isMacLike, isMobile } from '../../Utils/Platform';
const adaptAcceleratorString = (accelerator: string): string => {
if (isMobile()) {
return ''; // Do not display accelerators on mobile devices
} else if (isMacLike()) {
return accelerator
.replace(/CmdOrCtrl\+/, '⌘')
.replace(/CommandOrControl\+/, '⌘')
.replace(/Super\+/, '⌘')
.replace(/Shift\+/, '⇧')
.replace(/Alt\+/, '⌥')
.replace(/Option\+/, '⌥')
.replace(/Delete/, '⌦')
.replace(/Backspace/, '⌫');
} else {
return accelerator
.replace(/CmdOrCtrl\+/, 'Ctrl+')
.replace(/CommandOrControl\+/, 'Ctrl+')
.replace(/Super\+/, 'Win+')
.replace(/Option\+/, 'Alt+')
.replace(/Delete/, 'DEL');
}
};
import { adaptAcceleratorString } from '../AcceleratorString';
/**
* Construct items for material-ui's Menu, using a template which