Skip to content

Commit 183e40f

Browse files
committed
Rename the button to call out replace and show a confirmation dialog
1 parent 3c37e5a commit 183e40f

1 file changed

Lines changed: 40 additions & 16 deletions

File tree

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

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ const CONTEXT_AUTH_TOKEN_STATE = new RawContextKey<string>('authTokenStatus', Au
5757

5858
type ConfigureSyncQuickPickItem = { id: string, label: string, description?: string };
5959

60+
function getSyncAreaLabel(source: SyncSource): string {
61+
switch (source) {
62+
case SyncSource.Settings: return localize('settings', "Settings");
63+
case SyncSource.Keybindings: return localize('keybindings', "Keybindings");
64+
case SyncSource.Extensions: return localize('extensions', "Extensions");
65+
case SyncSource.UIState: return localize('ui state label', "UI State");
66+
}
67+
}
68+
6069
export class UserDataSyncWorkbenchContribution extends Disposable implements IWorkbenchContribution {
6170

6271
private static readonly ENABLEMENT_SETTING = 'sync.enable';
@@ -198,7 +207,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
198207

199208
if (this.userDataSyncService.status === SyncStatus.HasConflicts) {
200209
if (!this.conflictsWarningDisposable.value) {
201-
const conflictsArea = this.userDataSyncService.conflictsSource === SyncSource.Settings ? localize('settings', "Settings") : localize('keybindings', "Keybindings");
210+
const conflictsArea = getSyncAreaLabel(this.userDataSyncService.conflictsSource!);
202211
const handle = this.notificationService.prompt(Severity.Warning, localize('conflicts detected', "Unable to sync due to conflicts in {0}. Please resolve them to continue.", conflictsArea),
203212
[
204213
{
@@ -308,16 +317,16 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
308317
private getConfigureSyncQuickPickItems(): ConfigureSyncQuickPickItem[] {
309318
return [{
310319
id: 'sync.enableSettings',
311-
label: localize('settings', "Settings")
320+
label: getSyncAreaLabel(SyncSource.Settings)
312321
}, {
313322
id: 'sync.enableKeybindings',
314-
label: localize('keybindings', "Keybindings")
323+
label: getSyncAreaLabel(SyncSource.Keybindings)
315324
}, {
316325
id: 'sync.enableExtensions',
317-
label: localize('extensions', "Extensions")
326+
label: getSyncAreaLabel(SyncSource.Extensions)
318327
}, {
319328
id: 'sync.enableUIState',
320-
label: localize('ui state label', "UI State"),
329+
label: getSyncAreaLabel(SyncSource.UIState),
321330
description: localize('ui state description', "Display Language (Only)")
322331
}];
323332
}
@@ -680,7 +689,8 @@ class AcceptChangesContribution extends Disposable implements IEditorContributio
680689
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
681690
@IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService,
682691
@IFileService private readonly fileService: IFileService,
683-
@INotificationService private readonly notificationService: INotificationService
692+
@INotificationService private readonly notificationService: INotificationService,
693+
@IDialogService private readonly dialogService: IDialogService
684694
) {
685695
super();
686696

@@ -724,22 +734,36 @@ class AcceptChangesContribution extends Disposable implements IEditorContributio
724734

725735
private createAcceptChangesWidgetRenderer(): void {
726736
if (!this.acceptChangesButton) {
727-
this.acceptChangesButton = this.instantiationService.createInstance(FloatingClickWidget, this.editor, getSyncSourceFromRemoteContentResource(this.editor.getModel()!.uri) !== undefined ? localize('accept remote', "Accept (Remote)") : localize('accept local', "Accept (Local)"), null);
737+
const replaceLabel = localize('accept remote', "Replace (Overwrite Local)");
738+
const acceptLabel = localize('accept local', "Accept");
739+
this.acceptChangesButton = this.instantiationService.createInstance(FloatingClickWidget, this.editor, getSyncSourceFromRemoteContentResource(this.editor.getModel()!.uri) !== undefined ? replaceLabel : acceptLabel, null);
728740
this._register(this.acceptChangesButton.onClick(async () => {
729741
const model = this.editor.getModel();
730742
if (model) {
731743
try {
732744
const syncSource = getSyncSourceFromRemoteContentResource(model.uri);
733-
if (syncSource === SyncSource.Settings) {
734-
const remoteContent = await this.userDataSyncService.getRemoteContent(SyncSource.Settings);
735-
if (remoteContent) {
736-
await this.fileService.writeFile(this.environmentService.settingsSyncPreviewResource, VSBuffer.fromString(remoteContent));
745+
if (syncSource !== undefined) {
746+
const syncAreaLabel = getSyncAreaLabel(syncSource);
747+
const result = await this.dialogService.confirm({
748+
type: 'info',
749+
title: localize('Sync overwrite local', "Sync: {0}", replaceLabel),
750+
message: localize('confirm replace and overwrite local', "Would you like to replace Local {0} with Remote {1}?", syncAreaLabel, syncAreaLabel),
751+
primaryButton: replaceLabel
752+
});
753+
if (!result.confirmed) {
754+
return;
737755
}
738-
}
739-
else if (syncSource === SyncSource.Keybindings) {
740-
const remoteContent = await this.userDataSyncService.getRemoteContent(SyncSource.Keybindings);
741-
if (remoteContent) {
742-
await this.fileService.writeFile(this.environmentService.keybindingsSyncPreviewResource, VSBuffer.fromString(remoteContent));
756+
if (syncSource === SyncSource.Settings) {
757+
const remoteContent = await this.userDataSyncService.getRemoteContent(SyncSource.Settings);
758+
if (remoteContent) {
759+
await this.fileService.writeFile(this.environmentService.settingsSyncPreviewResource, VSBuffer.fromString(remoteContent));
760+
}
761+
}
762+
else if (syncSource === SyncSource.Keybindings) {
763+
const remoteContent = await this.userDataSyncService.getRemoteContent(SyncSource.Keybindings);
764+
if (remoteContent) {
765+
await this.fileService.writeFile(this.environmentService.keybindingsSyncPreviewResource, VSBuffer.fromString(remoteContent));
766+
}
743767
}
744768
}
745769
await this.userDataSyncService.sync(true);

0 commit comments

Comments
 (0)