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

View file

@ -13,10 +13,22 @@ class ModeTools extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'hasSelectedPoints',
'handleCopyToClipboard', 'handleCopyToClipboard',
'handlePasteFromClipboard' 'handlePasteFromClipboard'
]); ]);
} }
hasSelectedPoints () {
const selectedItems = getSelectedLeafItems();
for (const item of selectedItems) {
for (const seg of item.segments) {
if (seg.selected) {
return true;
}
}
}
return false;
}
handleCopyToClipboard () { handleCopyToClipboard () {
const selectedItems = getSelectedRootItems(); const selectedItems = getSelectedRootItems();
if (selectedItems.length > 0) { if (selectedItems.length > 0) {
@ -50,6 +62,7 @@ class ModeTools extends React.Component {
render () { render () {
return ( return (
<ModeToolsComponent <ModeToolsComponent
hasSelectedPoints={this.hasSelectedPoints()}
onCopyToClipboard={this.handleCopyToClipboard} onCopyToClipboard={this.handleCopyToClipboard}
onPasteFromClipboard={this.handlePasteFromClipboard} onPasteFromClipboard={this.handlePasteFromClipboard}
/> />
@ -63,13 +76,16 @@ ModeTools.propTypes = {
incrementPasteOffset: PropTypes.func.isRequired, incrementPasteOffset: PropTypes.func.isRequired,
onUpdateSvg: PropTypes.func.isRequired, onUpdateSvg: PropTypes.func.isRequired,
pasteOffset: PropTypes.number, 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, setClipboardItems: PropTypes.func.isRequired,
setSelectedItems: PropTypes.func.isRequired setSelectedItems: PropTypes.func.isRequired
}; };
const mapStateToProps = state => ({ const mapStateToProps = state => ({
clipboardItems: state.scratchPaint.clipboard.items, clipboardItems: state.scratchPaint.clipboard.items,
pasteOffset: state.scratchPaint.clipboard.pasteOffset pasteOffset: state.scratchPaint.clipboard.pasteOffset,
selectedItems: state.scratchPaint.selectedItems
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
setClipboardItems: items => { setClipboardItems: items => {