Skip to content

Commit 092a43c

Browse files
authored
Merge profile name and configuration pickers (microsoft#187862)
1 parent c9d8ab6 commit 092a43c

File tree

4 files changed

+54
-18
lines changed

4 files changed

+54
-18
lines changed

src/vs/platform/quickinput/browser/media/quickInput.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
}
5151

5252
.quick-input-description {
53-
margin: 6px;
53+
margin: 6px 6px 6px 11px;
5454
}
5555

5656
.quick-input-header .quick-input-description {

src/vs/platform/quickinput/browser/quickInput.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
537537
private _customButtonHover: string | undefined;
538538
private _quickNavigate: IQuickNavigateConfiguration | undefined;
539539
private _hideInput: boolean | undefined;
540+
private _hideCountBadge: boolean | undefined;
540541
private _hideCheckAll: boolean | undefined;
541542

542543
get quickNavigate() {
@@ -796,6 +797,15 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
796797
this.update();
797798
}
798799

800+
get hideCountBadge() {
801+
return !!this._hideCountBadge;
802+
}
803+
804+
set hideCountBadge(hideCountBadge: boolean) {
805+
this._hideCountBadge = hideCountBadge;
806+
this.update();
807+
}
808+
799809
get hideCheckAll() {
800810
return !!this._hideCheckAll;
801811
}
@@ -1038,7 +1048,7 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
10381048
inputBox: !this._hideInput,
10391049
progressBar: !this._hideInput || hasDescription,
10401050
visibleCount: true,
1041-
count: this.canSelectMany,
1051+
count: this.canSelectMany && !this._hideCountBadge,
10421052
ok: this.ok === 'default' ? this.canSelectMany : this.ok,
10431053
list: true,
10441054
message: !!this.validationMessage,
@@ -1315,8 +1325,8 @@ export class QuickInputController extends Disposable {
13151325
const rightActionBar = this._register(new ActionBar(titleBar));
13161326
rightActionBar.domNode.classList.add('quick-input-right-action-bar');
13171327

1318-
const description1 = dom.append(container, $('.quick-input-description'));
13191328
const headerContainer = dom.append(container, $('.quick-input-header'));
1329+
const description1 = dom.append(container, $('.quick-input-description'));
13201330

13211331
const checkAll = <HTMLInputElement>dom.append(headerContainer, $('input.quick-input-check-all'));
13221332
checkAll.type = 'checkbox';

src/vs/platform/quickinput/common/quickInput.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ export interface IQuickPick<T extends IQuickPickItem> extends IQuickInput {
351351

352352
validationMessage: string | undefined;
353353

354+
severity: Severity;
355+
354356
inputHasFocus(): boolean;
355357

356358
focusOnInput(): void;
@@ -362,6 +364,11 @@ export interface IQuickPick<T extends IQuickPickItem> extends IQuickInput {
362364
*/
363365
hideInput: boolean;
364366

367+
/**
368+
* Allows to control if the count for the items should be shown
369+
*/
370+
hideCountBadge: boolean;
371+
365372
hideCheckAll: boolean;
366373

367374
/**

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

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { IProductService } from 'vs/platform/product/common/productService';
3030
import { IRequestService, asJson } from 'vs/platform/request/common/request';
3131
import { CancellationToken } from 'vs/base/common/cancellation';
3232
import { ILogService } from 'vs/platform/log/common/log';
33+
import Severity from 'vs/base/common/severity';
3334

3435
const CREATE_EMPTY_PROFILE_ACTION_ID = 'workbench.profiles.actions.createEmptyProfile';
3536
const CREATE_EMPTY_PROFILE_ACTION_TITLE = {
@@ -500,14 +501,19 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
500501

501502
const quickPick = this.quickInputService.createQuickPick();
502503
quickPick.title = title;
503-
quickPick.hideInput = true;
504+
quickPick.placeholder = localize('name placeholder', "Name the new profile");
504505
quickPick.canSelectMany = true;
506+
quickPick.matchOnDescription = false;
507+
quickPick.matchOnDetail = false;
508+
quickPick.matchOnLabel = false;
509+
quickPick.sortByLabel = false;
510+
quickPick.hideCountBadge = true;
505511
quickPick.ok = false;
506512
quickPick.customButton = true;
507513
quickPick.hideCheckAll = true;
508514
quickPick.ignoreFocusOut = true;
509515
quickPick.customLabel = localize('create', "Create Profile");
510-
quickPick.description = localize('customise the profile', "Choose what you want to configure in the profile. Unselected items are shared from the default profile.");
516+
quickPick.description = localize('customise the profile', "Choose what to configure in the profile. Unselected items are shared from the default profile.");
511517
quickPick.items = resources;
512518
quickPick.selectedItems = resources.filter(item => item.picked);
513519

@@ -518,12 +524,29 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
518524
}
519525
}));
520526

521-
let result: ReadonlyArray<IQuickPickItem> | undefined;
527+
disposables.add(quickPick.onDidChangeValue(value => {
528+
if (this.userDataProfilesService.profiles.some(p => p.name === value)) {
529+
quickPick.validationMessage = localize('profileExists', "Profile with name {0} already exists.", value);
530+
quickPick.severity = Severity.Error;
531+
} else {
532+
quickPick.severity = Severity.Ignore;
533+
quickPick.validationMessage = undefined;
534+
}
535+
}));
536+
537+
let result: { name: string; items: ReadonlyArray<IQuickPickItem> } | undefined;
522538
disposables.add(quickPick.onDidCustom(async () => {
539+
if (!quickPick.value) {
540+
quickPick.validationMessage = localize('name required', "Provide a name for the new profile");
541+
quickPick.severity = Severity.Error;
542+
return;
543+
}
523544
if (resources.some(resource => quickPick.selectedItems.includes(resource))) {
524-
result = quickPick.selectedItems;
545+
result = { name: quickPick.value, items: quickPick.selectedItems };
525546
quickPick.hide();
526547
}
548+
quickPick.severity = Severity.Ignore;
549+
quickPick.validationMessage = undefined;
527550
}));
528551
quickPick.show();
529552

@@ -538,18 +561,14 @@ export class UserDataProfilesWorkbenchContribution extends Disposable implements
538561
return;
539562
}
540563

541-
const name = await this.getNameForProfile(title);
542-
if (!name) {
543-
return;
544-
}
545-
564+
const { name, items } = result;
546565
try {
547-
const useDefaultFlags: UseDefaultProfileFlags | undefined = result.length !== resources.length ? {
548-
settings: !result.includes(settings),
549-
keybindings: !result.includes(keybindings),
550-
snippets: !result.includes(snippets),
551-
tasks: !result.includes(tasks),
552-
extensions: !result.includes(extensions)
566+
const useDefaultFlags: UseDefaultProfileFlags | undefined = items.length !== resources.length ? {
567+
settings: !items.includes(settings),
568+
keybindings: !items.includes(keybindings),
569+
snippets: !items.includes(snippets),
570+
tasks: !items.includes(tasks),
571+
extensions: !items.includes(extensions)
553572
} : undefined;
554573
await this.userDataProfileManagementService.createAndEnterProfile(name, { useDefaultFlags });
555574
} catch (error) {

0 commit comments

Comments
 (0)