From 11672c58f0e5eae0d17f5a01b8945a3eb58052d0 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Wed, 16 Sep 2015 19:16:54 +0430 Subject: [PATCH] Fix pre-filling rename dialog with file name --- build/main.js | 22 ++++++++++++++++++++-- releases/hawk-1.0.0.zip | Bin 1248294 -> 1248546 bytes src/js/components/dialog.js | 12 ++++++++++-- src/js/dialogs.js | 12 +++++++++++- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/build/main.js b/build/main.js index 5707cb5..b1ef892 100644 --- a/build/main.js +++ b/build/main.js @@ -30343,9 +30343,8 @@ var Dialog = (function (_Component) { var title = _props.title; var description = _props.description; 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) { return _react2['default'].createElement( @@ -30388,6 +30387,15 @@ var Dialog = (function (_Component) { 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; @@ -31584,6 +31592,8 @@ var _store = require('store'); var _store2 = _interopRequireDefault(_store); +var INVALID_NAME = 'Please enter a valid name.'; + exports['default'] = { createDialog: { title: 'Create', @@ -31594,6 +31604,8 @@ exports['default'] = { action: function action() { 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 path = cwd + '/' + input.value; var action = (0, _actionsFile.create)(path.replace(/^\//, '')); @@ -31607,6 +31619,8 @@ exports['default'] = { action: function action() { 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 path = cwd + '/' + input.value; var action = (0, _actionsFile.create)(path.replace(/^\//, ''), true); @@ -31640,6 +31654,8 @@ exports['default'] = { action: function action() { 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'); this.props.dispatch((0, _actionsFile.rename)(activeFile, input.value)); this.props.dispatch((0, _actionsDialog.hideAll)()); @@ -31689,6 +31705,8 @@ exports['default'] = { action: function action() { 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); this.props.dispatch(action); this.props.dispatch((0, _actionsDialog.hideAll)()); diff --git a/releases/hawk-1.0.0.zip b/releases/hawk-1.0.0.zip index 7f2cb3b188556d29e2cd5843002567f1cb942960..4e32b79bdcacb38adccdf03fc54ddbf1c0119cf1 100644 GIT binary patch delta 894 zcma)*-Afcv7{=$!e$38{?#_7dD|U6vi``9KO-pLm4b-Is4XiLJDwuZ9>e6bsA4Uq1 zK^fji2%SYL#EbAskifZ#pj+9St_l^TKOkB!guyWOyfb`E0;Ice@*SBNoBHm!riJqmdXuUn;>| zxQ@OGV4CirZ!R#(7+P?Ed6h=GY5q*1F%dfBvuKwGbMX=KnXAZCbYO?htp(I$1};;y zXXebVpy$YaSm?O)S{^AjEP1$wrFnG~G4V_`COeaZ$;l)zxtK&IiAiRvV5($t8|td3 zaMj(aWk@ot`Qzgxe$P)&c$IZy^uY6kr`_|4*Vmj(rAgZanaqducrG{o8rYSx30*&_)pswMSwme5aomDQBQl)9SZGjf?cF&@N} zjwss*EzK#NbbC&zhF!6ud4rE?^!tdtrs=Yt8xQGsvjNj&?&l{Hfoy7qXzkjxp3ak? z(c7hp2tMA>8TF=1o=;vKH4BT*8^Ghy#4(d~)#YCBJL>z(sj%dxVl`LK>b5XMLwj^tvUB=x<4i+7d zu^%#~WbEa8&eBC0`=DNjx)7m78Q1s1VU%V!_dmCA97r_(pnpSgr;5ww9;Qhsp3M#q SI-KyJmfd|0j@uG2tNsGn_BV3? delta 712 zcmZ29%V*gPAD#ejW)?065HPQu$fL*vB=r@5z zdRq9I4?uc*iU;EjUJ%1BjPW5mh@lwA_?8325J+e2Vg)hgXyR8P$w; zm_Q7-I!0NruGCh>uPh*um@Y;euz|CtGu{WAQ@wz(gOSg?*1-La?0;vaN&E~-liCFr zF#<6Y5HkZY3lOscF&hxG12G2>a{@6J5OV`D4-oSLG2eEW;Yo~v75>S|)=PbaxeU_`h9~(yB=?|L(jHaJz z5)cI%1Y|33WK@{`K9ogF+&8f#L$4^mG%rP?II}8ML0_RPF{dbOMx~#U*SF62Hy`Q7_C5q5YwBH#fw*W87eU z(|Cl<&?0HN3y-im$cS7XVHqX|lj+?&!m=R#Dj?r_j+G!oL4HnUT4qj;URH5{HzSh> m11u>TxN}u+`*>ZOfdPa$!3h*bT(~uzkylun?HrphPzV5!LfGQ~ diff --git a/src/js/components/dialog.js b/src/js/components/dialog.js index 44a8255..27c85de 100644 --- a/src/js/components/dialog.js +++ b/src/js/components/dialog.js @@ -3,8 +3,8 @@ import { template } from 'utils'; export default class Dialog extends Component { render() { - let { input, title, description, active, value } = this.props; - let conditionalInput = input ? : ''; + let { input, title, description, active } = this.props; + let conditionalInput = input ? : ''; let buttons = this.props.buttons.map((button, i) => { return ( @@ -41,4 +41,12 @@ export default class Dialog extends Component { ) } + + componentDidUpdate() { + if (!this.props.value) return; + + let input = React.findDOMNode(this.refs.input); + + input.value = this.props.value; + } } diff --git a/src/js/dialogs.js b/src/js/dialogs.js index a233019..624c4e2 100644 --- a/src/js/dialogs.js +++ b/src/js/dialogs.js @@ -1,9 +1,11 @@ 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 { search } from 'actions/files-view'; import store, { bind } from 'store'; +const INVALID_NAME = 'Please enter a valid name.'; + export default { createDialog: { title: 'Create', @@ -15,6 +17,8 @@ export default { action() { let input = React.findDOMNode(this.refs.input); + if (!input.value) show('errorDialog', {description: INVALID_NAME}); + let cwd = store.getState().get('cwd'); let path = cwd + '/' + input.value; let action = create(path.replace(/^\//, '')); @@ -29,6 +33,8 @@ export default { action() { let input = React.findDOMNode(this.refs.input); + if (!input.value) show('errorDialog', {description: INVALID_NAME}); + let cwd = store.getState().get('cwd'); let path = cwd + '/' + input.value; let action = create(path.replace(/^\//, ''), true); @@ -66,6 +72,8 @@ export default { action() { let input = React.findDOMNode(this.refs.input); + if (!input.value) show('errorDialog', {description: INVALID_NAME}); + let activeFile = store.getState().get('activeFile'); this.props.dispatch(rename(activeFile, input.value)) this.props.dispatch(hideAll()); @@ -121,6 +129,8 @@ export default { action() { let input = React.findDOMNode(this.refs.input); + if (!input.value) show('errorDialog', {description: INVALID_NAME}); + let action = search(input.value); this.props.dispatch(action); this.props.dispatch(hideAll());