Skip to content

Commit db32c69

Browse files
committed
Merge pull request #41 from parallaxinc/delete-file-dialog
add confirmation dialog for delete file operation - ref #27
2 parents aa79359 + 717f796 commit db32c69

File tree

3 files changed

+70
-17
lines changed

3 files changed

+70
-17
lines changed

plugins/sidebar/file-operations.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const { Menu, MainButton, ChildButton } = require('react-mfb-iceddev');
55

66
require('react-mfb-iceddev/mfb.css');
77

8-
const NewFileOverlay = require('./new-file-overlay');
8+
const NewFileOverlay = require('./overlays/new-file');
9+
const DeleteFileOverlay = require('./overlays/delete-file');
910

1011
const FileOperations = React.createClass({
1112
saveFile: function(evt){
@@ -31,7 +32,17 @@ const FileOperations = React.createClass({
3132
// TODO: these should transparently accept cursors for all non-function params
3233
space.saveFile(space.filename.deref(), space.current, overlay.hide);
3334
},
34-
newFile: function(evt){
35+
deleteFile: function(name){
36+
const space = this.props.workspace;
37+
const overlay = this.props.overlay;
38+
39+
if(!name){
40+
return;
41+
}
42+
43+
space.deleteFile(space.filename, overlay.hide);
44+
},
45+
showCreateOverlay: function(evt){
3546
evt.preventDefault();
3647

3748
const overlay = this.props.overlay;
@@ -44,37 +55,35 @@ const FileOperations = React.createClass({
4455

4556
overlay.show({ backdrop: true });
4657
},
47-
deleteFile: function(evt){
58+
showDeleteOverlay: function(evt){
4859
evt.preventDefault();
4960

5061
const space = this.props.workspace;
62+
const overlay = this.props.overlay;
5163

52-
space.deleteFile(space.filename, function(err){
53-
console.log('deleted', err);
54-
});
55-
},
56-
updateName: function(evt){
57-
const space = this.props.workspace;
58-
evt.stopPropagation();
59-
evt.preventDefault();
60-
space.filename.update(function(){
61-
return evt.target.value;
62-
});
64+
overlay.content(
65+
<DeleteFileOverlay
66+
filename={space.filename.deref()}
67+
onAccept={this.deleteFile}
68+
onCancel={overlay.hide} />
69+
);
70+
71+
overlay.show({ backdrop: true });
6372
},
6473
render: function(){
6574
return (
6675
<Menu effect="zoomin" method="click" position="bl">
6776
<MainButton iconResting="ion-plus-round" iconActive="ion-close-round" />
6877
<ChildButton
69-
onClick={this.deleteFile}
78+
onClick={this.showDeleteOverlay}
7079
icon="ion-backspace-outline"
7180
label="Delete File" />
7281
<ChildButton
7382
onClick={this.saveFile}
7483
icon="ion-compose"
7584
label="Save File" />
7685
<ChildButton
77-
onClick={this.newFile}
86+
onClick={this.showCreateOverlay}
7887
icon="ion-document"
7988
label="New File" />
8089
</Menu>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
const Card = require('react-material/components/Card');
5+
const Button = require('react-material/components/Button');
6+
7+
const styles = require('../styles');
8+
9+
class DeleteFileOverlay extends React.Component {
10+
constructor(){
11+
this.state = {
12+
value: ''
13+
};
14+
15+
this.onAccept = this.onAccept.bind(this);
16+
this.onCancel = this.onCancel.bind(this);
17+
}
18+
19+
onAccept(evt){
20+
if(typeof this.props.onAccept === 'function'){
21+
this.props.onAccept(this.props.filename, evt);
22+
}
23+
}
24+
25+
onCancel(evt){
26+
if(typeof this.props.onCancel === 'function'){
27+
this.props.onCancel(evt);
28+
}
29+
}
30+
31+
render(){
32+
return (
33+
<Card styles={styles.overlay}>
34+
<h3 style={styles.overlayTitle}>Are you you want to delete {this.props.filename}?</h3>
35+
<div style={styles.overlayButtonContainer}>
36+
<Button onClick={this.onAccept}>Yes</Button>
37+
<Button onClick={this.onCancel}>No</Button>
38+
</div>
39+
</Card>
40+
);
41+
}
42+
}
43+
44+
module.exports = DeleteFileOverlay;

plugins/sidebar/new-file-overlay.js renamed to plugins/sidebar/overlays/new-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Card = require('react-material/components/Card');
55
const Button = require('react-material/components/Button');
66
const TextField = require('react-material/components/TextField');
77

8-
const styles = require('./styles');
8+
const styles = require('../styles');
99

1010
class NewFileOverlay extends React.Component {
1111
constructor(){

0 commit comments

Comments
 (0)