mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 05:52:42 -05:00
Implement ordering buttons
This commit is contained in:
parent
c3f578c140
commit
3b4f509f89
3 changed files with 102 additions and 7 deletions
|
@ -117,35 +117,35 @@ class PaintEditorComponent extends React.Component {
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
|
|
||||||
{/* To be Forward/Backward */}
|
{/* Forward/Backward */}
|
||||||
<InputGroup className={styles.modDashedBorder}>
|
<InputGroup className={styles.modDashedBorder}>
|
||||||
<EditFieldButton
|
<EditFieldButton
|
||||||
imgAlt="Send Forward Icon"
|
imgAlt="Send Forward Icon"
|
||||||
imgSrc={sendForwardIcon}
|
imgSrc={sendForwardIcon}
|
||||||
title="Forward"
|
title="Forward"
|
||||||
onClick={function () {}}
|
onClick={this.props.onSendForward}
|
||||||
/>
|
/>
|
||||||
<EditFieldButton
|
<EditFieldButton
|
||||||
imgAlt="Send Backward Icon"
|
imgAlt="Send Backward Icon"
|
||||||
imgSrc={sendBackwardIcon}
|
imgSrc={sendBackwardIcon}
|
||||||
title="Backward"
|
title="Backward"
|
||||||
onClick={function () {}}
|
onClick={this.props.onSendBackward}
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
|
|
||||||
{/* To be Front/back */}
|
{/* Front/Back */}
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
<EditFieldButton
|
<EditFieldButton
|
||||||
imgAlt="Send to Front Icon"
|
imgAlt="Send to Front Icon"
|
||||||
imgSrc={sendFrontIcon}
|
imgSrc={sendFrontIcon}
|
||||||
title="Front"
|
title="Front"
|
||||||
onClick={function () {}}
|
onClick={this.props.onSendToFront}
|
||||||
/>
|
/>
|
||||||
<EditFieldButton
|
<EditFieldButton
|
||||||
imgAlt="Send to Back Icon"
|
imgAlt="Send to Back Icon"
|
||||||
imgSrc={sendBackIcon}
|
imgSrc={sendBackIcon}
|
||||||
title="Back"
|
title="Back"
|
||||||
onClick={function () {}}
|
onClick={this.props.onSendToBack}
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
|
|
||||||
|
@ -237,6 +237,10 @@ PaintEditorComponent.propTypes = {
|
||||||
intl: intlShape,
|
intl: intlShape,
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
onRedo: PropTypes.func.isRequired,
|
onRedo: PropTypes.func.isRequired,
|
||||||
|
onSendBackward: PropTypes.func.isRequired,
|
||||||
|
onSendForward: PropTypes.func.isRequired,
|
||||||
|
onSendToBack: PropTypes.func.isRequired,
|
||||||
|
onSendToFront: PropTypes.func.isRequired,
|
||||||
onUndo: PropTypes.func.isRequired,
|
onUndo: PropTypes.func.isRequired,
|
||||||
onUpdateName: PropTypes.func.isRequired,
|
onUpdateName: PropTypes.func.isRequired,
|
||||||
onUpdateSvg: PropTypes.func.isRequired,
|
onUpdateSvg: PropTypes.func.isRequired,
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {undo, redo, undoSnapshot} from '../reducers/undo';
|
||||||
|
|
||||||
import {getGuideLayer} from '../helper/layer';
|
import {getGuideLayer} from '../helper/layer';
|
||||||
import {performUndo, performRedo, performSnapshot} from '../helper/undo';
|
import {performUndo, performRedo, performSnapshot} from '../helper/undo';
|
||||||
|
import {bringToFront, sendBackward, sendToBack, bringForward} from '../helper/order';
|
||||||
|
|
||||||
import Modes from '../modes/modes';
|
import Modes from '../modes/modes';
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
|
@ -19,7 +20,11 @@ class PaintEditor extends React.Component {
|
||||||
bindAll(this, [
|
bindAll(this, [
|
||||||
'handleUpdateSvg',
|
'handleUpdateSvg',
|
||||||
'handleUndo',
|
'handleUndo',
|
||||||
'handleRedo'
|
'handleRedo',
|
||||||
|
'handleSendBackward',
|
||||||
|
'handleSendForward',
|
||||||
|
'handleSendToBack',
|
||||||
|
'handleSendToFront'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
|
@ -51,6 +56,18 @@ class PaintEditor extends React.Component {
|
||||||
handleRedo () {
|
handleRedo () {
|
||||||
performRedo(this.props.undoState, this.props.onRedo, this.handleUpdateSvg);
|
performRedo(this.props.undoState, this.props.onRedo, this.handleUpdateSvg);
|
||||||
}
|
}
|
||||||
|
handleSendBackward () {
|
||||||
|
sendBackward(this.handleUpdateSvg);
|
||||||
|
}
|
||||||
|
handleSendForward () {
|
||||||
|
bringForward(this.handleUpdateSvg);
|
||||||
|
}
|
||||||
|
handleSendToBack () {
|
||||||
|
sendToBack(this.handleUpdateSvg);
|
||||||
|
}
|
||||||
|
handleSendToFront () {
|
||||||
|
bringToFront(this.handleUpdateSvg);
|
||||||
|
}
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<PaintEditorComponent
|
<PaintEditorComponent
|
||||||
|
@ -60,6 +77,10 @@ class PaintEditor extends React.Component {
|
||||||
svg={this.props.svg}
|
svg={this.props.svg}
|
||||||
svgId={this.props.svgId}
|
svgId={this.props.svgId}
|
||||||
onRedo={this.handleRedo}
|
onRedo={this.handleRedo}
|
||||||
|
onSendBackward={this.handleSendBackward}
|
||||||
|
onSendForward={this.handleSendForward}
|
||||||
|
onSendToBack={this.handleSendToBack}
|
||||||
|
onSendToFront={this.handleSendToFront}
|
||||||
onUndo={this.handleUndo}
|
onUndo={this.handleUndo}
|
||||||
onUpdateName={this.props.onUpdateName}
|
onUpdateName={this.props.onUpdateName}
|
||||||
onUpdateSvg={this.handleUpdateSvg}
|
onUpdateSvg={this.handleUpdateSvg}
|
||||||
|
|
70
src/helper/order.js
Normal file
70
src/helper/order.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
import {getSelectedRootItems} from './selection';
|
||||||
|
|
||||||
|
const bringToFront = function (onUpdateSvg) {
|
||||||
|
const items = getSelectedRootItems();
|
||||||
|
for (const item of items) {
|
||||||
|
item.bringToFront();
|
||||||
|
}
|
||||||
|
onUpdateSvg();
|
||||||
|
};
|
||||||
|
|
||||||
|
const sendToBack = function (onUpdateSvg) {
|
||||||
|
const items = getSelectedRootItems();
|
||||||
|
for (let i = items.length - 1; i >= 0; i--) {
|
||||||
|
items[i].sendToBack();
|
||||||
|
}
|
||||||
|
onUpdateSvg();
|
||||||
|
};
|
||||||
|
|
||||||
|
const bringForward = function (onUpdateSvg) {
|
||||||
|
const items = getSelectedRootItems();
|
||||||
|
// Already at front
|
||||||
|
if (items.length === 0 || !items[items.length - 1].nextSibling) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextSibling = items[items.length - 1].nextSibling;
|
||||||
|
for (let i = items.length - 1; i >= 0; i--) {
|
||||||
|
items[i].insertAbove(nextSibling);
|
||||||
|
}
|
||||||
|
onUpdateSvg();
|
||||||
|
};
|
||||||
|
|
||||||
|
const sendBackward = function (onUpdateSvg) {
|
||||||
|
const items = getSelectedRootItems();
|
||||||
|
// Already at front
|
||||||
|
if (items.length === 0 || !items[0].previousSibling) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const previousSibling = items[0].previousSibling;
|
||||||
|
for (const item of items) {
|
||||||
|
item.insertBelow(previousSibling);
|
||||||
|
}
|
||||||
|
onUpdateSvg();
|
||||||
|
};
|
||||||
|
|
||||||
|
const shouldShowSendBackward = function () {
|
||||||
|
const items = getSelectedRootItems();
|
||||||
|
if (items.length === 0 || !items[0].previousSibling) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const shouldShowBringForward = function () {
|
||||||
|
const items = getSelectedRootItems();
|
||||||
|
if (items.length === 0 || !items[items.length - 1].nextSibling) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
bringToFront,
|
||||||
|
sendToBack,
|
||||||
|
bringForward,
|
||||||
|
sendBackward,
|
||||||
|
shouldShowBringForward,
|
||||||
|
shouldShowSendBackward
|
||||||
|
};
|
Loading…
Reference in a new issue