Mailspring/internal_packages/preferences/lib/tabs/preferences-appearance.jsx
Ben Gotow a48ddd51f8 refactor(menus): Major prune of keymaps/commands, real conditional menus
Summary:
Keymaps & menus CSON => JSON, remove AtomKeymaps, CommandRegistry use of CSS selectors, use Mousetrap instead

Important Notes:

- The `application:` prefix is reserved for commands which are handled in the application process. Don't use it for other things. You will not receive the events in the window.

- Maintaining dynamic menus seems to come with quite an overhead, because Electron updates the entire menu every time. In the future, we'll need https://github.com/electron/electron/issues/528 to really make things nice. I will be tracking this upstream.

- The format for keyboard shortcuts has changed. `cmd-X` is now `command+shift+x`

Test Plan: Run tests

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2917
2016-04-24 12:16:25 -05:00

118 lines
2.7 KiB
JavaScript

import React from 'react';
import {RetinaImg, Flexbox} from 'nylas-component-kit';
class AppearanceModeSwitch extends React.Component {
static displayName = 'AppearanceModeSwitch';
static propTypes = {
config: React.PropTypes.object.isRequired,
};
constructor(props) {
super();
this.state = {
value: props.config.get('core.workspace.mode'),
};
}
componentWillReceiveProps(nextProps) {
this.setState({
value: nextProps.config.get('core.workspace.mode'),
});
}
_onApplyChanges = () => {
NylasEnv.commands.dispatch(`application:select-${this.state.value}-mode`);
}
_renderModeOptions() {
return ['list', 'split'].map((mode) =>
<AppearanceModeOption
mode={mode}
key={mode}
active={this.state.value === mode}
onClick={() => this.setState({value: mode})} />
);
}
render() {
const hasChanges = this.state.value !== this.props.config.get('core.workspace.mode');
let applyChangesClass = "btn";
if (!hasChanges) applyChangesClass += " btn-disabled";
return (
<div className="appearance-mode-switch">
<Flexbox
direction="row"
style={{alignItems: "center"}}
className="item">
{this._renderModeOptions()}
</Flexbox>
<div className={applyChangesClass} onClick={this._onApplyChanges}>Apply Layout</div>
</div>
);
}
}
class AppearanceModeOption extends React.Component {
static propTypes = {
mode: React.PropTypes.string.isRequired,
active: React.PropTypes.bool,
onClick: React.PropTypes.func,
}
constructor() {
super();
}
render() {
let classname = "appearance-mode";
if (this.props.active) classname += " active";
const label = {
'list': 'Single Panel',
'split': 'Two Panel',
}[this.props.mode];
return (
<div className={classname} onClick={this.props.onClick}>
<RetinaImg name={`appearance-mode-${this.props.mode}.png`} mode={RetinaImg.Mode.ContentIsMask}/>
<div>{label}</div>
</div>
);
}
}
class PreferencesAppearance extends React.Component {
static displayName = 'PreferencesAppearance';
static propTypes = {
config: React.PropTypes.object,
configSchema: React.PropTypes.object,
}
onClick = () => {
NylasEnv.commands.dispatch("window:launch-theme-picker");
}
render() {
return (
<div className="container-appearance">
<label>Change layout:</label>
<AppearanceModeSwitch config={this.props.config} />
<button className="btn btn-large" onClick={this.onClick}>Change theme...</button>
</div>
);
}
}
export default PreferencesAppearance;