nextEditorActions.ts 6.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*---------------------------------------------------------------------------------------------
 *  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 URI from 'vs/base/common/uri';
import { Action } from 'vs/base/common/actions';
import { localize } from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
B
Benjamin Pasero 已提交
12
import { INextEditorGroupsService, GroupDirection } from 'vs/workbench/services/group/common/nextEditorGroupsService';
13
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
14
import { EditorInput } from 'vs/workbench/common/editor';
15 16
import { join, dirname } from 'vs/base/common/paths';
import { isWindows } from 'vs/base/common/platform';
17
import { INextEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/nextEditorService';
18 19 20 21 22 23 24 25

function getVSCodeBaseFolder(): string {
	let workingDir = process.cwd();
	if (isWindows) {
		workingDir = dirname(dirname(workingDir));
	}
	return workingDir;
}
26

27
export class GridOpenEditorsAction extends Action {
28

29
	static readonly ID = 'workbench.action.gridOpenEditors';
30
	static readonly LABEL = localize('gridOpenEditors', "Open Some Editors");
31 32 33 34 35

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private legacyEditorService: IWorkbenchEditorService,
36
		@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService
37 38 39 40
	) {
		super(id, label);
	}

B
Benjamin Pasero 已提交
41
	run(): TPromise<any> {
42 43
		let workingDir = getVSCodeBaseFolder();

44
		const inputs = [
45 46 47 48 49 50 51
			join(workingDir, 'src/vs/workbench/browser/parts/editor/editor.contribution.ts'),
			join(workingDir, 'src/vs/workbench/browser/parts/editor2/nextEditorActions.ts'),
			join(workingDir, 'src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts'),
			join(workingDir, 'src/vs/workbench/browser/parts/editor2/nextEditorPart.ts'),
			join(workingDir, 'src/vs/workbench/browser/parts/editor2/nextNoTabsTitleControl.ts'),
			join(workingDir, 'src/vs/workbench/browser/parts/editor2/nextTabsTitleControl.ts'),
			join(workingDir, 'src/vs/workbench/browser/parts/editor2/nextTitleControl.ts')
52 53
		].map(input => {
			return this.legacyEditorService.createInput({ resource: URI.file(input) }) as EditorInput;
54
		});
55

B
Benjamin Pasero 已提交
56 57 58 59 60
		const firstGroup = this.nextEditorGroupsService.activeGroup;
		firstGroup.openEditor(inputs[0], { pinned: true });
		firstGroup.openEditor(inputs[1], { inactive: true, pinned: true });
		firstGroup.openEditor(inputs[2], { inactive: true, pinned: true });

61
		const secondGroup = this.nextEditorGroupsService.addGroup(firstGroup, GroupDirection.DOWN);
B
Benjamin Pasero 已提交
62 63 64
		secondGroup.openEditor(inputs[3], { pinned: true, preserveFocus: true });
		secondGroup.openEditor(inputs[4], { inactive: true, pinned: true });

65
		const thirdGroup = this.nextEditorGroupsService.addGroup(secondGroup, GroupDirection.RIGHT);
B
Benjamin Pasero 已提交
66 67 68
		thirdGroup.openEditor(inputs[5], { pinned: true, preserveFocus: true });
		thirdGroup.openEditor(inputs[6], { inactive: true, pinned: true });

69
		this.nextEditorGroupsService.addGroup(firstGroup, GroupDirection.RIGHT); // play with empty group
70

71 72 73 74 75 76 77
		return TPromise.as(void 0);
	}
}

export class GridOpenOneEditorAction extends Action {

	static readonly ID = 'workbench.action.gridOpenOneEditor';
78
	static readonly LABEL = localize('gridOpenOneEditor', "Open One Editor");
79 80 81 82 83 84 85 86 87 88 89

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private legacyEditorService: IWorkbenchEditorService,
		@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService
	) {
		super(id, label);
	}

	run(): TPromise<any> {
90
		const path = join(getVSCodeBaseFolder(), 'src/vs/workbench/browser/parts/editor/editor.contribution.ts');
91 92
		this.nextEditorGroupsService.activeGroup.openEditor(this.legacyEditorService.createInput({ resource: URI.file(path) }) as EditorInput);

93 94 95 96
		return TPromise.as(void 0);
	}
}

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
export class ResetGridEditorAction extends Action {

	static readonly ID = 'workbench.action.resetGrid';
	static readonly LABEL = localize('gridReset', "Reset");

	constructor(
		id: string,
		label: string,
		@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService
	) {
		super(id, label);
	}

	async run(): TPromise<any> {
		while (true) {
			let group = this.nextEditorGroupsService.activeGroup;
			if (this.nextEditorGroupsService.count === 1 && group.count === 0) {
				break;
			}

			await TPromise.join(group.editors.map(editor => group.closeEditor(editor)));
			this.nextEditorGroupsService.removeGroup(group);
		}

		return TPromise.as(void 0);
	}
}

125 126 127
export class GridOpenOneEditorSideBySideAction extends Action {

	static readonly ID = 'workbench.action.gridOpenOneEditorSideBySide';
128
	static readonly LABEL = localize('gridOpenOneEditorSideBySide', "Open One Editor Side by Side");
129 130 131 132 133 134 135 136 137 138 139 140

	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private legacyEditorService: IWorkbenchEditorService,
		@INextEditorService private editorService: INextEditorService
	) {
		super(id, label);
	}

	run(): TPromise<any> {
		const path = join(getVSCodeBaseFolder(), 'src/vs/workbench/browser/parts/editor/editor.contribution.ts');
141
		this.editorService.openEditor(this.legacyEditorService.createInput({ resource: URI.file(path) }) as EditorInput, null, SIDE_GROUP);
142

143 144 145 146 147 148 149
		return TPromise.as(void 0);
	}
}

export class GridCloseActiveEditorAction extends Action {

	static readonly ID = 'workbench.action.gridCloseActiveEditor';
150
	static readonly LABEL = localize('gridCloseActiveEditor', "Close Active Editor");
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

	constructor(
		id: string,
		label: string,
		@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService
	) {
		super(id, label);
	}

	run(): TPromise<any> {
		this.nextEditorGroupsService.activeGroup.closeEditor();

		return TPromise.as(void 0);
	}
}

export class GridRemoveActiveGroupAction extends Action {

	static readonly ID = 'workbench.action.gridRemoveActiveGroup';
170
	static readonly LABEL = localize('gridRemoveActiveGroup', "Remove Active Group");
171 172 173 174 175 176 177 178 179 180 181 182

	constructor(
		id: string,
		label: string,
		@INextEditorGroupsService private nextEditorGroupsService: INextEditorGroupsService
	) {
		super(id, label);
	}

	run(): TPromise<any> {
		this.nextEditorGroupsService.removeGroup(this.nextEditorGroupsService.activeGroup);

183
		return TPromise.as(void 0);
184 185
	}
}