@theia/workspace 1.45.1 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/lib/browser/canonical-uri-service.d.ts +11 -11
- package/lib/browser/canonical-uri-service.js +59 -59
- package/lib/browser/diff-service.d.ts +10 -10
- package/lib/browser/diff-service.js +85 -85
- package/lib/browser/index.d.ts +7 -7
- package/lib/browser/index.js +34 -34
- package/lib/browser/quick-open-workspace.d.ts +25 -25
- package/lib/browser/quick-open-workspace.js +137 -137
- package/lib/browser/untitled-workspace-exit-dialog.d.ts +19 -19
- package/lib/browser/untitled-workspace-exit-dialog.js +74 -74
- package/lib/browser/workspace-breadcrumbs-contribution.d.ts +10 -10
- package/lib/browser/workspace-breadcrumbs-contribution.js +66 -66
- package/lib/browser/workspace-commands.d.ts +117 -117
- package/lib/browser/workspace-commands.js +601 -601
- package/lib/browser/workspace-commands.spec.d.ts +1 -1
- package/lib/browser/workspace-commands.spec.js +127 -127
- package/lib/browser/workspace-compare-handler.d.ts +26 -26
- package/lib/browser/workspace-compare-handler.js +66 -66
- package/lib/browser/workspace-delete-handler.d.ts +75 -75
- package/lib/browser/workspace-delete-handler.js +214 -214
- package/lib/browser/workspace-duplicate-handler.d.ts +30 -30
- package/lib/browser/workspace-duplicate-handler.js +86 -86
- package/lib/browser/workspace-frontend-contribution.d.ts +110 -110
- package/lib/browser/workspace-frontend-contribution.js +546 -546
- package/lib/browser/workspace-frontend-contribution.js.map +1 -1
- package/lib/browser/workspace-frontend-module.d.ts +3 -3
- package/lib/browser/workspace-frontend-module.js +91 -91
- package/lib/browser/workspace-input-dialog.d.ts +19 -19
- package/lib/browser/workspace-input-dialog.js +74 -74
- package/lib/browser/workspace-preferences.d.ts +11 -11
- package/lib/browser/workspace-preferences.js +46 -46
- package/lib/browser/workspace-schema-updater.d.ts +34 -34
- package/lib/browser/workspace-schema-updater.js +153 -153
- package/lib/browser/workspace-service.d.ts +184 -184
- package/lib/browser/workspace-service.js +739 -739
- package/lib/browser/workspace-storage-service.d.ts +15 -15
- package/lib/browser/workspace-storage-service.js +80 -80
- package/lib/browser/workspace-trust-preferences.d.ts +21 -21
- package/lib/browser/workspace-trust-preferences.js +65 -65
- package/lib/browser/workspace-trust-service.d.ts +27 -27
- package/lib/browser/workspace-trust-service.js +152 -152
- package/lib/browser/workspace-uri-contribution.d.ts +20 -20
- package/lib/browser/workspace-uri-contribution.js +113 -113
- package/lib/browser/workspace-uri-contribution.spec.d.ts +1 -1
- package/lib/browser/workspace-uri-contribution.spec.js +169 -169
- package/lib/browser/workspace-user-working-directory-provider.d.ts +12 -12
- package/lib/browser/workspace-user-working-directory-provider.js +62 -62
- package/lib/browser/workspace-utils.d.ts +15 -15
- package/lib/browser/workspace-utils.js +54 -54
- package/lib/browser/workspace-variable-contribution.d.ts +23 -23
- package/lib/browser/workspace-variable-contribution.js +237 -237
- package/lib/browser/workspace-window-title-updater.d.ts +7 -7
- package/lib/browser/workspace-window-title-updater.js +57 -57
- package/lib/browser-only/browser-only-workspace-server.d.ts +13 -0
- package/lib/browser-only/browser-only-workspace-server.d.ts.map +1 -0
- package/lib/browser-only/browser-only-workspace-server.js +81 -0
- package/lib/browser-only/browser-only-workspace-server.js.map +1 -0
- package/lib/browser-only/workspace-frontend-only-module.d.ts +4 -0
- package/lib/browser-only/workspace-frontend-only-module.d.ts.map +1 -0
- package/lib/browser-only/workspace-frontend-only-module.js +30 -0
- package/lib/browser-only/workspace-frontend-only-module.js.map +1 -0
- package/lib/common/index.d.ts +3 -3
- package/lib/common/index.js +30 -30
- package/lib/common/test/mock-workspace-server.d.ts +7 -7
- package/lib/common/test/mock-workspace-server.js +35 -35
- package/lib/common/untitled-workspace-service.d.ts +8 -8
- package/lib/common/untitled-workspace-service.js +60 -60
- package/lib/common/workspace-file-service.d.ts +26 -26
- package/lib/common/workspace-file-service.js +71 -71
- package/lib/common/workspace-protocol.d.ts +26 -26
- package/lib/common/workspace-protocol.js +23 -23
- package/lib/node/default-workspace-server.d.ts +65 -65
- package/lib/node/default-workspace-server.js +248 -248
- package/lib/node/default-workspace-server.spec.d.ts +1 -1
- package/lib/node/default-workspace-server.spec.js +85 -85
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +29 -29
- package/lib/node/workspace-backend-module.d.ts +3 -3
- package/lib/node/workspace-backend-module.js +33 -33
- package/package.json +9 -6
- package/src/browser/canonical-uri-service.ts +57 -57
- package/src/browser/diff-service.ts +62 -62
- package/src/browser/index.ts +23 -23
- package/src/browser/quick-open-workspace.ts +112 -112
- package/src/browser/untitled-workspace-exit-dialog.ts +70 -70
- package/src/browser/workspace-breadcrumbs-contribution.ts +56 -56
- package/src/browser/workspace-commands.spec.ts +153 -153
- package/src/browser/workspace-commands.ts +588 -588
- package/src/browser/workspace-compare-handler.ts +56 -56
- package/src/browser/workspace-delete-handler.ts +212 -212
- package/src/browser/workspace-duplicate-handler.ts +75 -75
- package/src/browser/workspace-frontend-contribution.ts +537 -537
- package/src/browser/workspace-frontend-module.ts +118 -118
- package/src/browser/workspace-input-dialog.ts +61 -61
- package/src/browser/workspace-preferences.ts +58 -58
- package/src/browser/workspace-schema-updater.ts +150 -150
- package/src/browser/workspace-service.ts +780 -780
- package/src/browser/workspace-storage-service.ts +67 -67
- package/src/browser/workspace-trust-preferences.ts +76 -76
- package/src/browser/workspace-trust-service.ts +147 -147
- package/src/browser/workspace-uri-contribution.spec.ts +191 -191
- package/src/browser/workspace-uri-contribution.ts +97 -97
- package/src/browser/workspace-user-working-directory-provider.ts +49 -49
- package/src/browser/workspace-utils.ts +45 -45
- package/src/browser/workspace-variable-contribution.ts +222 -222
- package/src/browser/workspace-window-title-updater.ts +45 -45
- package/src/browser-only/browser-only-workspace-server.ts +69 -0
- package/src/browser-only/workspace-frontend-only-module.ts +28 -0
- package/src/common/index.ts +19 -19
- package/src/common/test/mock-workspace-server.ts +29 -29
- package/src/common/untitled-workspace-service.ts +50 -50
- package/src/common/workspace-file-service.ts +72 -72
- package/src/common/workspace-protocol.ts +47 -47
- package/src/node/default-workspace-server.spec.ts +100 -100
- package/src/node/default-workspace-server.ts +244 -244
- package/src/node/index.ts +18 -18
- package/src/node/workspace-backend-module.ts +38 -38
|
@@ -1,602 +1,602 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2017 TypeFox and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.WorkspaceRootUriAwareCommandHandler = exports.WorkspaceCommandContribution = exports.EditMenuContribution = exports.FileMenuContribution = exports.WorkspaceCommands = void 0;
|
|
28
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
29
|
-
const selection_service_1 = require("@theia/core/lib/common/selection-service");
|
|
30
|
-
const command_1 = require("@theia/core/lib/common/command");
|
|
31
|
-
const common_frontend_contribution_1 = require("@theia/core/lib/browser/common-frontend-contribution");
|
|
32
|
-
const browser_1 = require("@theia/filesystem/lib/browser");
|
|
33
|
-
const dialogs_1 = require("@theia/core/lib/browser/dialogs");
|
|
34
|
-
const browser_2 = require("@theia/core/lib/browser");
|
|
35
|
-
const uri_command_handler_1 = require("@theia/core/lib/common/uri-command-handler");
|
|
36
|
-
const workspace_service_1 = require("./workspace-service");
|
|
37
|
-
const message_service_1 = require("@theia/core/lib/common/message-service");
|
|
38
|
-
const workspace_preferences_1 = require("./workspace-preferences");
|
|
39
|
-
const workspace_delete_handler_1 = require("./workspace-delete-handler");
|
|
40
|
-
const workspace_duplicate_handler_1 = require("./workspace-duplicate-handler");
|
|
41
|
-
const common_1 = require("@theia/filesystem/lib/common");
|
|
42
|
-
const workspace_compare_handler_1 = require("./workspace-compare-handler");
|
|
43
|
-
const file_download_command_contribution_1 = require("@theia/filesystem/lib/browser/download/file-download-command-contribution");
|
|
44
|
-
const filesystem_frontend_contribution_1 = require("@theia/filesystem/lib/browser/filesystem-frontend-contribution");
|
|
45
|
-
const workspace_input_dialog_1 = require("./workspace-input-dialog");
|
|
46
|
-
const common_2 = require("@theia/core/lib/common");
|
|
47
|
-
const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
|
|
48
|
-
const nls_1 = require("@theia/core/lib/common/nls");
|
|
49
|
-
const clipboard_service_1 = require("@theia/core/lib/browser/clipboard-service");
|
|
50
|
-
const validFilename = require('valid-filename');
|
|
51
|
-
var WorkspaceCommands;
|
|
52
|
-
(function (WorkspaceCommands) {
|
|
53
|
-
const WORKSPACE_CATEGORY = 'Workspaces';
|
|
54
|
-
const FILE_CATEGORY = browser_2.CommonCommands.FILE_CATEGORY;
|
|
55
|
-
// On Linux and Windows, both files and folders cannot be opened at the same time in electron.
|
|
56
|
-
// `OPEN_FILE` and `OPEN_FOLDER` must be available only on Linux and Windows in electron.
|
|
57
|
-
// `OPEN` must *not* be available on Windows and Linux in electron.
|
|
58
|
-
// VS Code does the same. See: https://github.com/eclipse-theia/theia/pull/3202#issuecomment-430585357
|
|
59
|
-
WorkspaceCommands.OPEN = {
|
|
60
|
-
...command_1.Command.toDefaultLocalizedCommand({
|
|
61
|
-
id: 'workspace:open',
|
|
62
|
-
category: browser_2.CommonCommands.FILE_CATEGORY,
|
|
63
|
-
label: 'Open...'
|
|
64
|
-
}),
|
|
65
|
-
dialogLabel: nls_1.nls.localizeByDefault('Open')
|
|
66
|
-
};
|
|
67
|
-
// No `label`. Otherwise, it shows up in the `Command Palette`.
|
|
68
|
-
WorkspaceCommands.OPEN_FILE = {
|
|
69
|
-
id: 'workspace:openFile',
|
|
70
|
-
originalCategory: FILE_CATEGORY,
|
|
71
|
-
category: nls_1.nls.localizeByDefault(browser_2.CommonCommands.FILE_CATEGORY),
|
|
72
|
-
dialogLabel: nls_1.nls.localizeByDefault('Open File')
|
|
73
|
-
};
|
|
74
|
-
WorkspaceCommands.OPEN_FOLDER = {
|
|
75
|
-
id: 'workspace:openFolder',
|
|
76
|
-
dialogLabel: nls_1.nls.localizeByDefault('Open Folder') // No `label`. Otherwise, it shows up in the `Command Palette`.
|
|
77
|
-
};
|
|
78
|
-
WorkspaceCommands.OPEN_WORKSPACE = {
|
|
79
|
-
...command_1.Command.toDefaultLocalizedCommand({
|
|
80
|
-
id: 'workspace:openWorkspace',
|
|
81
|
-
category: browser_2.CommonCommands.FILE_CATEGORY,
|
|
82
|
-
label: 'Open Workspace from File...',
|
|
83
|
-
}),
|
|
84
|
-
dialogLabel: nls_1.nls.localizeByDefault('Open Workspace from File')
|
|
85
|
-
};
|
|
86
|
-
WorkspaceCommands.OPEN_RECENT_WORKSPACE = command_1.Command.toLocalizedCommand({
|
|
87
|
-
id: 'workspace:openRecent',
|
|
88
|
-
category: FILE_CATEGORY,
|
|
89
|
-
label: 'Open Recent Workspace...'
|
|
90
|
-
}, 'theia/workspace/openRecentWorkspace', browser_2.CommonCommands.FILE_CATEGORY_KEY);
|
|
91
|
-
WorkspaceCommands.CLOSE = command_1.Command.toDefaultLocalizedCommand({
|
|
92
|
-
id: 'workspace:close',
|
|
93
|
-
category: WORKSPACE_CATEGORY,
|
|
94
|
-
label: 'Close Workspace'
|
|
95
|
-
});
|
|
96
|
-
WorkspaceCommands.NEW_FILE = command_1.Command.toDefaultLocalizedCommand({
|
|
97
|
-
id: 'file.newFile',
|
|
98
|
-
category: FILE_CATEGORY,
|
|
99
|
-
label: 'New File...'
|
|
100
|
-
});
|
|
101
|
-
WorkspaceCommands.NEW_FOLDER = command_1.Command.toDefaultLocalizedCommand({
|
|
102
|
-
id: 'file.newFolder',
|
|
103
|
-
category: FILE_CATEGORY,
|
|
104
|
-
label: 'New Folder...'
|
|
105
|
-
});
|
|
106
|
-
WorkspaceCommands.FILE_OPEN_WITH = (opener) => ({
|
|
107
|
-
id: `file.openWith.${opener.id}`
|
|
108
|
-
});
|
|
109
|
-
WorkspaceCommands.FILE_RENAME = command_1.Command.toDefaultLocalizedCommand({
|
|
110
|
-
id: 'file.rename',
|
|
111
|
-
category: FILE_CATEGORY,
|
|
112
|
-
label: 'Rename'
|
|
113
|
-
});
|
|
114
|
-
WorkspaceCommands.FILE_DELETE = command_1.Command.toDefaultLocalizedCommand({
|
|
115
|
-
id: 'file.delete',
|
|
116
|
-
category: FILE_CATEGORY,
|
|
117
|
-
label: 'Delete'
|
|
118
|
-
});
|
|
119
|
-
WorkspaceCommands.FILE_DUPLICATE = command_1.Command.toLocalizedCommand({
|
|
120
|
-
id: 'file.duplicate',
|
|
121
|
-
category: FILE_CATEGORY,
|
|
122
|
-
label: 'Duplicate'
|
|
123
|
-
}, 'theia/workspace/duplicate', browser_2.CommonCommands.FILE_CATEGORY_KEY);
|
|
124
|
-
WorkspaceCommands.FILE_COMPARE = command_1.Command.toLocalizedCommand({
|
|
125
|
-
id: 'file.compare',
|
|
126
|
-
category: FILE_CATEGORY,
|
|
127
|
-
label: 'Compare with Each Other'
|
|
128
|
-
}, 'theia/workspace/compareWithEachOther', browser_2.CommonCommands.FILE_CATEGORY_KEY);
|
|
129
|
-
WorkspaceCommands.ADD_FOLDER = command_1.Command.toDefaultLocalizedCommand({
|
|
130
|
-
id: 'workspace:addFolder',
|
|
131
|
-
category: WORKSPACE_CATEGORY,
|
|
132
|
-
label: 'Add Folder to Workspace...'
|
|
133
|
-
});
|
|
134
|
-
WorkspaceCommands.REMOVE_FOLDER = command_1.Command.toDefaultLocalizedCommand({
|
|
135
|
-
id: 'workspace:removeFolder',
|
|
136
|
-
category: WORKSPACE_CATEGORY,
|
|
137
|
-
label: 'Remove Folder from Workspace'
|
|
138
|
-
});
|
|
139
|
-
WorkspaceCommands.SAVE_WORKSPACE_AS = command_1.Command.toDefaultLocalizedCommand({
|
|
140
|
-
id: 'workspace:saveAs',
|
|
141
|
-
category: WORKSPACE_CATEGORY,
|
|
142
|
-
label: 'Save Workspace As...'
|
|
143
|
-
});
|
|
144
|
-
WorkspaceCommands.OPEN_WORKSPACE_FILE = command_1.Command.toDefaultLocalizedCommand({
|
|
145
|
-
id: 'workspace:openConfigFile',
|
|
146
|
-
category: WORKSPACE_CATEGORY,
|
|
147
|
-
label: 'Open Workspace Configuration File'
|
|
148
|
-
});
|
|
149
|
-
/** @deprecated @since 1.24.0 Use `CommonCommands.SAVE_AS` instead */
|
|
150
|
-
WorkspaceCommands.SAVE_AS = browser_2.CommonCommands.SAVE_AS;
|
|
151
|
-
WorkspaceCommands.COPY_RELATIVE_FILE_PATH = command_1.Command.toDefaultLocalizedCommand({
|
|
152
|
-
id: 'navigator.copyRelativeFilePath',
|
|
153
|
-
label: 'Copy Relative Path'
|
|
154
|
-
});
|
|
155
|
-
})(WorkspaceCommands = exports.WorkspaceCommands || (exports.WorkspaceCommands = {}));
|
|
156
|
-
let FileMenuContribution = class FileMenuContribution {
|
|
157
|
-
registerMenus(registry) {
|
|
158
|
-
registry.registerMenuAction(common_frontend_contribution_1.CommonMenus.FILE_NEW_TEXT, {
|
|
159
|
-
commandId: WorkspaceCommands.NEW_FOLDER.id,
|
|
160
|
-
order: 'b'
|
|
161
|
-
});
|
|
162
|
-
const downloadUploadMenu = [...common_frontend_contribution_1.CommonMenus.FILE, '4_downloadupload'];
|
|
163
|
-
registry.registerMenuAction(downloadUploadMenu, {
|
|
164
|
-
commandId: filesystem_frontend_contribution_1.FileSystemCommands.UPLOAD.id,
|
|
165
|
-
order: 'a'
|
|
166
|
-
});
|
|
167
|
-
registry.registerMenuAction(downloadUploadMenu, {
|
|
168
|
-
commandId: file_download_command_contribution_1.FileDownloadCommands.DOWNLOAD.id,
|
|
169
|
-
order: 'b'
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
FileMenuContribution = __decorate([
|
|
174
|
-
(0, inversify_1.injectable)()
|
|
175
|
-
], FileMenuContribution);
|
|
176
|
-
exports.FileMenuContribution = FileMenuContribution;
|
|
177
|
-
let EditMenuContribution = class EditMenuContribution {
|
|
178
|
-
registerMenus(registry) {
|
|
179
|
-
registry.registerMenuAction(common_frontend_contribution_1.CommonMenus.EDIT_CLIPBOARD, {
|
|
180
|
-
commandId: file_download_command_contribution_1.FileDownloadCommands.COPY_DOWNLOAD_LINK.id,
|
|
181
|
-
order: '9999'
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
EditMenuContribution = __decorate([
|
|
186
|
-
(0, inversify_1.injectable)()
|
|
187
|
-
], EditMenuContribution);
|
|
188
|
-
exports.EditMenuContribution = EditMenuContribution;
|
|
189
|
-
let WorkspaceCommandContribution = class WorkspaceCommandContribution {
|
|
190
|
-
constructor() {
|
|
191
|
-
this.onDidCreateNewFileEmitter = new common_2.Emitter();
|
|
192
|
-
this.onDidCreateNewFolderEmitter = new common_2.Emitter();
|
|
193
|
-
}
|
|
194
|
-
get onDidCreateNewFile() {
|
|
195
|
-
return this.onDidCreateNewFileEmitter.event;
|
|
196
|
-
}
|
|
197
|
-
get onDidCreateNewFolder() {
|
|
198
|
-
return this.onDidCreateNewFolderEmitter.event;
|
|
199
|
-
}
|
|
200
|
-
fireCreateNewFile(uri) {
|
|
201
|
-
this.onDidCreateNewFileEmitter.fire(uri);
|
|
202
|
-
}
|
|
203
|
-
fireCreateNewFolder(uri) {
|
|
204
|
-
this.onDidCreateNewFolderEmitter.fire(uri);
|
|
205
|
-
}
|
|
206
|
-
registerCommands(registry) {
|
|
207
|
-
this.registerOpenWith(registry);
|
|
208
|
-
registry.registerCommand(WorkspaceCommands.NEW_FILE, this.newWorkspaceRootUriAwareCommandHandler({
|
|
209
|
-
execute: uri => this.getDirectory(uri).then(parent => {
|
|
210
|
-
if (parent) {
|
|
211
|
-
const parentUri = parent.resource;
|
|
212
|
-
const { fileName, fileExtension } = this.getDefaultFileConfig();
|
|
213
|
-
const targetUri = parentUri.resolve(fileName + fileExtension);
|
|
214
|
-
const vacantChildUri = common_1.FileSystemUtils.generateUniqueResourceURI(parent, targetUri, false);
|
|
215
|
-
const dialog = new workspace_input_dialog_1.WorkspaceInputDialog({
|
|
216
|
-
title: nls_1.nls.localizeByDefault('New File...'),
|
|
217
|
-
maxWidth: 400,
|
|
218
|
-
parentUri: parentUri,
|
|
219
|
-
initialValue: vacantChildUri.path.base,
|
|
220
|
-
placeholder: nls_1.nls.localize('theia/workspace/newFilePlaceholder', 'File Name'),
|
|
221
|
-
validate: name => this.validateFileName(name, parent, true)
|
|
222
|
-
}, this.labelProvider);
|
|
223
|
-
dialog.open().then(async (name) => {
|
|
224
|
-
if (name) {
|
|
225
|
-
const fileUri = parentUri.resolve(name);
|
|
226
|
-
await this.fileService.create(fileUri);
|
|
227
|
-
this.fireCreateNewFile({ parent: parentUri, uri: fileUri });
|
|
228
|
-
(0, browser_2.open)(this.openerService, fileUri);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
})
|
|
233
|
-
}));
|
|
234
|
-
registry.registerCommand(WorkspaceCommands.NEW_FOLDER, this.newWorkspaceRootUriAwareCommandHandler({
|
|
235
|
-
execute: uri => this.getDirectory(uri).then(parent => {
|
|
236
|
-
if (parent) {
|
|
237
|
-
const parentUri = parent.resource;
|
|
238
|
-
const targetUri = parentUri.resolve('Untitled');
|
|
239
|
-
const vacantChildUri = common_1.FileSystemUtils.generateUniqueResourceURI(parent, targetUri, true);
|
|
240
|
-
const dialog = new workspace_input_dialog_1.WorkspaceInputDialog({
|
|
241
|
-
title: nls_1.nls.localizeByDefault('New Folder...'),
|
|
242
|
-
maxWidth: 400,
|
|
243
|
-
parentUri: parentUri,
|
|
244
|
-
initialValue: vacantChildUri.path.base,
|
|
245
|
-
placeholder: nls_1.nls.localize('theia/workspace/newFolderPlaceholder', 'Folder Name'),
|
|
246
|
-
validate: name => this.validateFileName(name, parent, true)
|
|
247
|
-
}, this.labelProvider);
|
|
248
|
-
dialog.open().then(async (name) => {
|
|
249
|
-
if (name) {
|
|
250
|
-
const folderUri = parentUri.resolve(name);
|
|
251
|
-
await this.fileService.createFolder(folderUri);
|
|
252
|
-
this.fireCreateNewFile({ parent: parentUri, uri: folderUri });
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
})
|
|
257
|
-
}));
|
|
258
|
-
registry.registerCommand(WorkspaceCommands.FILE_RENAME, this.newMultiUriAwareCommandHandler({
|
|
259
|
-
isEnabled: uris => uris.some(uri => !this.isWorkspaceRoot(uri)) && uris.length === 1,
|
|
260
|
-
isVisible: uris => uris.some(uri => !this.isWorkspaceRoot(uri)) && uris.length === 1,
|
|
261
|
-
execute: async (uris) => {
|
|
262
|
-
const uri = uris[0]; /* Since there is only one item in the array. */
|
|
263
|
-
const parent = await this.getParent(uri);
|
|
264
|
-
if (parent) {
|
|
265
|
-
const oldName = uri.path.base;
|
|
266
|
-
const dialog = new dialogs_1.SingleTextInputDialog({
|
|
267
|
-
title: nls_1.nls.localizeByDefault('Rename'),
|
|
268
|
-
maxWidth: 400,
|
|
269
|
-
initialValue: oldName,
|
|
270
|
-
initialSelectionRange: {
|
|
271
|
-
start: 0,
|
|
272
|
-
end: uri.path.name.length
|
|
273
|
-
},
|
|
274
|
-
validate: async (newName, mode) => {
|
|
275
|
-
if (oldName === newName && mode === 'preview') {
|
|
276
|
-
return false;
|
|
277
|
-
}
|
|
278
|
-
return this.validateFileRename(oldName, newName, parent);
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
const fileName = await dialog.open();
|
|
282
|
-
if (fileName) {
|
|
283
|
-
const oldUri = uri;
|
|
284
|
-
const newUri = uri.parent.resolve(fileName);
|
|
285
|
-
return this.fileService.move(oldUri, newUri);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}));
|
|
290
|
-
registry.registerCommand(WorkspaceCommands.FILE_DUPLICATE, this.newMultiUriAwareCommandHandler(this.duplicateHandler));
|
|
291
|
-
registry.registerCommand(WorkspaceCommands.FILE_DELETE, this.newMultiUriAwareCommandHandler(this.deleteHandler));
|
|
292
|
-
registry.registerCommand(WorkspaceCommands.FILE_COMPARE, this.newMultiUriAwareCommandHandler(this.compareHandler));
|
|
293
|
-
registry.registerCommand(WorkspaceCommands.COPY_RELATIVE_FILE_PATH, uri_command_handler_1.UriAwareCommandHandler.MultiSelect(this.selectionService, {
|
|
294
|
-
isEnabled: uris => !!uris.length,
|
|
295
|
-
isVisible: uris => !!uris.length,
|
|
296
|
-
execute: async (uris) => {
|
|
297
|
-
const lineDelimiter = common_2.EOL;
|
|
298
|
-
const text = uris.map((uri) => {
|
|
299
|
-
var _a;
|
|
300
|
-
const workspaceRoot = this.workspaceService.getWorkspaceRootUri(uri);
|
|
301
|
-
if (workspaceRoot) {
|
|
302
|
-
return (_a = workspaceRoot.relative(uri)) === null || _a === void 0 ? void 0 : _a.fsPath();
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
return uri.path.fsPath();
|
|
306
|
-
}
|
|
307
|
-
}).join(lineDelimiter);
|
|
308
|
-
await this.clipboardService.writeText(text);
|
|
309
|
-
}
|
|
310
|
-
}));
|
|
311
|
-
registry.registerCommand(WorkspaceCommands.ADD_FOLDER, {
|
|
312
|
-
isEnabled: () => this.workspaceService.opened,
|
|
313
|
-
isVisible: () => this.workspaceService.opened,
|
|
314
|
-
execute: async () => {
|
|
315
|
-
const selection = await this.fileDialogService.showOpenDialog({
|
|
316
|
-
title: WorkspaceCommands.ADD_FOLDER.label,
|
|
317
|
-
canSelectFiles: false,
|
|
318
|
-
canSelectFolders: true,
|
|
319
|
-
canSelectMany: true,
|
|
320
|
-
});
|
|
321
|
-
if (!selection) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
const uris = Array.isArray(selection) ? selection : [selection];
|
|
325
|
-
const workspaceSavedBeforeAdding = this.workspaceService.saved;
|
|
326
|
-
await this.addFolderToWorkspace(...uris);
|
|
327
|
-
if (!workspaceSavedBeforeAdding) {
|
|
328
|
-
this.saveWorkspaceWithPrompt(registry);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
registry.registerCommand(WorkspaceCommands.REMOVE_FOLDER, this.newMultiUriAwareCommandHandler({
|
|
333
|
-
execute: uris => this.removeFolderFromWorkspace(uris),
|
|
334
|
-
isEnabled: () => this.workspaceService.isMultiRootWorkspaceOpened,
|
|
335
|
-
isVisible: uris => this.areWorkspaceRoots(uris) && this.workspaceService.saved
|
|
336
|
-
}));
|
|
337
|
-
}
|
|
338
|
-
async registerOpenWith(registry) {
|
|
339
|
-
if (this.openerService.onDidChangeOpeners) {
|
|
340
|
-
this.openerService.onDidChangeOpeners(async (e) => {
|
|
341
|
-
this.openers = await this.openerService.getOpeners();
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
this.openers = await this.openerService.getOpeners();
|
|
345
|
-
for (const opener of this.openers) {
|
|
346
|
-
const openWithCommand = WorkspaceCommands.FILE_OPEN_WITH(opener);
|
|
347
|
-
registry.registerCommand(openWithCommand, this.newUriAwareCommandHandler({
|
|
348
|
-
execute: uri => opener.open(uri),
|
|
349
|
-
isEnabled: uri => opener.canHandle(uri) > 0,
|
|
350
|
-
isVisible: uri => opener.canHandle(uri) > 0 && this.areMultipleOpenHandlersPresent(this.openers, uri)
|
|
351
|
-
}));
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
newUriAwareCommandHandler(handler) {
|
|
355
|
-
return uri_command_handler_1.UriAwareCommandHandler.MonoSelect(this.selectionService, handler);
|
|
356
|
-
}
|
|
357
|
-
newMultiUriAwareCommandHandler(handler) {
|
|
358
|
-
return uri_command_handler_1.UriAwareCommandHandler.MultiSelect(this.selectionService, handler);
|
|
359
|
-
}
|
|
360
|
-
newWorkspaceRootUriAwareCommandHandler(handler) {
|
|
361
|
-
return new WorkspaceRootUriAwareCommandHandler(this.workspaceService, this.selectionService, handler);
|
|
362
|
-
}
|
|
363
|
-
async validateFileRename(oldName, newName, parent) {
|
|
364
|
-
if (common_2.OS.backend.isWindows && parent.resource.resolve(newName).isEqual(parent.resource.resolve(oldName), false)) {
|
|
365
|
-
return '';
|
|
366
|
-
}
|
|
367
|
-
return this.validateFileName(newName, parent, false);
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Returns an error message if the file name is invalid. Otherwise, an empty string.
|
|
371
|
-
*
|
|
372
|
-
* @param name the simple file name of the file to validate.
|
|
373
|
-
* @param parent the parent directory's file stat.
|
|
374
|
-
* @param allowNested allow file or folder creation using recursive path
|
|
375
|
-
*/
|
|
376
|
-
async validateFileName(name, parent, allowNested = false) {
|
|
377
|
-
if (!name) {
|
|
378
|
-
return '';
|
|
379
|
-
}
|
|
380
|
-
// do not allow recursive rename
|
|
381
|
-
if (!allowNested && !validFilename(name)) {
|
|
382
|
-
return nls_1.nls.localizeByDefault('The name **{0}** is not valid as a file or folder name. Please choose a different name.');
|
|
383
|
-
}
|
|
384
|
-
if (name.startsWith('/')) {
|
|
385
|
-
return nls_1.nls.localizeByDefault('A file or folder name cannot start with a slash.');
|
|
386
|
-
}
|
|
387
|
-
else if (name.startsWith(' ') || name.endsWith(' ')) {
|
|
388
|
-
return nls_1.nls.localizeByDefault('Leading or trailing whitespace detected in file or folder name.');
|
|
389
|
-
}
|
|
390
|
-
// check and validate each sub-paths
|
|
391
|
-
if (name.split(/[\\/]/).some(file => !file || !validFilename(file) || /^\s+$/.test(file))) {
|
|
392
|
-
return nls_1.nls.localizeByDefault('\'{0}\' is not a valid file name', this.trimFileName(name));
|
|
393
|
-
}
|
|
394
|
-
const childUri = parent.resource.resolve(name);
|
|
395
|
-
const exists = await this.fileService.exists(childUri);
|
|
396
|
-
if (exists) {
|
|
397
|
-
return nls_1.nls.localizeByDefault('A file or folder **{0}** already exists at this location. Please choose a different name.', this.trimFileName(name));
|
|
398
|
-
}
|
|
399
|
-
return '';
|
|
400
|
-
}
|
|
401
|
-
trimFileName(name) {
|
|
402
|
-
if (name && name.length > 30) {
|
|
403
|
-
return `${name.substring(0, 30)}...`;
|
|
404
|
-
}
|
|
405
|
-
return name;
|
|
406
|
-
}
|
|
407
|
-
async getDirectory(candidate) {
|
|
408
|
-
let stat;
|
|
409
|
-
try {
|
|
410
|
-
stat = await this.fileService.resolve(candidate);
|
|
411
|
-
}
|
|
412
|
-
catch { }
|
|
413
|
-
if (stat && stat.isDirectory) {
|
|
414
|
-
return stat;
|
|
415
|
-
}
|
|
416
|
-
return this.getParent(candidate);
|
|
417
|
-
}
|
|
418
|
-
async getParent(candidate) {
|
|
419
|
-
try {
|
|
420
|
-
return await this.fileService.resolve(candidate.parent);
|
|
421
|
-
}
|
|
422
|
-
catch {
|
|
423
|
-
return undefined;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
async addFolderToWorkspace(...uris) {
|
|
427
|
-
if (uris.length) {
|
|
428
|
-
const foldersToAdd = [];
|
|
429
|
-
try {
|
|
430
|
-
for (const uri of uris) {
|
|
431
|
-
const stat = await this.fileService.resolve(uri);
|
|
432
|
-
if (stat.isDirectory) {
|
|
433
|
-
foldersToAdd.push(uri);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
await this.workspaceService.addRoot(foldersToAdd);
|
|
437
|
-
}
|
|
438
|
-
catch { }
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
areWorkspaceRoots(uris) {
|
|
442
|
-
return this.workspaceService.areWorkspaceRoots(uris);
|
|
443
|
-
}
|
|
444
|
-
isWorkspaceRoot(uri) {
|
|
445
|
-
const rootUris = new Set(this.workspaceService.tryGetRoots().map(root => root.resource.toString()));
|
|
446
|
-
return rootUris.has(uri.toString());
|
|
447
|
-
}
|
|
448
|
-
getDefaultFileConfig() {
|
|
449
|
-
return {
|
|
450
|
-
fileName: 'Untitled',
|
|
451
|
-
fileExtension: '.txt'
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Removes the list of folders from the workspace upon confirmation from the user.
|
|
456
|
-
* @param uris the list of folder uris to remove.
|
|
457
|
-
*/
|
|
458
|
-
async removeFolderFromWorkspace(uris) {
|
|
459
|
-
const roots = new Set(this.workspaceService.tryGetRoots().map(root => root.resource.toString()));
|
|
460
|
-
const toRemove = uris.filter(uri => roots.has(uri.toString()));
|
|
461
|
-
if (toRemove.length > 0) {
|
|
462
|
-
const messageContainer = document.createElement('div');
|
|
463
|
-
if (toRemove.length > 1) {
|
|
464
|
-
messageContainer.textContent = nls_1.nls.localize('theia/workspace/removeFolders', 'Are you sure you want to remove the following folders from the workspace?');
|
|
465
|
-
}
|
|
466
|
-
else {
|
|
467
|
-
messageContainer.textContent = nls_1.nls.localize('theia/workspace/removeFolder', 'Are you sure you want to remove the following folder from the workspace?');
|
|
468
|
-
}
|
|
469
|
-
messageContainer.title = nls_1.nls.localize('theia/workspace/noErasure', 'Note: Nothing will be erased from disk');
|
|
470
|
-
const list = document.createElement('div');
|
|
471
|
-
list.classList.add('theia-dialog-node');
|
|
472
|
-
toRemove.forEach(uri => {
|
|
473
|
-
const listItem = document.createElement('div');
|
|
474
|
-
listItem.classList.add('theia-dialog-node-content');
|
|
475
|
-
const folderIcon = document.createElement('span');
|
|
476
|
-
folderIcon.classList.add('codicon', 'codicon-root-folder', 'theia-dialog-icon');
|
|
477
|
-
listItem.appendChild(folderIcon);
|
|
478
|
-
listItem.title = this.labelProvider.getLongName(uri);
|
|
479
|
-
const listContent = document.createElement('span');
|
|
480
|
-
listContent.classList.add('theia-dialog-node-segment');
|
|
481
|
-
listContent.appendChild(document.createTextNode(this.labelProvider.getName(uri)));
|
|
482
|
-
listItem.appendChild(listContent);
|
|
483
|
-
list.appendChild(listItem);
|
|
484
|
-
});
|
|
485
|
-
messageContainer.appendChild(list);
|
|
486
|
-
const dialog = new dialogs_1.ConfirmDialog({
|
|
487
|
-
title: nls_1.nls.localizeByDefault('Remove Folder from Workspace'),
|
|
488
|
-
msg: messageContainer
|
|
489
|
-
});
|
|
490
|
-
if (await dialog.open()) {
|
|
491
|
-
await this.workspaceService.removeRoots(toRemove);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
async saveWorkspaceWithPrompt(registry) {
|
|
496
|
-
const saveCommand = registry.getCommand(WorkspaceCommands.SAVE_WORKSPACE_AS.id);
|
|
497
|
-
if (saveCommand && await new dialogs_1.ConfirmDialog({
|
|
498
|
-
title: nls_1.nls.localize('theia/workspace/workspaceFolderAddedTitle', 'Folder added to Workspace'),
|
|
499
|
-
msg: nls_1.nls.localize('theia/workspace/workspaceFolderAdded', 'A workspace with multiple roots was created. Do you want to save your workspace configuration as a file?'),
|
|
500
|
-
ok: dialogs_1.Dialog.YES,
|
|
501
|
-
cancel: dialogs_1.Dialog.NO
|
|
502
|
-
}).open()) {
|
|
503
|
-
return registry.executeCommand(saveCommand.id);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
areMultipleOpenHandlersPresent(openers, uri) {
|
|
507
|
-
let count = 0;
|
|
508
|
-
for (const opener of openers) {
|
|
509
|
-
if (opener.canHandle(uri) > 0) {
|
|
510
|
-
count++;
|
|
511
|
-
}
|
|
512
|
-
if (count > 1) {
|
|
513
|
-
return true;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return false;
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
__decorate([
|
|
520
|
-
(0, inversify_1.inject)(browser_2.LabelProvider),
|
|
521
|
-
__metadata("design:type", browser_2.LabelProvider)
|
|
522
|
-
], WorkspaceCommandContribution.prototype, "labelProvider", void 0);
|
|
523
|
-
__decorate([
|
|
524
|
-
(0, inversify_1.inject)(file_service_1.FileService),
|
|
525
|
-
__metadata("design:type", file_service_1.FileService)
|
|
526
|
-
], WorkspaceCommandContribution.prototype, "fileService", void 0);
|
|
527
|
-
__decorate([
|
|
528
|
-
(0, inversify_1.inject)(workspace_service_1.WorkspaceService),
|
|
529
|
-
__metadata("design:type", workspace_service_1.WorkspaceService)
|
|
530
|
-
], WorkspaceCommandContribution.prototype, "workspaceService", void 0);
|
|
531
|
-
__decorate([
|
|
532
|
-
(0, inversify_1.inject)(selection_service_1.SelectionService),
|
|
533
|
-
__metadata("design:type", selection_service_1.SelectionService)
|
|
534
|
-
], WorkspaceCommandContribution.prototype, "selectionService", void 0);
|
|
535
|
-
__decorate([
|
|
536
|
-
(0, inversify_1.inject)(browser_2.OpenerService),
|
|
537
|
-
__metadata("design:type", Object)
|
|
538
|
-
], WorkspaceCommandContribution.prototype, "openerService", void 0);
|
|
539
|
-
__decorate([
|
|
540
|
-
(0, inversify_1.inject)(browser_2.FrontendApplication),
|
|
541
|
-
__metadata("design:type", browser_2.FrontendApplication)
|
|
542
|
-
], WorkspaceCommandContribution.prototype, "app", void 0);
|
|
543
|
-
__decorate([
|
|
544
|
-
(0, inversify_1.inject)(message_service_1.MessageService),
|
|
545
|
-
__metadata("design:type", message_service_1.MessageService)
|
|
546
|
-
], WorkspaceCommandContribution.prototype, "messageService", void 0);
|
|
547
|
-
__decorate([
|
|
548
|
-
(0, inversify_1.inject)(workspace_preferences_1.WorkspacePreferences),
|
|
549
|
-
__metadata("design:type", Object)
|
|
550
|
-
], WorkspaceCommandContribution.prototype, "preferences", void 0);
|
|
551
|
-
__decorate([
|
|
552
|
-
(0, inversify_1.inject)(browser_1.FileDialogService),
|
|
553
|
-
__metadata("design:type", Object)
|
|
554
|
-
], WorkspaceCommandContribution.prototype, "fileDialogService", void 0);
|
|
555
|
-
__decorate([
|
|
556
|
-
(0, inversify_1.inject)(workspace_delete_handler_1.WorkspaceDeleteHandler),
|
|
557
|
-
__metadata("design:type", workspace_delete_handler_1.WorkspaceDeleteHandler)
|
|
558
|
-
], WorkspaceCommandContribution.prototype, "deleteHandler", void 0);
|
|
559
|
-
__decorate([
|
|
560
|
-
(0, inversify_1.inject)(workspace_duplicate_handler_1.WorkspaceDuplicateHandler),
|
|
561
|
-
__metadata("design:type", workspace_duplicate_handler_1.WorkspaceDuplicateHandler)
|
|
562
|
-
], WorkspaceCommandContribution.prototype, "duplicateHandler", void 0);
|
|
563
|
-
__decorate([
|
|
564
|
-
(0, inversify_1.inject)(workspace_compare_handler_1.WorkspaceCompareHandler),
|
|
565
|
-
__metadata("design:type", workspace_compare_handler_1.WorkspaceCompareHandler)
|
|
566
|
-
], WorkspaceCommandContribution.prototype, "compareHandler", void 0);
|
|
567
|
-
__decorate([
|
|
568
|
-
(0, inversify_1.inject)(clipboard_service_1.ClipboardService),
|
|
569
|
-
__metadata("design:type", Object)
|
|
570
|
-
], WorkspaceCommandContribution.prototype, "clipboardService", void 0);
|
|
571
|
-
WorkspaceCommandContribution = __decorate([
|
|
572
|
-
(0, inversify_1.injectable)()
|
|
573
|
-
], WorkspaceCommandContribution);
|
|
574
|
-
exports.WorkspaceCommandContribution = WorkspaceCommandContribution;
|
|
575
|
-
class WorkspaceRootUriAwareCommandHandler extends uri_command_handler_1.UriAwareCommandHandler {
|
|
576
|
-
constructor(workspaceService, selectionService, handler) {
|
|
577
|
-
super(selectionService, handler);
|
|
578
|
-
this.workspaceService = workspaceService;
|
|
579
|
-
}
|
|
580
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
581
|
-
isEnabled(...args) {
|
|
582
|
-
return super.isEnabled(...args) && !!this.workspaceService.tryGetRoots().length;
|
|
583
|
-
}
|
|
584
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
585
|
-
isVisible(...args) {
|
|
586
|
-
return super.isVisible(...args) && !!this.workspaceService.tryGetRoots().length;
|
|
587
|
-
}
|
|
588
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
589
|
-
getUri(...args) {
|
|
590
|
-
const uri = super.getUri(...args);
|
|
591
|
-
// Return the `uri` immediately if the resource exists in any of the workspace roots and is of `file` scheme.
|
|
592
|
-
if (uri && uri.scheme === 'file' && this.workspaceService.getWorkspaceRootUri(uri)) {
|
|
593
|
-
return uri;
|
|
594
|
-
}
|
|
595
|
-
// Return the first root if available.
|
|
596
|
-
if (!!this.workspaceService.tryGetRoots().length) {
|
|
597
|
-
return this.workspaceService.tryGetRoots()[0].resource;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
exports.WorkspaceRootUriAwareCommandHandler = WorkspaceRootUriAwareCommandHandler;
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2017 TypeFox and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
};
|
|
23
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.WorkspaceRootUriAwareCommandHandler = exports.WorkspaceCommandContribution = exports.EditMenuContribution = exports.FileMenuContribution = exports.WorkspaceCommands = void 0;
|
|
28
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
29
|
+
const selection_service_1 = require("@theia/core/lib/common/selection-service");
|
|
30
|
+
const command_1 = require("@theia/core/lib/common/command");
|
|
31
|
+
const common_frontend_contribution_1 = require("@theia/core/lib/browser/common-frontend-contribution");
|
|
32
|
+
const browser_1 = require("@theia/filesystem/lib/browser");
|
|
33
|
+
const dialogs_1 = require("@theia/core/lib/browser/dialogs");
|
|
34
|
+
const browser_2 = require("@theia/core/lib/browser");
|
|
35
|
+
const uri_command_handler_1 = require("@theia/core/lib/common/uri-command-handler");
|
|
36
|
+
const workspace_service_1 = require("./workspace-service");
|
|
37
|
+
const message_service_1 = require("@theia/core/lib/common/message-service");
|
|
38
|
+
const workspace_preferences_1 = require("./workspace-preferences");
|
|
39
|
+
const workspace_delete_handler_1 = require("./workspace-delete-handler");
|
|
40
|
+
const workspace_duplicate_handler_1 = require("./workspace-duplicate-handler");
|
|
41
|
+
const common_1 = require("@theia/filesystem/lib/common");
|
|
42
|
+
const workspace_compare_handler_1 = require("./workspace-compare-handler");
|
|
43
|
+
const file_download_command_contribution_1 = require("@theia/filesystem/lib/browser/download/file-download-command-contribution");
|
|
44
|
+
const filesystem_frontend_contribution_1 = require("@theia/filesystem/lib/browser/filesystem-frontend-contribution");
|
|
45
|
+
const workspace_input_dialog_1 = require("./workspace-input-dialog");
|
|
46
|
+
const common_2 = require("@theia/core/lib/common");
|
|
47
|
+
const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
|
|
48
|
+
const nls_1 = require("@theia/core/lib/common/nls");
|
|
49
|
+
const clipboard_service_1 = require("@theia/core/lib/browser/clipboard-service");
|
|
50
|
+
const validFilename = require('valid-filename');
|
|
51
|
+
var WorkspaceCommands;
|
|
52
|
+
(function (WorkspaceCommands) {
|
|
53
|
+
const WORKSPACE_CATEGORY = 'Workspaces';
|
|
54
|
+
const FILE_CATEGORY = browser_2.CommonCommands.FILE_CATEGORY;
|
|
55
|
+
// On Linux and Windows, both files and folders cannot be opened at the same time in electron.
|
|
56
|
+
// `OPEN_FILE` and `OPEN_FOLDER` must be available only on Linux and Windows in electron.
|
|
57
|
+
// `OPEN` must *not* be available on Windows and Linux in electron.
|
|
58
|
+
// VS Code does the same. See: https://github.com/eclipse-theia/theia/pull/3202#issuecomment-430585357
|
|
59
|
+
WorkspaceCommands.OPEN = {
|
|
60
|
+
...command_1.Command.toDefaultLocalizedCommand({
|
|
61
|
+
id: 'workspace:open',
|
|
62
|
+
category: browser_2.CommonCommands.FILE_CATEGORY,
|
|
63
|
+
label: 'Open...'
|
|
64
|
+
}),
|
|
65
|
+
dialogLabel: nls_1.nls.localizeByDefault('Open')
|
|
66
|
+
};
|
|
67
|
+
// No `label`. Otherwise, it shows up in the `Command Palette`.
|
|
68
|
+
WorkspaceCommands.OPEN_FILE = {
|
|
69
|
+
id: 'workspace:openFile',
|
|
70
|
+
originalCategory: FILE_CATEGORY,
|
|
71
|
+
category: nls_1.nls.localizeByDefault(browser_2.CommonCommands.FILE_CATEGORY),
|
|
72
|
+
dialogLabel: nls_1.nls.localizeByDefault('Open File')
|
|
73
|
+
};
|
|
74
|
+
WorkspaceCommands.OPEN_FOLDER = {
|
|
75
|
+
id: 'workspace:openFolder',
|
|
76
|
+
dialogLabel: nls_1.nls.localizeByDefault('Open Folder') // No `label`. Otherwise, it shows up in the `Command Palette`.
|
|
77
|
+
};
|
|
78
|
+
WorkspaceCommands.OPEN_WORKSPACE = {
|
|
79
|
+
...command_1.Command.toDefaultLocalizedCommand({
|
|
80
|
+
id: 'workspace:openWorkspace',
|
|
81
|
+
category: browser_2.CommonCommands.FILE_CATEGORY,
|
|
82
|
+
label: 'Open Workspace from File...',
|
|
83
|
+
}),
|
|
84
|
+
dialogLabel: nls_1.nls.localizeByDefault('Open Workspace from File')
|
|
85
|
+
};
|
|
86
|
+
WorkspaceCommands.OPEN_RECENT_WORKSPACE = command_1.Command.toLocalizedCommand({
|
|
87
|
+
id: 'workspace:openRecent',
|
|
88
|
+
category: FILE_CATEGORY,
|
|
89
|
+
label: 'Open Recent Workspace...'
|
|
90
|
+
}, 'theia/workspace/openRecentWorkspace', browser_2.CommonCommands.FILE_CATEGORY_KEY);
|
|
91
|
+
WorkspaceCommands.CLOSE = command_1.Command.toDefaultLocalizedCommand({
|
|
92
|
+
id: 'workspace:close',
|
|
93
|
+
category: WORKSPACE_CATEGORY,
|
|
94
|
+
label: 'Close Workspace'
|
|
95
|
+
});
|
|
96
|
+
WorkspaceCommands.NEW_FILE = command_1.Command.toDefaultLocalizedCommand({
|
|
97
|
+
id: 'file.newFile',
|
|
98
|
+
category: FILE_CATEGORY,
|
|
99
|
+
label: 'New File...'
|
|
100
|
+
});
|
|
101
|
+
WorkspaceCommands.NEW_FOLDER = command_1.Command.toDefaultLocalizedCommand({
|
|
102
|
+
id: 'file.newFolder',
|
|
103
|
+
category: FILE_CATEGORY,
|
|
104
|
+
label: 'New Folder...'
|
|
105
|
+
});
|
|
106
|
+
WorkspaceCommands.FILE_OPEN_WITH = (opener) => ({
|
|
107
|
+
id: `file.openWith.${opener.id}`
|
|
108
|
+
});
|
|
109
|
+
WorkspaceCommands.FILE_RENAME = command_1.Command.toDefaultLocalizedCommand({
|
|
110
|
+
id: 'file.rename',
|
|
111
|
+
category: FILE_CATEGORY,
|
|
112
|
+
label: 'Rename'
|
|
113
|
+
});
|
|
114
|
+
WorkspaceCommands.FILE_DELETE = command_1.Command.toDefaultLocalizedCommand({
|
|
115
|
+
id: 'file.delete',
|
|
116
|
+
category: FILE_CATEGORY,
|
|
117
|
+
label: 'Delete'
|
|
118
|
+
});
|
|
119
|
+
WorkspaceCommands.FILE_DUPLICATE = command_1.Command.toLocalizedCommand({
|
|
120
|
+
id: 'file.duplicate',
|
|
121
|
+
category: FILE_CATEGORY,
|
|
122
|
+
label: 'Duplicate'
|
|
123
|
+
}, 'theia/workspace/duplicate', browser_2.CommonCommands.FILE_CATEGORY_KEY);
|
|
124
|
+
WorkspaceCommands.FILE_COMPARE = command_1.Command.toLocalizedCommand({
|
|
125
|
+
id: 'file.compare',
|
|
126
|
+
category: FILE_CATEGORY,
|
|
127
|
+
label: 'Compare with Each Other'
|
|
128
|
+
}, 'theia/workspace/compareWithEachOther', browser_2.CommonCommands.FILE_CATEGORY_KEY);
|
|
129
|
+
WorkspaceCommands.ADD_FOLDER = command_1.Command.toDefaultLocalizedCommand({
|
|
130
|
+
id: 'workspace:addFolder',
|
|
131
|
+
category: WORKSPACE_CATEGORY,
|
|
132
|
+
label: 'Add Folder to Workspace...'
|
|
133
|
+
});
|
|
134
|
+
WorkspaceCommands.REMOVE_FOLDER = command_1.Command.toDefaultLocalizedCommand({
|
|
135
|
+
id: 'workspace:removeFolder',
|
|
136
|
+
category: WORKSPACE_CATEGORY,
|
|
137
|
+
label: 'Remove Folder from Workspace'
|
|
138
|
+
});
|
|
139
|
+
WorkspaceCommands.SAVE_WORKSPACE_AS = command_1.Command.toDefaultLocalizedCommand({
|
|
140
|
+
id: 'workspace:saveAs',
|
|
141
|
+
category: WORKSPACE_CATEGORY,
|
|
142
|
+
label: 'Save Workspace As...'
|
|
143
|
+
});
|
|
144
|
+
WorkspaceCommands.OPEN_WORKSPACE_FILE = command_1.Command.toDefaultLocalizedCommand({
|
|
145
|
+
id: 'workspace:openConfigFile',
|
|
146
|
+
category: WORKSPACE_CATEGORY,
|
|
147
|
+
label: 'Open Workspace Configuration File'
|
|
148
|
+
});
|
|
149
|
+
/** @deprecated @since 1.24.0 Use `CommonCommands.SAVE_AS` instead */
|
|
150
|
+
WorkspaceCommands.SAVE_AS = browser_2.CommonCommands.SAVE_AS;
|
|
151
|
+
WorkspaceCommands.COPY_RELATIVE_FILE_PATH = command_1.Command.toDefaultLocalizedCommand({
|
|
152
|
+
id: 'navigator.copyRelativeFilePath',
|
|
153
|
+
label: 'Copy Relative Path'
|
|
154
|
+
});
|
|
155
|
+
})(WorkspaceCommands = exports.WorkspaceCommands || (exports.WorkspaceCommands = {}));
|
|
156
|
+
let FileMenuContribution = class FileMenuContribution {
|
|
157
|
+
registerMenus(registry) {
|
|
158
|
+
registry.registerMenuAction(common_frontend_contribution_1.CommonMenus.FILE_NEW_TEXT, {
|
|
159
|
+
commandId: WorkspaceCommands.NEW_FOLDER.id,
|
|
160
|
+
order: 'b'
|
|
161
|
+
});
|
|
162
|
+
const downloadUploadMenu = [...common_frontend_contribution_1.CommonMenus.FILE, '4_downloadupload'];
|
|
163
|
+
registry.registerMenuAction(downloadUploadMenu, {
|
|
164
|
+
commandId: filesystem_frontend_contribution_1.FileSystemCommands.UPLOAD.id,
|
|
165
|
+
order: 'a'
|
|
166
|
+
});
|
|
167
|
+
registry.registerMenuAction(downloadUploadMenu, {
|
|
168
|
+
commandId: file_download_command_contribution_1.FileDownloadCommands.DOWNLOAD.id,
|
|
169
|
+
order: 'b'
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
FileMenuContribution = __decorate([
|
|
174
|
+
(0, inversify_1.injectable)()
|
|
175
|
+
], FileMenuContribution);
|
|
176
|
+
exports.FileMenuContribution = FileMenuContribution;
|
|
177
|
+
let EditMenuContribution = class EditMenuContribution {
|
|
178
|
+
registerMenus(registry) {
|
|
179
|
+
registry.registerMenuAction(common_frontend_contribution_1.CommonMenus.EDIT_CLIPBOARD, {
|
|
180
|
+
commandId: file_download_command_contribution_1.FileDownloadCommands.COPY_DOWNLOAD_LINK.id,
|
|
181
|
+
order: '9999'
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
EditMenuContribution = __decorate([
|
|
186
|
+
(0, inversify_1.injectable)()
|
|
187
|
+
], EditMenuContribution);
|
|
188
|
+
exports.EditMenuContribution = EditMenuContribution;
|
|
189
|
+
let WorkspaceCommandContribution = class WorkspaceCommandContribution {
|
|
190
|
+
constructor() {
|
|
191
|
+
this.onDidCreateNewFileEmitter = new common_2.Emitter();
|
|
192
|
+
this.onDidCreateNewFolderEmitter = new common_2.Emitter();
|
|
193
|
+
}
|
|
194
|
+
get onDidCreateNewFile() {
|
|
195
|
+
return this.onDidCreateNewFileEmitter.event;
|
|
196
|
+
}
|
|
197
|
+
get onDidCreateNewFolder() {
|
|
198
|
+
return this.onDidCreateNewFolderEmitter.event;
|
|
199
|
+
}
|
|
200
|
+
fireCreateNewFile(uri) {
|
|
201
|
+
this.onDidCreateNewFileEmitter.fire(uri);
|
|
202
|
+
}
|
|
203
|
+
fireCreateNewFolder(uri) {
|
|
204
|
+
this.onDidCreateNewFolderEmitter.fire(uri);
|
|
205
|
+
}
|
|
206
|
+
registerCommands(registry) {
|
|
207
|
+
this.registerOpenWith(registry);
|
|
208
|
+
registry.registerCommand(WorkspaceCommands.NEW_FILE, this.newWorkspaceRootUriAwareCommandHandler({
|
|
209
|
+
execute: uri => this.getDirectory(uri).then(parent => {
|
|
210
|
+
if (parent) {
|
|
211
|
+
const parentUri = parent.resource;
|
|
212
|
+
const { fileName, fileExtension } = this.getDefaultFileConfig();
|
|
213
|
+
const targetUri = parentUri.resolve(fileName + fileExtension);
|
|
214
|
+
const vacantChildUri = common_1.FileSystemUtils.generateUniqueResourceURI(parent, targetUri, false);
|
|
215
|
+
const dialog = new workspace_input_dialog_1.WorkspaceInputDialog({
|
|
216
|
+
title: nls_1.nls.localizeByDefault('New File...'),
|
|
217
|
+
maxWidth: 400,
|
|
218
|
+
parentUri: parentUri,
|
|
219
|
+
initialValue: vacantChildUri.path.base,
|
|
220
|
+
placeholder: nls_1.nls.localize('theia/workspace/newFilePlaceholder', 'File Name'),
|
|
221
|
+
validate: name => this.validateFileName(name, parent, true)
|
|
222
|
+
}, this.labelProvider);
|
|
223
|
+
dialog.open().then(async (name) => {
|
|
224
|
+
if (name) {
|
|
225
|
+
const fileUri = parentUri.resolve(name);
|
|
226
|
+
await this.fileService.create(fileUri);
|
|
227
|
+
this.fireCreateNewFile({ parent: parentUri, uri: fileUri });
|
|
228
|
+
(0, browser_2.open)(this.openerService, fileUri);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
}));
|
|
234
|
+
registry.registerCommand(WorkspaceCommands.NEW_FOLDER, this.newWorkspaceRootUriAwareCommandHandler({
|
|
235
|
+
execute: uri => this.getDirectory(uri).then(parent => {
|
|
236
|
+
if (parent) {
|
|
237
|
+
const parentUri = parent.resource;
|
|
238
|
+
const targetUri = parentUri.resolve('Untitled');
|
|
239
|
+
const vacantChildUri = common_1.FileSystemUtils.generateUniqueResourceURI(parent, targetUri, true);
|
|
240
|
+
const dialog = new workspace_input_dialog_1.WorkspaceInputDialog({
|
|
241
|
+
title: nls_1.nls.localizeByDefault('New Folder...'),
|
|
242
|
+
maxWidth: 400,
|
|
243
|
+
parentUri: parentUri,
|
|
244
|
+
initialValue: vacantChildUri.path.base,
|
|
245
|
+
placeholder: nls_1.nls.localize('theia/workspace/newFolderPlaceholder', 'Folder Name'),
|
|
246
|
+
validate: name => this.validateFileName(name, parent, true)
|
|
247
|
+
}, this.labelProvider);
|
|
248
|
+
dialog.open().then(async (name) => {
|
|
249
|
+
if (name) {
|
|
250
|
+
const folderUri = parentUri.resolve(name);
|
|
251
|
+
await this.fileService.createFolder(folderUri);
|
|
252
|
+
this.fireCreateNewFile({ parent: parentUri, uri: folderUri });
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
}));
|
|
258
|
+
registry.registerCommand(WorkspaceCommands.FILE_RENAME, this.newMultiUriAwareCommandHandler({
|
|
259
|
+
isEnabled: uris => uris.some(uri => !this.isWorkspaceRoot(uri)) && uris.length === 1,
|
|
260
|
+
isVisible: uris => uris.some(uri => !this.isWorkspaceRoot(uri)) && uris.length === 1,
|
|
261
|
+
execute: async (uris) => {
|
|
262
|
+
const uri = uris[0]; /* Since there is only one item in the array. */
|
|
263
|
+
const parent = await this.getParent(uri);
|
|
264
|
+
if (parent) {
|
|
265
|
+
const oldName = uri.path.base;
|
|
266
|
+
const dialog = new dialogs_1.SingleTextInputDialog({
|
|
267
|
+
title: nls_1.nls.localizeByDefault('Rename'),
|
|
268
|
+
maxWidth: 400,
|
|
269
|
+
initialValue: oldName,
|
|
270
|
+
initialSelectionRange: {
|
|
271
|
+
start: 0,
|
|
272
|
+
end: uri.path.name.length
|
|
273
|
+
},
|
|
274
|
+
validate: async (newName, mode) => {
|
|
275
|
+
if (oldName === newName && mode === 'preview') {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
return this.validateFileRename(oldName, newName, parent);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
const fileName = await dialog.open();
|
|
282
|
+
if (fileName) {
|
|
283
|
+
const oldUri = uri;
|
|
284
|
+
const newUri = uri.parent.resolve(fileName);
|
|
285
|
+
return this.fileService.move(oldUri, newUri);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}));
|
|
290
|
+
registry.registerCommand(WorkspaceCommands.FILE_DUPLICATE, this.newMultiUriAwareCommandHandler(this.duplicateHandler));
|
|
291
|
+
registry.registerCommand(WorkspaceCommands.FILE_DELETE, this.newMultiUriAwareCommandHandler(this.deleteHandler));
|
|
292
|
+
registry.registerCommand(WorkspaceCommands.FILE_COMPARE, this.newMultiUriAwareCommandHandler(this.compareHandler));
|
|
293
|
+
registry.registerCommand(WorkspaceCommands.COPY_RELATIVE_FILE_PATH, uri_command_handler_1.UriAwareCommandHandler.MultiSelect(this.selectionService, {
|
|
294
|
+
isEnabled: uris => !!uris.length,
|
|
295
|
+
isVisible: uris => !!uris.length,
|
|
296
|
+
execute: async (uris) => {
|
|
297
|
+
const lineDelimiter = common_2.EOL;
|
|
298
|
+
const text = uris.map((uri) => {
|
|
299
|
+
var _a;
|
|
300
|
+
const workspaceRoot = this.workspaceService.getWorkspaceRootUri(uri);
|
|
301
|
+
if (workspaceRoot) {
|
|
302
|
+
return (_a = workspaceRoot.relative(uri)) === null || _a === void 0 ? void 0 : _a.fsPath();
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
return uri.path.fsPath();
|
|
306
|
+
}
|
|
307
|
+
}).join(lineDelimiter);
|
|
308
|
+
await this.clipboardService.writeText(text);
|
|
309
|
+
}
|
|
310
|
+
}));
|
|
311
|
+
registry.registerCommand(WorkspaceCommands.ADD_FOLDER, {
|
|
312
|
+
isEnabled: () => this.workspaceService.opened,
|
|
313
|
+
isVisible: () => this.workspaceService.opened,
|
|
314
|
+
execute: async () => {
|
|
315
|
+
const selection = await this.fileDialogService.showOpenDialog({
|
|
316
|
+
title: WorkspaceCommands.ADD_FOLDER.label,
|
|
317
|
+
canSelectFiles: false,
|
|
318
|
+
canSelectFolders: true,
|
|
319
|
+
canSelectMany: true,
|
|
320
|
+
});
|
|
321
|
+
if (!selection) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const uris = Array.isArray(selection) ? selection : [selection];
|
|
325
|
+
const workspaceSavedBeforeAdding = this.workspaceService.saved;
|
|
326
|
+
await this.addFolderToWorkspace(...uris);
|
|
327
|
+
if (!workspaceSavedBeforeAdding) {
|
|
328
|
+
this.saveWorkspaceWithPrompt(registry);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
registry.registerCommand(WorkspaceCommands.REMOVE_FOLDER, this.newMultiUriAwareCommandHandler({
|
|
333
|
+
execute: uris => this.removeFolderFromWorkspace(uris),
|
|
334
|
+
isEnabled: () => this.workspaceService.isMultiRootWorkspaceOpened,
|
|
335
|
+
isVisible: uris => this.areWorkspaceRoots(uris) && this.workspaceService.saved
|
|
336
|
+
}));
|
|
337
|
+
}
|
|
338
|
+
async registerOpenWith(registry) {
|
|
339
|
+
if (this.openerService.onDidChangeOpeners) {
|
|
340
|
+
this.openerService.onDidChangeOpeners(async (e) => {
|
|
341
|
+
this.openers = await this.openerService.getOpeners();
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
this.openers = await this.openerService.getOpeners();
|
|
345
|
+
for (const opener of this.openers) {
|
|
346
|
+
const openWithCommand = WorkspaceCommands.FILE_OPEN_WITH(opener);
|
|
347
|
+
registry.registerCommand(openWithCommand, this.newUriAwareCommandHandler({
|
|
348
|
+
execute: uri => opener.open(uri),
|
|
349
|
+
isEnabled: uri => opener.canHandle(uri) > 0,
|
|
350
|
+
isVisible: uri => opener.canHandle(uri) > 0 && this.areMultipleOpenHandlersPresent(this.openers, uri)
|
|
351
|
+
}));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
newUriAwareCommandHandler(handler) {
|
|
355
|
+
return uri_command_handler_1.UriAwareCommandHandler.MonoSelect(this.selectionService, handler);
|
|
356
|
+
}
|
|
357
|
+
newMultiUriAwareCommandHandler(handler) {
|
|
358
|
+
return uri_command_handler_1.UriAwareCommandHandler.MultiSelect(this.selectionService, handler);
|
|
359
|
+
}
|
|
360
|
+
newWorkspaceRootUriAwareCommandHandler(handler) {
|
|
361
|
+
return new WorkspaceRootUriAwareCommandHandler(this.workspaceService, this.selectionService, handler);
|
|
362
|
+
}
|
|
363
|
+
async validateFileRename(oldName, newName, parent) {
|
|
364
|
+
if (common_2.OS.backend.isWindows && parent.resource.resolve(newName).isEqual(parent.resource.resolve(oldName), false)) {
|
|
365
|
+
return '';
|
|
366
|
+
}
|
|
367
|
+
return this.validateFileName(newName, parent, false);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Returns an error message if the file name is invalid. Otherwise, an empty string.
|
|
371
|
+
*
|
|
372
|
+
* @param name the simple file name of the file to validate.
|
|
373
|
+
* @param parent the parent directory's file stat.
|
|
374
|
+
* @param allowNested allow file or folder creation using recursive path
|
|
375
|
+
*/
|
|
376
|
+
async validateFileName(name, parent, allowNested = false) {
|
|
377
|
+
if (!name) {
|
|
378
|
+
return '';
|
|
379
|
+
}
|
|
380
|
+
// do not allow recursive rename
|
|
381
|
+
if (!allowNested && !validFilename(name)) {
|
|
382
|
+
return nls_1.nls.localizeByDefault('The name **{0}** is not valid as a file or folder name. Please choose a different name.');
|
|
383
|
+
}
|
|
384
|
+
if (name.startsWith('/')) {
|
|
385
|
+
return nls_1.nls.localizeByDefault('A file or folder name cannot start with a slash.');
|
|
386
|
+
}
|
|
387
|
+
else if (name.startsWith(' ') || name.endsWith(' ')) {
|
|
388
|
+
return nls_1.nls.localizeByDefault('Leading or trailing whitespace detected in file or folder name.');
|
|
389
|
+
}
|
|
390
|
+
// check and validate each sub-paths
|
|
391
|
+
if (name.split(/[\\/]/).some(file => !file || !validFilename(file) || /^\s+$/.test(file))) {
|
|
392
|
+
return nls_1.nls.localizeByDefault('\'{0}\' is not a valid file name', this.trimFileName(name));
|
|
393
|
+
}
|
|
394
|
+
const childUri = parent.resource.resolve(name);
|
|
395
|
+
const exists = await this.fileService.exists(childUri);
|
|
396
|
+
if (exists) {
|
|
397
|
+
return nls_1.nls.localizeByDefault('A file or folder **{0}** already exists at this location. Please choose a different name.', this.trimFileName(name));
|
|
398
|
+
}
|
|
399
|
+
return '';
|
|
400
|
+
}
|
|
401
|
+
trimFileName(name) {
|
|
402
|
+
if (name && name.length > 30) {
|
|
403
|
+
return `${name.substring(0, 30)}...`;
|
|
404
|
+
}
|
|
405
|
+
return name;
|
|
406
|
+
}
|
|
407
|
+
async getDirectory(candidate) {
|
|
408
|
+
let stat;
|
|
409
|
+
try {
|
|
410
|
+
stat = await this.fileService.resolve(candidate);
|
|
411
|
+
}
|
|
412
|
+
catch { }
|
|
413
|
+
if (stat && stat.isDirectory) {
|
|
414
|
+
return stat;
|
|
415
|
+
}
|
|
416
|
+
return this.getParent(candidate);
|
|
417
|
+
}
|
|
418
|
+
async getParent(candidate) {
|
|
419
|
+
try {
|
|
420
|
+
return await this.fileService.resolve(candidate.parent);
|
|
421
|
+
}
|
|
422
|
+
catch {
|
|
423
|
+
return undefined;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
async addFolderToWorkspace(...uris) {
|
|
427
|
+
if (uris.length) {
|
|
428
|
+
const foldersToAdd = [];
|
|
429
|
+
try {
|
|
430
|
+
for (const uri of uris) {
|
|
431
|
+
const stat = await this.fileService.resolve(uri);
|
|
432
|
+
if (stat.isDirectory) {
|
|
433
|
+
foldersToAdd.push(uri);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
await this.workspaceService.addRoot(foldersToAdd);
|
|
437
|
+
}
|
|
438
|
+
catch { }
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
areWorkspaceRoots(uris) {
|
|
442
|
+
return this.workspaceService.areWorkspaceRoots(uris);
|
|
443
|
+
}
|
|
444
|
+
isWorkspaceRoot(uri) {
|
|
445
|
+
const rootUris = new Set(this.workspaceService.tryGetRoots().map(root => root.resource.toString()));
|
|
446
|
+
return rootUris.has(uri.toString());
|
|
447
|
+
}
|
|
448
|
+
getDefaultFileConfig() {
|
|
449
|
+
return {
|
|
450
|
+
fileName: 'Untitled',
|
|
451
|
+
fileExtension: '.txt'
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Removes the list of folders from the workspace upon confirmation from the user.
|
|
456
|
+
* @param uris the list of folder uris to remove.
|
|
457
|
+
*/
|
|
458
|
+
async removeFolderFromWorkspace(uris) {
|
|
459
|
+
const roots = new Set(this.workspaceService.tryGetRoots().map(root => root.resource.toString()));
|
|
460
|
+
const toRemove = uris.filter(uri => roots.has(uri.toString()));
|
|
461
|
+
if (toRemove.length > 0) {
|
|
462
|
+
const messageContainer = document.createElement('div');
|
|
463
|
+
if (toRemove.length > 1) {
|
|
464
|
+
messageContainer.textContent = nls_1.nls.localize('theia/workspace/removeFolders', 'Are you sure you want to remove the following folders from the workspace?');
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
messageContainer.textContent = nls_1.nls.localize('theia/workspace/removeFolder', 'Are you sure you want to remove the following folder from the workspace?');
|
|
468
|
+
}
|
|
469
|
+
messageContainer.title = nls_1.nls.localize('theia/workspace/noErasure', 'Note: Nothing will be erased from disk');
|
|
470
|
+
const list = document.createElement('div');
|
|
471
|
+
list.classList.add('theia-dialog-node');
|
|
472
|
+
toRemove.forEach(uri => {
|
|
473
|
+
const listItem = document.createElement('div');
|
|
474
|
+
listItem.classList.add('theia-dialog-node-content');
|
|
475
|
+
const folderIcon = document.createElement('span');
|
|
476
|
+
folderIcon.classList.add('codicon', 'codicon-root-folder', 'theia-dialog-icon');
|
|
477
|
+
listItem.appendChild(folderIcon);
|
|
478
|
+
listItem.title = this.labelProvider.getLongName(uri);
|
|
479
|
+
const listContent = document.createElement('span');
|
|
480
|
+
listContent.classList.add('theia-dialog-node-segment');
|
|
481
|
+
listContent.appendChild(document.createTextNode(this.labelProvider.getName(uri)));
|
|
482
|
+
listItem.appendChild(listContent);
|
|
483
|
+
list.appendChild(listItem);
|
|
484
|
+
});
|
|
485
|
+
messageContainer.appendChild(list);
|
|
486
|
+
const dialog = new dialogs_1.ConfirmDialog({
|
|
487
|
+
title: nls_1.nls.localizeByDefault('Remove Folder from Workspace'),
|
|
488
|
+
msg: messageContainer
|
|
489
|
+
});
|
|
490
|
+
if (await dialog.open()) {
|
|
491
|
+
await this.workspaceService.removeRoots(toRemove);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
async saveWorkspaceWithPrompt(registry) {
|
|
496
|
+
const saveCommand = registry.getCommand(WorkspaceCommands.SAVE_WORKSPACE_AS.id);
|
|
497
|
+
if (saveCommand && await new dialogs_1.ConfirmDialog({
|
|
498
|
+
title: nls_1.nls.localize('theia/workspace/workspaceFolderAddedTitle', 'Folder added to Workspace'),
|
|
499
|
+
msg: nls_1.nls.localize('theia/workspace/workspaceFolderAdded', 'A workspace with multiple roots was created. Do you want to save your workspace configuration as a file?'),
|
|
500
|
+
ok: dialogs_1.Dialog.YES,
|
|
501
|
+
cancel: dialogs_1.Dialog.NO
|
|
502
|
+
}).open()) {
|
|
503
|
+
return registry.executeCommand(saveCommand.id);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
areMultipleOpenHandlersPresent(openers, uri) {
|
|
507
|
+
let count = 0;
|
|
508
|
+
for (const opener of openers) {
|
|
509
|
+
if (opener.canHandle(uri) > 0) {
|
|
510
|
+
count++;
|
|
511
|
+
}
|
|
512
|
+
if (count > 1) {
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
__decorate([
|
|
520
|
+
(0, inversify_1.inject)(browser_2.LabelProvider),
|
|
521
|
+
__metadata("design:type", browser_2.LabelProvider)
|
|
522
|
+
], WorkspaceCommandContribution.prototype, "labelProvider", void 0);
|
|
523
|
+
__decorate([
|
|
524
|
+
(0, inversify_1.inject)(file_service_1.FileService),
|
|
525
|
+
__metadata("design:type", file_service_1.FileService)
|
|
526
|
+
], WorkspaceCommandContribution.prototype, "fileService", void 0);
|
|
527
|
+
__decorate([
|
|
528
|
+
(0, inversify_1.inject)(workspace_service_1.WorkspaceService),
|
|
529
|
+
__metadata("design:type", workspace_service_1.WorkspaceService)
|
|
530
|
+
], WorkspaceCommandContribution.prototype, "workspaceService", void 0);
|
|
531
|
+
__decorate([
|
|
532
|
+
(0, inversify_1.inject)(selection_service_1.SelectionService),
|
|
533
|
+
__metadata("design:type", selection_service_1.SelectionService)
|
|
534
|
+
], WorkspaceCommandContribution.prototype, "selectionService", void 0);
|
|
535
|
+
__decorate([
|
|
536
|
+
(0, inversify_1.inject)(browser_2.OpenerService),
|
|
537
|
+
__metadata("design:type", Object)
|
|
538
|
+
], WorkspaceCommandContribution.prototype, "openerService", void 0);
|
|
539
|
+
__decorate([
|
|
540
|
+
(0, inversify_1.inject)(browser_2.FrontendApplication),
|
|
541
|
+
__metadata("design:type", browser_2.FrontendApplication)
|
|
542
|
+
], WorkspaceCommandContribution.prototype, "app", void 0);
|
|
543
|
+
__decorate([
|
|
544
|
+
(0, inversify_1.inject)(message_service_1.MessageService),
|
|
545
|
+
__metadata("design:type", message_service_1.MessageService)
|
|
546
|
+
], WorkspaceCommandContribution.prototype, "messageService", void 0);
|
|
547
|
+
__decorate([
|
|
548
|
+
(0, inversify_1.inject)(workspace_preferences_1.WorkspacePreferences),
|
|
549
|
+
__metadata("design:type", Object)
|
|
550
|
+
], WorkspaceCommandContribution.prototype, "preferences", void 0);
|
|
551
|
+
__decorate([
|
|
552
|
+
(0, inversify_1.inject)(browser_1.FileDialogService),
|
|
553
|
+
__metadata("design:type", Object)
|
|
554
|
+
], WorkspaceCommandContribution.prototype, "fileDialogService", void 0);
|
|
555
|
+
__decorate([
|
|
556
|
+
(0, inversify_1.inject)(workspace_delete_handler_1.WorkspaceDeleteHandler),
|
|
557
|
+
__metadata("design:type", workspace_delete_handler_1.WorkspaceDeleteHandler)
|
|
558
|
+
], WorkspaceCommandContribution.prototype, "deleteHandler", void 0);
|
|
559
|
+
__decorate([
|
|
560
|
+
(0, inversify_1.inject)(workspace_duplicate_handler_1.WorkspaceDuplicateHandler),
|
|
561
|
+
__metadata("design:type", workspace_duplicate_handler_1.WorkspaceDuplicateHandler)
|
|
562
|
+
], WorkspaceCommandContribution.prototype, "duplicateHandler", void 0);
|
|
563
|
+
__decorate([
|
|
564
|
+
(0, inversify_1.inject)(workspace_compare_handler_1.WorkspaceCompareHandler),
|
|
565
|
+
__metadata("design:type", workspace_compare_handler_1.WorkspaceCompareHandler)
|
|
566
|
+
], WorkspaceCommandContribution.prototype, "compareHandler", void 0);
|
|
567
|
+
__decorate([
|
|
568
|
+
(0, inversify_1.inject)(clipboard_service_1.ClipboardService),
|
|
569
|
+
__metadata("design:type", Object)
|
|
570
|
+
], WorkspaceCommandContribution.prototype, "clipboardService", void 0);
|
|
571
|
+
WorkspaceCommandContribution = __decorate([
|
|
572
|
+
(0, inversify_1.injectable)()
|
|
573
|
+
], WorkspaceCommandContribution);
|
|
574
|
+
exports.WorkspaceCommandContribution = WorkspaceCommandContribution;
|
|
575
|
+
class WorkspaceRootUriAwareCommandHandler extends uri_command_handler_1.UriAwareCommandHandler {
|
|
576
|
+
constructor(workspaceService, selectionService, handler) {
|
|
577
|
+
super(selectionService, handler);
|
|
578
|
+
this.workspaceService = workspaceService;
|
|
579
|
+
}
|
|
580
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
581
|
+
isEnabled(...args) {
|
|
582
|
+
return super.isEnabled(...args) && !!this.workspaceService.tryGetRoots().length;
|
|
583
|
+
}
|
|
584
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
585
|
+
isVisible(...args) {
|
|
586
|
+
return super.isVisible(...args) && !!this.workspaceService.tryGetRoots().length;
|
|
587
|
+
}
|
|
588
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
589
|
+
getUri(...args) {
|
|
590
|
+
const uri = super.getUri(...args);
|
|
591
|
+
// Return the `uri` immediately if the resource exists in any of the workspace roots and is of `file` scheme.
|
|
592
|
+
if (uri && uri.scheme === 'file' && this.workspaceService.getWorkspaceRootUri(uri)) {
|
|
593
|
+
return uri;
|
|
594
|
+
}
|
|
595
|
+
// Return the first root if available.
|
|
596
|
+
if (!!this.workspaceService.tryGetRoots().length) {
|
|
597
|
+
return this.workspaceService.tryGetRoots()[0].resource;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
exports.WorkspaceRootUriAwareCommandHandler = WorkspaceRootUriAwareCommandHandler;
|
|
602
602
|
//# sourceMappingURL=workspace-commands.js.map
|