2016-04-01 06:52:03 +08:00
|
|
|
import React from 'react';
|
2017-09-27 02:33:08 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-09-27 02:46:00 +08:00
|
|
|
import { RetinaImg, Flexbox } from 'mailspring-component-kit';
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
class AppearanceModeSwitch extends React.Component {
|
|
|
|
static displayName = 'AppearanceModeSwitch';
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-09-27 02:33:08 +08:00
|
|
|
config: PropTypes.object.isRequired,
|
2016-04-01 06:52:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super();
|
|
|
|
this.state = {
|
|
|
|
value: props.config.get('core.workspace.mode'),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
this.setState({
|
|
|
|
value: nextProps.config.get('core.workspace.mode'),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onApplyChanges = () => {
|
2017-09-27 02:36:58 +08:00
|
|
|
AppEnv.commands.dispatch(`application:select-${this.state.value}-mode`);
|
2017-09-27 02:33:08 +08:00
|
|
|
};
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
_renderModeOptions() {
|
2017-09-27 02:33:08 +08:00
|
|
|
return ['list', 'split'].map(mode => (
|
2016-04-01 06:52:03 +08:00
|
|
|
<AppearanceModeOption
|
|
|
|
mode={mode}
|
|
|
|
key={mode}
|
|
|
|
active={this.state.value === mode}
|
2017-09-27 02:33:08 +08:00
|
|
|
onClick={() => this.setState({ value: mode })}
|
2016-05-07 07:24:40 +08:00
|
|
|
/>
|
2017-09-27 02:33:08 +08:00
|
|
|
));
|
2016-04-01 06:52:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const hasChanges = this.state.value !== this.props.config.get('core.workspace.mode');
|
2017-09-27 02:33:08 +08:00
|
|
|
let applyChangesClass = 'btn';
|
|
|
|
if (!hasChanges) applyChangesClass += ' btn-disabled';
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="appearance-mode-switch">
|
2017-09-27 02:33:08 +08:00
|
|
|
<Flexbox direction="row" style={{ alignItems: 'center' }} className="item">
|
2016-04-01 06:52:03 +08:00
|
|
|
{this._renderModeOptions()}
|
|
|
|
</Flexbox>
|
2017-09-27 02:33:08 +08:00
|
|
|
<div className={applyChangesClass} onClick={this._onApplyChanges}>
|
|
|
|
Apply Layout
|
|
|
|
</div>
|
2016-04-01 06:52:03 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-07 07:24:40 +08:00
|
|
|
const AppearanceModeOption = function AppearanceModeOption(props) {
|
2017-09-27 02:33:08 +08:00
|
|
|
let classname = 'appearance-mode';
|
|
|
|
if (props.active) classname += ' active';
|
2016-05-07 07:24:40 +08:00
|
|
|
|
|
|
|
const label = {
|
|
|
|
list: 'Single Panel',
|
|
|
|
split: 'Two Panel',
|
|
|
|
}[props.mode];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classname} onClick={props.onClick}>
|
|
|
|
<RetinaImg name={`appearance-mode-${props.mode}.png`} mode={RetinaImg.Mode.ContentIsMask} />
|
|
|
|
<div>{label}</div>
|
|
|
|
</div>
|
|
|
|
);
|
2017-09-27 02:33:08 +08:00
|
|
|
};
|
2016-05-07 07:24:40 +08:00
|
|
|
AppearanceModeOption.propTypes = {
|
2017-09-27 02:33:08 +08:00
|
|
|
mode: PropTypes.string.isRequired,
|
|
|
|
active: PropTypes.bool,
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
};
|
2016-04-01 06:52:03 +08:00
|
|
|
|
|
|
|
class PreferencesAppearance extends React.Component {
|
|
|
|
static displayName = 'PreferencesAppearance';
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-09-27 02:33:08 +08:00
|
|
|
config: PropTypes.object,
|
|
|
|
configSchema: PropTypes.object,
|
|
|
|
};
|
2016-04-01 06:52:03 +08:00
|
|
|
|
2016-04-20 08:14:25 +08:00
|
|
|
onClick = () => {
|
2017-09-27 02:36:58 +08:00
|
|
|
AppEnv.commands.dispatch('window:launch-theme-picker');
|
2017-09-27 02:33:08 +08:00
|
|
|
};
|
2016-04-20 08:14:25 +08:00
|
|
|
|
2016-04-01 06:52:03 +08:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="container-appearance">
|
2016-10-18 08:59:33 +08:00
|
|
|
<label htmlFor="change-layout">Change layout:</label>
|
|
|
|
<AppearanceModeSwitch id="change-layout" config={this.props.config} />
|
2017-09-27 02:33:08 +08:00
|
|
|
<button className="btn btn-large" onClick={this.onClick}>
|
|
|
|
Change theme...
|
|
|
|
</button>
|
2016-04-01 06:52:03 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PreferencesAppearance;
|