Skip to content

Commit

Permalink
align auto sync conflicts with manual sync conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jul 20, 2020
1 parent 2f7e5d9 commit 993df78
Showing 1 changed file with 16 additions and 36 deletions.
52 changes: 16 additions & 36 deletions src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
}
},
{
label: localize('accept local', "Accept Local"),
label: localize('accept merges', "Accept Merges"),
run: () => {
this.telemetryService.publicLog2<{ source: string, action: string }, SyncConflictsClassification>('sync/handleConflicts', { source: syncResource, action: 'acceptLocal' });
this.acceptLocal(syncResource, conflicts);
}
},
{
label: localize('show conflicts', "Show Conflicts"),
label: localize('show merges', "Show Merges"),
run: () => {
this.telemetryService.publicLog2<{ source: string, action?: string }, SyncConflictsClassification>('sync/showConflicts', { source: syncResource });
this.handleConflicts([syncResource, conflicts]);
Expand Down Expand Up @@ -651,18 +651,12 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo

private async handleConflicts([syncResource, conflicts]: [SyncResource, IResourcePreview[]]): Promise<void> {
for (const conflict of conflicts) {
let label: string | undefined = undefined;
if (syncResource === SyncResource.Settings) {
label = localize('settings conflicts preview', "Settings Conflicts (Remote ↔ Local)");
} else if (syncResource === SyncResource.Keybindings) {
label = localize('keybindings conflicts preview', "Keybindings Conflicts (Remote ↔ Local)");
} else if (syncResource === SyncResource.Snippets) {
label = localize('snippets conflicts preview', "User Snippet Conflicts (Remote ↔ Local) - {0}", basename(conflict.previewResource));
}
const leftResourceName = localize({ key: 'leftResourceName', comment: ['remote as in file in cloud'] }, "{0} (Remote)", basename(conflict.remoteResource));
const rightResourceName = localize('merges', "{0} (Merges)", basename(conflict.previewResource));
await this.editorService.openEditor({
leftResource: conflict.remoteResource,
rightResource: conflict.previewResource,
label,
label: localize('sideBySideLabels', "{0} ↔ {1}", leftResourceName, rightResourceName),
options: {
preserveFocus: false,
pinned: true,
Expand Down Expand Up @@ -1127,7 +1121,6 @@ class AcceptChangesContribution extends Disposable implements IEditorContributio
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService,
@INotificationService private readonly notificationService: INotificationService,
@IDialogService private readonly dialogService: IDialogService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IUserDataAutoSyncService private readonly userDataAutoSyncService: IUserDataAutoSyncService,
Expand Down Expand Up @@ -1185,35 +1178,22 @@ class AcceptChangesContribution extends Disposable implements IEditorContributio
const [syncResource, conflicts] = this.getSyncResourceConflicts(resource)!;
const isRemote = conflicts.some(({ remoteResource }) => isEqual(remoteResource, resource));
const acceptRemoteLabel = localize('accept remote', "Accept Remote");
const acceptLocalLabel = localize('accept merge preview', "Accept Merge Preview");
this.acceptChangesButton = this.instantiationService.createInstance(FloatingClickWidget, this.editor, isRemote ? acceptRemoteLabel : acceptLocalLabel, null);
const acceptMergesLabel = localize('accept merges', "Accept Merges");
this.acceptChangesButton = this.instantiationService.createInstance(FloatingClickWidget, this.editor, isRemote ? acceptRemoteLabel : acceptMergesLabel, null);
this._register(this.acceptChangesButton.onClick(async () => {
const model = this.editor.getModel();
if (model) {
this.telemetryService.publicLog2<{ source: string, action: string }, SyncConflictsClassification>('sync/handleConflicts', { source: syncResource, action: isRemote ? 'acceptRemote' : 'acceptLocal' });
const syncAreaLabel = getSyncAreaLabel(syncResource);
const result = await this.dialogService.confirm({
type: 'info',
title: isRemote
? localize('Sync accept remote', "Preferences Sync: {0}", acceptRemoteLabel)
: localize('Sync accept local', "Preferences Sync: {0}", acceptLocalLabel),
message: isRemote
? localize('confirm replace and overwrite local', "Would you like to accept remote {0} and replace local {1}?", syncAreaLabel.toLowerCase(), syncAreaLabel.toLowerCase())
: localize('confirm replace and overwrite remote', "Would you like to accept local {0} and replace remote {1}?", syncAreaLabel.toLowerCase(), syncAreaLabel.toLowerCase()),
primaryButton: isRemote ? acceptRemoteLabel : acceptLocalLabel
});
if (result.confirmed) {
try {
await this.userDataSyncService.accept(syncResource, model.uri, model.getValue(), true);
} catch (e) {
if (e instanceof UserDataSyncError && e.code === UserDataSyncErrorCode.LocalPreconditionFailed) {
const syncResourceCoflicts = this.userDataSyncService.conflicts.filter(syncResourceCoflicts => syncResourceCoflicts[0] === syncResource)[0];
if (syncResourceCoflicts && conflicts.some(conflict => isEqual(conflict.previewResource, model.uri) || isEqual(conflict.remoteResource, model.uri))) {
this.notificationService.warn(localize('update conflicts', "Could not resolve conflicts as there is new local version available. Please try again."));
}
} else {
this.notificationService.error(e);
try {
await this.userDataSyncService.accept(syncResource, model.uri, model.getValue(), true);
} catch (e) {
if (e instanceof UserDataSyncError && e.code === UserDataSyncErrorCode.LocalPreconditionFailed) {
const syncResourceCoflicts = this.userDataSyncService.conflicts.filter(syncResourceCoflicts => syncResourceCoflicts[0] === syncResource)[0];
if (syncResourceCoflicts && conflicts.some(conflict => isEqual(conflict.previewResource, model.uri) || isEqual(conflict.remoteResource, model.uri))) {
this.notificationService.warn(localize('update conflicts', "Could not resolve conflicts as there is new local version available. Please try again."));
}
} else {
this.notificationService.error(e);
}
}
}
Expand Down

0 comments on commit 993df78

Please sign in to comment.