workbench.ts 2.8 KB
Newer Older
S
Sandeep Somavarapu 已提交
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.
 *--------------------------------------------------------------------------------------------*/

import { Explorer } from '../explorer/explorer';
import { ActivityBar } from '../activitybar/activityBar';
import { QuickOpen } from '../quickopen/quickopen';
import { Extensions } from '../extensions/extensions';
import { Search } from '../search/search';
import { Editor } from '../editor/editor';
J
Joao 已提交
12
import { SCM } from '../git/scm';
I
isidor 已提交
13
import { Debug } from '../debug/debug';
S
Sandeep Somavarapu 已提交
14 15 16 17
import { StatusBar } from '../statusbar/statusbar';
import { Problems } from '../problems/problems';
import { SettingsEditor } from '../preferences/settings';
import { KeybindingsEditor } from '../preferences/keybindings';
18
import { Terminal } from '../terminal/terminal';
J
Joao Moreno 已提交
19
import { API } from '../../api';
J
green!  
Joao Moreno 已提交
20
import { Editors } from '../editor/editors';
S
Sandeep Somavarapu 已提交
21

J
green!  
Joao Moreno 已提交
22 23 24 25 26
export interface Commands {
	runCommand(command: string): Promise<any>;
}

export class Workbench implements Commands {
S
Sandeep Somavarapu 已提交
27

J
green!  
Joao Moreno 已提交
28 29
	readonly quickopen: QuickOpen;
	readonly editors: Editors;
S
Sandeep Somavarapu 已提交
30 31 32 33 34
	readonly explorer: Explorer;
	readonly activitybar: ActivityBar;
	readonly search: Search;
	readonly extensions: Extensions;
	readonly editor: Editor;
J
Joao 已提交
35
	readonly scm: SCM;
I
isidor 已提交
36
	readonly debug: Debug;
S
Sandeep Somavarapu 已提交
37 38 39 40
	readonly statusbar: StatusBar;
	readonly problems: Problems;
	readonly settingsEditor: SettingsEditor;
	readonly keybindingsEditor: KeybindingsEditor;
41
	readonly terminal: Terminal;
S
Sandeep Somavarapu 已提交
42

J
green!  
Joao Moreno 已提交
43 44 45 46
	constructor(private api: API, private keybindings: any[], userDataPath: string) {
		this.editors = new Editors(api, this);
		this.quickopen = new QuickOpen(api, this, this.editors);
		this.explorer = new Explorer(api, this.quickopen, this.editors);
J
Joao Moreno 已提交
47
		this.activitybar = new ActivityBar(api);
J
green!  
Joao Moreno 已提交
48 49 50 51 52
		this.search = new Search(api, this);
		this.extensions = new Extensions(api, this);
		this.editor = new Editor(api, this);
		this.scm = new SCM(api, this);
		this.debug = new Debug(api, this, this.editors, this.editor);
J
Joao Moreno 已提交
53
		this.statusbar = new StatusBar(api);
J
green!  
Joao Moreno 已提交
54 55 56 57
		this.problems = new Problems(api, this);
		this.settingsEditor = new SettingsEditor(api, userDataPath, this, this.editors, this.editor);
		this.keybindingsEditor = new KeybindingsEditor(api, this);
		this.terminal = new Terminal(api, this);
S
Sandeep Somavarapu 已提交
58
	}
J
Joao Moreno 已提交
59 60 61 62 63

	/**
	 * Retrieves the command from keybindings file and executes it with WebdriverIO client API
	 * @param command command (e.g. 'workbench.action.files.newUntitledFile')
	 */
J
green!  
Joao Moreno 已提交
64
	async runCommand(command: string): Promise<any> {
J
Joao Moreno 已提交
65 66
		const binding = this.keybindings.find(x => x['command'] === command);
		if (!binding) {
J
green!  
Joao Moreno 已提交
67 68
			await this.quickopen.runCommand(command);
			return;
J
Joao Moreno 已提交
69 70
		}

J
Joao Moreno 已提交
71
		return this.api.dispatchKeybinding(binding.key);
J
Joao Moreno 已提交
72
	}
S
Sandeep Somavarapu 已提交
73
}
J
green!  
Joao Moreno 已提交
74