workspaces.ts 3.8 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';
B
Benjamin Pasero 已提交
10
import { localize } from 'vs/nls';
M
Matt Bierner 已提交
11
import { Event } from 'vs/base/common/event';
S
Sandeep Somavarapu 已提交
12
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
13
import URI from 'vs/base/common/uri';
B
Benjamin Pasero 已提交
14 15 16 17

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

B
Benjamin Pasero 已提交
18
export const WORKSPACE_EXTENSION = 'code-workspace';
19
export const WORKSPACE_FILTER = [{ name: localize('codeWorkspace', "Code Workspace"), extensions: [WORKSPACE_EXTENSION] }];
20
export const UNTITLED_WORKSPACE_NAME = 'workspace.json';
B
Benjamin Pasero 已提交
21

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

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

J
Johannes Rieken 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
export function isStoredWorkspaceFolder(thing: any): thing is IStoredWorkspaceFolder {
	return isRawFileWorkspaceFolder(thing) || isRawUriWorkspaceFolder(thing);
}

export function isRawFileWorkspaceFolder(thing: any): thing is IRawFileWorkspaceFolder {
	return thing
		&& typeof thing === 'object'
		&& typeof thing.path === 'string'
		&& (!thing.name || typeof thing.name === 'string');
}

export function isRawUriWorkspaceFolder(thing: any): thing is IRawUriWorkspaceFolder {
	return thing
		&& typeof thing === 'object'
		&& typeof thing.uri === 'string'
		&& (!thing.name || typeof thing.name === 'string');
}

export interface IRawFileWorkspaceFolder {
51
	path: string;
52
	name?: string;
53 54
}

J
Johannes Rieken 已提交
55 56 57 58 59 60 61
export interface IRawUriWorkspaceFolder {
	uri: string;
	name?: string;
}

export type IStoredWorkspaceFolder = IRawFileWorkspaceFolder | IRawUriWorkspaceFolder;

62
export interface IResolvedWorkspace extends IWorkspaceIdentifier {
S
Sandeep Somavarapu 已提交
63
	folders: IWorkspaceFolder[];
B
Benjamin Pasero 已提交
64 65
}

J
Johannes Rieken 已提交
66 67 68 69
export interface IStoredWorkspace {
	folders: IStoredWorkspaceFolder[];
}

70 71 72 73 74
export interface IWorkspaceSavedEvent {
	workspace: IWorkspaceIdentifier;
	oldConfigPath: string;
}

75 76 77 78 79
export interface IWorkspaceFolderCreationData {
	uri: URI;
	name?: string;
}

B
Benjamin Pasero 已提交
80 81 82
export interface IWorkspacesMainService extends IWorkspacesService {
	_serviceBrand: any;

83
	onWorkspaceSaved: Event<IWorkspaceSavedEvent>;
84
	onUntitledWorkspaceDeleted: Event<IWorkspaceIdentifier>;
85

86
	saveWorkspace(workspace: IWorkspaceIdentifier, target: string): TPromise<IWorkspaceIdentifier>;
87

88
	createWorkspaceSync(folders?: IWorkspaceFolderCreationData[]): IWorkspaceIdentifier;
89

90 91
	resolveWorkspace(path: string): TPromise<IResolvedWorkspace>;

92
	resolveWorkspaceSync(path: string): IResolvedWorkspace;
B
Benjamin Pasero 已提交
93

B
Benjamin Pasero 已提交
94
	isUntitledWorkspace(workspace: IWorkspaceIdentifier): boolean;
95

96
	deleteUntitledWorkspaceSync(workspace: IWorkspaceIdentifier): void;
97 98

	getUntitledWorkspacesSync(): IWorkspaceIdentifier[];
99 100

	getWorkspaceId(workspacePath: string): string;
B
Benjamin Pasero 已提交
101 102 103 104 105
}

export interface IWorkspacesService {
	_serviceBrand: any;

106
	createWorkspace(folders?: IWorkspaceFolderCreationData[]): TPromise<IWorkspaceIdentifier>;
107 108
}

109
export function isSingleFolderWorkspaceIdentifier(obj: any): obj is ISingleFolderWorkspaceIdentifier {
110
	return obj instanceof URI;
111 112 113 114 115 116
}

export function isWorkspaceIdentifier(obj: any): obj is IWorkspaceIdentifier {
	const workspaceIdentifier = obj as IWorkspaceIdentifier;

	return workspaceIdentifier && typeof workspaceIdentifier.id === 'string' && typeof workspaceIdentifier.configPath === 'string';
J
Johannes Rieken 已提交
117
}