1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-27 23:28:38 +02:00
Files
joplin/ElectronClient/gui/NoteEditor/NoteBody/CodeMirror/Toolbar.tsx
Laurent Cozic 3a57cfea02 Desktop: Simplified and improve command service, and added command palette
- Commands "enabled" state is now expressed using a "when-clause" like in VSCode
- A command palette has been added to the Tools menu
2020-10-18 21:52:10 +01:00

64 lines
1.7 KiB
TypeScript

import * as React from 'react';
import CommandService from 'lib/services/CommandService';
import ToolbarBase from '../../../ToolbarBase';
import { utils as pluginUtils } from 'lib/services/plugins/reducer';
import { connect } from 'react-redux';
import { AppState } from '../../../../app';
import ToolbarButtonUtils, { ToolbarButtonInfo } from 'lib/services/commands/ToolbarButtonUtils';
import stateToWhenClauseContext from 'lib/services/commands/stateToWhenClauseContext';
const { buildStyle } = require('lib/theme');
interface ToolbarProps {
themeId: number,
toolbarButtonInfos: ToolbarButtonInfo[],
}
function styles_(props:ToolbarProps) {
return buildStyle('CodeMirrorToolbar', props.themeId, () => {
return {
root: {
flex: 1,
marginBottom: 0,
},
};
});
}
const toolbarButtonUtils = new ToolbarButtonUtils(CommandService.instance());
function Toolbar(props:ToolbarProps) {
const styles = styles_(props);
return <ToolbarBase style={styles.root} items={props.toolbarButtonInfos} />;
}
const mapStateToProps = (state: AppState) => {
const whenClauseContext = stateToWhenClauseContext(state);
const commandNames = [
'historyBackward',
'historyForward',
'toggleExternalEditing',
'-',
'textBold',
'textItalic',
'-',
'textLink',
'textCode',
'attachFile',
'-',
'textNumberedList',
'textBulletedList',
'textCheckbox',
'textHeading',
'textHorizontalRule',
'insertDateTime',
'toggleEditors',
].concat(pluginUtils.commandNamesFromViews(state.pluginService.plugins, 'editorToolbar'));
return {
toolbarButtonInfos: toolbarButtonUtils.commandsToToolbarButtons(commandNames, whenClauseContext),
};
};
export default connect(mapStateToProps)(Toolbar);