|
6 | 6 | import { Action } from 'vs/base/common/actions';
|
7 | 7 | import { getErrorMessage, isCancellationError } from 'vs/base/common/errors';
|
8 | 8 | import { Event } from 'vs/base/common/event';
|
9 |
| -import { Disposable, DisposableStore, MutableDisposable, toDisposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; |
| 9 | +import { Disposable, DisposableStore, MutableDisposable, toDisposable, IDisposable } from 'vs/base/common/lifecycle'; |
10 | 10 | import { isEqual, basename } from 'vs/base/common/resources';
|
11 | 11 | import { URI } from 'vs/base/common/uri';
|
12 |
| -import { registerEditorContribution, ServicesAccessor } from 'vs/editor/browser/editorExtensions'; |
| 12 | +import { ServicesAccessor } from 'vs/editor/browser/editorExtensions'; |
13 | 13 | import type { ITextModel } from 'vs/editor/common/model';
|
14 | 14 | import { IModelService } from 'vs/editor/common/services/model';
|
15 | 15 | import { ILanguageService } from 'vs/editor/common/languages/language';
|
@@ -59,10 +59,6 @@ import { IHostService } from 'vs/workbench/services/host/browser/host';
|
59 | 59 | import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
|
60 | 60 | import { MergeEditorInput } from 'vs/workbench/contrib/mergeEditor/browser/mergeEditorInput';
|
61 | 61 | import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
|
62 |
| -import { FloatingClickWidget } from 'vs/workbench/browser/codeeditor'; |
63 |
| -import { IEditorContribution } from 'vs/editor/common/editorCommon'; |
64 |
| -import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; |
65 |
| -import { EditorResolution } from 'vs/platform/editor/common/editor'; |
66 | 62 |
|
67 | 63 | const CONTEXT_CONFLICTS_SOURCES = new RawContextKey<string>('conflictsSources', '');
|
68 | 64 |
|
@@ -169,7 +165,6 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
|
169 | 165 | this.registerViews();
|
170 | 166 |
|
171 | 167 | textModelResolverService.registerTextModelContentProvider(USER_DATA_SYNC_SCHEME, instantiationService.createInstance(UserDataRemoteContentProvider));
|
172 |
| - registerEditorContribution(AcceptChangesContribution.ID, AcceptChangesContribution); |
173 | 168 |
|
174 | 169 | this._register(Event.any(userDataSyncService.onDidChangeStatus, userDataSyncEnablementService.onDidChangeEnablement)
|
175 | 170 | (() => this.turningOnSync = !userDataSyncEnablementService.isEnabled() && userDataSyncService.status !== SyncStatus.Idle));
|
@@ -730,35 +725,17 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
|
730 | 725 | }
|
731 | 726 |
|
732 | 727 | private async handleConflicts([syncResource, conflicts]: [SyncResource, IResourcePreview[]]): Promise<void> {
|
733 |
| - const useMergeEditor = this.configurationService.getValue('settingsSync.mergeEditor') ?? true; |
734 | 728 | for (const conflict of conflicts) {
|
735 |
| - if (useMergeEditor) { |
736 |
| - const remoteResourceName = localize({ key: 'remoteResourceName', comment: ['remote as in file in cloud'] }, "{0} (Remote)", basename(conflict.remoteResource)); |
737 |
| - const localResourceName = localize('localResourceName', "{0} (Local)", basename(conflict.remoteResource)); |
738 |
| - const input = this.instantiationService.createInstance( |
739 |
| - MergeEditorInput, |
740 |
| - conflict.baseResource, |
741 |
| - { title: localize('Yours', 'Yours'), description: localResourceName, detail: undefined, uri: conflict.localResource }, |
742 |
| - { title: localize('Theirs', 'Theirs'), description: remoteResourceName, detail: undefined, uri: conflict.remoteResource }, |
743 |
| - conflict.previewResource, |
744 |
| - ); |
745 |
| - await this.editorService.openEditor(input); |
746 |
| - } else { |
747 |
| - const leftResourceName = localize({ key: 'leftResourceName', comment: ['remote as in file in cloud'] }, "{0} (Remote)", basename(conflict.remoteResource)); |
748 |
| - const rightResourceName = localize('merges', "{0} (Merges)", basename(conflict.previewResource)); |
749 |
| - await this.editorService.openEditor({ |
750 |
| - original: { resource: conflict.remoteResource }, |
751 |
| - modified: { resource: conflict.previewResource }, |
752 |
| - label: localize('sideBySideLabels', "{0} ↔ {1}", leftResourceName, rightResourceName), |
753 |
| - description: localize('sideBySideDescription', "Settings Sync"), |
754 |
| - options: { |
755 |
| - preserveFocus: false, |
756 |
| - pinned: true, |
757 |
| - revealIfVisible: true, |
758 |
| - override: EditorResolution.DISABLED |
759 |
| - }, |
760 |
| - }); |
761 |
| - } |
| 729 | + const remoteResourceName = localize({ key: 'remoteResourceName', comment: ['remote as in file in cloud'] }, "{0} (Remote)", basename(conflict.remoteResource)); |
| 730 | + const localResourceName = localize('localResourceName', "{0} (Local)", basename(conflict.remoteResource)); |
| 731 | + const input = this.instantiationService.createInstance( |
| 732 | + MergeEditorInput, |
| 733 | + conflict.baseResource, |
| 734 | + { title: localize('Yours', 'Yours'), description: localResourceName, detail: undefined, uri: conflict.localResource }, |
| 735 | + { title: localize('Theirs', 'Theirs'), description: remoteResourceName, detail: undefined, uri: conflict.remoteResource }, |
| 736 | + conflict.previewResource, |
| 737 | + ); |
| 738 | + await this.editorService.openEditor(input); |
762 | 739 | }
|
763 | 740 | }
|
764 | 741 |
|
@@ -1394,131 +1371,3 @@ class UserDataRemoteContentProvider implements ITextModelContentProvider {
|
1394 | 1371 | return null;
|
1395 | 1372 | }
|
1396 | 1373 | }
|
1397 |
| - |
1398 |
| -class AcceptChangesContribution extends Disposable implements IEditorContribution { |
1399 |
| - |
1400 |
| - static get(editor: ICodeEditor): AcceptChangesContribution | null { |
1401 |
| - return editor.getContribution<AcceptChangesContribution>(AcceptChangesContribution.ID); |
1402 |
| - } |
1403 |
| - |
1404 |
| - public static readonly ID = 'editor.contrib.acceptChangesButton'; |
1405 |
| - |
1406 |
| - private acceptChangesButton: FloatingClickWidget | undefined; |
1407 |
| - |
1408 |
| - constructor( |
1409 |
| - private editor: ICodeEditor, |
1410 |
| - @IInstantiationService private readonly instantiationService: IInstantiationService, |
1411 |
| - @IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService, |
1412 |
| - @INotificationService private readonly notificationService: INotificationService, |
1413 |
| - @IDialogService private readonly dialogService: IDialogService, |
1414 |
| - @IConfigurationService private readonly configurationService: IConfigurationService, |
1415 |
| - @ITelemetryService private readonly telemetryService: ITelemetryService, |
1416 |
| - @IUserDataSyncEnablementService private readonly userDataSyncEnablementService: IUserDataSyncEnablementService, |
1417 |
| - ) { |
1418 |
| - super(); |
1419 |
| - |
1420 |
| - this.update(); |
1421 |
| - this.registerListeners(); |
1422 |
| - } |
1423 |
| - |
1424 |
| - private registerListeners(): void { |
1425 |
| - this._register(this.editor.onDidChangeModel(() => this.update())); |
1426 |
| - this._register(this.userDataSyncService.onDidChangeConflicts(() => this.update())); |
1427 |
| - this._register(Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('diffEditor.renderSideBySide'))(() => this.update())); |
1428 |
| - } |
1429 |
| - |
1430 |
| - private update(): void { |
1431 |
| - if (!this.shouldShowButton(this.editor)) { |
1432 |
| - this.disposeAcceptChangesWidgetRenderer(); |
1433 |
| - return; |
1434 |
| - } |
1435 |
| - |
1436 |
| - this.createAcceptChangesWidgetRenderer(); |
1437 |
| - } |
1438 |
| - |
1439 |
| - private shouldShowButton(editor: ICodeEditor): boolean { |
1440 |
| - const model = editor.getModel(); |
1441 |
| - if (!model) { |
1442 |
| - return false; // we need a model |
1443 |
| - } |
1444 |
| - |
1445 |
| - if (!this.userDataSyncEnablementService.isEnabled()) { |
1446 |
| - return false; |
1447 |
| - } |
1448 |
| - |
1449 |
| - const syncResourceConflicts = this.getSyncResourceConflicts(model.uri); |
1450 |
| - if (!syncResourceConflicts) { |
1451 |
| - return false; |
1452 |
| - } |
1453 |
| - |
1454 |
| - if (syncResourceConflicts[1].some(({ previewResource }) => isEqual(previewResource, model.uri))) { |
1455 |
| - return true; |
1456 |
| - } |
1457 |
| - |
1458 |
| - if (syncResourceConflicts[1].some(({ remoteResource }) => isEqual(remoteResource, model.uri))) { |
1459 |
| - return this.configurationService.getValue('diffEditor.renderSideBySide'); |
1460 |
| - } |
1461 |
| - |
1462 |
| - return false; |
1463 |
| - } |
1464 |
| - |
1465 |
| - private createAcceptChangesWidgetRenderer(): void { |
1466 |
| - if (!this.acceptChangesButton) { |
1467 |
| - const resource = this.editor.getModel()!.uri; |
1468 |
| - const [syncResource, conflicts] = this.getSyncResourceConflicts(resource)!; |
1469 |
| - const isRemote = conflicts.some(({ remoteResource }) => isEqual(remoteResource, resource)); |
1470 |
| - const acceptRemoteLabel = localize('accept remote', "Accept Remote"); |
1471 |
| - const acceptMergesLabel = localize('accept merges', "Accept Merges"); |
1472 |
| - const acceptRemoteButtonLabel = localize('accept remote button', "Accept &&Remote"); |
1473 |
| - const acceptMergesButtonLabel = localize('accept merges button', "Accept &&Merges"); |
1474 |
| - this.acceptChangesButton = this.instantiationService.createInstance(FloatingClickWidget, this.editor, isRemote ? acceptRemoteLabel : acceptMergesLabel, null); |
1475 |
| - this._register(this.acceptChangesButton.onClick(async () => { |
1476 |
| - const model = this.editor.getModel(); |
1477 |
| - if (model) { |
1478 |
| - this.telemetryService.publicLog2<{ source: string; action: string }, SyncConflictsClassification>('sync/handleConflicts', { source: syncResource, action: isRemote ? 'acceptRemote' : 'acceptLocal' }); |
1479 |
| - const syncAreaLabel = getSyncAreaLabel(syncResource); |
1480 |
| - const result = await this.dialogService.confirm({ |
1481 |
| - type: 'info', |
1482 |
| - title: isRemote |
1483 |
| - ? localize('Sync accept remote', "{0}: {1}", SYNC_TITLE, acceptRemoteLabel) |
1484 |
| - : localize('Sync accept merges', "{0}: {1}", SYNC_TITLE, acceptMergesLabel), |
1485 |
| - message: isRemote |
1486 |
| - ? localize('confirm replace and overwrite local', "Would you like to accept remote {0} and replace local {1}?", syncAreaLabel.toLowerCase(), syncAreaLabel.toLowerCase()) |
1487 |
| - : localize('confirm replace and overwrite remote', "Would you like to accept merges and replace remote {0}?", syncAreaLabel.toLowerCase()), |
1488 |
| - primaryButton: isRemote ? acceptRemoteButtonLabel : acceptMergesButtonLabel |
1489 |
| - }); |
1490 |
| - if (result.confirmed) { |
1491 |
| - try { |
1492 |
| - await this.userDataSyncService.accept(syncResource, model.uri, model.getValue(), true); |
1493 |
| - } catch (e) { |
1494 |
| - if (e instanceof UserDataSyncError && e.code === UserDataSyncErrorCode.LocalPreconditionFailed) { |
1495 |
| - const syncResourceCoflicts = this.userDataSyncService.conflicts.filter(syncResourceCoflicts => syncResourceCoflicts[0] === syncResource)[0]; |
1496 |
| - if (syncResourceCoflicts && conflicts.some(conflict => isEqual(conflict.previewResource, model.uri) || isEqual(conflict.remoteResource, model.uri))) { |
1497 |
| - this.notificationService.warn(localize('update conflicts', "Could not resolve conflicts as there is new local version available. Please try again.")); |
1498 |
| - } |
1499 |
| - } else { |
1500 |
| - this.notificationService.error(localize('accept failed', "Error while accepting changes. Please check [logs]({0}) for more details.", `command:${SHOW_SYNC_LOG_COMMAND_ID}`)); |
1501 |
| - } |
1502 |
| - } |
1503 |
| - } |
1504 |
| - } |
1505 |
| - })); |
1506 |
| - |
1507 |
| - this.acceptChangesButton.render(); |
1508 |
| - } |
1509 |
| - } |
1510 |
| - |
1511 |
| - private getSyncResourceConflicts(resource: URI): [SyncResource, IResourcePreview[]] | undefined { |
1512 |
| - return this.userDataSyncService.conflicts.filter(([, conflicts]) => conflicts.some(({ previewResource, remoteResource }) => isEqual(previewResource, resource) || isEqual(remoteResource, resource)))[0]; |
1513 |
| - } |
1514 |
| - |
1515 |
| - private disposeAcceptChangesWidgetRenderer(): void { |
1516 |
| - dispose(this.acceptChangesButton); |
1517 |
| - this.acceptChangesButton = undefined; |
1518 |
| - } |
1519 |
| - |
1520 |
| - override dispose(): void { |
1521 |
| - this.disposeAcceptChangesWidgetRenderer(); |
1522 |
| - super.dispose(); |
1523 |
| - } |
1524 |
| -} |
0 commit comments