@@ -25,6 +25,7 @@ import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
2525import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart' ;
2626import { StatusbarPart } from 'vs/workbench/browser/parts/statusbar/statusbarPart' ;
2727import { getZoomFactor } from 'vs/base/browser/browser' ;
28+ import { RunOnceScheduler } from 'vs/base/common/async' ;
2829
2930const TITLE_BAR_HEIGHT = isMacintosh ? 22 : 30 ;
3031const STATUS_BAR_HEIGHT = 22 ;
@@ -67,6 +68,8 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
6768 private _panelHeight : number ;
6869 private _panelWidth : number ;
6970
71+ private saveStateScheduler : RunOnceScheduler ;
72+
7073 constructor (
7174 private parent : HTMLElement ,
7275 private workbenchContainer : HTMLElement ,
@@ -99,6 +102,9 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
99102 this . sashXTwo = new Sash ( this . workbenchContainer , this ) ;
100103 this . sashY = new Sash ( this . workbenchContainer , this , { orientation : Orientation . HORIZONTAL } ) ;
101104
105+ // State scheduler
106+ this . saveStateScheduler = new RunOnceScheduler ( ( ) => this . saveState ( ) , 1000 ) ;
107+
102108 this . registerListeners ( ) ;
103109 }
104110
@@ -115,6 +121,10 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
115121 private registerListeners ( ) : void {
116122 this . _register ( this . themeService . onThemeChange ( _ => this . layout ( ) ) ) ;
117123 this . _register ( this . parts . editor . onDidSizeConstraintsChange ( ( ) => this . onDidEditorSizeConstraintsChange ( ) ) ) ;
124+ this . _register ( this . storageService . onWillClose ( ( ) => {
125+ this . saveStateScheduler . dispose ( ) ;
126+ this . saveState ( ) ;
127+ } ) ) ;
118128
119129 this . registerSashListeners ( ) ;
120130 }
@@ -372,20 +382,21 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
372382 } ) ) ;
373383
374384 this . _register ( this . sashXOne . onDidEnd ( ( ) => {
375- this . storageService . store ( WorkbenchLayout . sashXOneWidthSettingsKey , this . sidebarWidth , StorageScope . GLOBAL ) ;
385+ this . saveStateScheduler . schedule ( ) ;
376386 } ) ) ;
377387
378388 this . _register ( this . sashY . onDidEnd ( ( ) => {
379- this . storageService . store ( WorkbenchLayout . sashYHeightSettingsKey , this . panelHeight , StorageScope . GLOBAL ) ;
389+ this . saveStateScheduler . schedule ( ) ;
380390 } ) ) ;
381391
382392 this . _register ( this . sashXTwo . onDidEnd ( ( ) => {
383- this . storageService . store ( WorkbenchLayout . sashXTwoWidthSettingsKey , this . panelWidth , StorageScope . GLOBAL ) ;
393+ this . saveStateScheduler . schedule ( ) ;
384394 } ) ) ;
385395
386396 this . _register ( this . sashY . onDidReset ( ( ) => {
387397 this . panelHeight = this . sidebarHeight * DEFAULT_PANEL_SIZE_COEFFICIENT ;
388- this . storageService . store ( WorkbenchLayout . sashYHeightSettingsKey , this . panelHeight , StorageScope . GLOBAL ) ;
398+
399+ this . saveStateScheduler . schedule ( ) ;
389400
390401 this . layout ( ) ;
391402 } ) ) ;
@@ -394,20 +405,22 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
394405 let activeViewlet = this . viewletService . getActiveViewlet ( ) ;
395406 let optimalWidth = activeViewlet && activeViewlet . getOptimalWidth ( ) ;
396407 this . sidebarWidth = Math . max ( optimalWidth , DEFAULT_SIDEBAR_PART_WIDTH ) ;
397- this . storageService . store ( WorkbenchLayout . sashXOneWidthSettingsKey , this . sidebarWidth , StorageScope . GLOBAL ) ;
408+
409+ this . saveStateScheduler . schedule ( ) ;
398410
399411 this . partService . setSideBarHidden ( false ) . then ( ( ) => this . layout ( ) ) ;
400412 } ) ) ;
401413
402414 this . _register ( this . sashXTwo . onDidReset ( ( ) => {
403415 this . panelWidth = ( this . workbenchSize . width - this . sidebarWidth - this . activitybarWidth ) * DEFAULT_PANEL_SIZE_COEFFICIENT ;
404- this . storageService . store ( WorkbenchLayout . sashXTwoWidthSettingsKey , this . panelWidth , StorageScope . GLOBAL ) ;
416+
417+ this . saveStateScheduler . schedule ( ) ;
405418
406419 this . layout ( ) ;
407420 } ) ) ;
408421 }
409422
410- layout ( options ?: ILayoutOptions ) : void {
423+ layout ( options ?: ILayoutOptions ) : void { //
411424 this . workbenchSize = getClientArea ( this . parent ) ;
412425
413426 const isActivityBarHidden = ! this . partService . isVisible ( Parts . ACTIVITYBAR_PART ) ;
@@ -476,8 +489,6 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
476489 }
477490 }
478491
479- this . storageService . store ( WorkbenchLayout . panelSizeBeforeMaximizedKey , this . panelSizeBeforeMaximized , StorageScope . GLOBAL ) ;
480-
481492 const panelDimension = new Dimension ( panelWidth , panelHeight ) ;
482493
483494 // Editor
@@ -532,16 +543,13 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
532543
533544 if ( ! isSidebarHidden ) {
534545 this . sidebarWidth = sidebarSize . width ;
535- this . storageService . store ( WorkbenchLayout . sashXOneWidthSettingsKey , this . sidebarWidth , StorageScope . GLOBAL ) ;
536546 }
537547
538548 if ( ! isPanelHidden ) {
539549 if ( panelPosition === Position . BOTTOM ) {
540550 this . panelHeight = panelDimension . height ;
541- this . storageService . store ( WorkbenchLayout . sashYHeightSettingsKey , this . panelHeight , StorageScope . GLOBAL ) ;
542551 } else {
543552 this . panelWidth = panelDimension . width ;
544- this . storageService . store ( WorkbenchLayout . sashXTwoWidthSettingsKey , this . panelWidth , StorageScope . GLOBAL ) ;
545553 }
546554 }
547555
@@ -647,6 +655,9 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
647655
648656 // Propagate to Context View
649657 this . contextViewService . layout ( ) ;
658+
659+ // Schedule save state
660+ this . saveStateScheduler . schedule ( ) ;
650661 }
651662
652663 getVerticalSashTop ( sash : Sash ) : number {
@@ -748,4 +759,13 @@ export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutPr
748759 this . layout ( ) ;
749760 }
750761 }
762+
763+ private saveState ( ) : void {
764+ this . storageService . store ( WorkbenchLayout . sashXOneWidthSettingsKey , this . sidebarWidth , StorageScope . GLOBAL ) ;
765+
766+ this . storageService . store ( WorkbenchLayout . sashYHeightSettingsKey , this . panelHeight , StorageScope . GLOBAL ) ;
767+ this . storageService . store ( WorkbenchLayout . sashXTwoWidthSettingsKey , this . panelWidth , StorageScope . GLOBAL ) ;
768+
769+ this . storageService . store ( WorkbenchLayout . panelSizeBeforeMaximizedKey , this . panelSizeBeforeMaximized , StorageScope . GLOBAL ) ;
770+ }
751771}
0 commit comments