workspaces.ts 2.5 KB
Newer Older
B
Benjamin Pasero 已提交
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 { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { TPromise } from 'vs/base/common/winjs.base';
10 11 12 13 14
import { isParent } from "vs/platform/files/common/files";
import { localize } from "vs/nls";
import { basename } from "vs/base/common/paths";
import { isLinux } from "vs/base/common/platform";
import { IEnvironmentService } from "vs/platform/environment/common/environment";
15
import Event from 'vs/base/common/event';
B
Benjamin Pasero 已提交
16 17 18 19

export const IWorkspacesMainService = createDecorator<IWorkspacesMainService>('workspacesMainService');
export const IWorkspacesService = createDecorator<IWorkspacesService>('workspacesService');

B
Benjamin Pasero 已提交
20
export const WORKSPACE_EXTENSION = 'code-workspace';
B
Benjamin Pasero 已提交
21

22 23 24 25 26
/**
 * A single folder workspace identifier is just the path to the folder.
 */
export type ISingleFolderWorkspaceIdentifier = string;

27 28
export interface IWorkspaceIdentifier {
	id: string;
29
	configPath: string;
B
Benjamin Pasero 已提交
30 31 32 33 34 35 36
}

export interface IStoredWorkspace {
	id: string;
	folders: string[];
}

37 38 39 40 41
export interface IWorkspaceSavedEvent {
	workspace: IWorkspaceIdentifier;
	oldConfigPath: string;
}

B
Benjamin Pasero 已提交
42 43 44
export interface IWorkspacesMainService extends IWorkspacesService {
	_serviceBrand: any;

45 46
	onWorkspaceSaved: Event<IWorkspaceSavedEvent>;

47
	resolveWorkspaceSync(path: string): IWorkspaceIdentifier;
B
Benjamin Pasero 已提交
48
	isUntitledWorkspace(workspace: IWorkspaceIdentifier): boolean;
B
Benjamin Pasero 已提交
49 50 51 52 53
}

export interface IWorkspacesService {
	_serviceBrand: any;

54
	createWorkspace(folders?: string[]): TPromise<IWorkspaceIdentifier>;
55
	saveWorkspace(workspace: IWorkspaceIdentifier, target: string): TPromise<IWorkspaceIdentifier>;
56 57 58 59 60 61 62
}

export function getWorkspaceLabel(environmentService: IEnvironmentService, workspace: IWorkspaceIdentifier): string {
	if (isParent(workspace.configPath, environmentService.workspacesHome, !isLinux /* ignore case */)) {
		return localize('untitledWorkspace', "Untitled Workspace");
	}

B
Benjamin Pasero 已提交
63 64 65 66
	const filename = basename(workspace.configPath);
	const workspaceName = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);

	return localize('workspaceName', "{0} (Workspace)", workspaceName);
B
Benjamin Pasero 已提交
67 68 69 70
}

export function isSingleFolderWorkspaceIdentifier(obj: any): obj is ISingleFolderWorkspaceIdentifier {
	return typeof obj === 'string';
B
Benjamin Pasero 已提交
71
}