提交 b135faa0 编写于 作者: S Sandeep Somavarapu

#85216 use quick pick to turn on

上级 7e2f61f3
...@@ -48,6 +48,7 @@ const SYNC_PUSH_LIGHT_ICON_URI = URI.parse(registerAndGetAmdImageURL(`vs/workben ...@@ -48,6 +48,7 @@ const SYNC_PUSH_LIGHT_ICON_URI = URI.parse(registerAndGetAmdImageURL(`vs/workben
const SYNC_PUSH_DARK_ICON_URI = URI.parse(registerAndGetAmdImageURL(`vs/workbench/contrib/userDataSync/browser/media/check-dark.svg`)); const SYNC_PUSH_DARK_ICON_URI = URI.parse(registerAndGetAmdImageURL(`vs/workbench/contrib/userDataSync/browser/media/check-dark.svg`));
const MSA = 'MSA'; const MSA = 'MSA';
type ConfigureSyncQuickPickItem = { id: string, label: string, description?: string };
export class UserDataSyncWorkbenchContribution extends Disposable implements IWorkbenchContribution { export class UserDataSyncWorkbenchContribution extends Disposable implements IWorkbenchContribution {
...@@ -253,90 +254,91 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo ...@@ -253,90 +254,91 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
} }
private async turnOn(): Promise<void> { private async turnOn(): Promise<void> {
const message = localize('turn on sync', "Turn on Sync"); return new Promise((c, e) => {
let detail: string, primaryButton: string; const disposables: DisposableStore = new DisposableStore();
if (this.authenticationState.get() === MSAAuthStatus.SignedIn) { const quickPick = this.quickInputService.createQuickPick<ConfigureSyncQuickPickItem>();
detail = `${localize('turn on sync detail', "This will synchronize your following data across all your devices.")}\n${this.getSyncAreasString()}`; disposables.add(quickPick);
primaryButton = localize('turn on', "Turn on"); quickPick.title = localize('turn on sync', "Turn on Sync");
} else { quickPick.ok = false;
detail = `${localize('sign in and turn on sync detail', "Please sign in with your {0} account to synchronize your following data across all your devices.", this.userDataSyncStore!.account)}\n${this.getSyncAreasString()}`; quickPick.customButton = true;
primaryButton = localize('sign in and turn on sync', "Sign in & Turn on"); if (this.authenticationState.get() === MSAAuthStatus.SignedIn) {
} quickPick.description = localize('turn on sync detail', "Turn on to synchronize your following data across all your devices.");
const result = await this.dialogService.show( quickPick.customLabel = localize('turn on', "Turn on");
Severity.Info, message, } else {
[ quickPick.description = localize('sign in and turn on sync detail', "Please sign in with your {0} account to synchronize your following data across all your devices.", this.userDataSyncStore!.account);
primaryButton, quickPick.customLabel = localize('sign in and turn on sync', "Sign in & Turn on");
localize('cancel', "Cancel"), }
localize('configure', "Configure...") quickPick.placeholder = localize('configure sync placeholder', "Choose what to sync");
], quickPick.canSelectMany = true;
{ quickPick.ignoreFocusOut = true;
detail, const items = this.getConfigureSyncQuickPickItems();
cancelId: 1 quickPick.items = items;
}); quickPick.selectedItems = items.filter(item => this.configurationService.getValue(item.id));
switch (result.choice) { disposables.add(Event.any(quickPick.onDidAccept, quickPick.onDidCustom)(async () => {
case 1: return; if (quickPick.selectedItems.length) {
case 2: await this.configureSyncOptions(); return this.turnOn(); await this.updateConfiguration(items, quickPick.selectedItems);
} this.doTurnOn();
quickPick.hide();
}
}));
disposables.add(quickPick.onDidHide(() => {
disposables.dispose();
c();
}));
quickPick.show();
});
}
private async doTurnOn(): Promise<void> {
if (this.authenticationState.get() === MSAAuthStatus.SignedOut) { if (this.authenticationState.get() === MSAAuthStatus.SignedOut) {
await this.signIn(); await this.signIn();
} }
await this.handleFirstTimeSync(); await this.handleFirstTimeSync();
await this.enableSync(); await this.enableSync();
} }
private getSyncAreasString(): string { private getConfigureSyncQuickPickItems(): ConfigureSyncQuickPickItem[] {
const { enableSettings, enableKeybindings, enableExtensions, enableUIState } = this.configurationService.getValue<{ enableSettings: boolean, enableKeybindings: boolean, enableExtensions: boolean, enableUIState: boolean }>('sync'); return [{
let result = ''; id: 'sync.enableSettings',
if (enableSettings) { label: localize('settings', "Settings")
result += '\n - ' + localize('settings', "Settings"); }, {
} id: 'sync.enableKeybindings',
if (enableKeybindings) { label: localize('keybindings', "Keybindings")
result += '\n - ' + localize('keybindings', "Keybindings"); }, {
} id: 'sync.enableExtensions',
if (enableExtensions) { label: localize('extensions', "Extensions")
result += '\n - ' + localize('extensions', "Extensions"); }, {
} id: 'sync.enableUIState',
if (enableUIState) { label: localize('ui state label', "UI State"),
result += '\n - ' + localize('ui state', "UI State (Display Language Only)"); description: localize('ui state description', "Display Language (Only)")
}];
}
private async updateConfiguration(items: ConfigureSyncQuickPickItem[], selectedItems: ReadonlyArray<ConfigureSyncQuickPickItem>): Promise<void> {
for (const item of items) {
const wasEnabled = this.configurationService.getValue(item.id);
const isEnabled = !!selectedItems.filter(selected => selected.id === item.id)[0];
if (wasEnabled !== isEnabled) {
await this.configurationService.updateValue(item.id!, isEnabled);
}
} }
return result;
} }
private async configureSyncOptions(): Promise<ISyncConfiguration> { private async configureSyncOptions(): Promise<ISyncConfiguration> {
return new Promise((c, e) => { return new Promise((c, e) => {
const disposables: DisposableStore = new DisposableStore(); const disposables: DisposableStore = new DisposableStore();
const quickPick = this.quickInputService.createQuickPick(); const quickPick = this.quickInputService.createQuickPick<ConfigureSyncQuickPickItem>();
disposables.add(quickPick); disposables.add(quickPick);
quickPick.title = localize('configure sync title', "Sync: Configure What to Sync"); quickPick.title = localize('turn on sync', "Turn on Sync");
quickPick.placeholder = localize('configure sync placeholder', "Choose what to sync"); quickPick.placeholder = localize('configure sync placeholder', "Choose what to sync");
quickPick.canSelectMany = true; quickPick.canSelectMany = true;
quickPick.ignoreFocusOut = true; quickPick.ignoreFocusOut = true;
const items = [{ const items = this.getConfigureSyncQuickPickItems();
id: 'sync.enableSettings',
label: localize('settings', "Settings")
}, {
id: 'sync.enableKeybindings',
label: localize('keybindings', "Keybindings")
}, {
id: 'sync.enableExtensions',
label: localize('extensions', "Extensions")
}, {
id: 'sync.enableUIState',
label: localize('ui state label', "UI State"),
description: localize('ui state description', "Display Language (Only)")
}];
quickPick.items = items; quickPick.items = items;
quickPick.selectedItems = items.filter(item => this.configurationService.getValue(item.id)); quickPick.selectedItems = items.filter(item => this.configurationService.getValue(item.id));
disposables.add(quickPick.onDidAccept(async () => { disposables.add(quickPick.onDidAccept(async () => {
if (quickPick.selectedItems.length) { if (quickPick.selectedItems.length) {
for (const item of items) { await this.updateConfiguration(items, quickPick.selectedItems);
const wasEnabled = this.configurationService.getValue(item.id);
const isEnabled = !!quickPick.selectedItems.filter(selected => selected.id === item.id)[0];
if (wasEnabled !== isEnabled) {
await this.configurationService.updateValue(item.id!, isEnabled);
}
}
quickPick.hide(); quickPick.hide();
} }
})); }));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册