2017-02-28 21:32:23 +00:00
|
|
|
|
import React, {PureComponent, PropTypes} from 'react';
|
2016-09-03 05:14:48 +00:00
|
|
|
|
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
|
2016-07-16 02:06:10 +00:00
|
|
|
|
import {shell} from 'electron';
|
2016-07-22 22:27:04 +00:00
|
|
|
|
import Modal from '../base/Modal';
|
2017-02-13 08:12:02 +00:00
|
|
|
|
import Button from '../base/Button';
|
2016-07-22 22:27:04 +00:00
|
|
|
|
import ModalBody from '../base/ModalBody';
|
|
|
|
|
import ModalHeader from '../base/ModalHeader';
|
2016-11-07 20:24:38 +00:00
|
|
|
|
import SettingsShortcuts from '../settings/SettingsShortcuts';
|
|
|
|
|
import SettingsAbout from '../settings/SettingsAbout';
|
|
|
|
|
import SettingsGeneral from '../settings/SettingsGeneral';
|
|
|
|
|
import SettingsImportExport from '../settings/SettingsImportExport';
|
2017-01-20 21:54:03 +00:00
|
|
|
|
import SettingsTheme from '../settings/SettingsTheme';
|
2017-01-20 17:51:18 +00:00
|
|
|
|
import * as models from '../../../models/index';
|
2016-11-29 20:55:31 +00:00
|
|
|
|
import {getAppVersion, getAppName} from '../../../common/constants';
|
2016-11-11 01:36:23 +00:00
|
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2017-02-08 00:31:48 +00:00
|
|
|
|
import * as session from '../../../sync/session';
|
2016-05-07 17:29:24 +00:00
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
|
export const TAB_INDEX_EXPORT = 1;
|
2016-07-19 04:01:31 +00:00
|
|
|
|
|
2017-02-28 21:32:23 +00:00
|
|
|
|
class SettingsModal extends PureComponent {
|
2016-08-17 20:58:44 +00:00
|
|
|
|
constructor (props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this._currentTabIndex = -1;
|
2016-11-16 17:18:39 +00:00
|
|
|
|
this.state = {}
|
2016-08-17 20:58:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 21:32:23 +00:00
|
|
|
|
_setModalRef = n => this.modal = n;
|
2017-02-13 08:12:02 +00:00
|
|
|
|
_trackTab = name => trackEvent('Setting', `Tab ${name}`);
|
|
|
|
|
_handleTabSelect = currentTabIndex => this.setState({currentTabIndex});
|
|
|
|
|
_handleUpdateSetting = (key, value) => {
|
|
|
|
|
models.settings.update(this.props.settings, {[key]: value});
|
|
|
|
|
trackEvent('Setting', 'Change', key)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_handleExportAllToFile = () => {
|
|
|
|
|
this.props.handleExportAllToFile();
|
|
|
|
|
this.modal.hide()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_handleExportWorkspace = () => {
|
|
|
|
|
this.props.handleExportWorkspaceToFile();
|
|
|
|
|
this.modal.hide()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_handleImport = () => {
|
|
|
|
|
this.props.handleImportFile();
|
|
|
|
|
this.modal.hide()
|
|
|
|
|
};
|
|
|
|
|
|
2017-02-15 20:32:15 +00:00
|
|
|
|
_handleChangeTheme = (theme, persist = true) => {
|
2017-01-20 21:54:03 +00:00
|
|
|
|
document.body.setAttribute('theme', theme);
|
2017-01-24 06:08:21 +00:00
|
|
|
|
|
2017-02-15 20:32:15 +00:00
|
|
|
|
if (persist) {
|
|
|
|
|
trackEvent('Setting', 'Change Theme', theme);
|
|
|
|
|
models.settings.update(this.props.settings, {theme});
|
2017-01-24 06:08:21 +00:00
|
|
|
|
}
|
2016-11-29 20:55:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-01-23 22:41:31 +00:00
|
|
|
|
componentDidMount () {
|
|
|
|
|
// Hacky way to set theme on launch
|
|
|
|
|
// TODO: move somewhere else
|
2017-01-24 06:08:21 +00:00
|
|
|
|
this._handleChangeTheme(this.props.settings.theme, false);
|
2017-01-23 22:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
|
show (currentTabIndex = 0) {
|
|
|
|
|
this.setState({currentTabIndex});
|
|
|
|
|
this.modal.show();
|
2016-07-19 04:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
|
hide () {
|
|
|
|
|
this.modal.hide();
|
2016-08-17 20:58:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
|
toggle (currentTabIndex = 0) {
|
|
|
|
|
this.setState({currentTabIndex});
|
|
|
|
|
this.modal.toggle();
|
2016-07-19 04:01:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render () {
|
2017-02-13 08:12:02 +00:00
|
|
|
|
const {settings} = this.props;
|
2016-11-16 17:18:39 +00:00
|
|
|
|
const {currentTabIndex} = this.state;
|
2017-02-08 00:31:48 +00:00
|
|
|
|
const email = session.isLoggedIn() ? session.getEmail() : null;
|
2016-07-19 04:01:31 +00:00
|
|
|
|
|
2016-05-07 17:29:24 +00:00
|
|
|
|
return (
|
2017-02-13 08:12:02 +00:00
|
|
|
|
<Modal ref={this._setModalRef} tall={true} {...this.props}>
|
2016-07-19 22:28:29 +00:00
|
|
|
|
<ModalHeader>
|
2016-11-29 20:55:31 +00:00
|
|
|
|
{getAppName()} Preferences
|
2017-02-08 00:31:48 +00:00
|
|
|
|
<span className="faint txt-sm">
|
|
|
|
|
–
|
2017-02-13 08:12:02 +00:00
|
|
|
|
v{getAppVersion()}
|
|
|
|
|
{email ? ` – ${email}` : null}
|
2017-02-08 00:31:48 +00:00
|
|
|
|
</span>
|
2016-07-19 22:28:29 +00:00
|
|
|
|
</ModalHeader>
|
2016-10-21 17:20:36 +00:00
|
|
|
|
<ModalBody noScroll={true}>
|
2017-02-13 08:12:02 +00:00
|
|
|
|
<Tabs onSelect={this._handleTabSelect} selectedIndex={currentTabIndex}>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
<TabList>
|
|
|
|
|
<Tab selected={this._currentTabIndex === 0}>
|
2017-02-13 08:12:02 +00:00
|
|
|
|
<Button value="General" onClick={this._trackTab}>
|
2017-01-20 21:54:03 +00:00
|
|
|
|
General
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
|
|
|
|
<Tab selected={this._currentTabIndex === 1}>
|
2017-02-13 08:12:02 +00:00
|
|
|
|
<Button value="Import/Export" onClick={this._trackTab}>
|
2017-01-20 21:54:03 +00:00
|
|
|
|
Import/Export
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
|
|
|
|
<Tab selected={this._currentTabIndex === 2}>
|
2017-02-13 08:12:02 +00:00
|
|
|
|
<Button value="Themes" onClick={this._trackTab}>
|
2017-01-23 22:41:31 +00:00
|
|
|
|
Themes
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2017-01-20 21:54:03 +00:00
|
|
|
|
</Tab>
|
|
|
|
|
<Tab selected={this._currentTabIndex === 3}>
|
2017-02-13 08:12:02 +00:00
|
|
|
|
<Button value="shortcuts" onClick={this._trackTab}>
|
2017-01-20 21:54:03 +00:00
|
|
|
|
Shortcuts
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
2017-02-13 08:12:02 +00:00
|
|
|
|
<Tab selected={this._currentTabIndex === 4}>
|
|
|
|
|
<Button value="About" onClick={this._trackTab}>
|
2017-01-20 21:54:03 +00:00
|
|
|
|
About
|
2017-02-13 08:12:02 +00:00
|
|
|
|
</Button>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</Tab>
|
|
|
|
|
</TabList>
|
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
|
<SettingsGeneral
|
|
|
|
|
settings={settings}
|
2017-02-13 08:12:02 +00:00
|
|
|
|
updateSetting={this._handleUpdateSetting}
|
2016-11-16 17:18:39 +00:00
|
|
|
|
/>
|
|
|
|
|
</TabPanel>
|
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
|
<SettingsImportExport
|
2017-02-13 08:12:02 +00:00
|
|
|
|
handleExportAll={this._handleExportAllToFile}
|
|
|
|
|
handleExportWorkspace={this._handleExportWorkspace}
|
|
|
|
|
handleImport={this._handleImport}
|
2016-11-16 17:18:39 +00:00
|
|
|
|
/>
|
|
|
|
|
</TabPanel>
|
|
|
|
|
<TabPanel className="pad scrollable">
|
2017-01-20 21:54:03 +00:00
|
|
|
|
<SettingsTheme
|
|
|
|
|
handleChangeTheme={this._handleChangeTheme}
|
|
|
|
|
activeTheme={settings.theme}
|
|
|
|
|
/>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</TabPanel>
|
|
|
|
|
<TabPanel className="pad scrollable">
|
2017-01-20 21:54:03 +00:00
|
|
|
|
<SettingsShortcuts />
|
2016-11-16 17:18:39 +00:00
|
|
|
|
</TabPanel>
|
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
|
<SettingsAbout/>
|
|
|
|
|
</TabPanel>
|
|
|
|
|
</Tabs>
|
2016-05-07 17:29:24 +00:00
|
|
|
|
</ModalBody>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-16 17:18:39 +00:00
|
|
|
|
|
|
|
|
|
SettingsModal.propTypes = {
|
|
|
|
|
// Functions
|
|
|
|
|
handleExportWorkspaceToFile: PropTypes.func.isRequired,
|
|
|
|
|
handleExportAllToFile: PropTypes.func.isRequired,
|
|
|
|
|
handleImportFile: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
|
settings: PropTypes.object.isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
2016-05-07 17:29:24 +00:00
|
|
|
|
export default SettingsModal;
|