Skip to content

Commit 525b7a4

Browse files
authored
profile improvements (microsoft#188245)
- fix edit title - show using default profile
1 parent c85bf61 commit 525b7a4

File tree

6 files changed

+250
-190
lines changed

6 files changed

+250
-190
lines changed

src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
7878
import { IStringDictionary } from 'vs/base/common/collections';
7979
import { CONTEXT_KEYBINDINGS_EDITOR } from 'vs/workbench/contrib/preferences/common/preferences';
8080
import { DeprecatedExtensionsChecker } from 'vs/workbench/contrib/extensions/browser/deprecatedExtensionsChecker';
81+
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
8182

8283
// Singletons
8384
registerSingleton(IExtensionsWorkbenchService, ExtensionsWorkbenchService, InstantiationType.Eager /* Auto updates extensions */);
@@ -472,6 +473,7 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi
472473
@IInstantiationService private readonly instantiationService: IInstantiationService,
473474
@IDialogService private readonly dialogService: IDialogService,
474475
@ICommandService private readonly commandService: ICommandService,
476+
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
475477
) {
476478
super();
477479
const hasGalleryContext = CONTEXT_HAS_GALLERY.bindTo(contextKeyService);
@@ -515,22 +517,31 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi
515517

516518
// Global actions
517519
private registerGlobalActions(): void {
518-
this._register(MenuRegistry.appendMenuItem(MenuId.MenubarPreferencesMenu, {
519-
command: {
520-
id: VIEWLET_ID,
521-
title: localize({ key: 'miPreferencesExtensions', comment: ['&& denotes a mnemonic'] }, "&&Extensions")
522-
},
523-
group: '2_configuration',
524-
order: 3
525-
}));
526-
this._register(MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
527-
command: {
528-
id: VIEWLET_ID,
529-
title: localize('showExtensions', "Extensions")
530-
},
531-
group: '2_configuration',
532-
order: 3
533-
}));
520+
const getTitle = (title: string) => !this.userDataProfileService.currentProfile.isDefault && this.userDataProfileService.currentProfile.useDefaultFlags?.extensions
521+
? `${title} (${localize('default profile', "Default Profile")})`
522+
: title;
523+
const registerOpenExtensionsActionDisposables = this._register(new DisposableStore());
524+
const registerOpenExtensionsAction = () => {
525+
registerOpenExtensionsActionDisposables.clear();
526+
registerOpenExtensionsActionDisposables.add(MenuRegistry.appendMenuItem(MenuId.MenubarPreferencesMenu, {
527+
command: {
528+
id: VIEWLET_ID,
529+
title: getTitle(localize({ key: 'miPreferencesExtensions', comment: ['&& denotes a mnemonic'] }, "&&Extensions"))
530+
},
531+
group: '2_configuration',
532+
order: 3
533+
}));
534+
registerOpenExtensionsActionDisposables.add(MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
535+
command: {
536+
id: VIEWLET_ID,
537+
title: getTitle(localize('showExtensions', "Extensions"))
538+
},
539+
group: '2_configuration',
540+
order: 3
541+
}));
542+
};
543+
registerOpenExtensionsAction();
544+
this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => registerOpenExtensionsAction()));
534545

535546
this.registerExtensionAction({
536547
id: 'workbench.extensions.action.installExtensions',

src/vs/workbench/contrib/preferences/browser/preferences.contribution.ts

Lines changed: 93 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -187,37 +187,46 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon
187187
}
188188

189189
private registerSettingsActions() {
190-
this._register(registerAction2(class extends Action2 {
191-
constructor() {
192-
super({
193-
id: SETTINGS_COMMAND_OPEN_SETTINGS,
194-
title: {
195-
value: nls.localize('settings', "Settings"),
196-
mnemonicTitle: nls.localize({ key: 'miOpenSettings', comment: ['&& denotes a mnemonic'] }, "&&Settings"),
197-
original: 'Settings'
198-
},
199-
keybinding: {
200-
weight: KeybindingWeight.WorkbenchContrib,
201-
when: null,
202-
primary: KeyMod.CtrlCmd | KeyCode.Comma,
203-
},
204-
menu: [{
205-
id: MenuId.GlobalActivity,
206-
group: '2_configuration',
207-
order: 1
208-
}, {
209-
id: MenuId.MenubarPreferencesMenu,
210-
group: '2_configuration',
211-
order: 1
212-
}],
213-
});
214-
}
215-
run(accessor: ServicesAccessor, args: string | IOpenSettingsActionOptions) {
216-
// args takes a string for backcompat
217-
const opts = typeof args === 'string' ? { query: args } : sanitizeOpenSettingsArgs(args);
218-
return accessor.get(IPreferencesService).openSettings(opts);
219-
}
220-
}));
190+
const registerOpenSettingsActionDisposables = this._register(new DisposableStore());
191+
const registerOpenSettingsAction = () => {
192+
registerOpenSettingsActionDisposables.clear();
193+
const getTitle = (title: string) => !this.userDataProfileService.currentProfile.isDefault && this.userDataProfileService.currentProfile.useDefaultFlags?.settings
194+
? `${title} (${nls.localize('default profile', "Default Profile")})`
195+
: title;
196+
registerOpenSettingsActionDisposables.add(registerAction2(class extends Action2 {
197+
constructor() {
198+
super({
199+
id: SETTINGS_COMMAND_OPEN_SETTINGS,
200+
title: {
201+
value: getTitle(nls.localize('settings', "Settings")),
202+
mnemonicTitle: getTitle(nls.localize({ key: 'miOpenSettings', comment: ['&& denotes a mnemonic'] }, "&&Settings")),
203+
original: 'Settings'
204+
},
205+
keybinding: {
206+
weight: KeybindingWeight.WorkbenchContrib,
207+
when: null,
208+
primary: KeyMod.CtrlCmd | KeyCode.Comma,
209+
},
210+
menu: [{
211+
id: MenuId.GlobalActivity,
212+
group: '2_configuration',
213+
order: 1
214+
}, {
215+
id: MenuId.MenubarPreferencesMenu,
216+
group: '2_configuration',
217+
order: 1
218+
}],
219+
});
220+
}
221+
run(accessor: ServicesAccessor, args: string | IOpenSettingsActionOptions) {
222+
// args takes a string for backcompat
223+
const opts = typeof args === 'string' ? { query: args } : sanitizeOpenSettingsArgs(args);
224+
return accessor.get(IPreferencesService).openSettings(opts);
225+
}
226+
}));
227+
};
228+
registerOpenSettingsAction();
229+
this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => registerOpenSettingsAction()));
221230
registerAction2(class extends Action2 {
222231
constructor() {
223232
super({
@@ -296,13 +305,13 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon
296305
}
297306
});
298307

299-
const registerOpenUserSettingsEditorFromJsonActionDisposables = this._register(new MutableDisposable());
308+
const registerOpenUserSettingsEditorFromJsonActionDisposable = this._register(new MutableDisposable());
300309
const openUserSettingsEditorWhen = ContextKeyExpr.and(
301310
ContextKeyExpr.or(ResourceContextKey.Resource.isEqualTo(this.userDataProfileService.currentProfile.settingsResource.toString()),
302311
ResourceContextKey.Resource.isEqualTo(this.userDataProfilesService.defaultProfile.settingsResource.toString())),
303312
ContextKeyExpr.not('isInDiffEditor'));
304313
const registerOpenUserSettingsEditorFromJsonAction = () => {
305-
registerOpenUserSettingsEditorFromJsonActionDisposables.value = registerAction2(class extends Action2 {
314+
registerOpenUserSettingsEditorFromJsonActionDisposable.value = registerAction2(class extends Action2 {
306315
constructor() {
307316
super({
308317
id: '_workbench.openUserSettingsEditor',
@@ -806,49 +815,58 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon
806815
private registerKeybindingsActions() {
807816
const that = this;
808817
const category = { value: nls.localize('preferences', "Preferences"), original: 'Preferences' };
809-
const id = 'workbench.action.openGlobalKeybindings';
810-
this._register(registerAction2(class extends Action2 {
811-
constructor() {
812-
super({
813-
id,
814-
title: { value: nls.localize('openGlobalKeybindings', "Open Keyboard Shortcuts"), original: 'Open Keyboard Shortcuts' },
815-
shortTitle: nls.localize('keyboardShortcuts', "Keyboard Shortcuts"),
816-
category,
817-
icon: preferencesOpenSettingsIcon,
818-
keybinding: {
819-
when: null,
820-
weight: KeybindingWeight.WorkbenchContrib,
821-
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyS)
822-
},
823-
menu: [
824-
{ id: MenuId.CommandPalette },
825-
{
826-
id: MenuId.EditorTitle,
827-
when: ResourceContextKey.Resource.isEqualTo(that.userDataProfileService.currentProfile.keybindingsResource.toString()),
828-
group: 'navigation',
829-
order: 1,
818+
const registerOpenGlobalKeybindingsActionDisposables = this._register(new DisposableStore());
819+
const registerOpenGlobalKeybindingsAction = () => {
820+
registerOpenGlobalKeybindingsActionDisposables.clear();
821+
const id = 'workbench.action.openGlobalKeybindings';
822+
const shortTitle = !that.userDataProfileService.currentProfile.isDefault && that.userDataProfileService.currentProfile.useDefaultFlags?.keybindings
823+
? nls.localize('keyboardShortcutsFromDefault', "Keyboard Shortcuts ({0})", nls.localize('default profile', "Default Profile"))
824+
: nls.localize('keyboardShortcuts', "Keyboard Shortcuts");
825+
registerOpenGlobalKeybindingsActionDisposables.add(registerAction2(class extends Action2 {
826+
constructor() {
827+
super({
828+
id,
829+
title: { value: nls.localize('openGlobalKeybindings', "Open Keyboard Shortcuts"), original: 'Open Keyboard Shortcuts' },
830+
shortTitle,
831+
category,
832+
icon: preferencesOpenSettingsIcon,
833+
keybinding: {
834+
when: null,
835+
weight: KeybindingWeight.WorkbenchContrib,
836+
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyS)
830837
},
831-
{
832-
id: MenuId.GlobalActivity,
833-
group: '2_configuration',
834-
order: 3
835-
}
836-
]
837-
});
838-
}
839-
run(accessor: ServicesAccessor, args: string | undefined) {
840-
const query = typeof args === 'string' ? args : undefined;
841-
return accessor.get(IPreferencesService).openGlobalKeybindingSettings(false, { query });
842-
}
843-
}));
844-
this._register(MenuRegistry.appendMenuItem(MenuId.MenubarPreferencesMenu, {
845-
command: {
846-
id,
847-
title: nls.localize('keyboardShortcuts', "Keyboard Shortcuts"),
848-
},
849-
group: '2_configuration',
850-
order: 3
851-
}));
838+
menu: [
839+
{ id: MenuId.CommandPalette },
840+
{
841+
id: MenuId.EditorTitle,
842+
when: ResourceContextKey.Resource.isEqualTo(that.userDataProfileService.currentProfile.keybindingsResource.toString()),
843+
group: 'navigation',
844+
order: 1,
845+
},
846+
{
847+
id: MenuId.GlobalActivity,
848+
group: '2_configuration',
849+
order: 3
850+
}
851+
]
852+
});
853+
}
854+
run(accessor: ServicesAccessor, args: string | undefined) {
855+
const query = typeof args === 'string' ? args : undefined;
856+
return accessor.get(IPreferencesService).openGlobalKeybindingSettings(false, { query });
857+
}
858+
}));
859+
registerOpenGlobalKeybindingsActionDisposables.add(MenuRegistry.appendMenuItem(MenuId.MenubarPreferencesMenu, {
860+
command: {
861+
id,
862+
title: shortTitle,
863+
},
864+
group: '2_configuration',
865+
order: 3
866+
}));
867+
};
868+
registerOpenGlobalKeybindingsAction();
869+
this._register(this.userDataProfileService.onDidChangeCurrentProfile(() => registerOpenGlobalKeybindingsAction()));
852870
registerAction2(class extends Action2 {
853871
constructor() {
854872
super({

0 commit comments

Comments
 (0)