titlebarPart.ts 20.2 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';
34
import { MenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl';
S
SteVen Batten 已提交
35
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;
55
	private menubarPart: MenubarControl;
S
SteVen Batten 已提交
56
	private menubar: Builder;
S
SteVen Batten 已提交
57
	private resizer: Builder;
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 86
		@IThemeService themeService: IThemeService,
		@IUriDisplayService private uriDisplayService: IUriDisplayService
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 {
B
Benjamin Pasero 已提交
97 98 99 100 101 102 103
		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())));
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 126
	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');
127

S
SteVen Batten 已提交
128 129 130 131 132 133 134
				// 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);
			}
		}
135 136
	}

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

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

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

		// 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;
171 172 173 174
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

B
Benjamin Pasero 已提交
306
		// Context menu on title
307 308 309
		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 已提交
310 311 312 313 314

				this.onContextMenu(e);
			}
		});

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

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

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

					return this.windowService.maximizeWindow();
S
SteVen Batten 已提交
332
				}).then(null, errors.onUnexpectedError);
333
			});
R
Ryan Adolf 已提交
334

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

S
SteVen Batten 已提交
340 341 342
			// Resizer
			this.resizer = $(this.titleContainer).div({ class: 'resizer' });

B
Benjamin Pasero 已提交
343
			const isMaximized = this.windowService.getConfiguration().maximized ? true : false;
344
			this.onDidChangeMaximized(isMaximized);
345
			this.windowService.onDidChangeMaximize(this.onDidChangeMaximized, this);
346
		}
R
Ryan Adolf 已提交
347

348 349
		// 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.
350
		this.titleContainer.on([EventType.MOUSE_DOWN], () => {
351 352 353 354 355 356 357 358
			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 */);

359
		return this.titleContainer.getHTMLElement();
B
Benjamin Pasero 已提交
360 361
	}

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

S
SteVen Batten 已提交
373 374 375 376 377 378
		if (this.resizer) {
			if (maximized) {
				this.resizer.hide();
			} else {
				this.resizer.show();
			}
S
SteVen Batten 已提交
379
		}
380 381
	}

B
Benjamin Pasero 已提交
382 383 384 385
	protected updateStyles(): void {
		super.updateStyles();

		// Part container
386
		if (this.titleContainer) {
S
SteVen Batten 已提交
387 388 389 390 391 392
			if (this.isInactive) {
				this.titleContainer.addClass('inactive');
			} else {
				this.titleContainer.removeClass('inactive');
			}

B
Benjamin Pasero 已提交
393 394 395
			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 已提交
396 397 398 399
				this.titleContainer.addClass('light');
			} else {
				this.titleContainer.removeClass('light');
			}
400

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

404
			const titleBorder = this.getColor(TITLE_BAR_BORDER);
405
			this.titleContainer.style('border-bottom', titleBorder ? `1px solid ${titleBorder}` : null);
406
		}
B
Benjamin Pasero 已提交
407 408
	}

409
	private onTitleDoubleclick(): void {
410
		this.windowService.onWindowTitleDoubleClick().then(null, errors.onUnexpectedError);
411 412
	}

B
Benjamin Pasero 已提交
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
	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--) {
436 437 438 439 440 441 442 443 444
				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 已提交
445
				let label: string;
446
				if (!isFile) {
I
isidor 已提交
447
					label = getBaseLabel(paths.dirname(path));
B
Benjamin Pasero 已提交
448
				} else {
I
isidor 已提交
449
					label = getBaseLabel(path);
450 451 452
				}

				actions.push(new ShowItemInFolderAction(path, label || paths.sep, this.windowsService));
B
Benjamin Pasero 已提交
453 454 455 456 457 458
			}
		}

		return actions;
	}

B
Benjamin Pasero 已提交
459
	setTitle(title: string): void {
B
Benjamin Pasero 已提交
460 461 462 463 464 465 466 467 468 469 470 471

		// 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 已提交
472 473
	private updateLayout(dimension: Dimension) {
		// Store initital title sizing if we need to prevent zooming
474
		if (typeof this.initialSizing.titleFontSize !== 'number') {
S
SteVen Batten 已提交
475
			this.initialSizing.titleFontSize = parseInt(this.title.getComputedStyle().fontSize, 10);
476 477 478
		}

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

S
SteVen Batten 已提交
482 483 484 485 486 487 488 489
		// 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`
			});
490

S
SteVen Batten 已提交
491 492 493 494 495
			// Windows/Linux specific layout
			if (isWindows || isLinux) {
				if (typeof this.initialSizing.controlsWidth !== 'number') {
					this.initialSizing.controlsWidth = parseInt(this.windowControls.getComputedStyle().width, 10);
				}
496

S
SteVen Batten 已提交
497 498 499
				if (typeof this.initialSizing.appIconWidth !== 'number') {
					this.initialSizing.appIconWidth = parseInt(this.appIcon.getComputedStyle().width, 10);
				}
500

S
SteVen Batten 已提交
501 502 503
				if (typeof this.initialSizing.appIconSize !== 'number') {
					this.initialSizing.appIconSize = parseInt(this.appIcon.getComputedStyle().backgroundSize, 10);
				}
504

S
SteVen Batten 已提交
505 506 507 508 509 510 511 512 513 514 515 516
				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`
				});
517

S
SteVen Batten 已提交
518 519 520 521
				// Adjust windows controls
				this.windowControls.style({
					'width': `${newControlsWidth}px`
				});
522
			}
S
SteVen Batten 已提交
523 524 525 526 527 528
		} else {
			// We need to undo zoom prevention
			this.title.style({
				fontSize: null,
				'line-height': null
			});
529

530
			this.appIcon.style({
S
SteVen Batten 已提交
531 532 533 534
				'width': null,
				'background-size': null,
				'padding-top': null,
				'padding-bottom': null
535 536 537
			});

			this.windowControls.style({
S
SteVen Batten 已提交
538
				'width': null
539
			});
S
SteVen Batten 已提交
540
		}
541

S
SteVen Batten 已提交
542 543 544
		if (this.menubarPart) {
			const menubarDimension = new Dimension(undefined, dimension.height);
			this.menubarPart.layout(menubarDimension);
545 546 547
		}
	}

B
Benjamin Pasero 已提交
548
	layout(dimension: Dimension): Dimension[] {
S
SteVen Batten 已提交
549
		this.updateLayout(dimension);
B
Benjamin Pasero 已提交
550 551 552

		return super.layout(dimension);
	}
B
Benjamin Pasero 已提交
553 554 555 556
}

class ShowItemInFolderAction extends Action {

557 558
	constructor(private path: string, label: string, private windowsService: IWindowsService) {
		super('showItemInFolder.action.id', label);
B
Benjamin Pasero 已提交
559 560
	}

B
Benjamin Pasero 已提交
561
	run(): TPromise<void> {
B
Benjamin Pasero 已提交
562 563
		return this.windowsService.showItemInFolder(this.path);
	}
R
Ryan Adolf 已提交
564
}
S
SteVen Batten 已提交
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584

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