2016-07-19 04:01:31 +00:00
|
|
|
import React, {Component, 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';
|
|
|
|
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';
|
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
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
class SettingsModal extends Component {
|
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-01-24 06:08:21 +00:00
|
|
|
_handleChangeTheme = (theme, track = true) => {
|
2017-01-20 21:54:03 +00:00
|
|
|
document.body.setAttribute('theme', theme);
|
|
|
|
models.settings.update(this.props.settings, {theme});
|
2017-01-24 06:08:21 +00:00
|
|
|
|
|
|
|
if (track) {
|
|
|
|
trackEvent('Setting', 'Change Theme', theme)
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
_handleTabSelect (currentTabIndex) {
|
|
|
|
this.setState({currentTabIndex});
|
2016-08-15 22:31:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
render () {
|
2016-11-16 17:18:39 +00:00
|
|
|
const {
|
|
|
|
settings,
|
|
|
|
handleExportAllToFile,
|
|
|
|
handleExportWorkspaceToFile,
|
|
|
|
handleImportFile,
|
|
|
|
} = this.props;
|
2016-07-21 16:33:35 +00:00
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
const {currentTabIndex} = this.state;
|
2016-07-19 04:01:31 +00:00
|
|
|
|
2016-05-07 17:29:24 +00:00
|
|
|
return (
|
2016-08-15 17:04:36 +00:00
|
|
|
<Modal ref={m => this.modal = m} tall={true} {...this.props}>
|
2016-07-19 22:28:29 +00:00
|
|
|
<ModalHeader>
|
2016-11-29 20:55:31 +00:00
|
|
|
{getAppName()} Preferences
|
2016-07-21 22:26:51 +00:00
|
|
|
|
|
|
|
<span className="faint txt-sm">v{getAppVersion()}</span>
|
2016-07-19 22:28:29 +00:00
|
|
|
</ModalHeader>
|
2016-10-21 17:20:36 +00:00
|
|
|
<ModalBody noScroll={true}>
|
2016-11-16 17:18:39 +00:00
|
|
|
<Tabs onSelect={i => this._handleTabSelect(i)} selectedIndex={currentTabIndex}>
|
|
|
|
<TabList>
|
|
|
|
<Tab selected={this._currentTabIndex === 0}>
|
2017-01-20 21:54:03 +00:00
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab General')}>
|
|
|
|
General
|
|
|
|
</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab selected={this._currentTabIndex === 1}>
|
2017-01-20 21:54:03 +00:00
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab Import/Export')}>
|
|
|
|
Import/Export
|
2016-12-21 23:37:48 +00:00
|
|
|
</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab selected={this._currentTabIndex === 2}>
|
2017-01-23 22:41:31 +00:00
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab Themes')}>
|
|
|
|
Themes
|
2017-01-20 21:54:03 +00:00
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
<Tab selected={this._currentTabIndex === 3}>
|
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab Shortcuts')}>
|
|
|
|
Shortcuts
|
|
|
|
</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
</Tab>
|
2017-01-20 21:54:03 +00:00
|
|
|
<Tab selected={this._currentTabIndex === 5}>
|
|
|
|
<button onClick={e => trackEvent('Setting', 'Tab About')}>
|
|
|
|
About
|
|
|
|
</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
</Tab>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
<SettingsGeneral
|
|
|
|
settings={settings}
|
2016-11-23 19:33:24 +00:00
|
|
|
updateSetting={(key, value) => {
|
|
|
|
models.settings.update(settings, {[key]: value});
|
|
|
|
trackEvent('Setting', 'Change', key)
|
|
|
|
}}
|
2016-11-16 17:18:39 +00:00
|
|
|
/>
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="pad scrollable">
|
|
|
|
<SettingsImportExport
|
|
|
|
handleExportAll={() => {
|
|
|
|
handleExportAllToFile();
|
|
|
|
this.modal.hide()
|
|
|
|
}}
|
|
|
|
handleExportWorkspace={() => {
|
|
|
|
handleExportWorkspaceToFile();
|
|
|
|
this.modal.hide()
|
|
|
|
}}
|
|
|
|
handleImport={() => {
|
|
|
|
handleImportFile();
|
|
|
|
this.modal.hide()
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</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;
|