@@ -269,136 +269,135 @@ export class Workbench implements IPartService {
269269 * once. Use the shutdown function to free up resources created by the workbench on startup.
270270 */
271271 public startup ( callbacks ?: IWorkbenchCallbacks ) : void {
272- try {
273- this . workbenchStarted = true ;
274- this . callbacks = callbacks ;
272+ this . workbenchStarted = true ;
273+ this . callbacks = callbacks ;
275274
276- // Create Workbench
277- this . createWorkbench ( ) ;
275+ // Create Workbench
276+ this . createWorkbench ( ) ;
278277
279- // Install some global actions
280- this . createGlobalActions ( ) ;
278+ // Install some global actions
279+ this . createGlobalActions ( ) ;
281280
282- // Services
283- this . initServices ( ) ;
284- if ( this . callbacks && this . callbacks . onServicesCreated ) {
285- this . callbacks . onServicesCreated ( ) ;
286- }
281+ // Services
282+ this . initServices ( ) ;
283+ if ( this . callbacks && this . callbacks . onServicesCreated ) {
284+ this . callbacks . onServicesCreated ( ) ;
285+ }
287286
288- // Contexts
289- this . messagesVisibleContext = MessagesVisibleContext . bindTo ( this . contextKeyService ) ;
290- this . editorsVisibleContext = EditorsVisibleContext . bindTo ( this . contextKeyService ) ;
291- this . inZenMode = InZenModeContext . bindTo ( this . contextKeyService ) ;
292- this . sideBarVisibleContext = SidebarVisibleContext . bindTo ( this . contextKeyService ) ;
287+ // Contexts
288+ this . messagesVisibleContext = MessagesVisibleContext . bindTo ( this . contextKeyService ) ;
289+ this . editorsVisibleContext = EditorsVisibleContext . bindTo ( this . contextKeyService ) ;
290+ this . inZenMode = InZenModeContext . bindTo ( this . contextKeyService ) ;
291+ this . sideBarVisibleContext = SidebarVisibleContext . bindTo ( this . contextKeyService ) ;
293292
294- // Register Listeners
295- this . registerListeners ( ) ;
293+ // Register Listeners
294+ this . registerListeners ( ) ;
296295
297- // Settings
298- this . initSettings ( ) ;
296+ // Settings
297+ this . initSettings ( ) ;
299298
300- // Create Workbench and Parts
301- this . renderWorkbench ( ) ;
299+ // Create Workbench and Parts
300+ this . renderWorkbench ( ) ;
302301
303- // Workbench Layout
304- this . createWorkbenchLayout ( ) ;
302+ // Workbench Layout
303+ this . createWorkbenchLayout ( ) ;
305304
306- // Load composites and editors in parallel
307- const compositeAndEditorPromises : TPromise < any > [ ] = [ ] ;
305+ // Restore Parts
306+ this . restoreParts ( ) . done ( startedInfo => {
307+ this . workbenchCreated = true ;
308+ this . creationPromiseComplete ( true ) ;
308309
309- // Restore last opened viewlet
310- let viewletRestoreStopWatch : StopWatch ;
311- let viewletIdToRestore : string ;
312- if ( ! this . sideBarHidden ) {
313- this . sideBarVisibleContext . set ( true ) ;
310+ if ( this . callbacks && this . callbacks . onWorkbenchStarted ) {
311+ this . callbacks . onWorkbenchStarted ( startedInfo ) ;
312+ }
313+ } ) ;
314+ }
314315
315- if ( this . shouldRestoreLastOpenedViewlet ( ) ) {
316- viewletIdToRestore = this . storageService . get ( SidebarPart . activeViewletSettingsKey , StorageScope . WORKSPACE ) ;
317- }
316+ private restoreParts ( ) : TPromise < IWorkbenchStartedInfo > {
317+ const restorePromises : TPromise < any > [ ] = [ ] ;
318318
319- if ( ! viewletIdToRestore ) {
320- viewletIdToRestore = this . viewletService . getDefaultViewletId ( ) ;
321- }
319+ // Restore Editors
320+ const editorRestoreStopWatch = StopWatch . create ( ) ;
321+ const editorRestoreClock = time ( 'restore:editors' ) ;
322+ const restoredEditors : string [ ] = [ ] ;
323+ restorePromises . push ( this . resolveEditorsToOpen ( ) . then ( inputs => {
324+ this . lifecycleService . phase = LifecyclePhase . Restoring ;
322325
323- viewletRestoreStopWatch = StopWatch . create ( ) ;
324- const viewletRestoreClock = time ( 'restore:viewlet' ) ;
325- compositeAndEditorPromises . push ( this . viewletService . openViewlet ( viewletIdToRestore ) . then ( ( ) => {
326- viewletRestoreStopWatch . stop ( ) ;
327- viewletRestoreClock . stop ( ) ;
328- } ) ) ;
326+ let editorOpenPromise : TPromise < IEditor [ ] > ;
327+ if ( inputs . length ) {
328+ editorOpenPromise = this . editorService . openEditors ( inputs . map ( input => { return { input, position : EditorPosition . ONE } ; } ) ) ;
329+ } else {
330+ editorOpenPromise = this . editorPart . restoreEditors ( ) ;
329331 }
330332
331- // Load Panel
332- const panelRegistry = Registry . as < PanelRegistry > ( PanelExtensions . Panels ) ;
333- const panelId = this . storageService . get ( PanelPart . activePanelSettingsKey , StorageScope . WORKSPACE , panelRegistry . getDefaultPanelId ( ) ) ;
334- if ( ! this . panelHidden && ! ! panelId ) {
335- compositeAndEditorPromises . push ( this . panelPart . openPanel ( panelId , false ) ) ;
336- }
333+ return editorOpenPromise . then ( editors => {
334+ this . handleEditorBackground ( ) ; // make sure we show the proper background in the editor area
337335
338- // Load Editors
339- const editorRestoreStopWatch = StopWatch . create ( ) ;
340- const editorRestoreClock = time ( 'restore:editors' ) ;
341- const restoredEditors : string [ ] = [ ] ;
342- compositeAndEditorPromises . push ( this . resolveEditorsToOpen ( ) . then ( inputs => {
343- this . lifecycleService . phase = LifecyclePhase . Restoring ;
344- let editorOpenPromise : TPromise < IEditor [ ] > ;
345- if ( inputs . length ) {
346- editorOpenPromise = this . editorService . openEditors ( inputs . map ( input => { return { input, position : EditorPosition . ONE } ; } ) ) ;
347- } else {
348- editorOpenPromise = this . editorPart . restoreEditors ( ) ;
349- }
336+ editorRestoreClock . stop ( ) ;
337+ editorRestoreStopWatch . stop ( ) ;
350338
351- return editorOpenPromise . then ( editors => {
352- this . handleEditorBackground ( ) ; // make sure we show the proper background in the editor area
353- editorRestoreClock . stop ( ) ;
354- editorRestoreStopWatch . stop ( ) ;
355- for ( const editor of editors ) {
356- if ( editor ) {
357- if ( editor . input ) {
358- restoredEditors . push ( editor . input . getName ( ) ) ;
359- } else {
360- restoredEditors . push ( `other:${ editor . getId ( ) } ` ) ;
361- }
339+ for ( const editor of editors ) {
340+ if ( editor ) {
341+ if ( editor . input ) {
342+ restoredEditors . push ( editor . input . getName ( ) ) ;
343+ } else {
344+ restoredEditors . push ( `other:${ editor . getId ( ) } ` ) ;
362345 }
363346 }
364- } ) ;
365- } ) ) ;
347+ }
348+ } ) ;
349+ } ) ) ;
366350
367- if ( this . storageService . getBoolean ( Workbench . zenModeActiveSettingKey , StorageScope . WORKSPACE , false ) ) {
368- this . toggleZenMode ( true ) ;
369- }
351+ // Restore Sidebar
352+ let viewletRestoreStopWatch : StopWatch ;
353+ let viewletIdToRestore : string ;
354+ if ( ! this . sideBarHidden ) {
355+ this . sideBarVisibleContext . set ( true ) ;
370356
371- // Flag workbench as created once done
372- const workbenchDone = ( error ?: Error ) => {
373- this . workbenchCreated = true ;
374- this . creationPromiseComplete ( true ) ;
375-
376- if ( this . callbacks && this . callbacks . onWorkbenchStarted ) {
377- this . callbacks . onWorkbenchStarted ( {
378- customKeybindingsCount : this . keybindingService . customKeybindingsCount ( ) ,
379- restoreViewletDuration : viewletRestoreStopWatch ? Math . round ( viewletRestoreStopWatch . elapsed ( ) ) : 0 ,
380- restoreEditorsDuration : Math . round ( editorRestoreStopWatch . elapsed ( ) ) ,
381- pinnedViewlets : this . activitybarPart . getPinned ( ) ,
382- restoredViewlet : viewletIdToRestore ,
383- restoredEditors
384- } ) ;
385- }
357+ if ( this . shouldRestoreLastOpenedViewlet ( ) ) {
358+ viewletIdToRestore = this . storageService . get ( SidebarPart . activeViewletSettingsKey , StorageScope . WORKSPACE ) ;
359+ }
386360
387- if ( error ) {
388- errors . onUnexpectedError ( error ) ;
389- }
390- } ;
361+ if ( ! viewletIdToRestore ) {
362+ viewletIdToRestore = this . viewletService . getDefaultViewletId ( ) ;
363+ }
391364
392- // Join viewlet, panel and editor promises
393- TPromise . join ( compositeAndEditorPromises ) . then ( ( ) => workbenchDone ( ) , error => workbenchDone ( error ) ) ;
394- } catch ( error ) {
365+ viewletRestoreStopWatch = StopWatch . create ( ) ;
366+ const viewletRestoreClock = time ( 'restore:viewlet' ) ;
367+ restorePromises . push ( this . viewletService . openViewlet ( viewletIdToRestore ) . then ( ( ) => {
368+ viewletRestoreStopWatch . stop ( ) ;
369+ viewletRestoreClock . stop ( ) ;
370+ } ) ) ;
371+ }
395372
396- // Print out error
397- console . error ( toErrorMessage ( error , true ) ) ;
373+ // Restore Panel
374+ const panelRegistry = Registry . as < PanelRegistry > ( PanelExtensions . Panels ) ;
375+ const panelId = this . storageService . get ( PanelPart . activePanelSettingsKey , StorageScope . WORKSPACE , panelRegistry . getDefaultPanelId ( ) ) ;
376+ if ( ! this . panelHidden && ! ! panelId ) {
377+ restorePromises . push ( this . panelPart . openPanel ( panelId , false ) ) ;
378+ }
398379
399- // Rethrow
400- throw error ;
380+ // Restore Zen Mode if active
381+ if ( this . storageService . getBoolean ( Workbench . zenModeActiveSettingKey , StorageScope . WORKSPACE , false ) ) {
382+ this . toggleZenMode ( true ) ;
401383 }
384+
385+ const onRestored = ( error ?: Error ) : IWorkbenchStartedInfo => {
386+ if ( error ) {
387+ errors . onUnexpectedError ( error ) ;
388+ }
389+
390+ return {
391+ customKeybindingsCount : this . keybindingService . customKeybindingsCount ( ) ,
392+ restoreViewletDuration : viewletRestoreStopWatch ? Math . round ( viewletRestoreStopWatch . elapsed ( ) ) : 0 ,
393+ restoreEditorsDuration : Math . round ( editorRestoreStopWatch . elapsed ( ) ) ,
394+ pinnedViewlets : this . activitybarPart . getPinned ( ) ,
395+ restoredViewlet : viewletIdToRestore ,
396+ restoredEditors
397+ } ;
398+ } ;
399+
400+ return TPromise . join ( restorePromises ) . then ( ( ) => onRestored ( ) , error => onRestored ( error ) ) ;
402401 }
403402
404403 private createGlobalActions ( ) : void {
0 commit comments