@@ -1320,6 +1320,38 @@ define(function (require, exports, module) {
13201320 return saveAll ( ) ;
13211321 }
13221322
1323+ let closedFilesHistory = new Map ( ) ;
1324+
1325+ function _enableOrDisableReopenClosedCmd ( ) {
1326+ CommandManager . get ( Commands . FILE_REOPEN_CLOSED ) . setEnabled ( ! ! closedFilesHistory . size ) ;
1327+ }
1328+
1329+ function _addToClosedFilesHistory ( filePath , paneID ) {
1330+ closedFilesHistory . set ( filePath , { paneID, closeTime : Date . now ( ) } ) ;
1331+ _enableOrDisableReopenClosedCmd ( ) ;
1332+ }
1333+
1334+ function handleReopenClosed ( ) {
1335+ // find the file that was most recently closed
1336+ let leastRecentlyClosedPath , leastRecentlyClosedTime , paneToUse ;
1337+ for ( let closedFilePath of closedFilesHistory . keys ( ) ) {
1338+ const currentScan = closedFilesHistory . get ( closedFilePath ) ;
1339+ if ( ! leastRecentlyClosedPath || leastRecentlyClosedTime < currentScan . closeTime ) {
1340+ leastRecentlyClosedPath = closedFilePath ;
1341+ leastRecentlyClosedTime = currentScan . closeTime ;
1342+ paneToUse = currentScan . paneID ;
1343+ }
1344+ }
1345+ if ( leastRecentlyClosedPath ) {
1346+ closedFilesHistory . delete ( leastRecentlyClosedPath ) ;
1347+ if ( MainViewManager . getPaneCount ( ) === 1 ) {
1348+ paneToUse = MainViewManager . ACTIVE_PANE ;
1349+ }
1350+ FileViewController . openFileAndAddToWorkingSet ( leastRecentlyClosedPath , paneToUse ) ;
1351+ }
1352+ _enableOrDisableReopenClosedCmd ( ) ;
1353+ }
1354+
13231355 /**
13241356 * Closes the specified file: removes it from the workingset, and closes the main editor if one
13251357 * is open. Prompts user about saving changes first, if document is dirty.
@@ -1339,7 +1371,8 @@ define(function (require, exports, module) {
13391371 promptOnly ,
13401372 _forceClose ,
13411373 _spawnedRequest ,
1342- paneId = MainViewManager . ACTIVE_PANE ;
1374+ paneId = MainViewManager . ACTIVE_PANE ,
1375+ activePaneID = MainViewManager . getActivePaneId ( ) ;
13431376
13441377 if ( commandData ) {
13451378 file = commandData . file ;
@@ -1353,6 +1386,11 @@ define(function (require, exports, module) {
13531386 function doClose ( file ) {
13541387 if ( ! promptOnly ) {
13551388 MainViewManager . _close ( paneId , file ) ;
1389+ let paneClosing = paneId ;
1390+ if ( paneId === MainViewManager . ACTIVE_PANE ) {
1391+ paneClosing = activePaneID ;
1392+ }
1393+ _addToClosedFilesHistory ( file . fullPath , paneClosing ) ;
13561394 _fileClosed ( file ) ;
13571395 }
13581396 }
@@ -2192,6 +2230,8 @@ define(function (require, exports, module) {
21922230
21932231 let firstProjectOpenHandled = false ;
21942232 ProjectManager . on ( ProjectManager . EVENT_AFTER_PROJECT_OPEN , ( ) => {
2233+ closedFilesHistory = new Map ( ) ;
2234+ _enableOrDisableReopenClosedCmd ( ) ;
21952235 if ( firstProjectOpenHandled ) {
21962236 return ;
21972237 }
@@ -2252,6 +2292,7 @@ define(function (require, exports, module) {
22522292 CommandManager . register ( Strings . CMD_FILE_CLOSE , Commands . FILE_CLOSE , handleFileClose ) ;
22532293 CommandManager . register ( Strings . CMD_FILE_CLOSE_ALL , Commands . FILE_CLOSE_ALL , handleFileCloseAll ) ;
22542294 CommandManager . register ( Strings . CMD_FILE_CLOSE_LIST , Commands . FILE_CLOSE_LIST , handleFileCloseList ) ;
2295+ CommandManager . register ( Strings . CMD_REOPEN_CLOSED , Commands . FILE_REOPEN_CLOSED , handleReopenClosed ) ;
22552296
22562297 // Traversal
22572298 CommandManager . register ( Strings . CMD_NEXT_DOC , Commands . NAVIGATE_NEXT_DOC , handleGoNextDoc ) ;
0 commit comments