Improve dialogs:

- Clear dialogs after closing them
- Rename dialog should be filled with File name intiially
- Add a Cancel button to Create dialog (buttons grouped by twos)
This commit is contained in:
Mahdi Dibaiee
2015-09-16 14:54:16 +04:30
parent 43239b4a4c
commit 427cbca2dc
7 changed files with 96 additions and 27 deletions

View File

@ -102,9 +102,10 @@ export async function createDirectory(...args) {
}
export async function remove(file, deep) {
let path = normalize(file);
let parent = await root();
return parent[deep ? 'removeDeep' : 'remove'](file);
return parent[deep ? 'removeDeep' : 'remove'](path);
}
export async function move(file, newPath) {
@ -117,7 +118,7 @@ export async function move(file, newPath) {
export async function copy(file, newPath) {
let path = normalize(file.path || '').replace(/^\//, '');
let oldPath = path + file.name;
let oldPath = normalize(path + file.name);
newPath = normalize(newPath);

View File

@ -3,16 +3,31 @@ import { template } from 'utils';
export default class Dialog extends Component {
render() {
let { input, title, description, active } = this.props;
let conditionalInput = input ? <input ref='input' /> : '';
let { input, title, description, active, value } = this.props;
let conditionalInput = input ? <input ref='input' value={value} /> : '';
let buttons = this.props.buttons.map((button, i) => {
return <button className={button.className + ' btn'} key={i}
onClick={button.action.bind(this)}>
{button.text}
</button>;
return (
<button className={button.className + ' btn'} key={i}
onClick={button.action.bind(this)}>
{button.text}
</button>
)
});
let groupButtons = [];
for (let i = 0; i < buttons.length; i++) {
if (i % 2 === 0) {
groupButtons.push(
<div className='foot'>
{buttons[i]}
{buttons[i+1]}
</div>
)
}
}
let className = active ? 'dialog active' : 'dialog';
return (
@ -22,9 +37,7 @@ export default class Dialog extends Component {
{conditionalInput}
<div className='foot'>
{buttons}
</div>
{groupButtons}
</div>
)
}

View File

@ -21,6 +21,7 @@ export default {
this.props.dispatch(action);
this.props.dispatch(hideAll());
this.props.dispatch(active());
input.value = '';
}
},
{
@ -34,6 +35,15 @@ export default {
this.props.dispatch(action);
this.props.dispatch(hideAll());
this.props.dispatch(active());
input.value = '';
}
},
{
text: 'Cancel',
action() {
let input = React.findDOMNode(this.refs.input);
this.props.dispatch(hideAll());
input.value = '';
}
}
]
@ -45,7 +55,11 @@ export default {
buttons: [
{
text: 'Cancel',
action: bind(hideAll())
action() {
let input = React.findDOMNode(this.refs.input);
this.props.dispatch(hideAll());
input.value = '';
}
},
{
text: 'Rename',
@ -56,6 +70,7 @@ export default {
this.props.dispatch(rename(activeFile, input.value))
this.props.dispatch(hideAll());
this.props.dispatch(active());
input.value = '';
},
className: 'success'
}
@ -95,7 +110,11 @@ export default {
buttons: [
{
text: 'Cancel',
action: bind(hideAll())
action() {
let input = React.findDOMNode(this.refs.input);
this.props.dispatch(hideAll());
input.value = '';
}
},
{
text: 'Search',
@ -105,6 +124,7 @@ export default {
let action = search(input.value);
this.props.dispatch(action);
this.props.dispatch(hideAll());
input.value = '';
},
className: 'success'
}

View File

@ -11,10 +11,11 @@ const entryMenu = {
action() {
let files = store.getState().get('files');
let active = store.getState().get('activeFile');
const description = `Enter the new name for ${active[0].name}`;
let name = active[0].name;
const description = `Enter the new name for ${name}`;
store.dispatch(hideAll());
store.dispatch(show('renameDialog', {description}));
store.dispatch(show('renameDialog', {description, value: name}));
}
},
{

View File

@ -48,6 +48,8 @@
justify-content: space-between;
margin-bottom: 1rem;
button {
flex: 1;