Skip to content

Commit 94f8698

Browse files
authored
polish profiles ui (microsoft#226639)
* polish profiles ui - support exporting new profile - other fixes * add await
1 parent dc51350 commit 94f8698

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditor.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,13 @@ class ProfileWidget extends Disposable {
574574
}
575575

576576
render(profileElement: AbstractUserDataProfileElement): void {
577+
if (this._profileElement.value?.element === profileElement) {
578+
return;
579+
}
580+
581+
if (this._profileElement.value?.element instanceof UserDataProfileElement) {
582+
this._profileElement.value.element.reset();
583+
}
577584
this.profileTree.setInput(profileElement);
578585

579586
const disposables = new DisposableStore();
@@ -907,7 +914,6 @@ class ProfileNameRenderer extends ProfilePropertyRenderer {
907914
}
908915
}
909916
));
910-
disposables.add(this.userDataProfilesService.onDidChangeProfiles(() => nameInput.validate()));
911917
nameInput.onDidChange(value => {
912918
if (profileElement && value) {
913919
profileElement.root.name = value;
@@ -938,6 +944,9 @@ class ProfileNameRenderer extends ProfilePropertyRenderer {
938944
if (e.name || e.disabled) {
939945
renderName(element);
940946
}
947+
if (e.profile) {
948+
nameInput.validate();
949+
}
941950
}));
942951
},
943952
disposables,
@@ -1720,6 +1729,15 @@ export class UserDataProfilesEditorInput extends EditorInput {
17201729
}
17211730

17221731
override matches(otherInput: EditorInput | IUntypedEditorInput): boolean { return otherInput instanceof UserDataProfilesEditorInput; }
1732+
1733+
override dispose(): void {
1734+
for (const profile of this.model.profiles) {
1735+
if (profile instanceof UserDataProfileElement) {
1736+
profile.reset();
1737+
}
1738+
}
1739+
super.dispose();
1740+
}
17231741
}
17241742

17251743
export class UserDataProfilesEditorInputSerializer implements IEditorSerializer {

src/vs/workbench/contrib/userDataProfile/browser/userDataProfilesEditorModel.ts

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export type ChangeEvent = {
5050
readonly copyFromInfo?: boolean;
5151
readonly copyFlags?: boolean;
5252
readonly preview?: boolean;
53+
readonly profile?: boolean;
5354
readonly disabled?: boolean;
5455
readonly newWindowProfile?: boolean;
5556
};
@@ -353,17 +354,22 @@ export class UserDataProfileElement extends AbstractUserDataProfileElement {
353354
}
354355
));
355356
this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => this.active = this.userDataProfileService.currentProfile.id === this.profile.id));
356-
this._register(this.userDataProfilesService.onDidChangeProfiles(() => {
357-
const profile = this.userDataProfilesService.profiles.find(p => p.id === this.profile.id);
357+
this._register(this.userDataProfilesService.onDidChangeProfiles(({ updated }) => {
358+
const profile = updated.find(p => p.id === this.profile.id);
358359
if (profile) {
359360
this._profile = profile;
360-
this.name = profile.name;
361-
this.icon = profile.icon;
362-
this.flags = profile.useDefaultFlags;
361+
this.reset();
362+
this._onDidChange.fire({ profile: true });
363363
}
364364
}));
365365
}
366366

367+
reset(): void {
368+
this.name = this._profile.name;
369+
this.icon = this._profile.icon;
370+
this.flags = this._profile.useDefaultFlags;
371+
}
372+
367373
public async toggleNewWindowProfile(): Promise<void> {
368374
if (this._isNewWindowProfile) {
369375
await this.configurationService.updateValue(CONFIG_NEW_WINDOW_PROFILE, null);
@@ -783,7 +789,7 @@ export class UserDataProfilesEditorModel extends EditorModel {
783789
localize('export', "Export..."),
784790
ThemeIcon.asClassName(Codicon.export),
785791
true,
786-
() => this.exportProfile(profileElement.profile)
792+
() => this.userDataProfileImportExportService.exportProfile(profile)
787793
));
788794

789795
const deleteAction = disposables.add(new Action(
@@ -906,11 +912,18 @@ export class UserDataProfilesEditorModel extends EditorModel {
906912
if (!isWeb) {
907913
secondaryActions.push(previewProfileAction);
908914
}
915+
const exportAction = disposables.add(new Action(
916+
'userDataProfile.export',
917+
localize('export', "Export..."),
918+
ThemeIcon.asClassName(Codicon.export),
919+
isUserDataProfile(copyFrom),
920+
() => this.exportNewProfile(cancellationTokenSource.token)
921+
));
909922
this.newProfileElement = disposables.add(this.instantiationService.createInstance(NewProfileElement,
910923
copyFrom ? '' : localize('untitled', "Untitled"),
911924
copyFrom,
912925
[primaryActions, secondaryActions],
913-
[[cancelAction], []],
926+
[[cancelAction], [exportAction]],
914927
));
915928
const updateCreateActionLabel = () => {
916929
if (createAction.enabled) {
@@ -931,6 +944,7 @@ export class UserDataProfilesEditorModel extends EditorModel {
931944
}
932945
if (e.name || e.copyFrom) {
933946
updateCreateActionLabel();
947+
exportAction.enabled = isUserDataProfile(this.newProfileElement?.copyFrom);
934948
}
935949
}));
936950
disposables.add(this.userDataProfilesService.onDidChangeProfiles((e) => {
@@ -972,6 +986,27 @@ export class UserDataProfilesEditorModel extends EditorModel {
972986
}
973987
}
974988

989+
private async exportNewProfile(token: CancellationToken): Promise<void> {
990+
if (!this.newProfileElement) {
991+
return;
992+
}
993+
if (!isUserDataProfile(this.newProfileElement.copyFrom)) {
994+
return;
995+
}
996+
const profile = toUserDataProfile(
997+
generateUuid(),
998+
this.newProfileElement.name,
999+
this.newProfileElement.copyFrom.location,
1000+
this.newProfileElement.copyFrom.cacheHome,
1001+
{
1002+
icon: this.newProfileElement.icon,
1003+
useDefaultFlags: this.newProfileElement.flags,
1004+
},
1005+
this.userDataProfilesService.defaultProfile
1006+
);
1007+
await this.userDataProfileImportExportService.exportProfile(profile, this.newProfileElement.copyFlags);
1008+
}
1009+
9751010
async saveNewProfile(transient?: boolean, token?: CancellationToken): Promise<IUserDataProfile | undefined> {
9761011
if (!this.newProfileElement) {
9771012
return undefined;
@@ -1097,8 +1132,4 @@ export class UserDataProfilesEditorModel extends EditorModel {
10971132
private async openWindow(profile: IUserDataProfile): Promise<void> {
10981133
await this.hostService.openWindow({ forceProfile: profile.name });
10991134
}
1100-
1101-
private async exportProfile(profile: IUserDataProfile): Promise<void> {
1102-
return this.userDataProfileImportExportService.exportProfile(profile);
1103-
}
11041135
}

src/vs/workbench/services/userDataProfile/browser/userDataProfileImportExportService.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { IFileService } from 'vs/platform/files/common/files';
1717
import { URI } from 'vs/base/common/uri';
1818
import { ITreeItem, ITreeViewDataProvider } from 'vs/workbench/common/views';
1919
import { IUserDataProfile, IUserDataProfileOptions, IUserDataProfilesService, ProfileResourceType, ProfileResourceTypeFlags } from 'vs/platform/userDataProfile/common/userDataProfile';
20-
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2120
import { SettingsResource, SettingsResourceTreeItem } from 'vs/workbench/services/userDataProfile/browser/settingsResource';
2221
import { KeybindingsResource, KeybindingsResourceTreeItem } from 'vs/workbench/services/userDataProfile/browser/keybindingsResource';
2322
import { SnippetsResource, SnippetsResourceTreeItem } from 'vs/workbench/services/userDataProfile/browser/snippetsResource';
@@ -74,7 +73,6 @@ export class UserDataProfileImportExportService extends Disposable implements IU
7473
constructor(
7574
@IInstantiationService private readonly instantiationService: IInstantiationService,
7675
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
77-
@IContextKeyService contextKeyService: IContextKeyService,
7876
@IUserDataProfileManagementService private readonly userDataProfileManagementService: IUserDataProfileManagementService,
7977
@IUserDataProfilesService private readonly userDataProfilesService: IUserDataProfilesService,
8078
@IExtensionService private readonly extensionService: IExtensionService,
@@ -220,10 +218,10 @@ export class UserDataProfileImportExportService extends Disposable implements IU
220218
}
221219
}
222220

223-
async exportProfile(profile: IUserDataProfile): Promise<void> {
221+
async exportProfile(profile: IUserDataProfile, exportFlags?: ProfileResourceTypeFlags): Promise<void> {
224222
const disposables = new DisposableStore();
225223
try {
226-
const userDataProfilesExportState = disposables.add(this.instantiationService.createInstance(UserDataProfileExportState, profile, undefined));
224+
const userDataProfilesExportState = disposables.add(this.instantiationService.createInstance(UserDataProfileExportState, profile, exportFlags));
227225
await this.doExportProfile(userDataProfilesExportState, ProgressLocation.Notification);
228226
} finally {
229227
disposables.dispose();

src/vs/workbench/services/userDataProfile/common/userDataProfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export interface IUserDataProfileImportExportService {
104104
unregisterProfileContentHandler(id: string): void;
105105

106106
resolveProfileTemplate(uri: URI): Promise<IUserDataProfileTemplate | null>;
107-
exportProfile(profile: IUserDataProfile): Promise<void>;
107+
exportProfile(profile: IUserDataProfile, exportFlags?: ProfileResourceTypeFlags): Promise<void>;
108108
createFromProfile(from: IUserDataProfile, options: IUserDataProfileCreateOptions, token: CancellationToken): Promise<IUserDataProfile | undefined>;
109109
createProfileFromTemplate(profileTemplate: IUserDataProfileTemplate, options: IUserDataProfileCreateOptions, token: CancellationToken): Promise<IUserDataProfile | undefined>;
110110
createTroubleshootProfile(): Promise<void>;

0 commit comments

Comments
 (0)