Set enabled state based on whether any points are selected

This commit is contained in:
DD 2017-12-20 15:15:45 -05:00
parent 18db05fdce
commit 0fc9fd151d
2 changed files with 20 additions and 1 deletions

View file

@ -95,12 +95,14 @@ const ModeToolsComponent = props => {
return (
<div className={classNames(props.className, styles.modeTools)}>
<LabeledIconButton
disabled={!props.hasSelectedPoints}
imgAlt="Curved Point Icon"
imgSrc={curvedPointIcon}
title="Curved"
onClick={function () {}}
/>
<LabeledIconButton
disabled={!props.hasSelectedPoints}
imgAlt="Straight Point Icon"
imgSrc={straightPointIcon}
title="Pointed"
@ -152,6 +154,7 @@ ModeToolsComponent.propTypes = {
className: PropTypes.string,
clipboardItems: PropTypes.arrayOf(PropTypes.array),
eraserValue: PropTypes.number,
hasSelectedPoints: PropTypes.bool,
intl: intlShape.isRequired,
mode: PropTypes.string.isRequired,
onBrushSliderChange: PropTypes.func,

View file

@ -13,10 +13,22 @@ class ModeTools extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'hasSelectedPoints',
'handleCopyToClipboard',
'handlePasteFromClipboard'
]);
}
hasSelectedPoints () {
const selectedItems = getSelectedLeafItems();
for (const item of selectedItems) {
for (const seg of item.segments) {
if (seg.selected) {
return true;
}
}
}
return false;
}
handleCopyToClipboard () {
const selectedItems = getSelectedRootItems();
if (selectedItems.length > 0) {
@ -50,6 +62,7 @@ class ModeTools extends React.Component {
render () {
return (
<ModeToolsComponent
hasSelectedPoints={this.hasSelectedPoints()}
onCopyToClipboard={this.handleCopyToClipboard}
onPasteFromClipboard={this.handlePasteFromClipboard}
/>
@ -63,13 +76,16 @@ ModeTools.propTypes = {
incrementPasteOffset: PropTypes.func.isRequired,
onUpdateSvg: PropTypes.func.isRequired,
pasteOffset: PropTypes.number,
// Listen on selected items to update hasSelectedPoints
selectedItems: PropTypes.arrayOf(PropTypes.instanceOf(paper.Item)), // eslint-disable-line react/no-unused-prop-types
setClipboardItems: PropTypes.func.isRequired,
setSelectedItems: PropTypes.func.isRequired
};
const mapStateToProps = state => ({
clipboardItems: state.scratchPaint.clipboard.items,
pasteOffset: state.scratchPaint.clipboard.pasteOffset
pasteOffset: state.scratchPaint.clipboard.pasteOffset,
selectedItems: state.scratchPaint.selectedItems
});
const mapDispatchToProps = dispatch => ({
setClipboardItems: items => {