titlebarPart.ts 20.9 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 10
import { TPromise } from 'vs/base/common/winjs.base';
import * as paths from 'vs/base/common/paths';
B
Benjamin Pasero 已提交
11
import { Part } from 'vs/workbench/browser/part';
12
import { ITitleService, ITitleProperties } from 'vs/workbench/services/title/common/titleService';
B
Benjamin Pasero 已提交
13
import { getZoomFactor } from 'vs/base/browser/browser';
14
import { IWindowService, IWindowsService, MenuBarVisibility } from 'vs/platform/windows/common/windows';
B
Benjamin Pasero 已提交
15 16 17 18
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';
19
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
B
Benjamin Pasero 已提交
20
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
21
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
22
import * as nls from 'vs/nls';
B
Benjamin Pasero 已提交
23
import { EditorInput, toResource, Verbosity } from 'vs/workbench/common/editor';
24
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
25
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
S
SteVen Batten 已提交
26
import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
27
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 已提交
28
import { isMacintosh, isWindows, isLinux } from 'vs/base/common/platform';
29
import { URI } from 'vs/base/common/uri';
R
Ryan Adolf 已提交
30
import { Color } from 'vs/base/common/color';
B
Benjamin Pasero 已提交
31
import { trim } from 'vs/base/common/strings';
32
import { EventType, EventHelper, Dimension, isAncestor, hide, show, removeClass, addClass, append, $, addDisposableListener } from 'vs/base/browser/dom';
33
import { MenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl';
S
SteVen Batten 已提交
34
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
I
isidor 已提交
35
import { template, getBaseLabel } from 'vs/base/common/labels';
I
isidor 已提交
36
import { ILabelService } from 'vs/platform/label/common/label';
37
import { Event } from 'vs/base/common/event';
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

49 50 51 52 53 54
	private titleContainer: HTMLElement;
	private title: HTMLElement;
	private dragRegion: HTMLElement;
	private windowControls: HTMLElement;
	private maxRestoreControl: HTMLElement;
	private appIcon: HTMLElement;
55
	private menubarPart: MenubarControl;
56 57
	private menubar: HTMLElement;
	private resizer: HTMLElement;
B
Benjamin Pasero 已提交
58

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

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

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

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

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

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

93 94 95 96
		this.registerListeners();
	}

	private registerListeners(): void {
97
		this._register(this.windowService.onDidChangeFocus(focused => focused ? this.onFocus() : this.onBlur()));
B
Benjamin Pasero 已提交
98 99 100 101 102
		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
		this._register(this.labelService.onDidRegisterFormatter(() => this.setTitle(this.getWindowTitle())));
104 105
	}

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

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

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

S
SteVen Batten 已提交
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) {
126
				this.title.style.visibility = 'hidden';
127

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

137 138 139 140
	onMenubarVisibilityChange(): Event<boolean> {
		return this.menubarPart.onVisibilityChange;
	}

B
Benjamin Pasero 已提交
141
	private onActiveEditorChange(): void {
142 143 144 145 146 147 148 149 150

		// 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 已提交
151 152 153
		const activeEditor = this.editorService.activeEditor;
		if (activeEditor instanceof EditorInput) {
			this.activeEditorListeners.push(activeEditor.onDidChangeDirty(() => {
154 155 156
				this.setTitle(this.getWindowTitle());
			}));

B
Benjamin Pasero 已提交
157
			this.activeEditorListeners.push(activeEditor.onDidChangeLabel(() => {
158 159 160
				this.setTitle(this.getWindowTitle());
			}));
		}
B
Benjamin Pasero 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174

		// 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;
175 176 177 178
	}

	private getWindowTitle(): string {
		let title = this.doGetWindowTitle();
B
Benjamin Pasero 已提交
179
		if (!trim(title)) {
180 181 182
			title = this.environmentService.appNameLong;
		}

183 184 185 186 187
		if (this.properties.isAdmin) {
			title = `${title} ${TitlebarPart.NLS_USER_IS_ADMIN}`;
		}

		if (!this.properties.isPure) {
188 189 190 191 192 193 194 195 196 197 198
			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 已提交
199
	updateProperties(properties: ITitleProperties): void {
200 201 202 203 204 205 206 207 208 209 210
		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());
		}
	}

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

229
		let root: URI;
230
		if (workspace.configuration) {
231
			root = workspace.configuration;
232 233
		} else if (workspace.folders.length) {
			root = workspace.folders[0].uri;
234 235 236 237
		}

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

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

I
isidor 已提交
254
		return template(titleTemplate, {
B
Benjamin Pasero 已提交
255 256 257
			activeEditorShort,
			activeEditorLong,
			activeEditorMedium,
258 259
			rootName,
			rootPath,
260 261
			folderName,
			folderPath,
262 263 264 265 266 267
			dirty,
			appName,
			separator: { label: separator }
		});
	}

B
Benjamin Pasero 已提交
268
	createContentArea(parent: HTMLElement): HTMLElement {
269
		this.titleContainer = parent;
B
Benjamin Pasero 已提交
270

271
		// Draggable region that we can manipulate for #52522
272
		this.dragRegion = append(this.titleContainer, $('div.titlebar-drag-region'));
273

B
Benjamin Pasero 已提交
274
		// App Icon (Windows/Linux)
R
Ryan Adolf 已提交
275
		if (!isMacintosh) {
276
			this.appIcon = append(this.titleContainer, $('div.window-appicon'));
277
		}
S
SteVen Batten 已提交
278

S
SteVen Batten 已提交
279
		// Menubar: the menubar part which is responsible for populating both the custom and native menubars
280 281 282
		this.menubarPart = this.instantiationService.createInstance(MenubarControl);
		this.menubar = append(this.titleContainer, $('div.menubar'));
		this.menubar.setAttribute('role', 'menubar');
S
SteVen Batten 已提交
283

284
		this.menubarPart.create(this.menubar);
S
SteVen Batten 已提交
285 286 287 288 289

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

B
Benjamin Pasero 已提交
290
		// Title
291
		this.title = append(this.titleContainer, $('div.window-title'));
B
Benjamin Pasero 已提交
292
		if (this.pendingTitle) {
293
			this.title.innerText = this.pendingTitle;
B
Benjamin Pasero 已提交
294 295
		} else {
			this.setTitle(this.getWindowTitle());
B
Benjamin Pasero 已提交
296 297
		}

298
		// Maximize/Restore on doubleclick
S
SteVen Batten 已提交
299
		if (isMacintosh) {
300
			this._register(addDisposableListener(this.titleContainer, EventType.DBLCLICK, e => {
S
SteVen Batten 已提交
301
				EventHelper.stop(e);
302

S
SteVen Batten 已提交
303
				this.onTitleDoubleclick();
304
			}));
S
SteVen Batten 已提交
305
		}
306

B
Benjamin Pasero 已提交
307
		// Context menu on title
308 309 310 311
		[EventType.CONTEXT_MENU, EventType.MOUSE_DOWN].forEach(event => {
			this._register(addDisposableListener(this.title, event, e => {
				if (e.type === EventType.CONTEXT_MENU || e.metaKey) {
					EventHelper.stop(e);
B
Benjamin Pasero 已提交
312

313 314 315
					this.onContextMenu(e);
				}
			}));
B
Benjamin Pasero 已提交
316 317
		});

B
Benjamin Pasero 已提交
318
		// Window Controls (Windows/Linux)
R
Ryan Adolf 已提交
319
		if (!isMacintosh) {
320 321
			this.windowControls = append(this.titleContainer, $('div.window-controls-container'));

S
SteVen Batten 已提交
322

B
Benjamin Pasero 已提交
323
			// Minimize
324 325 326 327 328 329
			const minimizeIconContainer = append(this.windowControls, $('div.window-icon-bg'));
			const minimizeIcon = append(minimizeIconContainer, $('div.window-icon'));
			addClass(minimizeIcon, 'window-minimize');
			this._register(addDisposableListener(minimizeIcon, EventType.CLICK, e => {
				this.windowService.minimizeWindow();
			}));
R
Ryan Adolf 已提交
330

B
Benjamin Pasero 已提交
331
			// Restore
332 333 334 335
			const restoreIconContainer = append(this.windowControls, $('div.window-icon-bg'));
			this.maxRestoreControl = append(restoreIconContainer, $('div.window-icon'));
			addClass(this.maxRestoreControl, 'window-max-restore');
			this._register(addDisposableListener(this.maxRestoreControl, EventType.CLICK, e => {
S
SteVen Batten 已提交
336 337 338 339
				this.windowService.isMaximized().then((maximized) => {
					if (maximized) {
						return this.windowService.unmaximizeWindow();
					}
B
Benjamin Pasero 已提交
340 341

					return this.windowService.maximizeWindow();
342 343
				});
			}));
R
Ryan Adolf 已提交
344

B
Benjamin Pasero 已提交
345
			// Close
346 347 348 349 350 351 352
			const closeIconContainer = append(this.windowControls, $('div.window-icon-bg'));
			addClass(closeIconContainer, 'window-close-bg');
			const closeIcon = append(closeIconContainer, $('div.window-icon'));
			addClass(closeIcon, 'window-close');
			this._register(addDisposableListener(closeIcon, EventType.CLICK, e => {
				this.windowService.closeWindow();
			}));
353

S
SteVen Batten 已提交
354
			// Resizer
355
			this.resizer = append(this.titleContainer, $('div.resizer'));
S
SteVen Batten 已提交
356

B
Benjamin Pasero 已提交
357
			const isMaximized = this.windowService.getConfiguration().maximized ? true : false;
358
			this.onDidChangeMaximized(isMaximized);
359
			this.windowService.onDidChangeMaximize(this.onDidChangeMaximized, this);
360
		}
R
Ryan Adolf 已提交
361

362 363
		// 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.
364 365
		this._register(addDisposableListener(this.titleContainer, EventType.MOUSE_DOWN, e => {
			if (e.target && isAncestor(e.target as HTMLElement, this.menubar)) {
S
SteVen Batten 已提交
366 367 368
				return;
			}

369 370 371 372 373 374
			const active = document.activeElement;
			setTimeout(() => {
				if (active instanceof HTMLElement) {
					active.focus();
				}
			}, 0 /* need a timeout because we are in capture phase */);
375
		}, true /* use capture to know the currently active element properly */));
376

377
		return this.titleContainer;
B
Benjamin Pasero 已提交
378 379
	}

380
	private onDidChangeMaximized(maximized: boolean) {
S
SteVen Batten 已提交
381 382
		if (this.maxRestoreControl) {
			if (maximized) {
383 384
				removeClass(this.maxRestoreControl, 'window-maximize');
				addClass(this.maxRestoreControl, 'window-unmaximize');
S
SteVen Batten 已提交
385
			} else {
386 387
				removeClass(this.maxRestoreControl, 'window-unmaximize');
				addClass(this.maxRestoreControl, 'window-maximize');
S
SteVen Batten 已提交
388
			}
S
SteVen Batten 已提交
389
		}
S
SteVen Batten 已提交
390

S
SteVen Batten 已提交
391 392
		if (this.resizer) {
			if (maximized) {
393
				hide(this.resizer);
S
SteVen Batten 已提交
394
			} else {
395
				show(this.resizer);
S
SteVen Batten 已提交
396
			}
S
SteVen Batten 已提交
397
		}
398 399
	}

B
Benjamin Pasero 已提交
400 401 402 403
	protected updateStyles(): void {
		super.updateStyles();

		// Part container
404
		if (this.titleContainer) {
S
SteVen Batten 已提交
405
			if (this.isInactive) {
406
				addClass(this.titleContainer, 'inactive');
S
SteVen Batten 已提交
407
			} else {
408
				removeClass(this.titleContainer, 'inactive');
S
SteVen Batten 已提交
409 410
			}

B
Benjamin Pasero 已提交
411
			const titleBackground = this.getColor(this.isInactive ? TITLE_BAR_INACTIVE_BACKGROUND : TITLE_BAR_ACTIVE_BACKGROUND);
412
			this.titleContainer.style.backgroundColor = titleBackground;
B
Benjamin Pasero 已提交
413
			if (Color.fromHex(titleBackground).isLighter()) {
414
				addClass(this.titleContainer, 'light');
S
SteVen Batten 已提交
415
			} else {
416
				removeClass(this.titleContainer, 'light');
S
SteVen Batten 已提交
417
			}
418

B
Benjamin Pasero 已提交
419
			const titleForeground = this.getColor(this.isInactive ? TITLE_BAR_INACTIVE_FOREGROUND : TITLE_BAR_ACTIVE_FOREGROUND);
420
			this.titleContainer.style.color = titleForeground;
B
Benjamin Pasero 已提交
421

422
			const titleBorder = this.getColor(TITLE_BAR_BORDER);
423
			this.titleContainer.style.borderBottom = titleBorder ? `1px solid ${titleBorder}` : null;
424
		}
B
Benjamin Pasero 已提交
425 426
	}

427
	private onTitleDoubleclick(): void {
428
		this.windowService.onWindowTitleDoubleClick().then(null, errors.onUnexpectedError);
429 430
	}

B
Benjamin Pasero 已提交
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
	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--) {
454 455 456 457 458 459 460 461 462
				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 已提交
463
				let label: string;
464
				if (!isFile) {
I
isidor 已提交
465
					label = getBaseLabel(paths.dirname(path));
B
Benjamin Pasero 已提交
466
				} else {
I
isidor 已提交
467
					label = getBaseLabel(path);
468 469 470
				}

				actions.push(new ShowItemInFolderAction(path, label || paths.sep, this.windowsService));
B
Benjamin Pasero 已提交
471 472 473 474 475 476
			}
		}

		return actions;
	}

B
Benjamin Pasero 已提交
477
	setTitle(title: string): void {
B
Benjamin Pasero 已提交
478 479 480 481 482 483

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

		// Apply if we can
		if (this.title) {
484
			this.title.innerText = title;
B
Benjamin Pasero 已提交
485 486 487 488 489
		} else {
			this.pendingTitle = title;
		}
	}

S
SteVen Batten 已提交
490 491
	private updateLayout(dimension: Dimension) {
		// Store initital title sizing if we need to prevent zooming
492
		if (typeof this.initialSizing.titleFontSize !== 'number') {
493
			this.initialSizing.titleFontSize = parseInt(getComputedStyle(this.title).fontSize, 10);
494 495 496
		}

		if (typeof this.initialSizing.titlebarHeight !== 'number') {
497
			this.initialSizing.titlebarHeight = parseInt(getComputedStyle(this.title).height, 10);
B
Benjamin Pasero 已提交
498
		}
499

S
SteVen Batten 已提交
500 501 502 503
		// 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();
504 505
			this.title.style.fontSize = `${this.initialSizing.titleFontSize / getZoomFactor()}px`;
			this.title.style.lineHeight = `${newHeight}px`;
506

S
SteVen Batten 已提交
507 508 509
			// Windows/Linux specific layout
			if (isWindows || isLinux) {
				if (typeof this.initialSizing.controlsWidth !== 'number') {
510
					this.initialSizing.controlsWidth = parseInt(getComputedStyle(this.windowControls).width, 10);
S
SteVen Batten 已提交
511
				}
512

513
				const appIconComputedStyles = getComputedStyle(this.appIcon);
S
SteVen Batten 已提交
514
				if (typeof this.initialSizing.appIconWidth !== 'number') {
515
					this.initialSizing.appIconWidth = parseInt(appIconComputedStyles.width, 10);
S
SteVen Batten 已提交
516
				}
517

S
SteVen Batten 已提交
518
				if (typeof this.initialSizing.appIconSize !== 'number') {
519
					this.initialSizing.appIconSize = parseInt(appIconComputedStyles.backgroundSize, 10);
S
SteVen Batten 已提交
520
				}
521

522
				const currentAppIconHeight = parseInt(appIconComputedStyles.height, 10);
S
SteVen Batten 已提交
523 524 525 526 527
				const newControlsWidth = this.initialSizing.controlsWidth / getZoomFactor();
				const newAppIconWidth = this.initialSizing.appIconWidth / getZoomFactor();
				const newAppIconSize = this.initialSizing.appIconSize / getZoomFactor();

				// Adjust app icon mimic menubar
528 529 530 531
				this.appIcon.style.width = `${newAppIconWidth}px`;
				this.appIcon.style.backgroundSize = `${newAppIconSize}px`;
				this.appIcon.style.paddingTop = `${(newHeight - currentAppIconHeight) / 2.0}px`;
				this.appIcon.style.paddingBottom = `${(newHeight - currentAppIconHeight) / 2.0}px`;
532

S
SteVen Batten 已提交
533
				// Adjust windows controls
534
				this.windowControls.style.width = `${newControlsWidth}px`;
535
			}
S
SteVen Batten 已提交
536 537
		} else {
			// We need to undo zoom prevention
538 539
			this.title.style.fontSize = null;
			this.title.style.lineHeight = null;
540

541 542 543 544
			this.appIcon.style.width = null;
			this.appIcon.style.backgroundSize = null;
			this.appIcon.style.paddingTop = null;
			this.appIcon.style.paddingBottom = null;
545

546
			this.windowControls.style.width = null;
S
SteVen Batten 已提交
547
		}
548

S
SteVen Batten 已提交
549 550 551
		if (this.menubarPart) {
			const menubarDimension = new Dimension(undefined, dimension.height);
			this.menubarPart.layout(menubarDimension);
552 553 554
		}
	}

B
Benjamin Pasero 已提交
555
	layout(dimension: Dimension): Dimension[] {
S
SteVen Batten 已提交
556
		this.updateLayout(dimension);
B
Benjamin Pasero 已提交
557 558 559

		return super.layout(dimension);
	}
B
Benjamin Pasero 已提交
560 561 562 563
}

class ShowItemInFolderAction extends Action {

564 565
	constructor(private path: string, label: string, private windowsService: IWindowsService) {
		super('showItemInFolder.action.id', label);
B
Benjamin Pasero 已提交
566 567
	}

B
Benjamin Pasero 已提交
568
	run(): TPromise<void> {
B
Benjamin Pasero 已提交
569 570
		return this.windowsService.showItemInFolder(this.path);
	}
R
Ryan Adolf 已提交
571
}
S
SteVen Batten 已提交
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591

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};
			}
		`);
	}
});