Skip to content

Commit

Permalink
implement #192386
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Sep 20, 2023
1 parent ceda6cc commit 41cbeb9
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/vs/base/browser/ui/icons/iconSelectBox.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@

.icon-select-box .icon-select-id-container .icon-select-id-label .highlight {
color: var(--vscode-list-highlightForeground);
font-weight: bold;
}
2 changes: 1 addition & 1 deletion src/vs/base/browser/ui/icons/iconSelectBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class IconSelectBox extends Disposable {
private scrollableElement: DomScrollableElement | undefined;
private iconIdElement: HighlightedLabel | undefined;
private readonly iconContainerWidth = 36;
private readonly iconContainerHeight = 32;
private readonly iconContainerHeight = 36;

constructor(
private readonly options: IIconSelectBoxOptions,
Expand Down
19 changes: 15 additions & 4 deletions src/vs/platform/userDataProfile/common/userDataProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface IUserDataProfile {
readonly isDefault: boolean;
readonly name: string;
readonly shortName?: string;
readonly icon?: string;
readonly location: URI;
readonly globalStorageHome: URI;
readonly settingsResource: URI;
Expand Down Expand Up @@ -84,12 +85,14 @@ export type WillRemoveProfileEvent = {

export interface IUserDataProfileOptions {
readonly shortName?: string;
readonly icon?: string;
readonly useDefaultFlags?: UseDefaultProfileFlags;
readonly transient?: boolean;
}

export interface IUserDataProfileUpdateOptions extends IUserDataProfileOptions {
export interface IUserDataProfileUpdateOptions extends Omit<IUserDataProfileOptions, 'icon'> {
readonly name?: string;
readonly icon?: string | null;
}

export const IUserDataProfilesService = createDecorator<IUserDataProfilesService>('IUserDataProfilesService');
Expand Down Expand Up @@ -124,6 +127,7 @@ export function reviveProfile(profile: UriDto<IUserDataProfile>, scheme: string)
isDefault: profile.isDefault,
name: profile.name,
shortName: profile.shortName,
icon: profile.icon,
location: URI.revive(profile.location).with({ scheme }),
globalStorageHome: URI.revive(profile.globalStorageHome).with({ scheme }),
settingsResource: URI.revive(profile.settingsResource).with({ scheme }),
Expand All @@ -144,6 +148,7 @@ export function toUserDataProfile(id: string, name: string, location: URI, profi
location,
isDefault: false,
shortName: options?.shortName,
icon: options?.icon,
globalStorageHome: defaultProfile && options?.useDefaultFlags?.globalState ? defaultProfile.globalStorageHome : joinPath(location, 'globalStorage'),
settingsResource: defaultProfile && options?.useDefaultFlags?.settings ? defaultProfile.settingsResource : joinPath(location, 'settings.json'),
keybindingsResource: defaultProfile && options?.useDefaultFlags?.keybindings ? defaultProfile.keybindingsResource : joinPath(location, 'keybindings.json'),
Expand All @@ -166,6 +171,7 @@ export type StoredUserDataProfile = {
name: string;
location: URI;
shortName?: string;
icon?: string;
useDefaultFlags?: UseDefaultProfileFlags;
};

Expand Down Expand Up @@ -246,7 +252,7 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf
this.logService.warn('Skipping the invalid stored profile', storedProfile.location || storedProfile.name);
continue;
}
profiles.push(toUserDataProfile(basename(storedProfile.location), storedProfile.name, storedProfile.location, this.profilesCacheHome, { shortName: storedProfile.shortName, useDefaultFlags: storedProfile.useDefaultFlags }, defaultProfile));
profiles.push(toUserDataProfile(basename(storedProfile.location), storedProfile.name, storedProfile.location, this.profilesCacheHome, { shortName: storedProfile.shortName, icon: storedProfile.icon, useDefaultFlags: storedProfile.useDefaultFlags }, defaultProfile));
}
} catch (error) {
this.logService.error(error);
Expand Down Expand Up @@ -365,7 +371,12 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf
throw new Error(`Profile '${profileToUpdate.name}' does not exist`);
}

profile = toUserDataProfile(profile.id, options.name ?? profile.name, profile.location, this.profilesCacheHome, { shortName: options.shortName ?? profile.shortName, transient: options.transient ?? profile.isTransient, useDefaultFlags: options.useDefaultFlags ?? profile.useDefaultFlags }, this.defaultProfile);
profile = toUserDataProfile(profile.id, options.name ?? profile.name, profile.location, this.profilesCacheHome, {
shortName: options.shortName ?? profile.shortName,
icon: options.icon === null ? undefined : options.icon ?? profile.icon,
transient: options.transient ?? profile.isTransient,
useDefaultFlags: options.useDefaultFlags ?? profile.useDefaultFlags
}, this.defaultProfile);
this.updateProfiles([], [], [profile]);

return profile;
Expand Down Expand Up @@ -516,7 +527,7 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf
if (profile.isTransient) {
this.transientProfilesObject.profiles.push(profile);
} else {
storedProfiles.push({ location: profile.location, name: profile.name, shortName: profile.shortName, useDefaultFlags: profile.useDefaultFlags });
storedProfiles.push({ location: profile.location, name: profile.name, shortName: profile.shortName, icon: profile.icon, useDefaultFlags: profile.useDefaultFlags });
}
}
this.saveStoredProfiles(storedProfiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IUserDataProfileInfo {
readonly id: string;
readonly name: string;
readonly shortName?: string;
readonly icon?: string;
readonly useDefaultFlags?: UseDefaultProfileFlags;
}

Expand Down Expand Up @@ -119,14 +120,15 @@ function compare(from: IUserDataProfileInfo[] | null, to: IUserDataProfileInfo[]
const removed = fromKeys.filter(key => !toKeys.includes(key));
const updated: string[] = [];

for (const { id, name, shortName, useDefaultFlags } of from) {
for (const { id, name, shortName, icon, useDefaultFlags } of from) {
if (removed.includes(id)) {
continue;
}
const toProfile = to.find(p => p.id === id);
if (!toProfile
|| toProfile.name !== name
|| toProfile.shortName !== shortName
|| toProfile.icon !== icon
|| !equals(toProfile.useDefaultFlags, useDefaultFlags)
) {
updated.push(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i
for (const profile of local.added) {
promises.push((async () => {
this.logService.trace(`${this.syncResourceLogLabel}: Creating '${profile.name}' profile...`);
await this.userDataProfilesService.createProfile(profile.id, profile.name, { shortName: profile.shortName, useDefaultFlags: profile.useDefaultFlags });
await this.userDataProfilesService.createProfile(profile.id, profile.name, { shortName: profile.shortName, icon: profile.icon, useDefaultFlags: profile.useDefaultFlags });
this.logService.info(`${this.syncResourceLogLabel}: Created profile '${profile.name}'.`);
})());
}
Expand All @@ -207,7 +207,7 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i
if (localProfile) {
promises.push((async () => {
this.logService.trace(`${this.syncResourceLogLabel}: Updating '${profile.name}' profile...`);
await this.userDataProfilesService.updateProfile(localProfile, { name: profile.name, shortName: profile.shortName, useDefaultFlags: profile.useDefaultFlags });
await this.userDataProfilesService.updateProfile(localProfile, { name: profile.name, shortName: profile.shortName, icon: profile.icon, useDefaultFlags: profile.useDefaultFlags });
this.logService.info(`${this.syncResourceLogLabel}: Updated profile '${profile.name}'.`);
})());
} else {
Expand All @@ -225,7 +225,7 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i
for (const profile of remote?.added || []) {
const collection = await this.userDataSyncStoreService.createCollection(this.syncHeaders);
addedCollections.push(collection);
remoteProfiles.push({ id: profile.id, name: profile.name, collection, shortName: profile.shortName, useDefaultFlags: profile.useDefaultFlags });
remoteProfiles.push({ id: profile.id, name: profile.name, collection, shortName: profile.shortName, icon: profile.icon, useDefaultFlags: profile.useDefaultFlags });
}
} else {
this.logService.info(`${this.syncResourceLogLabel}: Could not create remote profiles as there are too many profiles.`);
Expand All @@ -236,7 +236,7 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i
for (const profile of remote?.updated || []) {
const profileToBeUpdated = remoteProfiles.find(({ id }) => profile.id === id);
if (profileToBeUpdated) {
remoteProfiles.splice(remoteProfiles.indexOf(profileToBeUpdated), 1, { ...profileToBeUpdated, id: profile.id, name: profile.name, shortName: profile.shortName, useDefaultFlags: profile.useDefaultFlags });
remoteProfiles.splice(remoteProfiles.indexOf(profileToBeUpdated), 1, { ...profileToBeUpdated, id: profile.id, name: profile.name, shortName: profile.shortName, icon: profile.icon, useDefaultFlags: profile.useDefaultFlags });
}
}

Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/userDataSync/common/userDataSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ export interface ISyncUserDataProfile {
readonly collection: string;
readonly name: string;
readonly shortName?: string;
readonly icon?: string;
readonly useDefaultFlags?: UseDefaultProfileFlags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ export class GlobalActivityActionViewItem extends MenuActivityActionViewItem {
@IKeybindingService keybindingService: IKeybindingService,
) {
super(MenuId.GlobalActivity, action, contextMenuActionsProvider, true, colors, activityHoverOptions, themeService, hoverService, menuService, contextMenuService, contextKeyService, configurationService, environmentService, keybindingService);
this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => this.updateProfileBadge()));
}

override render(container: HTMLElement): void {
Expand Down
20 changes: 16 additions & 4 deletions src/vs/workbench/browser/parts/activitybar/activitybarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import { StringSHA1 } from 'vs/base/common/hash';
import { HoverPosition } from 'vs/base/browser/ui/hover/hoverWidget';
import { GestureEvent } from 'vs/base/browser/touch';
import { IPaneCompositePart, IPaneCompositeSelectorPart } from 'vs/workbench/browser/parts/paneCompositePart';
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataProfile';

interface IPlaceholderViewContainer {
readonly id: string;
Expand Down Expand Up @@ -130,6 +132,7 @@ export class ActivitybarPart extends Part implements IPaneCompositeSelectorPart
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
) {
super(Parts.ACTIVITYBAR_PART, { hasTitle: false }, themeService, storageService, layoutService);

Expand Down Expand Up @@ -523,10 +526,11 @@ export class ActivitybarPart extends Part implements IPaneCompositeSelectorPart
preventLoopNavigation: true
}));

this.globalActivityAction = this._register(new ActivityAction({
id: 'workbench.actions.manage',
name: localize('manage', "Manage"),
classNames: ThemeIcon.asClassNameArray(ActivitybarPart.GEAR_ICON),
this.globalActivityAction = this._register(new ActivityAction(this.createGlobalActivity(this.userDataProfileService.currentProfile)));
this._register(this.userDataProfileService.onDidChangeCurrentProfile(e => {
if (this.globalActivityAction) {
this.globalActivityAction.activity = this.createGlobalActivity(e.profile);
}
}));

if (this.accountsVisibilityPreference) {
Expand All @@ -542,6 +546,14 @@ export class ActivitybarPart extends Part implements IPaneCompositeSelectorPart
this.globalActivityActionBar.push(this.globalActivityAction);
}

private createGlobalActivity(profile: IUserDataProfile): IActivity {
return {
id: 'workbench.actions.manage',
name: localize('manage', "Manage"),
classNames: ThemeIcon.asClassNameArray(profile.icon ? ThemeIcon.fromId(profile.icon) : ActivitybarPart.GEAR_ICON),
};
}

private toggleAccountsActivity() {
if (!!this.accountsActivityAction === this.accountsVisibilityPreference) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,63 @@
padding: 0 4px;
}

.profile-type-widget {
.profile-edit-widget {
padding: 4px 6px 0px 11px;
}

.profile-edit-widget > .profile-icon-container {
display: flex;
margin-bottom: 8px;
}

.profile-edit-widget > .profile-icon-container > .profile-icon {
cursor: pointer;
padding: 3px;
border-radius: 5px;
}

.profile-edit-widget > .profile-icon-container > .profile-icon.codicon{
font-size: 18px;
}

.profile-edit-widget > .profile-icon-container > .profile-icon:hover {
outline: 1px dashed var(--vscode-toolbar-hoverOutline);
outline-offset: -1px;
background-color: var(--vscode-toolbar-hoverBackground);
}

.profile-edit-widget > .profile-type-container {
display: flex;
margin: 0px 6px 8px 11px;
align-items: center;
justify-content: space-between;
font-size: 12px;
margin-bottom: 8px;
}

.profile-edit-widget > .profile-icon-container > .profile-icon-label,
.profile-edit-widget > .profile-type-container > .profile-type-create-label {
width: 90px;
display: inline-flex;
align-items: center;
}

.profile-edit-widget > .profile-icon-container > .profile-icon-id {
display: inline-flex;
align-items: center;
margin-left: 5px;
opacity: .8;
font-size: 0.9em;
}

.profile-type-widget>.profile-type-select-container {
.profile-edit-widget > .profile-type-container > .profile-type-select-container {
overflow: hidden;
padding-left: 10px;
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}

.profile-type-widget>.profile-type-select-container>.monaco-select-box {
.profile-edit-widget > .profile-type-container > .profile-type-select-container > .monaco-select-box {
cursor: pointer;
line-height: 17px;
padding: 2px 23px 2px 8px;
Expand Down
Loading

0 comments on commit 41cbeb9

Please sign in to comment.