2020-06-06 17:00:20 +02:00
|
|
|
import * as React from 'react';
|
2020-11-07 17:59:37 +02:00
|
|
|
import CommandService from '@joplin/lib/services/CommandService';
|
2020-09-23 11:21:24 +02:00
|
|
|
import ToolbarBase from '../../../ToolbarBase';
|
2020-11-07 17:59:37 +02:00
|
|
|
import { utils as pluginUtils } from '@joplin/lib/services/plugins/reducer';
|
2020-10-09 19:35:46 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { AppState } from '../../../../app';
|
2020-11-07 17:59:37 +02:00
|
|
|
import ToolbarButtonUtils, { ToolbarButtonInfo } from '@joplin/lib/services/commands/ToolbarButtonUtils';
|
|
|
|
import stateToWhenClauseContext from '@joplin/lib/services/commands/stateToWhenClauseContext';
|
|
|
|
const { buildStyle } = require('@joplin/lib/theme');
|
2020-06-06 17:00:20 +02:00
|
|
|
|
|
|
|
interface ToolbarProps {
|
2020-09-15 15:01:07 +02:00
|
|
|
themeId: number,
|
2020-10-09 19:35:46 +02:00
|
|
|
toolbarButtonInfos: ToolbarButtonInfo[],
|
2020-06-06 17:00:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function styles_(props: ToolbarProps) {
|
2020-09-15 15:01:07 +02:00
|
|
|
return buildStyle('CodeMirrorToolbar', props.themeId, () => {
|
2020-06-06 17:00:20 +02:00
|
|
|
return {
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
marginBottom: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
const toolbarButtonUtils = new ToolbarButtonUtils(CommandService.instance());
|
2020-09-15 15:01:07 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function Toolbar(props: ToolbarProps) {
|
2020-10-09 19:35:46 +02:00
|
|
|
const styles = styles_(props);
|
|
|
|
return <ToolbarBase style={styles.root} items={props.toolbarButtonInfos} />;
|
2020-06-06 17:00:20 +02:00
|
|
|
}
|
2020-10-09 19:35:46 +02:00
|
|
|
|
|
|
|
const mapStateToProps = (state: AppState) => {
|
2020-10-18 22:52:10 +02:00
|
|
|
const whenClauseContext = stateToWhenClauseContext(state);
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
const commandNames = [
|
|
|
|
'historyBackward',
|
|
|
|
'historyForward',
|
2020-10-10 14:32:30 +02:00
|
|
|
'toggleExternalEditing',
|
2020-10-09 19:35:46 +02:00
|
|
|
'-',
|
|
|
|
'textBold',
|
|
|
|
'textItalic',
|
|
|
|
'-',
|
|
|
|
'textLink',
|
|
|
|
'textCode',
|
|
|
|
'attachFile',
|
|
|
|
'-',
|
|
|
|
'textBulletedList',
|
2020-10-21 11:39:53 +02:00
|
|
|
'textNumberedList',
|
2020-10-09 19:35:46 +02:00
|
|
|
'textCheckbox',
|
|
|
|
'textHeading',
|
|
|
|
'textHorizontalRule',
|
|
|
|
'insertDateTime',
|
|
|
|
'toggleEditors',
|
|
|
|
].concat(pluginUtils.commandNamesFromViews(state.pluginService.plugins, 'editorToolbar'));
|
|
|
|
|
|
|
|
return {
|
2020-10-18 22:52:10 +02:00
|
|
|
toolbarButtonInfos: toolbarButtonUtils.commandsToToolbarButtons(commandNames, whenClauseContext),
|
2020-10-09 19:35:46 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(Toolbar);
|