<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
import { Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation } from 'vs/base/browser/ui/sash/sash';
import { IPartService, Position, ILayoutOptions, Parts } from 'vs/workbench/services/part/common/partService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { Disposable } from 'vs/base/common/lifecycle';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { isMacintosh } from 'vs/base/common/platform';
import { memoize } from 'vs/base/common/decorators';
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
import { Dimension, getClientArea, size, position, hide, show } from 'vs/base/browser/dom';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
import { TitlebarPart } from 'vs/workbench/browser/parts/titlebar/titlebarPart';
import { ActivitybarPart } from 'vs/workbench/browser/parts/activitybar/activitybarPart';
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart';
import { StatusbarPart } from 'vs/workbench/browser/parts/statusbar/statusbarPart';
import { getZoomFactor } from 'vs/base/browser/browser';
import { RunOnceScheduler } from 'vs/base/common/async';

const TITLE_BAR_HEIGHT = isMacintosh ? 22 : 30;
const STATUS_BAR_HEIGHT = 22;
const ACTIVITY_BAR_WIDTH = 50;

const MIN_SIDEBAR_PART_WIDTH = 170;
const DEFAULT_SIDEBAR_PART_WIDTH = 300;
const HIDE_SIDEBAR_WIDTH_THRESHOLD = 50;

const MIN_PANEL_PART_HEIGHT = 77;
const MIN_PANEL_PART_WIDTH = 300;
const DEFAULT_PANEL_PART_SIZE = 350;
const DEFAULT_PANEL_SIZE_COEFFICIENT = 0.4;
const PANEL_SIZE_BEFORE_MAXIMIZED_BOUNDARY = 0.7;
const HIDE_PANEL_HEIGHT_THRESHOLD = 50;
const HIDE_PANEL_WIDTH_THRESHOLD = 100;

/**
 * The workbench layout is responsible to lay out all parts that make the Workbench.
 */
export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider {

	private static readonly sashXOneWidthSettingsKey = 'workbench.sidebar.width';
	private static readonly sashXTwoWidthSettingsKey = 'workbench.panel.width';
	private static readonly sashYHeightSettingsKey = 'workbench.panel.height';
	private static readonly panelSizeBeforeMaximizedKey = 'workbench.panel.sizeBeforeMaximized';

	private workbenchSize: Dimension;

	private sashXOne: Sash;
	private sashXTwo: Sash;
	private sashY: Sash;

	private _sidebarWidth: number;
	private sidebarHeight: number;
	private titlebarHeight: number;
	private statusbarHeight: number;
	private panelSizeBeforeMaximized: number;
	private panelMaximized: boolean;
	private _panelHeight: number;
	private _panelWidth: number;

	private saveStateScheduler: RunOnceScheduler;

	constructor(
		private parent: HTMLElement,
		private workbenchContainer: HTMLElement,
		private parts: {
			titlebar: TitlebarPart,
			activitybar: ActivitybarPart,
			editor: EditorPart,
			sidebar: SidebarPart,
			panel: PanelPart,
			statusbar: StatusbarPart
		},
		private quickopen: QuickOpenController,
		private quickInput: QuickInputService,
		private notificationsCenter: NotificationsCenter,
		private notificationsToasts: NotificationsToasts,
		@IStorageService private storageService: IStorageService,
		@IContextViewService private contextViewService: IContextViewService,
		@IPartService private partService: IPartService,
		@IViewletService private viewletService: IViewletService,
		@IThemeService private themeService: IThemeService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
	) {
		super();

		// Restore state
		this.restorePreviousState();

		// Create layout sashes
		this.sashXOne = new Sash(this.workbenchContainer, this);
		this.sashXTwo = new Sash(this.workbenchContainer, this);
		this.sashY = new Sash(this.workbenchContainer, this, { orientation: Orientation.HORIZONTAL });

		// State scheduler
		this.saveStateScheduler = new RunOnceScheduler(() => this.saveState(), 1000);

		this.registerListeners();
	}

	private restorePreviousState(): void {
		this._sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, this.storageService.getInteger(WorkbenchLayout.sashXOneWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_SIDEBAR_PART_WIDTH));

		this._panelWidth = Math.max(this.partLayoutInfo.panel.minWidth, this.storageService.getInteger(WorkbenchLayout.sashXTwoWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));
		this._panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, this.storageService.getInteger(WorkbenchLayout.sashYHeightSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));

		this.panelMaximized = false;
		this.panelSizeBeforeMaximized = this.storageService.getInteger(WorkbenchLayout.panelSizeBeforeMaximizedKey, StorageScope.GLOBAL, 0);
	}

	private registerListeners(): void {
		this._register(this.themeService.onThemeChange(_ => this.layout()));
		this._register(this.parts.editor.onDidSizeConstraintsChange(() => this.onDidEditorSizeConstraintsChange()));
		this._register(this.storageService.onWillSaveState(() => {
			this.saveStateScheduler.dispose();
			this.saveState();
		}));

		this.registerSashListeners();
	}<commit_msg>storage - fix missing disposable<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickInput';
import { Sash, ISashEvent, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider, Orientation } from 'vs/base/browser/ui/sash/sash';
import { IPartService, Position, ILayoutOptions, Parts } from 'vs/workbench/services/part/common/partService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { Disposable } from 'vs/base/common/lifecycle';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { isMacintosh } from 'vs/base/common/platform';
import { memoize } from 'vs/base/common/decorators';
import { NotificationsCenter } from 'vs/workbench/browser/parts/notifications/notificationsCenter';
import { NotificationsToasts } from 'vs/workbench/browser/parts/notifications/notificationsToasts';
import { Dimension, getClientArea, size, position, hide, show } from 'vs/base/browser/dom';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
import { EditorPart } from 'vs/workbench/browser/parts/editor/editorPart';
import { TitlebarPart } from 'vs/workbench/browser/parts/titlebar/titlebarPart';
import { ActivitybarPart } from 'vs/workbench/browser/parts/activitybar/activitybarPart';
import { SidebarPart } from 'vs/workbench/browser/parts/sidebar/sidebarPart';
import { PanelPart } from 'vs/workbench/browser/parts/panel/panelPart';
import { StatusbarPart } from 'vs/workbench/browser/parts/statusbar/statusbarPart';
import { getZoomFactor } from 'vs/base/browser/browser';
import { RunOnceScheduler } from 'vs/base/common/async';

const TITLE_BAR_HEIGHT = isMacintosh ? 22 : 30;
const STATUS_BAR_HEIGHT = 22;
const ACTIVITY_BAR_WIDTH = 50;

const MIN_SIDEBAR_PART_WIDTH = 170;
const DEFAULT_SIDEBAR_PART_WIDTH = 300;
const HIDE_SIDEBAR_WIDTH_THRESHOLD = 50;

const MIN_PANEL_PART_HEIGHT = 77;
const MIN_PANEL_PART_WIDTH = 300;
const DEFAULT_PANEL_PART_SIZE = 350;
const DEFAULT_PANEL_SIZE_COEFFICIENT = 0.4;
const PANEL_SIZE_BEFORE_MAXIMIZED_BOUNDARY = 0.7;
const HIDE_PANEL_HEIGHT_THRESHOLD = 50;
const HIDE_PANEL_WIDTH_THRESHOLD = 100;

/**
 * The workbench layout is responsible to lay out all parts that make the Workbench.
 */
export class WorkbenchLayout extends Disposable implements IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider {

	private static readonly sashXOneWidthSettingsKey = 'workbench.sidebar.width';
	private static readonly sashXTwoWidthSettingsKey = 'workbench.panel.width';
	private static readonly sashYHeightSettingsKey = 'workbench.panel.height';
	private static readonly panelSizeBeforeMaximizedKey = 'workbench.panel.sizeBeforeMaximized';

	private workbenchSize: Dimension;

	private sashXOne: Sash;
	private sashXTwo: Sash;
	private sashY: Sash;

	private _sidebarWidth: number;
	private sidebarHeight: number;
	private titlebarHeight: number;
	private statusbarHeight: number;
	private panelSizeBeforeMaximized: number;
	private panelMaximized: boolean;
	private _panelHeight: number;
	private _panelWidth: number;

	private saveStateScheduler: RunOnceScheduler;

	constructor(
		private parent: HTMLElement,
		private workbenchContainer: HTMLElement,
		private parts: {
			titlebar: TitlebarPart,
			activitybar: ActivitybarPart,
			editor: EditorPart,
			sidebar: SidebarPart,
			panel: PanelPart,
			statusbar: StatusbarPart
		},
		private quickopen: QuickOpenController,
		private quickInput: QuickInputService,
		private notificationsCenter: NotificationsCenter,
		private notificationsToasts: NotificationsToasts,
		@IStorageService private storageService: IStorageService,
		@IContextViewService private contextViewService: IContextViewService,
		@IPartService private partService: IPartService,
		@IViewletService private viewletService: IViewletService,
		@IThemeService private themeService: IThemeService,
		@IEditorGroupsService private editorGroupService: IEditorGroupsService
	) {
		super();

		// Restore state
		this.restorePreviousState();

		// Create layout sashes
		this.sashXOne = new Sash(this.workbenchContainer, this);
		this.sashXTwo = new Sash(this.workbenchContainer, this);
		this.sashY = new Sash(this.workbenchContainer, this, { orientation: Orientation.HORIZONTAL });

		// State scheduler
		this.saveStateScheduler = this._register(new RunOnceScheduler(() => this.saveState(), 800));

		this.registerListeners();
	}

	private restorePreviousState(): void {
		this._sidebarWidth = Math.max(this.partLayoutInfo.sidebar.minWidth, this.storageService.getInteger(WorkbenchLayout.sashXOneWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_SIDEBAR_PART_WIDTH));

		this._panelWidth = Math.max(this.partLayoutInfo.panel.minWidth, this.storageService.getInteger(WorkbenchLayout.sashXTwoWidthSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));
		this._panelHeight = Math.max(this.partLayoutInfo.panel.minHeight, this.storageService.getInteger(WorkbenchLayout.sashYHeightSettingsKey, StorageScope.GLOBAL, DEFAULT_PANEL_PART_SIZE));

		this.panelMaximized = false;
		this.panelSizeBeforeMaximized = this.storageService.getInteger(WorkbenchLayout.panelSizeBeforeMaximizedKey, StorageScope.GLOBAL, 0);
	}

	private registerListeners(): void {
		this._register(this.themeService.onThemeChange(_ => this.layout()));
		this._register(this.parts.editor.onDidSizeConstraintsChange(() => this.onDidEditorSizeConstraintsChange()));
		this._register(this.storageService.onWillSaveState(() => {
			this.saveStateScheduler.dispose();
			this.saveState();
		}));

		this.registerSashListeners();
	}
{'fraction_non_alphanumeric': 0.12243910308114211, 'fraction_numerical': 0.006049362800451686, 'mean_word_length': 5.277974683544304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3812115', 'n_tokens_mistral': 3793, 'n_tokens_neox': 3573, 'n_words': 743}