var React = require('react');
var connect = require('react-redux').connect;
var actions = require('../../store/actions');
var dialog = require('remote').require('dialog');
var ProfileMenu = React.createClass({
render: function() {
return (
Ouvrir
Enregistrer
);
},
handleOpenClick: function() {
var dispatch = this.props.dispatch;
this.showOpenProfileDialog()
.then(function(profilePath) {
if(profilePath) dispatch(actions.common.loadProfile(profilePath));
})
;
},
handleSaveClick: function() {
var dispatch = this.props.dispatch;
var profile = this.props.profile;
var profilePath = this.props.profilePath;
var promise = profilePath ? Promise.resolve(profilePath) : this.showSaveProfileDialog();
promise.then(function(profilePath) {
if(profilePath) dispatch(actions.edit.saveProfile(profilePath, profile));
});
},
showOpenProfileDialog: function() {
return new Promise(function(resolve) {
dialog.showOpenDialog(
{
title: 'Éditer un profil',
filters: [ {name: 'Profils Pitaya', extensions: ['json'] } ],
properties: ['openFile']
},
function(files) {
return resolve(files ? files[0] : null);
}
)
});
},
showSaveProfileDialog: function() {
return new Promise(function(resolve) {
dialog.showSaveDialog(
{
title: 'Éditer un profil',
filters: [ {name: 'Profils Pitaya', extensions: ['json'] } ]
},
function(file) {
return resolve(file);
}
)
});
}
});
function select(state) {
return {
profile: state.profile,
profilePath: state.profilePath
};
}
module.exports = connect(select)(ProfileMenu);