Skip to content

Commit

Permalink
polish profiles ui (#226639)
Browse files Browse the repository at this point in the history
* polish profiles ui
- support exporting new profile
-  other fixes

* add await
  • Loading branch information
sandy081 authored Aug 26, 2024
1 parent dc51350 commit 94f8698
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,13 @@ class ProfileWidget extends Disposable {
}

render(profileElement: AbstractUserDataProfileElement): void {
if (this._profileElement.value?.element === profileElement) {
return;
}

if (this._profileElement.value?.element instanceof UserDataProfileElement) {
this._profileElement.value.element.reset();
}
this.profileTree.setInput(profileElement);

const disposables = new DisposableStore();
Expand Down Expand Up @@ -907,7 +914,6 @@ class ProfileNameRenderer extends ProfilePropertyRenderer {
}
}
));
disposables.add(this.userDataProfilesService.onDidChangeProfiles(() => nameInput.validate()));
nameInput.onDidChange(value => {
if (profileElement && value) {
profileElement.root.name = value;
Expand Down Expand Up @@ -938,6 +944,9 @@ class ProfileNameRenderer extends ProfilePropertyRenderer {
if (e.name || e.disabled) {
renderName(element);
}
if (e.profile) {
nameInput.validate();
}
}));
},
disposables,
Expand Down Expand Up @@ -1720,6 +1729,15 @@ export class UserDataProfilesEditorInput extends EditorInput {
}

override matches(otherInput: EditorInput | IUntypedEditorInput): boolean { return otherInput instanceof UserDataProfilesEditorInput; }

override dispose(): void {
for (const profile of this.model.profiles) {
if (profile instanceof UserDataProfileElement) {
profile.reset();
}
}
super.dispose();
}
}

export class UserDataProfilesEditorInputSerializer implements IEditorSerializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type ChangeEvent = {
readonly copyFromInfo?: boolean;
readonly copyFlags?: boolean;
readonly preview?: boolean;
readonly profile?: boolean;
readonly disabled?: boolean;
readonly newWindowProfile?: boolean;
};
Expand Down Expand Up @@ -353,17 +354,22 @@ export class UserDataProfileElement extends AbstractUserDataProfileElement {
}
));
this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => this.active = this.userDataProfileService.currentProfile.id === this.profile.id));
this._register(this.userDataProfilesService.onDidChangeProfiles(() => {
const profile = this.userDataProfilesService.profiles.find(p => p.id === this.profile.id);
this._register(this.userDataProfilesService.onDidChangeProfiles(({ updated }) => {
const profile = updated.find(p => p.id === this.profile.id);
if (profile) {
this._profile = profile;
this.name = profile.name;
this.icon = profile.icon;
this.flags = profile.useDefaultFlags;
this.reset();
this._onDidChange.fire({ profile: true });
}
}));
}

reset(): void {
this.name = this._profile.name;
this.icon = this._profile.icon;
this.flags = this._profile.useDefaultFlags;
}

public async toggleNewWindowProfile(): Promise<void> {
if (this._isNewWindowProfile) {
await this.configurationService.updateValue(CONFIG_NEW_WINDOW_PROFILE, null);
Expand Down Expand Up @@ -783,7 +789,7 @@ export class UserDataProfilesEditorModel extends EditorModel {
localize('export', "Export..."),
ThemeIcon.asClassName(Codicon.export),
true,
() => this.exportProfile(profileElement.profile)
() => this.userDataProfileImportExportService.exportProfile(profile)
));

const deleteAction = disposables.add(new Action(
Expand Down Expand Up @@ -906,11 +912,18 @@ export class UserDataProfilesEditorModel extends EditorModel {
if (!isWeb) {
secondaryActions.push(previewProfileAction);
}
const exportAction = disposables.add(new Action(
'userDataProfile.export',
localize('export', "Export..."),
ThemeIcon.asClassName(Codicon.export),
isUserDataProfile(copyFrom),
() => this.exportNewProfile(cancellationTokenSource.token)
));
this.newProfileElement = disposables.add(this.instantiationService.createInstance(NewProfileElement,
copyFrom ? '' : localize('untitled', "Untitled"),
copyFrom,
[primaryActions, secondaryActions],
[[cancelAction], []],
[[cancelAction], [exportAction]],
));
const updateCreateActionLabel = () => {
if (createAction.enabled) {
Expand All @@ -931,6 +944,7 @@ export class UserDataProfilesEditorModel extends EditorModel {
}
if (e.name || e.copyFrom) {
updateCreateActionLabel();
exportAction.enabled = isUserDataProfile(this.newProfileElement?.copyFrom);
}
}));
disposables.add(this.userDataProfilesService.onDidChangeProfiles((e) => {
Expand Down Expand Up @@ -972,6 +986,27 @@ export class UserDataProfilesEditorModel extends EditorModel {
}
}

private async exportNewProfile(token: CancellationToken): Promise<void> {
if (!this.newProfileElement) {
return;
}
if (!isUserDataProfile(this.newProfileElement.copyFrom)) {
return;
}
const profile = toUserDataProfile(
generateUuid(),
this.newProfileElement.name,
this.newProfileElement.copyFrom.location,
this.newProfileElement.copyFrom.cacheHome,
{
icon: this.newProfileElement.icon,
useDefaultFlags: this.newProfileElement.flags,
},
this.userDataProfilesService.defaultProfile
);
await this.userDataProfileImportExportService.exportProfile(profile, this.newProfileElement.copyFlags);
}

async saveNewProfile(transient?: boolean, token?: CancellationToken): Promise<IUserDataProfile | undefined> {
if (!this.newProfileElement) {
return undefined;
Expand Down Expand Up @@ -1097,8 +1132,4 @@ export class UserDataProfilesEditorModel extends EditorModel {
private async openWindow(profile: IUserDataProfile): Promise<void> {
await this.hostService.openWindow({ forceProfile: profile.name });
}

private async exportProfile(profile: IUserDataProfile): Promise<void> {
return this.userDataProfileImportExportService.exportProfile(profile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { IFileService } from 'vs/platform/files/common/files';
import { URI } from 'vs/base/common/uri';
import { ITreeItem, ITreeViewDataProvider } from 'vs/workbench/common/views';
import { IUserDataProfile, IUserDataProfileOptions, IUserDataProfilesService, ProfileResourceType, ProfileResourceTypeFlags } from 'vs/platform/userDataProfile/common/userDataProfile';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { SettingsResource, SettingsResourceTreeItem } from 'vs/workbench/services/userDataProfile/browser/settingsResource';
import { KeybindingsResource, KeybindingsResourceTreeItem } from 'vs/workbench/services/userDataProfile/browser/keybindingsResource';
import { SnippetsResource, SnippetsResourceTreeItem } from 'vs/workbench/services/userDataProfile/browser/snippetsResource';
Expand Down Expand Up @@ -74,7 +73,6 @@ export class UserDataProfileImportExportService extends Disposable implements IU
constructor(
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
@IContextKeyService contextKeyService: IContextKeyService,
@IUserDataProfileManagementService private readonly userDataProfileManagementService: IUserDataProfileManagementService,
@IUserDataProfilesService private readonly userDataProfilesService: IUserDataProfilesService,
@IExtensionService private readonly extensionService: IExtensionService,
Expand Down Expand Up @@ -220,10 +218,10 @@ export class UserDataProfileImportExportService extends Disposable implements IU
}
}

async exportProfile(profile: IUserDataProfile): Promise<void> {
async exportProfile(profile: IUserDataProfile, exportFlags?: ProfileResourceTypeFlags): Promise<void> {
const disposables = new DisposableStore();
try {
const userDataProfilesExportState = disposables.add(this.instantiationService.createInstance(UserDataProfileExportState, profile, undefined));
const userDataProfilesExportState = disposables.add(this.instantiationService.createInstance(UserDataProfileExportState, profile, exportFlags));
await this.doExportProfile(userDataProfilesExportState, ProgressLocation.Notification);
} finally {
disposables.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export interface IUserDataProfileImportExportService {
unregisterProfileContentHandler(id: string): void;

resolveProfileTemplate(uri: URI): Promise<IUserDataProfileTemplate | null>;
exportProfile(profile: IUserDataProfile): Promise<void>;
exportProfile(profile: IUserDataProfile, exportFlags?: ProfileResourceTypeFlags): Promise<void>;
createFromProfile(from: IUserDataProfile, options: IUserDataProfileCreateOptions, token: CancellationToken): Promise<IUserDataProfile | undefined>;
createProfileFromTemplate(profileTemplate: IUserDataProfileTemplate, options: IUserDataProfileCreateOptions, token: CancellationToken): Promise<IUserDataProfile | undefined>;
createTroubleshootProfile(): Promise<void>;
Expand Down

0 comments on commit 94f8698

Please sign in to comment.