@codingame/monaco-vscode-user-data-profile-service-override 6.0.3 → 7.0.1

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.
@@ -5,9 +5,9 @@ import { ThemeIcon } from 'vscode/vscode/vs/base/common/themables';
5
5
  import { localizeWithPath } from 'vscode/vscode/vs/nls';
6
6
  import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
7
7
  import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry.service';
8
- import { ProfileResourceType, toUserDataProfile, isUserDataProfile } from 'vscode/vscode/vs/platform/userDataProfile/common/userDataProfile';
8
+ import { ProfileResourceType, isUserDataProfile, toUserDataProfile } from 'vscode/vscode/vs/platform/userDataProfile/common/userDataProfile';
9
9
  import { IUserDataProfilesService } from 'vscode/vscode/vs/platform/userDataProfile/common/userDataProfile.service';
10
- import { IUserDataProfileService, IUserDataProfileManagementService, IUserDataProfileImportExportService } from 'vscode/vscode/vs/workbench/services/userDataProfile/common/userDataProfile.service';
10
+ import { IUserDataProfileManagementService, IUserDataProfileService, IUserDataProfileImportExportService } from 'vscode/vscode/vs/workbench/services/userDataProfile/common/userDataProfile.service';
11
11
  import { Disposable, toDisposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
12
12
  import { URI } from 'vscode/vscode/vs/base/common/uri';
13
13
  import { equals } from 'vscode/vscode/vs/base/common/objects';
@@ -22,19 +22,36 @@ import { IDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs
22
22
  import { InMemoryFileSystemProvider } from 'vscode/vscode/vs/platform/files/common/inMemoryFilesystemProvider';
23
23
  import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
24
24
  import { generateUuid } from 'vscode/vscode/vs/base/common/uuid';
25
- import { RunOnceScheduler } from 'vscode/vscode/vs/base/common/async';
25
+ import { RunOnceScheduler, createCancelablePromise } from 'vscode/vscode/vs/base/common/async';
26
+ import { IHostService } from 'vscode/vscode/vs/workbench/services/host/browser/host.service';
27
+ import { CancellationTokenSource, CancellationToken } from 'vscode/vscode/vs/base/common/cancellation';
28
+ import { API_OPEN_EDITOR_COMMAND_ID } from 'vscode/vscode/vs/workbench/browser/parts/editor/editorCommands';
29
+ import { SIDE_GROUP } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
30
+ import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands.service';
31
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
32
+ import { CONFIG_NEW_WINDOW_PROFILE } from 'vscode/vscode/vs/workbench/common/configuration';
26
33
 
27
34
  var UserDataProfilesEditorModel_1;
28
35
  const _moduleId = "vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel";
36
+ function isProfileResourceTypeElement(element) {
37
+ return element.resourceType !== undefined;
38
+ }
39
+ function isProfileResourceChildElement(element) {
40
+ return element.label !== undefined;
41
+ }
29
42
  let AbstractUserDataProfileElement = class AbstractUserDataProfileElement extends Disposable {
30
- constructor(name, icon, flags, isActive, userDataProfilesService, instantiationService) {
43
+ constructor(name, icon, flags, isActive, userDataProfileManagementService, userDataProfilesService, commandService, instantiationService) {
31
44
  super();
45
+ this.userDataProfileManagementService = userDataProfileManagementService;
32
46
  this.userDataProfilesService = userDataProfilesService;
47
+ this.commandService = commandService;
33
48
  this.instantiationService = instantiationService;
34
49
  this._onDidChange = this._register(( (new Emitter())));
35
50
  this.onDidChange = this._onDidChange.event;
51
+ this.saveScheduler = this._register(( (new RunOnceScheduler(() => this.doSave(), 500))));
36
52
  this._name = '';
37
53
  this._active = false;
54
+ this._disabled = false;
38
55
  this._name = name;
39
56
  this._icon = icon;
40
57
  this._flags = flags;
@@ -43,15 +60,14 @@ let AbstractUserDataProfileElement = class AbstractUserDataProfileElement extend
43
60
  if (!e.message) {
44
61
  this.validate();
45
62
  }
46
- if (this.primaryAction) {
47
- this.primaryAction.enabled = !this.message;
48
- }
63
+ this.save();
49
64
  }));
50
65
  }
51
66
  get name() { return this._name; }
52
- set name(label) {
53
- if (this._name !== label) {
54
- this._name = label;
67
+ set name(name) {
68
+ name = name.trim();
69
+ if (this._name !== name) {
70
+ this._name = name;
55
71
  this._onDidChange.fire({ name: true });
56
72
  }
57
73
  }
@@ -83,6 +99,13 @@ let AbstractUserDataProfileElement = class AbstractUserDataProfileElement extend
83
99
  this._onDidChange.fire({ message: true });
84
100
  }
85
101
  }
102
+ get disabled() { return this._disabled; }
103
+ set disabled(saving) {
104
+ if (this._disabled !== saving) {
105
+ this._disabled = saving;
106
+ this._onDidChange.fire({ disabled: true });
107
+ }
108
+ }
86
109
  getFlag(key) {
87
110
  return this.flags?.[key] ?? false;
88
111
  }
@@ -112,43 +135,133 @@ let AbstractUserDataProfileElement = class AbstractUserDataProfileElement extend
112
135
  this.message = undefined;
113
136
  }
114
137
  async getChildren(resourceType) {
138
+ if (resourceType === undefined) {
139
+ const resourceTypes = [
140
+ ProfileResourceType.Settings,
141
+ ProfileResourceType.Keybindings,
142
+ ProfileResourceType.Tasks,
143
+ ProfileResourceType.Snippets,
144
+ ProfileResourceType.Extensions
145
+ ];
146
+ return Promise.all(( (resourceTypes.map(async (r) => {
147
+ const children = (r === ProfileResourceType.Settings
148
+ || r === ProfileResourceType.Keybindings
149
+ || r === ProfileResourceType.Tasks) ? await this.getChildrenForResourceType(r) : [];
150
+ return {
151
+ handle: r,
152
+ checkbox: undefined,
153
+ resourceType: r,
154
+ action: children.length
155
+ ? ( (new Action('_open', ( localizeWithPath(_moduleId, 3, "Open to the Side")), ThemeIcon.asClassName(Codicon.goToFile), true, () => children[0]?.action?.run())))
156
+ : undefined
157
+ };
158
+ }))));
159
+ }
160
+ return this.getChildrenForResourceType(resourceType);
161
+ }
162
+ async getChildrenForResourceType(resourceType) {
115
163
  return [];
116
164
  }
117
165
  async getChildrenFromProfile(profile, resourceType) {
118
166
  profile = this.getFlag(resourceType) ? this.userDataProfilesService.defaultProfile : profile;
167
+ let children = [];
119
168
  switch (resourceType) {
120
169
  case ProfileResourceType.Settings:
121
- return this.instantiationService.createInstance(SettingsResourceTreeItem, profile).getChildren();
170
+ children = await this.instantiationService.createInstance(SettingsResourceTreeItem, profile).getChildren();
171
+ break;
122
172
  case ProfileResourceType.Keybindings:
123
- return this.instantiationService.createInstance(KeybindingsResourceTreeItem, profile).getChildren();
173
+ children = await this.instantiationService.createInstance(KeybindingsResourceTreeItem, profile).getChildren();
174
+ break;
124
175
  case ProfileResourceType.Snippets:
125
- return (await this.instantiationService.createInstance(SnippetsResourceTreeItem, profile).getChildren()) ?? [];
176
+ children = (await this.instantiationService.createInstance(SnippetsResourceTreeItem, profile).getChildren()) ?? [];
177
+ break;
126
178
  case ProfileResourceType.Tasks:
127
- return this.instantiationService.createInstance(TasksResourceTreeItem, profile).getChildren();
179
+ children = await this.instantiationService.createInstance(TasksResourceTreeItem, profile).getChildren();
180
+ break;
128
181
  case ProfileResourceType.Extensions:
129
- return this.instantiationService.createInstance(ExtensionsResourceExportTreeItem, profile).getChildren();
130
- }
131
- return [];
182
+ children = await this.instantiationService.createInstance(ExtensionsResourceExportTreeItem, profile).getChildren();
183
+ break;
184
+ }
185
+ return (
186
+ (children.map(child => this.toUserDataProfileResourceChildElement(child)))
187
+ );
188
+ }
189
+ toUserDataProfileResourceChildElement(child) {
190
+ return {
191
+ handle: child.handle,
192
+ checkbox: child.checkbox,
193
+ label: child.label?.label ?? '',
194
+ resource: URI.revive(child.resourceUri),
195
+ icon: child.themeIcon,
196
+ action: ( (new Action('_openChild', ( localizeWithPath(_moduleId, 3, "Open to the Side")), ThemeIcon.asClassName(Codicon.goToFile), true, async () => {
197
+ if (child.parent.type === ProfileResourceType.Extensions) {
198
+ await this.commandService.executeCommand('extension.open', child.handle, undefined, true, undefined, true);
199
+ }
200
+ else if (child.resourceUri) {
201
+ await this.commandService.executeCommand(API_OPEN_EDITOR_COMMAND_ID, child.resourceUri, [SIDE_GROUP], undefined);
202
+ }
203
+ })))
204
+ };
132
205
  }
133
206
  getInitialName() {
134
207
  return '';
135
208
  }
209
+ save() {
210
+ this.saveScheduler.schedule();
211
+ }
212
+ hasUnsavedChanges(profile) {
213
+ if (this.name !== profile.name) {
214
+ return true;
215
+ }
216
+ if (this.icon !== profile.icon) {
217
+ return true;
218
+ }
219
+ if (!equals(this.flags ?? {}, profile.useDefaultFlags ?? {})) {
220
+ return true;
221
+ }
222
+ return false;
223
+ }
224
+ async saveProfile(profile) {
225
+ if (!this.hasUnsavedChanges(profile)) {
226
+ return;
227
+ }
228
+ this.validate();
229
+ if (this.message) {
230
+ return;
231
+ }
232
+ const useDefaultFlags = this.flags
233
+ ? this.flags.settings && this.flags.keybindings && this.flags.tasks && this.flags.globalState && this.flags.extensions ? undefined : this.flags
234
+ : undefined;
235
+ return await this.userDataProfileManagementService.updateProfile(profile, {
236
+ name: this.name,
237
+ icon: this.icon,
238
+ useDefaultFlags: profile.useDefaultFlags && !useDefaultFlags ? {} : useDefaultFlags
239
+ });
240
+ }
136
241
  };
137
242
  AbstractUserDataProfileElement = ( (__decorate([
138
- ( (__param(4, IUserDataProfilesService))),
139
- ( (__param(5, IInstantiationService)))
243
+ ( (__param(4, IUserDataProfileManagementService))),
244
+ ( (__param(5, IUserDataProfilesService))),
245
+ ( (__param(6, ICommandService))),
246
+ ( (__param(7, IInstantiationService)))
140
247
  ], AbstractUserDataProfileElement)));
141
248
  let UserDataProfileElement = class UserDataProfileElement extends AbstractUserDataProfileElement {
142
249
  get profile() { return this._profile; }
143
- constructor(_profile, titleActions, contextMenuActions, userDataProfileService, userDataProfileManagementService, userDataProfilesService, instantiationService) {
144
- super(_profile.name, _profile.icon, _profile.useDefaultFlags, userDataProfileService.currentProfile.id === _profile.id, userDataProfilesService, instantiationService);
250
+ constructor(_profile, titleButtons, titleActions, actions, userDataProfileService, configurationService, userDataProfileManagementService, userDataProfilesService, commandService, instantiationService) {
251
+ super(_profile.name, _profile.icon, _profile.useDefaultFlags, userDataProfileService.currentProfile.id === _profile.id, userDataProfileManagementService, userDataProfilesService, commandService, instantiationService);
145
252
  this._profile = _profile;
253
+ this.titleButtons = titleButtons;
146
254
  this.titleActions = titleActions;
147
- this.contextMenuActions = contextMenuActions;
255
+ this.actions = actions;
148
256
  this.userDataProfileService = userDataProfileService;
149
- this.userDataProfileManagementService = userDataProfileManagementService;
150
- this.primaryAction = undefined;
151
- this.saveScheduler = this._register(( (new RunOnceScheduler(() => this.doSave(), 500))));
257
+ this.configurationService = configurationService;
258
+ this._isNewWindowProfile = false;
259
+ this._isNewWindowProfile = this.configurationService.getValue(CONFIG_NEW_WINDOW_PROFILE) === this.profile.name;
260
+ this._register(configurationService.onDidChangeConfiguration(e => {
261
+ if (e.affectsConfiguration(CONFIG_NEW_WINDOW_PROFILE)) {
262
+ this.isNewWindowProfile = this.configurationService.getValue(CONFIG_NEW_WINDOW_PROFILE) === this.profile.name;
263
+ }
264
+ }));
152
265
  this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => this.active = this.userDataProfileService.currentProfile.id === this.profile.id));
153
266
  this._register(this.userDataProfilesService.onDidChangeProfiles(() => {
154
267
  const profile = this.userDataProfilesService.profiles.find(p => p.id === this.profile.id);
@@ -159,43 +272,26 @@ let UserDataProfileElement = class UserDataProfileElement extends AbstractUserDa
159
272
  this.flags = profile.useDefaultFlags;
160
273
  }
161
274
  }));
162
- this._register(this.onDidChange(e => {
163
- this.save();
164
- }));
165
275
  }
166
- hasUnsavedChanges() {
167
- if (this.name !== this.profile.name) {
168
- return true;
169
- }
170
- if (this.icon !== this.profile.icon) {
171
- return true;
276
+ async toggleNewWindowProfile() {
277
+ if (this._isNewWindowProfile) {
278
+ await this.configurationService.updateValue(CONFIG_NEW_WINDOW_PROFILE, null);
172
279
  }
173
- if (!equals(this.flags ?? {}, this.profile.useDefaultFlags ?? {})) {
174
- return true;
280
+ else {
281
+ await this.configurationService.updateValue(CONFIG_NEW_WINDOW_PROFILE, this.profile.name);
175
282
  }
176
- return false;
177
283
  }
178
- save() {
179
- this.saveScheduler.schedule();
284
+ get isNewWindowProfile() { return this._isNewWindowProfile; }
285
+ set isNewWindowProfile(isNewWindowProfile) {
286
+ if (this._isNewWindowProfile !== isNewWindowProfile) {
287
+ this._isNewWindowProfile = isNewWindowProfile;
288
+ this._onDidChange.fire({ newWindowProfile: true });
289
+ }
180
290
  }
181
291
  async doSave() {
182
- if (!this.hasUnsavedChanges()) {
183
- return;
184
- }
185
- this.validate();
186
- if (this.message) {
187
- return;
188
- }
189
- const useDefaultFlags = this.flags
190
- ? this.flags.settings && this.flags.keybindings && this.flags.tasks && this.flags.globalState && this.flags.extensions ? undefined : this.flags
191
- : undefined;
192
- await this.userDataProfileManagementService.updateProfile(this.profile, {
193
- name: this.name,
194
- icon: this.icon,
195
- useDefaultFlags: this.profile.useDefaultFlags && !useDefaultFlags ? {} : useDefaultFlags
196
- });
292
+ await this.saveProfile(this.profile);
197
293
  }
198
- async getChildren(resourceType) {
294
+ async getChildrenForResourceType(resourceType) {
199
295
  return this.getChildrenFromProfile(this.profile, resourceType);
200
296
  }
201
297
  getInitialName() {
@@ -203,22 +299,26 @@ let UserDataProfileElement = class UserDataProfileElement extends AbstractUserDa
203
299
  }
204
300
  };
205
301
  UserDataProfileElement = ( (__decorate([
206
- ( (__param(3, IUserDataProfileService))),
207
- ( (__param(4, IUserDataProfileManagementService))),
208
- ( (__param(5, IUserDataProfilesService))),
209
- ( (__param(6, IInstantiationService)))
302
+ ( (__param(4, IUserDataProfileService))),
303
+ ( (__param(5, IConfigurationService))),
304
+ ( (__param(6, IUserDataProfileManagementService))),
305
+ ( (__param(7, IUserDataProfilesService))),
306
+ ( (__param(8, ICommandService))),
307
+ ( (__param(9, IInstantiationService)))
210
308
  ], UserDataProfileElement)));
211
309
  const USER_DATA_PROFILE_TEMPLATE_PREVIEW_SCHEME = 'userdataprofiletemplatepreview';
212
310
  let NewProfileElement = class NewProfileElement extends AbstractUserDataProfileElement {
213
- constructor(name, copyFrom, primaryAction, titleActions, contextMenuActions, fileService, userDataProfileImportExportService, userDataProfilesService, instantiationService) {
214
- super(name, undefined, undefined, false, userDataProfilesService, instantiationService);
215
- this.primaryAction = primaryAction;
311
+ constructor(name, copyFrom, titleButtons, titleActions, actions, fileService, userDataProfileImportExportService, userDataProfileManagementService, userDataProfilesService, commandService, instantiationService) {
312
+ super(name, undefined, undefined, false, userDataProfileManagementService, userDataProfilesService, commandService, instantiationService);
313
+ this.titleButtons = titleButtons;
216
314
  this.titleActions = titleActions;
217
- this.contextMenuActions = contextMenuActions;
315
+ this.actions = actions;
218
316
  this.fileService = fileService;
219
317
  this.userDataProfileImportExportService = userDataProfileImportExportService;
318
+ this.template = null;
220
319
  this._copyFrom = copyFrom;
221
320
  this._copyFlags = this.getCopyFlagsFrom(copyFrom);
321
+ this.initialize();
222
322
  this._register(this.fileService.registerProvider(USER_DATA_PROFILE_TEMPLATE_PREVIEW_SCHEME, this._register(( (new InMemoryFileSystemProvider())))));
223
323
  }
224
324
  get copyFrom() { return this._copyFrom; }
@@ -228,6 +328,11 @@ let NewProfileElement = class NewProfileElement extends AbstractUserDataProfileE
228
328
  this._onDidChange.fire({ copyFrom: true });
229
329
  this.flags = undefined;
230
330
  this.copyFlags = this.getCopyFlagsFrom(copyFrom);
331
+ if (copyFrom instanceof URI) {
332
+ this.templatePromise?.cancel();
333
+ this.templatePromise = undefined;
334
+ }
335
+ this.initialize();
231
336
  }
232
337
  }
233
338
  get copyFlags() { return this._copyFlags; }
@@ -237,6 +342,13 @@ let NewProfileElement = class NewProfileElement extends AbstractUserDataProfileE
237
342
  this._onDidChange.fire({ copyFlags: true });
238
343
  }
239
344
  }
345
+ get previewProfile() { return this._previewProfile; }
346
+ set previewProfile(profile) {
347
+ if (this._previewProfile !== profile) {
348
+ this._previewProfile = profile;
349
+ this._onDidChange.fire({ preview: true });
350
+ }
351
+ }
240
352
  getCopyFlagsFrom(copyFrom) {
241
353
  return copyFrom ? {
242
354
  settings: true,
@@ -246,6 +358,73 @@ let NewProfileElement = class NewProfileElement extends AbstractUserDataProfileE
246
358
  extensions: true
247
359
  } : undefined;
248
360
  }
361
+ async initialize() {
362
+ this.disabled = true;
363
+ try {
364
+ if (this.copyFrom instanceof URI) {
365
+ await this.resolveTemplate(this.copyFrom);
366
+ if (this.template) {
367
+ this.name = this.template.name ?? '';
368
+ this.icon = this.template.icon;
369
+ this.setCopyFlag(ProfileResourceType.Settings, !!this.template.settings);
370
+ this.setCopyFlag(ProfileResourceType.Keybindings, !!this.template.keybindings);
371
+ this.setCopyFlag(ProfileResourceType.Tasks, !!this.template.tasks);
372
+ this.setCopyFlag(ProfileResourceType.Snippets, !!this.template.snippets);
373
+ this.setCopyFlag(ProfileResourceType.Extensions, !!this.template.extensions);
374
+ }
375
+ return;
376
+ }
377
+ if (isUserDataProfile(this.copyFrom)) {
378
+ this.name = `${this.copyFrom.name} (Copy)`;
379
+ this.icon = this.copyFrom.icon;
380
+ this.setCopyFlag(ProfileResourceType.Settings, true);
381
+ this.setCopyFlag(ProfileResourceType.Keybindings, true);
382
+ this.setCopyFlag(ProfileResourceType.Tasks, true);
383
+ this.setCopyFlag(ProfileResourceType.Snippets, true);
384
+ this.setCopyFlag(ProfileResourceType.Extensions, true);
385
+ return;
386
+ }
387
+ this.name = ( localizeWithPath(_moduleId, 4, "Untitled"));
388
+ this.icon = undefined;
389
+ this.setCopyFlag(ProfileResourceType.Settings, false);
390
+ this.setCopyFlag(ProfileResourceType.Keybindings, false);
391
+ this.setCopyFlag(ProfileResourceType.Tasks, false);
392
+ this.setCopyFlag(ProfileResourceType.Snippets, false);
393
+ this.setCopyFlag(ProfileResourceType.Extensions, false);
394
+ }
395
+ finally {
396
+ this.disabled = false;
397
+ }
398
+ }
399
+ async resolveTemplate(uri) {
400
+ if (!this.templatePromise) {
401
+ this.templatePromise = createCancelablePromise(async (token) => {
402
+ const template = await this.userDataProfileImportExportService.resolveProfileTemplate(uri);
403
+ if (!token.isCancellationRequested) {
404
+ this.template = template;
405
+ }
406
+ });
407
+ }
408
+ await this.templatePromise;
409
+ return this.template;
410
+ }
411
+ hasResource(resourceType) {
412
+ if (this.template) {
413
+ switch (resourceType) {
414
+ case ProfileResourceType.Settings:
415
+ return !!this.template.settings;
416
+ case ProfileResourceType.Keybindings:
417
+ return !!this.template.keybindings;
418
+ case ProfileResourceType.Snippets:
419
+ return !!this.template.snippets;
420
+ case ProfileResourceType.Tasks:
421
+ return !!this.template.tasks;
422
+ case ProfileResourceType.Extensions:
423
+ return !!this.template.extensions;
424
+ }
425
+ }
426
+ return true;
427
+ }
249
428
  getCopyFlag(key) {
250
429
  return this.copyFlags?.[key] ?? false;
251
430
  }
@@ -254,23 +433,32 @@ let NewProfileElement = class NewProfileElement extends AbstractUserDataProfileE
254
433
  flags[key] = value;
255
434
  this.copyFlags = flags;
256
435
  }
257
- async getChildren(resourceType) {
436
+ getCopyFromName() {
437
+ if (isUserDataProfile(this.copyFrom)) {
438
+ return this.copyFrom.name;
439
+ }
440
+ if (this.template) {
441
+ return this.template.name;
442
+ }
443
+ return undefined;
444
+ }
445
+ async getChildrenForResourceType(resourceType) {
446
+ if (this.getFlag(resourceType)) {
447
+ return this.getChildrenFromProfile(this.userDataProfilesService.defaultProfile, resourceType);
448
+ }
258
449
  if (!this.getCopyFlag(resourceType)) {
259
450
  return [];
260
451
  }
261
452
  if (this.copyFrom instanceof URI) {
262
- const template = await this.userDataProfileImportExportService.resolveProfileTemplate(this.copyFrom);
263
- if (!template) {
453
+ await this.resolveTemplate(this.copyFrom);
454
+ if (!this.template) {
264
455
  return [];
265
456
  }
266
- return this.getChildrenFromProfileTemplate(template, resourceType);
457
+ return this.getChildrenFromProfileTemplate(this.template, resourceType);
267
458
  }
268
459
  if (this.copyFrom) {
269
460
  return this.getChildrenFromProfile(this.copyFrom, resourceType);
270
461
  }
271
- if (this.getFlag(resourceType)) {
272
- return this.getChildrenFromProfile(this.userDataProfilesService.defaultProfile, resourceType);
273
- }
274
462
  return [];
275
463
  }
276
464
  async getChildrenFromProfileTemplate(profileTemplate, resourceType) {
@@ -279,36 +467,57 @@ let NewProfileElement = class NewProfileElement extends AbstractUserDataProfileE
279
467
  case ProfileResourceType.Settings:
280
468
  if (profileTemplate.settings) {
281
469
  await this.instantiationService.createInstance(SettingsResource).apply(profileTemplate.settings, profile);
470
+ return this.getChildrenFromProfile(profile, resourceType);
282
471
  }
283
- return this.getChildrenFromProfile(profile, resourceType);
472
+ return [];
284
473
  case ProfileResourceType.Keybindings:
285
474
  if (profileTemplate.keybindings) {
286
475
  await this.instantiationService.createInstance(KeybindingsResource).apply(profileTemplate.keybindings, profile);
476
+ return this.getChildrenFromProfile(profile, resourceType);
287
477
  }
288
- return this.getChildrenFromProfile(profile, resourceType);
478
+ return [];
289
479
  case ProfileResourceType.Snippets:
290
480
  if (profileTemplate.snippets) {
291
481
  await this.instantiationService.createInstance(SnippetsResource).apply(profileTemplate.snippets, profile);
482
+ return this.getChildrenFromProfile(profile, resourceType);
292
483
  }
293
- return this.getChildrenFromProfile(profile, resourceType);
484
+ return [];
294
485
  case ProfileResourceType.Tasks:
295
486
  if (profileTemplate.tasks) {
296
487
  await this.instantiationService.createInstance(TasksResource).apply(profileTemplate.tasks, profile);
488
+ return this.getChildrenFromProfile(profile, resourceType);
297
489
  }
298
- return this.getChildrenFromProfile(profile, resourceType);
490
+ return [];
299
491
  case ProfileResourceType.Extensions:
300
492
  if (profileTemplate.extensions) {
301
- return this.instantiationService.createInstance(ExtensionsResourceImportTreeItem, profileTemplate.extensions).getChildren();
493
+ const children = await this.instantiationService.createInstance(ExtensionsResourceImportTreeItem, profileTemplate.extensions).getChildren();
494
+ return (
495
+ (children.map(child => this.toUserDataProfileResourceChildElement(child)))
496
+ );
302
497
  }
498
+ return [];
303
499
  }
304
500
  return [];
305
501
  }
502
+ getInitialName() {
503
+ return this.previewProfile?.name ?? '';
504
+ }
505
+ async doSave() {
506
+ if (this.previewProfile) {
507
+ const profile = await this.saveProfile(this.previewProfile);
508
+ if (profile) {
509
+ this.previewProfile = profile;
510
+ }
511
+ }
512
+ }
306
513
  };
307
514
  NewProfileElement = ( (__decorate([
308
515
  ( (__param(5, IFileService))),
309
516
  ( (__param(6, IUserDataProfileImportExportService))),
310
- ( (__param(7, IUserDataProfilesService))),
311
- ( (__param(8, IInstantiationService)))
517
+ ( (__param(7, IUserDataProfileManagementService))),
518
+ ( (__param(8, IUserDataProfilesService))),
519
+ ( (__param(9, ICommandService))),
520
+ ( (__param(10, IInstantiationService)))
312
521
  ], NewProfileElement)));
313
522
  let UserDataProfilesEditorModel = class UserDataProfilesEditorModel extends EditorModel {
314
523
  static { UserDataProfilesEditorModel_1 = this; }
@@ -337,7 +546,7 @@ let UserDataProfilesEditorModel = class UserDataProfilesEditorModel extends Edit
337
546
  return a.name.localeCompare(b.name);
338
547
  });
339
548
  }
340
- constructor(userDataProfileService, userDataProfilesService, userDataProfileManagementService, userDataProfileImportExportService, dialogService, telemetryService, instantiationService) {
549
+ constructor(userDataProfileService, userDataProfilesService, userDataProfileManagementService, userDataProfileImportExportService, dialogService, telemetryService, hostService, instantiationService) {
341
550
  super();
342
551
  this.userDataProfileService = userDataProfileService;
343
552
  this.userDataProfilesService = userDataProfilesService;
@@ -345,45 +554,62 @@ let UserDataProfilesEditorModel = class UserDataProfilesEditorModel extends Edit
345
554
  this.userDataProfileImportExportService = userDataProfileImportExportService;
346
555
  this.dialogService = dialogService;
347
556
  this.telemetryService = telemetryService;
557
+ this.hostService = hostService;
348
558
  this.instantiationService = instantiationService;
349
559
  this._profiles = [];
350
560
  this._onDidChange = this._register(( (new Emitter())));
351
561
  this.onDidChange = this._onDidChange.event;
352
562
  for (const profile of userDataProfilesService.profiles) {
353
- this._profiles.push(this.createProfileElement(profile));
563
+ if (!profile.isTransient) {
564
+ this._profiles.push(this.createProfileElement(profile));
565
+ }
354
566
  }
355
567
  this._register(toDisposable(() => ( (this._profiles.splice(0, this._profiles.length).map(([, disposables]) => disposables.dispose())))));
356
568
  this._register(userDataProfilesService.onDidChangeProfiles(e => this.onDidChangeProfiles(e)));
357
569
  }
358
570
  onDidChangeProfiles(e) {
571
+ let changed = false;
359
572
  for (const profile of e.added) {
360
- if (profile.name !== this.newProfileElement?.name) {
573
+ if (!profile.isTransient && profile.name !== this.newProfileElement?.name) {
574
+ changed = true;
361
575
  this._profiles.push(this.createProfileElement(profile));
362
576
  }
363
577
  }
364
578
  for (const profile of e.removed) {
365
- this._profiles.findIndex(([p]) => p instanceof UserDataProfileElement && p.profile.id === profile.id);
579
+ if (profile.id === this.newProfileElement?.previewProfile?.id) {
580
+ this.newProfileElement.previewProfile = undefined;
581
+ }
582
+ const index = this._profiles.findIndex(([p]) => p instanceof UserDataProfileElement && p.profile.id === profile.id);
583
+ if (index !== -1) {
584
+ changed = true;
585
+ }
586
+ }
587
+ if (changed) {
588
+ this._onDidChange.fire(undefined);
366
589
  }
367
- this._onDidChange.fire(undefined);
368
590
  }
369
591
  createProfileElement(profile) {
370
592
  const disposables = ( (new DisposableStore()));
371
- const activateAction = disposables.add(( (new Action('userDataProfile.activate', ( localizeWithPath(_moduleId, 3, "Activate")), ThemeIcon.asClassName(Codicon.check), true, () => this.userDataProfileManagementService.switchProfile(profile)))));
372
- activateAction.checked = this.userDataProfileService.currentProfile.id === profile.id;
373
- disposables.add(this.userDataProfileService.onDidChangeCurrentProfile(() => activateAction.checked = this.userDataProfileService.currentProfile.id === profile.id));
374
- const copyFromProfileAction = disposables.add(( (new Action('userDataProfile.copyFromProfile', ( localizeWithPath(_moduleId, 4, "Save As...")), ThemeIcon.asClassName(Codicon.copy), true, () => this.createNewProfile(profile)))));
375
- const exportAction = disposables.add(( (new Action('userDataProfile.export', ( localizeWithPath(_moduleId, 5, "Export...")), ThemeIcon.asClassName(Codicon.export), true, () => this.exportProfile(profile)))));
376
- const deleteAction = disposables.add(( (new Action('userDataProfile.delete', ( localizeWithPath(_moduleId, 6, "Delete")), ThemeIcon.asClassName(Codicon.trash), true, () => this.removeProfile(profile)))));
593
+ const activateAction = disposables.add(( (new Action('userDataProfile.activate', ( localizeWithPath(_moduleId, 5, "Use for Current Window")), ThemeIcon.asClassName(Codicon.check), true, () => this.userDataProfileManagementService.switchProfile(profileElement.profile)))));
594
+ const copyFromProfileAction = disposables.add(( (new Action('userDataProfile.copyFromProfile', ( localizeWithPath(_moduleId, 6, "Duplicate...")), ThemeIcon.asClassName(Codicon.copy), true, () => this.createNewProfile(profileElement.profile)))));
595
+ const exportAction = disposables.add(( (new Action('userDataProfile.export', ( localizeWithPath(_moduleId, 7, "Export...")), ThemeIcon.asClassName(Codicon.export), true, () => this.exportProfile(profileElement.profile)))));
596
+ const deleteAction = disposables.add(( (new Action('userDataProfile.delete', ( localizeWithPath(_moduleId, 8, "Delete")), ThemeIcon.asClassName(Codicon.trash), true, () => this.removeProfile(profileElement.profile)))));
597
+ const newWindowAction = disposables.add(( (new Action('userDataProfile.newWindow', ( localizeWithPath(_moduleId, 9, "Open New Window with this Profile")), ThemeIcon.asClassName(Codicon.emptyWindow), true, () => this.openWindow(profileElement.profile)))));
598
+ const useAsNewWindowProfileAction = disposables.add(( (new Action('userDataProfile.useAsNewWindowProfile', ( localizeWithPath(_moduleId, 10, "Use for New Windows")), undefined, true, () => profileElement.toggleNewWindowProfile()))));
377
599
  const titlePrimaryActions = [];
378
- titlePrimaryActions.push(activateAction);
379
- titlePrimaryActions.push(exportAction);
380
- if (!profile.isDefault) {
381
- titlePrimaryActions.push(deleteAction);
382
- }
600
+ titlePrimaryActions.push(newWindowAction);
383
601
  const titleSecondaryActions = [];
384
602
  titleSecondaryActions.push(copyFromProfileAction);
603
+ titleSecondaryActions.push(exportAction);
604
+ if (!profile.isDefault) {
605
+ titleSecondaryActions.push(( (new Separator())));
606
+ titleSecondaryActions.push(deleteAction);
607
+ }
608
+ const primaryActions = [];
609
+ primaryActions.push(newWindowAction);
385
610
  const secondaryActions = [];
386
611
  secondaryActions.push(activateAction);
612
+ secondaryActions.push(useAsNewWindowProfileAction);
387
613
  secondaryActions.push(( (new Separator())));
388
614
  secondaryActions.push(copyFromProfileAction);
389
615
  secondaryActions.push(exportAction);
@@ -391,17 +617,50 @@ let UserDataProfilesEditorModel = class UserDataProfilesEditorModel extends Edit
391
617
  secondaryActions.push(( (new Separator())));
392
618
  secondaryActions.push(deleteAction);
393
619
  }
394
- const profileElement = disposables.add(this.instantiationService.createInstance(UserDataProfileElement, profile, [titlePrimaryActions, titleSecondaryActions], secondaryActions));
620
+ const profileElement = disposables.add(this.instantiationService.createInstance(UserDataProfileElement, profile, [[], []], [titlePrimaryActions, titleSecondaryActions], [primaryActions, secondaryActions]));
621
+ activateAction.checked = this.userDataProfileService.currentProfile.id === profileElement.profile.id;
622
+ disposables.add(this.userDataProfileService.onDidChangeCurrentProfile(() => activateAction.checked = this.userDataProfileService.currentProfile.id === profileElement.profile.id));
623
+ useAsNewWindowProfileAction.checked = profileElement.isNewWindowProfile;
624
+ disposables.add(profileElement.onDidChange(e => {
625
+ if (e.newWindowProfile) {
626
+ useAsNewWindowProfileAction.checked = profileElement.isNewWindowProfile;
627
+ }
628
+ }));
395
629
  return [profileElement, disposables];
396
630
  }
397
- createNewProfile(copyFrom) {
631
+ async createNewProfile(copyFrom) {
632
+ if (this.newProfileElement) {
633
+ const result = await this.dialogService.confirm({
634
+ type: 'info',
635
+ message: ( localizeWithPath(
636
+ _moduleId,
637
+ 11,
638
+ "A new profile is already being created. Do you want to discard it and create a new one?"
639
+ )),
640
+ primaryButton: ( localizeWithPath(_moduleId, 12, "Discard & Create")),
641
+ cancelButton: ( localizeWithPath(_moduleId, 13, "Cancel"))
642
+ });
643
+ if (!result.confirmed) {
644
+ return;
645
+ }
646
+ this.revert();
647
+ }
398
648
  if (!this.newProfileElement) {
399
649
  const disposables = ( (new DisposableStore()));
400
- const discardAction = disposables.add(( (new Action('userDataProfile.discard', ( localizeWithPath(_moduleId, 7, "Discard")), ThemeIcon.asClassName(Codicon.close), true, () => {
401
- this.removeNewProfile();
402
- this._onDidChange.fire(undefined);
403
- }))));
404
- this.newProfileElement = disposables.add(this.instantiationService.createInstance(NewProfileElement, ( localizeWithPath(_moduleId, 8, "Untitled")), copyFrom, disposables.add(( (new Action('userDataProfile.create', ( localizeWithPath(_moduleId, 9, "Create & Apply")), undefined, true, () => this.saveNewProfile())))), [[discardAction], []], [discardAction]));
650
+ const cancellationTokenSource = ( (new CancellationTokenSource()));
651
+ disposables.add(toDisposable(() => cancellationTokenSource.dispose(true)));
652
+ const createAction = disposables.add(( (new Action('userDataProfile.create', ( localizeWithPath(_moduleId, 14, "Create")), undefined, true, () => this.saveNewProfile(false, cancellationTokenSource.token)))));
653
+ const cancelAction = disposables.add(( (new Action('userDataProfile.cancel', ( localizeWithPath(_moduleId, 13, "Cancel")), ThemeIcon.asClassName(Codicon.trash), true, () => this.discardNewProfile()))));
654
+ const previewProfileAction = disposables.add(( (new Action('userDataProfile.preview', ( localizeWithPath(_moduleId, 15, "Preview")), ThemeIcon.asClassName(Codicon.openPreview), true, () => this.previewNewProfile(cancellationTokenSource.token)))));
655
+ this.newProfileElement = disposables.add(this.instantiationService.createInstance(NewProfileElement, copyFrom ? '' : ( localizeWithPath(_moduleId, 4, "Untitled")), copyFrom, [[createAction], [cancelAction, previewProfileAction]], [[], []], [[cancelAction], []]));
656
+ disposables.add(this.newProfileElement.onDidChange(e => {
657
+ if (e.preview) {
658
+ previewProfileAction.checked = !!this.newProfileElement?.previewProfile;
659
+ }
660
+ if (e.disabled || e.message) {
661
+ previewProfileAction.enabled = createAction.enabled = !this.newProfileElement?.disabled && !this.newProfileElement?.message;
662
+ }
663
+ }));
405
664
  this._profiles.push([this.newProfileElement, disposables]);
406
665
  this._onDidChange.fire(this.newProfileElement);
407
666
  }
@@ -417,55 +676,122 @@ let UserDataProfilesEditorModel = class UserDataProfilesEditorModel extends Edit
417
676
  this.newProfileElement = undefined;
418
677
  }
419
678
  }
420
- async saveNewProfile() {
679
+ async previewNewProfile(token) {
421
680
  if (!this.newProfileElement) {
422
681
  return;
423
682
  }
683
+ if (this.newProfileElement.previewProfile) {
684
+ return;
685
+ }
686
+ const profile = await this.saveNewProfile(true, token);
687
+ if (profile) {
688
+ this.newProfileElement.previewProfile = profile;
689
+ await this.openWindow(profile);
690
+ }
691
+ }
692
+ async saveNewProfile(transient, token) {
693
+ if (!this.newProfileElement) {
694
+ return undefined;
695
+ }
424
696
  this.newProfileElement.validate();
425
697
  if (this.newProfileElement.message) {
698
+ return undefined;
699
+ }
700
+ this.newProfileElement.disabled = true;
701
+ let profile;
702
+ try {
703
+ if (this.newProfileElement.previewProfile) {
704
+ if (!transient) {
705
+ profile = await this.userDataProfileManagementService.updateProfile(this.newProfileElement.previewProfile, { transient: false });
706
+ }
707
+ }
708
+ else {
709
+ const { flags, icon, name, copyFrom } = this.newProfileElement;
710
+ const useDefaultFlags = flags
711
+ ? flags.settings && flags.keybindings && flags.tasks && flags.globalState && flags.extensions ? undefined : flags
712
+ : undefined;
713
+ const createProfileTelemetryData = { source: copyFrom instanceof URI ? 'template' : isUserDataProfile(copyFrom) ? 'profile' : copyFrom ? 'external' : undefined };
714
+ if (copyFrom instanceof URI) {
715
+ const template = await this.newProfileElement.resolveTemplate(copyFrom);
716
+ if (template) {
717
+ this.telemetryService.publicLog2('userDataProfile.createFromTemplate', createProfileTelemetryData);
718
+ profile = await this.userDataProfileImportExportService.createProfileFromTemplate(template, {
719
+ name,
720
+ useDefaultFlags,
721
+ icon,
722
+ resourceTypeFlags: this.newProfileElement.copyFlags,
723
+ transient
724
+ }, token ?? CancellationToken.None);
725
+ }
726
+ }
727
+ else if (isUserDataProfile(copyFrom)) {
728
+ this.telemetryService.publicLog2('userDataProfile.createFromProfile', createProfileTelemetryData);
729
+ profile = await this.userDataProfileImportExportService.createFromProfile(copyFrom, {
730
+ name,
731
+ useDefaultFlags,
732
+ icon: icon,
733
+ resourceTypeFlags: this.newProfileElement.copyFlags,
734
+ transient
735
+ }, token ?? CancellationToken.None);
736
+ }
737
+ else {
738
+ this.telemetryService.publicLog2('userDataProfile.createEmptyProfile', createProfileTelemetryData);
739
+ profile = await this.userDataProfileManagementService.createProfile(name, { useDefaultFlags, icon, transient });
740
+ }
741
+ }
742
+ }
743
+ finally {
744
+ if (this.newProfileElement) {
745
+ this.newProfileElement.disabled = false;
746
+ }
747
+ }
748
+ if (token?.isCancellationRequested) {
749
+ if (profile) {
750
+ try {
751
+ await this.userDataProfileManagementService.removeProfile(profile);
752
+ }
753
+ catch (error) {
754
+ }
755
+ }
426
756
  return;
427
757
  }
428
- const { flags, icon, name, copyFrom } = this.newProfileElement;
429
- const useDefaultFlags = flags
430
- ? flags.settings && flags.keybindings && flags.tasks && flags.globalState && flags.extensions ? undefined : flags
431
- : undefined;
432
- const createProfileTelemetryData = { source: copyFrom instanceof URI ? 'template' : isUserDataProfile(copyFrom) ? 'profile' : copyFrom ? 'external' : undefined };
433
- if (copyFrom instanceof URI) {
434
- this.telemetryService.publicLog2('userDataProfile.createFromTemplate', createProfileTelemetryData);
435
- await this.userDataProfileImportExportService.importProfile(copyFrom, { mode: 'apply', name: name, useDefaultFlags, icon: icon ? icon : undefined, resourceTypeFlags: this.newProfileElement.copyFlags });
758
+ if (profile && !profile.isTransient && this.newProfileElement) {
759
+ this.removeNewProfile();
760
+ this.onDidChangeProfiles({ added: [profile], removed: [], updated: [], all: this.userDataProfilesService.profiles });
436
761
  }
437
- else if (isUserDataProfile(copyFrom)) {
438
- this.telemetryService.publicLog2('userDataProfile.createFromProfile', createProfileTelemetryData);
439
- await this.userDataProfileImportExportService.createFromProfile(copyFrom, name, { useDefaultFlags, icon: icon ? icon : undefined, resourceTypeFlags: this.newProfileElement.copyFlags });
762
+ return profile;
763
+ }
764
+ async discardNewProfile() {
765
+ if (!this.newProfileElement) {
766
+ return;
440
767
  }
441
- else {
442
- this.telemetryService.publicLog2('userDataProfile.createEmptyProfile', createProfileTelemetryData);
443
- await this.userDataProfileManagementService.createAndEnterProfile(name, { useDefaultFlags, icon: icon ? icon : undefined });
768
+ if (this.newProfileElement.previewProfile) {
769
+ await this.userDataProfileManagementService.removeProfile(this.newProfileElement.previewProfile);
444
770
  }
445
771
  this.removeNewProfile();
446
- const profile = this.userDataProfilesService.profiles.find(p => p.name === name);
447
- if (profile) {
448
- this.onDidChangeProfiles({ added: [profile], removed: [], updated: [], all: this.userDataProfilesService.profiles });
449
- }
772
+ this._onDidChange.fire(undefined);
450
773
  }
451
774
  async removeProfile(profile) {
452
775
  const result = await this.dialogService.confirm({
453
776
  type: 'info',
454
777
  message: ( localizeWithPath(
455
778
  _moduleId,
456
- 10,
779
+ 16,
457
780
  "Are you sure you want to delete the profile '{0}'?",
458
781
  profile.name
459
782
  )),
460
- primaryButton: ( localizeWithPath(_moduleId, 6, "Delete")),
461
- cancelButton: ( localizeWithPath(_moduleId, 11, "Cancel"))
783
+ primaryButton: ( localizeWithPath(_moduleId, 8, "Delete")),
784
+ cancelButton: ( localizeWithPath(_moduleId, 13, "Cancel"))
462
785
  });
463
786
  if (result.confirmed) {
464
787
  await this.userDataProfileManagementService.removeProfile(profile);
465
788
  }
466
789
  }
790
+ async openWindow(profile) {
791
+ await this.hostService.openWindow({ forceProfile: profile.name });
792
+ }
467
793
  async exportProfile(profile) {
468
- return this.userDataProfileImportExportService.exportProfile2(profile);
794
+ return this.userDataProfileImportExportService.exportProfile(profile);
469
795
  }
470
796
  };
471
797
  UserDataProfilesEditorModel = UserDataProfilesEditorModel_1 = ( (__decorate([
@@ -475,7 +801,8 @@ UserDataProfilesEditorModel = UserDataProfilesEditorModel_1 = ( (__decorate([
475
801
  ( (__param(3, IUserDataProfileImportExportService))),
476
802
  ( (__param(4, IDialogService))),
477
803
  ( (__param(5, ITelemetryService))),
478
- ( (__param(6, IInstantiationService)))
804
+ ( (__param(6, IHostService))),
805
+ ( (__param(7, IInstantiationService)))
479
806
  ], UserDataProfilesEditorModel)));
480
807
 
481
- export { AbstractUserDataProfileElement, NewProfileElement, UserDataProfileElement, UserDataProfilesEditorModel };
808
+ export { AbstractUserDataProfileElement, NewProfileElement, UserDataProfileElement, UserDataProfilesEditorModel, isProfileResourceChildElement, isProfileResourceTypeElement };