@theia/workspace 1.34.3 → 1.34.4
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/LICENSE +641 -641
- package/README.md +30 -30
- package/lib/browser/diff-service.d.ts +10 -10
- package/lib/browser/diff-service.js +85 -85
- package/lib/browser/index.d.ts +6 -6
- package/lib/browser/index.js +33 -33
- 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 +593 -593
- 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 +135 -135
- package/lib/browser/workspace-frontend-contribution.js +568 -568
- package/lib/browser/workspace-frontend-contribution.spec.d.ts +1 -1
- package/lib/browser/workspace-frontend-contribution.spec.js +53 -53
- package/lib/browser/workspace-frontend-module.d.ts +3 -3
- package/lib/browser/workspace-frontend-module.js +88 -88
- package/lib/browser/workspace-input-dialog.d.ts +19 -19
- package/lib/browser/workspace-input-dialog.js +73 -73
- 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 +32 -32
- package/lib/browser/workspace-schema-updater.js +148 -148
- package/lib/browser/workspace-service.d.ts +182 -182
- package/lib/browser/workspace-service.js +729 -729
- 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 +26 -26
- package/lib/browser/workspace-trust-service.js +149 -149
- 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/common/index.d.ts +2 -2
- package/lib/common/index.js +29 -29
- package/lib/common/test/mock-workspace-server.d.ts +7 -7
- package/lib/common/test/mock-workspace-server.js +35 -35
- package/lib/common/utils.d.ts +21 -21
- package/lib/common/utils.js +73 -73
- 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 +64 -64
- 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 +84 -84
- 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 +32 -32
- package/package.json +6 -6
- package/src/browser/diff-service.ts +62 -62
- package/src/browser/index.ts +22 -22
- 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 +586 -586
- 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.spec.ts +63 -63
- package/src/browser/workspace-frontend-contribution.ts +558 -558
- package/src/browser/workspace-frontend-module.ts +115 -115
- package/src/browser/workspace-input-dialog.ts +60 -60
- package/src/browser/workspace-preferences.ts +58 -58
- package/src/browser/workspace-schema-updater.ts +148 -148
- package/src/browser/workspace-service.ts +772 -772
- 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 +143 -143
- 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 +48 -48
- 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/common/index.ts +18 -18
- package/src/common/test/mock-workspace-server.ts +29 -29
- package/src/common/utils.ts +69 -69
- package/src/common/workspace-protocol.ts +47 -47
- package/src/node/default-workspace-server.spec.ts +99 -99
- package/src/node/default-workspace-server.ts +242 -242
- package/src/node/index.ts +18 -18
- package/src/node/workspace-backend-module.ts +37 -37
|
@@ -1,569 +1,569 @@
|
|
|
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 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
|
-
var WorkspaceFrontendContribution_1;
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.WorkspaceFrontendContribution = exports.FILE_WORKSPACE = exports.WorkspaceStates = void 0;
|
|
29
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
30
|
-
const common_1 = require("@theia/core/lib/common");
|
|
31
|
-
const core_1 = require("@theia/core");
|
|
32
|
-
const browser_1 = require("@theia/core/lib/browser");
|
|
33
|
-
const browser_2 = require("@theia/filesystem/lib/browser");
|
|
34
|
-
const context_key_service_1 = require("@theia/core/lib/browser/context-key-service");
|
|
35
|
-
const workspace_service_1 = require("./workspace-service");
|
|
36
|
-
const common_2 = require("../common");
|
|
37
|
-
const workspace_commands_1 = require("./workspace-commands");
|
|
38
|
-
const quick_open_workspace_1 = require("./quick-open-workspace");
|
|
39
|
-
const workspace_preferences_1 = require("./workspace-preferences");
|
|
40
|
-
const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
|
|
41
|
-
const encoding_registry_1 = require("@theia/core/lib/browser/encoding-registry");
|
|
42
|
-
const encodings_1 = require("@theia/core/lib/common/encodings");
|
|
43
|
-
const disposable_1 = require("@theia/core/lib/common/disposable");
|
|
44
|
-
const preference_configurations_1 = require("@theia/core/lib/browser/preferences/preference-configurations");
|
|
45
|
-
const nls_1 = require("@theia/core/lib/common/nls");
|
|
46
|
-
const buffer_1 = require("@theia/core/lib/common/buffer");
|
|
47
|
-
const untitled_workspace_exit_dialog_1 = require("./untitled-workspace-exit-dialog");
|
|
48
|
-
const filesystem_save_resource_service_1 = require("@theia/filesystem/lib/browser/filesystem-save-resource-service");
|
|
49
|
-
const frontend_application_state_1 = require("@theia/core/lib/common/frontend-application-state");
|
|
50
|
-
var WorkspaceStates;
|
|
51
|
-
(function (WorkspaceStates) {
|
|
52
|
-
/**
|
|
53
|
-
* The state is `empty` when no workspace is opened.
|
|
54
|
-
*/
|
|
55
|
-
WorkspaceStates["empty"] = "empty";
|
|
56
|
-
/**
|
|
57
|
-
* The state is `workspace` when a workspace is opened.
|
|
58
|
-
*/
|
|
59
|
-
WorkspaceStates["workspace"] = "workspace";
|
|
60
|
-
/**
|
|
61
|
-
* The state is `folder` when a folder is opened. (1 folder)
|
|
62
|
-
*/
|
|
63
|
-
WorkspaceStates["folder"] = "folder";
|
|
64
|
-
})(WorkspaceStates = exports.WorkspaceStates || (exports.WorkspaceStates = {}));
|
|
65
|
-
;
|
|
66
|
-
/** Create the workspace section after open {@link CommonMenus.FILE_OPEN}. */
|
|
67
|
-
exports.FILE_WORKSPACE = [...browser_1.CommonMenus.FILE, '2_workspace'];
|
|
68
|
-
let WorkspaceFrontendContribution = WorkspaceFrontendContribution_1 = class WorkspaceFrontendContribution {
|
|
69
|
-
constructor() {
|
|
70
|
-
this.toDisposeOnUpdateEncodingOverrides = new disposable_1.DisposableCollection();
|
|
71
|
-
}
|
|
72
|
-
configure() {
|
|
73
|
-
this.encodingRegistry.registerOverride({ encoding: encodings_1.UTF8, extension: common_2.THEIA_EXT });
|
|
74
|
-
this.encodingRegistry.registerOverride({ encoding: encodings_1.UTF8, extension: common_2.VSCODE_EXT });
|
|
75
|
-
this.updateEncodingOverrides();
|
|
76
|
-
const workspaceFolderCountKey = this.contextKeyService.createKey('workspaceFolderCount', 0);
|
|
77
|
-
const updateWorkspaceFolderCountKey = () => workspaceFolderCountKey.set(this.workspaceService.tryGetRoots().length);
|
|
78
|
-
updateWorkspaceFolderCountKey();
|
|
79
|
-
const workspaceStateKey = this.contextKeyService.createKey('workspaceState', 'empty');
|
|
80
|
-
const updateWorkspaceStateKey = () => workspaceStateKey.set(this.updateWorkspaceStateKey());
|
|
81
|
-
updateWorkspaceStateKey();
|
|
82
|
-
const workbenchStateKey = this.contextKeyService.createKey('workbenchState', 'empty');
|
|
83
|
-
const updateWorkbenchStateKey = () => workbenchStateKey.set(this.updateWorkbenchStateKey());
|
|
84
|
-
updateWorkbenchStateKey();
|
|
85
|
-
this.updateStyles();
|
|
86
|
-
this.workspaceService.onWorkspaceChanged(() => {
|
|
87
|
-
this.updateEncodingOverrides();
|
|
88
|
-
updateWorkspaceFolderCountKey();
|
|
89
|
-
updateWorkspaceStateKey();
|
|
90
|
-
updateWorkbenchStateKey();
|
|
91
|
-
this.updateStyles();
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
updateEncodingOverrides() {
|
|
95
|
-
this.toDisposeOnUpdateEncodingOverrides.dispose();
|
|
96
|
-
for (const root of this.workspaceService.tryGetRoots()) {
|
|
97
|
-
for (const configPath of this.preferenceConfigurations.getPaths()) {
|
|
98
|
-
const parent = root.resource.resolve(configPath);
|
|
99
|
-
this.toDisposeOnUpdateEncodingOverrides.push(this.encodingRegistry.registerOverride({ encoding: encodings_1.UTF8, parent }));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
updateStyles() {
|
|
104
|
-
document.body.classList.remove('theia-no-open-workspace');
|
|
105
|
-
// Display the 'no workspace opened' theme color when no folders are opened (single-root).
|
|
106
|
-
if (!this.workspaceService.isMultiRootWorkspaceOpened &&
|
|
107
|
-
!this.workspaceService.tryGetRoots().length) {
|
|
108
|
-
document.body.classList.add('theia-no-open-workspace');
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
registerCommands(commands) {
|
|
112
|
-
// Not visible/enabled on Windows/Linux in electron.
|
|
113
|
-
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN, {
|
|
114
|
-
isEnabled: () => core_1.isOSX || !this.isElectron(),
|
|
115
|
-
isVisible: () => core_1.isOSX || !this.isElectron(),
|
|
116
|
-
execute: () => this.doOpen()
|
|
117
|
-
});
|
|
118
|
-
// Visible/enabled only on Windows/Linux in electron.
|
|
119
|
-
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_FILE, {
|
|
120
|
-
isEnabled: () => true,
|
|
121
|
-
execute: () => this.doOpenFile()
|
|
122
|
-
});
|
|
123
|
-
// Visible/enabled only on Windows/Linux in electron.
|
|
124
|
-
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_FOLDER, {
|
|
125
|
-
isEnabled: () => true,
|
|
126
|
-
execute: () => this.doOpenFolder()
|
|
127
|
-
});
|
|
128
|
-
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE, {
|
|
129
|
-
isEnabled: () => true,
|
|
130
|
-
execute: () => this.doOpenWorkspace()
|
|
131
|
-
});
|
|
132
|
-
commands.registerCommand(workspace_commands_1.WorkspaceCommands.CLOSE, {
|
|
133
|
-
isEnabled: () => this.workspaceService.opened,
|
|
134
|
-
execute: () => this.closeWorkspace()
|
|
135
|
-
});
|
|
136
|
-
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_RECENT_WORKSPACE, {
|
|
137
|
-
execute: () => this.quickOpenWorkspace.select()
|
|
138
|
-
});
|
|
139
|
-
commands.registerCommand(workspace_commands_1.WorkspaceCommands.SAVE_WORKSPACE_AS, {
|
|
140
|
-
isVisible: () => this.workspaceService.opened,
|
|
141
|
-
isEnabled: () => this.workspaceService.opened,
|
|
142
|
-
execute: () => this.saveWorkspaceAs()
|
|
143
|
-
});
|
|
144
|
-
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE_FILE, {
|
|
145
|
-
isEnabled: () => this.workspaceService.saved,
|
|
146
|
-
execute: () => {
|
|
147
|
-
if (this.workspaceService.saved && this.workspaceService.workspace) {
|
|
148
|
-
(0, browser_1.open)(this.openerService, this.workspaceService.workspace.resource);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
registerMenus(menus) {
|
|
154
|
-
if (core_1.isOSX || !this.isElectron()) {
|
|
155
|
-
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
156
|
-
commandId: workspace_commands_1.WorkspaceCommands.OPEN.id,
|
|
157
|
-
order: 'a00'
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
if (!core_1.isOSX && this.isElectron()) {
|
|
161
|
-
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
162
|
-
commandId: workspace_commands_1.WorkspaceCommands.OPEN_FILE.id,
|
|
163
|
-
label: `${workspace_commands_1.WorkspaceCommands.OPEN_FILE.dialogLabel}...`,
|
|
164
|
-
order: 'a01'
|
|
165
|
-
});
|
|
166
|
-
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
167
|
-
commandId: workspace_commands_1.WorkspaceCommands.OPEN_FOLDER.id,
|
|
168
|
-
label: `${workspace_commands_1.WorkspaceCommands.OPEN_FOLDER.dialogLabel}...`,
|
|
169
|
-
order: 'a02'
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
173
|
-
commandId: workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE.id,
|
|
174
|
-
order: 'a10'
|
|
175
|
-
});
|
|
176
|
-
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
177
|
-
commandId: workspace_commands_1.WorkspaceCommands.OPEN_RECENT_WORKSPACE.id,
|
|
178
|
-
order: 'a20'
|
|
179
|
-
});
|
|
180
|
-
menus.registerMenuAction(exports.FILE_WORKSPACE, {
|
|
181
|
-
commandId: workspace_commands_1.WorkspaceCommands.ADD_FOLDER.id,
|
|
182
|
-
order: 'a10'
|
|
183
|
-
});
|
|
184
|
-
menus.registerMenuAction(exports.FILE_WORKSPACE, {
|
|
185
|
-
commandId: workspace_commands_1.WorkspaceCommands.SAVE_WORKSPACE_AS.id,
|
|
186
|
-
order: 'a20'
|
|
187
|
-
});
|
|
188
|
-
menus.registerMenuAction(browser_1.CommonMenus.FILE_CLOSE, {
|
|
189
|
-
commandId: workspace_commands_1.WorkspaceCommands.CLOSE.id
|
|
190
|
-
});
|
|
191
|
-
menus.registerMenuAction(browser_1.CommonMenus.FILE_SAVE, {
|
|
192
|
-
commandId: workspace_commands_1.WorkspaceCommands.SAVE_AS.id,
|
|
193
|
-
});
|
|
194
|
-
menus.registerMenuAction(browser_1.SHELL_TABBAR_CONTEXT_COPY, {
|
|
195
|
-
commandId: workspace_commands_1.WorkspaceCommands.COPY_RELATIVE_FILE_PATH.id,
|
|
196
|
-
label: workspace_commands_1.WorkspaceCommands.COPY_RELATIVE_FILE_PATH.label,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
registerKeybindings(keybindings) {
|
|
200
|
-
keybindings.registerKeybinding({
|
|
201
|
-
command: core_1.isOSX || !this.isElectron() ? workspace_commands_1.WorkspaceCommands.OPEN.id : workspace_commands_1.WorkspaceCommands.OPEN_FILE.id,
|
|
202
|
-
keybinding: this.isElectron() ? 'ctrlcmd+o' : 'ctrlcmd+alt+o',
|
|
203
|
-
});
|
|
204
|
-
if (!core_1.isOSX && this.isElectron()) {
|
|
205
|
-
keybindings.registerKeybinding({
|
|
206
|
-
command: workspace_commands_1.WorkspaceCommands.OPEN_FOLDER.id,
|
|
207
|
-
keybinding: 'ctrl+k ctrl+o',
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
keybindings.registerKeybinding({
|
|
211
|
-
command: workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE.id,
|
|
212
|
-
keybinding: 'ctrlcmd+alt+w',
|
|
213
|
-
});
|
|
214
|
-
keybindings.registerKeybinding({
|
|
215
|
-
command: workspace_commands_1.WorkspaceCommands.OPEN_RECENT_WORKSPACE.id,
|
|
216
|
-
keybinding: 'ctrlcmd+alt+r',
|
|
217
|
-
});
|
|
218
|
-
keybindings.registerKeybinding({
|
|
219
|
-
command: workspace_commands_1.WorkspaceCommands.SAVE_AS.id,
|
|
220
|
-
keybinding: 'ctrlcmd+shift+s',
|
|
221
|
-
});
|
|
222
|
-
keybindings.registerKeybinding({
|
|
223
|
-
command: workspace_commands_1.WorkspaceCommands.COPY_RELATIVE_FILE_PATH.id,
|
|
224
|
-
keybinding: common_1.isWindows ? 'ctrl+k ctrl+shift+c' : 'ctrlcmd+shift+alt+c',
|
|
225
|
-
when: '!editorFocus'
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* This is the generic `Open` method. Opens files and directories too. Resolves to the opened URI.
|
|
230
|
-
* Except when you are on either Windows or Linux `AND` running in electron. If so, it opens a file.
|
|
231
|
-
*/
|
|
232
|
-
async doOpen() {
|
|
233
|
-
var _a;
|
|
234
|
-
if (!core_1.isOSX && this.isElectron()) {
|
|
235
|
-
return this.doOpenFile();
|
|
236
|
-
}
|
|
237
|
-
const [rootStat] = await this.workspaceService.roots;
|
|
238
|
-
const destinationUri = await this.fileDialogService.showOpenDialog({
|
|
239
|
-
title: workspace_commands_1.WorkspaceCommands.OPEN.dialogLabel,
|
|
240
|
-
canSelectFolders: true,
|
|
241
|
-
canSelectFiles: true
|
|
242
|
-
}, rootStat);
|
|
243
|
-
if (destinationUri && ((_a = this.getCurrentWorkspaceUri()) === null || _a === void 0 ? void 0 : _a.toString()) !== destinationUri.toString()) {
|
|
244
|
-
const destination = await this.fileService.resolve(destinationUri);
|
|
245
|
-
if (destination.isDirectory) {
|
|
246
|
-
this.workspaceService.open(destinationUri);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
await (0, browser_1.open)(this.openerService, destinationUri);
|
|
250
|
-
}
|
|
251
|
-
return destinationUri;
|
|
252
|
-
}
|
|
253
|
-
return undefined;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Opens a file after prompting the `Open File` dialog. Resolves to `undefined`, if
|
|
257
|
-
* - the workspace root is not set,
|
|
258
|
-
* - the file to open does not exist, or
|
|
259
|
-
* - it was not a file, but a directory.
|
|
260
|
-
*
|
|
261
|
-
* Otherwise, resolves to the URI of the file.
|
|
262
|
-
*/
|
|
263
|
-
async doOpenFile() {
|
|
264
|
-
const props = {
|
|
265
|
-
title: workspace_commands_1.WorkspaceCommands.OPEN_FILE.dialogLabel,
|
|
266
|
-
canSelectFolders: false,
|
|
267
|
-
canSelectFiles: true
|
|
268
|
-
};
|
|
269
|
-
const [rootStat] = await this.workspaceService.roots;
|
|
270
|
-
const destinationFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
|
|
271
|
-
if (destinationFileUri) {
|
|
272
|
-
const destinationFile = await this.fileService.resolve(destinationFileUri);
|
|
273
|
-
if (!destinationFile.isDirectory) {
|
|
274
|
-
await (0, browser_1.open)(this.openerService, destinationFileUri);
|
|
275
|
-
return destinationFileUri;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return undefined;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Opens one or more folders after prompting the `Open Folder` dialog. Resolves to `undefined`, if
|
|
282
|
-
* - the user's selection is empty or contains only files.
|
|
283
|
-
* - the new workspace is equal to the old workspace.
|
|
284
|
-
*
|
|
285
|
-
* Otherwise, resolves to the URI of the new workspace:
|
|
286
|
-
* - a single folder if a single folder was selected.
|
|
287
|
-
* - a new, untitled workspace file if multiple folders were selected.
|
|
288
|
-
*/
|
|
289
|
-
async doOpenFolder() {
|
|
290
|
-
const props = {
|
|
291
|
-
title: workspace_commands_1.WorkspaceCommands.OPEN_FOLDER.dialogLabel,
|
|
292
|
-
canSelectFolders: true,
|
|
293
|
-
canSelectFiles: false,
|
|
294
|
-
canSelectMany: true,
|
|
295
|
-
};
|
|
296
|
-
const [rootStat] = await this.workspaceService.roots;
|
|
297
|
-
const targetFolders = await this.fileDialogService.showOpenDialog(props, rootStat);
|
|
298
|
-
if (targetFolders) {
|
|
299
|
-
const openableURI = await this.getOpenableWorkspaceUri(targetFolders);
|
|
300
|
-
if (openableURI) {
|
|
301
|
-
if (!this.workspaceService.workspace || !openableURI.isEqual(this.workspaceService.workspace.resource)) {
|
|
302
|
-
this.workspaceService.open(openableURI);
|
|
303
|
-
return openableURI;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
;
|
|
307
|
-
}
|
|
308
|
-
return undefined;
|
|
309
|
-
}
|
|
310
|
-
async getOpenableWorkspaceUri(uris) {
|
|
311
|
-
if (Array.isArray(uris)) {
|
|
312
|
-
if (uris.length < 2) {
|
|
313
|
-
return uris[0];
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
const foldersToOpen = (await Promise.all(uris.map(uri => this.fileService.resolve(uri))))
|
|
317
|
-
.filter(fileStat => !!(fileStat === null || fileStat === void 0 ? void 0 : fileStat.isDirectory));
|
|
318
|
-
if (foldersToOpen.length === 1) {
|
|
319
|
-
return foldersToOpen[0].resource;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
return this.createMultiRootWorkspace(foldersToOpen);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
return uris;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
async createMultiRootWorkspace(roots) {
|
|
331
|
-
const untitledWorkspace = await this.workspaceService.getUntitledWorkspace();
|
|
332
|
-
const folders = Array.from(new Set(roots.map(stat => stat.resource.path.toString())), path => ({ path }));
|
|
333
|
-
const workspaceStat = await this.fileService.createFile(untitledWorkspace, buffer_1.BinaryBuffer.fromString(JSON.stringify({ folders }, null, 4)), // eslint-disable-line no-null/no-null
|
|
334
|
-
{ overwrite: true });
|
|
335
|
-
return workspaceStat.resource;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Opens a workspace after raising the `Open Workspace` dialog. Resolves to the URI of the recently opened workspace,
|
|
339
|
-
* if it was successful. Otherwise, resolves to `undefined`.
|
|
340
|
-
*
|
|
341
|
-
* **Caveat**: this behaves differently on different platforms
|
|
342
|
-
* and `electron`/`browser` version has impact too. See [here](https://github.com/eclipse-theia/theia/pull/3202#issuecomment-430884195) for more details.
|
|
343
|
-
*
|
|
344
|
-
* Legend:
|
|
345
|
-
* - Folders only: => `F`
|
|
346
|
-
* - Workspace files only: => `W`
|
|
347
|
-
* - Folders and workspace files: => `FW`
|
|
348
|
-
*
|
|
349
|
-
* -----
|
|
350
|
-
*
|
|
351
|
-
* |---------|-----------|-----------|------------|------------|
|
|
352
|
-
* | | browser Y | browser N | electron Y | electron N |
|
|
353
|
-
* |---------|-----------|-----------|------------|------------|
|
|
354
|
-
* | Linux | FW | F | W | F |
|
|
355
|
-
* | Windows | FW | F | W | F |
|
|
356
|
-
* | OS X | FW | F | FW | FW |
|
|
357
|
-
* |---------|-----------|-----------|------------|------------|
|
|
358
|
-
*
|
|
359
|
-
*/
|
|
360
|
-
async doOpenWorkspace() {
|
|
361
|
-
var _a;
|
|
362
|
-
const props = await this.openWorkspaceOpenFileDialogProps();
|
|
363
|
-
const [rootStat] = await this.workspaceService.roots;
|
|
364
|
-
const workspaceFolderOrWorkspaceFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
|
|
365
|
-
if (workspaceFolderOrWorkspaceFileUri &&
|
|
366
|
-
((_a = this.getCurrentWorkspaceUri()) === null || _a === void 0 ? void 0 : _a.toString()) !== workspaceFolderOrWorkspaceFileUri.toString()) {
|
|
367
|
-
const destinationFolder = await this.fileService.exists(workspaceFolderOrWorkspaceFileUri);
|
|
368
|
-
if (destinationFolder) {
|
|
369
|
-
this.workspaceService.open(workspaceFolderOrWorkspaceFileUri);
|
|
370
|
-
return workspaceFolderOrWorkspaceFileUri;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
return undefined;
|
|
374
|
-
}
|
|
375
|
-
async openWorkspaceOpenFileDialogProps() {
|
|
376
|
-
await this.preferences.ready;
|
|
377
|
-
const type = core_1.OS.type();
|
|
378
|
-
const electron = this.isElectron();
|
|
379
|
-
return WorkspaceFrontendContribution_1.createOpenWorkspaceOpenFileDialogProps({
|
|
380
|
-
type,
|
|
381
|
-
electron,
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
async closeWorkspace() {
|
|
385
|
-
await this.workspaceService.close();
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* @returns whether the file was successfully saved.
|
|
389
|
-
*/
|
|
390
|
-
async saveWorkspaceAs() {
|
|
391
|
-
let exist = false;
|
|
392
|
-
let overwrite = false;
|
|
393
|
-
let selected;
|
|
394
|
-
do {
|
|
395
|
-
selected = await this.fileDialogService.showSaveDialog({
|
|
396
|
-
title: workspace_commands_1.WorkspaceCommands.SAVE_WORKSPACE_AS.label,
|
|
397
|
-
filters: WorkspaceFrontendContribution_1.DEFAULT_FILE_FILTER
|
|
398
|
-
});
|
|
399
|
-
if (selected) {
|
|
400
|
-
const displayName = selected.displayName;
|
|
401
|
-
if (!displayName.endsWith(`.${common_2.THEIA_EXT}`) && !displayName.endsWith(`.${common_2.VSCODE_EXT}`)) {
|
|
402
|
-
selected = selected.parent.resolve(`${displayName}.${common_2.THEIA_EXT}`);
|
|
403
|
-
}
|
|
404
|
-
exist = await this.fileService.exists(selected);
|
|
405
|
-
if (exist) {
|
|
406
|
-
overwrite = await this.saveService.confirmOverwrite(selected);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
} while (selected && exist && !overwrite);
|
|
410
|
-
if (selected) {
|
|
411
|
-
try {
|
|
412
|
-
await this.workspaceService.save(selected);
|
|
413
|
-
return true;
|
|
414
|
-
}
|
|
415
|
-
catch (_a) {
|
|
416
|
-
this.messageService.error(nls_1.nls.localizeByDefault("Unable to save workspace '{0}'", selected.path.fsPath()));
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
return false;
|
|
420
|
-
}
|
|
421
|
-
canBeSavedAs(widget) {
|
|
422
|
-
return this.saveService.canSaveAs(widget);
|
|
423
|
-
}
|
|
424
|
-
async saveAs(widget) {
|
|
425
|
-
return this.saveService.saveAs(widget);
|
|
426
|
-
}
|
|
427
|
-
updateWorkspaceStateKey() {
|
|
428
|
-
return this.doUpdateState();
|
|
429
|
-
}
|
|
430
|
-
updateWorkbenchStateKey() {
|
|
431
|
-
return this.doUpdateState();
|
|
432
|
-
}
|
|
433
|
-
doUpdateState() {
|
|
434
|
-
if (this.workspaceService.opened) {
|
|
435
|
-
return this.workspaceService.isMultiRootWorkspaceOpened ? 'workspace' : 'folder';
|
|
436
|
-
}
|
|
437
|
-
return 'empty';
|
|
438
|
-
}
|
|
439
|
-
isElectron() {
|
|
440
|
-
return core_1.environment.electron.is();
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Get the current workspace URI.
|
|
444
|
-
*
|
|
445
|
-
* @returns the current workspace URI.
|
|
446
|
-
*/
|
|
447
|
-
getCurrentWorkspaceUri() {
|
|
448
|
-
var _a;
|
|
449
|
-
return (_a = this.workspaceService.workspace) === null || _a === void 0 ? void 0 : _a.resource;
|
|
450
|
-
}
|
|
451
|
-
onWillStop() {
|
|
452
|
-
const { workspace } = this.workspaceService;
|
|
453
|
-
if (workspace && this.workspaceService.isUntitledWorkspace(workspace.resource)) {
|
|
454
|
-
return {
|
|
455
|
-
prepare: async (reason) => reason === frontend_application_state_1.StopReason.Reload && this.workspaceService.isSafeToReload(workspace.resource),
|
|
456
|
-
action: async (alreadyConfirmedSafe) => {
|
|
457
|
-
if (alreadyConfirmedSafe) {
|
|
458
|
-
return true;
|
|
459
|
-
}
|
|
460
|
-
const shouldSaveFile = await new untitled_workspace_exit_dialog_1.UntitledWorkspaceExitDialog({
|
|
461
|
-
title: nls_1.nls.localizeByDefault('Do you want to save your workspace configuration as a file?')
|
|
462
|
-
}).open();
|
|
463
|
-
if (shouldSaveFile === "Don't Save") {
|
|
464
|
-
return true;
|
|
465
|
-
}
|
|
466
|
-
else if (shouldSaveFile === 'Save') {
|
|
467
|
-
return this.saveWorkspaceAs();
|
|
468
|
-
}
|
|
469
|
-
return false; // If cancel, prevent exit.
|
|
470
|
-
},
|
|
471
|
-
reason: 'Untitled workspace.',
|
|
472
|
-
// Since deleting the workspace would hobble any future functionality, run this late.
|
|
473
|
-
priority: 100,
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
__decorate([
|
|
479
|
-
(0, inversify_1.inject)(common_1.MessageService),
|
|
480
|
-
__metadata("design:type", common_1.MessageService)
|
|
481
|
-
], WorkspaceFrontendContribution.prototype, "messageService", void 0);
|
|
482
|
-
__decorate([
|
|
483
|
-
(0, inversify_1.inject)(file_service_1.FileService),
|
|
484
|
-
__metadata("design:type", file_service_1.FileService)
|
|
485
|
-
], WorkspaceFrontendContribution.prototype, "fileService", void 0);
|
|
486
|
-
__decorate([
|
|
487
|
-
(0, inversify_1.inject)(browser_1.OpenerService),
|
|
488
|
-
__metadata("design:type", Object)
|
|
489
|
-
], WorkspaceFrontendContribution.prototype, "openerService", void 0);
|
|
490
|
-
__decorate([
|
|
491
|
-
(0, inversify_1.inject)(workspace_service_1.WorkspaceService),
|
|
492
|
-
__metadata("design:type", workspace_service_1.WorkspaceService)
|
|
493
|
-
], WorkspaceFrontendContribution.prototype, "workspaceService", void 0);
|
|
494
|
-
__decorate([
|
|
495
|
-
(0, inversify_1.inject)(quick_open_workspace_1.QuickOpenWorkspace),
|
|
496
|
-
__metadata("design:type", quick_open_workspace_1.QuickOpenWorkspace)
|
|
497
|
-
], WorkspaceFrontendContribution.prototype, "quickOpenWorkspace", void 0);
|
|
498
|
-
__decorate([
|
|
499
|
-
(0, inversify_1.inject)(browser_2.FileDialogService),
|
|
500
|
-
__metadata("design:type", Object)
|
|
501
|
-
], WorkspaceFrontendContribution.prototype, "fileDialogService", void 0);
|
|
502
|
-
__decorate([
|
|
503
|
-
(0, inversify_1.inject)(workspace_preferences_1.WorkspacePreferences),
|
|
504
|
-
__metadata("design:type", Object)
|
|
505
|
-
], WorkspaceFrontendContribution.prototype, "preferences", void 0);
|
|
506
|
-
__decorate([
|
|
507
|
-
(0, inversify_1.inject)(context_key_service_1.ContextKeyService),
|
|
508
|
-
__metadata("design:type", Object)
|
|
509
|
-
], WorkspaceFrontendContribution.prototype, "contextKeyService", void 0);
|
|
510
|
-
__decorate([
|
|
511
|
-
(0, inversify_1.inject)(encoding_registry_1.EncodingRegistry),
|
|
512
|
-
__metadata("design:type", encoding_registry_1.EncodingRegistry)
|
|
513
|
-
], WorkspaceFrontendContribution.prototype, "encodingRegistry", void 0);
|
|
514
|
-
__decorate([
|
|
515
|
-
(0, inversify_1.inject)(preference_configurations_1.PreferenceConfigurations),
|
|
516
|
-
__metadata("design:type", preference_configurations_1.PreferenceConfigurations)
|
|
517
|
-
], WorkspaceFrontendContribution.prototype, "preferenceConfigurations", void 0);
|
|
518
|
-
__decorate([
|
|
519
|
-
(0, inversify_1.inject)(filesystem_save_resource_service_1.FilesystemSaveResourceService),
|
|
520
|
-
__metadata("design:type", filesystem_save_resource_service_1.FilesystemSaveResourceService)
|
|
521
|
-
], WorkspaceFrontendContribution.prototype, "saveService", void 0);
|
|
522
|
-
WorkspaceFrontendContribution = WorkspaceFrontendContribution_1 = __decorate([
|
|
523
|
-
(0, inversify_1.injectable)()
|
|
524
|
-
], WorkspaceFrontendContribution);
|
|
525
|
-
exports.WorkspaceFrontendContribution = WorkspaceFrontendContribution;
|
|
526
|
-
(function (WorkspaceFrontendContribution) {
|
|
527
|
-
/**
|
|
528
|
-
* File filter for all Theia and VS Code workspace file types.
|
|
529
|
-
*/
|
|
530
|
-
WorkspaceFrontendContribution.DEFAULT_FILE_FILTER = {
|
|
531
|
-
'Theia Workspace (*.theia-workspace)': [common_2.THEIA_EXT],
|
|
532
|
-
'VS Code Workspace (*.code-workspace)': [common_2.VSCODE_EXT]
|
|
533
|
-
};
|
|
534
|
-
/**
|
|
535
|
-
* Returns with an `OpenFileDialogProps` for opening the `Open Workspace` dialog.
|
|
536
|
-
*/
|
|
537
|
-
function createOpenWorkspaceOpenFileDialogProps(options) {
|
|
538
|
-
const { electron, type } = options;
|
|
539
|
-
const title = workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE.dialogLabel;
|
|
540
|
-
// If browser
|
|
541
|
-
if (!electron) {
|
|
542
|
-
return {
|
|
543
|
-
title,
|
|
544
|
-
canSelectFiles: true,
|
|
545
|
-
canSelectFolders: true,
|
|
546
|
-
filters: WorkspaceFrontendContribution.DEFAULT_FILE_FILTER
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
// If electron
|
|
550
|
-
if (core_1.OS.Type.OSX === type) {
|
|
551
|
-
// `Finder` can select folders and files at the same time. We allow folders and workspace files.
|
|
552
|
-
return {
|
|
553
|
-
title,
|
|
554
|
-
canSelectFiles: true,
|
|
555
|
-
canSelectFolders: true,
|
|
556
|
-
filters: WorkspaceFrontendContribution.DEFAULT_FILE_FILTER
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
return {
|
|
560
|
-
title,
|
|
561
|
-
canSelectFiles: true,
|
|
562
|
-
canSelectFolders: false,
|
|
563
|
-
filters: WorkspaceFrontendContribution.DEFAULT_FILE_FILTER
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
WorkspaceFrontendContribution.createOpenWorkspaceOpenFileDialogProps = createOpenWorkspaceOpenFileDialogProps;
|
|
567
|
-
})(WorkspaceFrontendContribution = exports.WorkspaceFrontendContribution || (exports.WorkspaceFrontendContribution = {}));
|
|
568
|
-
exports.WorkspaceFrontendContribution = WorkspaceFrontendContribution;
|
|
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 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
|
+
var WorkspaceFrontendContribution_1;
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.WorkspaceFrontendContribution = exports.FILE_WORKSPACE = exports.WorkspaceStates = void 0;
|
|
29
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
30
|
+
const common_1 = require("@theia/core/lib/common");
|
|
31
|
+
const core_1 = require("@theia/core");
|
|
32
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
33
|
+
const browser_2 = require("@theia/filesystem/lib/browser");
|
|
34
|
+
const context_key_service_1 = require("@theia/core/lib/browser/context-key-service");
|
|
35
|
+
const workspace_service_1 = require("./workspace-service");
|
|
36
|
+
const common_2 = require("../common");
|
|
37
|
+
const workspace_commands_1 = require("./workspace-commands");
|
|
38
|
+
const quick_open_workspace_1 = require("./quick-open-workspace");
|
|
39
|
+
const workspace_preferences_1 = require("./workspace-preferences");
|
|
40
|
+
const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
|
|
41
|
+
const encoding_registry_1 = require("@theia/core/lib/browser/encoding-registry");
|
|
42
|
+
const encodings_1 = require("@theia/core/lib/common/encodings");
|
|
43
|
+
const disposable_1 = require("@theia/core/lib/common/disposable");
|
|
44
|
+
const preference_configurations_1 = require("@theia/core/lib/browser/preferences/preference-configurations");
|
|
45
|
+
const nls_1 = require("@theia/core/lib/common/nls");
|
|
46
|
+
const buffer_1 = require("@theia/core/lib/common/buffer");
|
|
47
|
+
const untitled_workspace_exit_dialog_1 = require("./untitled-workspace-exit-dialog");
|
|
48
|
+
const filesystem_save_resource_service_1 = require("@theia/filesystem/lib/browser/filesystem-save-resource-service");
|
|
49
|
+
const frontend_application_state_1 = require("@theia/core/lib/common/frontend-application-state");
|
|
50
|
+
var WorkspaceStates;
|
|
51
|
+
(function (WorkspaceStates) {
|
|
52
|
+
/**
|
|
53
|
+
* The state is `empty` when no workspace is opened.
|
|
54
|
+
*/
|
|
55
|
+
WorkspaceStates["empty"] = "empty";
|
|
56
|
+
/**
|
|
57
|
+
* The state is `workspace` when a workspace is opened.
|
|
58
|
+
*/
|
|
59
|
+
WorkspaceStates["workspace"] = "workspace";
|
|
60
|
+
/**
|
|
61
|
+
* The state is `folder` when a folder is opened. (1 folder)
|
|
62
|
+
*/
|
|
63
|
+
WorkspaceStates["folder"] = "folder";
|
|
64
|
+
})(WorkspaceStates = exports.WorkspaceStates || (exports.WorkspaceStates = {}));
|
|
65
|
+
;
|
|
66
|
+
/** Create the workspace section after open {@link CommonMenus.FILE_OPEN}. */
|
|
67
|
+
exports.FILE_WORKSPACE = [...browser_1.CommonMenus.FILE, '2_workspace'];
|
|
68
|
+
let WorkspaceFrontendContribution = WorkspaceFrontendContribution_1 = class WorkspaceFrontendContribution {
|
|
69
|
+
constructor() {
|
|
70
|
+
this.toDisposeOnUpdateEncodingOverrides = new disposable_1.DisposableCollection();
|
|
71
|
+
}
|
|
72
|
+
configure() {
|
|
73
|
+
this.encodingRegistry.registerOverride({ encoding: encodings_1.UTF8, extension: common_2.THEIA_EXT });
|
|
74
|
+
this.encodingRegistry.registerOverride({ encoding: encodings_1.UTF8, extension: common_2.VSCODE_EXT });
|
|
75
|
+
this.updateEncodingOverrides();
|
|
76
|
+
const workspaceFolderCountKey = this.contextKeyService.createKey('workspaceFolderCount', 0);
|
|
77
|
+
const updateWorkspaceFolderCountKey = () => workspaceFolderCountKey.set(this.workspaceService.tryGetRoots().length);
|
|
78
|
+
updateWorkspaceFolderCountKey();
|
|
79
|
+
const workspaceStateKey = this.contextKeyService.createKey('workspaceState', 'empty');
|
|
80
|
+
const updateWorkspaceStateKey = () => workspaceStateKey.set(this.updateWorkspaceStateKey());
|
|
81
|
+
updateWorkspaceStateKey();
|
|
82
|
+
const workbenchStateKey = this.contextKeyService.createKey('workbenchState', 'empty');
|
|
83
|
+
const updateWorkbenchStateKey = () => workbenchStateKey.set(this.updateWorkbenchStateKey());
|
|
84
|
+
updateWorkbenchStateKey();
|
|
85
|
+
this.updateStyles();
|
|
86
|
+
this.workspaceService.onWorkspaceChanged(() => {
|
|
87
|
+
this.updateEncodingOverrides();
|
|
88
|
+
updateWorkspaceFolderCountKey();
|
|
89
|
+
updateWorkspaceStateKey();
|
|
90
|
+
updateWorkbenchStateKey();
|
|
91
|
+
this.updateStyles();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
updateEncodingOverrides() {
|
|
95
|
+
this.toDisposeOnUpdateEncodingOverrides.dispose();
|
|
96
|
+
for (const root of this.workspaceService.tryGetRoots()) {
|
|
97
|
+
for (const configPath of this.preferenceConfigurations.getPaths()) {
|
|
98
|
+
const parent = root.resource.resolve(configPath);
|
|
99
|
+
this.toDisposeOnUpdateEncodingOverrides.push(this.encodingRegistry.registerOverride({ encoding: encodings_1.UTF8, parent }));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
updateStyles() {
|
|
104
|
+
document.body.classList.remove('theia-no-open-workspace');
|
|
105
|
+
// Display the 'no workspace opened' theme color when no folders are opened (single-root).
|
|
106
|
+
if (!this.workspaceService.isMultiRootWorkspaceOpened &&
|
|
107
|
+
!this.workspaceService.tryGetRoots().length) {
|
|
108
|
+
document.body.classList.add('theia-no-open-workspace');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
registerCommands(commands) {
|
|
112
|
+
// Not visible/enabled on Windows/Linux in electron.
|
|
113
|
+
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN, {
|
|
114
|
+
isEnabled: () => core_1.isOSX || !this.isElectron(),
|
|
115
|
+
isVisible: () => core_1.isOSX || !this.isElectron(),
|
|
116
|
+
execute: () => this.doOpen()
|
|
117
|
+
});
|
|
118
|
+
// Visible/enabled only on Windows/Linux in electron.
|
|
119
|
+
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_FILE, {
|
|
120
|
+
isEnabled: () => true,
|
|
121
|
+
execute: () => this.doOpenFile()
|
|
122
|
+
});
|
|
123
|
+
// Visible/enabled only on Windows/Linux in electron.
|
|
124
|
+
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_FOLDER, {
|
|
125
|
+
isEnabled: () => true,
|
|
126
|
+
execute: () => this.doOpenFolder()
|
|
127
|
+
});
|
|
128
|
+
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE, {
|
|
129
|
+
isEnabled: () => true,
|
|
130
|
+
execute: () => this.doOpenWorkspace()
|
|
131
|
+
});
|
|
132
|
+
commands.registerCommand(workspace_commands_1.WorkspaceCommands.CLOSE, {
|
|
133
|
+
isEnabled: () => this.workspaceService.opened,
|
|
134
|
+
execute: () => this.closeWorkspace()
|
|
135
|
+
});
|
|
136
|
+
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_RECENT_WORKSPACE, {
|
|
137
|
+
execute: () => this.quickOpenWorkspace.select()
|
|
138
|
+
});
|
|
139
|
+
commands.registerCommand(workspace_commands_1.WorkspaceCommands.SAVE_WORKSPACE_AS, {
|
|
140
|
+
isVisible: () => this.workspaceService.opened,
|
|
141
|
+
isEnabled: () => this.workspaceService.opened,
|
|
142
|
+
execute: () => this.saveWorkspaceAs()
|
|
143
|
+
});
|
|
144
|
+
commands.registerCommand(workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE_FILE, {
|
|
145
|
+
isEnabled: () => this.workspaceService.saved,
|
|
146
|
+
execute: () => {
|
|
147
|
+
if (this.workspaceService.saved && this.workspaceService.workspace) {
|
|
148
|
+
(0, browser_1.open)(this.openerService, this.workspaceService.workspace.resource);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
registerMenus(menus) {
|
|
154
|
+
if (core_1.isOSX || !this.isElectron()) {
|
|
155
|
+
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
156
|
+
commandId: workspace_commands_1.WorkspaceCommands.OPEN.id,
|
|
157
|
+
order: 'a00'
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
if (!core_1.isOSX && this.isElectron()) {
|
|
161
|
+
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
162
|
+
commandId: workspace_commands_1.WorkspaceCommands.OPEN_FILE.id,
|
|
163
|
+
label: `${workspace_commands_1.WorkspaceCommands.OPEN_FILE.dialogLabel}...`,
|
|
164
|
+
order: 'a01'
|
|
165
|
+
});
|
|
166
|
+
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
167
|
+
commandId: workspace_commands_1.WorkspaceCommands.OPEN_FOLDER.id,
|
|
168
|
+
label: `${workspace_commands_1.WorkspaceCommands.OPEN_FOLDER.dialogLabel}...`,
|
|
169
|
+
order: 'a02'
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
173
|
+
commandId: workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE.id,
|
|
174
|
+
order: 'a10'
|
|
175
|
+
});
|
|
176
|
+
menus.registerMenuAction(browser_1.CommonMenus.FILE_OPEN, {
|
|
177
|
+
commandId: workspace_commands_1.WorkspaceCommands.OPEN_RECENT_WORKSPACE.id,
|
|
178
|
+
order: 'a20'
|
|
179
|
+
});
|
|
180
|
+
menus.registerMenuAction(exports.FILE_WORKSPACE, {
|
|
181
|
+
commandId: workspace_commands_1.WorkspaceCommands.ADD_FOLDER.id,
|
|
182
|
+
order: 'a10'
|
|
183
|
+
});
|
|
184
|
+
menus.registerMenuAction(exports.FILE_WORKSPACE, {
|
|
185
|
+
commandId: workspace_commands_1.WorkspaceCommands.SAVE_WORKSPACE_AS.id,
|
|
186
|
+
order: 'a20'
|
|
187
|
+
});
|
|
188
|
+
menus.registerMenuAction(browser_1.CommonMenus.FILE_CLOSE, {
|
|
189
|
+
commandId: workspace_commands_1.WorkspaceCommands.CLOSE.id
|
|
190
|
+
});
|
|
191
|
+
menus.registerMenuAction(browser_1.CommonMenus.FILE_SAVE, {
|
|
192
|
+
commandId: workspace_commands_1.WorkspaceCommands.SAVE_AS.id,
|
|
193
|
+
});
|
|
194
|
+
menus.registerMenuAction(browser_1.SHELL_TABBAR_CONTEXT_COPY, {
|
|
195
|
+
commandId: workspace_commands_1.WorkspaceCommands.COPY_RELATIVE_FILE_PATH.id,
|
|
196
|
+
label: workspace_commands_1.WorkspaceCommands.COPY_RELATIVE_FILE_PATH.label,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
registerKeybindings(keybindings) {
|
|
200
|
+
keybindings.registerKeybinding({
|
|
201
|
+
command: core_1.isOSX || !this.isElectron() ? workspace_commands_1.WorkspaceCommands.OPEN.id : workspace_commands_1.WorkspaceCommands.OPEN_FILE.id,
|
|
202
|
+
keybinding: this.isElectron() ? 'ctrlcmd+o' : 'ctrlcmd+alt+o',
|
|
203
|
+
});
|
|
204
|
+
if (!core_1.isOSX && this.isElectron()) {
|
|
205
|
+
keybindings.registerKeybinding({
|
|
206
|
+
command: workspace_commands_1.WorkspaceCommands.OPEN_FOLDER.id,
|
|
207
|
+
keybinding: 'ctrl+k ctrl+o',
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
keybindings.registerKeybinding({
|
|
211
|
+
command: workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE.id,
|
|
212
|
+
keybinding: 'ctrlcmd+alt+w',
|
|
213
|
+
});
|
|
214
|
+
keybindings.registerKeybinding({
|
|
215
|
+
command: workspace_commands_1.WorkspaceCommands.OPEN_RECENT_WORKSPACE.id,
|
|
216
|
+
keybinding: 'ctrlcmd+alt+r',
|
|
217
|
+
});
|
|
218
|
+
keybindings.registerKeybinding({
|
|
219
|
+
command: workspace_commands_1.WorkspaceCommands.SAVE_AS.id,
|
|
220
|
+
keybinding: 'ctrlcmd+shift+s',
|
|
221
|
+
});
|
|
222
|
+
keybindings.registerKeybinding({
|
|
223
|
+
command: workspace_commands_1.WorkspaceCommands.COPY_RELATIVE_FILE_PATH.id,
|
|
224
|
+
keybinding: common_1.isWindows ? 'ctrl+k ctrl+shift+c' : 'ctrlcmd+shift+alt+c',
|
|
225
|
+
when: '!editorFocus'
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* This is the generic `Open` method. Opens files and directories too. Resolves to the opened URI.
|
|
230
|
+
* Except when you are on either Windows or Linux `AND` running in electron. If so, it opens a file.
|
|
231
|
+
*/
|
|
232
|
+
async doOpen() {
|
|
233
|
+
var _a;
|
|
234
|
+
if (!core_1.isOSX && this.isElectron()) {
|
|
235
|
+
return this.doOpenFile();
|
|
236
|
+
}
|
|
237
|
+
const [rootStat] = await this.workspaceService.roots;
|
|
238
|
+
const destinationUri = await this.fileDialogService.showOpenDialog({
|
|
239
|
+
title: workspace_commands_1.WorkspaceCommands.OPEN.dialogLabel,
|
|
240
|
+
canSelectFolders: true,
|
|
241
|
+
canSelectFiles: true
|
|
242
|
+
}, rootStat);
|
|
243
|
+
if (destinationUri && ((_a = this.getCurrentWorkspaceUri()) === null || _a === void 0 ? void 0 : _a.toString()) !== destinationUri.toString()) {
|
|
244
|
+
const destination = await this.fileService.resolve(destinationUri);
|
|
245
|
+
if (destination.isDirectory) {
|
|
246
|
+
this.workspaceService.open(destinationUri);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
await (0, browser_1.open)(this.openerService, destinationUri);
|
|
250
|
+
}
|
|
251
|
+
return destinationUri;
|
|
252
|
+
}
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Opens a file after prompting the `Open File` dialog. Resolves to `undefined`, if
|
|
257
|
+
* - the workspace root is not set,
|
|
258
|
+
* - the file to open does not exist, or
|
|
259
|
+
* - it was not a file, but a directory.
|
|
260
|
+
*
|
|
261
|
+
* Otherwise, resolves to the URI of the file.
|
|
262
|
+
*/
|
|
263
|
+
async doOpenFile() {
|
|
264
|
+
const props = {
|
|
265
|
+
title: workspace_commands_1.WorkspaceCommands.OPEN_FILE.dialogLabel,
|
|
266
|
+
canSelectFolders: false,
|
|
267
|
+
canSelectFiles: true
|
|
268
|
+
};
|
|
269
|
+
const [rootStat] = await this.workspaceService.roots;
|
|
270
|
+
const destinationFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
|
|
271
|
+
if (destinationFileUri) {
|
|
272
|
+
const destinationFile = await this.fileService.resolve(destinationFileUri);
|
|
273
|
+
if (!destinationFile.isDirectory) {
|
|
274
|
+
await (0, browser_1.open)(this.openerService, destinationFileUri);
|
|
275
|
+
return destinationFileUri;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Opens one or more folders after prompting the `Open Folder` dialog. Resolves to `undefined`, if
|
|
282
|
+
* - the user's selection is empty or contains only files.
|
|
283
|
+
* - the new workspace is equal to the old workspace.
|
|
284
|
+
*
|
|
285
|
+
* Otherwise, resolves to the URI of the new workspace:
|
|
286
|
+
* - a single folder if a single folder was selected.
|
|
287
|
+
* - a new, untitled workspace file if multiple folders were selected.
|
|
288
|
+
*/
|
|
289
|
+
async doOpenFolder() {
|
|
290
|
+
const props = {
|
|
291
|
+
title: workspace_commands_1.WorkspaceCommands.OPEN_FOLDER.dialogLabel,
|
|
292
|
+
canSelectFolders: true,
|
|
293
|
+
canSelectFiles: false,
|
|
294
|
+
canSelectMany: true,
|
|
295
|
+
};
|
|
296
|
+
const [rootStat] = await this.workspaceService.roots;
|
|
297
|
+
const targetFolders = await this.fileDialogService.showOpenDialog(props, rootStat);
|
|
298
|
+
if (targetFolders) {
|
|
299
|
+
const openableURI = await this.getOpenableWorkspaceUri(targetFolders);
|
|
300
|
+
if (openableURI) {
|
|
301
|
+
if (!this.workspaceService.workspace || !openableURI.isEqual(this.workspaceService.workspace.resource)) {
|
|
302
|
+
this.workspaceService.open(openableURI);
|
|
303
|
+
return openableURI;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
;
|
|
307
|
+
}
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
async getOpenableWorkspaceUri(uris) {
|
|
311
|
+
if (Array.isArray(uris)) {
|
|
312
|
+
if (uris.length < 2) {
|
|
313
|
+
return uris[0];
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
const foldersToOpen = (await Promise.all(uris.map(uri => this.fileService.resolve(uri))))
|
|
317
|
+
.filter(fileStat => !!(fileStat === null || fileStat === void 0 ? void 0 : fileStat.isDirectory));
|
|
318
|
+
if (foldersToOpen.length === 1) {
|
|
319
|
+
return foldersToOpen[0].resource;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
return this.createMultiRootWorkspace(foldersToOpen);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
return uris;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async createMultiRootWorkspace(roots) {
|
|
331
|
+
const untitledWorkspace = await this.workspaceService.getUntitledWorkspace();
|
|
332
|
+
const folders = Array.from(new Set(roots.map(stat => stat.resource.path.toString())), path => ({ path }));
|
|
333
|
+
const workspaceStat = await this.fileService.createFile(untitledWorkspace, buffer_1.BinaryBuffer.fromString(JSON.stringify({ folders }, null, 4)), // eslint-disable-line no-null/no-null
|
|
334
|
+
{ overwrite: true });
|
|
335
|
+
return workspaceStat.resource;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Opens a workspace after raising the `Open Workspace` dialog. Resolves to the URI of the recently opened workspace,
|
|
339
|
+
* if it was successful. Otherwise, resolves to `undefined`.
|
|
340
|
+
*
|
|
341
|
+
* **Caveat**: this behaves differently on different platforms
|
|
342
|
+
* and `electron`/`browser` version has impact too. See [here](https://github.com/eclipse-theia/theia/pull/3202#issuecomment-430884195) for more details.
|
|
343
|
+
*
|
|
344
|
+
* Legend:
|
|
345
|
+
* - Folders only: => `F`
|
|
346
|
+
* - Workspace files only: => `W`
|
|
347
|
+
* - Folders and workspace files: => `FW`
|
|
348
|
+
*
|
|
349
|
+
* -----
|
|
350
|
+
*
|
|
351
|
+
* |---------|-----------|-----------|------------|------------|
|
|
352
|
+
* | | browser Y | browser N | electron Y | electron N |
|
|
353
|
+
* |---------|-----------|-----------|------------|------------|
|
|
354
|
+
* | Linux | FW | F | W | F |
|
|
355
|
+
* | Windows | FW | F | W | F |
|
|
356
|
+
* | OS X | FW | F | FW | FW |
|
|
357
|
+
* |---------|-----------|-----------|------------|------------|
|
|
358
|
+
*
|
|
359
|
+
*/
|
|
360
|
+
async doOpenWorkspace() {
|
|
361
|
+
var _a;
|
|
362
|
+
const props = await this.openWorkspaceOpenFileDialogProps();
|
|
363
|
+
const [rootStat] = await this.workspaceService.roots;
|
|
364
|
+
const workspaceFolderOrWorkspaceFileUri = await this.fileDialogService.showOpenDialog(props, rootStat);
|
|
365
|
+
if (workspaceFolderOrWorkspaceFileUri &&
|
|
366
|
+
((_a = this.getCurrentWorkspaceUri()) === null || _a === void 0 ? void 0 : _a.toString()) !== workspaceFolderOrWorkspaceFileUri.toString()) {
|
|
367
|
+
const destinationFolder = await this.fileService.exists(workspaceFolderOrWorkspaceFileUri);
|
|
368
|
+
if (destinationFolder) {
|
|
369
|
+
this.workspaceService.open(workspaceFolderOrWorkspaceFileUri);
|
|
370
|
+
return workspaceFolderOrWorkspaceFileUri;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
async openWorkspaceOpenFileDialogProps() {
|
|
376
|
+
await this.preferences.ready;
|
|
377
|
+
const type = core_1.OS.type();
|
|
378
|
+
const electron = this.isElectron();
|
|
379
|
+
return WorkspaceFrontendContribution_1.createOpenWorkspaceOpenFileDialogProps({
|
|
380
|
+
type,
|
|
381
|
+
electron,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
async closeWorkspace() {
|
|
385
|
+
await this.workspaceService.close();
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* @returns whether the file was successfully saved.
|
|
389
|
+
*/
|
|
390
|
+
async saveWorkspaceAs() {
|
|
391
|
+
let exist = false;
|
|
392
|
+
let overwrite = false;
|
|
393
|
+
let selected;
|
|
394
|
+
do {
|
|
395
|
+
selected = await this.fileDialogService.showSaveDialog({
|
|
396
|
+
title: workspace_commands_1.WorkspaceCommands.SAVE_WORKSPACE_AS.label,
|
|
397
|
+
filters: WorkspaceFrontendContribution_1.DEFAULT_FILE_FILTER
|
|
398
|
+
});
|
|
399
|
+
if (selected) {
|
|
400
|
+
const displayName = selected.displayName;
|
|
401
|
+
if (!displayName.endsWith(`.${common_2.THEIA_EXT}`) && !displayName.endsWith(`.${common_2.VSCODE_EXT}`)) {
|
|
402
|
+
selected = selected.parent.resolve(`${displayName}.${common_2.THEIA_EXT}`);
|
|
403
|
+
}
|
|
404
|
+
exist = await this.fileService.exists(selected);
|
|
405
|
+
if (exist) {
|
|
406
|
+
overwrite = await this.saveService.confirmOverwrite(selected);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
} while (selected && exist && !overwrite);
|
|
410
|
+
if (selected) {
|
|
411
|
+
try {
|
|
412
|
+
await this.workspaceService.save(selected);
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
catch (_a) {
|
|
416
|
+
this.messageService.error(nls_1.nls.localizeByDefault("Unable to save workspace '{0}'", selected.path.fsPath()));
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
canBeSavedAs(widget) {
|
|
422
|
+
return this.saveService.canSaveAs(widget);
|
|
423
|
+
}
|
|
424
|
+
async saveAs(widget) {
|
|
425
|
+
return this.saveService.saveAs(widget);
|
|
426
|
+
}
|
|
427
|
+
updateWorkspaceStateKey() {
|
|
428
|
+
return this.doUpdateState();
|
|
429
|
+
}
|
|
430
|
+
updateWorkbenchStateKey() {
|
|
431
|
+
return this.doUpdateState();
|
|
432
|
+
}
|
|
433
|
+
doUpdateState() {
|
|
434
|
+
if (this.workspaceService.opened) {
|
|
435
|
+
return this.workspaceService.isMultiRootWorkspaceOpened ? 'workspace' : 'folder';
|
|
436
|
+
}
|
|
437
|
+
return 'empty';
|
|
438
|
+
}
|
|
439
|
+
isElectron() {
|
|
440
|
+
return core_1.environment.electron.is();
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Get the current workspace URI.
|
|
444
|
+
*
|
|
445
|
+
* @returns the current workspace URI.
|
|
446
|
+
*/
|
|
447
|
+
getCurrentWorkspaceUri() {
|
|
448
|
+
var _a;
|
|
449
|
+
return (_a = this.workspaceService.workspace) === null || _a === void 0 ? void 0 : _a.resource;
|
|
450
|
+
}
|
|
451
|
+
onWillStop() {
|
|
452
|
+
const { workspace } = this.workspaceService;
|
|
453
|
+
if (workspace && this.workspaceService.isUntitledWorkspace(workspace.resource)) {
|
|
454
|
+
return {
|
|
455
|
+
prepare: async (reason) => reason === frontend_application_state_1.StopReason.Reload && this.workspaceService.isSafeToReload(workspace.resource),
|
|
456
|
+
action: async (alreadyConfirmedSafe) => {
|
|
457
|
+
if (alreadyConfirmedSafe) {
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
const shouldSaveFile = await new untitled_workspace_exit_dialog_1.UntitledWorkspaceExitDialog({
|
|
461
|
+
title: nls_1.nls.localizeByDefault('Do you want to save your workspace configuration as a file?')
|
|
462
|
+
}).open();
|
|
463
|
+
if (shouldSaveFile === "Don't Save") {
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
else if (shouldSaveFile === 'Save') {
|
|
467
|
+
return this.saveWorkspaceAs();
|
|
468
|
+
}
|
|
469
|
+
return false; // If cancel, prevent exit.
|
|
470
|
+
},
|
|
471
|
+
reason: 'Untitled workspace.',
|
|
472
|
+
// Since deleting the workspace would hobble any future functionality, run this late.
|
|
473
|
+
priority: 100,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
__decorate([
|
|
479
|
+
(0, inversify_1.inject)(common_1.MessageService),
|
|
480
|
+
__metadata("design:type", common_1.MessageService)
|
|
481
|
+
], WorkspaceFrontendContribution.prototype, "messageService", void 0);
|
|
482
|
+
__decorate([
|
|
483
|
+
(0, inversify_1.inject)(file_service_1.FileService),
|
|
484
|
+
__metadata("design:type", file_service_1.FileService)
|
|
485
|
+
], WorkspaceFrontendContribution.prototype, "fileService", void 0);
|
|
486
|
+
__decorate([
|
|
487
|
+
(0, inversify_1.inject)(browser_1.OpenerService),
|
|
488
|
+
__metadata("design:type", Object)
|
|
489
|
+
], WorkspaceFrontendContribution.prototype, "openerService", void 0);
|
|
490
|
+
__decorate([
|
|
491
|
+
(0, inversify_1.inject)(workspace_service_1.WorkspaceService),
|
|
492
|
+
__metadata("design:type", workspace_service_1.WorkspaceService)
|
|
493
|
+
], WorkspaceFrontendContribution.prototype, "workspaceService", void 0);
|
|
494
|
+
__decorate([
|
|
495
|
+
(0, inversify_1.inject)(quick_open_workspace_1.QuickOpenWorkspace),
|
|
496
|
+
__metadata("design:type", quick_open_workspace_1.QuickOpenWorkspace)
|
|
497
|
+
], WorkspaceFrontendContribution.prototype, "quickOpenWorkspace", void 0);
|
|
498
|
+
__decorate([
|
|
499
|
+
(0, inversify_1.inject)(browser_2.FileDialogService),
|
|
500
|
+
__metadata("design:type", Object)
|
|
501
|
+
], WorkspaceFrontendContribution.prototype, "fileDialogService", void 0);
|
|
502
|
+
__decorate([
|
|
503
|
+
(0, inversify_1.inject)(workspace_preferences_1.WorkspacePreferences),
|
|
504
|
+
__metadata("design:type", Object)
|
|
505
|
+
], WorkspaceFrontendContribution.prototype, "preferences", void 0);
|
|
506
|
+
__decorate([
|
|
507
|
+
(0, inversify_1.inject)(context_key_service_1.ContextKeyService),
|
|
508
|
+
__metadata("design:type", Object)
|
|
509
|
+
], WorkspaceFrontendContribution.prototype, "contextKeyService", void 0);
|
|
510
|
+
__decorate([
|
|
511
|
+
(0, inversify_1.inject)(encoding_registry_1.EncodingRegistry),
|
|
512
|
+
__metadata("design:type", encoding_registry_1.EncodingRegistry)
|
|
513
|
+
], WorkspaceFrontendContribution.prototype, "encodingRegistry", void 0);
|
|
514
|
+
__decorate([
|
|
515
|
+
(0, inversify_1.inject)(preference_configurations_1.PreferenceConfigurations),
|
|
516
|
+
__metadata("design:type", preference_configurations_1.PreferenceConfigurations)
|
|
517
|
+
], WorkspaceFrontendContribution.prototype, "preferenceConfigurations", void 0);
|
|
518
|
+
__decorate([
|
|
519
|
+
(0, inversify_1.inject)(filesystem_save_resource_service_1.FilesystemSaveResourceService),
|
|
520
|
+
__metadata("design:type", filesystem_save_resource_service_1.FilesystemSaveResourceService)
|
|
521
|
+
], WorkspaceFrontendContribution.prototype, "saveService", void 0);
|
|
522
|
+
WorkspaceFrontendContribution = WorkspaceFrontendContribution_1 = __decorate([
|
|
523
|
+
(0, inversify_1.injectable)()
|
|
524
|
+
], WorkspaceFrontendContribution);
|
|
525
|
+
exports.WorkspaceFrontendContribution = WorkspaceFrontendContribution;
|
|
526
|
+
(function (WorkspaceFrontendContribution) {
|
|
527
|
+
/**
|
|
528
|
+
* File filter for all Theia and VS Code workspace file types.
|
|
529
|
+
*/
|
|
530
|
+
WorkspaceFrontendContribution.DEFAULT_FILE_FILTER = {
|
|
531
|
+
'Theia Workspace (*.theia-workspace)': [common_2.THEIA_EXT],
|
|
532
|
+
'VS Code Workspace (*.code-workspace)': [common_2.VSCODE_EXT]
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* Returns with an `OpenFileDialogProps` for opening the `Open Workspace` dialog.
|
|
536
|
+
*/
|
|
537
|
+
function createOpenWorkspaceOpenFileDialogProps(options) {
|
|
538
|
+
const { electron, type } = options;
|
|
539
|
+
const title = workspace_commands_1.WorkspaceCommands.OPEN_WORKSPACE.dialogLabel;
|
|
540
|
+
// If browser
|
|
541
|
+
if (!electron) {
|
|
542
|
+
return {
|
|
543
|
+
title,
|
|
544
|
+
canSelectFiles: true,
|
|
545
|
+
canSelectFolders: true,
|
|
546
|
+
filters: WorkspaceFrontendContribution.DEFAULT_FILE_FILTER
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
// If electron
|
|
550
|
+
if (core_1.OS.Type.OSX === type) {
|
|
551
|
+
// `Finder` can select folders and files at the same time. We allow folders and workspace files.
|
|
552
|
+
return {
|
|
553
|
+
title,
|
|
554
|
+
canSelectFiles: true,
|
|
555
|
+
canSelectFolders: true,
|
|
556
|
+
filters: WorkspaceFrontendContribution.DEFAULT_FILE_FILTER
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
title,
|
|
561
|
+
canSelectFiles: true,
|
|
562
|
+
canSelectFolders: false,
|
|
563
|
+
filters: WorkspaceFrontendContribution.DEFAULT_FILE_FILTER
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
WorkspaceFrontendContribution.createOpenWorkspaceOpenFileDialogProps = createOpenWorkspaceOpenFileDialogProps;
|
|
567
|
+
})(WorkspaceFrontendContribution = exports.WorkspaceFrontendContribution || (exports.WorkspaceFrontendContribution = {}));
|
|
568
|
+
exports.WorkspaceFrontendContribution = WorkspaceFrontendContribution;
|
|
569
569
|
//# sourceMappingURL=workspace-frontend-contribution.js.map
|