move items from editor dropdown to nav

This commit is contained in:
Cassie Tarakajian 2017-09-01 12:40:15 -04:00
parent 1a4193f574
commit 251ab99ac7
3 changed files with 37 additions and 29 deletions

View file

@ -180,7 +180,6 @@ class Nav extends React.PureComponent {
</li> </li>
</ul> </ul>
</li> </li>
{/* TODO--add these things to the nav
<li className={navDropdownState.edit}> <li className={navDropdownState.edit}>
<button <button
onClick={this.toggleDropdown.bind(this, 'edit')} onClick={this.toggleDropdown.bind(this, 'edit')}
@ -196,13 +195,26 @@ class Nav extends React.PureComponent {
<InlineSVG src={triangleUrl} /> <InlineSVG src={triangleUrl} />
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button
onClick={() => this.props.cmController.tidyCode()}
onFocus={this.handleFocus.bind(this, 'edit')}
onBlur={this.handleBlur}
>
Tidy Code Tidy Code
</button>
</li> </li>
<li className="nav__dropdown-item"> <li className="nav__dropdown-item">
<button
onClick={() => this.props.cmController.showFind()}
onFocus={this.handleFocus.bind(this, 'edit')}
onBlur={this.handleBlur}
>
Find Find
</button>
</li> </li>
</ul> </ul>
</li> </li>
{/*
<li className={navDropdownState.sketch}> <li className={navDropdownState.sketch}>
<button <button
onClick={this.toggleDropdown.bind(this, 'sketch')} onClick={this.toggleDropdown.bind(this, 'sketch')}
@ -373,14 +385,19 @@ Nav.propTypes = {
showErrorModal: PropTypes.func.isRequired, showErrorModal: PropTypes.func.isRequired,
unsavedChanges: PropTypes.bool.isRequired, unsavedChanges: PropTypes.bool.isRequired,
warnIfUnsavedChanges: PropTypes.func.isRequired, warnIfUnsavedChanges: PropTypes.func.isRequired,
showKeyboardShortcutModal: PropTypes.func.isRequired showKeyboardShortcutModal: PropTypes.func.isRequired,
cmController: PropTypes.shape({
tidyCode: PropTypes.func,
showFind: PropTypes.func
})
}; };
Nav.defaultProps = { Nav.defaultProps = {
project: { project: {
id: undefined, id: undefined,
owner: undefined owner: undefined
} },
cmController: {}
}; };
export default Nav; export default Nav;

View file

@ -40,7 +40,6 @@ window.CSSLint = CSSLint;
window.HTMLHint = HTMLHint; window.HTMLHint = HTMLHint;
const beepUrl = require('../../../sounds/audioAlert.mp3'); const beepUrl = require('../../../sounds/audioAlert.mp3');
const downArrowUrl = require('../../../images/down-arrow.svg');
const unsavedChangesDotUrl = require('../../../images/unsaved-changes-dot.svg'); const unsavedChangesDotUrl = require('../../../images/unsaved-changes-dot.svg');
const rightArrowUrl = require('../../../images/right-arrow.svg'); const rightArrowUrl = require('../../../images/right-arrow.svg');
const leftArrowUrl = require('../../../images/left-arrow.svg'); const leftArrowUrl = require('../../../images/left-arrow.svg');
@ -49,6 +48,7 @@ class Editor extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.tidyCode = this.tidyCode.bind(this); this.tidyCode = this.tidyCode.bind(this);
this.showFind = this.showFind.bind(this);
} }
componentDidMount() { componentDidMount() {
this.beep = new Audio(beepUrl); this.beep = new Audio(beepUrl);
@ -119,6 +119,11 @@ class Editor extends React.Component {
this._cm.getWrapperElement().style['font-size'] = `${this.props.fontSize}px`; this._cm.getWrapperElement().style['font-size'] = `${this.props.fontSize}px`;
this._cm.setOption('indentWithTabs', this.props.isTabIndent); this._cm.setOption('indentWithTabs', this.props.isTabIndent);
this._cm.setOption('tabSize', this.props.indentationAmount); this._cm.setOption('tabSize', this.props.indentationAmount);
this.props.provideController({
tidyCode: this.tidyCode,
showFind: this.showFind
});
} }
componentWillUpdate(nextProps) { componentWillUpdate(nextProps) {
@ -158,6 +163,7 @@ class Editor extends React.Component {
componentWillUnmount() { componentWillUnmount() {
this._cm = null; this._cm = null;
this.props.provideController(null);
} }
getFileMode(fileName) { getFileMode(fileName) {
@ -201,6 +207,10 @@ class Editor extends React.Component {
} }
} }
showFind() {
this._cm.execCommand('find');
}
toggleEditorOptions() { toggleEditorOptions() {
if (this.props.editorOptionsVisible) { if (this.props.editorOptionsVisible) {
this.props.closeEditorOptions(); this.props.closeEditorOptions();
@ -250,26 +260,6 @@ class Editor extends React.Component {
isUserOwner={this.props.isUserOwner} isUserOwner={this.props.isUserOwner}
/> />
</div> </div>
<button
className="editor__options-button"
aria-label="editor options"
tabIndex="0"
ref={(element) => { this.optionsButton = element; }}
onClick={() => {
this.toggleEditorOptions();
}}
onBlur={() => setTimeout(this.props.closeEditorOptions, 200)}
>
<InlineSVG src={downArrowUrl} />
</button>
<ul className="editor__options" title="editor options">
<li>
<button onClick={this.tidyCode}>Tidy</button>
</li>
<li>
<button onClick={this.props.showKeyboardShortcutModal}>Keyboard shortcuts</button>
</li>
</ul>
</header> </header>
<div ref={(element) => { this.codemirrorContainer = element; }} className="editor-holder" tabIndex="0"> <div ref={(element) => { this.codemirrorContainer = element; }} className="editor-holder" tabIndex="0">
</div> </div>
@ -303,7 +293,6 @@ Editor.propTypes = {
editorOptionsVisible: PropTypes.bool.isRequired, editorOptionsVisible: PropTypes.bool.isRequired,
showEditorOptions: PropTypes.func.isRequired, showEditorOptions: PropTypes.func.isRequired,
closeEditorOptions: PropTypes.func.isRequired, closeEditorOptions: PropTypes.func.isRequired,
showKeyboardShortcutModal: PropTypes.func.isRequired,
setUnsavedChanges: PropTypes.func.isRequired, setUnsavedChanges: PropTypes.func.isRequired,
startRefreshSketch: PropTypes.func.isRequired, startRefreshSketch: PropTypes.func.isRequired,
autorefresh: PropTypes.bool.isRequired, autorefresh: PropTypes.bool.isRequired,
@ -320,7 +309,8 @@ Editor.propTypes = {
collapseSidebar: PropTypes.func.isRequired, collapseSidebar: PropTypes.func.isRequired,
expandSidebar: PropTypes.func.isRequired, expandSidebar: PropTypes.func.isRequired,
isUserOwner: PropTypes.bool, isUserOwner: PropTypes.bool,
clearConsole: PropTypes.func.isRequired clearConsole: PropTypes.func.isRequired,
provideController: PropTypes.func.isRequired
}; };
Editor.defaultProps = { Editor.defaultProps = {

View file

@ -219,6 +219,7 @@ class IDEView extends React.Component {
unsavedChanges={this.props.ide.unsavedChanges} unsavedChanges={this.props.ide.unsavedChanges}
warnIfUnsavedChanges={this.warnIfUnsavedChanges} warnIfUnsavedChanges={this.warnIfUnsavedChanges}
showKeyboardShortcutModal={this.props.showKeyboardShortcutModal} showKeyboardShortcutModal={this.props.showKeyboardShortcutModal}
cmController={this.cmController}
/> />
<Toolbar <Toolbar
className="Toolbar" className="Toolbar"
@ -342,6 +343,7 @@ class IDEView extends React.Component {
collapseSidebar={this.props.collapseSidebar} collapseSidebar={this.props.collapseSidebar}
isUserOwner={this.isUserOwner()} isUserOwner={this.isUserOwner()}
clearConsole={this.props.clearConsole} clearConsole={this.props.clearConsole}
provideController={(ctl) => { this.cmController = ctl; }}
/> />
<Console <Console
consoleEvents={this.props.console} consoleEvents={this.props.console}
@ -527,7 +529,6 @@ class IDEView extends React.Component {
} }
})()} })()}
</div> </div>
); );
} }
} }