7676 *
7777 * - fileNameChange -- When the name of a file or folder has changed. The 2nd arg is the old name.
7878 * The 3rd arg is the new name.
79+ * - pathDeleted -- When a file or folder has been deleted. The 2nd arg is the path that was deleted.
7980 *
8081 * These are jQuery events, so to listen for them you do something like this:
8182 * $(DocumentManager).on("eventname", handler);
@@ -478,8 +479,9 @@ define(function (require, exports, module) {
478479 * This is a subset of notifyFileDeleted(). Use this for the user-facing Close command.
479480 *
480481 * @param {!FileEntry } file
482+ * @param {boolean } skipAutoSelect - if true, don't automatically open and select the next document
481483 */
482- function closeFullEditor ( file ) {
484+ function closeFullEditor ( file , skipAutoSelect ) {
483485 // If this was the current document shown in the editor UI, we're going to switch to a
484486 // different document (or none if working set has no other options)
485487 if ( _currentDocument && _currentDocument . file . fullPath === file . fullPath ) {
@@ -491,7 +493,7 @@ define(function (require, exports, module) {
491493 }
492494
493495 // Switch editor to next document (or blank it out)
494- if ( nextFile ) {
496+ if ( nextFile && ! skipAutoSelect ) {
495497 CommandManager . execute ( Commands . FILE_OPEN , { fullPath : nextFile . fullPath } )
496498 . done ( function ( ) {
497499 // (Now we're guaranteed that the current document is not the one we're closing)
@@ -1063,10 +1065,11 @@ define(function (require, exports, module) {
10631065 * sort of "project file model," making this just a private event handler.
10641066 *
10651067 * @param {!FileEntry } file
1068+ * @param {boolean } skipAutoSelect - if true, don't automatically open/select the next document
10661069 */
1067- function notifyFileDeleted ( file ) {
1070+ function notifyFileDeleted ( file , skipAutoSelect ) {
10681071 // First ensure it's not currentDocument, and remove from working set
1069- closeFullEditor ( file ) ;
1072+ closeFullEditor ( file , skipAutoSelect ) ;
10701073
10711074 // Notify all other editors to close as well
10721075 var doc = getOpenDocumentForPath ( file . fullPath ) ;
@@ -1211,6 +1214,27 @@ define(function (require, exports, module) {
12111214 $ ( exports ) . triggerHandler ( "fileNameChange" , [ oldName , newName ] ) ;
12121215 }
12131216
1217+ /**
1218+ * Called after a file or folder has been deleted. This function is responsible
1219+ * for updating underlying model data and notifying all views of the change.
1220+ *
1221+ * @param {string } path The path of the file/folder that has been deleted
1222+ */
1223+ function notifyPathDeleted ( path ) {
1224+ var i , docPath ;
1225+
1226+ for ( docPath in _openDocuments ) {
1227+ if ( FileUtils . isAffectedWhenRenaming ( docPath , path ) ) {
1228+ // This will close the doc and remove from the working set
1229+ notifyFileDeleted ( new NativeFileSystem . FileEntry ( docPath ) , true ) ;
1230+ delete _openDocuments [ docPath ] ;
1231+ }
1232+ }
1233+
1234+ // Send a "pathDeleted" event. This will trigger the views to update.
1235+ $ ( exports ) . triggerHandler ( "pathDeleted" , path ) ;
1236+ }
1237+
12141238 /**
12151239 * @private
12161240 * Update document
@@ -1262,6 +1286,7 @@ define(function (require, exports, module) {
12621286 exports . closeAll = closeAll ;
12631287 exports . notifyFileDeleted = notifyFileDeleted ;
12641288 exports . notifyPathNameChanged = notifyPathNameChanged ;
1289+ exports . notifyPathDeleted = notifyPathDeleted ;
12651290
12661291 // Setup preferences
12671292 _prefs = PreferencesManager . getPreferenceStorage ( module ) ;
0 commit comments