Fix pre-filling rename dialog with file name

This commit is contained in:
Mahdi Dibaiee 2015-09-16 19:16:54 +04:30
parent 31a873d2bb
commit 11672c58f0
4 changed files with 41 additions and 5 deletions

View File

@ -30343,9 +30343,8 @@ var Dialog = (function (_Component) {
var title = _props.title; var title = _props.title;
var description = _props.description; var description = _props.description;
var active = _props.active; var active = _props.active;
var value = _props.value;
var conditionalInput = input ? _react2['default'].createElement('input', { ref: 'input', defaultValue: value }) : ''; var conditionalInput = input ? _react2['default'].createElement('input', { ref: 'input' }) : '';
var buttons = this.props.buttons.map(function (button, i) { var buttons = this.props.buttons.map(function (button, i) {
return _react2['default'].createElement( return _react2['default'].createElement(
@ -30388,6 +30387,15 @@ var Dialog = (function (_Component) {
groupButtons groupButtons
); );
} }
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
if (!this.props.value) return;
var input = _react2['default'].findDOMNode(this.refs.input);
input.value = this.props.value;
}
}]); }]);
return Dialog; return Dialog;
@ -31584,6 +31592,8 @@ var _store = require('store');
var _store2 = _interopRequireDefault(_store); var _store2 = _interopRequireDefault(_store);
var INVALID_NAME = 'Please enter a valid name.';
exports['default'] = { exports['default'] = {
createDialog: { createDialog: {
title: 'Create', title: 'Create',
@ -31594,6 +31604,8 @@ exports['default'] = {
action: function action() { action: function action() {
var input = _react2['default'].findDOMNode(this.refs.input); var input = _react2['default'].findDOMNode(this.refs.input);
if (!input.value) (0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME });
var cwd = _store2['default'].getState().get('cwd'); var cwd = _store2['default'].getState().get('cwd');
var path = cwd + '/' + input.value; var path = cwd + '/' + input.value;
var action = (0, _actionsFile.create)(path.replace(/^\//, '')); var action = (0, _actionsFile.create)(path.replace(/^\//, ''));
@ -31607,6 +31619,8 @@ exports['default'] = {
action: function action() { action: function action() {
var input = _react2['default'].findDOMNode(this.refs.input); var input = _react2['default'].findDOMNode(this.refs.input);
if (!input.value) (0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME });
var cwd = _store2['default'].getState().get('cwd'); var cwd = _store2['default'].getState().get('cwd');
var path = cwd + '/' + input.value; var path = cwd + '/' + input.value;
var action = (0, _actionsFile.create)(path.replace(/^\//, ''), true); var action = (0, _actionsFile.create)(path.replace(/^\//, ''), true);
@ -31640,6 +31654,8 @@ exports['default'] = {
action: function action() { action: function action() {
var input = _react2['default'].findDOMNode(this.refs.input); var input = _react2['default'].findDOMNode(this.refs.input);
if (!input.value) (0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME });
var activeFile = _store2['default'].getState().get('activeFile'); var activeFile = _store2['default'].getState().get('activeFile');
this.props.dispatch((0, _actionsFile.rename)(activeFile, input.value)); this.props.dispatch((0, _actionsFile.rename)(activeFile, input.value));
this.props.dispatch((0, _actionsDialog.hideAll)()); this.props.dispatch((0, _actionsDialog.hideAll)());
@ -31689,6 +31705,8 @@ exports['default'] = {
action: function action() { action: function action() {
var input = _react2['default'].findDOMNode(this.refs.input); var input = _react2['default'].findDOMNode(this.refs.input);
if (!input.value) (0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME });
var action = (0, _actionsFilesView.search)(input.value); var action = (0, _actionsFilesView.search)(input.value);
this.props.dispatch(action); this.props.dispatch(action);
this.props.dispatch((0, _actionsDialog.hideAll)()); this.props.dispatch((0, _actionsDialog.hideAll)());

Binary file not shown.

View File

@ -3,8 +3,8 @@ import { template } from 'utils';
export default class Dialog extends Component { export default class Dialog extends Component {
render() { render() {
let { input, title, description, active, value } = this.props; let { input, title, description, active } = this.props;
let conditionalInput = input ? <input ref='input' defaultValue={value} /> : ''; let conditionalInput = input ? <input ref='input' /> : '';
let buttons = this.props.buttons.map((button, i) => { let buttons = this.props.buttons.map((button, i) => {
return ( return (
@ -41,4 +41,12 @@ export default class Dialog extends Component {
</div> </div>
) )
} }
componentDidUpdate() {
if (!this.props.value) return;
let input = React.findDOMNode(this.refs.input);
input.value = this.props.value;
}
} }

View File

@ -1,9 +1,11 @@
import React from 'react'; import React from 'react';
import { hide, hideAll } from 'actions/dialog'; import { hide, hideAll, show } from 'actions/dialog';
import { rename, remove, create, active } from 'actions/file'; import { rename, remove, create, active } from 'actions/file';
import { search } from 'actions/files-view'; import { search } from 'actions/files-view';
import store, { bind } from 'store'; import store, { bind } from 'store';
const INVALID_NAME = 'Please enter a valid name.';
export default { export default {
createDialog: { createDialog: {
title: 'Create', title: 'Create',
@ -15,6 +17,8 @@ export default {
action() { action() {
let input = React.findDOMNode(this.refs.input); let input = React.findDOMNode(this.refs.input);
if (!input.value) show('errorDialog', {description: INVALID_NAME});
let cwd = store.getState().get('cwd'); let cwd = store.getState().get('cwd');
let path = cwd + '/' + input.value; let path = cwd + '/' + input.value;
let action = create(path.replace(/^\//, '')); let action = create(path.replace(/^\//, ''));
@ -29,6 +33,8 @@ export default {
action() { action() {
let input = React.findDOMNode(this.refs.input); let input = React.findDOMNode(this.refs.input);
if (!input.value) show('errorDialog', {description: INVALID_NAME});
let cwd = store.getState().get('cwd'); let cwd = store.getState().get('cwd');
let path = cwd + '/' + input.value; let path = cwd + '/' + input.value;
let action = create(path.replace(/^\//, ''), true); let action = create(path.replace(/^\//, ''), true);
@ -66,6 +72,8 @@ export default {
action() { action() {
let input = React.findDOMNode(this.refs.input); let input = React.findDOMNode(this.refs.input);
if (!input.value) show('errorDialog', {description: INVALID_NAME});
let activeFile = store.getState().get('activeFile'); let activeFile = store.getState().get('activeFile');
this.props.dispatch(rename(activeFile, input.value)) this.props.dispatch(rename(activeFile, input.value))
this.props.dispatch(hideAll()); this.props.dispatch(hideAll());
@ -121,6 +129,8 @@ export default {
action() { action() {
let input = React.findDOMNode(this.refs.input); let input = React.findDOMNode(this.refs.input);
if (!input.value) show('errorDialog', {description: INVALID_NAME});
let action = search(input.value); let action = search(input.value);
this.props.dispatch(action); this.props.dispatch(action);
this.props.dispatch(hideAll()); this.props.dispatch(hideAll());