@@ -15,7 +15,8 @@ const highlighter = require('../lib/highlighter');
15
15
16
16
const {
17
17
NEW_FILE ,
18
- CHANGE_FILE
18
+ CHANGE_FILE ,
19
+ OVERWRITE_FILE
19
20
} = require ( '../constants/queued-action-types' ) ;
20
21
21
22
// TODO: move somewhere else?
@@ -71,6 +72,8 @@ function handlers(app, opts, done){
71
72
return newFile ( ) ;
72
73
case CHANGE_FILE :
73
74
return changeFile ( nextFile ) ;
75
+ case OVERWRITE_FILE :
76
+ return saveFileAs ( nextFile , true ) ;
74
77
}
75
78
}
76
79
@@ -117,23 +120,32 @@ function handlers(app, opts, done){
117
120
. then ( function ( ) {
118
121
documents . swap ( path . join ( cwd , filename ) ) ;
119
122
} ) ;
123
+ store . dispatch ( creators . hideOverlay ( ) ) ;
120
124
}
121
125
}
122
126
123
- function saveFileAs ( filename ) {
127
+ function saveFileAs ( filename , overwrite ) {
124
128
if ( ! filename ) {
125
129
return ;
126
130
}
127
131
128
- const { cwd, content } = workspace . getState ( ) ;
132
+ const { cwd, content, directory } = workspace . getState ( ) ;
133
+ if ( ! overwrite && _ . filter ( directory , { name : filename } ) . length ) {
134
+ return showOverwriteOverlay ( filename ) ;
135
+ }
129
136
130
137
workspace . updateFilename ( filename )
131
138
. then ( ( ) => workspace . saveFile ( filename , content ) )
132
139
. then ( ( ) => userConfig . set ( 'last-file' , filename ) )
133
140
. then ( function ( ) {
134
- documents . swap ( path . join ( cwd , filename ) ) ;
141
+ documents . replace ( path . join ( cwd , filename ) ) ;
135
142
handleActionQueue ( ) ;
136
143
} ) ;
144
+ store . dispatch ( creators . hideOverlay ( ) ) ;
145
+ }
146
+
147
+ function overwriteFile ( ) {
148
+ handleActionQueue ( ) ;
137
149
}
138
150
139
151
function dontSaveFile ( ) {
@@ -233,6 +245,11 @@ function handlers(app, opts, done){
233
245
store . dispatch ( creators . showSaveOverlay ( ) ) ;
234
246
}
235
247
248
+ function showOverwriteOverlay ( name ) {
249
+ store . dispatch ( creators . queueOverwriteFile ( name ) ) ;
250
+ store . dispatch ( creators . showOverwriteOverlay ( ) ) ;
251
+ }
252
+
236
253
function showDownloadOverlay ( ) {
237
254
store . dispatch ( creators . showDownloadOverlay ( ) ) ;
238
255
// TODO: is there ever a time when show download overlay doesn't reload devices?
@@ -571,6 +588,7 @@ function handlers(app, opts, done){
571
588
deleteFile,
572
589
changeFile,
573
590
dontSaveFile,
591
+ overwriteFile,
574
592
// project methods
575
593
changeProject,
576
594
deleteProject,
0 commit comments