windowService.ts 4.0 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6 7 8 9
/*---------------------------------------------------------------------------------------------
 *  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 { TPromise } from 'vs/base/common/winjs.base';
import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows';
10
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
11
import { remote } from 'electron';
12
import { IRecentlyOpened } from "vs/platform/history/common/history";
J
Joao Moreno 已提交
13 14 15 16 17 18 19 20 21 22

export class WindowService implements IWindowService {

	_serviceBrand: any;

	constructor(
		private windowId: number,
		@IWindowsService private windowsService: IWindowsService
	) { }

J
Joao Moreno 已提交
23 24 25 26
	getCurrentWindowId(): number {
		return this.windowId;
	}

B
renames  
Benjamin Pasero 已提交
27 28
	pickFileFolderAndOpen(forceNewWindow?: boolean, data?: ITelemetryData): TPromise<void> {
		return this.windowsService.pickFileFolderAndOpen(this.windowId, forceNewWindow, data);
J
Joao Moreno 已提交
29 30
	}

B
renames  
Benjamin Pasero 已提交
31 32
	pickFileAndOpen(forceNewWindow?: boolean, path?: string, data?: ITelemetryData): TPromise<void> {
		return this.windowsService.pickFileAndOpen(this.windowId, forceNewWindow, path, data);
J
Joao Moreno 已提交
33 34
	}

B
renames  
Benjamin Pasero 已提交
35 36
	pickFolderAndOpen(forceNewWindow?: boolean, data?: ITelemetryData): TPromise<void> {
		return this.windowsService.pickFolderAndOpen(this.windowId, forceNewWindow, data);
J
Joao Moreno 已提交
37
	}
38

B
Benjamin Pasero 已提交
39
	pickFolder(options?: { buttonLabel: string; title: string; }): TPromise<string[]> {
40
		return this.windowsService.pickFolder(this.windowId, options);
41 42
	}

43 44 45
	reloadWindow(): TPromise<void> {
		return this.windowsService.reloadWindow(this.windowId);
	}
J
Joao Moreno 已提交
46

J
Joao Moreno 已提交
47 48 49 50
	openDevTools(): TPromise<void> {
		return this.windowsService.openDevTools(this.windowId);
	}

J
Joao Moreno 已提交
51 52 53
	toggleDevTools(): TPromise<void> {
		return this.windowsService.toggleDevTools(this.windowId);
	}
J
Joao Moreno 已提交
54 55 56 57

	closeFolder(): TPromise<void> {
		return this.windowsService.closeFolder(this.windowId);
	}
J
Joao Moreno 已提交
58

59 60 61 62
	closeWindow(): TPromise<void> {
		return this.windowsService.closeWindow(this.windowId);
	}

J
Joao Moreno 已提交
63 64 65
	toggleFullScreen(): TPromise<void> {
		return this.windowsService.toggleFullScreen(this.windowId);
	}
66 67 68 69

	setRepresentedFilename(fileName: string): TPromise<void> {
		return this.windowsService.setRepresentedFilename(this.windowId, fileName);
	}
J
Joao Moreno 已提交
70

71
	getRecentlyOpened(): TPromise<IRecentlyOpened> {
B
Benjamin Pasero 已提交
72
		return this.windowsService.getRecentlyOpened(this.windowId);
J
Joao Moreno 已提交
73
	}
J
Joao Moreno 已提交
74 75 76 77

	focusWindow(): TPromise<void> {
		return this.windowsService.focusWindow(this.windowId);
	}
J
Joao Moreno 已提交
78

79 80 81 82
	isFocused(): TPromise<boolean> {
		return this.windowsService.isFocused(this.windowId);
	}

83 84 85 86 87 88 89 90 91 92 93 94
	isMaximized(): TPromise<boolean> {
		return this.windowsService.isMaximized(this.windowId);
	}

	maximizeWindow(): TPromise<void> {
		return this.windowsService.maximizeWindow(this.windowId);
	}

	unmaximizeWindow(): TPromise<void> {
		return this.windowsService.unmaximizeWindow(this.windowId);
	}

95 96 97 98
	onWindowTitleDoubleClick(): TPromise<void> {
		return this.windowsService.onWindowTitleDoubleClick(this.windowId);
	}

J
Joao Moreno 已提交
99 100 101
	setDocumentEdited(flag: boolean): TPromise<void> {
		return this.windowsService.setDocumentEdited(this.windowId, flag);
	}
J
Joao Moreno 已提交
102

103 104 105 106 107 108 109 110 111 112 113
	showMessageBox(options: Electron.ShowMessageBoxOptions): number {
		return remote.dialog.showMessageBox(remote.getCurrentWindow(), options);
	}

	showSaveDialog(options: Electron.SaveDialogOptions, callback?: (fileName: string) => void): string {
		if (callback) {
			return remote.dialog.showSaveDialog(remote.getCurrentWindow(), options, callback);
		}

		return remote.dialog.showSaveDialog(remote.getCurrentWindow(), options); // https://github.com/electron/electron/issues/4936
	}
114 115 116 117 118 119 120 121

	showOpenDialog(options: Electron.OpenDialogOptions, callback?: (fileNames: string[]) => void): string[] {
		if (callback) {
			return remote.dialog.showOpenDialog(remote.getCurrentWindow(), options, callback);
		}

		return remote.dialog.showOpenDialog(remote.getCurrentWindow(), options); // https://github.com/electron/electron/issues/4936
	}
122
}