@@ -239,33 +239,66 @@ define(function (require, exports, module) {
239239 // Try to see if we have same doc split
240240 // Check existing list for this doc path and active pane entry
241241 var entryIndex = _ . findIndex ( _mrofList , function ( record ) {
242- return ( record && record . file === value . file && record . paneId === MainViewManager . getActivePaneId ( ) ) ;
242+ return (
243+ record &&
244+ record . file === value . file &&
245+ record . paneId === MainViewManager . getActivePaneId ( )
246+ ) ;
243247 } ) ;
244248
245249 // If found don't process this entry, as the document is already present in active pane
246250 if ( entryIndex >= 0 ) {
247251 return true ;
248252 }
249- // Process this for active pane id
253+ // Process this for active pane id
250254 value . paneId = MainViewManager . getActivePaneId ( ) ;
251255
252256 }
253257
254258 var indxInWS = MainViewManager . findInWorkingSet ( value . paneId , value . file ) ;
255259
256- data = { fullPath : value . file ,
260+ data = {
261+ fullPath : value . file ,
257262 name : FileUtils . getBaseName ( value . file ) ,
258- isFile : true } ;
263+ isFile : true
264+ } ;
259265
260266 fileEntry = FileSystem . getFileForPath ( value . file ) ;
261267
262268 // Create new list item with a link
263- $link = $ ( "<a href='#' class='mroitem'></a>" ) . html ( ViewUtils . getFileEntryDisplay ( { name : FileUtils . getBaseName ( value . file ) } ) ) ;
269+ $link = $ ( "<a href='#' class='mroitem'></a>" ) . html (
270+ ViewUtils . getFileEntryDisplay ( { name : FileUtils . getBaseName ( value . file ) } )
271+ ) ;
272+
273+ // Create remove button
274+ var $removeBtn = $ ( "<span class='remove-file'>×</span>" ) . on ( "click" , function ( e ) {
275+ e . preventDefault ( ) ;
276+ e . stopPropagation ( ) ;
277+
278+ // Find and remove the entry from _mrofList
279+ var filePath = $ ( this ) . parent ( ) . data ( "path" ) ;
280+ var paneId = $ ( this ) . parent ( ) . data ( "paneId" ) ;
281+
282+ _mrofList = _mrofList . filter ( function ( entry ) {
283+ return ! ( entry && entry . file === filePath && entry . paneId === paneId ) ;
284+ } ) ;
285+
286+ // Remove the list item from UI
287+ $ ( this ) . parent ( ) . remove ( ) ;
288+
289+ // Update preferences
290+ PreferencesManager . setViewState (
291+ OPEN_FILES_VIEW_STATE ,
292+ _mrofList ,
293+ PreferencesManager . STATE_PROJECT_CONTEXT
294+ ) ;
295+ } ) ;
264296
265297 // Use the file icon providers
266298 WorkingSetView . useIconProviders ( data , $link ) ;
267299
268- $newItem = $ ( "<li></li>" ) . append ( $link ) ;
300+ // Create list item with link and remove button
301+ $newItem = $ ( "<li></li>" ) . append ( $link ) . append ( $removeBtn ) ;
269302
270303 if ( indxInWS !== - 1 ) { // in working set show differently
271304 $newItem . addClass ( "working-set" ) ;
@@ -285,7 +318,7 @@ define(function (require, exports, module) {
285318 // Use the class providers(git e.t.c)
286319 WorkingSetView . useClassProviders ( data , $newItem ) ;
287320
288- // If a file is dirty , mark it in the list
321+ // If a file is dirty, mark it in the list
289322 if ( _isOpenAndDirty ( fileEntry ) ) {
290323 $ ( dirtyDotTemplate ) . prependTo ( $newItem ) ;
291324 }
0 commit comments