1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/Toolbar.tsx

64 lines
1.7 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
2020-11-05 18:58:23 +02:00
import CommandService from '@joplinapp/lib/services/CommandService';
import ToolbarBase from '../../../ToolbarBase';
2020-11-05 18:58:23 +02:00
import { utils as pluginUtils } from '@joplinapp/lib/services/plugins/reducer';
import { connect } from 'react-redux';
import { AppState } from '../../../../app';
2020-11-05 18:58:23 +02:00
import ToolbarButtonUtils, { ToolbarButtonInfo } from '@joplinapp/lib/services/commands/ToolbarButtonUtils';
import stateToWhenClauseContext from '@joplinapp/lib/services/commands/stateToWhenClauseContext';
const { buildStyle } = require('@joplinapp/lib/theme');
interface ToolbarProps {
2020-09-15 15:01:07 +02:00
themeId: number,
toolbarButtonInfos: ToolbarButtonInfo[],
}
function styles_(props:ToolbarProps) {
2020-09-15 15:01:07 +02:00
return buildStyle('CodeMirrorToolbar', props.themeId, () => {
return {
root: {
flex: 1,
marginBottom: 0,
},
};
});
}
const toolbarButtonUtils = new ToolbarButtonUtils(CommandService.instance());
2020-09-15 15:01:07 +02:00
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',
'-',
'textBulletedList',
'textNumberedList',
'textCheckbox',
'textHeading',
'textHorizontalRule',
'insertDateTime',
'toggleEditors',
].concat(pluginUtils.commandNamesFromViews(state.pluginService.plugins, 'editorToolbar'));
return {
toolbarButtonInfos: toolbarButtonUtils.commandsToToolbarButtons(commandNames, whenClauseContext),
};
};
export default connect(mapStateToProps)(Toolbar);