extensionsActions.ts 3.5 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

J
Joao Moreno 已提交
6
import { localize } from 'vs/nls';
J
Joao Moreno 已提交
7
import { TPromise } from 'vs/base/common/winjs.base';
8
import { Action } from 'vs/base/common/actions';
9
import severity from 'vs/base/common/severity';
10
import paths = require('vs/base/common/paths');
J
Joao Moreno 已提交
11
import { ReloadWindowAction } from 'vs/workbench/electron-browser/actions';
12
import { IExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/common/extensions';
13
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
14
import { IMessageService } from 'vs/platform/message/common/message';
15
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
16
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
17 18
import { IFileService } from 'vs/platform/files/common/files';
import URI from 'vs/base/common/uri';
19
import { mnemonicButtonLabel } from 'vs/base/common/labels';
J
Joao Moreno 已提交
20

21 22 23 24 25 26 27 28
export class OpenExtensionsFolderAction extends Action {

	static ID = 'workbench.extensions.action.openExtensionsFolder';
	static LABEL = localize('openExtensionsFolder', "Open Extensions Folder");

	constructor(
		id: string,
		label: string,
J
Joao Moreno 已提交
29
		@IWindowsService private windowsService: IWindowsService,
30
		@IFileService private fileService: IFileService,
31 32 33 34 35
		@IEnvironmentService private environmentService: IEnvironmentService
	) {
		super(id, label, null, true);
	}

J
Joao Moreno 已提交
36
	run(): TPromise<void> {
37
		const extensionsHome = this.environmentService.extensionsPath;
38 39 40 41 42 43 44 45 46 47 48

		return this.fileService.resolveFile(URI.file(extensionsHome)).then(file => {
			let itemToShow: string;
			if (file.hasChildren) {
				itemToShow = file.children[0].resource.fsPath;
			} else {
				itemToShow = paths.normalize(extensionsHome, true);
			}

			return this.windowsService.showItemInFolder(itemToShow);
		});
49
	}
S
Sandeep Somavarapu 已提交
50 51
}

J
Joao Moreno 已提交
52 53 54 55 56 57 58 59
export class InstallVSIXAction extends Action {

	static ID = 'workbench.extensions.action.installVSIX';
	static LABEL = localize('installVSIX', "Install from VSIX...");

	constructor(
		id = InstallVSIXAction.ID,
		label = InstallVSIXAction.LABEL,
60 61
		@IExtensionsWorkbenchService private extensionsWorkbenchService: IExtensionsWorkbenchService,
		@IMessageService private messageService: IMessageService,
62 63
		@IInstantiationService private instantiationService: IInstantiationService,
		@IWindowService private windowsService: IWindowService
J
Joao Moreno 已提交
64 65 66 67 68
	) {
		super(id, label, 'extension-action install-vsix', true);
	}

	run(): TPromise<any> {
69
		return this.windowsService.showOpenDialog({
70
			title: localize('installFromVSIX', "Install from VSIX"),
J
Joao Moreno 已提交
71
			filters: [{ name: 'VSIX Extensions', extensions: ['vsix'] }],
72 73
			properties: ['openFile'],
			buttonLabel: mnemonicButtonLabel(localize({ key: 'installButton', comment: ['&& denotes a mnemonic'] }, "&&Install"))
74 75 76 77
		}).then(result => {
			if (!result) {
				return TPromise.as(null);
			}
J
Joao Moreno 已提交
78

79 80 81 82 83 84 85 86 87
			return TPromise.join(result.map(vsix => this.extensionsWorkbenchService.install(vsix))).then(() => {
				this.messageService.show(
					severity.Info,
					{
						message: localize('InstallVSIXAction.success', "Successfully installed the extension. Restart to enable it."),
						actions: [this.instantiationService.createInstance(ReloadWindowAction, ReloadWindowAction.ID, localize('InstallVSIXAction.reloadNow', "Reload Now"))]
					}
				);
			});
88
		});
J
Joao Moreno 已提交
89
	}
90
}