@@ -15,7 +15,8 @@ const highlighter = require('../lib/highlighter');
1515
1616const {
1717 NEW_FILE ,
18- CHANGE_FILE
18+ CHANGE_FILE ,
19+ OVERWRITE_FILE
1920} = require ( '../constants/queued-action-types' ) ;
2021
2122// TODO: move somewhere else?
@@ -71,6 +72,8 @@ function handlers(app, opts, done){
7172 return newFile ( ) ;
7273 case CHANGE_FILE :
7374 return changeFile ( nextFile ) ;
75+ case OVERWRITE_FILE :
76+ return saveFileAs ( nextFile , true ) ;
7477 }
7578 }
7679
@@ -117,23 +120,32 @@ function handlers(app, opts, done){
117120 . then ( function ( ) {
118121 documents . swap ( path . join ( cwd , filename ) ) ;
119122 } ) ;
123+ store . dispatch ( creators . hideOverlay ( ) ) ;
120124 }
121125 }
122126
123- function saveFileAs ( filename ) {
127+ function saveFileAs ( filename , overwrite ) {
124128 if ( ! filename ) {
125129 return ;
126130 }
127131
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+ }
129136
130137 workspace . updateFilename ( filename )
131138 . then ( ( ) => workspace . saveFile ( filename , content ) )
132139 . then ( ( ) => userConfig . set ( 'last-file' , filename ) )
133140 . then ( function ( ) {
134- documents . swap ( path . join ( cwd , filename ) ) ;
141+ documents . replace ( path . join ( cwd , filename ) ) ;
135142 handleActionQueue ( ) ;
136143 } ) ;
144+ store . dispatch ( creators . hideOverlay ( ) ) ;
145+ }
146+
147+ function overwriteFile ( ) {
148+ handleActionQueue ( ) ;
137149 }
138150
139151 function dontSaveFile ( ) {
@@ -233,6 +245,11 @@ function handlers(app, opts, done){
233245 store . dispatch ( creators . showSaveOverlay ( ) ) ;
234246 }
235247
248+ function showOverwriteOverlay ( name ) {
249+ store . dispatch ( creators . queueOverwriteFile ( name ) ) ;
250+ store . dispatch ( creators . showOverwriteOverlay ( ) ) ;
251+ }
252+
236253 function showDownloadOverlay ( ) {
237254 store . dispatch ( creators . showDownloadOverlay ( ) ) ;
238255 // TODO: is there ever a time when show download overlay doesn't reload devices?
@@ -571,6 +588,7 @@ function handlers(app, opts, done){
571588 deleteFile,
572589 changeFile,
573590 dontSaveFile,
591+ overwriteFile,
574592 // project methods
575593 changeProject,
576594 deleteProject,
0 commit comments