titlebarPart.ts 20.0 KB
Newer Older
B
Benjamin Pasero 已提交
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import 'vs/css!./media/titlebarpart';
B
Benjamin Pasero 已提交
9
import { TPromise } from 'vs/base/common/winjs.base';
10
import { Builder, $ } from 'vs/base/browser/builder';
B
Benjamin Pasero 已提交
11
import * as paths from 'vs/base/common/paths';
B
Benjamin Pasero 已提交
12
import { Part } from 'vs/workbench/browser/part';
13
import { ITitleService, ITitleProperties } from 'vs/workbench/services/title/common/titleService';
B
Benjamin Pasero 已提交
14
import { getZoomFactor } from 'vs/base/browser/browser';
15
import { IWindowService, IWindowsService, MenuBarVisibility } from 'vs/platform/windows/common/windows';
B
Benjamin Pasero 已提交
16 17 18 19
import * as errors from 'vs/base/common/errors';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { IAction, Action } from 'vs/base/common/actions';
20
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
B
Benjamin Pasero 已提交
21
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
22
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
23
import * as nls from 'vs/nls';
B
Benjamin Pasero 已提交
24
import { EditorInput, toResource, Verbosity } from 'vs/workbench/common/editor';
25
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
26
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
S
SteVen Batten 已提交
27
import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
28
import { TITLE_BAR_ACTIVE_BACKGROUND, TITLE_BAR_ACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_BACKGROUND, TITLE_BAR_BORDER } from 'vs/workbench/common/theme';
B
Benjamin Pasero 已提交
29
import { isMacintosh, isWindows, isLinux } from 'vs/base/common/platform';
B
Benjamin Pasero 已提交
30
import URI from 'vs/base/common/uri';
R
Ryan Adolf 已提交
31
import { Color } from 'vs/base/common/color';
B
Benjamin Pasero 已提交
32
import { trim } from 'vs/base/common/strings';
S
SteVen Batten 已提交
33
import { addDisposableListener, EventType, EventHelper, Dimension } from 'vs/base/browser/dom';
S
SteVen Batten 已提交
34 35
import { MenubarPart } from 'vs/workbench/browser/parts/menubar/menubarPart';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
I
isidor 已提交
36 37
import { template, getBaseLabel } from 'vs/base/common/labels';
import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
B
Benjamin Pasero 已提交
38 39 40

export class TitlebarPart extends Part implements ITitleService {

B
Benjamin Pasero 已提交
41
	_serviceBrand: any;
B
Benjamin Pasero 已提交
42

43
	private static readonly NLS_UNSUPPORTED = nls.localize('patchedWindowTitle', "[Unsupported]");
44
	private static readonly NLS_USER_IS_ADMIN = isWindows ? nls.localize('userIsAdmin', "[Administrator]") : nls.localize('userIsSudo', "[Superuser]");
45 46 47
	private static readonly NLS_EXTENSION_HOST = nls.localize('devExtensionWindowTitlePrefix', "[Extension Development Host]");
	private static readonly TITLE_DIRTY = '\u25cf ';
	private static readonly TITLE_SEPARATOR = isMacintosh ? '' : ' - '; // macOS uses special - separator
48

B
Benjamin Pasero 已提交
49 50
	private titleContainer: Builder;
	private title: Builder;
51
	private dragRegion: Builder;
52
	private windowControls: Builder;
S
SteVen Batten 已提交
53
	private maxRestoreControl: Builder;
54
	private appIcon: Builder;
S
SteVen Batten 已提交
55 56
	private menubarPart: MenubarPart;
	private menubar: Builder;
B
Benjamin Pasero 已提交
57

B
Benjamin Pasero 已提交
58
	private pendingTitle: string;
B
Benjamin Pasero 已提交
59
	private representedFileName: string;
60 61 62 63 64

	private initialSizing: {
		titleFontSize?: number;
		titlebarHeight?: number;
		controlsWidth?: number;
65
		appIconSize?: number;
66
		appIconWidth?: number;
B
Benjamin Pasero 已提交
67
	} = Object.create(null);
B
Benjamin Pasero 已提交
68

B
Benjamin Pasero 已提交
69 70
	private isInactive: boolean;

71
	private properties: ITitleProperties;
72 73
	private activeEditorListeners: IDisposable[];

74 75
	constructor(
		id: string,
B
Benjamin Pasero 已提交
76 77
		@IContextMenuService private contextMenuService: IContextMenuService,
		@IWindowService private windowService: IWindowService,
78 79
		@IConfigurationService private configurationService: IConfigurationService,
		@IWindowsService private windowsService: IWindowsService,
B
Benjamin Pasero 已提交
80
		@IEditorService private editorService: IEditorService,
81
		@IEnvironmentService private environmentService: IEnvironmentService,
B
Benjamin Pasero 已提交
82
		@IWorkspaceContextService private contextService: IWorkspaceContextService,
S
SteVen Batten 已提交
83
		@IInstantiationService private instantiationService: IInstantiationService,
I
isidor 已提交
84 85
		@IThemeService themeService: IThemeService,
		@IUriDisplayService private uriDisplayService: IUriDisplayService
86
	) {
B
Benjamin Pasero 已提交
87
		super(id, { hasTitle: false }, themeService);
88

89
		this.properties = { isPure: true, isAdmin: false };
90 91
		this.activeEditorListeners = [];

92 93 94 95
		this.registerListeners();
	}

	private registerListeners(): void {
B
Benjamin Pasero 已提交
96 97 98 99 100 101 102
		this._register(addDisposableListener(window, EventType.BLUR, () => this.onBlur()));
		this._register(addDisposableListener(window, EventType.FOCUS, () => this.onFocus()));
		this._register(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationChanged(e)));
		this._register(this.editorService.onDidActiveEditorChange(() => this.onActiveEditorChange()));
		this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.setTitle(this.getWindowTitle())));
		this._register(this.contextService.onDidChangeWorkbenchState(() => this.setTitle(this.getWindowTitle())));
		this._register(this.contextService.onDidChangeWorkspaceName(() => this.setTitle(this.getWindowTitle())));
103 104
	}

B
Benjamin Pasero 已提交
105 106 107 108 109 110 111 112 113 114
	private onBlur(): void {
		this.isInactive = true;
		this.updateStyles();
	}

	private onFocus(): void {
		this.isInactive = false;
		this.updateStyles();
	}

115 116
	private onConfigurationChanged(event: IConfigurationChangeEvent): void {
		if (event.affectsConfiguration('window.title')) {
117 118 119 120
			this.setTitle(this.getWindowTitle());
		}
	}

S
SteVen Batten 已提交
121 122 123 124 125
	private onMenubarVisibilityChanged(visible: boolean) {
		if (isWindows || isLinux) {
			// Hide title when toggling menu bar
			if (this.configurationService.getValue<MenuBarVisibility>('window.menuBarVisibility') === 'toggle' && visible) {
				this.title.style('visibility', 'hidden');
126

S
SteVen Batten 已提交
127 128 129 130 131 132 133
				// Hack to fix issue #52522 with layered webkit-app-region elements appearing under cursor
				this.dragRegion.hide();
				this.dragRegion.showDelayed(50);
			} else {
				this.title.style('visibility', null);
			}
		}
134 135
	}

B
Benjamin Pasero 已提交
136
	private onActiveEditorChange(): void {
137 138 139 140 141 142 143 144 145

		// Dispose old listeners
		dispose(this.activeEditorListeners);
		this.activeEditorListeners = [];

		// Calculate New Window Title
		this.setTitle(this.getWindowTitle());

		// Apply listener for dirty and label changes
B
Benjamin Pasero 已提交
146 147 148
		const activeEditor = this.editorService.activeEditor;
		if (activeEditor instanceof EditorInput) {
			this.activeEditorListeners.push(activeEditor.onDidChangeDirty(() => {
149 150 151
				this.setTitle(this.getWindowTitle());
			}));

B
Benjamin Pasero 已提交
152
			this.activeEditorListeners.push(activeEditor.onDidChangeLabel(() => {
153 154 155
				this.setTitle(this.getWindowTitle());
			}));
		}
B
Benjamin Pasero 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169

		// Represented File Name
		this.updateRepresentedFilename();
	}

	private updateRepresentedFilename(): void {
		const file = toResource(this.editorService.activeEditor, { supportSideBySide: true, filter: 'file' });
		const path = file ? file.fsPath : '';

		// Apply to window
		this.windowService.setRepresentedFilename(path);

		// Keep for context menu
		this.representedFileName = path;
170 171 172 173
	}

	private getWindowTitle(): string {
		let title = this.doGetWindowTitle();
B
Benjamin Pasero 已提交
174
		if (!trim(title)) {
175 176 177
			title = this.environmentService.appNameLong;
		}

178 179 180 181 182
		if (this.properties.isAdmin) {
			title = `${title} ${TitlebarPart.NLS_USER_IS_ADMIN}`;
		}

		if (!this.properties.isPure) {
183 184 185 186 187 188 189 190 191 192 193
			title = `${title} ${TitlebarPart.NLS_UNSUPPORTED}`;
		}

		// Extension Development Host gets a special title to identify itself
		if (this.environmentService.isExtensionDevelopment) {
			title = `${TitlebarPart.NLS_EXTENSION_HOST} - ${title}`;
		}

		return title;
	}

B
Benjamin Pasero 已提交
194
	updateProperties(properties: ITitleProperties): void {
195 196 197 198 199 200 201 202 203 204 205
		const isAdmin = typeof properties.isAdmin === 'boolean' ? properties.isAdmin : this.properties.isAdmin;
		const isPure = typeof properties.isPure === 'boolean' ? properties.isPure : this.properties.isPure;

		if (isAdmin !== this.properties.isAdmin || isPure !== this.properties.isPure) {
			this.properties.isAdmin = isAdmin;
			this.properties.isPure = isPure;

			this.setTitle(this.getWindowTitle());
		}
	}

206 207 208
	/**
	 * Possible template values:
	 *
B
Benjamin Pasero 已提交
209 210 211
	 * {activeEditorLong}: e.g. /Users/Development/myProject/myFolder/myFile.txt
	 * {activeEditorMedium}: e.g. myFolder/myFile.txt
	 * {activeEditorShort}: e.g. myFile.txt
212
	 * {rootName}: e.g. myFolder1, myFolder2, myFolder3
213
	 * {rootPath}: e.g. /Users/Development/myProject
214 215
	 * {folderName}: e.g. myFolder
	 * {folderPath}: e.g. /Users/Development/myFolder
216 217 218 219 220
	 * {appName}: e.g. VS Code
	 * {dirty}: indiactor
	 * {separator}: conditional separator
	 */
	private doGetWindowTitle(): string {
B
Benjamin Pasero 已提交
221
		const editor = this.editorService.activeEditor;
B
Benjamin Pasero 已提交
222
		const workspace = this.contextService.getWorkspace();
223

224
		let root: URI;
225
		if (workspace.configuration) {
226
			root = workspace.configuration;
227 228
		} else if (workspace.folders.length) {
			root = workspace.folders[0].uri;
229 230 231 232
		}

		// Compute folder resource
		// Single Root Workspace: always the root single workspace in this case
233
		// Otherwise: root folder of the currently active file if any
B
Benjamin Pasero 已提交
234
		let folder = this.contextService.getWorkbenchState() === WorkbenchState.FOLDER ? workspace.folders[0] : this.contextService.getWorkspaceFolder(toResource(editor, { supportSideBySide: true }));
235

236
		// Variables
B
Benjamin Pasero 已提交
237 238 239
		const activeEditorShort = editor ? editor.getTitle(Verbosity.SHORT) : '';
		const activeEditorMedium = editor ? editor.getTitle(Verbosity.MEDIUM) : activeEditorShort;
		const activeEditorLong = editor ? editor.getTitle(Verbosity.LONG) : activeEditorMedium;
240
		const rootName = workspace.name;
I
isidor 已提交
241
		const rootPath = root ? this.uriDisplayService.getLabel(root) : '';
B
Benjamin Pasero 已提交
242
		const folderName = folder ? folder.name : '';
I
isidor 已提交
243
		const folderPath = folder ? this.uriDisplayService.getLabel(folder.uri) : '';
B
Benjamin Pasero 已提交
244
		const dirty = editor && editor.isDirty() ? TitlebarPart.TITLE_DIRTY : '';
245 246
		const appName = this.environmentService.appNameLong;
		const separator = TitlebarPart.TITLE_SEPARATOR;
247
		const titleTemplate = this.configurationService.getValue<string>('window.title');
248

I
isidor 已提交
249
		return template(titleTemplate, {
B
Benjamin Pasero 已提交
250 251 252
			activeEditorShort,
			activeEditorLong,
			activeEditorMedium,
253 254
			rootName,
			rootPath,
255 256
			folderName,
			folderPath,
257 258 259 260 261 262
			dirty,
			appName,
			separator: { label: separator }
		});
	}

B
Benjamin Pasero 已提交
263
	createContentArea(parent: HTMLElement): HTMLElement {
B
Benjamin Pasero 已提交
264 265
		this.titleContainer = $(parent);

266 267 268
		// Draggable region that we can manipulate for #52522
		this.dragRegion = $(this.titleContainer).div({ class: 'titlebar-drag-region' });

B
Benjamin Pasero 已提交
269
		// App Icon (Windows/Linux)
R
Ryan Adolf 已提交
270
		if (!isMacintosh) {
S
SteVen Batten 已提交
271
			this.appIcon = $(this.titleContainer).div({ class: 'window-appicon' });
272
		}
S
SteVen Batten 已提交
273

S
SteVen Batten 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286 287
		// Menubar: the menubar part which is responsible for populating both the custom and native menubars
		this.menubarPart = this.instantiationService.createInstance(MenubarPart, 'workbench.parts.menubar');
		this.menubar = $(this.titleContainer).div({
			'class': ['part', 'menubar'],
			id: 'workbench.parts.menubar',
			role: 'menubar'
		});

		this.menubarPart.create(this.menubar.getHTMLElement());

		if (!isMacintosh) {
			this._register(this.menubarPart.onVisibilityChange(e => this.onMenubarVisibilityChanged(e)));
		}

B
Benjamin Pasero 已提交
288 289 290 291
		// Title
		this.title = $(this.titleContainer).div({ class: 'window-title' });
		if (this.pendingTitle) {
			this.title.text(this.pendingTitle);
B
Benjamin Pasero 已提交
292 293
		} else {
			this.setTitle(this.getWindowTitle());
B
Benjamin Pasero 已提交
294 295
		}

296
		// Maximize/Restore on doubleclick
S
SteVen Batten 已提交
297
		this.title.on(EventType.DBLCLICK, (e) => {
298
			EventHelper.stop(e);
299 300 301 302

			this.onTitleDoubleclick();
		});

B
Benjamin Pasero 已提交
303
		// Context menu on title
304 305 306
		this.title.on([EventType.CONTEXT_MENU, EventType.MOUSE_DOWN], (e: MouseEvent) => {
			if (e.type === EventType.CONTEXT_MENU || e.metaKey) {
				EventHelper.stop(e);
B
Benjamin Pasero 已提交
307 308 309 310 311

				this.onContextMenu(e);
			}
		});

B
Benjamin Pasero 已提交
312
		// Window Controls (Windows/Linux)
R
Ryan Adolf 已提交
313
		if (!isMacintosh) {
314
			this.windowControls = $(this.titleContainer).div({ class: 'window-controls-container' });
S
SteVen Batten 已提交
315

B
Benjamin Pasero 已提交
316
			// Minimize
S
SteVen Batten 已提交
317
			$($(this.windowControls).div({ class: 'window-icon-bg' })).div({ class: 'window-icon window-minimize' }).on(EventType.CLICK, () => {
R
Ryan Adolf 已提交
318
				this.windowService.minimizeWindow().then(null, errors.onUnexpectedError);
319
			});
R
Ryan Adolf 已提交
320

B
Benjamin Pasero 已提交
321
			// Restore
S
SteVen Batten 已提交
322
			this.maxRestoreControl = $($(this.windowControls).div({ class: 'window-icon-bg' })).div({ class: 'window-icon window-max-restore' }).on(EventType.CLICK, () => {
S
SteVen Batten 已提交
323 324 325 326
				this.windowService.isMaximized().then((maximized) => {
					if (maximized) {
						return this.windowService.unmaximizeWindow();
					}
B
Benjamin Pasero 已提交
327 328

					return this.windowService.maximizeWindow();
S
SteVen Batten 已提交
329
				}).then(null, errors.onUnexpectedError);
330
			});
R
Ryan Adolf 已提交
331

B
Benjamin Pasero 已提交
332
			// Close
S
SteVen Batten 已提交
333
			$($(this.windowControls).div({ class: 'window-icon-bg window-close-bg' })).div({ class: 'window-icon window-close' }).on(EventType.CLICK, () => {
R
Ryan Adolf 已提交
334
				this.windowService.closeWindow().then(null, errors.onUnexpectedError);
335
			});
336

B
Benjamin Pasero 已提交
337
			const isMaximized = this.windowService.getConfiguration().maximized ? true : false;
338
			this.onDidChangeMaximized(isMaximized);
339
			this.windowService.onDidChangeMaximize(this.onDidChangeMaximized, this);
340 341 342

			// Resizer
			$(this.titleContainer).div({ class: 'resizer' });
343
		}
R
Ryan Adolf 已提交
344

345 346
		// Since the title area is used to drag the window, we do not want to steal focus from the
		// currently active element. So we restore focus after a timeout back to where it was.
347
		this.titleContainer.on([EventType.MOUSE_DOWN], () => {
348 349 350 351 352 353 354 355
			const active = document.activeElement;
			setTimeout(() => {
				if (active instanceof HTMLElement) {
					active.focus();
				}
			}, 0 /* need a timeout because we are in capture phase */);
		}, void 0, true /* use capture to know the currently active element properly */);

356
		return this.titleContainer.getHTMLElement();
B
Benjamin Pasero 已提交
357 358
	}

359
	private onDidChangeMaximized(maximized: boolean) {
S
SteVen Batten 已提交
360
		if (!this.maxRestoreControl) {
S
SteVen Batten 已提交
361 362
			return;
		}
S
SteVen Batten 已提交
363

S
SteVen Batten 已提交
364
		if (maximized) {
S
SteVen Batten 已提交
365 366
			this.maxRestoreControl.removeClass('window-maximize');
			this.maxRestoreControl.addClass('window-unmaximize');
S
SteVen Batten 已提交
367
		} else {
S
SteVen Batten 已提交
368 369
			this.maxRestoreControl.removeClass('window-unmaximize');
			this.maxRestoreControl.addClass('window-maximize');
S
SteVen Batten 已提交
370
		}
371 372
	}

B
Benjamin Pasero 已提交
373 374 375 376
	protected updateStyles(): void {
		super.updateStyles();

		// Part container
377
		if (this.titleContainer) {
S
SteVen Batten 已提交
378 379 380 381 382 383
			if (this.isInactive) {
				this.titleContainer.addClass('inactive');
			} else {
				this.titleContainer.removeClass('inactive');
			}

B
Benjamin Pasero 已提交
384 385 386
			const titleBackground = this.getColor(this.isInactive ? TITLE_BAR_INACTIVE_BACKGROUND : TITLE_BAR_ACTIVE_BACKGROUND);
			this.titleContainer.style('background-color', titleBackground);
			if (Color.fromHex(titleBackground).isLighter()) {
S
SteVen Batten 已提交
387 388 389 390
				this.titleContainer.addClass('light');
			} else {
				this.titleContainer.removeClass('light');
			}
391

B
Benjamin Pasero 已提交
392 393 394
			const titleForeground = this.getColor(this.isInactive ? TITLE_BAR_INACTIVE_FOREGROUND : TITLE_BAR_ACTIVE_FOREGROUND);
			this.titleContainer.style('color', titleForeground);

395
			const titleBorder = this.getColor(TITLE_BAR_BORDER);
396
			this.titleContainer.style('border-bottom', titleBorder ? `1px solid ${titleBorder}` : null);
397
		}
B
Benjamin Pasero 已提交
398 399
	}

400
	private onTitleDoubleclick(): void {
401
		this.windowService.onWindowTitleDoubleClick().then(null, errors.onUnexpectedError);
402 403
	}

B
Benjamin Pasero 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
	private onContextMenu(e: MouseEvent): void {

		// Find target anchor
		const event = new StandardMouseEvent(e);
		const anchor = { x: event.posx, y: event.posy };

		// Show menu
		const actions = this.getContextMenuActions();
		if (actions.length) {
			this.contextMenuService.showContextMenu({
				getAnchor: () => anchor,
				getActions: () => TPromise.as(actions),
				onHide: () => actions.forEach(a => a.dispose())
			});
		}
	}

	private getContextMenuActions(): IAction[] {
		const actions: IAction[] = [];

		if (this.representedFileName) {
			const segments = this.representedFileName.split(paths.sep);
			for (let i = segments.length; i > 0; i--) {
427 428 429 430 431 432 433 434 435
				const isFile = (i === segments.length);

				let pathOffset = i;
				if (!isFile) {
					pathOffset++; // for segments which are not the file name we want to open the folder
				}

				const path = segments.slice(0, pathOffset).join(paths.sep);

B
Benjamin Pasero 已提交
436
				let label: string;
437
				if (!isFile) {
I
isidor 已提交
438
					label = getBaseLabel(paths.dirname(path));
B
Benjamin Pasero 已提交
439
				} else {
I
isidor 已提交
440
					label = getBaseLabel(path);
441 442 443
				}

				actions.push(new ShowItemInFolderAction(path, label || paths.sep, this.windowsService));
B
Benjamin Pasero 已提交
444 445 446 447 448 449
			}
		}

		return actions;
	}

B
Benjamin Pasero 已提交
450
	setTitle(title: string): void {
B
Benjamin Pasero 已提交
451 452 453 454 455 456 457 458 459 460 461 462

		// Always set the native window title to identify us properly to the OS
		window.document.title = title;

		// Apply if we can
		if (this.title) {
			this.title.text(title);
		} else {
			this.pendingTitle = title;
		}
	}

S
SteVen Batten 已提交
463 464
	private updateLayout(dimension: Dimension) {
		// Store initital title sizing if we need to prevent zooming
465
		if (typeof this.initialSizing.titleFontSize !== 'number') {
S
SteVen Batten 已提交
466
			this.initialSizing.titleFontSize = parseInt(this.title.getComputedStyle().fontSize, 10);
467 468 469
		}

		if (typeof this.initialSizing.titlebarHeight !== 'number') {
S
SteVen Batten 已提交
470
			this.initialSizing.titlebarHeight = parseInt(this.title.getComputedStyle().height, 10);
B
Benjamin Pasero 已提交
471
		}
472

S
SteVen Batten 已提交
473 474 475 476 477 478 479 480
		// Only prevent zooming behavior on macOS or when the menubar is not visible
		if (isMacintosh || this.configurationService.getValue<MenuBarVisibility>('window.menuBarVisibility') === 'hidden') {
			// To prevent zooming we need to adjust the font size with the zoom factor
			const newHeight = this.initialSizing.titlebarHeight / getZoomFactor();
			this.title.style({
				fontSize: `${this.initialSizing.titleFontSize / getZoomFactor()}px`,
				'line-height': `${newHeight}px`
			});
481

S
SteVen Batten 已提交
482 483 484 485 486
			// Windows/Linux specific layout
			if (isWindows || isLinux) {
				if (typeof this.initialSizing.controlsWidth !== 'number') {
					this.initialSizing.controlsWidth = parseInt(this.windowControls.getComputedStyle().width, 10);
				}
487

S
SteVen Batten 已提交
488 489 490
				if (typeof this.initialSizing.appIconWidth !== 'number') {
					this.initialSizing.appIconWidth = parseInt(this.appIcon.getComputedStyle().width, 10);
				}
491

S
SteVen Batten 已提交
492 493 494
				if (typeof this.initialSizing.appIconSize !== 'number') {
					this.initialSizing.appIconSize = parseInt(this.appIcon.getComputedStyle().backgroundSize, 10);
				}
495

S
SteVen Batten 已提交
496 497 498 499 500 501 502 503 504 505 506 507
				const currentAppIconHeight = parseInt(this.appIcon.getComputedStyle().height, 10);
				const newControlsWidth = this.initialSizing.controlsWidth / getZoomFactor();
				const newAppIconWidth = this.initialSizing.appIconWidth / getZoomFactor();
				const newAppIconSize = this.initialSizing.appIconSize / getZoomFactor();

				// Adjust app icon mimic menubar
				this.appIcon.style({
					'width': `${newAppIconWidth}px`,
					'background-size': `${newAppIconSize}px`,
					'padding-top': `${(newHeight - currentAppIconHeight) / 2.0}px`,
					'padding-bottom': `${(newHeight - currentAppIconHeight) / 2.0}px`
				});
508

S
SteVen Batten 已提交
509 510 511 512
				// Adjust windows controls
				this.windowControls.style({
					'width': `${newControlsWidth}px`
				});
513
			}
S
SteVen Batten 已提交
514 515 516 517 518 519
		} else {
			// We need to undo zoom prevention
			this.title.style({
				fontSize: null,
				'line-height': null
			});
520

521
			this.appIcon.style({
S
SteVen Batten 已提交
522 523 524 525
				'width': null,
				'background-size': null,
				'padding-top': null,
				'padding-bottom': null
526 527 528
			});

			this.windowControls.style({
S
SteVen Batten 已提交
529
				'width': null
530
			});
S
SteVen Batten 已提交
531
		}
532

S
SteVen Batten 已提交
533 534 535
		if (this.menubarPart) {
			const menubarDimension = new Dimension(undefined, dimension.height);
			this.menubarPart.layout(menubarDimension);
536 537 538
		}
	}

B
Benjamin Pasero 已提交
539
	layout(dimension: Dimension): Dimension[] {
S
SteVen Batten 已提交
540
		this.updateLayout(dimension);
B
Benjamin Pasero 已提交
541 542 543

		return super.layout(dimension);
	}
B
Benjamin Pasero 已提交
544 545 546 547
}

class ShowItemInFolderAction extends Action {

548 549
	constructor(private path: string, label: string, private windowsService: IWindowsService) {
		super('showItemInFolder.action.id', label);
B
Benjamin Pasero 已提交
550 551
	}

B
Benjamin Pasero 已提交
552
	run(): TPromise<void> {
B
Benjamin Pasero 已提交
553 554
		return this.windowsService.showItemInFolder(this.path);
	}
R
Ryan Adolf 已提交
555
}
S
SteVen Batten 已提交
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575

registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
	const titlebarActiveFg = theme.getColor(TITLE_BAR_ACTIVE_FOREGROUND);
	if (titlebarActiveFg) {
		collector.addRule(`
		.monaco-workbench > .part.titlebar > .window-controls-container .window-icon {
			background-color: ${titlebarActiveFg};
		}
		`);
	}

	const titlebarInactiveFg = theme.getColor(TITLE_BAR_INACTIVE_FOREGROUND);
	if (titlebarInactiveFg) {
		collector.addRule(`
		.monaco-workbench > .part.titlebar.inactive > .window-controls-container .window-icon {
				background-color: ${titlebarInactiveFg};
			}
		`);
	}
});