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

'use strict';

J
Johannes Rieken 已提交
8 9
import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions';
E
Erich Gamma 已提交
10 11 12 13 14 15
import nls = require('vs/nls');
import paths = require('vs/base/common/paths');
import labels = require('vs/base/common/labels');
import platform = require('vs/base/common/platform');
import uri from 'vs/base/common/uri';
import severity from 'vs/base/common/severity';
J
Johannes Rieken 已提交
16 17 18 19
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { asFileEditorInput } from 'vs/workbench/common/editor';
import { IMessageService } from 'vs/platform/message/common/message';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
J
Joao Moreno 已提交
20
import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
21 22
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import { clipboard } from 'electron';
E
Erich Gamma 已提交
23 24 25 26

export class RevealInOSAction extends Action {
	private resource: uri;

B
Benjamin Pasero 已提交
27 28
	constructor(
		resource: uri,
J
Joao Moreno 已提交
29
		@IWindowIPCService private windowService: IWindowIPCService
B
Benjamin Pasero 已提交
30
	) {
E
Erich Gamma 已提交
31 32 33 34 35 36 37
		super('workbench.action.files.revealInWindows', platform.isWindows ? nls.localize('revealInWindows', "Reveal in Explorer") : (platform.isMacintosh ? nls.localize('revealInMac', "Reveal in Finder") : nls.localize('openContainer', "Open Containing Folder")));

		this.resource = resource;

		this.order = 45;
	}

A
Alex Dima 已提交
38
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
39
		this.windowService.getWindow().showItemInFolder(paths.normalize(this.resource.fsPath, true));
E
Erich Gamma 已提交
40

A
Alex Dima 已提交
41
		return TPromise.as(true);
E
Erich Gamma 已提交
42 43 44 45 46 47 48 49 50
	}
}

export class GlobalRevealInOSAction extends Action {

	public static ID = 'workbench.action.files.revealActiveFileInWindows';
	public static LABEL = platform.isWindows ? nls.localize('revealActiveFileInWindows', "Reveal Active File in Windows Explorer") : (platform.isMacintosh ? nls.localize('revealActiveFileInMac', "Reveal Active File in Finder") : nls.localize('openActiveFileContainer', "Open Containing Folder of Active File"));

	constructor(
51
		id: string,
E
Erich Gamma 已提交
52 53
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
J
Joao Moreno 已提交
54
		@IWindowIPCService private windowService: IWindowIPCService,
E
Erich Gamma 已提交
55 56 57 58 59
		@IMessageService private messageService: IMessageService
	) {
		super(id, label);
	}

A
Alex Dima 已提交
60
	public run(): TPromise<any> {
61
		const fileInput = asFileEditorInput(this.editorService.getActiveEditorInput(), true);
E
Erich Gamma 已提交
62
		if (fileInput) {
B
Benjamin Pasero 已提交
63
			this.windowService.getWindow().showItemInFolder(paths.normalize(fileInput.getResource().fsPath, true));
E
Erich Gamma 已提交
64 65 66 67
		} else {
			this.messageService.show(severity.Info, nls.localize('openFileToReveal', "Open a file first to reveal"));
		}

A
Alex Dima 已提交
68
		return TPromise.as(true);
E
Erich Gamma 已提交
69 70 71 72 73 74
	}
}

export class CopyPathAction extends Action {
	private resource: uri;

75
	constructor(resource: uri) {
E
Erich Gamma 已提交
76 77 78 79 80 81 82
		super('workbench.action.files.copyPath', nls.localize('copyPath', "Copy Path"));

		this.resource = resource;

		this.order = 140;
	}

A
Alex Dima 已提交
83
	public run(): TPromise<any> {
B
Benjamin Pasero 已提交
84
		clipboard.writeText(labels.getPathLabel(this.resource));
E
Erich Gamma 已提交
85

A
Alex Dima 已提交
86
		return TPromise.as(true);
E
Erich Gamma 已提交
87 88 89 90 91 92 93 94 95
	}
}

export class GlobalCopyPathAction extends Action {

	public static ID = 'workbench.action.files.copyPathOfActiveFile';
	public static LABEL = nls.localize('copyPathOfActive', "Copy Path of Active File");

	constructor(
96
		id: string,
E
Erich Gamma 已提交
97 98
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
99
		@IEditorGroupService private editorGroupService: IEditorGroupService,
E
Erich Gamma 已提交
100 101 102 103 104
		@IMessageService private messageService: IMessageService
	) {
		super(id, label);
	}

A
Alex Dima 已提交
105
	public run(): TPromise<any> {
106
		const activeEditor = this.editorService.getActiveEditor();
107
		const fileInput = activeEditor ? asFileEditorInput(activeEditor.input, true) : void 0;
E
Erich Gamma 已提交
108
		if (fileInput) {
B
Benjamin Pasero 已提交
109
			clipboard.writeText(labels.getPathLabel(fileInput.getResource()));
110
			this.editorGroupService.focusGroup(activeEditor.position); // focus back to active editor group
E
Erich Gamma 已提交
111 112 113 114
		} else {
			this.messageService.show(severity.Info, nls.localize('openFileToCopy', "Open a file first to copy its path"));
		}

A
Alex Dima 已提交
115
		return TPromise.as(true);
E
Erich Gamma 已提交
116 117 118
	}
}

119
export class OpenFileAction extends Action {
E
Erich Gamma 已提交
120

121 122
	static ID = 'workbench.action.files.openFile';
	static LABEL = nls.localize('openFile', "Open File...");
123

124 125 126 127 128 129
	constructor(
		id: string,
		label: string,
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IWindowService private windowService: IWindowService
	) {
130 131 132
		super(id, label);
	}

133
	run(): TPromise<any> {
134 135 136 137
		const fileInput = asFileEditorInput(this.editorService.getActiveEditorInput(), true);

		// Handle in browser process
		if (fileInput) {
138
			return this.windowService.openFilePicker(false, paths.dirname(fileInput.getResource().fsPath));
139 140
		}

141
		return this.windowService.openFilePicker();
E
Erich Gamma 已提交
142 143 144
	}
}

145
export class OpenFolderAction extends Action {
E
Erich Gamma 已提交
146

147 148
	static ID = 'workbench.action.files.openFolder';
	static LABEL = nls.localize('openFolder', "Open Folder...");
149

150 151 152 153 154 155 156 157 158 159
	constructor(
		id: string,
		label: string,
		@IWindowService private windowService: IWindowService
	) {
		super(id, label);
	}

	run(): TPromise<any> {
		return this.windowService.openFolderPicker();
E
Erich Gamma 已提交
160 161 162
	}
}

163 164 165 166
export class OpenFileFolderAction extends Action {

	static ID = 'workbench.action.files.openFileFolder';
	static LABEL = nls.localize('openFileFolder', "Open...");
E
Erich Gamma 已提交
167

168 169 170 171 172 173 174
	constructor(
		id: string,
		label: string,
		@IWindowService private windowService: IWindowService
	) {
		super(id, label);
	}
175

176 177
	run(): TPromise<any> {
		return this.windowService.openFileFolderPicker();
E
Erich Gamma 已提交
178 179 180 181 182 183 184 185 186
	}
}

export class ShowOpenedFileInNewWindow extends Action {

	public static ID = 'workbench.action.files.showOpenedFileInNewWindow';
	public static LABEL = nls.localize('openFileInNewWindow', "Open Active File in New Window");

	constructor(
187
		id: string,
E
Erich Gamma 已提交
188
		label: string,
189
		@IWindowsService private windowsService: IWindowsService,
E
Erich Gamma 已提交
190 191 192 193 194 195
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
		@IMessageService private messageService: IMessageService
	) {
		super(id, label);
	}

A
Alex Dima 已提交
196
	public run(): TPromise<any> {
197
		const fileInput = asFileEditorInput(this.editorService.getActiveEditorInput(), true);
E
Erich Gamma 已提交
198
		if (fileInput) {
199
			this.windowsService.windowOpen([fileInput.getResource().fsPath], true);
E
Erich Gamma 已提交
200 201 202 203
		} else {
			this.messageService.show(severity.Info, nls.localize('openFileToShow', "Open a file first to open in new window"));
		}

A
Alex Dima 已提交
204
		return TPromise.as(true);
E
Erich Gamma 已提交
205 206
	}
}