@@ -1115,6 +1115,77 @@ define(function (require, exports, module) {
11151115 } ) ;
11161116 }
11171117
1118+ function _loadProjectInternal ( rootPath ) {
1119+ const result = new $ . Deferred ( ) ;
1120+ const rootEntry = FileSystem . getDirectoryForPath ( rootPath ) ;
1121+ rootEntry . exists ( function ( err , exists ) {
1122+ if ( exists ) {
1123+ var projectRootChanged = ( ! model . projectRoot || ! rootEntry ) ||
1124+ model . projectRoot . fullPath !== rootEntry . fullPath ;
1125+
1126+ // Success!
1127+ var perfTimerName = PerfUtils . markStart ( "Load Project: " + rootPath ) ;
1128+
1129+ _projectWarnedForTooManyFiles = false ;
1130+
1131+ _setProjectRoot ( rootEntry ) . always ( function ( ) {
1132+ model . setBaseUrl ( PreferencesManager . getViewState ( "project.baseUrl" , PreferencesManager . STATE_PROJECT_CONTEXT ) || "" ) ;
1133+
1134+ if ( projectRootChanged ) {
1135+ _reloadProjectPreferencesScope ( ) ;
1136+ PreferencesManager . _setCurrentFile ( rootPath ) ;
1137+ }
1138+ _watchProjectRoot ( rootPath ) ;
1139+
1140+ // If this is the most current welcome project, record it. In future launches, we want
1141+ // to substitute the latest welcome project from the current build instead of using an
1142+ // outdated one (when loading recent projects or the last opened project).
1143+ if ( rootPath === getWelcomeProjectPath ( ) ) {
1144+ addWelcomeProjectPath ( rootPath ) ;
1145+ }
1146+
1147+ if ( projectRootChanged ) {
1148+ // Allow asynchronous event handlers to finish before resolving result by collecting promises from them
1149+ exports . trigger ( EVENT_PROJECT_OPEN , model . projectRoot ) ;
1150+ result . resolve ( ) ;
1151+ exports . trigger ( EVENT_AFTER_PROJECT_OPEN , model . projectRoot ) ;
1152+ } else {
1153+ exports . trigger ( EVENT_PROJECT_REFRESH , model . projectRoot ) ;
1154+ result . resolve ( ) ;
1155+ }
1156+ let projectLoadTime = PerfUtils . addMeasurement ( perfTimerName ) ;
1157+ Metrics . valueEvent ( Metrics . EVENT_TYPE . PERFORMANCE , "projectLoad" ,
1158+ "timeMs" , Number ( projectLoadTime ) ) ;
1159+ } ) ;
1160+ } else {
1161+ console . error ( "error loading project" ) ;
1162+ exports . trigger ( EVENT_PROJECT_OPEN_FAILED , rootPath ) ;
1163+ _showErrorDialog ( ERR_TYPE_LOADING_PROJECT_NATIVE , true , err || FileSystemError . NOT_FOUND , rootPath )
1164+ . done ( function ( ) {
1165+ // Reset _projectRoot to null so that the following _loadProject call won't
1166+ // run the 'beforeProjectClose' event a second time on the original project,
1167+ // which is now partially torn down (see #6574).
1168+ model . projectRoot = null ;
1169+
1170+ // The project folder stored in preference doesn't exist, so load the default
1171+ // project directory.
1172+ // TODO (issue #267): When Brackets supports having no project directory
1173+ // defined this code will need to change
1174+ _getFallbackProjectPath ( ) . done ( function ( path ) {
1175+ _loadProject ( path ) . always ( function ( ) {
1176+ // Make sure not to reject the original deferred until the fallback
1177+ // project is loaded, so we don't violate expectations that there is always
1178+ // a current project before continuing after _loadProject().
1179+ result . reject ( ) ;
1180+ } ) ;
1181+ } ) ;
1182+ } ) ;
1183+ }
1184+ } ) ;
1185+
1186+ return result . promise ( ) ;
1187+ }
1188+
11181189 /**
11191190 * Loads the given folder as a project. Does NOT prompt about any unsaved changes - use openProject()
11201191 * instead to check for unsaved changes and (optionally) let the user choose the folder to open.
@@ -1126,8 +1197,6 @@ define(function (require, exports, module) {
11261197 * fails to load.
11271198 */
11281199 function _loadProject ( rootPath ) {
1129- var result = new $ . Deferred ( ) ,
1130- startLoad = new $ . Deferred ( ) ;
11311200
11321201 Metrics . valueEvent ( Metrics . EVENT_TYPE . PROJECT , "Load" ,
11331202 isWelcomeProjectPath ( rootPath ) ? "default" :"other" , 1 ) ;
@@ -1155,81 +1224,8 @@ define(function (require, exports, module) {
11551224 exports . trigger ( EVENT_PROJECT_CLOSE , model . projectRoot ) ;
11561225 }
11571226
1158- startLoad . resolve ( ) ;
1159-
1160- startLoad . done ( function ( ) {
1161- // Populate file tree as long as we aren't running in the browser
1162- if ( ! brackets . inBrowser ) {
1163- // Point at a real folder structure on local disk
1164- var rootEntry = FileSystem . getDirectoryForPath ( rootPath ) ;
1165- rootEntry . exists ( function ( err , exists ) {
1166- if ( exists ) {
1167- var projectRootChanged = ( ! model . projectRoot || ! rootEntry ) ||
1168- model . projectRoot . fullPath !== rootEntry . fullPath ;
1169-
1170- // Success!
1171- var perfTimerName = PerfUtils . markStart ( "Load Project: " + rootPath ) ;
1172-
1173- _projectWarnedForTooManyFiles = false ;
1174-
1175- _setProjectRoot ( rootEntry ) . always ( function ( ) {
1176- model . setBaseUrl ( PreferencesManager . getViewState ( "project.baseUrl" , PreferencesManager . STATE_PROJECT_CONTEXT ) || "" ) ;
1177-
1178- if ( projectRootChanged ) {
1179- _reloadProjectPreferencesScope ( ) ;
1180- PreferencesManager . _setCurrentFile ( rootPath ) ;
1181- }
1182- _watchProjectRoot ( rootPath ) ;
1183-
1184- // If this is the most current welcome project, record it. In future launches, we want
1185- // to substitute the latest welcome project from the current build instead of using an
1186- // outdated one (when loading recent projects or the last opened project).
1187- if ( rootPath === getWelcomeProjectPath ( ) ) {
1188- addWelcomeProjectPath ( rootPath ) ;
1189- }
1190-
1191- if ( projectRootChanged ) {
1192- // Allow asynchronous event handlers to finish before resolving result by collecting promises from them
1193- exports . trigger ( EVENT_PROJECT_OPEN , model . projectRoot ) ;
1194- result . resolve ( ) ;
1195- exports . trigger ( EVENT_AFTER_PROJECT_OPEN , model . projectRoot ) ;
1196- } else {
1197- exports . trigger ( EVENT_PROJECT_REFRESH , model . projectRoot ) ;
1198- result . resolve ( ) ;
1199- }
1200- let projectLoadTime = PerfUtils . addMeasurement ( perfTimerName ) ;
1201- Metrics . valueEvent ( Metrics . EVENT_TYPE . PERFORMANCE , "projectLoad" ,
1202- "timeMs" , Number ( projectLoadTime ) ) ;
1203- } ) ;
1204- } else {
1205- console . error ( "error loading project" ) ;
1206- exports . trigger ( EVENT_PROJECT_OPEN_FAILED , rootPath ) ;
1207- _showErrorDialog ( ERR_TYPE_LOADING_PROJECT_NATIVE , true , err || FileSystemError . NOT_FOUND , rootPath )
1208- . done ( function ( ) {
1209- // Reset _projectRoot to null so that the following _loadProject call won't
1210- // run the 'beforeProjectClose' event a second time on the original project,
1211- // which is now partially torn down (see #6574).
1212- model . projectRoot = null ;
1213-
1214- // The project folder stored in preference doesn't exist, so load the default
1215- // project directory.
1216- // TODO (issue #267): When Brackets supports having no project directory
1217- // defined this code will need to change
1218- _getFallbackProjectPath ( ) . done ( function ( path ) {
1219- _loadProject ( path ) . always ( function ( ) {
1220- // Make sure not to reject the original deferred until the fallback
1221- // project is loaded, so we don't violate expectations that there is always
1222- // a current project before continuing after _loadProject().
1223- result . reject ( ) ;
1224- } ) ;
1225- } ) ;
1226- } ) ;
1227- }
1228- } ) ;
1229- }
1230- } ) ;
1231-
1232- return result . promise ( ) ;
1227+ // Point at a real folder structure on local disk
1228+ return _loadProjectInternal ( rootPath ) ;
12331229 }
12341230
12351231 /**
0 commit comments